From: Daniel Wagner <[email protected]>

---
 unit/session-api.c  |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 unit/test-connman.h |    5 ++++
 unit/test-session.c |   57 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 128 insertions(+), 0 deletions(-)

diff --git a/unit/session-api.c b/unit/session-api.c
index 209faff..2c5873c 100644
--- a/unit/session-api.c
+++ b/unit/session-api.c
@@ -338,3 +338,69 @@ void session_append_settings(DBusMessageIter *dict,
                                                DBUS_TYPE_STRING,
                                                &policy);
 }
+
+DBusMessage *session_connect(DBusConnection *connection,
+                               struct test_session *session)
+{
+       DBusMessage *message, *reply;
+       DBusError error;
+
+       message = dbus_message_new_method_call(CONNMAN_SERVICE,
+                                               session->session_path,
+                                               CONNMAN_SESSION_INTERFACE,
+                                                       "Connect");
+       if (message == NULL)
+               return NULL;
+
+       dbus_error_init(&error);
+
+       reply = dbus_connection_send_with_reply_and_block(connection,
+                                                       message, -1, &error);
+       if (reply == NULL) {
+               if (dbus_error_is_set(&error) == TRUE) {
+                       LOG("%s", error.message);
+                       dbus_error_free(&error);
+               } else {
+                       LOG("Failed to get properties");
+               }
+               dbus_message_unref(message);
+               return NULL;
+       }
+
+       dbus_message_unref(message);
+
+       return reply;
+}
+
+DBusMessage *session_disconnect(DBusConnection *connection,
+                                       struct test_session *session)
+{
+       DBusMessage *message, *reply;
+       DBusError error;
+
+       message = dbus_message_new_method_call(CONNMAN_SERVICE,
+                                               session->session_path,
+                                               CONNMAN_SESSION_INTERFACE,
+                                                       "Disconnect");
+       if (message == NULL)
+               return NULL;
+
+       dbus_error_init(&error);
+
+       reply = dbus_connection_send_with_reply_and_block(connection,
+                                                       message, -1, &error);
+       if (reply == NULL) {
+               if (dbus_error_is_set(&error) == TRUE) {
+                       LOG("%s", error.message);
+                       dbus_error_free(&error);
+               } else {
+                       LOG("Failed to get properties");
+               }
+               dbus_message_unref(message);
+               return NULL;
+       }
+
+       dbus_message_unref(message);
+
+       return reply;
+}
diff --git a/unit/test-connman.h b/unit/test-connman.h
index 4521e93..e930b4c 100644
--- a/unit/test-connman.h
+++ b/unit/test-connman.h
@@ -96,6 +96,11 @@ int session_notify_register(struct test_session *session,
 int session_notify_unregister(struct test_session *session,
                                const char *notify_path);
 
+DBusMessage *session_connect(DBusConnection *connection,
+                               struct test_session *session);
+DBusMessage *session_disconnect(DBusConnection *connection,
+                                       struct test_session *session);
+
 /* #define DEBUG */
 #ifdef DEBUG
 #include <stdio.h>
diff --git a/unit/test-session.c b/unit/test-session.c
index 866d0be..5e236ae 100644
--- a/unit/test-session.c
+++ b/unit/test-session.c
@@ -338,6 +338,60 @@ static gboolean test_session_create_many(gpointer data)
        return FALSE;
 }
 
+static gboolean test_session_connect(gpointer data)
+{
+       struct session_fix *fix = data;
+       struct test_session *session;
+       DBusMessage *msg;
+
+       helper_session_create(fix, 1);
+       session = fix->session;
+
+       session->notify_path = g_strdup("/foo");
+
+       helper_session_init(session);
+
+       msg = session_connect(session->system_bus, session);
+       g_assert(msg != NULL);
+       dbus_message_unref(msg);
+
+       /* XXX wait for the connection notification */
+
+       helper_session_cleanup(session);
+
+       g_assert(is_connman_running(session->system_bus) == TRUE);
+       helper_quit_on_idle_and_cleanup(fix);
+
+       return FALSE;
+}
+
+static gboolean test_session_disconnect(gpointer data)
+{
+       struct session_fix *fix = data;
+       struct test_session *session;
+       DBusMessage *msg;
+
+       helper_session_create(fix, 1);
+       session = fix->session;
+
+       session->notify_path = g_strdup("/foo");
+
+       helper_session_init(session);
+
+       msg = session_disconnect(session->system_bus, session);
+       g_assert(msg != NULL);
+       dbus_message_unref(msg);
+
+       /* XXX wait for the disconnection notification */
+
+       helper_session_cleanup(session);
+
+       g_assert(is_connman_running(session->system_bus) == TRUE);
+       helper_quit_on_idle_and_cleanup(fix);
+
+       return FALSE;
+}
+
 static void helper_test_add(const char *test_name, GSourceFunc test_func)
 {
        g_test_add(test_name, struct session_fix, test_func,
@@ -355,5 +409,8 @@ int main(int argc, char *argv[])
        helper_test_add("/manager/session create destroy", 
test_session_create_destroy);
        helper_test_add("/manager/session create many", 
test_session_create_many);
 
+       helper_test_add("/session/connect", test_session_connect);
+       helper_test_add("/session/disconnect", test_session_disconnect);
+
        return g_test_run();
 }
-- 
1.7.4.4

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to