Author: mmichelson Date: Tue Mar 24 14:25:22 2015 New Revision: 433337 URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=433337 Log: Factor off-nominal tests into their own function.
Off-nominal NAPTR tests all follow the same pattern, so instead of repeating the same thing, I can now make it simpler to write new tests. Just specify the invalid records and be done. Modified: team/group/dns_naptr/tests/test_dns_naptr.c Modified: team/group/dns_naptr/tests/test_dns_naptr.c URL: http://svnview.digium.com/svn/asterisk/team/group/dns_naptr/tests/test_dns_naptr.c?view=diff&rev=433337&r1=433336&r2=433337 ============================================================================== --- team/group/dns_naptr/tests/test_dns_naptr.c (original) +++ team/group/dns_naptr/tests/test_dns_naptr.c Tue Mar 24 14:25:22 2015 @@ -332,9 +332,49 @@ return res; } +static enum ast_test_result_state off_nominal_test(struct ast_test *test, struct naptr_record *records, int num_records) +{ + RAII_VAR(struct ast_dns_result *, result, NULL, ast_dns_result_free); + enum ast_test_result_state res = AST_TEST_PASS; + const struct ast_dns_record *record; + + test_records = records; + num_test_records = num_records; + memset(ans_buffer, 0, sizeof(ans_buffer)); + + ast_dns_resolver_register(&naptr_resolver); + + if (ast_dns_resolve("goose.feathers", ns_t_naptr, ns_c_in, &result)) { + ast_test_status_update(test, "Failed to perform DNS resolution, despite using valid inputs\n"); + res = AST_TEST_FAIL; + goto cleanup; + } + + if (!result) { + ast_test_status_update(test, "Synchronous DNS resolution failed to set a result\n"); + res = AST_TEST_FAIL; + goto cleanup; + } + + record = ast_dns_result_get_records(result); + if (record) { + ast_test_status_update(test, "DNS resolution returned records when it was not expected to\n"); + res = AST_TEST_FAIL; + goto cleanup; + } + +cleanup: + ast_dns_resolver_unregister(&naptr_resolver); + + test_records = NULL; + num_test_records = 0; + memset(ans_buffer, 0, sizeof(ans_buffer)); + + return res; +} + AST_TEST_DEFINE(naptr_resolve_off_nominal_length) { - RAII_VAR(struct ast_dns_result *, result, NULL, ast_dns_result_free); struct naptr_record records[] = { { 100, 100, {255, "A"}, {4, "BLAH"}, {15, "!.*!horse.mane!"}, "" }, { 100, 100, {0, "A"}, {4, "BLAH"}, {15, "!.*!horse.mane!"}, "" }, @@ -345,8 +385,6 @@ { 100, 100, {255, "A"}, {255, "BLAH"}, {255, "!.*!horse.mane!"}, "" }, { 100, 100, {0, "A"}, {2, "BLAH"}, {3, "!.*!horse.mane!"}, "" }, }; - enum ast_test_result_state res = AST_TEST_PASS; - const struct ast_dns_record *record; switch (cmd) { case TEST_INIT: @@ -362,45 +400,11 @@ break; } - test_records = records; - num_test_records = ARRAY_LEN(records); - memset(ans_buffer, 0, sizeof(ans_buffer)); - - ast_dns_resolver_register(&naptr_resolver); - - if (ast_dns_resolve("goose.feathers", ns_t_naptr, ns_c_in, &result)) { - ast_test_status_update(test, "Failed to perform DNS resolution, despite using valid inputs\n"); - res = AST_TEST_FAIL; - goto cleanup; - } - - if (!result) { - ast_test_status_update(test, "Synchronous DNS resolution failed to set a result\n"); - res = AST_TEST_FAIL; - goto cleanup; - } - - record = ast_dns_result_get_records(result); - if (record) { - ast_test_status_update(test, "DNS resolution returned records when it was not expected to\n"); - res = AST_TEST_FAIL; - goto cleanup; - } - -cleanup: - - ast_dns_resolver_unregister(&naptr_resolver); - - test_records = NULL; - num_test_records = 0; - memset(ans_buffer, 0, sizeof(ans_buffer)); - - return res; + return off_nominal_test(test, records, ARRAY_LEN(records)); } AST_TEST_DEFINE(naptr_resolve_off_nominal_flags) { - RAII_VAR(struct ast_dns_result *, result, NULL, ast_dns_result_free); struct naptr_record records[] = { /* Non-alphanumeric flag */ { 100, 100, {1, "\x0a"}, {4, "BLAH"}, {15, "!.*!horse.mane!"}, ""}, @@ -420,8 +424,6 @@ { 100, 100, {2, "ps"}, {4, "BLAH"}, {15, "!.*!horse.mane!"}, ""}, { 100, 100, {2, "pu"}, {4, "BLAH"}, {15, "!.*!horse.mane!"}, ""}, }; - enum ast_test_result_state res = AST_TEST_PASS; - const struct ast_dns_record *record; switch (cmd) { case TEST_INIT: @@ -437,40 +439,7 @@ break; } - test_records = records; - num_test_records = ARRAY_LEN(records); - memset(ans_buffer, 0, sizeof(ans_buffer)); - - ast_dns_resolver_register(&naptr_resolver); - - if (ast_dns_resolve("goose.feathers", ns_t_naptr, ns_c_in, &result)) { - ast_test_status_update(test, "Failed to perform DNS resolution, despite using valid inputs\n"); - res = AST_TEST_FAIL; - goto cleanup; - } - - if (!result) { - ast_test_status_update(test, "Synchronous DNS resolution failed to set a result\n"); - res = AST_TEST_FAIL; - goto cleanup; - } - - record = ast_dns_result_get_records(result); - if (record) { - ast_test_status_update(test, "DNS resolution returned records when it was not expected to\n"); - res = AST_TEST_FAIL; - goto cleanup; - } - -cleanup: - - ast_dns_resolver_unregister(&naptr_resolver); - - test_records = NULL; - num_test_records = 0; - memset(ans_buffer, 0, sizeof(ans_buffer)); - - return res; + return off_nominal_test(test, records, ARRAY_LEN(records)); } static int unload_module(void) -- _____________________________________________________________________ -- 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