diff options
author | Zhang zhengguang <zhengguang.zhang@intel.com> | 2014-07-17 10:37:39 +0800 |
---|---|---|
committer | Zhang zhengguang <zhengguang.zhang@intel.com> | 2014-07-17 10:37:39 +0800 |
commit | 1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7 (patch) | |
tree | 6e991827d28537f7f40f20786c2354fd04a9fdad /tools/session-test.c | |
parent | fbe905ab58ecc31fe64c410c5f580cadc30e7f04 (diff) | |
download | connman-1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7.tar.gz connman-1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7.tar.bz2 connman-1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7.zip |
Imported Upstream version 1.24upstream/1.24
Diffstat (limited to 'tools/session-test.c')
-rw-r--r-- | tools/session-test.c | 152 |
1 files changed, 56 insertions, 96 deletions
diff --git a/tools/session-test.c b/tools/session-test.c index ac918947..18fd588c 100644 --- a/tools/session-test.c +++ b/tools/session-test.c @@ -58,38 +58,32 @@ static struct test_session *get_session(struct test_session *session, return &session->fix->session[index]; } -static gboolean test_session_create_no_notify(gpointer data) +static void test_session_create_no_notify(struct test_fix *fix) { - struct test_fix *fix = data; DBusMessage *msg; util_session_create(fix, 1); msg = manager_create_session(fix->session->connection, fix->session->info, "/foo"); - g_assert(msg != NULL); + g_assert(msg); g_assert(dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_ERROR); dbus_message_unref(msg); util_idle_call(fix, util_quit_loop, util_session_destroy); - - return FALSE; } -static gboolean test_session_destroy_no_notify(gpointer data) +static void test_session_destroy_no_notify(struct test_fix *fix) { - 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(!msg); util_idle_call(fix, util_quit_loop, util_session_destroy); - - return FALSE; } static void test_session_create_notify(struct test_session *session) @@ -99,9 +93,8 @@ static void test_session_create_notify(struct test_session *session) util_idle_call(session->fix, util_quit_loop, util_session_destroy); } -static gboolean test_session_create(gpointer data) +static void test_session_create(struct test_fix *fix) { - struct test_fix *fix = data; struct test_session *session; DBusMessage *msg; int err; @@ -118,17 +111,14 @@ static gboolean test_session_create(gpointer data) msg = manager_create_session(session->connection, session->info, session->notify_path); - g_assert(msg != NULL); + g_assert(msg); g_assert(dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_ERROR); dbus_message_unref(msg); - - return FALSE; } -static gboolean test_session_create_destroy(gpointer data) +static void test_session_create_destroy(struct test_fix *fix) { - struct test_fix *fix = data; struct test_session *session; util_session_create(fix, 1); @@ -140,13 +130,10 @@ static gboolean test_session_create_destroy(gpointer data) util_session_cleanup(fix->session); util_idle_call(fix, util_quit_loop, util_session_destroy); - - return FALSE; } -static gboolean test_session_create_already_exists(gpointer data) +static void test_session_create_dup_notification(struct test_fix *fix) { - struct test_fix *fix = data; struct test_session *session0, *session1; DBusMessage *msg; @@ -162,13 +149,11 @@ static gboolean test_session_create_already_exists(gpointer data) msg = manager_create_session(session1->connection, session1->info, session1->notify_path); - g_assert(msg == NULL); + g_assert(msg); util_session_cleanup(session0); util_idle_call(fix, util_quit_loop, util_session_destroy); - - return FALSE; } static void test_session_create_many_notify(struct test_session *session) @@ -187,9 +172,8 @@ static void test_session_create_many_notify(struct test_session *session) util_idle_call(session->fix, util_quit_loop, util_session_destroy); } -static gboolean test_session_create_many(gpointer data) +static void test_session_create_many(struct test_fix *fix) { - struct test_fix *fix = data; struct test_session *session; unsigned int i, max; @@ -207,17 +191,15 @@ static gboolean test_session_create_many(gpointer data) util_session_init(session); } - - return FALSE; } static void set_session_mode(struct test_fix *fix, - connman_bool_t enable) + bool enable) { DBusMessage *msg; msg = manager_set_session_mode(fix->main_connection, enable); - g_assert(msg != NULL); + g_assert(msg); g_assert(dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_ERROR); dbus_message_unref(msg); @@ -235,9 +217,8 @@ static void test_session_connect_notify(struct test_session *session) util_idle_call(session->fix, util_quit_loop, util_session_destroy); } -static gboolean test_session_connect(gpointer data) +static void test_session_connect(struct test_fix *fix) { - struct test_fix *fix = data; struct test_session *session; DBusMessage *msg; @@ -249,12 +230,10 @@ static gboolean test_session_connect(gpointer data) util_session_init(session); msg = session_connect(session->connection, session); - g_assert(msg != NULL); + g_assert(msg); g_assert(dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_ERROR); dbus_message_unref(msg); - - return FALSE; } static void test_session_disconnect_notify(struct test_session *session) @@ -269,9 +248,8 @@ static void test_session_disconnect_notify(struct test_session *session) util_idle_call(session->fix, util_quit_loop, util_session_destroy); } -static gboolean test_session_disconnect(gpointer data) +static void test_session_disconnect(struct test_fix *fix) { - struct test_fix *fix = data; struct test_session *session; DBusMessage *msg; @@ -283,10 +261,8 @@ static gboolean test_session_disconnect(gpointer data) util_session_init(session); msg = session_disconnect(session->connection, session); - g_assert(msg != NULL); + g_assert(msg); dbus_message_unref(msg); - - return FALSE; } static void test_session_connect_disconnect_notify(struct test_session *session) @@ -302,6 +278,10 @@ static void test_session_connect_disconnect_notify(struct test_session *session) case TEST_SESSION_STATE_0: if (session->info->state == CONNMAN_SESSION_STATE_DISCONNECTED) next_state = TEST_SESSION_STATE_1; + if (session->info->state == CONNMAN_SESSION_STATE_CONNECTED) { + LOG("state was already connected, continuing"); + next_state = TEST_SESSION_STATE_2; + } break; case TEST_SESSION_STATE_1: if (session->info->state >= CONNMAN_SESSION_STATE_CONNECTED) @@ -324,12 +304,12 @@ static void test_session_connect_disconnect_notify(struct test_session *session) switch (next_state) { case TEST_SESSION_STATE_1: msg = session_connect(session->connection, session); - g_assert(msg != NULL); + g_assert(msg); dbus_message_unref(msg); return; case TEST_SESSION_STATE_2: msg = session_disconnect(session->connection, session); - g_assert(msg != NULL); + g_assert(msg); dbus_message_unref(msg); return; case TEST_SESSION_STATE_3: @@ -342,9 +322,8 @@ static void test_session_connect_disconnect_notify(struct test_session *session) } } -static gboolean test_session_connect_disconnect(gpointer data) +static void test_session_connect_disconnect(struct test_fix *fix) { - struct test_fix *fix = data; struct test_session *session; /* @@ -374,8 +353,6 @@ static gboolean test_session_connect_disconnect(gpointer data) util_session_init(session); set_session_state(session, TEST_SESSION_STATE_0); - - return FALSE; } static void test_session_connect_free_ride_notify(struct test_session *session) @@ -396,6 +373,12 @@ static void test_session_connect_free_ride_notify(struct test_session *session) CONNMAN_SESSION_STATE_DISCONNECTED) { next_state = TEST_SESSION_STATE_1; } + if (session0->info->state == CONNMAN_SESSION_STATE_CONNECTED && + session1->info->state == + CONNMAN_SESSION_STATE_CONNECTED) { + LOG("state was already connected, continuing"); + next_state = TEST_SESSION_STATE_2; + } break; case TEST_SESSION_STATE_1: @@ -408,8 +391,12 @@ static void test_session_connect_free_ride_notify(struct test_session *session) break; case TEST_SESSION_STATE_2: if (session0->info->state == CONNMAN_SESSION_STATE_DISCONNECTED - && session1->info->state == - CONNMAN_SESSION_STATE_DISCONNECTED) { + && (session1->info->state == + CONNMAN_SESSION_STATE_DISCONNECTED || + session1->info->state == + CONNMAN_SESSION_STATE_CONNECTED) ) { + LOG("session0 /foo is disconnected, session1 /bar " + "can be either connected or disconnected"); next_state = TEST_SESSION_STATE_3; } @@ -432,14 +419,14 @@ static void test_session_connect_free_ride_notify(struct test_session *session) return; case TEST_SESSION_STATE_1: msg = session_connect(session0->connection, session0); - g_assert(msg != NULL); + g_assert(msg); dbus_message_unref(msg); return; case TEST_SESSION_STATE_2: msg = session_disconnect(session0->connection, session0); - g_assert(msg != NULL); + g_assert(msg); dbus_message_unref(msg); return; @@ -454,9 +441,8 @@ static void test_session_connect_free_ride_notify(struct test_session *session) } } -static gboolean test_session_connect_free_ride(gpointer data) +static void test_session_connect_free_ride(struct test_fix *fix) { - struct test_fix *fix = data; struct test_session *session0, *session1; /* @@ -496,8 +482,6 @@ static gboolean test_session_connect_free_ride(gpointer data) util_session_init(session1); set_session_state(session0, TEST_SESSION_STATE_0); - - return FALSE; } static void policy_save(GKeyFile *keyfile, char *pathname) @@ -508,7 +492,7 @@ static void policy_save(GKeyFile *keyfile, char *pathname) data = g_key_file_to_data(keyfile, &length, NULL); - if(!g_file_set_contents(pathname, data, length, &error)) { + if (!g_file_set_contents(pathname, data, length, &error)) { DBG("Failed to store information: %s", error->message); g_error_free(error); g_assert(0); @@ -528,7 +512,7 @@ static void policy_allowed_bearers(const char *allowed_bearers) uid = getuid(); pwd = getpwuid(uid); - g_assert(pwd != NULL); + g_assert(pwd); keyfile = g_key_file_new(); g_key_file_set_string(keyfile, "policy_foo", "uid", pwd->pw_name); @@ -588,7 +572,7 @@ static void test_session_policy_notify(struct test_session *session) policy_allowed_bearers("ethernet"); msg = session_connect(session->connection, session); - g_assert(msg != NULL); + g_assert(msg); dbus_message_unref(msg); return; case TEST_SESSION_STATE_2: @@ -605,9 +589,8 @@ static void test_session_policy_notify(struct test_session *session) } } -static gboolean test_session_policy(gpointer data) +static void test_session_policy(struct test_fix *fix) { - struct test_fix *fix = data; struct test_session *session; /* @@ -639,71 +622,48 @@ static gboolean test_session_policy(gpointer data) util_session_init(session); set_session_state(session, TEST_SESSION_STATE_0); - - return FALSE; } -static connman_bool_t is_online(struct test_fix *fix) +static bool is_online(struct test_fix *fix) { if (g_strcmp0(fix->manager.state, "online") == 0) - return TRUE; + return true; - return FALSE; + return false; } -static gboolean enable_session_mode(gpointer data) +static void enable_session_mode(struct test_fix *fix) { - struct test_fix *fix = data; - - set_session_mode(fix, TRUE); + set_session_mode(fix, true); - if (is_online(fix) == FALSE) + if (!is_online(fix)) util_idle_call(fix, util_quit_loop, NULL); - - return FALSE; } -static gboolean manager_state_changed(gpointer data) +static void manager_state_changed(struct test_fix *fix) { - struct test_fix *fix = data; - - if (is_online(fix) == FALSE) { + if (!is_online(fix)) { fix->manager_changed = NULL; util_idle_call(fix, util_quit_loop, NULL); } - - return FALSE; } -static gboolean disable_session_mode(gpointer data) +static void disable_session_mode(struct test_fix *fix) { - struct test_fix *fix = data; - - set_session_mode(fix, FALSE); - - return FALSE; + set_session_mode(fix, false); } -static void setup_cb(struct test_fix *fix, gconstpointer data) +static void setup_cb(struct test_fix *fix) { 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) +static void teardown_cb(struct test_fix *fix) { 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); } int main(int argc, char *argv[]) @@ -718,8 +678,8 @@ int main(int argc, char *argv[]) test_session_create, setup_cb, teardown_cb); util_test_add("/manager/session create destroy", test_session_create_destroy, setup_cb, teardown_cb); - util_test_add("/manager/session create already exists", - test_session_create_already_exists, setup_cb, teardown_cb); + util_test_add("/manager/session create duplicate notification", + test_session_create_dup_notification, setup_cb, teardown_cb); util_test_add("/manager/session create many", test_session_create_many, setup_cb, teardown_cb); |