[asterisk-commits] mmichelson: branch mmichelson/trunk-digiumphones r362303 - in /team/mmichelso...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 17 11:13:49 CDT 2012


Author: mmichelson
Date: Tue Apr 17 11:13:45 2012
New Revision: 362303

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=362303
Log:
Fix test failure and add some cleanup to presence change test.

Switching to use an enum instead of an int for presence state values
made tests for results being less than 0 meaningless since enums are
treated as unsigned values. The fix for this is to create an enum value
for an invalid presence. Comparison to this value tells if the presence
is valid or bogus.

In addition, the presence change unit test has been changed to use a more
"unique" value for setting presence and then cleaning the DB afterwards.


Modified:
    team/mmichelson/trunk-digiumphones/funcs/func_presencestate.c
    team/mmichelson/trunk-digiumphones/include/asterisk/presencestate.h
    team/mmichelson/trunk-digiumphones/main/presencestate.c

Modified: team/mmichelson/trunk-digiumphones/funcs/func_presencestate.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/trunk-digiumphones/funcs/func_presencestate.c?view=diff&rev=362303&r1=362302&r2=362303
==============================================================================
--- team/mmichelson/trunk-digiumphones/funcs/func_presencestate.c (original)
+++ team/mmichelson/trunk-digiumphones/funcs/func_presencestate.c Tue Apr 17 11:13:45 2012
@@ -121,7 +121,7 @@
 	}
 
 	state = ast_presence_state(args.provider, &subtype, &message);
-	if (state < 0) {
+	if (state == AST_PRESENCE_INVALID) {
 		ast_log(LOG_WARNING, "PRESENCE_STATE unknown \n");
 		return -1;
 	}
@@ -170,7 +170,7 @@
 	*state = ast_presence_state_val(state_str);
 
 	/* not a valid state */
-	if (*state < 0) {
+	if (*state == AST_PRESENCE_INVALID) {
 		ast_log(LOG_WARNING, "Unknown presence state value %s\n", state_str);
 		return -1;
 	}
@@ -624,9 +624,9 @@
 			res = AST_TEST_FAIL;
 			break;
 		}
-		printf("parse string is %s\n", parse_string);
 		parse_result = parse_data(parse_string, &state, &subtype, &message, &options);
 		if (parse_result == 0) {
+			ast_log(LOG_WARNING, "Invalid string parsing failed on %s\n", tests[i]);
 			res = AST_TEST_FAIL;
 			ast_free(parse_string);
 			break;
@@ -654,7 +654,6 @@
 	cb_data->subtype = ast_strdup(ast_event_get_ie_str(event, AST_EVENT_IE_PRESENCE_SUBTYPE));
 	cb_data->message = ast_strdup(ast_event_get_ie_str(event, AST_EVENT_IE_PRESENCE_MESSAGE));
 	sem_post(&cb_data->sem);
-	ast_log(LOG_NOTICE, "Callback called\n");
 }
 
 /* XXX This test could probably stand to be moved since
@@ -693,10 +692,10 @@
 		return AST_TEST_FAIL;
 	}
 
-	presence_write(NULL, "PRESENCESTATE", "CustomPresence:Bob", "away,down the hall,Quarterly financial meeting");
+	presence_write(NULL, "PRESENCESTATE", "CustomPresence:TestPresenceStateChange", "away,down the hall,Quarterly financial meeting");
 	sem_wait(&cb_data->sem);
 	if (cb_data->presence != AST_PRESENCE_AWAY ||
-			strcmp(cb_data->provider, "CustomPresence:Bob") ||
+			strcmp(cb_data->provider, "CustomPresence:TestPresenceStateChange") ||
 			strcmp(cb_data->subtype, "down the hall") ||
 			strcmp(cb_data->message, "Quarterly financial meeting")) {
 		return AST_TEST_FAIL;
@@ -706,6 +705,8 @@
 	ast_free((char *)cb_data->subtype);
 	ast_free((char *)cb_data->message);
 	ast_free((char *)cb_data);
+
+	ast_db_del("CustomPresence", "TestPresenceStateChange");
 
 	return AST_TEST_PASS;
 }

Modified: team/mmichelson/trunk-digiumphones/include/asterisk/presencestate.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/trunk-digiumphones/include/asterisk/presencestate.h?view=diff&rev=362303&r1=362302&r2=362303
==============================================================================
--- team/mmichelson/trunk-digiumphones/include/asterisk/presencestate.h (original)
+++ team/mmichelson/trunk-digiumphones/include/asterisk/presencestate.h Tue Apr 17 11:13:45 2012
@@ -31,6 +31,12 @@
 	AST_PRESENCE_XA,
 	AST_PRESENCE_CHAT,
 	AST_PRESENCE_DND,
+	/* This is not something that a user can
+	 * set his presence to. Rather, this is returned
+	 * to indicate that presence is in some invalid
+	 * state
+	 */
+	AST_PRESENCE_INVALID,
 };
 
 /*! \brief Presence state provider call back */

Modified: team/mmichelson/trunk-digiumphones/main/presencestate.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/trunk-digiumphones/main/presencestate.c?view=diff&rev=362303&r1=362302&r2=362303
==============================================================================
--- team/mmichelson/trunk-digiumphones/main/presencestate.c (original)
+++ team/mmichelson/trunk-digiumphones/main/presencestate.c Tue Apr 17 11:13:45 2012
@@ -92,12 +92,12 @@
 			return state2string[i].state;
 		}
 	}
-	return -1;
+	return AST_PRESENCE_INVALID;
 }
 
 static enum ast_presence_state presence_state_cached(const char *presence_provider, char **subtype, char **message)
 {
-	enum ast_presence_state res = -1;
+	enum ast_presence_state res = AST_PRESENCE_INVALID;
 	struct ast_event *event;
 	const char *_subtype;
 	const char *_message;
@@ -126,11 +126,11 @@
 	struct presence_state_provider *provider;
 	char *address;
 	char *label = ast_strdupa(presence_provider);
-	int res = -1;
+	int res = AST_PRESENCE_INVALID;
 
 	if (check_cache) {
 		res = presence_state_cached(presence_provider, subtype, message);
-		if (res > 0) {
+		if (res != AST_PRESENCE_INVALID) {
 			return res;
 		}
 	}




More information about the asterisk-commits mailing list