[PATCH 11/12] unit: switching from online to state property into test-session

Tomasz Bursztyka tomasz.bursztyka at linux.intel.com
Wed Feb 8 06:13:10 PST 2012


---
 unit/session-api.c  |   22 +++++++++++++++++-----
 unit/test-connman.h |    8 +++++++-
 unit/test-session.c |   37 ++++++++++++++++++++-----------------
 3 files changed, 44 insertions(+), 23 deletions(-)

diff --git a/unit/session-api.c b/unit/session-api.c
index 480a1ac..7e3a3b1 100644
--- a/unit/session-api.c
+++ b/unit/session-api.c
@@ -29,6 +29,16 @@
 
 #include "test-connman.h"
 
+static enum connman_session_state string2state(const char *state)
+{
+	if (g_strcmp0(state, "connected") == 0)
+		return CONNMAN_SESSION_STATE_CONNECTED;
+	if (g_strcmp0(state, "online") == 0)
+		return CONNMAN_SESSION_STATE_ONLINE;
+
+	return CONNMAN_SESSION_STATE_DISCONNECTED;
+}
+
 static const char *roamingpolicy2string(enum connman_session_roaming_policy policy)
 {
 	switch (policy) {
@@ -163,10 +173,7 @@ static DBusMessage *notify_update(DBusConnection *conn,
 			}
 			break;
 		case DBUS_TYPE_BOOLEAN:
-			if (g_str_equal(key, "Online") == TRUE) {
-				dbus_message_iter_get_basic(&value,
-							&info->online);
-			} else if (g_str_equal(key, "Priority") == TRUE) {
+			if (g_str_equal(key, "Priority") == TRUE) {
 				dbus_message_iter_get_basic(&value,
 							&info->priority);
 
@@ -206,7 +213,12 @@ static DBusMessage *notify_update(DBusConnection *conn,
 			}
 			break;
 		case DBUS_TYPE_STRING:
-			if (g_str_equal(key, "Bearer") == TRUE) {
+			if (g_str_equal(key, "State") == TRUE) {
+				const char *val;
+				dbus_message_iter_get_basic(&value, &val);
+
+				info->state = string2state(val);
+			} else if (g_str_equal(key, "Bearer") == TRUE) {
 				const char *val;
 				dbus_message_iter_get_basic(&value, &val);
 
diff --git a/unit/test-connman.h b/unit/test-connman.h
index 5602daa..d04e230 100644
--- a/unit/test-connman.h
+++ b/unit/test-connman.h
@@ -71,6 +71,12 @@ void util_session_cleanup(struct test_session *session);
 
 typedef void (* notify_cb) (struct test_session *session);
 
+enum connman_session_state {
+	CONNMAN_SESSION_STATE_DISCONNECTED   = 0,
+	CONNMAN_SESSION_STATE_CONNECTED      = 1,
+	CONNMAN_SESSION_STATE_ONLINE         = 2,
+};
+
 enum connman_session_roaming_policy {
 	CONNMAN_SESSION_ROAMING_POLICY_UNKNOWN		= 0,
 	CONNMAN_SESSION_ROAMING_POLICY_DEFAULT		= 1,
@@ -82,7 +88,7 @@ enum connman_session_roaming_policy {
 
 struct test_session_info {
 	char *bearer;
-	connman_bool_t online;
+	enum connman_session_state state;
 	char *name;
 	/* ipv4, ipv6 dicts */
 	GSList *allowed_bearers;
diff --git a/unit/test-session.c b/unit/test-session.c
index 47704da..38ed2bf 100644
--- a/unit/test-session.c
+++ b/unit/test-session.c
@@ -220,9 +220,9 @@ static void set_session_mode(struct test_fix *fix,
 
 static void test_session_connect_notify(struct test_session *session)
 {
-	LOG("session %p online %d", session, session->info->online);
+	LOG("session %p state %d", session, session->info->state);
 
-	if (session->info->online != TRUE)
+	if (session->info->state == CONNMAN_SESSION_STATE_DISCONNECTED)
 		return;
 
 	util_session_cleanup(session);
@@ -254,9 +254,9 @@ static gboolean test_session_connect(gpointer data)
 
 static void test_session_disconnect_notify(struct test_session *session)
 {
-	LOG("session %p online %d", session, session->info->online);
+	LOG("session %p state %d", session, session->info->state);
 
-	if (session->info->online != FALSE)
+	if (session->info->state >= CONNMAN_SESSION_STATE_CONNECTED)
 		return;
 
 	util_session_cleanup(session);
@@ -290,20 +290,20 @@ static void test_session_connect_disconnect_notify(struct test_session *session)
 	enum test_session_state next_state = state;
 	DBusMessage *msg;
 
-	LOG("state %d session %p %s online %d", state, session,
-		session->notify_path, session->info->online);
+	LOG("state %d session %p %s state %d", state, session,
+		session->notify_path, session->info->state);
 
 	switch (state) {
 	case TEST_SESSION_STATE_0:
-		if (session->info->online == FALSE)
+		if (session->info->state == CONNMAN_SESSION_STATE_DISCONNECTED)
 			next_state = TEST_SESSION_STATE_1;
 		break;
 	case TEST_SESSION_STATE_1:
-		if (session->info->online == TRUE)
+		if (session->info->state >= CONNMAN_SESSION_STATE_CONNECTED)
 			next_state = TEST_SESSION_STATE_2;
 		break;
 	case TEST_SESSION_STATE_2:
-		if (session->info->online == FALSE)
+		if (session->info->state == CONNMAN_SESSION_STATE_DISCONNECTED)
 			next_state = TEST_SESSION_STATE_3;
 	default:
 		break;
@@ -381,27 +381,30 @@ static void test_session_connect_free_ride_notify(struct test_session *session)
 	enum test_session_state next_state = state;
 	DBusMessage *msg;
 
-	LOG("state %d session %p %s online %d", state, session,
-		session->notify_path, session->info->online);
+	LOG("state %d session %p %s state %d", state, session,
+		session->notify_path, session->info->state);
 
 	switch (state) {
 	case TEST_SESSION_STATE_0:
-		if (session0->info->online == FALSE &&
-				session1->info->online == FALSE) {
+		if (session0->info->state == CONNMAN_SESSION_STATE_DISCONNECTED
+				&& session1->info->state ==
+					CONNMAN_SESSION_STATE_DISCONNECTED) {
 			next_state = TEST_SESSION_STATE_1;
 		}
 
 		break;
 	case TEST_SESSION_STATE_1:
-		if (session0->info->online == TRUE &&
-				session1->info->online == TRUE) {
+		if (session0->info->state >= CONNMAN_SESSION_STATE_CONNECTED &&
+				session1->info->state >=
+					CONNMAN_SESSION_STATE_CONNECTED) {
 			next_state = TEST_SESSION_STATE_2;
 		}
 
 		break;
 	case TEST_SESSION_STATE_2:
-		if (session0->info->online == FALSE &&
-				session1->info->online == FALSE) {
+		if (session0->info->state == CONNMAN_SESSION_STATE_DISCONNECTED
+				&& session1->info->state ==
+					CONNMAN_SESSION_STATE_DISCONNECTED) {
 			next_state = TEST_SESSION_STATE_3;
 		}
 
-- 
1.7.8.4




More information about the connman mailing list