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