[asterisk-commits] kmoore: branch kmoore/peer-field-restoration r398743 - /team/kmoore/peer-fiel...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Sep 10 10:26:01 CDT 2013


Author: kmoore
Date: Tue Sep 10 10:25:59 2013
New Revision: 398743

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=398743
Log:
Fix the attended transfer merge test

Modified:
    team/kmoore/peer-field-restoration/tests/test_cel.c

Modified: team/kmoore/peer-field-restoration/tests/test_cel.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/peer-field-restoration/tests/test_cel.c?view=diff&rev=398743&r1=398742&r2=398743
==============================================================================
--- team/kmoore/peer-field-restoration/tests/test_cel.c (original)
+++ team/kmoore/peer-field-restoration/tests/test_cel.c Tue Sep 10 10:25:59 2013
@@ -121,15 +121,19 @@
 	} while (0)
 
 #define BRIDGE_EXIT_EVENT(channel, bridge) do { \
-	RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
 	RAII_VAR(struct ast_str *, peer_str, NULL, ast_free); \
 	stasis_topic_wait(ast_channel_topic_all()); \
 	stasis_topic_wait(ast_bridge_topic_all()); \
 	peer_str = test_cel_generate_peer_str(channel, bridge); \
 	ast_test_validate(test, peer_str != NULL); \
+	BRIDGE_EXIT_EVENT_PEER(channel, bridge, ast_str_buffer(peer_str)); \
+	} while (0)
+
+#define BRIDGE_EXIT_EVENT_PEER(channel, bridge, peer) do { \
+	RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
 	extra = ast_json_pack("{s: s}", "bridge_id", bridge->uniqueid); \
 	ast_test_validate(test, extra != NULL); \
-	APPEND_EVENT_PEER(channel, AST_CEL_BRIDGE_EXIT, NULL, extra, ast_str_buffer(peer_str)); \
+	APPEND_EVENT_PEER(channel, AST_CEL_BRIDGE_EXIT, NULL, extra, peer); \
 	} while (0)
 
 #define BRIDGE_EXIT_SNAPSHOT(channel, bridge) do { \
@@ -1354,8 +1358,8 @@
 	/* Perform attended transfer */
 	ast_bridge_transfer_attended(chan_alice, chan_david);
 	do_sleep();
-	BRIDGE_EXIT_EVENT(chan_charlie, bridge2);
-	BRIDGE_ENTER_EVENT(chan_charlie, bridge1);
+	BRIDGE_EXIT_EVENT_PEER(chan_charlie, bridge2, "CELTestChannel/David");
+	BRIDGE_ENTER_EVENT_PEER(chan_charlie, bridge1, "CELTestChannel/Bob,CELTestChannel/Alice");
 	BRIDGE_EXIT_EVENT(chan_david, bridge2);
 	BRIDGE_EXIT_EVENT(chan_alice, bridge1);
 
@@ -1743,7 +1747,48 @@
 	return 0;
 }
 
-/*! \brief Check an IE value from two events,  */
+/*!
+ * \brief Check two peer strings for equality
+ *
+ * \retval zero if the peer strings do not match
+ * \retval non-zero if the peer strings match
+ */
+static int test_cel_peer_strings_match(const char *str1, const char *str2)
+{
+	struct ao2_container *intersection = ast_str_container_alloc(11);
+	RAII_VAR(char *, str1_dup, ast_strdup(str1), ast_free);
+	RAII_VAR(char *, str2_dup, ast_strdup(str2), ast_free);
+	char *chan;
+
+	while ((chan = strsep(&str1_dup, ","))) {
+		ast_str_container_add(intersection, chan);
+	}
+
+	while ((chan = strsep(&str2_dup, ","))) {
+		RAII_VAR(char *, ao2_chan, ao2_find(intersection, chan, OBJ_SEARCH_KEY), ao2_cleanup);
+
+		/* item in str2 not in str1 */
+		if (!ao2_chan) {
+			return 0;
+		}
+
+		ast_str_container_remove(intersection, chan);
+	}
+
+	/* item in str1 not in str2 */
+	if (ao2_container_count(intersection)) {
+		return 0;
+	}
+
+	return 1;
+}
+
+/*!
+ * \brief Check an IE value from two events
+ *
+ * \retval zero if the IEs in the events of the specified type do not match
+ * \retval non-zero if the IEs in the events of the specified type match
+ */
 static int match_ie_val(
 	const struct ast_event *event1,
 	const struct ast_event *event2,
@@ -1751,6 +1796,15 @@
 {
 	enum ast_event_ie_pltype pltype = ast_event_get_ie_pltype(type);
 
+	/* XXX ignore sec/usec for now */
+	if (type == AST_EVENT_IE_CEL_EVENT_TIME_USEC) {
+		return 1;
+	}
+
+	if (type == AST_EVENT_IE_CEL_EVENT_TIME) {
+		return 1;
+	}
+
 	switch (pltype) {
 	case AST_EVENT_IE_PLTYPE_UINT:
 	{
@@ -1760,20 +1814,23 @@
 	}
 	case AST_EVENT_IE_PLTYPE_STR:
 	{
-		const char *str;
-
-		str = ast_event_get_ie_str(event2, type);
-		if (str) {
-			const char *e1str, *e2str;
-			e1str = ast_event_get_ie_str(event1, type);
-			e2str = str;
-
-			if (!strcmp(e1str, e2str)) {
-				return 1;
-			}
+		const char *str1 = ast_event_get_ie_str(event1, type);
+		const char *str2 = ast_event_get_ie_str(event2, type);
+
+		if (!str1 && !str2) {
+			return 1;
+		} else if (!str1) {
+			return 0;
+		} else if (!str2) {
+			return 0;
 		}
 
-		return 0;
+		/* use special matching for CEL PEER field */
+		if (type == AST_EVENT_IE_CEL_PEER) {
+			return test_cel_peer_strings_match(str1, str2);
+		}
+
+		return !strcmp(str1, str2);
 	}
 	default:
 		break;
@@ -1792,11 +1849,8 @@
 	}
 
 	for (res = ast_event_iterator_init(&iterator, received); !res; res = ast_event_iterator_next(&iterator)) {
-		/* XXX ignore sec/usec for now */
 		int ie_type = ast_event_iterator_get_ie_type(&iterator);
-		if (ie_type != AST_EVENT_IE_CEL_EVENT_TIME_USEC
-			&& ie_type != AST_EVENT_IE_CEL_EVENT_TIME
-			&& !match_ie_val(received, expected, ie_type)) {
+		if (!match_ie_val(received, expected, ie_type)) {
 			ast_test_status_update(test, "Failed matching on field %s\n", ast_event_get_ie_type_name(ie_type));
 			return 0;
 		}




More information about the asterisk-commits mailing list