| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
#include "asterisk.h" |
| 43 |
|
| 44 |
#include "asterisk/module.h" |
| 45 |
#include "asterisk/file.h" |
| 46 |
#include "asterisk/test.h" |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
static char *test_strings[][2] = { |
| 52 |
{"wav", "wav"}, |
| 53 |
{"wav|ulaw", "wav|ulaw"}, |
| 54 |
{"pcm|wav", "pcm|wav"}, |
| 55 |
{"pcm|wav|ulaw", "pcm|wav"}, |
| 56 |
{"wav|ulaw|pcm", "wav|ulaw"}, |
| 57 |
{"wav|ulaw|pcm|alaw", "wav|ulaw|alaw"}, |
| 58 |
{"pcm|ulaw|ul|mu|ulw", "pcm"}, |
| 59 |
{"wav|ulaw|pcm|alaw|sln|raw", "wav|ulaw|alaw|sln"}, |
| 60 |
{"wav|gsm|wav49", "wav|gsm|wav49"}, |
| 61 |
{"WAV|gsm|wav49", "WAV|gsm"}, |
| 62 |
{"wav|invalid|gsm", "wav|gsm"}, |
| 63 |
{"invalid|gsm", "gsm"}, |
| 64 |
{"ulaw|gsm|invalid", "ulaw|gsm"}, |
| 65 |
{"g723|g726-40|g729|gsm|ilbc|ogg|wav|WAV|siren7|siren14|sln", "g723|g726-40|g729|gsm|ilbc|ogg|wav|WAV|siren7|siren14"}, |
| 66 |
{NULL, NULL}, |
| 67 |
}; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
static char *fail_strings[] = { |
| 72 |
"this will fail", |
| 73 |
"this one|should|fail also", |
| 74 |
NULL, |
| 75 |
}; |
| 76 |
|
| 77 |
AST_TEST_DEFINE(ast_format_str_reduce_test_1) |
| 78 |
{ |
| 79 |
int i; |
| 80 |
char *c; |
| 81 |
|
| 82 |
switch (cmd) { |
| 83 |
case TEST_INIT: |
| 84 |
info->name = "ast_format_str_reduce_test_1"; |
| 85 |
info->category = "/main/file/"; |
| 86 |
info->summary = "reduce format strings"; |
| 87 |
info->description = "Reduce some format strings and make sure the results match what we expect."; |
| 88 |
return AST_TEST_NOT_RUN; |
| 89 |
case TEST_EXECUTE: |
| 90 |
break; |
| 91 |
} |
| 92 |
|
| 93 |
for (i = 0; test_strings[i][0]; i++) { |
| 94 |
c = ast_strdupa(test_strings[i][0]); |
| 95 |
if (!(c = ast_format_str_reduce(c))) { |
| 96 |
ast_test_status_update(test, "Error running ast_format_str_reduce() on string '%s'\n", |
| 97 |
test_strings[i][0]); |
| 98 |
return AST_TEST_FAIL; |
| 99 |
} |
| 100 |
|
| 101 |
if (strcmp(test_strings[i][1], c)) { |
| 102 |
ast_test_status_update(test, "Format string '%s' reduced to '%s'. Expected '%s'\n", |
| 103 |
test_strings[i][0], c, test_strings[i][1]); |
| 104 |
return AST_TEST_FAIL; |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
for (i = 0; fail_strings[i]; i++) { |
| 109 |
c = ast_strdupa(fail_strings[i]); |
| 110 |
if ((c = ast_format_str_reduce(c))) { |
| 111 |
ast_test_status_update(test, "ast_format_str_reduce() succeded on string '%s' " |
| 112 |
"with result '%s', but we expected it to fail\n", |
| 113 |
fail_strings[i], c); |
| 114 |
return AST_TEST_FAIL; |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
return AST_TEST_PASS; |
| 119 |
} |
| 120 |
|
| 121 |
static int unload_module(void) |
| 122 |
{ |
| 123 |
AST_TEST_UNREGISTER(ast_format_str_reduce_test_1); |
| 124 |
return 0; |
| 125 |
} |
| 126 |
|
| 127 |
static int load_module(void) |
| 128 |
{ |
| 129 |
|
| 130 |
AST_TEST_REGISTER(ast_format_str_reduce_test_1); |
| 131 |
|
| 132 |
return AST_MODULE_LOAD_SUCCESS; |
| 133 |
} |
| 134 |
|
| 135 |
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "ast_format_str_reduce() test module"); |