unit: Add manager create/destroy tests
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Tue, 7 Jun 2011 13:42:22 +0000 (15:42 +0200)
committerDaniel Wagner <daniel.wagner@bmw-carit.de>
Tue, 7 Jun 2011 13:42:57 +0000 (15:42 +0200)
Also add util function for creating the test fixture data structure.

unit/test-connman.h
unit/test-session.c
unit/utils.c

index 894025f..17037f9 100644 (file)
@@ -55,6 +55,9 @@ void util_test_add(const char *test_name, GSourceFunc test_func,
 void util_setup(struct test_fix *fix, gconstpointer data);
 void util_teardown(struct test_fix *fix, gconstpointer data);
 
+void util_session_create(struct test_fix *fix, unsigned int max_sessions);
+void util_session_destroy(gpointer fix);
+
 typedef void (* notify_cb) (struct test_session *session);
 
 enum connman_session_roaming_policy {
index d0f232e..b129326 100644 (file)
 #include <config.h>
 #endif
 
+#include <stdio.h>
+
 #include "gdbus/gdbus.h"
 
 #include "test-connman.h"
 
-static gboolean test_empty(gpointer data)
+static connman_bool_t is_connman_running(DBusConnection *connection)
+{
+       DBusError error;
+       connman_bool_t running;
+
+       dbus_error_init(&error);
+
+       running = dbus_bus_name_has_owner(connection, CONNMAN_SERVICE, &error);
+
+       if (dbus_error_is_set(&error) == TRUE) {
+               fprintf(stderr, "%s\n", error.message);
+               dbus_error_free(&error);
+
+               return FALSE;
+       }
+
+       return running;
+}
+
+static gboolean test_session_create_no_notify(gpointer data)
 {
        struct test_fix *fix = data;
+       DBusMessage *msg;
 
-       util_idle_call(fix, util_quit_loop, NULL);
+       util_session_create(fix, 1);
+
+       msg = manager_create_session(fix->session->connection,
+                                       fix->session->info, "/foo");
+       g_assert(msg != NULL);
+       g_assert(dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_ERROR);
+
+       dbus_message_unref(msg);
+
+       g_assert(is_connman_running(fix->session->connection) == TRUE);
+       util_idle_call(fix, util_quit_loop, util_session_destroy);
+
+       return FALSE;
+}
+
+static gboolean test_session_destroy_no_notify(gpointer data)
+{
+       struct test_fix *fix = data;
+       DBusMessage *msg;
+
+       util_session_create(fix, 1);
+
+       msg = manager_destroy_session(fix->session->connection, "/foo");
+       g_assert(msg == NULL);
+
+       g_assert(is_connman_running(fix->session->connection) == TRUE);
+       util_idle_call(fix, util_quit_loop, util_session_destroy);
 
        return FALSE;
 }
@@ -88,8 +136,10 @@ int main(int argc, char *argv[])
 {
        g_test_init(&argc, &argv, NULL);
 
-       util_test_add("/empty",
-               test_empty, setup_cb, teardown_cb);
+       util_test_add("/manager/session create no notify",
+               test_session_create_no_notify, setup_cb, teardown_cb);
+       util_test_add("/manager/session destroy no notify",
+               test_session_destroy_no_notify, setup_cb, teardown_cb);
 
        return g_test_run();
 }
index bd42439..3c8eaae 100644 (file)
@@ -107,3 +107,32 @@ void util_test_add(const char *test_name, GSourceFunc test_func,
        g_test_add(test_name, struct test_fix, test_func,
                setup_cb, util_wrapper, teardown_cb);
 }
+
+void util_session_create(struct test_fix *fix, unsigned int max_sessions)
+{
+       unsigned int i;
+
+       fix->max_sessions = max_sessions;
+       fix->session = g_try_new0(struct test_session, max_sessions);
+
+       for (i = 0; i < max_sessions; i++) {
+               fix->session[i].fix = fix;
+               fix->session[i].info = g_try_new0(struct test_session_info, 1);
+               fix->session[i].connection = g_dbus_setup_private(
+                                               DBUS_BUS_SYSTEM, NULL, NULL);
+       }
+}
+
+void util_session_destroy(gpointer data)
+{
+       struct test_fix *fix = data;
+
+       unsigned int i;
+
+       for (i = 0; i < fix->max_sessions; i++) {
+               dbus_connection_close(fix->session[i].connection);
+               g_free(fix->session[i].info);
+       }
+
+       g_free(fix->session);
+}