#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;
}
{
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();
}
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);
+}