unit: Add manager state callback
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Thu, 11 Aug 2011 14:56:17 +0000 (16:56 +0200)
committerDaniel Wagner <daniel.wagner@bmw-carit.de>
Thu, 11 Aug 2011 15:40:52 +0000 (17:40 +0200)
unit/test-connman.h
unit/test-session.c
unit/utils.c

index 0d9da93..5602daa 100644 (file)
@@ -40,6 +40,7 @@ struct test_fix {
        guint manager_watch;
 
        struct test_manager manager;
+       GSourceFunc manager_changed;
 
        /* session test cases */
        unsigned int max_sessions;
index c626e04..3431cea 100644 (file)
@@ -216,8 +216,6 @@ static void set_session_mode(struct test_fix *fix,
        g_assert(dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_ERROR);
 
        dbus_message_unref(msg);
-
-       util_idle_call(fix, util_quit_loop, NULL);
 }
 
 static void test_session_connect_notify(struct test_session *session)
@@ -445,12 +443,35 @@ static gboolean test_session_connect_free_ride(gpointer data)
        return FALSE;
 }
 
+static connman_bool_t is_online(struct test_fix *fix)
+{
+       if (g_strcmp0(fix->manager.state, "online") == 0)
+               return TRUE;
+
+       return FALSE;
+}
+
 static gboolean enable_session_mode(gpointer data)
 {
        struct test_fix *fix = data;
 
        set_session_mode(fix, TRUE);
 
+       if (is_online(fix) == FALSE)
+               util_idle_call(fix, util_quit_loop, NULL);
+
+       return FALSE;
+}
+
+static gboolean manager_state_changed(gpointer data)
+{
+       struct test_fix *fix = data;
+
+       if (is_online(fix) == FALSE) {
+               fix->manager_changed = NULL;
+               util_idle_call(fix, util_quit_loop, NULL);
+       }
+
        return FALSE;
 }
 
@@ -465,15 +486,21 @@ static gboolean disable_session_mode(gpointer data)
 
 static void setup_cb(struct test_fix *fix, gconstpointer data)
 {
-       util_setup(fix, data);
+       fix->manager_changed = manager_state_changed;
 
+       util_setup(fix, data);
        util_call(fix, enable_session_mode, NULL);
+
        g_main_loop_run(fix->main_loop);
+
+       fix->manager_changed = NULL;
 }
 
 static void teardown_cb(struct test_fix *fix, gconstpointer data)
 {
        util_call(fix, disable_session_mode, NULL);
+       util_idle_call(fix, util_quit_loop, NULL);
+
        g_main_loop_run(fix->main_loop);
 
        util_teardown(fix, data);
index 9664463..6ff1c71 100644 (file)
@@ -91,6 +91,9 @@ static void manager_changed(struct test_fix *fix,
 
                fix->manager.state = g_strdup(value);
        }
+
+       if (fix->manager_changed != NULL)
+               fix->manager_changed(fix);
 }
 
 static gboolean handle_manager_changed(DBusConnection *connection,