res_rtp_asterisk.c: Fix rtp source address learning for broken clients
[asterisk/asterisk.git] / tests / test_utils.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2010, Digium, Inc.
5  *
6  * David Vossel <dvossel@digium.com>
7  * Russell Bryant <russell@digium.com>
8  *
9  * See http://www.asterisk.org for more information about
10  * the Asterisk project. Please do not directly contact
11  * any of the maintainers of this project for assistance;
12  * the project provides a web site, mailing lists and IRC
13  * channels for your use.
14  *
15  * This program is free software, distributed under the terms of
16  * the GNU General Public License Version 2. See the LICENSE file
17  * at the top of the source tree.
18  */
19
20 /*!
21  * \file
22  * \brief Unit Tests for utils API
23  *
24  * \author David Vossel <dvossel@digium.com>
25  * \author Russell Bryant <russell@digium.com>
26  */
27
28 /*** MODULEINFO
29         <depend>TEST_FRAMEWORK</depend>
30         <use type="module">res_agi</use>
31         <use type="module">res_crypto</use>
32         <support_level>core</support_level>
33  ***/
34
35 #include "asterisk.h"
36
37 #include "asterisk/utils.h"
38 #include "asterisk/test.h"
39 #include "asterisk/crypto.h"
40 #include "asterisk/adsi.h"
41 #include "asterisk/agi.h"
42 #include "asterisk/channel.h"
43 #include "asterisk/module.h"
44
45 #include <sys/stat.h>
46
47 AST_TEST_DEFINE(uri_encode_decode_test)
48 {
49         int res = AST_TEST_PASS;
50         const char *in = "abcdefghijklmnopurstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 ~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/";
51         char out[256] = { 0 };
52         char small[4] = { 0 };
53         const struct ast_flags none = {0};
54         int i = 0;
55
56         static struct {
57                 const char *spec_str;
58                 struct ast_flags spec;
59
60                 char *buf;
61                 size_t buflen;
62
63                 const char *input;
64                 const char *output;
65                 const char *decoded_output;
66         } tests[5];
67
68 #define INIT_ENCODE_TEST(s, buffer, in, out, dec_out) do { \
69         if (i < ARRAY_LEN(tests)) { \
70                 tests[i].spec_str = #s; \
71                 tests[i].spec = s; \
72                 tests[i].buf = buffer; \
73                 tests[i].buflen = sizeof(buffer); \
74                 tests[i].input = in; \
75                 tests[i].output = out; \
76                 tests[i].decoded_output = dec_out; \
77                 i++; \
78         } else { \
79                         ast_test_status_update(test, "error: 'tests' array too small\n"); \
80                         res = AST_TEST_FAIL; \
81         } \
82         } while (0)
83
84         INIT_ENCODE_TEST(ast_uri_http, out, in,
85                 "abcdefghijklmnopurstuvwxyz%20ABCDEFGHIJKLMNOPQRSTUVWXYZ%201234567890%20~%60!%40%23%24%25%5E%26*()_-%2B%3D%7B%5B%7D%5D%7C%5C%3A%3B%22'%3C%2C%3E.%3F%2F", in);
86         INIT_ENCODE_TEST(ast_uri_http_legacy, out, in,
87                 "abcdefghijklmnopurstuvwxyz+ABCDEFGHIJKLMNOPQRSTUVWXYZ+1234567890+~%60!%40%23%24%25%5E%26*()_-%2B%3D%7B%5B%7D%5D%7C%5C%3A%3B%22'%3C%2C%3E.%3F%2F", in);
88         INIT_ENCODE_TEST(ast_uri_sip_user, out, in,
89                 "abcdefghijklmnopurstuvwxyz%20ABCDEFGHIJKLMNOPQRSTUVWXYZ%201234567890%20~%60!%40%23$%25%5E&*()_-+=%7B%5B%7D%5D%7C%5C%3A;%22'%3C,%3E.?/", in);
90         INIT_ENCODE_TEST(none, small, in, "%61", "a");
91         INIT_ENCODE_TEST(ast_uri_http, small, in, "abc", "abc");
92
93         switch (cmd) {
94         case TEST_INIT:
95                 info->name = "uri_encode_decode_test";
96                 info->category = "/main/utils/";
97                 info->summary = "encode and decode a hex escaped string";
98                 info->description = "encode a string, verify encoded string matches what we expect.  Decode the encoded string, verify decoded string matches the original string.";
99                 return AST_TEST_NOT_RUN;
100         case TEST_EXECUTE:
101                 break;
102         }
103
104         for (i = 0; i < ARRAY_LEN(tests); i++) {
105                 ast_uri_encode(tests[i].input, tests[i].buf, tests[i].buflen, tests[i].spec);
106                 if (strcmp(tests[i].output, tests[i].buf)) {
107                         ast_test_status_update(test, "encoding with %s did not match expected output, FAIL\n", tests[i].spec_str);
108                         ast_test_status_update(test, "original: %s\n", tests[i].input);
109                         ast_test_status_update(test, "expected: %s\n", tests[i].output);
110                         ast_test_status_update(test, "result: %s\n", tests[i].buf);
111                         res = AST_TEST_FAIL;
112                         continue;
113                 }
114
115                 ast_uri_decode(tests[i].buf, tests[i].spec);
116                 if (strcmp(tests[i].decoded_output, tests[i].buf)) {
117                         ast_test_status_update(test, "decoding with %s did not match the original input (or expected decoded output)\n", tests[i].spec_str);
118                         ast_test_status_update(test, "original: %s\n", tests[i].input);
119                         ast_test_status_update(test, "expected: %s\n", tests[i].decoded_output);
120                         ast_test_status_update(test, "decoded: %s\n", tests[i].buf);
121                         res = AST_TEST_FAIL;
122                 }
123         }
124
125         return res;
126 }
127
128 AST_TEST_DEFINE(quoted_escape_test)
129 {
130         int res = AST_TEST_PASS;
131         const char *in = "a\"bcdefg\"hijkl\\mnopqrs tuv\twxyz";
132         char out[256] = { 0 };
133         char small[4] = { 0 };
134         int i;
135
136         static struct {
137                 char *buf;
138                 const size_t buflen;
139
140                 const char *output;
141         } tests[] = {
142                 {0, sizeof(out),
143                         "a\\\"bcdefg\\\"hijkl\\\\mnopqrs tuv\twxyz"},
144                 {0, sizeof(small),
145                         "a\\\""},
146         };
147
148         tests[0].buf = out;
149         tests[1].buf = small;
150
151         switch (cmd) {
152         case TEST_INIT:
153                 info->name = "quoted_escape_test";
154                 info->category = "/main/utils/";
155                 info->summary = "escape a quoted string";
156                 info->description = "Escape a string to be quoted and check the result.";
157                 return AST_TEST_NOT_RUN;
158         case TEST_EXECUTE:
159                 break;
160         }
161
162         for (i = 0; i < ARRAY_LEN(tests); i++) {
163                 ast_escape_quoted(in, tests[i].buf, tests[i].buflen);
164                 if (strcmp(tests[i].output, tests[i].buf)) {
165                         ast_test_status_update(test, "ESCAPED DOES NOT MATCH EXPECTED, FAIL\n");
166                         ast_test_status_update(test, "original: %s\n", in);
167                         ast_test_status_update(test, "expected: %s\n", tests[i].output);
168                         ast_test_status_update(test, "result: %s\n", tests[i].buf);
169                         res = AST_TEST_FAIL;
170                 }
171         }
172
173         return res;
174 }
175
176 AST_TEST_DEFINE(md5_test)
177 {
178         static const struct {
179                 const char *input;
180                 const char *expected_output;
181         } tests[] = {
182                 { "apples",                          "daeccf0ad3c1fc8c8015205c332f5b42" },
183                 { "bananas",                         "ec121ff80513ae58ed478d5c5787075b" },
184                 { "reallylongstringaboutgoatcheese", "0a2d9280d37e2e37545cfef6e7e4e890" },
185         };
186         enum ast_test_result_state res = AST_TEST_PASS;
187         int i;
188
189         switch (cmd) {
190         case TEST_INIT:
191                 info->name = "md5_test";
192                 info->category = "/main/utils/";
193                 info->summary = "MD5 test";
194                 info->description =
195                         "This test exercises MD5 calculations."
196                         "";
197                 return AST_TEST_NOT_RUN;
198         case TEST_EXECUTE:
199                 break;
200         }
201
202         ast_test_status_update(test, "Testing MD5 ...\n");
203
204         for (i = 0; i < ARRAY_LEN(tests); i++) {
205                 char md5_hash[33];
206                 ast_md5_hash(md5_hash, tests[i].input);
207                 if (strcasecmp(md5_hash, tests[i].expected_output)) {
208                         ast_test_status_update(test,
209                                         "input: '%s'  hash: '%s'  expected hash: '%s'\n",
210                                         tests[i].input, md5_hash, tests[i].expected_output);
211                         res = AST_TEST_FAIL;
212                 }
213         }
214
215         return res;
216 }
217
218 AST_TEST_DEFINE(sha1_test)
219 {
220         static const struct {
221                 const char *input;
222                 const char *expected_output;
223         } tests[] = {
224                 { "giraffe",
225                         "fac8f1a31d2998734d6a5253e49876b8e6a08239" },
226                 { "platypus",
227                         "1dfb21b7a4d35e90d943e3a16107ccbfabd064d5" },
228                 { "ParastratiosphecomyiaStratiosphecomyioides",
229                         "58af4e8438676f2bd3c4d8df9e00ee7fe06945bb" },
230         };
231         enum ast_test_result_state res = AST_TEST_PASS;
232         int i;
233
234         switch (cmd) {
235         case TEST_INIT:
236                 info->name = "sha1_test";
237                 info->category = "/main/utils/";
238                 info->summary = "SHA1 test";
239                 info->description =
240                         "This test exercises SHA1 calculations."
241                         "";
242                 return AST_TEST_NOT_RUN;
243         case TEST_EXECUTE:
244                 break;
245         }
246
247         ast_test_status_update(test, "Testing SHA1 ...\n");
248
249         for (i = 0; i < ARRAY_LEN(tests); i++) {
250                 char sha1_hash[64];
251                 ast_sha1_hash(sha1_hash, tests[i].input);
252                 if (strcasecmp(sha1_hash, tests[i].expected_output)) {
253                         ast_test_status_update(test,
254                                         "input: '%s'  hash: '%s'  expected hash: '%s'\n",
255                                         tests[i].input, sha1_hash, tests[i].expected_output);
256                         res = AST_TEST_FAIL;
257                 }
258         }
259
260         return res;
261 }
262
263 AST_TEST_DEFINE(base64_test)
264 {
265         static const struct {
266                 const char *input;
267                 const char *decoded;
268         } tests[] = {
269                 { "giraffe",
270                         "Z2lyYWZmZQ==" },
271                 { "platypus",
272                         "cGxhdHlwdXM=" },
273                 { "ParastratiosphecomyiaStratiosphecomyioides",
274                         "UGFyYXN0cmF0aW9zcGhlY29teWlhU3RyYXRpb3NwaGVjb215aW9pZGVz" },
275         };
276         int i;
277         enum ast_test_result_state res = AST_TEST_PASS;
278
279         switch (cmd) {
280         case TEST_INIT:
281                 info->name = "base64_test";
282                 info->category = "/main/utils/";
283                 info->summary = "base64 test";
284                 info->description = "This test exercises the base64 conversions.";
285                 return AST_TEST_NOT_RUN;
286         case TEST_EXECUTE:
287                 break;
288         }
289
290
291         for (i = 0; i < ARRAY_LEN(tests); i++) {
292                 char tmp[64];
293                 ast_base64encode(tmp, (unsigned char *)tests[i].input, strlen(tests[i].input), sizeof(tmp));
294                 if (strcasecmp(tmp, tests[i].decoded)) {
295                         ast_test_status_update(test,
296                                         "input: '%s'  base64 output: '%s'  expected base64 output: '%s'\n",
297                                         tests[i].input, tmp, tests[i].decoded);
298                         res = AST_TEST_FAIL;
299                 }
300
301                 memset(tmp, 0, sizeof(tmp));
302                 ast_base64decode((unsigned char *) tmp, tests[i].decoded, (sizeof(tmp) - 1));
303                 if (strcasecmp(tmp, tests[i].input)) {
304                         ast_test_status_update(test,
305                                         "base64 input: '%s'  output: '%s'  expected output: '%s'\n",
306                                         tests[i].decoded, tmp, tests[i].input);
307                         res = AST_TEST_FAIL;
308                 }
309         }
310
311         return res;
312 }
313
314 AST_TEST_DEFINE(crypto_loaded_test)
315 {
316         switch (cmd) {
317         case TEST_INIT:
318                 info->name = "crypto_loaded_test";
319                 info->category = "/res/crypto/";
320                 info->summary = "Crypto loaded into memory";
321                 info->description = "Verifies whether the crypto functions overrode the stubs";
322                 return AST_TEST_NOT_RUN;
323         case TEST_EXECUTE:
324                 break;
325         }
326
327 #if 0 /* Not defined on Solaris */
328         ast_test_status_update(test,
329                                "address of __stub__ast_crypto_loaded is %p\n",
330                                __stub__ast_crypto_loaded);
331 #ifndef HAVE_ATTRIBUTE_weak_import
332         ast_test_status_update(test,
333                                "address of __ref__ast_crypto_loaded is %p\n",
334                                __ref__ast_crypto_loaded);
335 #endif
336         ast_test_status_update(test,
337                                "pointer to ast_crypto_loaded is %p\n",
338                                ast_crypto_loaded);
339 #endif
340
341         return ast_crypto_loaded() ? AST_TEST_PASS : AST_TEST_FAIL;
342 }
343
344 AST_TEST_DEFINE(adsi_loaded_test)
345 {
346         struct ast_channel *c;
347         int res;
348         switch (cmd) {
349         case TEST_INIT:
350                 info->name = "adsi_loaded_test";
351                 info->category = "/res/adsi/";
352                 info->summary = "ADSI loaded into memory";
353                 info->description = "Verifies whether the adsi functions overrode the stubs";
354                 return AST_TEST_NOT_RUN;
355         case TEST_EXECUTE:
356                 break;
357         }
358
359         if (!(c = ast_dummy_channel_alloc())) {
360                 return AST_TEST_FAIL;
361         }
362         ast_channel_adsicpe_set(c, AST_ADSI_AVAILABLE);
363         res = ast_adsi_available(c) ? AST_TEST_PASS : AST_TEST_FAIL;
364         c = ast_channel_unref(c);
365         return res;
366 }
367
368 static int handle_noop(struct ast_channel *chan, AGI *agi, int arg, const char * const argv[])
369 {
370         ast_agi_send(agi->fd, chan, "200 result=0\n");
371         return RESULT_SUCCESS;
372 }
373
374 AST_TEST_DEFINE(agi_loaded_test)
375 {
376         int res = AST_TEST_PASS;
377         struct agi_command noop_command =
378                 { { "testnoop", NULL }, handle_noop, NULL, NULL, 0 };
379
380         switch (cmd) {
381         case TEST_INIT:
382                 info->name = "agi_loaded_test";
383                 info->category = "/res/agi/";
384                 info->summary = "AGI loaded into memory";
385                 info->description = "Verifies whether the agi functions overrode the stubs";
386                 return AST_TEST_NOT_RUN;
387         case TEST_EXECUTE:
388                 break;
389         }
390
391 #if 0
392         ast_test_status_update(test,
393                                "address of __stub__ast_agi_register is %p\n",
394                                __stub__ast_agi_register);
395 #ifndef HAVE_ATTRIBUTE_weak_import
396         ast_test_status_update(test,
397                                "address of __ref__ast_agi_register is %p\n",
398                                __ref__ast_agi_register);
399 #endif
400         ast_test_status_update(test,
401                                "pointer to ast_agi_register is %p\n",
402                                ast_agi_register);
403 #endif
404
405         if (ast_agi_register(ast_module_info->self, &noop_command) == AST_OPTIONAL_API_UNAVAILABLE) {
406                 ast_test_status_update(test, "Unable to register testnoop command, because res_agi is not loaded.\n");
407                 return AST_TEST_FAIL;
408         }
409
410 #ifndef HAVE_NULLSAFE_PRINTF
411         /* Test for condition without actually crashing Asterisk */
412         if (noop_command.usage == NULL) {
413                 ast_test_status_update(test, "AGI testnoop usage was not updated properly.\n");
414                 res = AST_TEST_FAIL;
415         }
416         if (noop_command.syntax == NULL) {
417                 ast_test_status_update(test, "AGI testnoop syntax was not updated properly.\n");
418                 res = AST_TEST_FAIL;
419         }
420 #endif
421
422         ast_agi_unregister(ast_module_info->self, &noop_command);
423         return res;
424 }
425
426 AST_TEST_DEFINE(safe_mkdir_test)
427 {
428         char base_path[] = "/tmp/safe_mkdir.XXXXXX";
429         char path[80] = {};
430         int res;
431         struct stat actual;
432
433         switch (cmd) {
434         case TEST_INIT:
435                 info->name = __func__;
436                 info->category = "/main/utils/";
437                 info->summary = "Safe mkdir test";
438                 info->description =
439                         "This test ensures that ast_safe_mkdir does what it is "
440                         "supposed to";
441                 return AST_TEST_NOT_RUN;
442         case TEST_EXECUTE:
443                 break;
444         }
445
446         if (mkdtemp(base_path) == NULL) {
447                 ast_test_status_update(test, "Failed to create tmpdir for test\n");
448                 return AST_TEST_FAIL;
449         }
450
451         snprintf(path, sizeof(path), "%s/should_work", base_path);
452         res = ast_safe_mkdir(base_path, path, 0777);
453         ast_test_validate(test, 0 == res);
454         res = stat(path, &actual);
455         ast_test_validate(test, 0 == res);
456         ast_test_validate(test, S_ISDIR(actual.st_mode));
457
458         snprintf(path, sizeof(path), "%s/should/also/work", base_path);
459         res = ast_safe_mkdir(base_path, path, 0777);
460         ast_test_validate(test, 0 == res);
461         res = stat(path, &actual);
462         ast_test_validate(test, 0 == res);
463         ast_test_validate(test, S_ISDIR(actual.st_mode));
464
465         snprintf(path, sizeof(path), "%s/even/this/../should/work", base_path);
466         res = ast_safe_mkdir(base_path, path, 0777);
467         ast_test_validate(test, 0 == res);
468         snprintf(path, sizeof(path), "%s/even/should/work", base_path);
469         res = stat(path, &actual);
470         ast_test_validate(test, 0 == res);
471         ast_test_validate(test, S_ISDIR(actual.st_mode));
472
473         snprintf(path, sizeof(path),
474                 "%s/surprisingly/this/should//////////////////work", base_path);
475         res = ast_safe_mkdir(base_path, path, 0777);
476         ast_test_validate(test, 0 == res);
477         snprintf(path, sizeof(path),
478                 "%s/surprisingly/this/should/work", base_path);
479         res = stat(path, &actual);
480         ast_test_validate(test, 0 == res);
481         ast_test_validate(test, S_ISDIR(actual.st_mode));
482
483         snprintf(path, sizeof(path), "/should_not_work");
484         res = ast_safe_mkdir(base_path, path, 0777);
485         ast_test_validate(test, 0 != res);
486         ast_test_validate(test, EPERM == errno);
487         res = stat(path, &actual);
488         ast_test_validate(test, 0 != res);
489         ast_test_validate(test, ENOENT == errno);
490
491         snprintf(path, sizeof(path), "%s/../nor_should_this", base_path);
492         res = ast_safe_mkdir(base_path, path, 0777);
493         ast_test_validate(test, 0 != res);
494         ast_test_validate(test, EPERM == errno);
495         strncpy(path, "/tmp/nor_should_this", sizeof(path));
496         res = stat(path, &actual);
497         ast_test_validate(test, 0 != res);
498         ast_test_validate(test, ENOENT == errno);
499
500         snprintf(path, sizeof(path),
501                 "%s/this/especially/should/not/../../../../../work", base_path);
502         res = ast_safe_mkdir(base_path, path, 0777);
503         ast_test_validate(test, 0 != res);
504         ast_test_validate(test, EPERM == errno);
505         strncpy(path, "/tmp/work", sizeof(path));
506         res = stat(path, &actual);
507         ast_test_validate(test, 0 != res);
508         ast_test_validate(test, ENOENT == errno);
509
510         return AST_TEST_PASS;
511 }
512
513 AST_TEST_DEFINE(crypt_test)
514 {
515         RAII_VAR(char *, password_crypted, NULL, ast_free);
516         RAII_VAR(char *, blank_crypted, NULL, ast_free);
517         const char *password = "Passw0rd";
518         const char *not_a_password = "not-a-password";
519
520         switch (cmd) {
521         case TEST_INIT:
522                 info->name = "crypt_test";
523                 info->category = "/main/utils/";
524                 info->summary = "Test ast_crypt wrappers";
525                 info->description = "Verifies that the ast_crypt wrappers work as expected.";
526                 return AST_TEST_NOT_RUN;
527         case TEST_EXECUTE:
528                 break;
529         }
530
531         password_crypted = ast_crypt_encrypt(password);
532         ast_test_validate(test, NULL != password_crypted);
533         ast_test_validate(test, 0 != strcmp(password, password_crypted));
534         ast_test_validate(test, ast_crypt_validate(password, password_crypted));
535         ast_test_validate(test,
536                 !ast_crypt_validate(not_a_password, password_crypted));
537
538         blank_crypted = ast_crypt_encrypt("");
539         ast_test_validate(test, NULL != blank_crypted);
540         ast_test_validate(test, 0 != strcmp(blank_crypted, ""));
541         ast_test_validate(test, ast_crypt_validate("", blank_crypted));
542         ast_test_validate(test,
543                 !ast_crypt_validate(not_a_password, blank_crypted));
544
545         return AST_TEST_PASS;
546 }
547
548
549 struct quote_set {
550         char *input;
551         char *output;
552 };
553
554 AST_TEST_DEFINE(quote_mutation)
555 {
556         char escaped[64];
557         static const struct quote_set escape_sets[] = {
558                 {"\"string\"", "\\\"string\\\""},
559                 {"\"string", "\\\"string"},
560                 {"string\"", "string\\\""},
561                 {"string", "string"},
562                 {"str\"ing", "str\\\"ing"},
563                 {"\"", "\\\""},
564                 {"\\\"", "\\\\\\\""},
565         };
566         int i;
567
568         switch (cmd) {
569         case TEST_INIT:
570                 info->name = "quote_mutation";
571                 info->category = "/main/utils/";
572                 info->summary = "Test mutation of quotes in strings";
573                 info->description =
574                         "This tests escaping and unescaping of quotes in strings to "
575                         "verify that the original string is recovered.";
576                 return AST_TEST_NOT_RUN;
577         case TEST_EXECUTE:
578                 break;
579         }
580
581         for (i = 0; i < ARRAY_LEN(escape_sets); i++) {
582                 ast_escape_quoted(escape_sets[i].input, escaped, sizeof(escaped));
583
584                 if (strcmp(escaped, escape_sets[i].output)) {
585                         ast_test_status_update(test,
586                                 "Expected escaped string '%s' instead of '%s'\n",
587                                 escape_sets[i].output, escaped);
588                         return AST_TEST_FAIL;
589                 }
590
591                 ast_unescape_quoted(escaped);
592                 if (strcmp(escaped, escape_sets[i].input)) {
593                         ast_test_status_update(test,
594                                 "Expected unescaped string '%s' instead of '%s'\n",
595                                 escape_sets[i].input, escaped);
596                         return AST_TEST_FAIL;
597                 }
598         }
599
600         return AST_TEST_PASS;
601 }
602
603 AST_TEST_DEFINE(quote_unescaping)
604 {
605         static const struct quote_set escape_sets[] = {
606                 {"\"string\"", "\"string\""},
607                 {"\\\"string\"", "\"string\""},
608                 {"\"string\\\"", "\"string\""},
609                 {"str\\ing", "string"},
610                 {"string\\", "string"},
611                 {"\\string", "string"},
612         };
613         int i;
614
615         switch (cmd) {
616         case TEST_INIT:
617                 info->name = "quote_unescaping";
618                 info->category = "/main/utils/";
619                 info->summary = "Test unescaping of off-nominal strings";
620                 info->description =
621                         "This tests unescaping of strings which contain a mix of "
622                         "escaped and unescaped sequences.";
623                 return AST_TEST_NOT_RUN;
624         case TEST_EXECUTE:
625                 break;
626         }
627
628         for (i = 0; i < ARRAY_LEN(escape_sets); i++) {
629                 RAII_VAR(char *, escaped, ast_strdup(escape_sets[i].input), ast_free);
630
631                 ast_unescape_quoted(escaped);
632                 if (strcmp(escaped, escape_sets[i].output)) {
633                         ast_test_status_update(test,
634                                 "Expected unescaped string '%s' instead of '%s'\n",
635                                 escape_sets[i].output, escaped);
636                         return AST_TEST_FAIL;
637                 }
638         }
639
640         return AST_TEST_PASS;
641 }
642
643 static int unload_module(void)
644 {
645         AST_TEST_UNREGISTER(uri_encode_decode_test);
646         AST_TEST_UNREGISTER(quoted_escape_test);
647         AST_TEST_UNREGISTER(md5_test);
648         AST_TEST_UNREGISTER(sha1_test);
649         AST_TEST_UNREGISTER(base64_test);
650         AST_TEST_UNREGISTER(crypto_loaded_test);
651         AST_TEST_UNREGISTER(adsi_loaded_test);
652         AST_TEST_UNREGISTER(agi_loaded_test);
653         AST_TEST_UNREGISTER(safe_mkdir_test);
654         AST_TEST_UNREGISTER(crypt_test);
655         AST_TEST_UNREGISTER(quote_mutation);
656         AST_TEST_UNREGISTER(quote_unescaping);
657         return 0;
658 }
659
660 static int load_module(void)
661 {
662         AST_TEST_REGISTER(uri_encode_decode_test);
663         AST_TEST_REGISTER(quoted_escape_test);
664         AST_TEST_REGISTER(md5_test);
665         AST_TEST_REGISTER(sha1_test);
666         AST_TEST_REGISTER(base64_test);
667         AST_TEST_REGISTER(crypto_loaded_test);
668         AST_TEST_REGISTER(adsi_loaded_test);
669         AST_TEST_REGISTER(agi_loaded_test);
670         AST_TEST_REGISTER(safe_mkdir_test);
671         AST_TEST_REGISTER(crypt_test);
672         AST_TEST_REGISTER(quote_mutation);
673         AST_TEST_REGISTER(quote_unescaping);
674         return AST_MODULE_LOAD_SUCCESS;
675 }
676
677 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Utils test module");