Merge "Revert "app_voicemail: Remove need to subscribe to stasis""
[asterisk/asterisk.git] / tests / test_dns.c
index 13306ad..4c45c84 100644 (file)
@@ -62,7 +62,7 @@ AST_TEST_DEFINE(resolver_register_unregister)
                        "The test performs the following steps:\n"
                        "\t* Register a valid resolver.\n"
                        "\t* Unregister the resolver.\n"
-                       "If either step fails, the test fails\n";
+                       "If either step fails, the test fails";
                return AST_TEST_NOT_RUN;
        case TEST_EXECUTE:
                break;
@@ -114,7 +114,7 @@ AST_TEST_DEFINE(resolver_register_off_nominal)
                        "\t* Register a duplicate resolver\n"
                        "\t* Register a resolver without a name\n"
                        "\t* Register a resolver without a resolve() method\n"
-                       "\t* Register a resolver without a cancel() method\n";
+                       "\t* Register a resolver without a cancel() method";
                return AST_TEST_NOT_RUN;
        case TEST_EXECUTE:
                break;
@@ -174,7 +174,7 @@ AST_TEST_DEFINE(resolver_unregister_off_nominal)
                        "\t* Unregister a resolver that is not registered.\n"
                        "\t* Unregister a NULL pointer.\n"
                        "Because unregistering a resolver does not return an indicator of success, the best\n"
-                       "this test can do is verify that nothing blows up when this is attempted.\n";
+                       "this test can do is verify that nothing blows up when this is attempted.";
                return AST_TEST_NOT_RUN;
        case TEST_EXECUTE:
                break;
@@ -210,7 +210,7 @@ AST_TEST_DEFINE(resolver_data)
                        "\t* Ensure that setting resolver data does not result in an error.\n"
                        "\t* Ensure that retrieving the set resolver data returns the data we expect\n"
                        "\t* Ensure that setting new resolver data on the query does not result in an error\n"
-                       "\t* Ensure that retrieving the resolver data returns the new data that we set\n";
+                       "\t* Ensure that retrieving the resolver data returns the new data that we set";
                return AST_TEST_NOT_RUN;
        case TEST_EXECUTE:
                break;
@@ -304,10 +304,10 @@ AST_TEST_DEFINE(resolver_set_result)
                unsigned int bogus;
                unsigned int rcode;
        } results[] = {
-               { 0, 0, ns_r_noerror, },
-               { 0, 1, ns_r_noerror, },
-               { 1, 0, ns_r_noerror, },
-               { 0, 0, ns_r_nxdomain, },
+               { 0, 0, NOERROR, },
+               { 0, 1, NOERROR, },
+               { 1, 0, NOERROR, },
+               { 0, 0, NXDOMAIN, },
        };
        int i;
        enum ast_test_result_state res = AST_TEST_PASS;
@@ -361,13 +361,11 @@ AST_TEST_DEFINE(resolver_set_result_off_nominal)
        case TEST_INIT:
                info->name = "resolver_set_result_off_nominal";
                info->category = "/main/dns/";
-               info->summary = "Test setting off-nominal DNS results\n";
+               info->summary = "Test setting off-nominal DNS results";
                info->description =
                        "This test performs the following:\n"
                        "\t* Attempt to add a DNS result that is both bogus and secure\n"
-                       "\t* Attempt to add a DNS result that has no canonical name\n"
-                       "\t* Attempt to add a DNS result that has no answer\n"
-                       "\t* Attempt to add a DNS result with a zero answer size\n";
+                       "\t* Attempt to add a DNS result that has no canonical name";
                return AST_TEST_NOT_RUN;
        case TEST_EXECUTE:
                break;
@@ -375,7 +373,7 @@ AST_TEST_DEFINE(resolver_set_result_off_nominal)
 
        memset(&some_query, 0, sizeof(some_query));
 
-       if (!ast_dns_resolver_set_result(&some_query, 1, 1, ns_r_noerror, "asterisk.org",
+       if (!ast_dns_resolver_set_result(&some_query, 1, 1, NOERROR, "asterisk.org",
                                DNS_ANSWER, DNS_ANSWER_SIZE)) {
                ast_test_status_update(test, "Successfully added a result that was both secure and bogus\n");
                result = ast_dns_query_get_result(&some_query);
@@ -383,7 +381,7 @@ AST_TEST_DEFINE(resolver_set_result_off_nominal)
                return AST_TEST_FAIL;
        }
 
-       if (!ast_dns_resolver_set_result(&some_query, 0, 0, ns_r_noerror, NULL,
+       if (!ast_dns_resolver_set_result(&some_query, 0, 0, NOERROR, NULL,
                                DNS_ANSWER, DNS_ANSWER_SIZE)) {
                ast_test_status_update(test, "Successfully added result with no canonical name\n");
                result = ast_dns_query_get_result(&some_query);
@@ -391,22 +389,6 @@ AST_TEST_DEFINE(resolver_set_result_off_nominal)
                return AST_TEST_FAIL;
        }
 
-       if (!ast_dns_resolver_set_result(&some_query, 0, 0, ns_r_noerror, NULL,
-                               NULL, DNS_ANSWER_SIZE)) {
-               ast_test_status_update(test, "Successfully added result with no answer\n");
-               result = ast_dns_query_get_result(&some_query);
-               ast_dns_result_free(result);
-               return AST_TEST_FAIL;
-       }
-
-       if (!ast_dns_resolver_set_result(&some_query, 0, 0, ns_r_noerror, NULL,
-                               DNS_ANSWER, 0)) {
-               ast_test_status_update(test, "Successfully added result with answer size of zero\n");
-               result = ast_dns_query_get_result(&some_query);
-               ast_dns_result_free(result);
-               return AST_TEST_FAIL;
-       }
-
        return AST_TEST_PASS;
 }
 
@@ -458,8 +440,8 @@ AST_TEST_DEFINE(resolver_add_record)
                const size_t size;
                int visited;
        } records[] = {
-               { ns_t_a, ns_c_in, 12345, v4_buf, V4_BUFSIZE, 0, },
-               { ns_t_aaaa, ns_c_in, 12345, v6_buf, V6_BUFSIZE, 0, },
+               { T_A, C_IN, 12345, v4_buf, V4_BUFSIZE, 0, },
+               { T_AAAA, C_IN, 12345, v6_buf, V6_BUFSIZE, 0, },
        };
 
        int num_records_visited = 0;
@@ -474,7 +456,7 @@ AST_TEST_DEFINE(resolver_add_record)
                        "\t* Ensure a nominal A record can be added to a query result\n"
                        "\t* Ensures that the record can be retrieved\n"
                        "\t* Ensure that a second record can be added to the query result\n"
-                       "\t* Ensures that both records can be retrieved\n";
+                       "\t* Ensures that both records can be retrieved";
                return AST_TEST_NOT_RUN;
        case TEST_EXECUTE:
                break;
@@ -482,7 +464,7 @@ AST_TEST_DEFINE(resolver_add_record)
 
        memset(&some_query, 0, sizeof(some_query));
 
-       if (ast_dns_resolver_set_result(&some_query, 0, 0, ns_r_noerror, "asterisk.org",
+       if (ast_dns_resolver_set_result(&some_query, 0, 0, NOERROR, "asterisk.org",
                                DNS_ANSWER, DNS_ANSWER_SIZE)) {
                ast_test_status_update(test, "Unable to set result for DNS query\n");
                return AST_TEST_FAIL;
@@ -585,7 +567,7 @@ AST_TEST_DEFINE(resolver_add_record_off_nominal)
                        "\t* Ensure that an A record with invalid RR classes cannot be added to a query\n"
                        "\t* Ensure that an A record with invalid TTL cannot be added to a query\n"
                        "\t* Ensure that an A record with NULL data cannot be added to a query\n"
-                       "\t* Ensure that an A record with invalid length cannot be added to a query\n";
+                       "\t* Ensure that an A record with invalid length cannot be added to a query";
                return AST_TEST_NOT_RUN;
        case TEST_EXECUTE:
                break;
@@ -596,12 +578,12 @@ AST_TEST_DEFINE(resolver_add_record_off_nominal)
        inet_ntop(AF_INET, V4, v4_buf, V4_BUFSIZE);
 
        /* Add record before setting result */
-       if (!ast_dns_resolver_add_record(&some_query, ns_t_a, ns_c_in, 12345, v4_buf, V4_BUFSIZE)) {
+       if (!ast_dns_resolver_add_record(&some_query, T_A, C_IN, 12345, v4_buf, V4_BUFSIZE)) {
                ast_test_status_update(test, "Successfully added DNS record to query before setting a result\n");
                return AST_TEST_FAIL;
        }
 
-       if (ast_dns_resolver_set_result(&some_query, 0, 0, ns_r_noerror, "asterisk.org",
+       if (ast_dns_resolver_set_result(&some_query, 0, 0, NOERROR, "asterisk.org",
                                DNS_ANSWER, DNS_ANSWER_SIZE)) {
                ast_test_status_update(test, "Unable to set result for DNS query\n");
                return AST_TEST_FAIL;
@@ -611,41 +593,41 @@ AST_TEST_DEFINE(resolver_add_record_off_nominal)
        result = ast_dns_query_get_result(&some_query);
 
        /* Invalid RR types */
-       if (!ast_dns_resolver_add_record(&some_query, -1, ns_c_in, 12345, v4_buf, V4_BUFSIZE)) {
+       if (!ast_dns_resolver_add_record(&some_query, -1, C_IN, 12345, v4_buf, V4_BUFSIZE)) {
                ast_test_status_update(test, "Successfully added DNS record with negative RR type\n");
                return AST_TEST_FAIL;
        }
 
-       if (!ast_dns_resolver_add_record(&some_query, ns_t_max + 1, ns_c_in, 12345, v4_buf, V4_BUFSIZE)) {
+       if (!ast_dns_resolver_add_record(&some_query, 65536 + 1, C_IN, 12345, v4_buf, V4_BUFSIZE)) {
                ast_test_status_update(test, "Successfully added DNS record with too large RR type\n");
                return AST_TEST_FAIL;
        }
 
        /* Invalid RR classes */
-       if (!ast_dns_resolver_add_record(&some_query, ns_t_a, -1, 12345, v4_buf, V4_BUFSIZE)) {
+       if (!ast_dns_resolver_add_record(&some_query, T_A, -1, 12345, v4_buf, V4_BUFSIZE)) {
                ast_test_status_update(test, "Successfully added DNS record with negative RR class\n");
                return AST_TEST_FAIL;
        }
 
-       if (!ast_dns_resolver_add_record(&some_query, ns_t_a, ns_c_max + 1, 12345, v4_buf, V4_BUFSIZE)) {
+       if (!ast_dns_resolver_add_record(&some_query, T_A, 65536 + 1, 12345, v4_buf, V4_BUFSIZE)) {
                ast_test_status_update(test, "Successfully added DNS record with too large RR class\n");
                return AST_TEST_FAIL;
        }
 
        /* Invalid TTL */
-       if (!ast_dns_resolver_add_record(&some_query, ns_t_a, ns_c_in, -1, v4_buf, V4_BUFSIZE)) {
+       if (!ast_dns_resolver_add_record(&some_query, T_A, C_IN, -1, v4_buf, V4_BUFSIZE)) {
                ast_test_status_update(test, "Successfully added DNS record with negative TTL\n");
                return AST_TEST_FAIL;
        }
 
        /* No data */
-       if (!ast_dns_resolver_add_record(&some_query, ns_t_a, ns_c_in, 12345, NULL, 0)) {
+       if (!ast_dns_resolver_add_record(&some_query, T_A, C_IN, 12345, NULL, 0)) {
                ast_test_status_update(test, "Successfully added a DNS record with no data\n");
                return AST_TEST_FAIL;
        }
 
        /* Lie about the length */
-       if (!ast_dns_resolver_add_record(&some_query, ns_t_a, ns_c_in, 12345, v4_buf, 0)) {
+       if (!ast_dns_resolver_add_record(&some_query, T_A, C_IN, 12345, v4_buf, 0)) {
                ast_test_status_update(test, "Successfully added a DNS record with length zero\n");
                return AST_TEST_FAIL;
        }
@@ -694,7 +676,7 @@ static void *resolution_thread(void *dns_query)
        static const size_t V4_BUFSIZE = sizeof(struct in_addr);
        char v4_buf[V4_BUFSIZE];
 
-       clock_gettime(CLOCK_REALTIME, &timeout);
+       timeout = ast_tsnow();
        timeout.tv_sec += 5;
 
        ast_mutex_lock(&test_resolver_data.lock);
@@ -711,10 +693,10 @@ static void *resolution_thread(void *dns_query)
                return NULL;
        }
 
-       ast_dns_resolver_set_result(query, 0, 0, ns_r_noerror, "asterisk.org", DNS_ANSWER, DNS_ANSWER_SIZE);
+       ast_dns_resolver_set_result(query, 0, 0, NOERROR, "asterisk.org", DNS_ANSWER, DNS_ANSWER_SIZE);
 
        inet_pton(AF_INET, V4, v4_buf);
-       ast_dns_resolver_add_record(query, ns_t_a, ns_c_in, 12345, v4_buf, V4_BUFSIZE);
+       ast_dns_resolver_add_record(query, T_A, C_IN, 12345, v4_buf, V4_BUFSIZE);
 
        test_resolver_data.resolution_complete = 1;
        ast_dns_resolver_completed(query);
@@ -824,7 +806,7 @@ AST_TEST_DEFINE(resolver_resolve_sync)
 
        resolver_data_init();
 
-       if (ast_dns_resolve("asterisk.org", ns_t_a, ns_c_in, &result)) {
+       if (ast_dns_resolve("asterisk.org", T_A, C_IN, &result)) {
                ast_test_status_update(test, "Resolution of address failed\n");
                res = AST_TEST_FAIL;
                goto cleanup;
@@ -894,12 +876,12 @@ AST_TEST_DEFINE(resolver_resolve_sync_off_nominal)
                int rr_class;
                struct ast_dns_result **result;
        } resolves [] = {
-               { NULL,           ns_t_a,       ns_c_in,      &result },
-               { "asterisk.org", -1,           ns_c_in,      &result },
-               { "asterisk.org", ns_t_max + 1, ns_c_in,      &result },
-               { "asterisk.org", ns_t_a,       -1,           &result },
-               { "asterisk.org", ns_t_a,       ns_c_max + 1, &result },
-               { "asterisk.org", ns_t_a,       ns_c_in,      NULL },
+               { NULL,           T_A,       C_IN,      &result },
+               { "asterisk.org", -1,        C_IN,      &result },
+               { "asterisk.org", 65536 + 1, C_IN,      &result },
+               { "asterisk.org", T_A,       -1,        &result },
+               { "asterisk.org", T_A,       65536 + 1, &result },
+               { "asterisk.org", T_A,       C_IN,      NULL },
        };
 
        int i;
@@ -913,11 +895,11 @@ AST_TEST_DEFINE(resolver_resolve_sync_off_nominal)
                info->summary = "Test off-nominal synchronous DNS resolution";
                info->description =
                        "This test performs several off-nominal synchronous DNS resolutions:\n"
-                       "\t* Attempt resolution with NULL name\n",
-                       "\t* Attempt resolution with invalid RR type\n",
-                       "\t* Attempt resolution with invalid RR class\n",
-                       "\t* Attempt resolution with NULL result pointer\n",
-                       "\t* Attempt resolution with resolver that returns an error\n";
+                       "\t* Attempt resolution with NULL name\n"
+                       "\t* Attempt resolution with invalid RR type\n"
+                       "\t* Attempt resolution with invalid RR class\n"
+                       "\t* Attempt resolution with NULL result pointer\n"
+                       "\t* Attempt resolution with resolver that returns an error";
                return AST_TEST_NOT_RUN;
        case TEST_EXECUTE:
                break;
@@ -947,7 +929,7 @@ AST_TEST_DEFINE(resolver_resolve_sync_off_nominal)
                return AST_TEST_FAIL;
        }
 
-       if (!ast_dns_resolve("asterisk.org", ns_t_a, ns_c_in, &result)) {
+       if (!ast_dns_resolve("asterisk.org", T_A, C_IN, &result)) {
                ast_test_status_update(test, "DNS resolution succeeded when we expected it not to\n");
                ast_dns_resolver_unregister(&terrible_resolver);
                return AST_TEST_FAIL;
@@ -1070,7 +1052,7 @@ AST_TEST_DEFINE(resolver_resolve_async)
                goto cleanup;
        }
 
-       active = ast_dns_resolve_async("asterisk.org", ns_t_a, ns_c_in, async_callback, async_data);
+       active = ast_dns_resolve_async("asterisk.org", T_A, C_IN, async_callback, async_data);
        if (!active) {
                ast_test_status_update(test, "Asynchronous resolution of address failed\n");
                res = AST_TEST_FAIL;
@@ -1089,7 +1071,7 @@ AST_TEST_DEFINE(resolver_resolve_async)
                goto cleanup;
        }
 
-       clock_gettime(CLOCK_REALTIME, &timeout);
+       timeout = ast_tsnow();
        timeout.tv_sec += 10;
        ast_mutex_lock(&async_data->lock);
        while (!async_data->complete) {
@@ -1151,12 +1133,12 @@ AST_TEST_DEFINE(resolver_resolve_async_off_nominal)
                int rr_class;
                ast_dns_resolve_callback callback;
        } resolves [] = {
-               { NULL,           ns_t_a,       ns_c_in,      stub_callback },
-               { "asterisk.org", -1,           ns_c_in,      stub_callback },
-               { "asterisk.org", ns_t_max + 1, ns_c_in,      stub_callback },
-               { "asterisk.org", ns_t_a,       -1,           stub_callback },
-               { "asterisk.org", ns_t_a,       ns_c_max + 1, stub_callback },
-               { "asterisk.org", ns_t_a,       ns_c_in,      NULL },
+               { NULL,           T_A,       C_IN,      stub_callback },
+               { "asterisk.org", -1,        C_IN,      stub_callback },
+               { "asterisk.org", 65536 + 1, C_IN,      stub_callback },
+               { "asterisk.org", T_A,       -1,        stub_callback },
+               { "asterisk.org", T_A,       65536 + 1, stub_callback },
+               { "asterisk.org", T_A,       C_IN,      NULL },
        };
 
        struct ast_dns_query_active *active;
@@ -1170,11 +1152,11 @@ AST_TEST_DEFINE(resolver_resolve_async_off_nominal)
                info->summary = "Test off-nominal asynchronous DNS resolution";
                info->description =
                        "This test performs several off-nominal asynchronous DNS resolutions:\n"
-                       "\t* Attempt resolution with NULL name\n",
-                       "\t* Attempt resolution with invalid RR type\n",
-                       "\t* Attempt resolution with invalid RR class\n",
-                       "\t* Attempt resolution with NULL callback pointer\n",
-                       "\t* Attempt resolution with resolver that returns an error\n";
+                       "\t* Attempt resolution with NULL name\n"
+                       "\t* Attempt resolution with invalid RR type\n"
+                       "\t* Attempt resolution with invalid RR class\n"
+                       "\t* Attempt resolution with NULL callback pointer\n"
+                       "\t* Attempt resolution with resolver that returns an error";
                return AST_TEST_NOT_RUN;
        case TEST_EXECUTE:
                break;
@@ -1202,7 +1184,7 @@ AST_TEST_DEFINE(resolver_resolve_async_off_nominal)
                return AST_TEST_FAIL;
        }
 
-       active = ast_dns_resolve_async("asterisk.org", ns_t_a, ns_c_in, stub_callback, NULL);
+       active = ast_dns_resolve_async("asterisk.org", T_A, C_IN, stub_callback, NULL);
 
        ast_dns_resolver_unregister(&terrible_resolver);
 
@@ -1232,7 +1214,7 @@ AST_TEST_DEFINE(resolver_resolve_async_cancel)
                        "This test performs an asynchronous DNS resolution of a domain and then cancels\n"
                        "the resolution. The goal of this test is to ensure that the cancel() callback of\n"
                        "the resolver is called and that it properly interrupts the resolution such that no\n"
-                       "records are returned.\n";
+                       "records are returned.";
                return AST_TEST_NOT_RUN;
        case TEST_EXECUTE:
                break;
@@ -1252,7 +1234,7 @@ AST_TEST_DEFINE(resolver_resolve_async_cancel)
                goto cleanup;
        }
 
-       active = ast_dns_resolve_async("asterisk.org", ns_t_a, ns_c_in, async_callback, async_data);
+       active = ast_dns_resolve_async("asterisk.org", T_A, C_IN, async_callback, async_data);
        if (!active) {
                ast_test_status_update(test, "Asynchronous resolution of address failed\n");
                res = AST_TEST_FAIL;
@@ -1279,7 +1261,7 @@ AST_TEST_DEFINE(resolver_resolve_async_cancel)
                goto cleanup;
        }
 
-       clock_gettime(CLOCK_REALTIME, &timeout);
+       timeout = ast_tsnow();
        timeout.tv_sec += 10;
        ast_mutex_lock(&async_data->lock);
        while (!async_data->complete) {