[asterisk-commits] mmichelson: branch group/dns r432521 - /team/group/dns/tests/test_dns.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 6 11:08:44 CST 2015


Author: mmichelson
Date: Fri Mar  6 11:08:39 2015
New Revision: 432521

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=432521
Log:
Add a test for off-nominal synchronous resolution.


Modified:
    team/group/dns/tests/test_dns.c

Modified: team/group/dns/tests/test_dns.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns/tests/test_dns.c?view=diff&rev=432521&r1=432520&r2=432521
==============================================================================
--- team/group/dns/tests/test_dns.c (original)
+++ team/group/dns/tests/test_dns.c Fri Mar  6 11:08:39 2015
@@ -913,6 +913,53 @@
 	return res;
 }
 
+static int fail_resolve(struct ast_dns_query *query)
+{
+	return -1;
+}
+
+AST_TEST_DEFINE(resolver_resolve_sync_off_nominal)
+{
+	struct ast_dns_resolver terrible_resolver = {
+		.name = "Uwe Boll's Filmography",
+		.priority = 0,
+		.resolve = fail_resolve,
+		.cancel = stub_cancel,
+	};
+
+	struct ast_dns_result *result = NULL;
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "resolver_resolve_sync_off_nominal";
+		info->category = "/main/dns/";
+		info->summary = "Test off-nominal synchronous DNS resolution";
+		info->description =
+			"This test attempts to call into a resolver that fails to resolve\n";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	if (ast_dns_resolver_register(&terrible_resolver)) {
+		ast_test_status_update(test, "Failed to register the DNS resolver\n");
+		return AST_TEST_FAIL;
+	}
+
+	if (!ast_dns_resolve("asterisk.org", ns_t_a, ns_c_in, &result)) {
+		ast_test_status_update(test, "DNS resolution succeeded when we expected it not to\n");
+		return AST_TEST_FAIL;
+	}
+
+	if (result) {
+		ast_test_status_update(test, "Failed DNS resolution set the result to something non-NULL\n");
+		ast_dns_result_free(result);
+		return AST_TEST_FAIL;
+	}
+
+	return AST_TEST_PASS;
+}
+
 AST_TEST_DEFINE(resolver_resolve_async_cancel)
 {
 	RAII_VAR(struct async_resolution_data *, async_data, NULL, ao2_cleanup); 
@@ -1023,6 +1070,7 @@
 	AST_TEST_UNREGISTER(resolver_add_record);
 	AST_TEST_UNREGISTER(resolver_add_record_off_nominal);
 	AST_TEST_UNREGISTER(resolver_resolve_sync);
+	AST_TEST_UNREGISTER(resolver_resolve_sync_off_nominal);
 	AST_TEST_UNREGISTER(resolver_resolve_async);
 	AST_TEST_UNREGISTER(resolver_resolve_async_cancel);
 
@@ -1040,6 +1088,7 @@
 	AST_TEST_REGISTER(resolver_add_record);
 	AST_TEST_REGISTER(resolver_add_record_off_nominal);
 	AST_TEST_REGISTER(resolver_resolve_sync);
+	AST_TEST_REGISTER(resolver_resolve_sync_off_nominal);
 	AST_TEST_REGISTER(resolver_resolve_async);
 	AST_TEST_REGISTER(resolver_resolve_async_cancel);
 




More information about the asterisk-commits mailing list