[asterisk-commits] dlee: branch dlee/endpoints r387476 - /team/dlee/endpoints/tests/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 2 13:47:54 CDT 2013


Author: dlee
Date: Thu May  2 13:47:52 2013
New Revision: 387476

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=387476
Log:
Test cleanups

Modified:
    team/dlee/endpoints/tests/test_stasis_endpoints.c

Modified: team/dlee/endpoints/tests/test_stasis_endpoints.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/tests/test_stasis_endpoints.c?view=diff&rev=387476&r1=387475&r2=387476
==============================================================================
--- team/dlee/endpoints/tests/test_stasis_endpoints.c (original)
+++ team/dlee/endpoints/tests/test_stasis_endpoints.c Thu May  2 13:47:52 2013
@@ -53,6 +53,7 @@
 	ast_hangup(chan);
 }
 
+/*! \brief Message matcher looking for cache update messages */
 static int cache_update(struct stasis_message *msg, const void *data) {
 	struct stasis_cache_update *update;
 	struct ast_endpoint_snapshot *snapshot;
@@ -75,7 +76,61 @@
 	return 0 == strcmp(name, snapshot->resource);
 }
 
-AST_TEST_DEFINE(state_changes)
+AST_TEST_DEFINE(state_change)
+{
+	RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown);
+	RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_hangup);
+	RAII_VAR(struct stasis_message_sink *, sink, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_subscription *, sub, NULL, stasis_unsubscribe);
+	struct stasis_message *msg;
+	struct stasis_message_type *type;
+	struct ast_endpoint_snapshot *actual_snapshot;
+	int actual_count;
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = __func__;
+		info->category = test_category;
+		info->summary = "Test endpoint updates as its state changes";
+		info->description =
+			"Test endpoint updates as its state changes";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	uut = ast_endpoint_create("TEST", __func__);
+	ast_test_validate(test, NULL != uut);
+
+	sink = stasis_message_sink_create();
+	ast_test_validate(test, NULL != sink);
+
+	sub = stasis_subscribe(ast_endpoint_topic(uut),
+		stasis_message_sink_cb(), sink);
+	ast_test_validate(test, NULL != sub);
+
+	ast_endpoint_set_state(uut, AST_ENDPOINT_OFFLINE);
+	actual_count = stasis_message_sink_wait_for_count(sink, 1,
+		STASIS_SINK_DEFAULT_WAIT);
+	msg = sink->messages[0];
+	type = stasis_message_type(msg);
+	ast_test_validate(test, ast_endpoint_snapshot_type() == type);
+	actual_snapshot = stasis_message_data(msg);
+	ast_test_validate(test, AST_ENDPOINT_OFFLINE == actual_snapshot->state);
+
+	ast_endpoint_set_max_channels(uut, 8675309);
+	actual_count = stasis_message_sink_wait_for_count(sink, 2,
+		STASIS_SINK_DEFAULT_WAIT);
+	msg = sink->messages[1];
+	type = stasis_message_type(msg);
+	ast_test_validate(test, ast_endpoint_snapshot_type() == type);
+	actual_snapshot = stasis_message_data(msg);
+	ast_test_validate(test, 8675309 == actual_snapshot->max_channels);
+
+	return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(cache_clear)
 {
 	RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown);
 	RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_hangup);
@@ -91,8 +146,8 @@
 	case TEST_INIT:
 		info->name = __func__;
 		info->category = test_category;
-		info->summary = "Test endpoint setters";
-		info->description = "Test endpoint setters";
+		info->summary = "Test endpoint state change messages";
+		info->description = "Test endpoint state change messages";
 		return AST_TEST_NOT_RUN;
 	case TEST_EXECUTE:
 		break;
@@ -151,7 +206,7 @@
 	return AST_TEST_PASS;
 }
 
-AST_TEST_DEFINE(cache_clear)
+AST_TEST_DEFINE(channel_messages)
 {
 	RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown);
 	RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_hangup);
@@ -166,8 +221,9 @@
 	case TEST_INIT:
 		info->name = __func__;
 		info->category = test_category;
-		info->summary = "Test endpoint setters";
-		info->description = "Test endpoint setters";
+		info->summary = "Test channel messages on an endpoint topic";
+		info->description =
+			"Test channel messages on an endpoint topic";
 		return AST_TEST_NOT_RUN;
 	case TEST_EXECUTE:
 		break;
@@ -183,59 +239,6 @@
 		stasis_message_sink_cb(), sink);
 	ast_test_validate(test, NULL != sub);
 
-	ast_endpoint_set_state(uut, AST_ENDPOINT_OFFLINE);
-	actual_count = stasis_message_sink_wait_for_count(sink, 1,
-		STASIS_SINK_DEFAULT_WAIT);
-	msg = sink->messages[0];
-	type = stasis_message_type(msg);
-	ast_test_validate(test, ast_endpoint_snapshot_type() == type);
-	actual_snapshot = stasis_message_data(msg);
-	ast_test_validate(test, AST_ENDPOINT_OFFLINE == actual_snapshot->state);
-
-	ast_endpoint_set_max_channels(uut, 8675309);
-	actual_count = stasis_message_sink_wait_for_count(sink, 2,
-		STASIS_SINK_DEFAULT_WAIT);
-	msg = sink->messages[1];
-	type = stasis_message_type(msg);
-	ast_test_validate(test, ast_endpoint_snapshot_type() == type);
-	actual_snapshot = stasis_message_data(msg);
-	ast_test_validate(test, 8675309 == actual_snapshot->max_channels);
-
-	return AST_TEST_PASS;
-}
-
-AST_TEST_DEFINE(channel_messages)
-{
-	RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown);
-	RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_hangup);
-	RAII_VAR(struct stasis_message_sink *, sink, NULL, ao2_cleanup);
-	RAII_VAR(struct stasis_subscription *, sub, NULL, stasis_unsubscribe);
-	struct stasis_message *msg;
-	struct stasis_message_type *type;
-	struct ast_endpoint_snapshot *actual_snapshot;
-	int actual_count;
-
-	switch (cmd) {
-	case TEST_INIT:
-		info->name = __func__;
-		info->category = test_category;
-		info->summary = "Test endpoint setters";
-		info->description = "Test endpoint setters";
-		return AST_TEST_NOT_RUN;
-	case TEST_EXECUTE:
-		break;
-	}
-
-	uut = ast_endpoint_create("TEST", __func__);
-	ast_test_validate(test, NULL != uut);
-
-	sink = stasis_message_sink_create();
-	ast_test_validate(test, NULL != sink);
-
-	sub = stasis_subscribe(ast_endpoint_topic(uut),
-		stasis_message_sink_cb(), sink);
-	ast_test_validate(test, NULL != sub);
-
 	chan = ast_channel_alloc(0, AST_STATE_DOWN, "100", __func__, "100",
 		"100", "default", NULL, 0, "TEST/test_res");
 	ast_test_validate(test, NULL != chan);
@@ -283,7 +286,7 @@
 static int unload_module(void)
 {
 	AST_TEST_UNREGISTER(state_changes);
-	AST_TEST_UNREGISTER(cache_clear);
+	AST_TEST_UNREGISTER(channel_cache_clear);
 	AST_TEST_UNREGISTER(channel_messages);
 	return 0;
 }
@@ -291,13 +294,13 @@
 static int load_module(void)
 {
 	AST_TEST_REGISTER(state_changes);
-	AST_TEST_REGISTER(cache_clear);
+	AST_TEST_REGISTER(channel_cache_clear);
 	AST_TEST_REGISTER(channel_messages);
 	return AST_MODULE_LOAD_SUCCESS;
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,
-	"Endpoint testing",
+	"Endpoint stasis-related testing",
 	.load = load_module,
 	.unload = unload_module,
 	.nonoptreq = "res_stasis_test",




More information about the asterisk-commits mailing list