Author: file
Date: Tue Mar 24 12:57:27 2015
New Revision: 433331

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=433331
Log:
Add a test that confirms zero-weight SRV records are last.

Modified:
    team/group/dns_srv/tests/test_dns_srv.c

Modified: team/group/dns_srv/tests/test_dns_srv.c
URL: 
http://svnview.digium.com/svn/asterisk/team/group/dns_srv/tests/test_dns_srv.c?view=diff&rev=433331&r1=433330&r2=433331
==============================================================================
--- team/group/dns_srv/tests/test_dns_srv.c (original)
+++ team/group/dns_srv/tests/test_dns_srv.c Tue Mar 24 12:57:27 2015
@@ -380,10 +380,93 @@
        return res;
 }
 
+AST_TEST_DEFINE(srv_resolve_same_priority_zero_weight)
+{
+       RAII_VAR(struct ast_dns_result *, result, NULL, ast_dns_result_free);
+       const struct ast_dns_record *record;
+       struct srv_record records[] = {
+               { 10, 0, 5060, "tacos" },
+               { 10, 10, 5060, "goose.down" },
+       };
+
+       int srv_record_order[] = { 1, 0};
+       enum ast_test_result_state res = AST_TEST_PASS;
+       int i;
+
+       switch (cmd) {
+       case TEST_INIT:
+               info->name = "srv_resolve_same_priority_zero_weight";
+               info->category = "/main/dns/srv/";
+               info->summary = "Test an SRV lookup which returns two records 
with same priority but different weights";
+               info->description = "This test defines two SRV records with 
same priority but different weights and\n"
+                       "performs a resolution of the domain to which they 
belong. The test ensures that\n"
+                       "the record with zero weight comes last and that all 
fields of the SRV\n"
+                       "records are parsed correctly\n";
+               return AST_TEST_NOT_RUN;
+       case TEST_EXECUTE:
+               break;
+       }
+
+       test_records = records;
+       num_test_records = ARRAY_LEN(records);
+       memset(ans_buffer, 0, sizeof(ans_buffer));
+
+       ast_dns_resolver_register(&srv_resolver);
+
+       if (ast_dns_resolve("goose.feathers", ns_t_srv, ns_c_in, &result)) {
+               ast_test_status_update(test, "DNS resolution failed\n");
+               res = AST_TEST_FAIL;
+               goto cleanup;
+       }
+
+       if (!result) {
+               ast_test_status_update(test, "DNS resolution returned no 
result\n");
+               res = AST_TEST_FAIL;
+               goto cleanup;
+       }
+
+       i = 0;
+       for (record = ast_dns_result_get_records(result); record; record = 
ast_dns_record_get_next(record)) {
+               if (ast_dns_srv_get_priority(record) != 
records[srv_record_order[i]].priority) {
+                       ast_test_status_update(test, "Unexpected priority in 
returned SRV record\n");
+                       res = AST_TEST_FAIL;
+               }
+               if (ast_dns_srv_get_weight(record) != 
records[srv_record_order[i]].weight) {
+                       ast_test_status_update(test, "Unexpected weight in 
returned SRV record\n");
+                       res = AST_TEST_FAIL;
+               }
+               if (ast_dns_srv_get_port(record) != 
records[srv_record_order[i]].port) {
+                       ast_test_status_update(test, "Unexpected port in 
returned SRV record\n");
+                       res = AST_TEST_FAIL;
+               }
+               if (strcmp(ast_dns_srv_get_host(record), 
records[srv_record_order[i]].host)) {
+                       ast_test_status_update(test, "Unexpected host in 
returned SRV record\n");
+                       res = AST_TEST_FAIL;
+               }
+               ++i;
+       }
+
+       if (i != ARRAY_LEN(records)) {
+               ast_test_status_update(test, "Unexpected number of records 
returned in SRV lookup\n");
+               res = AST_TEST_FAIL;
+       }
+
+cleanup:
+
+       ast_dns_resolver_unregister(&srv_resolver);
+
+       test_records = NULL;
+       num_test_records = 0;
+       memset(ans_buffer, 0, sizeof(ans_buffer));
+
+       return res;
+}
+
 static int unload_module(void)
 {
        AST_TEST_UNREGISTER(srv_resolve_single_record);
        AST_TEST_UNREGISTER(srv_resolve_sort_priority);
+       AST_TEST_UNREGISTER(srv_resolve_same_priority_zero_weight);
 
        return 0;
 }
@@ -392,6 +475,7 @@
 {
        AST_TEST_REGISTER(srv_resolve_single_record);
        AST_TEST_REGISTER(srv_resolve_sort_priority);
+       AST_TEST_REGISTER(srv_resolve_same_priority_zero_weight);
 
        return AST_MODULE_LOAD_SUCCESS;
 }


-- 
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

svn-commits mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/svn-commits

Reply via email to