diff options
-rw-r--r-- | unit/manager-api.c | 73 | ||||
-rw-r--r-- | unit/test-connman.h | 11 | ||||
-rw-r--r-- | unit/utils.c | 61 |
3 files changed, 144 insertions, 1 deletions
diff --git a/unit/manager-api.c b/unit/manager-api.c index 02bf58ab..40ad3704 100644 --- a/unit/manager-api.c +++ b/unit/manager-api.c @@ -96,6 +96,38 @@ DBusMessage *manager_get_services(DBusConnection *connection) return reply; } +DBusMessage *manager_get_properties(DBusConnection *connection) +{ + DBusMessage *message, *reply; + DBusError error; + + message = dbus_message_new_method_call(CONNMAN_SERVICE, + CONNMAN_MANAGER_PATH, + CONNMAN_MANAGER_INTERFACE, + "GetProperties"); + 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("%s", error.message); + } + dbus_message_unref(message); + return NULL; + } + + dbus_message_unref(message); + + return reply; +} + DBusMessage *manager_create_session(DBusConnection *connection, struct test_session_info *info, const char *notifier_path) @@ -187,3 +219,44 @@ DBusMessage *manager_set_session_mode(DBusConnection *connection, return set_property(connection, "SessionMode", DBUS_TYPE_BOOLEAN, &enable); } + +int manager_parse_properties(DBusMessage *msg, + struct test_manager *manager) +{ + DBusMessageIter iter, array; + + dbus_message_iter_init(msg, &iter); + dbus_message_iter_recurse(&iter, &array); + + while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) { + DBusMessageIter entry, value; + const char *key; + + dbus_message_iter_recurse(&array, &entry); + dbus_message_iter_get_basic(&entry, &key); + + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &value); + + switch (dbus_message_iter_get_arg_type(&value)) { + case DBUS_TYPE_STRING: + if (g_str_equal(key, "State") == TRUE) { + const char *val; + dbus_message_iter_get_basic(&value, &val); + + if (manager->state != NULL) + g_free(manager->state); + + LOG("State %s", val); + + manager->state = g_strdup(val); + } + break; + default: + break; + } + dbus_message_iter_next(&array); + } + + return 0; +} diff --git a/unit/test-connman.h b/unit/test-connman.h index fb9f9578..0d9da930 100644 --- a/unit/test-connman.h +++ b/unit/test-connman.h @@ -27,12 +27,19 @@ struct test_session; +struct test_manager { + char *state; +}; + struct test_fix { gpointer user_data; GMainLoop *main_loop; DBusConnection *main_connection; guint watch; + guint manager_watch; + + struct test_manager manager; /* session test cases */ unsigned int max_sessions; @@ -123,6 +130,7 @@ DBusMessage *session_disconnect(DBusConnection *connection, /* manager-api.c */ DBusMessage *manager_get_services(DBusConnection *connection); +DBusMessage *manager_get_properties(DBusConnection *connection); DBusMessage *manager_create_session(DBusConnection *connection, struct test_session_info *info, const char *notifier_path); @@ -130,7 +138,8 @@ DBusMessage *manager_destroy_session(DBusConnection *connection, const char *notifier_path); DBusMessage *manager_set_session_mode(DBusConnection *connection, connman_bool_t enable); - +int manager_parse_properties(DBusMessage *msg, + struct test_manager *manager); /* #define DEBUG */ #ifdef DEBUG diff --git a/unit/utils.c b/unit/utils.c index 6a174bcc..96644631 100644 --- a/unit/utils.c +++ b/unit/utils.c @@ -30,6 +30,7 @@ #include "test-connman.h" #define ENABLE_WRAPPER 1 +#define PROPERTY_CHANGED "PropertyChanged" gboolean util_quit_loop(gpointer data) { @@ -59,6 +60,53 @@ static void connman_died(DBusConnection *connection, void *user_data) g_assert(FALSE); } +static void manager_changed(struct test_fix *fix, + DBusMessageIter *entry) +{ + DBusMessageIter iter; + const char *key; + const char *value; + int type; + + dbus_message_iter_get_basic(entry, &key); + + LOG("key %s", key); + + dbus_message_iter_next(entry); + + dbus_message_iter_recurse(entry, &iter); + + type = dbus_message_iter_get_arg_type(&iter); + + if (type != DBUS_TYPE_STRING) + return; + + dbus_message_iter_get_basic(&iter, &value); + + if (g_str_equal(key, "State") == TRUE) { + LOG("State %s", value); + + if (fix->manager.state != NULL) + g_free(fix->manager.state); + + fix->manager.state = g_strdup(value); + } +} + +static gboolean handle_manager_changed(DBusConnection *connection, + DBusMessage *message, + void *user_data) +{ + struct test_fix *fix = user_data; + + DBusMessageIter iter; + + if (dbus_message_iter_init(message, &iter)) + manager_changed(fix, &iter); + + return TRUE; +} + guint util_call(struct test_fix *fix, GSourceFunc func, GDestroyNotify notify) { @@ -75,6 +123,8 @@ guint util_call(struct test_fix *fix, GSourceFunc func, void util_setup(struct test_fix *fix, gconstpointer data) { + DBusMessage *msg; + fix->main_loop = g_main_loop_new(NULL, FALSE); fix->main_connection = g_dbus_setup_private(DBUS_BUS_SYSTEM, NULL, NULL); @@ -83,11 +133,22 @@ void util_setup(struct test_fix *fix, gconstpointer data) NULL, connman_died, NULL, NULL); + fix->manager_watch = g_dbus_add_signal_watch(fix->main_connection, + NULL, NULL, + CONNMAN_MANAGER_INTERFACE, + PROPERTY_CHANGED, + handle_manager_changed, + fix, NULL); + + msg = manager_get_properties(fix->main_connection); + manager_parse_properties(msg, &fix->manager); + dbus_message_unref(msg); } void util_teardown(struct test_fix *fix, gconstpointer data) { g_dbus_remove_watch(fix->main_connection, fix->watch); + g_dbus_remove_watch(fix->main_connection, fix->manager_watch); dbus_connection_close(fix->main_connection); dbus_connection_unref(fix->main_connection); |