| 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 |
#include "asterisk.h" |
| 36 |
|
| 37 |
#include "asterisk/test.h" |
| 38 |
#include "asterisk/utils.h" |
| 39 |
#include "asterisk/strings.h" |
| 40 |
#include "asterisk/module.h" |
| 41 |
|
| 42 |
AST_TEST_DEFINE(str_test) |
| 43 |
{ |
| 44 |
struct ast_str *stack_str; |
| 45 |
struct ast_str *heap_str; |
| 46 |
const char short_string1[] = "apple"; |
| 47 |
const char short_string2[] = "banana"; |
| 48 |
char short_string_cat[30]; |
| 49 |
const char long_string1[] = "applebananapeachmangocherrypeargrapeplumlimetangerinepomegranategravel"; |
| 50 |
const char long_string2[] = "passionuglinectarinepineapplekiwilemonpaintthinner"; |
| 51 |
char long_string_cat[200]; |
| 52 |
char string_limit_cat[11]; |
| 53 |
const int string_limit = 5; |
| 54 |
int current_size; |
| 55 |
enum ast_test_result_state res = AST_TEST_PASS; |
| 56 |
|
| 57 |
switch (cmd) { |
| 58 |
case TEST_INIT: |
| 59 |
info->name = "str_test"; |
| 60 |
info->category = "/main/strings/"; |
| 61 |
info->summary = "Test dynamic string operations"; |
| 62 |
info->description = "Test setting and appending stack and heap-allocated strings"; |
| 63 |
return AST_TEST_NOT_RUN; |
| 64 |
case TEST_EXECUTE: |
| 65 |
break; |
| 66 |
} |
| 67 |
snprintf(short_string_cat, sizeof(short_string_cat), "%s%s", short_string1, short_string2); |
| 68 |
snprintf(long_string_cat, sizeof(long_string_cat), "%s%s", long_string1, long_string2); |
| 69 |
snprintf(string_limit_cat, string_limit, "%s", long_string1); |
| 70 |
strncat(string_limit_cat, long_string2, string_limit); |
| 71 |
|
| 72 |
if (!(stack_str = ast_str_alloca(15))) { |
| 73 |
ast_test_status_update(test, "Failed to allocate an ast_str on the stack\n"); |
| 74 |
return AST_TEST_FAIL; |
| 75 |
} |
| 76 |
|
| 77 |
if (!(heap_str = ast_str_create(15))) { |
| 78 |
ast_test_status_update(test, "Failed to allocate an ast_str on the heap\n"); |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
if (ast_str_set(&stack_str, 0, "%s", short_string1) < 0) { |
| 93 |
ast_test_status_update(test, "Error setting stack string\n"); |
| 94 |
res = AST_TEST_FAIL; |
| 95 |
goto cleanup; |
| 96 |
} |
| 97 |
if (strcmp(ast_str_buffer(stack_str), short_string1)) { |
| 98 |
ast_test_status_update(test, "ast_str_set failed for stack string. Expected '%s' but" |
| 99 |
"instead got %s\n", short_string1, ast_str_buffer(stack_str)); |
| 100 |
res = AST_TEST_FAIL; |
| 101 |
goto cleanup; |
| 102 |
} |
| 103 |
|
| 104 |
if (ast_str_append(&stack_str, 0, "%s", short_string2) < 0) { |
| 105 |
ast_test_status_update(test, "Error appending to stack string\n"); |
| 106 |
res = AST_TEST_FAIL; |
| 107 |
goto cleanup; |
| 108 |
} |
| 109 |
if (strcmp(ast_str_buffer(stack_str), short_string_cat)) { |
| 110 |
ast_test_status_update(test, "ast_str_set failed for stack string. Expected '%s'" |
| 111 |
"but instead got %s\n", short_string_cat, ast_str_buffer(stack_str)); |
| 112 |
res = AST_TEST_FAIL; |
| 113 |
goto cleanup; |
| 114 |
} |
| 115 |
|
| 116 |
ast_str_reset(stack_str); |
| 117 |
if (ast_str_strlen(stack_str) != 0) { |
| 118 |
ast_test_status_update(test, "ast_str_reset resulted in non-zero length for stack_str\n"); |
| 119 |
res = AST_TEST_FAIL; |
| 120 |
goto cleanup; |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
if (ast_str_set(&stack_str, -1, "%s", long_string1) < 0) { |
| 125 |
ast_test_status_update(test, "Error setting stack string with long input\n"); |
| 126 |
res = AST_TEST_FAIL; |
| 127 |
goto cleanup; |
| 128 |
} |
| 129 |
if (strncmp(ast_str_buffer(stack_str), long_string1, ast_str_strlen(stack_str))) { |
| 130 |
ast_test_status_update(test, "Stack string not set to what is expected.\n"); |
| 131 |
res = AST_TEST_FAIL; |
| 132 |
goto cleanup; |
| 133 |
} |
| 134 |
|
| 135 |
if (ast_str_append(&stack_str, -1, "%s", long_string2) < 0) { |
| 136 |
ast_test_status_update(test, "Error appending long string to full stack string buffer\n"); |
| 137 |
res = AST_TEST_FAIL; |
| 138 |
goto cleanup; |
| 139 |
} |
| 140 |
if (strncmp(ast_str_buffer(stack_str), long_string_cat, ast_str_strlen(stack_str))) { |
| 141 |
ast_test_status_update(test, "Stack string not set to what is expected.\n"); |
| 142 |
res = AST_TEST_FAIL; |
| 143 |
goto cleanup; |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
if (ast_str_set(&heap_str, 0, "%s", short_string1) < 0) { |
| 155 |
ast_test_status_update(test, "Error setting heap string\n"); |
| 156 |
res = AST_TEST_FAIL; |
| 157 |
goto cleanup; |
| 158 |
} |
| 159 |
if (strcmp(ast_str_buffer(heap_str), short_string1)) { |
| 160 |
ast_test_status_update(test, "ast_str_set failed for heap string. Expected '%s' but" |
| 161 |
"instead got %s\n", short_string1, ast_str_buffer(heap_str)); |
| 162 |
res = AST_TEST_FAIL; |
| 163 |
goto cleanup; |
| 164 |
} |
| 165 |
|
| 166 |
if (ast_str_append(&heap_str, 0, "%s", short_string2) < 0) { |
| 167 |
ast_test_status_update(test, "Error appending to heap string\n"); |
| 168 |
res = AST_TEST_FAIL; |
| 169 |
goto cleanup; |
| 170 |
} |
| 171 |
if (strcmp(ast_str_buffer(heap_str), short_string_cat)) { |
| 172 |
ast_test_status_update(test, "ast_str_set failed for stack string. Expected '%s'" |
| 173 |
"but instead got %s\n", short_string_cat, ast_str_buffer(stack_str)); |
| 174 |
res = AST_TEST_FAIL; |
| 175 |
goto cleanup; |
| 176 |
} |
| 177 |
|
| 178 |
ast_str_reset(heap_str); |
| 179 |
if (ast_str_strlen(heap_str) != 0) { |
| 180 |
ast_test_status_update(test, "ast_str_reset resulted in non-zero length for stack_str\n"); |
| 181 |
res = AST_TEST_FAIL; |
| 182 |
goto cleanup; |
| 183 |
} |
| 184 |
|
| 185 |
current_size = ast_str_size(heap_str); |
| 186 |
if (ast_str_set(&heap_str, -1, "%s", long_string1) < 0) { |
| 187 |
ast_test_status_update(test, "Error setting heap string with long input\n"); |
| 188 |
res = AST_TEST_FAIL; |
| 189 |
goto cleanup; |
| 190 |
} |
| 191 |
if (current_size != ast_str_size(heap_str)) { |
| 192 |
ast_test_status_update(test, "Heap string changed size during ast_str_set when it was" |
| 193 |
"instructed not to. Was %d and now is %d\n", current_size, (int) ast_str_size(heap_str)); |
| 194 |
res = AST_TEST_FAIL; |
| 195 |
goto cleanup; |
| 196 |
} |
| 197 |
if (strncmp(ast_str_buffer(heap_str), long_string1, ast_str_strlen(heap_str))) { |
| 198 |
ast_test_status_update(test, "Heap string not set to what is expected.\n"); |
| 199 |
res = AST_TEST_FAIL; |
| 200 |
goto cleanup; |
| 201 |
} |
| 202 |
|
| 203 |
current_size = ast_str_size(heap_str); |
| 204 |
if (ast_str_append(&heap_str, -1, "%s", long_string2) < 0) { |
| 205 |
ast_test_status_update(test, "Error appending long string to full heap string buffer\n"); |
| 206 |
res = AST_TEST_FAIL; |
| 207 |
goto cleanup; |
| 208 |
} |
| 209 |
if (current_size != ast_str_size(heap_str)) { |
| 210 |
ast_test_status_update(test, "Heap string changed size during ast_str_append when it was" |
| 211 |
"instructed not to. Was %d and now is %d\n", current_size, (int) ast_str_size(heap_str)); |
| 212 |
res = AST_TEST_FAIL; |
| 213 |
goto cleanup; |
| 214 |
} |
| 215 |
if (strncmp(ast_str_buffer(heap_str), long_string_cat, ast_str_strlen(heap_str))) { |
| 216 |
ast_test_status_update(test, "Heap string not set to what is expected.\n"); |
| 217 |
res = AST_TEST_FAIL; |
| 218 |
goto cleanup; |
| 219 |
} |
| 220 |
|
| 221 |
ast_str_reset(heap_str); |
| 222 |
|
| 223 |
if (ast_str_set(&heap_str, 0, "%s", long_string1) < 0) { |
| 224 |
ast_test_status_update(test, "Error setting heap string with long input\n"); |
| 225 |
res = AST_TEST_FAIL; |
| 226 |
goto cleanup; |
| 227 |
} |
| 228 |
if (strcmp(ast_str_buffer(heap_str), long_string1)) { |
| 229 |
ast_test_status_update(test, "Heap string does not contain what was expected. Expected %s" |
| 230 |
"but have %s instead\n", long_string1, ast_str_buffer(heap_str)); |
| 231 |
res = AST_TEST_FAIL; |
| 232 |
goto cleanup; |
| 233 |
} |
| 234 |
|
| 235 |
if (ast_str_append(&heap_str, 0, "%s", long_string2) < 0) { |
| 236 |
ast_test_status_update(test, "Error setting heap string with long input\n"); |
| 237 |
res = AST_TEST_FAIL; |
| 238 |
goto cleanup; |
| 239 |
} |
| 240 |
if (strcmp(ast_str_buffer(heap_str), long_string_cat)) { |
| 241 |
ast_test_status_update(test, "Heap string does not contain what was expected. Expected %s" |
| 242 |
"but have %s instead\n", long_string_cat, ast_str_buffer(heap_str)); |
| 243 |
res = AST_TEST_FAIL; |
| 244 |
goto cleanup; |
| 245 |
} |
| 246 |
|
| 247 |
cleanup: |
| 248 |
ast_free(heap_str); |
| 249 |
return res; |
| 250 |
} |
| 251 |
|
| 252 |
AST_TEST_DEFINE(begins_with_test) |
| 253 |
{ |
| 254 |
switch (cmd) { |
| 255 |
case TEST_INIT: |
| 256 |
info->name = "begins_with"; |
| 257 |
info->category = "/main/strings/"; |
| 258 |
info->summary = "Test ast_begins_with"; |
| 259 |
info->description = "Test ast_begins_with"; |
| 260 |
return AST_TEST_NOT_RUN; |
| 261 |
case TEST_EXECUTE: |
| 262 |
break; |
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
ast_test_validate(test, 1 == ast_begins_with("foobar", "foobar")); |
| 267 |
ast_test_validate(test, 1 == ast_begins_with("foobar", "foo")); |
| 268 |
ast_test_validate(test, 1 == ast_begins_with("foobar", "")); |
| 269 |
ast_test_validate(test, 1 == ast_begins_with("", "")); |
| 270 |
|
| 271 |
|
| 272 |
ast_test_validate(test, 0 == ast_begins_with("foobar", "bang")); |
| 273 |
ast_test_validate(test, 0 == ast_begins_with("foobar", "foobat")); |
| 274 |
ast_test_validate(test, 0 == ast_begins_with("boo", "boom")); |
| 275 |
ast_test_validate(test, 0 == ast_begins_with("", "blitz")); |
| 276 |
|
| 277 |
|
| 278 |
return AST_TEST_PASS; |
| 279 |
} |
| 280 |
|
| 281 |
AST_TEST_DEFINE(ends_with_test) |
| 282 |
{ |
| 283 |
switch (cmd) { |
| 284 |
case TEST_INIT: |
| 285 |
info->name = "ends_with"; |
| 286 |
info->category = "/main/strings/"; |
| 287 |
info->summary = "Test ast_ends_with"; |
| 288 |
info->description = "Test ast_ends_with"; |
| 289 |
return AST_TEST_NOT_RUN; |
| 290 |
case TEST_EXECUTE: |
| 291 |
break; |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
ast_test_validate(test, 1 == ast_ends_with("foobar", "foobar")); |
| 296 |
ast_test_validate(test, 1 == ast_ends_with("foobar", "bar")); |
| 297 |
ast_test_validate(test, 1 == ast_ends_with("foobar", "")); |
| 298 |
ast_test_validate(test, 1 == ast_ends_with("", "")); |
| 299 |
|
| 300 |
|
| 301 |
ast_test_validate(test, 0 == ast_ends_with("bar", "bbar")); |
| 302 |
ast_test_validate(test, 0 == ast_ends_with("foobar", "bang")); |
| 303 |
ast_test_validate(test, 0 == ast_ends_with("foobar", "foobat")); |
| 304 |
ast_test_validate(test, 0 == ast_ends_with("boo", "boom")); |
| 305 |
ast_test_validate(test, 0 == ast_ends_with("", "blitz")); |
| 306 |
|
| 307 |
|
| 308 |
return AST_TEST_PASS; |
| 309 |
} |
| 310 |
|
| 311 |
AST_TEST_DEFINE(strsep_test) |
| 312 |
{ |
| 313 |
char *test1, *test2, *test3; |
| 314 |
|
| 315 |
switch (cmd) { |
| 316 |
case TEST_INIT: |
| 317 |
info->name = "strsep"; |
| 318 |
info->category = "/main/strings/"; |
| 319 |
info->summary = "Test ast_strsep"; |
| 320 |
info->description = "Test ast_strsep"; |
| 321 |
return AST_TEST_NOT_RUN; |
| 322 |
case TEST_EXECUTE: |
| 323 |
break; |
| 324 |
} |
| 325 |
|
| 326 |
test1 = ast_strdupa("ghi=jkl,mno='pqr,stu',abc=def, vwx = yz1 , vwx = yz1 , '" |
| 327 |
" vwx = yz1 ' , ' vwx , yz1 ',v\"w\"x, '\"x,v\",\"x\"' , \" i\\'m a test\"" |
| 328 |
", \" i\\'m a, test\", \" i\\'m a, test\", e\\,nd, end\\"); |
| 329 |
|
| 330 |
test2 = ast_strsep(&test1, ',', 0); |
| 331 |
ast_test_validate(test, 0 == strcmp("ghi=jkl", test2)); |
| 332 |
|
| 333 |
test3 = ast_strsep(&test2, '=', 0); |
| 334 |
ast_test_validate(test, 0 == strcmp("ghi", test3)); |
| 335 |
|
| 336 |
test3 = ast_strsep(&test2, '=', 0); |
| 337 |
ast_test_validate(test, 0 == strcmp("jkl", test3)); |
| 338 |
|
| 339 |
test2 = ast_strsep(&test1, ',', 0); |
| 340 |
ast_test_validate(test, 0 == strcmp("mno='pqr,stu'", test2)); |
| 341 |
|
| 342 |
test3 = ast_strsep(&test2, '=', 0); |
| 343 |
ast_test_validate(test, 0 == strcmp("mno", test3)); |
| 344 |
|
| 345 |
test3 = ast_strsep(&test2, '=', 0); |
| 346 |
ast_test_validate(test, 0 == strcmp("'pqr,stu'", test3)); |
| 347 |
|
| 348 |
test2 = ast_strsep(&test1, ',', 0); |
| 349 |
ast_test_validate(test, 0 == strcmp("abc=def", test2)); |
| 350 |
|
| 351 |
test2 = ast_strsep(&test1, ',', 0); |
| 352 |
ast_test_validate(test, 0 == strcmp(" vwx = yz1 ", test2)); |
| 353 |
|
| 354 |
test2 = ast_strsep(&test1, ',', AST_STRSEP_TRIM); |
| 355 |
ast_test_validate(test, 0 == strcmp("vwx = yz1", test2)); |
| 356 |
|
| 357 |
test2 = ast_strsep(&test1, ',', AST_STRSEP_STRIP); |
| 358 |
ast_test_validate(test, 0 == strcmp(" vwx = yz1 ", test2)); |
| 359 |
|
| 360 |
test2 = ast_strsep(&test1, ',', AST_STRSEP_STRIP | AST_STRSEP_TRIM); |
| 361 |
ast_test_validate(test, 0 == strcmp("vwx , yz1", test2)); |
| 362 |
|
| 363 |
test2 = ast_strsep(&test1, ',', AST_STRSEP_STRIP | AST_STRSEP_TRIM); |
| 364 |
ast_test_validate(test, 0 == strcmp("v\"w\"x", test2)); |
| 365 |
|
| 366 |
test2 = ast_strsep(&test1, ',', AST_STRSEP_TRIM); |
| 367 |
ast_test_validate(test, 0 == strcmp("'\"x,v\",\"x\"'", test2)); |
| 368 |
|
| 369 |
test2 = ast_strsep(&test1, ',', AST_STRSEP_TRIM); |
| 370 |
ast_test_validate(test, 0 == strcmp("\" i\\'m a test\"", test2)); |
| 371 |
|
| 372 |
test2 = ast_strsep(&test1, ',', AST_STRSEP_TRIM | AST_STRSEP_UNESCAPE); |
| 373 |
ast_test_validate(test, 0 == strcmp("\" i'm a, test\"", test2)); |
| 374 |
|
| 375 |
test2 = ast_strsep(&test1, ',', AST_STRSEP_ALL); |
| 376 |
ast_test_validate(test, 0 == strcmp("i'm a, test", test2)); |
| 377 |
|
| 378 |
test2 = ast_strsep(&test1, ',', AST_STRSEP_TRIM | AST_STRSEP_UNESCAPE); |
| 379 |
ast_test_validate(test, 0 == strcmp("e,nd", test2)); |
| 380 |
|
| 381 |
test2 = ast_strsep(&test1, ',', AST_STRSEP_TRIM | AST_STRSEP_UNESCAPE); |
| 382 |
ast_test_validate(test, 0 == strcmp("end", test2)); |
| 383 |
|
| 384 |
|
| 385 |
return AST_TEST_PASS; |
| 386 |
} |
| 387 |
|
| 388 |
AST_TEST_DEFINE(strsep_quoted_test) |
| 389 |
{ |
| 390 |
char *test1, *test2, *test3; |
| 391 |
|
| 392 |
switch (cmd) { |
| 393 |
case TEST_INIT: |
| 394 |
info->name = "strsep_quoted"; |
| 395 |
info->category = "/main/strings/"; |
| 396 |
info->summary = "Test ast_strsep_quoted"; |
| 397 |
info->description = "Test ast_strsep_quoted"; |
| 398 |
return AST_TEST_NOT_RUN; |
| 399 |
case TEST_EXECUTE: |
| 400 |
break; |
| 401 |
} |
| 402 |
|
| 403 |
test1 = ast_strdupa("ghi=jkl,mno=\"pqr,stu\",abc=def, vwx = yz1 , vwx = yz1 , " |
| 404 |
"\" vwx = yz1 \" , \" vwx , yz1 \",v'w'x, \"'x,v','x'\" , \" i\\'m a test\"" |
| 405 |
", \" i\\'m a, test\", \" i\\'m a, test\", e\\,nd, end\\"); |
| 406 |
|
| 407 |
test2 = ast_strsep_quoted(&test1, ',', '"', 0); |
| 408 |
ast_test_validate(test, 0 == strcmp("ghi=jkl", test2)); |
| 409 |
|
| 410 |
test3 = ast_strsep_quoted(&test2, '=', '"', 0); |
| 411 |
ast_test_validate(test, 0 == strcmp("ghi", test3)); |
| 412 |
|
| 413 |
test3 = ast_strsep_quoted(&test2, '=', '"', 0); |
| 414 |
ast_test_validate(test, 0 == strcmp("jkl", test3)); |
| 415 |
|
| 416 |
test2 = ast_strsep_quoted(&test1, ',', '"', 0); |
| 417 |
ast_test_validate(test, 0 == strcmp("mno=\"pqr,stu\"", test2)); |
| 418 |
|
| 419 |
test3 = ast_strsep_quoted(&test2, '=', '"', 0); |
| 420 |
ast_test_validate(test, 0 == strcmp("mno", test3)); |
| 421 |
|
| 422 |
test3 = ast_strsep_quoted(&test2, '=', '"', 0); |
| 423 |
ast_test_validate(test, 0 == strcmp("\"pqr,stu\"", test3)); |
| 424 |
|
| 425 |
test2 = ast_strsep_quoted(&test1, ',', '"', 0); |
| 426 |
ast_test_validate(test, 0 == strcmp("abc=def", test2)); |
| 427 |
|
| 428 |
test2 = ast_strsep_quoted(&test1, ',', '"', 0); |
| 429 |
ast_test_validate(test, 0 == strcmp(" vwx = yz1 ", test2)); |
| 430 |
|
| 431 |
test2 = ast_strsep_quoted(&test1, ',', '"', AST_STRSEP_TRIM); |
| 432 |
ast_test_validate(test, 0 == strcmp("vwx = yz1", test2)); |
| 433 |
|
| 434 |
test2 = ast_strsep_quoted(&test1, ',', '"', AST_STRSEP_STRIP); |
| 435 |
ast_test_validate(test, 0 == strcmp(" vwx = yz1 ", test2)); |
| 436 |
|
| 437 |
test2 = ast_strsep_quoted(&test1, ',', '"', AST_STRSEP_STRIP | AST_STRSEP_TRIM); |
| 438 |
ast_test_validate(test, 0 == strcmp("vwx , yz1", test2)); |
| 439 |
|
| 440 |
test2 = ast_strsep_quoted(&test1, ',', '"', AST_STRSEP_STRIP | AST_STRSEP_TRIM); |
| 441 |
ast_test_validate(test, 0 == strcmp("v'w'x", test2)); |
| 442 |
|
| 443 |
test2 = ast_strsep_quoted(&test1, ',', '"', AST_STRSEP_TRIM); |
| 444 |
ast_test_validate(test, 0 == strcmp("\"'x,v','x'\"", test2)); |
| 445 |
|
| 446 |
test2 = ast_strsep_quoted(&test1, ',', '"', AST_STRSEP_TRIM); |
| 447 |
ast_test_validate(test, 0 == strcmp("\" i\\'m a test\"", test2)); |
| 448 |
|
| 449 |
test2 = ast_strsep_quoted(&test1, ',', '"', AST_STRSEP_TRIM | AST_STRSEP_UNESCAPE); |
| 450 |
ast_test_validate(test, 0 == strcmp("\" i'm a, test\"", test2)); |
| 451 |
|
| 452 |
test2 = ast_strsep_quoted(&test1, ',', '"', AST_STRSEP_ALL); |
| 453 |
ast_test_validate(test, 0 == strcmp("i'm a, test", test2)); |
| 454 |
|
| 455 |
test2 = ast_strsep_quoted(&test1, ',', '"', AST_STRSEP_TRIM | AST_STRSEP_UNESCAPE); |
| 456 |
ast_test_validate(test, 0 == strcmp("e,nd", test2)); |
| 457 |
|
| 458 |
test2 = ast_strsep_quoted(&test1, ',', '"', AST_STRSEP_TRIM | AST_STRSEP_UNESCAPE); |
| 459 |
ast_test_validate(test, 0 == strcmp("end", test2)); |
| 460 |
|
| 461 |
|
| 462 |
test1 = ast_strdupa("ghi=jkl,mno=|pqr,stu|,abc=def, vwx = yz1 , vwx = yz1 , " |
| 463 |
"| vwx = yz1 | , | vwx , yz1 |,v'w'x, |'x,v','x'| , | i\\'m a test|" |
| 464 |
", | i\\'m a, test|, | i\\'m a, test|, e\\,nd, end\\"); |
| 465 |
|
| 466 |
test2 = ast_strsep_quoted(&test1, ',', '|', 0); |
| 467 |
ast_test_validate(test, 0 == strcmp("ghi=jkl", test2)); |
| 468 |
|
| 469 |
test3 = ast_strsep_quoted(&test2, '=', '|', 0); |
| 470 |
ast_test_validate(test, 0 == strcmp("ghi", test3)); |
| 471 |
|
| 472 |
test3 = ast_strsep_quoted(&test2, '=', '|', 0); |
| 473 |
ast_test_validate(test, 0 == strcmp("jkl", test3)); |
| 474 |
|
| 475 |
test2 = ast_strsep_quoted(&test1, ',', '|', 0); |
| 476 |
ast_test_validate(test, 0 == strcmp("mno=|pqr,stu|", test2)); |
| 477 |
|
| 478 |
test3 = ast_strsep_quoted(&test2, '=', '|', 0); |
| 479 |
ast_test_validate(test, 0 == strcmp("mno", test3)); |
| 480 |
|
| 481 |
test3 = ast_strsep_quoted(&test2, '=', '|', 0); |
| 482 |
ast_test_validate(test, 0 == strcmp("|pqr,stu|", test3)); |
| 483 |
|
| 484 |
test2 = ast_strsep_quoted(&test1, ',', '|', 0); |
| 485 |
ast_test_validate(test, 0 == strcmp("abc=def", test2)); |
| 486 |
|
| 487 |
test2 = ast_strsep_quoted(&test1, ',', '|', 0); |
| 488 |
ast_test_validate(test, 0 == strcmp(" vwx = yz1 ", test2)); |
| 489 |
|
| 490 |
test2 = ast_strsep_quoted(&test1, ',', '|', AST_STRSEP_TRIM); |
| 491 |
ast_test_validate(test, 0 == strcmp("vwx = yz1", test2)); |
| 492 |
|
| 493 |
test2 = ast_strsep_quoted(&test1, ',', '|', AST_STRSEP_STRIP); |
| 494 |
ast_test_validate(test, 0 == strcmp(" vwx = yz1 ", test2)); |
| 495 |
|
| 496 |
test2 = ast_strsep_quoted(&test1, ',', '|', AST_STRSEP_STRIP | AST_STRSEP_TRIM); |
| 497 |
ast_test_validate(test, 0 == strcmp("vwx , yz1", test2)); |
| 498 |
|
| 499 |
test2 = ast_strsep_quoted(&test1, ',', '|', AST_STRSEP_STRIP | AST_STRSEP_TRIM); |
| 500 |
ast_test_validate(test, 0 == strcmp("v'w'x", test2)); |
| 501 |
|
| 502 |
test2 = ast_strsep_quoted(&test1, ',', '|', AST_STRSEP_TRIM); |
| 503 |
ast_test_validate(test, 0 == strcmp("|'x,v','x'|", test2)); |
| 504 |
|
| 505 |
test2 = ast_strsep_quoted(&test1, ',', '|', AST_STRSEP_TRIM); |
| 506 |
ast_test_validate(test, 0 == strcmp("| i\\'m a test|", test2)); |
| 507 |
|
| 508 |
test2 = ast_strsep_quoted(&test1, ',', '|', AST_STRSEP_TRIM | AST_STRSEP_UNESCAPE); |
| 509 |
ast_test_validate(test, 0 == strcmp("| i'm a, test|", test2)); |
| 510 |
|
| 511 |
test2 = ast_strsep_quoted(&test1, ',', '|', AST_STRSEP_ALL); |
| 512 |
ast_test_validate(test, 0 == strcmp("i'm a, test", test2)); |
| 513 |
|
| 514 |
test2 = ast_strsep_quoted(&test1, ',', '|', AST_STRSEP_TRIM | AST_STRSEP_UNESCAPE); |
| 515 |
ast_test_validate(test, 0 == strcmp("e,nd", test2)); |
| 516 |
|
| 517 |
test2 = ast_strsep_quoted(&test1, ',', '|', AST_STRSEP_TRIM | AST_STRSEP_UNESCAPE); |
| 518 |
ast_test_validate(test, 0 == strcmp("end", test2)); |
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
return AST_TEST_PASS; |
| 523 |
} |
| 524 |
|
| 525 |
static int test_semi(char *string1, char *string2, int test_len) |
| 526 |
{ |
| 527 |
char *test2 = NULL; |
| 528 |
|
| 529 |
if (test_len > 0) { |
| 530 |
test2 = ast_alloca(test_len); |
| 531 |
*test2 = '\0'; |
| 532 |
} else if (test_len == 0) { |
| 533 |
test2 = ""; |
| 534 |
} |
| 535 |
ast_escape_semicolons(string1, test2, test_len); |
| 536 |
if (test2 != NULL && strcmp(string2, test2) == 0) { |
| 537 |
return 1; |
| 538 |
} else { |
| 539 |
return 0; |
| 540 |
} |
| 541 |
} |
| 542 |
|
| 543 |
AST_TEST_DEFINE(escape_semicolons_test) |
| 544 |
{ |
| 545 |
switch (cmd) { |
| 546 |
case TEST_INIT: |
| 547 |
info->name = "escape_semicolons"; |
| 548 |
info->category = "/main/strings/"; |
| 549 |
info->summary = "Test ast_escape_semicolons"; |
| 550 |
info->description = "Test ast_escape_semicolons"; |
| 551 |
return AST_TEST_NOT_RUN; |
| 552 |
case TEST_EXECUTE: |
| 553 |
break; |
| 554 |
} |
| 555 |
|
| 556 |
|
| 557 |
ast_test_validate(test, test_semi("this is a ;test", "this is a \\;test", 18)); |
| 558 |
ast_test_validate(test, test_semi(";", "\\;", 3)); |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
ast_test_validate(test, test_semi(";", "", 0)); |
| 564 |
ast_test_validate(test, test_semi(";", "", 1)); |
| 565 |
ast_test_validate(test, test_semi(";", "", 2)); |
| 566 |
ast_test_validate(test, test_semi("x", "", 0)); |
| 567 |
ast_test_validate(test, test_semi("x", "", 1)); |
| 568 |
|
| 569 |
|
| 570 |
ast_test_validate(test, test_semi("xx;xx", "x", 2)); |
| 571 |
ast_test_validate(test, test_semi("xx;xx", "xx", 3)); |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
ast_test_validate(test, test_semi("xx;xx", "xx", 4)); |
| 577 |
|
| 578 |
ast_test_validate(test, test_semi("xx;xx", "xx\\;", 5)); |
| 579 |
ast_test_validate(test, test_semi("xx;xx", "xx\\;x", 6)); |
| 580 |
ast_test_validate(test, test_semi("xx;xx", "xx\\;xx", 7)); |
| 581 |
ast_test_validate(test, test_semi("xx;xx", "xx\\;xx", 8)); |
| 582 |
|
| 583 |
|
| 584 |
ast_test_validate(test, test_semi("xx;xx;this is a test", "xx\\;xx\\;this is a test", 32)); |
| 585 |
ast_test_validate(test, test_semi(";;;;;", "\\;\\;\\;\\;\\;", 32)); |
| 586 |
ast_test_validate(test, test_semi(";;;;;", "\\;\\;\\;\\;", 10)); |
| 587 |
ast_test_validate(test, test_semi(";;;;;", "\\;\\;\\;\\;\\;", 11)); |
| 588 |
ast_test_validate(test, test_semi(";;\\;;;", "\\;\\;\\\\;\\;\\;", 32)); |
| 589 |
|
| 590 |
return AST_TEST_PASS; |
| 591 |
} |
| 592 |
|
| 593 |
AST_TEST_DEFINE(escape_test) |
| 594 |
{ |
| 595 |
char buf[128]; |
| 596 |
|
| 597 |
#define TEST_ESCAPE(s, to_escape, expected) \ |
| 598 |
!strcmp(ast_escape(buf, s, ARRAY_LEN(buf), to_escape), expected) |
| 599 |
|
| 600 |
#define TEST_ESCAPE_C(s, expected) \ |
| 601 |
!strcmp(ast_escape_c(buf, s, ARRAY_LEN(buf)), expected) |
| 602 |
|
| 603 |
#define TEST_ESCAPE_ALLOC(s, to_escape, expected) \ |
| 604 |
({ \ |
| 605 |
int res = 0; \ |
| 606 |
char *a_buf = ast_escape_alloc(s, to_escape); \ |
| 607 |
if (a_buf) { \ |
| 608 |
res = !strcmp(a_buf, expected); \ |
| 609 |
ast_free(a_buf); \ |
| 610 |
} \ |
| 611 |
res; \ |
| 612 |
}) |
| 613 |
|
| 614 |
#define TEST_ESCAPE_C_ALLOC(s, expected) \ |
| 615 |
({ \ |
| 616 |
int res = 0; \ |
| 617 |
char *a_buf = ast_escape_c_alloc(s); \ |
| 618 |
if (a_buf) { \ |
| 619 |
res = !strcmp(a_buf, expected); \ |
| 620 |
ast_free(a_buf); \ |
| 621 |
} \ |
| 622 |
res; \ |
| 623 |
}) |
| 624 |
|
| 625 |
switch (cmd) { |
| 626 |
case TEST_INIT: |
| 627 |
info->name = "escape"; |
| 628 |
info->category = "/main/strings/"; |
| 629 |
info->summary = "Test ast_escape"; |
| 630 |
info->description = "Test escaping values in a string"; |
| 631 |
return AST_TEST_NOT_RUN; |
| 632 |
case TEST_EXECUTE: |
| 633 |
break; |
| 634 |
} |
| 635 |
|
| 636 |
ast_test_validate(test, TEST_ESCAPE("null escape", NULL, "null escape")); |
| 637 |
ast_test_validate(test, TEST_ESCAPE("empty escape", "", "empty escape")); |
| 638 |
ast_test_validate(test, TEST_ESCAPE("", "Z", "")); |
| 639 |
ast_test_validate(test, TEST_ESCAPE("no matching escape", "Z", "no matching escape")); |
| 640 |
ast_test_validate(test, TEST_ESCAPE("escape Z", "Z", "escape \\Z")); |
| 641 |
ast_test_validate(test, TEST_ESCAPE("Z", "Z", "\\Z")); |
| 642 |
ast_test_validate(test, TEST_ESCAPE(";;", ";", "\\;\\;")); |
| 643 |
ast_test_validate(test, TEST_ESCAPE("escape \n", "\n", "escape \\n")); |
| 644 |
ast_test_validate(test, TEST_ESCAPE("escape \n again \n", "\n", "escape \\n again \\n")); |
| 645 |
|
| 646 |
ast_test_validate(test, TEST_ESCAPE_C("", "")); |
| 647 |
ast_test_validate(test, TEST_ESCAPE_C("escape \a\b\f\n\r\t\v\\\'\"\?", |
| 648 |
"escape \\a\\b\\f\\n\\r\\t\\v\\\\\\\'\\\"\\?")); |
| 649 |
|
| 650 |
ast_test_validate(test, TEST_ESCAPE_ALLOC("", "Z", "")); |
| 651 |
ast_test_validate(test, TEST_ESCAPE_ALLOC("Z", "Z", "\\Z")); |
| 652 |
ast_test_validate(test, TEST_ESCAPE_ALLOC("a", "Z", "a")); |
| 653 |
|
| 654 |
ast_test_validate(test, TEST_ESCAPE_C_ALLOC("", "")); |
| 655 |
ast_test_validate(test, TEST_ESCAPE_C_ALLOC("\n", "\\n")); |
| 656 |
ast_test_validate(test, TEST_ESCAPE_C_ALLOC("a", "a")); |
| 657 |
|
| 658 |
return AST_TEST_PASS; |
| 659 |
} |
| 660 |
|
| 661 |
AST_TEST_DEFINE(strings_match) |
| 662 |
{ |
| 663 |
switch (cmd) { |
| 664 |
case TEST_INIT: |
| 665 |
info->name = "strings_match"; |
| 666 |
info->category = "/main/strings/"; |
| 667 |
info->summary = "Test ast_strings_match"; |
| 668 |
info->description = "Test ast_strings_match"; |
| 669 |
return AST_TEST_NOT_RUN; |
| 670 |
case TEST_EXECUTE: |
| 671 |
break; |
| 672 |
} |
| 673 |
|
| 674 |
ast_test_validate(test, ast_strings_match("aaa", NULL, "aaa")); |
| 675 |
ast_test_validate(test, ast_strings_match("aaa", "", "aaa")); |
| 676 |
ast_test_validate(test, ast_strings_match("aaa", "=", "aaa")); |
| 677 |
ast_test_validate(test, !ast_strings_match("aaa", "!=", "aaa")); |
| 678 |
ast_test_validate(test, !ast_strings_match("aaa", NULL, "aba")); |
| 679 |
ast_test_validate(test, !ast_strings_match("aaa", "", "aba")); |
| 680 |
ast_test_validate(test, !ast_strings_match("aaa", "=", "aba")); |
| 681 |
ast_test_validate(test, ast_strings_match("aaa", "!=", "aba")); |
| 682 |
|
| 683 |
ast_test_validate(test, ast_strings_match("aaa", "<=", "aba")); |
| 684 |
ast_test_validate(test, ast_strings_match("aaa", "<=", "aaa")); |
| 685 |
ast_test_validate(test, !ast_strings_match("aaa", "<", "aaa")); |
| 686 |
|
| 687 |
ast_test_validate(test, !ast_strings_match("aaa", ">=", "aba")); |
| 688 |
ast_test_validate(test, ast_strings_match("aaa", ">=", "aaa")); |
| 689 |
ast_test_validate(test, !ast_strings_match("aaa", ">", "aaa")); |
| 690 |
|
| 691 |
ast_test_validate(test, !ast_strings_match("aaa", "=", "aa")); |
| 692 |
ast_test_validate(test, ast_strings_match("aaa", ">", "aa")); |
| 693 |
ast_test_validate(test, !ast_strings_match("aaa", "<", "aa")); |
| 694 |
|
| 695 |
ast_test_validate(test, ast_strings_match("1", "=", "1")); |
| 696 |
ast_test_validate(test, !ast_strings_match("1", "!=", "1")); |
| 697 |
ast_test_validate(test, !ast_strings_match("2", "=", "1")); |
| 698 |
ast_test_validate(test, ast_strings_match("2", ">", "1")); |
| 699 |
ast_test_validate(test, ast_strings_match("2", ">=", "1")); |
| 700 |
ast_test_validate(test, ast_strings_match("2", ">", "1.9888")); |
| 701 |
ast_test_validate(test, ast_strings_match("2.9", ">", "1")); |
| 702 |
ast_test_validate(test, ast_strings_match("2", ">", "1")); |
| 703 |
ast_test_validate(test, ast_strings_match("2.999", "<", "3")); |
| 704 |
ast_test_validate(test, ast_strings_match("2", ">", "#")); |
| 705 |
|
| 706 |
ast_test_validate(test, ast_strings_match("abcccc", "like", "%a%c")); |
| 707 |
ast_test_validate(test, !ast_strings_match("abcccx", "like", "%a%c")); |
| 708 |
ast_test_validate(test, ast_strings_match("abcccc", "regex", "a[bc]+c")); |
| 709 |
ast_test_validate(test, !ast_strings_match("abcccx", "regex", "^a[bxdfgtc]+c$")); |
| 710 |
|
| 711 |
ast_test_validate(test, !ast_strings_match("neener-93joe", "LIKE", "%blah-%")); |
| 712 |
ast_test_validate(test, ast_strings_match("blah-93joe", "LIKE", "%blah-%")); |
| 713 |
|
| 714 |
ast_test_validate(test, !ast_strings_match("abcccx", "regex", NULL)); |
| 715 |
ast_test_validate(test, !ast_strings_match("abcccx", NULL, NULL)); |
| 716 |
ast_test_validate(test, !ast_strings_match(NULL, "regex", NULL)); |
| 717 |
ast_test_validate(test, !ast_strings_match(NULL, NULL, "abc")); |
| 718 |
ast_test_validate(test, !ast_strings_match(NULL, NULL, NULL)); |
| 719 |
|
| 720 |
|
| 721 |
ast_test_validate(test, !ast_strings_match("123456789c1", NULL, "123456789c2")); |
| 722 |
|
| 723 |
return AST_TEST_PASS; |
| 724 |
} |
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
static const char *str_appender(struct ast_str**buf, char *a) |
| 730 |
{ |
| 731 |
ast_str_append(buf, 0, "<%s>", a); |
| 732 |
return ast_str_buffer(*buf); |
| 733 |
} |
| 734 |
|
| 735 |
AST_TEST_DEFINE(temp_strings) |
| 736 |
{ |
| 737 |
char *return_buffer = ast_malloc(128); |
| 738 |
switch (cmd) { |
| 739 |
case TEST_INIT: |
| 740 |
info->name = "temp_strings"; |
| 741 |
info->category = "/main/strings/"; |
| 742 |
info->summary = "Test ast_str_temp_buffer"; |
| 743 |
info->description = "Test ast_str_temp_buffer"; |
| 744 |
return AST_TEST_NOT_RUN; |
| 745 |
case TEST_EXECUTE: |
| 746 |
break; |
| 747 |
} |
| 748 |
|
| 749 |
snprintf(return_buffer, 128, "%s %s %s %s %s", |
| 750 |
ast_str_tmp(12, str_appender(&STR_TMP, "str1")), |
| 751 |
ast_str_tmp(12, str_appender(&STR_TMP, "str2")), |
| 752 |
ast_str_tmp(12, str_appender(&STR_TMP, "B")), |
| 753 |
"ccccccccccccc", |
| 754 |
ast_str_tmp(12, str_appender(&STR_TMP, "ww")) |
| 755 |
); |
| 756 |
|
| 757 |
ast_test_validate(test, ast_strings_match(return_buffer, "=", "<str1> <str2> <B> ccccccccccccc <ww>")); |
| 758 |
|
| 759 |
ast_free(return_buffer); |
| 760 |
return AST_TEST_PASS; |
| 761 |
} |
| 762 |
|
| 763 |
AST_TEST_DEFINE(in_delimited_string) |
| 764 |
{ |
| 765 |
switch (cmd) { |
| 766 |
case TEST_INIT: |
| 767 |
info->name = "in_delimited_string"; |
| 768 |
info->category = "/main/strings/"; |
| 769 |
info->summary = "Test ast_in_delimited_string"; |
| 770 |
info->description = info->summary; |
| 771 |
return AST_TEST_NOT_RUN; |
| 772 |
case TEST_EXECUTE: |
| 773 |
break; |
| 774 |
} |
| 775 |
|
| 776 |
|
| 777 |
ast_test_validate(test, ast_in_delimited_string("a", "a,b", ',')); |
| 778 |
ast_test_validate(test, ast_in_delimited_string("b", "a,b", ',')); |
| 779 |
|
| 780 |
ast_test_validate(test, !ast_in_delimited_string("c", "a,b", ',')); |
| 781 |
ast_test_validate(test, !ast_in_delimited_string("aa", "a,b", ',')); |
| 782 |
ast_test_validate(test, !ast_in_delimited_string("bb", "a,b", ',')); |
| 783 |
ast_test_validate(test, !ast_in_delimited_string("a,", "a,b", ',')); |
| 784 |
ast_test_validate(test, !ast_in_delimited_string(",b", "a,b", ',')); |
| 785 |
ast_test_validate(test, !ast_in_delimited_string("a,b", "a,b", ',')); |
| 786 |
|
| 787 |
|
| 788 |
ast_test_validate(test, !ast_in_delimited_string("a", "a,b", '#')); |
| 789 |
ast_test_validate(test, !ast_in_delimited_string("b", "a,b", '#')); |
| 790 |
|
| 791 |
ast_test_validate(test, !ast_in_delimited_string("c", "a,b", '#')); |
| 792 |
ast_test_validate(test, !ast_in_delimited_string("aa", "a,b", '#')); |
| 793 |
ast_test_validate(test, !ast_in_delimited_string("bb", "a,b", '#')); |
| 794 |
ast_test_validate(test, !ast_in_delimited_string("a,", "a,b", '#')); |
| 795 |
ast_test_validate(test, !ast_in_delimited_string(",b", "a,b", '#')); |
| 796 |
|
| 797 |
ast_test_validate(test, ast_in_delimited_string("a,b", "a,b", '#')); |
| 798 |
|
| 799 |
|
| 800 |
ast_test_validate(test, ast_in_delimited_string("abc", "abc,def", ',')); |
| 801 |
ast_test_validate(test, ast_in_delimited_string("def", "abc,def", ',')); |
| 802 |
|
| 803 |
ast_test_validate(test, !ast_in_delimited_string("a", "abc,def", ',')); |
| 804 |
ast_test_validate(test, !ast_in_delimited_string("b", "abc,def", ',')); |
| 805 |
ast_test_validate(test, !ast_in_delimited_string("c", "abc,def", ',')); |
| 806 |
|
| 807 |
ast_test_validate(test, !ast_in_delimited_string("d", "abc,def", ',')); |
| 808 |
ast_test_validate(test, !ast_in_delimited_string("e", "abc,def", ',')); |
| 809 |
ast_test_validate(test, !ast_in_delimited_string("f", "abc,def", ',')); |
| 810 |
|
| 811 |
ast_test_validate(test, !ast_in_delimited_string("abc,", "abc,def", ',')); |
| 812 |
ast_test_validate(test, !ast_in_delimited_string(",def", "abc,def", ',')); |
| 813 |
ast_test_validate(test, !ast_in_delimited_string("abc,def", "abc,def", ',')); |
| 814 |
|
| 815 |
|
| 816 |
ast_test_validate(test, ast_in_delimited_string("abc", "abcdef,abc", ',')); |
| 817 |
ast_test_validate(test, ast_in_delimited_string("abcdef", "abcdef,abc", ',')); |
| 818 |
|
| 819 |
ast_test_validate(test, !ast_in_delimited_string("abc", "abcdef,def", ',')); |
| 820 |
ast_test_validate(test, !ast_in_delimited_string("def", "abcdef,abc", ',')); |
| 821 |
ast_test_validate(test, !ast_in_delimited_string("def", "abcdefghi,abc", ',')); |
| 822 |
|
| 823 |
|
| 824 |
ast_test_validate(test, !ast_in_delimited_string(NULL, "abc,def", ',')); |
| 825 |
|
| 826 |
ast_test_validate(test, ast_in_delimited_string("abc", ",abc,def", ',')); |
| 827 |
ast_test_validate(test, ast_in_delimited_string("abc", "abc,def,", ',')); |
| 828 |
ast_test_validate(test, ast_in_delimited_string("abc", "abc,,def,", ',')); |
| 829 |
ast_test_validate(test, ast_in_delimited_string("def", "abc,,def", ',')); |
| 830 |
ast_test_validate(test, ast_in_delimited_string("def", ",abc,,def,", ',')); |
| 831 |
|
| 832 |
ast_test_validate(test, ast_in_delimited_string("", ",abc,def", ',')); |
| 833 |
ast_test_validate(test, ast_in_delimited_string("", "abc,def,", ',')); |
| 834 |
ast_test_validate(test, ast_in_delimited_string("", "abc,,def,", ',')); |
| 835 |
ast_test_validate(test, !ast_in_delimited_string("", "abc,def", ',')); |
| 836 |
|
| 837 |
|
| 838 |
ast_test_validate(test, ast_in_delimited_string("abc", "abc,def,ghi", ',')); |
| 839 |
ast_test_validate(test, ast_in_delimited_string("def", "abc,def,ghi", ',')); |
| 840 |
ast_test_validate(test, ast_in_delimited_string("ghi", "abc,def,ghi", ',')); |
| 841 |
|
| 842 |
ast_test_validate(test, !ast_in_delimited_string("a", "abc,def,ghi", ',')); |
| 843 |
ast_test_validate(test, !ast_in_delimited_string("d", "abc,def,ghi", ',')); |
| 844 |
ast_test_validate(test, !ast_in_delimited_string("g", "abc,def,ghi", ',')); |
| 845 |
|
| 846 |
ast_test_validate(test, !ast_in_delimited_string("ab", "abc,def,ghi", ',')); |
| 847 |
ast_test_validate(test, !ast_in_delimited_string("de", "abc,def,ghi", ',')); |
| 848 |
ast_test_validate(test, !ast_in_delimited_string("gh", "abc,def,ghi", ',')); |
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
ast_test_validate(test, ast_in_delimited_string("abc", " abc", ',')); |
| 853 |
ast_test_validate(test, ast_in_delimited_string("abc", " abc, def", ',')); |
| 854 |
ast_test_validate(test, ast_in_delimited_string("def", " abc, def", ',')); |
| 855 |
ast_test_validate(test, ast_in_delimited_string("abc", " abc, def, ghi", ',')); |
| 856 |
ast_test_validate(test, ast_in_delimited_string("def", " abc, def, ghi", ',')); |
| 857 |
ast_test_validate(test, ast_in_delimited_string("ghi", " abc, def, ghi", ',')); |
| 858 |
|
| 859 |
ast_test_validate(test, ast_in_delimited_string("abc", " abc", ',')); |
| 860 |
ast_test_validate(test, ast_in_delimited_string("abc", " abc, def", ',')); |
| 861 |
ast_test_validate(test, ast_in_delimited_string("def", " abc, def", ',')); |
| 862 |
ast_test_validate(test, ast_in_delimited_string("abc", " abc, def, ghi", ',')); |
| 863 |
ast_test_validate(test, ast_in_delimited_string("def", " abc, def, ghi", ',')); |
| 864 |
ast_test_validate(test, ast_in_delimited_string("ghi", " abc, def, ghi", ',')); |
| 865 |
|
| 866 |
|
| 867 |
ast_test_validate(test, ast_in_delimited_string("abc", " abc", ' ')); |
| 868 |
ast_test_validate(test, ast_in_delimited_string("abc", " abc def", ' ')); |
| 869 |
ast_test_validate(test, ast_in_delimited_string("def", " abc def", ' ')); |
| 870 |
ast_test_validate(test, ast_in_delimited_string("abc", " abc def ghi", ' ')); |
| 871 |
ast_test_validate(test, ast_in_delimited_string("def", " abc def ghi", ' ')); |
| 872 |
ast_test_validate(test, ast_in_delimited_string("ghi", " abc def ghi", ' ')); |
| 873 |
|
| 874 |
return AST_TEST_PASS; |
| 875 |
} |
| 876 |
|
| 877 |
static int unload_module(void) |
| 878 |
{ |
| 879 |
AST_TEST_UNREGISTER(str_test); |
| 880 |
AST_TEST_UNREGISTER(begins_with_test); |
| 881 |
AST_TEST_UNREGISTER(ends_with_test); |
| 882 |
AST_TEST_UNREGISTER(strsep_test); |
| 883 |
AST_TEST_UNREGISTER(strsep_quoted_test); |
| 884 |
AST_TEST_UNREGISTER(escape_semicolons_test); |
| 885 |
AST_TEST_UNREGISTER(escape_test); |
| 886 |
AST_TEST_UNREGISTER(strings_match); |
| 887 |
AST_TEST_UNREGISTER(temp_strings); |
| 888 |
AST_TEST_UNREGISTER(in_delimited_string); |
| 889 |
return 0; |
| 890 |
} |
| 891 |
|
| 892 |
static int load_module(void) |
| 893 |
{ |
| 894 |
AST_TEST_REGISTER(str_test); |
| 895 |
AST_TEST_REGISTER(begins_with_test); |
| 896 |
AST_TEST_REGISTER(ends_with_test); |
| 897 |
AST_TEST_REGISTER(strsep_test); |
| 898 |
AST_TEST_REGISTER(strsep_quoted_test); |
| 899 |
AST_TEST_REGISTER(escape_semicolons_test); |
| 900 |
AST_TEST_REGISTER(escape_test); |
| 901 |
AST_TEST_REGISTER(strings_match); |
| 902 |
AST_TEST_REGISTER(temp_strings); |
| 903 |
AST_TEST_REGISTER(in_delimited_string); |
| 904 |
return AST_MODULE_LOAD_SUCCESS; |
| 905 |
} |
| 906 |
|
| 907 |
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dynamic string test module"); |