[asterisk-commits] kmoore: branch kmoore/cel_transfers r393564 - /team/kmoore/cel_transfers/tests/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 3 13:38:38 CDT 2013


Author: kmoore
Date: Wed Jul  3 13:38:36 2013
New Revision: 393564

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=393564
Log:
Remove some commented code and add a blind transfer unit test

Modified:
    team/kmoore/cel_transfers/tests/test_cel.c

Modified: team/kmoore/cel_transfers/tests/test_cel.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/cel_transfers/tests/test_cel.c?view=diff&rev=393564&r1=393563&r2=393564
==============================================================================
--- team/kmoore/cel_transfers/tests/test_cel.c (original)
+++ team/kmoore/cel_transfers/tests/test_cel.c Wed Jul  3 13:38:36 2013
@@ -93,28 +93,24 @@
 /*! \brief Create a \ref test_cel_chan_tech for Alice. */
 #define CREATE_ALICE_CHANNEL(channel_var, caller_id) do { \
 	(channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, (caller_id)->id.number.str, (caller_id)->id.name.str, "100", "100", "default", NULL, 0, CHANNEL_TECH_NAME "/Alice"); \
-	/*ast_channel_set_caller((channel_var), (caller_id), NULL);*/ \
 	APPEND_EVENT(channel_var, AST_CEL_CHANNEL_START, NULL, NULL, NULL); \
 	} while (0)
 
 /*! \brief Create a \ref test_cel_chan_tech for Bob. */
 #define CREATE_BOB_CHANNEL(channel_var, caller_id) do { \
 	(channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, (caller_id)->id.number.str, (caller_id)->id.name.str, "200", "200", "default", NULL, 0, CHANNEL_TECH_NAME "/Bob"); \
-	/*ast_channel_set_caller((channel_var), (caller_id), NULL);*/ \
 	APPEND_EVENT(channel_var, AST_CEL_CHANNEL_START, NULL, NULL, NULL); \
 	} while (0)
 
 /*! \brief Create a \ref test_cel_chan_tech for Charlie. */
 #define CREATE_CHARLIE_CHANNEL(channel_var, caller_id) do { \
 	(channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, (caller_id)->id.number.str, (caller_id)->id.name.str, "300", "300", "default", NULL, 0, CHANNEL_TECH_NAME "/Charlie"); \
-	/*ast_channel_set_caller((channel_var), (caller_id), NULL);*/ \
 	APPEND_EVENT(channel_var, AST_CEL_CHANNEL_START, NULL, NULL, NULL); \
 	} while (0)
 
 /*! \brief Create a \ref test_cel_chan_tech for Charlie. */
 #define CREATE_DAVID_CHANNEL(channel_var, caller_id) do { \
 	(channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, (caller_id)->id.number.str, (caller_id)->id.name.str, "400", "400", "default", NULL, 0, CHANNEL_TECH_NAME "/David"); \
-	/*ast_channel_set_caller((channel_var), (caller_id), NULL);*/ \
 	APPEND_EVENT(channel_var, AST_CEL_CHANNEL_START, NULL, NULL, NULL); \
 	} while (0)
 
@@ -998,6 +994,60 @@
 	HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "16,,");
 	HANGUP_CHANNEL(chan_charlie, AST_CAUSE_NORMAL, "16,,ANSWER");
 	HANGUP_CHANNEL(chan_david, AST_CAUSE_NORMAL, "16,,");
+
+	return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(test_cel_blind_transfer)
+{
+	RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
+	RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
+	RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_str *, extra, ast_str_create(32), ast_free);
+	struct ast_party_caller alice_caller = ALICE_CALLERID;
+	struct ast_party_caller bob_caller = BOB_CALLERID;
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = __func__;
+		info->category = TEST_CATEGORY;
+		info->summary = "Test blind transfers to an extension";
+		info->description =
+			"This test creates two channels, bridges them, and then"
+			" blind transfers the bridge to an extension.\n";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+	ast_test_validate(test, extra != NULL);
+
+	bridge = ast_bridge_basic_new();
+	ast_test_validate(test, bridge != NULL);
+
+	CREATE_ALICE_CHANNEL(chan_alice, &alice_caller);
+	CREATE_BOB_CHANNEL(chan_bob, &bob_caller);
+
+	ANSWER_NO_APP(chan_alice);
+	ANSWER_NO_APP(chan_bob);
+
+	ast_test_validate(test, 0 == ast_bridge_impart(bridge, chan_bob, NULL, NULL, 0));
+	do_sleep();
+
+	ast_test_validate(test, 0 == ast_bridge_impart(bridge, chan_alice, NULL, NULL, 0));
+	do_sleep();
+	APPEND_EVENT(chan_bob, AST_CEL_BRIDGE_START, NULL, NULL, ast_channel_name(chan_alice));
+
+	ast_str_set(&extra, 0, "%s,%s,%s", bridge->uniqueid, "transfer_extension", "transfer_context");
+	APPEND_EVENT(chan_alice, AST_CEL_BLINDTRANSFER, NULL, ast_str_buffer(extra), NULL);
+	APPEND_EVENT(chan_bob, AST_CEL_BRIDGE_END, NULL, NULL, ast_channel_name(chan_alice));
+
+	ast_bridge_transfer_blind(1, chan_alice, "transfer_extension", "transfer_context", NULL, NULL);
+
+	ast_test_validate(test, 0 == ast_bridge_depart(chan_bob));
+
+
+	HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "16,,");
+	HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "16,,");
 
 	return AST_TEST_PASS;
 }
@@ -1335,19 +1385,15 @@
 	cel_expected_events = NULL;
 	cel_received_events = NULL;
 
-	/* check events */
-	ast_test_validate(test, !check_events(local_expected, local_received));
-
 	/* Restore the real CEL config */
 	ast_cel_set_config(saved_config);
 	ao2_cleanup(saved_config);
 	saved_config = NULL;
 
+	/* check events */
+	ast_test_validate(test, !check_events(local_expected, local_received));
+
 	/* get rid of events */
-	ao2_cleanup(cel_received_events);
-	cel_received_events = NULL;
-	ao2_cleanup(cel_expected_events);
-	cel_expected_events = NULL;
 	ast_mutex_destroy(&sync_lock);
 	ast_cond_destroy(&sync_out);
 	return 0;
@@ -1376,6 +1422,8 @@
 	AST_TEST_UNREGISTER(test_cel_dial_answer_twoparty_bridge_b);
 	AST_TEST_UNREGISTER(test_cel_dial_answer_multiparty);
 
+	AST_TEST_UNREGISTER(test_cel_blind_transfer);
+
 	ast_channel_unregister(&test_cel_chan_tech);
 
 	ao2_cleanup(cel_test_config);
@@ -1411,6 +1459,7 @@
 	cel_test_config->events |= 1<<AST_CEL_BRIDGE_TO_CONF;
 	cel_test_config->events |= 1<<AST_CEL_CONF_ENTER;
 	cel_test_config->events |= 1<<AST_CEL_CONF_EXIT;
+	cel_test_config->events |= 1<<AST_CEL_BLINDTRANSFER;
 
 	AST_TEST_REGISTER(test_cel_channel_creation);
 	AST_TEST_REGISTER(test_cel_unanswered_inbound_call);
@@ -1434,6 +1483,8 @@
 	AST_TEST_REGISTER(test_cel_dial_answer_twoparty_bridge_b);
 	AST_TEST_REGISTER(test_cel_dial_answer_multiparty);
 
+	AST_TEST_REGISTER(test_cel_blind_transfer);
+
 	ast_test_register_init(TEST_CATEGORY, test_cel_init_cb);
 	ast_test_register_cleanup(TEST_CATEGORY, test_cel_cleanup_cb);
 




More information about the asterisk-commits mailing list