[svn-commits] mjordan: branch mjordan/12-messaging r418443 - in /team/mjordan/12-messaging:...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat Jul 12 16:50:42 CDT 2014


Author: mjordan
Date: Sat Jul 12 16:50:36 2014
New Revision: 418443

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=418443
Log:
Add a unit test for ast_msg_send

Modified:
    team/mjordan/12-messaging/main/message.c
    team/mjordan/12-messaging/res/res_pjsip_messaging.c
    team/mjordan/12-messaging/tests/test_message.c

Modified: team/mjordan/12-messaging/main/message.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-messaging/main/message.c?view=diff&rev=418443&r1=418442&r2=418443
==============================================================================
--- team/mjordan/12-messaging/main/message.c (original)
+++ team/mjordan/12-messaging/main/message.c Sat Jul 12 16:50:36 2014
@@ -862,6 +862,11 @@
 	for (i = 0; i < AST_VECTOR_SIZE(&msg_handlers); i++) {
 		const struct ast_msg_handler *handler = AST_VECTOR_GET(&msg_handlers, i);
 
+		if (!handler->has_destination(msg)) {
+			ast_debug(5, "Handler %s doesn't want message, moving on\n", handler->name);
+			continue;
+		}
+
 		ast_debug(5, "Dispatching message to %s handler", handler->name);
 		res &= handler->handle_msg(msg);
 	}

Modified: team/mjordan/12-messaging/res/res_pjsip_messaging.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-messaging/res/res_pjsip_messaging.c?view=diff&rev=418443&r1=418442&r2=418443
==============================================================================
--- team/mjordan/12-messaging/res/res_pjsip_messaging.c (original)
+++ team/mjordan/12-messaging/res/res_pjsip_messaging.c Sat Jul 12 16:50:36 2014
@@ -475,7 +475,6 @@
 
 	/* endpoint name */
 	res |= ast_msg_set_tech(msg, "%s", "PJSIP");
-	ast_log(LOG_ERROR, "@@@@ endpoint is: %s\n", ast_sorcery_object_get_id(endpt));
 	res |= ast_msg_set_endpoint(msg, "%s", ast_sorcery_object_get_id(endpt));
 	if (endpt->id.self.name.valid) {
 		res |= ast_msg_set_var(msg, "PJSIP_ENDPOINT", endpt->id.self.name.str);

Modified: team/mjordan/12-messaging/tests/test_message.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-messaging/tests/test_message.c?view=diff&rev=418443&r1=418442&r2=418443
==============================================================================
--- team/mjordan/12-messaging/tests/test_message.c (original)
+++ team/mjordan/12-messaging/tests/test_message.c Sat Jul 12 16:50:36 2014
@@ -169,8 +169,12 @@
 	return 0;
 }
 
+static int message_received;
+
 static int test_msg_send(const struct ast_msg *msg, const char *to, const char *from)
 {
+	message_received = 1;
+
 	return 0;
 }
 
@@ -427,7 +431,7 @@
 	/* Test setting/getting endpoint */
 	result = ast_msg_set_endpoint(msg, "%s", "terminus");
 	ast_test_validate(test, result == 0);
-	actual = ast_msg_get_tech(msg);
+	actual = ast_msg_get_endpoint(msg);
 	ast_test_validate(test, !strcmp(actual, "terminus"));
 
 	/* Test setting/getting non-outbound variable */
@@ -733,10 +737,52 @@
 	return AST_TEST_PASS;
 }
 
+AST_TEST_DEFINE(test_message_msg_send)
+{
+	RAII_VAR(struct ast_msg *, msg, NULL, ast_msg_safe_destroy);
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = __func__;
+		info->category = TEST_CATEGORY;
+		info->summary = "Test message routing";
+		info->description =
+			"Test that a message can be routed if it has\n"
+			"a valid handler\n";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	ast_test_validate(test, ast_msg_tech_register(&test_msg_tech) == 0);
+	ast_test_validate(test, ast_msg_handler_register(&test_msg_handler) == 0);
+
+	msg = ast_msg_alloc();
+	ast_test_validate(test, msg != NULL);
+
+	ast_msg_set_to(msg, "foo");
+	ast_msg_set_context(msg, TEST_CONTEXT);
+	ast_msg_set_exten(msg, NULL);
+	ast_test_validate(test, ast_msg_has_destination(msg) == 1);
+
+	if (!ast_msg_send(msg, "testmsg:foo", "blah")) {
+		msg = NULL;
+	} else {
+		ast_test_status_update(test, "Failed to send message\n");
+		ast_test_set_result(test, AST_TEST_FAIL);
+	}
+
+	ast_test_validate(test, ast_msg_handler_unregister(&test_msg_handler) == 0);
+	ast_test_validate(test, ast_msg_tech_unregister(&test_msg_tech) == 0);
+
+	return AST_TEST_PASS;
+}
+
 static int test_init_cb(struct ast_test_info *info, struct ast_test *test)
 {
 	received_user_events = 0;
 	handler_received_message = 0;
+	message_received = 0;
 
 	AST_VECTOR_INIT(&expected_user_event_fields, DEFAULT_EXPECTED_EVENTS);
 	AST_VECTOR_INIT(&bad_headers, DEFAULT_EXPECTED_EVENTS);
@@ -780,6 +826,7 @@
 	AST_TEST_UNREGISTER(test_message_queue_both_nominal);
 	AST_TEST_UNREGISTER(test_message_has_destination_dialplan);
 	AST_TEST_UNREGISTER(test_message_has_destination_handler);
+	AST_TEST_UNREGISTER(test_message_msg_send);
 
 	if (test_message_context) {
 		ast_context_destroy(test_message_context, AST_MODULE);
@@ -833,6 +880,7 @@
 	AST_TEST_REGISTER(test_message_queue_both_nominal);
 	AST_TEST_REGISTER(test_message_has_destination_dialplan);
 	AST_TEST_REGISTER(test_message_has_destination_handler);
+	AST_TEST_REGISTER(test_message_msg_send);
 
 	create_test_dialplan();
 




More information about the svn-commits mailing list