test_ast_format_str_reduce.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2010, Digium, Inc.
  5. *
  6. * Matthew Nicholson <mnichiolson@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file
  19. *
  20. * \brief Test ast_format_str_reduce
  21. *
  22. * \author Matthew Nicholson <mnichiolson@digium.com>
  23. */
  24. /*** MODULEINFO
  25. <depend>TEST_FRAMEWORK</depend>
  26. <depend>format_g723</depend>
  27. <depend>format_g726</depend>
  28. <depend>format_g729</depend>
  29. <depend>format_gsm</depend>
  30. <depend>format_ogg_vorbis</depend>
  31. <depend>format_pcm</depend>
  32. <depend>format_siren14</depend>
  33. <depend>format_siren7</depend>
  34. <depend>format_sln</depend>
  35. <depend>format_wav</depend>
  36. <depend>format_wav_gsm</depend>
  37. <support_level>core</support_level>
  38. ***/
  39. #include "asterisk.h"
  40. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  41. #include "asterisk/module.h"
  42. #include "asterisk/file.h"
  43. #include "asterisk/test.h"
  44. /* this is an array containing a list of strings to test and the expected
  45. * result for each test string. The list should be terminated by an entry
  46. * containing NULL for both elements {NULL, NULL}) */
  47. static char *test_strings[][2] = {
  48. {"wav", "wav"},
  49. {"wav|ulaw", "wav|ulaw"},
  50. {"pcm|wav", "pcm|wav"},
  51. {"pcm|wav|ulaw", "pcm|wav"},
  52. {"wav|ulaw|pcm", "wav|ulaw"},
  53. {"wav|ulaw|pcm|alaw", "wav|ulaw|alaw"},
  54. {"pcm|ulaw|ul|mu|ulw", "pcm"},
  55. {"wav|ulaw|pcm|alaw|sln|raw", "wav|ulaw|alaw|sln"},
  56. {"wav|gsm|wav49", "wav|gsm|wav49"},
  57. {"WAV|gsm|wav49", "WAV|gsm"},
  58. {"wav|invalid|gsm", "wav|gsm"},
  59. {"invalid|gsm", "gsm"},
  60. {"ulaw|gsm|invalid", "ulaw|gsm"},
  61. {"g723|g726-40|g729|gsm|ilbc|ogg|wav|WAV|siren7|siren14|sln", "g723|g726-40|g729|gsm|ilbc|ogg|wav|WAV|siren7|siren14"},
  62. {NULL, NULL},
  63. };
  64. /* this is a NULL terminated array containing a list of strings that should
  65. * cause ast_format_str_reduce() to fail */
  66. static char *fail_strings[] = {
  67. "this will fail", /* format does not exist */
  68. "this one|should|fail also", /* format does not exist */
  69. NULL,
  70. };
  71. AST_TEST_DEFINE(ast_format_str_reduce_test_1)
  72. {
  73. int i;
  74. char *c;
  75. switch (cmd) {
  76. case TEST_INIT:
  77. info->name = "ast_format_str_reduce_test_1";
  78. info->category = "/main/file/";
  79. info->summary = "reduce format strings";
  80. info->description = "Reduce some format strings and make sure the results match what we expect.";
  81. return AST_TEST_NOT_RUN;
  82. case TEST_EXECUTE:
  83. break;
  84. }
  85. for (i = 0; test_strings[i][0]; i++) {
  86. c = ast_strdupa(test_strings[i][0]);
  87. if (!(c = ast_format_str_reduce(c))) {
  88. ast_test_status_update(test, "Error running ast_format_str_reduce() on string '%s'\n",
  89. test_strings[i][0]);
  90. return AST_TEST_FAIL;
  91. }
  92. if (strcmp(test_strings[i][1], c)) {
  93. ast_test_status_update(test, "Format string '%s' reduced to '%s'. Expected '%s'\n",
  94. test_strings[i][0], c, test_strings[i][1]);
  95. return AST_TEST_FAIL;
  96. }
  97. }
  98. for (i = 0; fail_strings[i]; i++) {
  99. c = ast_strdupa(fail_strings[i]);
  100. if ((c = ast_format_str_reduce(c))) {
  101. ast_test_status_update(test, "ast_format_str_reduce() succeded on string '%s' "
  102. "with result '%s', but we expected it to fail\n",
  103. fail_strings[i], c);
  104. return AST_TEST_FAIL;
  105. }
  106. }
  107. return AST_TEST_PASS;
  108. }
  109. static int unload_module(void)
  110. {
  111. AST_TEST_UNREGISTER(ast_format_str_reduce_test_1);
  112. return 0;
  113. }
  114. static int load_module(void)
  115. {
  116. AST_TEST_REGISTER(ast_format_str_reduce_test_1);
  117. return AST_MODULE_LOAD_SUCCESS;
  118. }
  119. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "ast_format_str_reduce() test module");