diff options
author | Cheoleun Moon <chleun.moon@samsung.com> | 2020-06-29 13:26:13 +0900 |
---|---|---|
committer | Cheoleun Moon <chleun.moon@samsung.com> | 2020-06-29 13:26:17 +0900 |
commit | b9522cbff503de50de7d1917b6b22525b65bb88a (patch) | |
tree | bc22976c0e1e476d55bf7e49831c1279d2448bc1 | |
parent | ca17c8f8d997755bb504ccc3cd0122c5b09db8f6 (diff) | |
download | wifi-aware-b9522cbff503de50de7d1917b6b22525b65bb88a.tar.gz wifi-aware-b9522cbff503de50de7d1917b6b22525b65bb88a.tar.bz2 wifi-aware-b9522cbff503de50de7d1917b6b22525b65bb88a.zip |
Change-Id: I047c942eb31830514c718e587ed3ece9e9239e15
-rw-r--r-- | tests/unittest/mocks/wifi-aware-mock-gdbus-internal.c | 37 | ||||
-rw-r--r-- | tests/unittest/mocks/wifi-aware-mock-gdbus-internal.h | 1 | ||||
-rw-r--r-- | tests/unittest/mocks/wifi-aware-mock-interface.h | 1 | ||||
-rw-r--r-- | tests/unittest/wifi-aware-data-path-unittest-fixture.h | 13 | ||||
-rw-r--r-- | tests/unittest/wifi-aware-data-path-unittest.cpp | 29 | ||||
-rw-r--r-- | tests/unittest/wifi-aware-publish-unittest.cpp | 38 | ||||
-rw-r--r-- | tests/unittest/wifi-aware-session-unittest-fixture.h | 2 | ||||
-rw-r--r-- | tests/unittest/wifi-aware-session-unittest.cpp | 392 | ||||
-rw-r--r-- | tests/unittest/wifi-aware-unittest-fixture.h | 3 | ||||
-rw-r--r-- | tests/unittest/wifi-aware-unittest-util.cpp | 34 | ||||
-rw-r--r-- | tests/unittest/wifi-aware-unittest-util.h | 9 |
11 files changed, 316 insertions, 243 deletions
diff --git a/tests/unittest/mocks/wifi-aware-mock-gdbus-internal.c b/tests/unittest/mocks/wifi-aware-mock-gdbus-internal.c index a71da00..afb80d8 100644 --- a/tests/unittest/mocks/wifi-aware-mock-gdbus-internal.c +++ b/tests/unittest/mocks/wifi-aware-mock-gdbus-internal.c @@ -91,12 +91,25 @@ static GVariant *__cancel_subscribe_handler(GVariant *parameters) return g_variant_new("(i)", WIFI_AWARE_ERROR_NONE); } +static void __followup_handler(GVariant *parameters, GAsyncReadyCallback callback, gpointer user_data) +{ + _gdbus_async_result.callback = callback; + _gdbus_async_result.result = g_variant_new("(i)", WIFI_AWARE_ERROR_NONE); + _gdbus_async_result.user_data = user_data; + g_timeout_add(ASYNC_RESULT_DELAY, __reply_async_method, &_gdbus_async_result); +} + static GVariant *__open_data_path_handler(GVariant *parameters) { _emit_gdbus_signal(DATA_PATH_OPENED); return g_variant_new("(i)", WIFI_AWARE_ERROR_NONE); } +static GVariant *__close_data_path_handler(GVariant *parameters) +{ + return g_variant_new("(i)", WIFI_AWARE_ERROR_NONE); +} + struct { const gchar *interface_name; const gchar *method_name; @@ -153,6 +166,12 @@ struct { }, { "net.nan.discovery", + "Followup", + __followup_handler, + NULL, + }, + { + "net.nan.discovery", "OpenDataPath", NULL, __open_data_path_handler, @@ -170,6 +189,12 @@ struct { __open_data_path_handler, }, { + "net.nan.discovery", + "CloseDataPath", + NULL, + __close_data_path_handler, + }, + { NULL, NULL, NULL, @@ -287,6 +312,11 @@ static GVariant *__session_terminated() return g_variant_new("(qi)", DUMMY_PUBLISH_ID, WIFI_AWARE_TERMINATION_REASON_UNKNOWN); } +static GVariant *__data_path_terminated() +{ + return g_variant_new("(u)", DUMMY_NDP_ID); +} + struct { const gchar *interface_name; const gchar *signal_name; @@ -322,6 +352,13 @@ struct { NULL, NULL, }, + [DATA_PATH_TERMINATED] = { + "net.nan.discovery", + "DataPathTerminated", + __data_path_terminated, + NULL, + NULL, + }, { NULL, NULL, diff --git a/tests/unittest/mocks/wifi-aware-mock-gdbus-internal.h b/tests/unittest/mocks/wifi-aware-mock-gdbus-internal.h index fc2c85a..9c4b234 100644 --- a/tests/unittest/mocks/wifi-aware-mock-gdbus-internal.h +++ b/tests/unittest/mocks/wifi-aware-mock-gdbus-internal.h @@ -37,6 +37,7 @@ typedef enum { MESSAGE_RECEIVED, DATA_PATH_OPENED, SESSION_TERMINATED, + DATA_PATH_TERMINATED, } wifi_aware_gdbus_signal_e; GDBusConnection *_get_dummy_gdbus_connection(); diff --git a/tests/unittest/mocks/wifi-aware-mock-interface.h b/tests/unittest/mocks/wifi-aware-mock-interface.h index 2086ef1..984cba9 100644 --- a/tests/unittest/mocks/wifi-aware-mock-interface.h +++ b/tests/unittest/mocks/wifi-aware-mock-interface.h @@ -24,6 +24,7 @@ typedef enum { MESSAGE_RECEIVED, DATA_PATH_OPENED, SESSION_TERMINATED, + DATA_PATH_TERMINATED, } wifi_aware_gdbus_signal_e; void wifi_aware_mock_emit_gdbus_signal(wifi_aware_gdbus_signal_e signal); diff --git a/tests/unittest/wifi-aware-data-path-unittest-fixture.h b/tests/unittest/wifi-aware-data-path-unittest-fixture.h index 9625676..24ab41b 100644 --- a/tests/unittest/wifi-aware-data-path-unittest-fixture.h +++ b/tests/unittest/wifi-aware-data-path-unittest-fixture.h @@ -28,17 +28,22 @@ protected: virtual void SetUp() { g_data_path_open = false; + g_data_path_terminated = false; WifiAware::SetUp(); - g_session = __create_dummy_session(WIFI_AWARE_SESSION_SUBSCRIBE); + g_subscribe_config = __create_dummy_subscribe_config(); + g_session = __create_dummy_session(WIFI_AWARE_SESSION_SUBSCRIBE, 1); + __set_subscribe_config(g_session, g_subscribe_config); g_peer = __create_dummy_peer(); g_data_path = __create_dummy_data_path(g_session, g_peer); } virtual void TearDown() { - __destroy_dummy_session(g_session); - __destroy_dummy_peer(g_peer); __destroy_dummy_data_path(g_data_path); + __destroy_dummy_peer(g_peer); + __destroy_dummy_session(g_session); + __destroy_dummy_subscribe_config(g_subscribe_config); + g_subscribe_config = NULL; g_session = NULL; g_peer = NULL; g_data_path = NULL; @@ -46,10 +51,12 @@ protected: WifiAware::TearDown(); } + wifi_aware_subscribe_h g_subscribe_config; wifi_aware_session_h g_session; wifi_aware_peer_h g_peer; wifi_aware_data_path_h g_data_path; public: static bool g_data_path_open; + static bool g_data_path_terminated; }; diff --git a/tests/unittest/wifi-aware-data-path-unittest.cpp b/tests/unittest/wifi-aware-data-path-unittest.cpp index 04fc0d4..2f0d692 100644 --- a/tests/unittest/wifi-aware-data-path-unittest.cpp +++ b/tests/unittest/wifi-aware-data-path-unittest.cpp @@ -16,10 +16,12 @@ #include <gtest/gtest.h> -#include "wifi-aware-data-path-unittest-fixture.h" #include "wifi-aware.h" +#include "wifi-aware-data-path-unittest-fixture.h" +#include "wifi-aware-mock-interface.h" bool WifiAwareDataPath::g_data_path_open; +bool WifiAwareDataPath::g_data_path_terminated; static void __open_cb(wifi_aware_data_path_h data_path, wifi_aware_error_e error, void *user_data) @@ -31,6 +33,8 @@ static void __open_cb(wifi_aware_data_path_h data_path, wifi_aware_error_e error static void __terminated_cb(wifi_aware_data_path_h data_path, wifi_aware_termination_reason_e reason, void *user_data) { + WifiAwareDataPath::g_data_path_terminated = true; + QUIT_GMAIN_LOOP; } TEST_F(WifiAwareDataPath, wifi_aware_data_path_create_p) @@ -165,7 +169,7 @@ TEST_F(WifiAwareDataPath, wifi_aware_data_path_destroy_n) CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_data_path_destroy"); } -TEST_F(WifiAwareDataPath, wifi_aware_data_path_open_p1) +TEST_F(WifiAwareDataPath, wifi_aware_data_path_open_close_p1) { int ret = 0; @@ -177,10 +181,14 @@ TEST_F(WifiAwareDataPath, wifi_aware_data_path_open_p1) RUN_GMAIN_LOOP; ASSERT_TRUE(WifiAwareDataPath::g_data_path_open) << "FAIL Data Path Open"; + + ret = wifi_aware_data_path_close(g_data_path); + CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_data_path_close"); + wifi_aware_disable(); } -TEST_F(WifiAwareDataPath, wifi_aware_data_path_open_p2) +TEST_F(WifiAwareDataPath, wifi_aware_data_path_open_close_p2) { int ret = 0; @@ -195,10 +203,14 @@ TEST_F(WifiAwareDataPath, wifi_aware_data_path_open_p2) RUN_GMAIN_LOOP; ASSERT_TRUE(WifiAwareDataPath::g_data_path_open) << "FAIL Data Path Open"; + + ret = wifi_aware_data_path_close(g_data_path); + CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_data_path_close"); + wifi_aware_disable(); } -TEST_F(WifiAwareDataPath, wifi_aware_data_path_open_p3) +TEST_F(WifiAwareDataPath, wifi_aware_data_path_open_close_p3) { int ret = 0; unsigned char pmk[PMK_LEN] = {0, }; @@ -214,6 +226,10 @@ TEST_F(WifiAwareDataPath, wifi_aware_data_path_open_p3) RUN_GMAIN_LOOP; ASSERT_TRUE(WifiAwareDataPath::g_data_path_open) << "FAIL Data Path Open"; + + ret = wifi_aware_data_path_close(g_data_path); + CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_data_path_close"); + wifi_aware_disable(); } @@ -312,6 +328,11 @@ TEST_F(WifiAwareDataPath, wifi_aware_data_path_set_terminated_cb_p) ret = wifi_aware_data_path_set_terminated_cb(g_data_path, __terminated_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_data_path_set_terminated_cb"); + + wifi_aware_mock_emit_gdbus_signal(DATA_PATH_TERMINATED); + RUN_GMAIN_LOOP; + + ASSERT_TRUE(g_data_path_terminated) << "SessionTerminated signal"; } TEST_F(WifiAwareDataPath, wifi_aware_data_path_set_terminated_cb_n) diff --git a/tests/unittest/wifi-aware-publish-unittest.cpp b/tests/unittest/wifi-aware-publish-unittest.cpp index 25dd4a4..42b2558 100644 --- a/tests/unittest/wifi-aware-publish-unittest.cpp +++ b/tests/unittest/wifi-aware-publish-unittest.cpp @@ -120,19 +120,28 @@ TEST_F(WifiAwarePublish, wifi_aware_publish_set_service_specific_info_p) { int ret = 0; - unsigned char info[255] = {0, }; + unsigned char info[MAX_SERVICE_SPECIFIC_INFO_LEN] = {0, }; memcpy(info, SERVICE_INFO, strlen(SERVICE_INFO)); - ret = wifi_aware_publish_set_service_specific_info(g_publish_config, info, 10); + ret = wifi_aware_publish_set_service_specific_info(g_publish_config, info, strlen(SERVICE_INFO)); CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_publish_set_service_specific_info"); } -TEST_F(WifiAwarePublish, wifi_aware_publish_set_service_specific_info_n) +TEST_F(WifiAwarePublish, wifi_aware_publish_set_service_specific_info_n1) { int ret = 0; - unsigned char info[255] = {0, }; + unsigned char info[MAX_SERVICE_SPECIFIC_INFO_LEN] = {0, }; memcpy(info, SERVICE_INFO, strlen(SERVICE_INFO)); - ret = wifi_aware_publish_set_service_specific_info(NULL, info, 10); + ret = wifi_aware_publish_set_service_specific_info(NULL, info, strlen(SERVICE_INFO)); + CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_publish_set_service_specific_info"); +} + +TEST_F(WifiAwarePublish, wifi_aware_publish_set_service_specific_info_n2) +{ + int ret = 0; + + unsigned char info[MAX_SERVICE_SPECIFIC_INFO_LEN + 10] = {0, }; + ret = wifi_aware_publish_set_service_specific_info(NULL, info, sizeof(info)); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_publish_set_service_specific_info"); } @@ -140,19 +149,28 @@ TEST_F(WifiAwarePublish, wifi_aware_publish_set_match_filter_p) { int ret = 0; - unsigned char filter[255] = {0, }; + unsigned char filter[MAX_MATCH_FILTER_LEN] = {0, }; memcpy(filter, MATCH_FILTER, strlen(MATCH_FILTER)); - ret = wifi_aware_publish_set_match_filter(g_publish_config, filter, 12); + ret = wifi_aware_publish_set_match_filter(g_publish_config, filter, strlen(MATCH_FILTER)); CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_publish_set_match_filter"); } -TEST_F(WifiAwarePublish, wifi_aware_publish_set_match_filter_n) +TEST_F(WifiAwarePublish, wifi_aware_publish_set_match_filter_n1) { int ret = 0; - unsigned char filter[255] = {0, }; + unsigned char filter[MAX_MATCH_FILTER_LEN] = {0, }; memcpy(filter, MATCH_FILTER, strlen(MATCH_FILTER)); - ret = wifi_aware_publish_set_match_filter(NULL, filter, 12); + ret = wifi_aware_publish_set_match_filter(NULL, filter, strlen(MATCH_FILTER)); + CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_publish_set_match_filter"); +} + +TEST_F(WifiAwarePublish, wifi_aware_publish_set_match_filter_n2) +{ + int ret = 0; + + unsigned char filter[MAX_MATCH_FILTER_LEN + 10] = {0, }; + ret = wifi_aware_publish_set_match_filter(NULL, filter, sizeof(filter)); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_publish_set_match_filter"); } diff --git a/tests/unittest/wifi-aware-session-unittest-fixture.h b/tests/unittest/wifi-aware-session-unittest-fixture.h index 227a597..9346ef3 100644 --- a/tests/unittest/wifi-aware-session-unittest-fixture.h +++ b/tests/unittest/wifi-aware-session-unittest-fixture.h @@ -26,6 +26,7 @@ protected: g_published = false; g_subscribed = false; g_discovered = false; + g_message_sent = false; g_message_received = false; g_session_terminated = false; WifiAware::SetUp(); @@ -58,6 +59,7 @@ protected: static bool g_published; static bool g_subscribed; static bool g_discovered; + static bool g_message_sent; static bool g_message_received; static bool g_session_terminated; diff --git a/tests/unittest/wifi-aware-session-unittest.cpp b/tests/unittest/wifi-aware-session-unittest.cpp index 9a86e04..f66f397 100644 --- a/tests/unittest/wifi-aware-session-unittest.cpp +++ b/tests/unittest/wifi-aware-session-unittest.cpp @@ -16,13 +16,14 @@ #include <gtest/gtest.h> -#include "wifi-aware-session-unittest-fixture.h" #include "wifi-aware.h" +#include "wifi-aware-session-unittest-fixture.h" #include "wifi-aware-mock-interface.h" bool WifiAwareSession::g_published; bool WifiAwareSession::g_subscribed; bool WifiAwareSession::g_discovered; +bool WifiAwareSession::g_message_sent; bool WifiAwareSession::g_message_received; bool WifiAwareSession::g_session_terminated; @@ -51,6 +52,8 @@ void WifiAwareSession::__discovered_cb(wifi_aware_session_h session, wifi_aware_ void WifiAwareSession::__send_reply(wifi_aware_session_h session, wifi_aware_error_e error, void *user_data) { + g_message_sent = true; + QUIT_GMAIN_LOOP; } @@ -125,8 +128,7 @@ TEST_F(WifiAwareSession, wifi_aware_session_destroy_n) TEST_F(WifiAwareSession, wifi_aware_session_set_terminated_cb_p) { int ret = 0; - - wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH); + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 1); ret = wifi_aware_session_set_terminated_cb(session, __session_terminated_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_session_set_terminated_cb"); @@ -150,13 +152,12 @@ TEST_F(WifiAwareSession, wifi_aware_session_set_terminated_cb_n) TEST_F(WifiAwareSession, wifi_aware_session_unset_terminated_cb_p) { int ret = 0; + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 1); - wifi_aware_session_create(WIFI_AWARE_SESSION_PUBLISH, &g_session); - - ret = wifi_aware_session_unset_terminated_cb(g_session); + ret = wifi_aware_session_unset_terminated_cb(session); CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_session_unset_terminated_cb"); - wifi_aware_session_destroy(g_session); + __destroy_dummy_session(session); } TEST_F(WifiAwareSession, wifi_aware_session_unset_terminated_cb_n) @@ -170,21 +171,18 @@ TEST_F(WifiAwareSession, wifi_aware_session_unset_terminated_cb_n) TEST_F(WifiAwareSession, wifi_aware_session_publish_p) { int ret = 0; + wifi_aware_publish_h config = __create_dummy_publish_config(); + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 0); - wifi_aware_publish_create(&g_publish_config); - wifi_aware_publish_set_service_name(g_publish_config, SERVICE_NAME); - wifi_aware_session_create(WIFI_AWARE_SESSION_PUBLISH, &g_session); - - ret = wifi_aware_session_publish(g_session, - g_publish_config, WifiAwareSession::__published_cb, NULL); + ret = wifi_aware_session_publish(session, + config, WifiAwareSession::__published_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_session_publish"); RUN_GMAIN_LOOP; CHECK_RESULT(g_published, true, "wifi_aware_session_publish"); - wifi_aware_session_stop(g_session); - wifi_aware_session_destroy(g_session); - wifi_aware_publish_destroy(g_publish_config); + __destroy_dummy_session(session); + __destroy_dummy_publish_config(config); } /** @@ -194,27 +192,27 @@ TEST_F(WifiAwareSession, wifi_aware_session_publish_n1) { int ret = 0; - wifi_aware_publish_create(&g_publish_config); + wifi_aware_publish_h config = __create_dummy_publish_config(); - ret = wifi_aware_session_publish(NULL, g_publish_config, WifiAwareSession::__published_cb, NULL); + ret = wifi_aware_session_publish(NULL, config, WifiAwareSession::__published_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_session_publish"); - wifi_aware_publish_destroy(g_publish_config); + __destroy_dummy_publish_config(config); } /** - * g_publish_config is NULL + * publish configuration is NULL */ TEST_F(WifiAwareSession, wifi_aware_session_publish_n2) { int ret = 0; - wifi_aware_session_create(WIFI_AWARE_SESSION_PUBLISH, &g_session); + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 0); - ret = wifi_aware_session_publish(g_session, NULL, __published_cb, NULL); + ret = wifi_aware_session_publish(session, NULL, __published_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_session_publish"); - wifi_aware_session_destroy(g_session); + __destroy_dummy_session(session); } /** @@ -225,15 +223,14 @@ TEST_F(WifiAwareSession, wifi_aware_session_publish_n3) { int ret = 0; - wifi_aware_publish_create(&g_publish_config); + wifi_aware_publish_h config = __create_dummy_publish_config(); + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_SUBSCRIBE, 0); - wifi_aware_session_create(WIFI_AWARE_SESSION_SUBSCRIBE, &g_session); - - ret = wifi_aware_session_publish(g_session, g_publish_config, __published_cb, NULL); + ret = wifi_aware_session_publish(session, config, __published_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_OPERATION, ret, "wifi_aware_session_publish"); - wifi_aware_session_destroy(g_session); - wifi_aware_publish_destroy(g_publish_config); + __destroy_dummy_session(session); + __destroy_dummy_publish_config(config); } /** @@ -243,43 +240,38 @@ TEST_F(WifiAwareSession, wifi_aware_session_publish_n3) TEST_F(WifiAwareSession, wifi_aware_session_publish_n4) { int ret = 0; + wifi_aware_publish_h config = __create_dummy_publish_config(); + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 0); - wifi_aware_publish_create(&g_publish_config); - wifi_aware_publish_set_service_name(g_publish_config, SERVICE_NAME); - wifi_aware_session_create(WIFI_AWARE_SESSION_PUBLISH, &g_session); - - ret = wifi_aware_session_publish(g_session, g_publish_config, __published_cb, NULL); + ret = wifi_aware_session_publish(session, config, __published_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_session_publish"); - ret = wifi_aware_session_publish(g_session, g_publish_config, __published_cb, NULL); + ret = wifi_aware_session_publish(session, config, __published_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_NOW_IN_PROGRESS, ret, "wifi_aware_session_publish"); - wifi_aware_session_stop(g_session); - wifi_aware_session_destroy(g_session); - wifi_aware_publish_destroy(g_publish_config); + __destroy_dummy_session(session); + __destroy_dummy_publish_config(config); } TEST_F(WifiAwareSession, wifi_aware_session_update_publish_p) { int ret = 0; + wifi_aware_publish_h config = __create_dummy_publish_config(); + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 0); - wifi_aware_publish_create(&g_publish_config); - wifi_aware_publish_set_service_name(g_publish_config, SERVICE_NAME); - wifi_aware_session_create(WIFI_AWARE_SESSION_PUBLISH, &g_session); - wifi_aware_session_publish(g_session, g_publish_config, __published_cb, NULL); + wifi_aware_session_publish(session, config, __published_cb, NULL); RUN_GMAIN_LOOP; g_published = false; - ret = wifi_aware_session_update_publish(g_session, g_publish_config, __published_cb, NULL); + ret = wifi_aware_session_update_publish(session, config, __published_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_session_update_publish"); RUN_GMAIN_LOOP; CHECK_RESULT(g_published, true, "wifi_aware_session_update_publish"); - wifi_aware_session_stop(g_session); - wifi_aware_session_destroy(g_session); - wifi_aware_publish_destroy(g_publish_config); + __destroy_dummy_session(session); + __destroy_dummy_publish_config(config); } /** @@ -288,16 +280,14 @@ TEST_F(WifiAwareSession, wifi_aware_session_update_publish_p) TEST_F(WifiAwareSession, wifi_aware_session_update_publish_n1) { int ret = 0; + wifi_aware_publish_h config = __create_dummy_publish_config(); + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 0); - wifi_aware_publish_create(&g_publish_config); - wifi_aware_publish_set_service_name(g_publish_config, SERVICE_NAME); - wifi_aware_session_create(WIFI_AWARE_SESSION_PUBLISH, &g_session); - - ret = wifi_aware_session_update_publish(g_session, g_publish_config, __published_cb, NULL); + ret = wifi_aware_session_update_publish(session, config, __published_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_OPERATION, ret, "wifi_aware_session_update_publish"); - wifi_aware_session_destroy(g_session); - wifi_aware_publish_destroy(g_publish_config); + __destroy_dummy_session(session); + __destroy_dummy_publish_config(config); } /** @@ -306,28 +296,26 @@ TEST_F(WifiAwareSession, wifi_aware_session_update_publish_n1) TEST_F(WifiAwareSession, wifi_aware_session_update_publish_n2) { int ret = 0; + wifi_aware_publish_h config = __create_dummy_publish_config(); - wifi_aware_publish_create(&g_publish_config); - - ret = wifi_aware_session_update_publish(NULL, g_publish_config, __published_cb, NULL); + ret = wifi_aware_session_update_publish(NULL, config, __published_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_session_update_publish"); - wifi_aware_publish_destroy(g_publish_config); + __destroy_dummy_publish_config(config); } /** - * g_publish_config is NULL + * publish configuration is NULL */ TEST_F(WifiAwareSession, wifi_aware_session_update_publish_n3) { int ret = 0; + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 0); - wifi_aware_session_create(WIFI_AWARE_SESSION_PUBLISH, &g_session); - - ret = wifi_aware_session_update_publish(g_session, NULL, __published_cb, NULL); + ret = wifi_aware_session_update_publish(session, NULL, __published_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_session_update_publish"); - wifi_aware_session_destroy(g_session); + __destroy_dummy_session(session); } /** @@ -337,34 +325,30 @@ TEST_F(WifiAwareSession, wifi_aware_session_update_publish_n3) TEST_F(WifiAwareSession, wifi_aware_session_update_publish_n4) { int ret = 0; + wifi_aware_publish_h config = __create_dummy_publish_config(); + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 0); - wifi_aware_publish_create(&g_publish_config); - wifi_aware_session_create(WIFI_AWARE_SESSION_SUBSCRIBE, &g_session); - - ret = wifi_aware_session_update_publish(g_session, g_publish_config, __published_cb, NULL); + ret = wifi_aware_session_update_publish(session, config, __published_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_OPERATION, ret, "wifi_aware_session_update_publish"); - wifi_aware_session_destroy(g_session); - wifi_aware_publish_destroy(g_publish_config); + __destroy_dummy_session(session); + __destroy_dummy_publish_config(config); } TEST_F(WifiAwareSession, wifi_aware_session_subscribe_p) { int ret = 0; + wifi_aware_subscribe_h config = __create_dummy_subscribe_config(); + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_SUBSCRIBE, 0); - wifi_aware_subscribe_create(&g_subscribe_config); - wifi_aware_subscribe_set_service_name(g_subscribe_config, SERVICE_NAME); - wifi_aware_session_create(WIFI_AWARE_SESSION_SUBSCRIBE, &g_session); - - ret = wifi_aware_session_subscribe(g_session, g_subscribe_config, WifiAwareSession::__subscribed_cb, NULL); + ret = wifi_aware_session_subscribe(session, config, WifiAwareSession::__subscribed_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_session_subscribe"); RUN_GMAIN_LOOP; CHECK_RESULT(g_subscribed, true, "wifi_aware_session_subscribe"); - wifi_aware_session_stop(g_session); - wifi_aware_session_destroy(g_session); - wifi_aware_subscribe_destroy(g_subscribe_config); + __destroy_dummy_session(session); + __destroy_dummy_subscribe_config(config); } /** @@ -373,28 +357,26 @@ TEST_F(WifiAwareSession, wifi_aware_session_subscribe_p) TEST_F(WifiAwareSession, wifi_aware_session_subscribe_n1) { int ret = 0; + wifi_aware_subscribe_h config = __create_dummy_subscribe_config(); - wifi_aware_subscribe_create(&g_subscribe_config); - - ret = wifi_aware_session_subscribe(NULL, g_subscribe_config, WifiAwareSession::__subscribed_cb, NULL); + ret = wifi_aware_session_subscribe(NULL, config, WifiAwareSession::__subscribed_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_session_subscribe"); - wifi_aware_subscribe_destroy(g_subscribe_config); + __destroy_dummy_subscribe_config(config); } /** - * g_subscribe_config is NULL + * subscribe configuration is NULL */ TEST_F(WifiAwareSession, wifi_aware_session_subscribe_n2) { int ret = 0; + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_SUBSCRIBE, 0); - wifi_aware_session_create(WIFI_AWARE_SESSION_SUBSCRIBE, &g_session); - - ret = wifi_aware_session_subscribe(g_session, NULL, WifiAwareSession::__subscribed_cb, NULL); + ret = wifi_aware_session_subscribe(session, NULL, WifiAwareSession::__subscribed_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_session_subscribe"); - wifi_aware_session_destroy(g_session); + __destroy_dummy_session(session); } /** @@ -404,15 +386,14 @@ TEST_F(WifiAwareSession, wifi_aware_session_subscribe_n2) TEST_F(WifiAwareSession, wifi_aware_session_subscribe_n3) { int ret = 0; + wifi_aware_subscribe_h config = __create_dummy_subscribe_config(); + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 0); - wifi_aware_subscribe_create(&g_subscribe_config); - wifi_aware_session_create(WIFI_AWARE_SESSION_PUBLISH, &g_session); - - ret = wifi_aware_session_subscribe(g_session, g_subscribe_config, WifiAwareSession::__subscribed_cb, NULL); + ret = wifi_aware_session_subscribe(session, config, WifiAwareSession::__subscribed_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_OPERATION, ret, "wifi_aware_session_subscribe"); - wifi_aware_session_destroy(g_session); - wifi_aware_subscribe_destroy(g_subscribe_config); + __destroy_dummy_session(session); + __destroy_dummy_publish_config(config); } /** @@ -422,44 +403,37 @@ TEST_F(WifiAwareSession, wifi_aware_session_subscribe_n3) TEST_F(WifiAwareSession, wifi_aware_session_subscribe_n4) { int ret = 0; + wifi_aware_subscribe_h config = __create_dummy_subscribe_config(); + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_SUBSCRIBE, 0); - wifi_aware_subscribe_create(&g_subscribe_config); - wifi_aware_subscribe_set_service_name(g_subscribe_config, SERVICE_NAME); - wifi_aware_session_create(WIFI_AWARE_SESSION_SUBSCRIBE, &g_session); - - ret = wifi_aware_session_subscribe(g_session, g_subscribe_config, WifiAwareSession::__subscribed_cb, NULL); + ret = wifi_aware_session_subscribe(session, config, WifiAwareSession::__subscribed_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_session_subscribe"); - ret = wifi_aware_session_subscribe(g_session, g_subscribe_config, WifiAwareSession::__subscribed_cb, NULL); + ret = wifi_aware_session_subscribe(session, config, WifiAwareSession::__subscribed_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_NOW_IN_PROGRESS, ret, "wifi_aware_session_subscribe"); - wifi_aware_session_stop(g_session); - wifi_aware_session_destroy(g_session); - wifi_aware_subscribe_destroy(g_subscribe_config); - + __destroy_dummy_session(session); + __destroy_dummy_subscribe_config(config); } TEST_F(WifiAwareSession, wifi_aware_session_update_subscribe_p) { int ret = 0; + wifi_aware_subscribe_h config = __create_dummy_subscribe_config(); + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_SUBSCRIBE, 0); - wifi_aware_subscribe_create(&g_subscribe_config); - wifi_aware_subscribe_set_service_name(g_subscribe_config, SERVICE_NAME); - wifi_aware_session_create(WIFI_AWARE_SESSION_SUBSCRIBE, &g_session); - wifi_aware_session_subscribe(g_session, g_subscribe_config, __subscribed_cb, NULL); - + wifi_aware_session_subscribe(session, config, __subscribed_cb, NULL); RUN_GMAIN_LOOP; g_subscribed = false; - ret = wifi_aware_session_update_subscribe(g_session, g_subscribe_config, __subscribed_cb, NULL); + ret = wifi_aware_session_update_subscribe(session, config, __subscribed_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_session_update_subscribe"); RUN_GMAIN_LOOP; CHECK_RESULT(g_subscribed, true, "wifi_aware_session_update_subscribe"); - wifi_aware_session_stop(g_session); - wifi_aware_session_destroy(g_session); - wifi_aware_subscribe_destroy(g_subscribe_config); + __destroy_dummy_session(session); + __destroy_dummy_subscribe_config(config); } /** @@ -468,16 +442,14 @@ TEST_F(WifiAwareSession, wifi_aware_session_update_subscribe_p) TEST_F(WifiAwareSession, wifi_aware_session_update_subscribe_n1) { int ret = 0; + wifi_aware_subscribe_h config = __create_dummy_subscribe_config(); + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_SUBSCRIBE, 0); - wifi_aware_subscribe_create(&g_subscribe_config); - wifi_aware_subscribe_set_service_name(g_subscribe_config, SERVICE_NAME); - wifi_aware_session_create(WIFI_AWARE_SESSION_SUBSCRIBE, &g_session); - - ret = wifi_aware_session_update_subscribe(g_session, g_subscribe_config, __subscribed_cb, NULL); + ret = wifi_aware_session_update_subscribe(session, config, __subscribed_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_OPERATION, ret, "wifi_aware_session_update_subscribe"); - wifi_aware_session_destroy(g_session); - wifi_aware_subscribe_destroy(g_subscribe_config); + __destroy_dummy_session(session); + __destroy_dummy_subscribe_config(config); } /** @@ -486,28 +458,26 @@ TEST_F(WifiAwareSession, wifi_aware_session_update_subscribe_n1) TEST_F(WifiAwareSession, wifi_aware_session_update_subscribe_n2) { int ret = 0; + wifi_aware_subscribe_h config = __create_dummy_subscribe_config(); - wifi_aware_subscribe_create(&g_subscribe_config); - - ret = wifi_aware_session_update_subscribe(NULL, g_subscribe_config, __subscribed_cb, NULL); + ret = wifi_aware_session_update_subscribe(NULL, config, __subscribed_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_session_update_subscribe"); - wifi_aware_subscribe_destroy(g_subscribe_config); + __destroy_dummy_subscribe_config(config); } /** - * g_subscribe_config is NULL + * subscribe configuration is NULL */ TEST_F(WifiAwareSession, wifi_aware_session_update_subscribe_n3) { int ret = 0; + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_SUBSCRIBE, 0); - wifi_aware_session_create(WIFI_AWARE_SESSION_SUBSCRIBE, &g_session); - - ret = wifi_aware_session_update_subscribe(g_session, NULL, __subscribed_cb, NULL); + ret = wifi_aware_session_update_subscribe(session, NULL, __subscribed_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_session_update_subscribe"); - wifi_aware_session_destroy(g_session); + __destroy_dummy_session(session); } /** @@ -517,52 +487,54 @@ TEST_F(WifiAwareSession, wifi_aware_session_update_subscribe_n3) TEST_F(WifiAwareSession, wifi_aware_session_update_subscribe_n4) { int ret = 0; + wifi_aware_subscribe_h config = __create_dummy_subscribe_config(); + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 0); - wifi_aware_subscribe_create(&g_subscribe_config); - wifi_aware_session_create(WIFI_AWARE_SESSION_PUBLISH, &g_session); - - ret = wifi_aware_session_update_subscribe(g_session, g_subscribe_config, __subscribed_cb, NULL); + ret = wifi_aware_session_update_subscribe(session, config, __subscribed_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_OPERATION, ret, "wifi_aware_session_update_subscribe"); - wifi_aware_session_destroy(g_session); - wifi_aware_subscribe_destroy(g_subscribe_config); + __destroy_dummy_session(session); + __destroy_dummy_subscribe_config(config); } -TEST_F(WifiAwareSession, wifi_aware_session_stop_p) +TEST_F(WifiAwareSession, wifi_aware_session_stop_p1) { int ret = 0; + wifi_aware_publish_h config = __create_dummy_publish_config(); + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 1); - wifi_aware_publish_create(&g_publish_config); - wifi_aware_publish_set_service_name(g_publish_config, SERVICE_NAME); - wifi_aware_session_create(WIFI_AWARE_SESSION_PUBLISH, &g_session); - wifi_aware_session_publish(g_session, g_publish_config, __published_cb, NULL); + ret = wifi_aware_session_stop(session); + CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_session_stop"); - RUN_GMAIN_LOOP; + __destroy_dummy_session(session); + __destroy_dummy_publish_config(config); +} - ret = wifi_aware_session_stop(g_session); +TEST_F(WifiAwareSession, wifi_aware_session_stop_p2) +{ + int ret = 0; + wifi_aware_subscribe_h config = __create_dummy_subscribe_config(); + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_SUBSCRIBE, 1); + + ret = wifi_aware_session_stop(session); CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_session_stop"); - wifi_aware_session_destroy(g_session); - wifi_aware_publish_destroy(g_publish_config); + __destroy_dummy_session(session); + __destroy_dummy_subscribe_config(config); } - /** * Session has not been published */ TEST_F(WifiAwareSession, wifi_aware_session_stop_n1) { int ret = 0; + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 0); - wifi_aware_publish_create(&g_publish_config); - wifi_aware_publish_set_service_name(g_publish_config, SERVICE_NAME); - wifi_aware_session_create(WIFI_AWARE_SESSION_PUBLISH, &g_session); - - ret = wifi_aware_session_stop(g_session); + ret = wifi_aware_session_stop(session); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_OPERATION, ret, "wifi_aware_session_stop"); - wifi_aware_session_destroy(g_session); - wifi_aware_publish_destroy(g_publish_config); + __destroy_dummy_session(session); } /** @@ -571,16 +543,12 @@ TEST_F(WifiAwareSession, wifi_aware_session_stop_n1) TEST_F(WifiAwareSession, wifi_aware_session_stop_n2) { int ret = 0; + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 0); - wifi_aware_subscribe_create(&g_subscribe_config); - wifi_aware_subscribe_set_service_name(g_subscribe_config, SERVICE_NAME); - wifi_aware_session_create(WIFI_AWARE_SESSION_SUBSCRIBE, &g_session); - - ret = wifi_aware_session_stop(g_session); + ret = wifi_aware_session_stop(session); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_OPERATION, ret, "wifi_aware_session_stop"); - wifi_aware_session_destroy(g_session); - wifi_aware_subscribe_destroy(g_subscribe_config); + __destroy_dummy_session(session); } /** @@ -597,19 +565,18 @@ TEST_F(WifiAwareSession, wifi_aware_session_stop_n3) TEST_F(WifiAwareSession, wifi_aware_session_set_service_discovered_cb_p) { int ret = 0; + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_SUBSCRIBE, 1); - wifi_aware_session_create(WIFI_AWARE_SESSION_SUBSCRIBE, &g_session); - - ret = wifi_aware_session_set_service_discovered_cb(g_session, __discovered_cb, NULL); + ret = wifi_aware_session_set_service_discovered_cb(session, __discovered_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_session_set_service_discovered_cb"); - wifi_aware_session_destroy(g_session); + __destroy_dummy_session(session); } // wifi_aware_service_discovered_cb is called TEST_F(WifiAwareSession, wifi_aware_service_discovered_cb_p) { - wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_SUBSCRIBE); + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_SUBSCRIBE, 1); wifi_aware_session_set_service_discovered_cb(session, __discovered_cb, NULL); @@ -624,7 +591,7 @@ TEST_F(WifiAwareSession, wifi_aware_service_discovered_cb_p) // wifi_aware_service_discovered_cb is not called TEST_F(WifiAwareSession, wifi_aware_service_discovered_cb_n) { - wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_SUBSCRIBE); + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_SUBSCRIBE, 1); wifi_aware_session_set_service_discovered_cb(session, __discovered_cb, NULL); RUN_GMAIN_LOOP; @@ -645,38 +612,36 @@ TEST_F(WifiAwareSession, wifi_aware_session_set_service_discovered_cb_n1) TEST_F(WifiAwareSession, wifi_aware_session_set_service_discovered_cb_n2) { int ret = 0; + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 1); - wifi_aware_session_create(WIFI_AWARE_SESSION_PUBLISH, &g_session); - - ret = wifi_aware_session_set_service_discovered_cb(g_session, __discovered_cb, NULL); + ret = wifi_aware_session_set_service_discovered_cb(session, __discovered_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_OPERATION, ret, "wifi_aware_session_set_service_discovered_cb"); - wifi_aware_session_destroy(g_session); + __destroy_dummy_session(session); } TEST_F(WifiAwareSession, wifi_aware_session_set_service_discovered_cb_n3) { int ret = 0; + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_SUBSCRIBE, 1); - wifi_aware_session_create(WIFI_AWARE_SESSION_SUBSCRIBE, &g_session); - - ret = wifi_aware_session_set_service_discovered_cb(g_session, NULL, NULL); + ret = wifi_aware_session_set_service_discovered_cb(session, NULL, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_session_set_service_discovered_cb"); - wifi_aware_session_destroy(g_session); + __destroy_dummy_session(session); } TEST_F(WifiAwareSession, wifi_aware_session_unset_service_discovered_cb_p) { int ret = 0; + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_SUBSCRIBE, 1); - wifi_aware_session_create(WIFI_AWARE_SESSION_SUBSCRIBE, &g_session); - wifi_aware_session_set_service_discovered_cb(g_session, __discovered_cb, NULL); + wifi_aware_session_set_service_discovered_cb(session, __discovered_cb, NULL); - ret = wifi_aware_session_unset_service_discovered_cb(g_session); + ret = wifi_aware_session_unset_service_discovered_cb(session); CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_session_unset_service_discovered_cb"); - wifi_aware_session_destroy(g_session); + __destroy_dummy_session(session); } TEST_F(WifiAwareSession, wifi_aware_session_unset_service_discovered_cb_n) @@ -687,40 +652,57 @@ TEST_F(WifiAwareSession, wifi_aware_session_unset_service_discovered_cb_n) CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_session_unset_service_discovered_cb"); } -TEST_F(WifiAwareSession, wifi_aware_session_send_message_n1) +TEST_F(WifiAwareSession, wifi_aware_session_send_message_p) { int ret = 0; unsigned char message[255] = {0, }; - memcpy(message, "MESSAGE", 7); + memcpy(message, MESSAGE, strlen(MESSAGE)); + + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 1); + wifi_aware_peer_h peer = __create_dummy_peer(); + + ret = wifi_aware_session_send_message(session, peer, message, strlen(MESSAGE), __send_reply, NULL); + CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_session_send_message"); + RUN_GMAIN_LOOP; + + ASSERT_TRUE(g_message_sent) << "Followup message"; - wifi_aware_session_create(WIFI_AWARE_SESSION_SUBSCRIBE, &g_session); + __destroy_dummy_peer(peer); + __destroy_dummy_session(session); +} - ret = wifi_aware_session_send_message(g_session, NULL, message, 7, __send_reply, NULL); +TEST_F(WifiAwareSession, wifi_aware_session_send_message_n1) +{ + int ret = 0; + unsigned char message[255] = {0, }; + memcpy(message, MESSAGE, strlen(MESSAGE)); + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 1); + + ret = wifi_aware_session_send_message(session, NULL, message, strlen(MESSAGE), __send_reply, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_session_send_message"); - wifi_aware_session_destroy(g_session); + __destroy_dummy_session(session); } TEST_F(WifiAwareSession, wifi_aware_session_send_message_n2) { int ret = 0; unsigned char message[255] = {0, }; - memcpy(message, "MESSAGE", 7); + memcpy(message, MESSAGE, strlen(MESSAGE)); - ret = wifi_aware_session_send_message(NULL, NULL, message, 7, __send_reply, NULL); + ret = wifi_aware_session_send_message(NULL, NULL, message, strlen(MESSAGE), __send_reply, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_session_send_message"); } TEST_F(WifiAwareSession, wifi_aware_session_set_message_received_cb_p) { int ret = 0; + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 1); - wifi_aware_session_create(WIFI_AWARE_SESSION_SUBSCRIBE, &g_session); - - ret = wifi_aware_session_set_message_received_cb(g_session, WifiAwareSession::__received_cb, NULL); + ret = wifi_aware_session_set_message_received_cb(session, WifiAwareSession::__received_cb, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_session_set_message_received_cb"); - wifi_aware_session_destroy(g_session); + __destroy_dummy_session(session); } TEST_F(WifiAwareSession, wifi_aware_session_set_message_received_cb_n1) @@ -734,26 +716,25 @@ TEST_F(WifiAwareSession, wifi_aware_session_set_message_received_cb_n1) TEST_F(WifiAwareSession, wifi_aware_session_set_message_received_cb_n2) { int ret = 0; + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 1); - wifi_aware_session_create(WIFI_AWARE_SESSION_SUBSCRIBE, &g_session); - - ret = wifi_aware_session_set_message_received_cb(g_session, NULL, NULL); + ret = wifi_aware_session_set_message_received_cb(session, NULL, NULL); CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_session_set_message_received_cb"); - wifi_aware_session_destroy(g_session); + __destroy_dummy_session(session); } TEST_F(WifiAwareSession, wifi_aware_session_unset_message_received_cb_p) { int ret = 0; + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 1); - wifi_aware_session_create(WIFI_AWARE_SESSION_SUBSCRIBE, &g_session); - wifi_aware_session_set_message_received_cb(g_session, WifiAwareSession::__received_cb, NULL); + wifi_aware_session_set_message_received_cb(session, WifiAwareSession::__received_cb, NULL); - ret = wifi_aware_session_unset_message_received_cb(g_session); + ret = wifi_aware_session_unset_message_received_cb(session); CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_session_unset_message_received_cb"); - wifi_aware_session_destroy(g_session); + __destroy_dummy_session(session); } TEST_F(WifiAwareSession, wifi_aware_session_unset_message_received_cb_n) @@ -766,12 +747,9 @@ TEST_F(WifiAwareSession, wifi_aware_session_unset_message_received_cb_n) TEST_F(WifiAwareSession, wifi_aware_message_received_cb_p) { - wifi_aware_publish_create(&g_publish_config); - wifi_aware_publish_set_service_name(g_publish_config, SERVICE_NAME); - wifi_aware_session_create(WIFI_AWARE_SESSION_PUBLISH, &g_session); + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 1); - wifi_aware_session_set_message_received_cb(g_session, WifiAwareSession::__received_cb, NULL); - wifi_aware_session_publish(g_session, g_publish_config, WifiAwareSession::__published_cb, NULL); + wifi_aware_session_set_message_received_cb(session, WifiAwareSession::__received_cb, NULL); RUN_GMAIN_LOOP; wifi_aware_mock_emit_gdbus_signal(MESSAGE_RECEIVED); @@ -779,26 +757,22 @@ TEST_F(WifiAwareSession, wifi_aware_message_received_cb_p) ASSERT_TRUE(g_message_received) << "MessageReceived signal"; - wifi_aware_session_stop(g_session); - wifi_aware_session_destroy(g_session); - wifi_aware_publish_destroy(g_publish_config); + __destroy_dummy_session(session); } TEST_F(WifiAwareSession, wifi_aware_message_received_cb_n) { - wifi_aware_publish_create(&g_publish_config); - wifi_aware_publish_set_service_name(g_publish_config, SERVICE_NAME); - wifi_aware_session_create(WIFI_AWARE_SESSION_PUBLISH, &g_session); + wifi_aware_publish_h config = __create_dummy_publish_config(); + wifi_aware_session_h session = __create_dummy_session(WIFI_AWARE_SESSION_PUBLISH, 1); - wifi_aware_session_set_message_received_cb(g_session, WifiAwareSession::__received_cb, NULL); - wifi_aware_session_publish(g_session, g_publish_config, WifiAwareSession::__published_cb, NULL); + wifi_aware_session_set_message_received_cb(session, WifiAwareSession::__received_cb, NULL); + wifi_aware_session_publish(session, config, WifiAwareSession::__published_cb, NULL); RUN_GMAIN_LOOP; RUN_GMAIN_LOOP; CHECK_RESULT(false, g_message_received, "message_received_cb"); - wifi_aware_session_stop(g_session); - wifi_aware_session_destroy(g_session); - wifi_aware_publish_destroy(g_publish_config); + __destroy_dummy_session(session); + __destroy_dummy_publish_config(config); } diff --git a/tests/unittest/wifi-aware-unittest-fixture.h b/tests/unittest/wifi-aware-unittest-fixture.h index 72dac90..fb14af7 100644 --- a/tests/unittest/wifi-aware-unittest-fixture.h +++ b/tests/unittest/wifi-aware-unittest-fixture.h @@ -32,7 +32,8 @@ protected: if (system_info_get_platform_bool(WIFI_AWARE_FEATURE, &WifiAware::g_wifi_aware_supported) != SYSTEM_INFO_ERROR_NONE) ASSERT_TRUE(true) << "FAIL system_info_get_platform_bool"; - wifi_aware_initialize(); + else + wifi_aware_initialize(); } virtual void TearDown() diff --git a/tests/unittest/wifi-aware-unittest-util.cpp b/tests/unittest/wifi-aware-unittest-util.cpp index d4d023c..2db16e4 100644 --- a/tests/unittest/wifi-aware-unittest-util.cpp +++ b/tests/unittest/wifi-aware-unittest-util.cpp @@ -141,57 +141,61 @@ typedef struct { bool is_open; } __wifi_aware_data_path_s; -static wifi_aware_publish_h __create_dummy_publish_config() +wifi_aware_publish_h __create_dummy_publish_config() { __wifi_aware_publish_request_s *config = (__wifi_aware_publish_request_s *)g_try_malloc0(sizeof(__wifi_aware_publish_request_s)); config->publish_type = WIFI_AWARE_PUBLISH_TYPE_UNSOLICITED; strncpy(config->service_name, SERVICE_NAME, MAX_SERVICE_NAME_LEN + 1); + memcpy(config->specific_info, SERVICE_INFO, strlen(SERVICE_INFO)); + config->specific_info_len = strlen(SERVICE_INFO); + memcpy(config->match_filter, MATCH_FILTER, strlen(MATCH_FILTER)); + config->match_filter_len = strlen(MATCH_FILTER); return config; } -static void __destroy_dummy_publish_config(wifi_aware_publish_h config) +void __destroy_dummy_publish_config(wifi_aware_publish_h config) { g_free(config); } -static wifi_aware_subscribe_h __create_dummy_subscribe_config() +wifi_aware_subscribe_h __create_dummy_subscribe_config() { __wifi_aware_subscribe_request_s *config = (__wifi_aware_subscribe_request_s *)g_try_malloc0(sizeof(__wifi_aware_subscribe_request_s)); config->subscribe_type = WIFI_AWARE_SUBSCRIBE_TYPE_PASSIVE; strncpy(config->service_name, SERVICE_NAME, MAX_SERVICE_NAME_LEN + 1); + memcpy(config->specific_info, SERVICE_INFO, strlen(SERVICE_INFO)); + config->specific_info_len = strlen(SERVICE_INFO); + memcpy(config->match_filter, MATCH_FILTER, strlen(MATCH_FILTER)); + config->match_filter_len = strlen(MATCH_FILTER); return config; } -static void __destroy_dummy_subscribe_config(wifi_aware_subscribe_h config) +void __destroy_dummy_subscribe_config(wifi_aware_subscribe_h config) { g_free(config); } -wifi_aware_session_h __create_dummy_session(wifi_aware_session_type_e type) +wifi_aware_session_h __create_dummy_session(wifi_aware_session_type_e type, bool is_created) { __wifi_aware_session_s *session = (__wifi_aware_session_s *)g_try_malloc0(sizeof(__wifi_aware_session_s)); - session->pub_sub_id = 1; + session->pub_sub_id = is_created ? 1 : 0; session->session_type = type; - if (type == WIFI_AWARE_SESSION_PUBLISH) - session->publish_config = __create_dummy_publish_config(); - else - session->subscribe_config = __create_dummy_subscribe_config(); return session; } void __destroy_dummy_session(wifi_aware_session_h session) { - __wifi_aware_session_s *s = (__wifi_aware_session_s *)session; - if (s->session_type == WIFI_AWARE_SESSION_PUBLISH) - __destroy_dummy_publish_config(s->publish_config); - else - __destroy_dummy_subscribe_config(s->subscribe_config); g_free(session); } +void __set_subscribe_config(wifi_aware_session_h session, wifi_aware_subscribe_h config) +{ + ((__wifi_aware_session_s *)session)->subscribe_config = config; +} + wifi_aware_peer_h __create_dummy_peer() { __wifi_aware_peer_s *peer = (__wifi_aware_peer_s *)g_try_malloc0(sizeof(__wifi_aware_peer_s)); diff --git a/tests/unittest/wifi-aware-unittest-util.h b/tests/unittest/wifi-aware-unittest-util.h index de16da0..e46d6b2 100644 --- a/tests/unittest/wifi-aware-unittest-util.h +++ b/tests/unittest/wifi-aware-unittest-util.h @@ -51,9 +51,11 @@ #define SERVICE_NAME "NanService" #define SERVICE_INFO "ServiceInfo" #define MATCH_FILTER "Match Filter" +#define MESSAGE "MESSAGE" #define MAX_SERVICE_NAME_LEN 255 #define MAX_MATCH_FILTER_LEN 255 #define MAX_SERVICE_SPECIFIC_INFO_LEN 1024 +#define MAX_MESSAGE_LEN MAX_SERVICE_SPECIFIC_INFO_LEN #define MAX_PSK_LEN 63 #define PMK_LEN 32 #define DATA_PATH_PEER_PORT 1234 @@ -66,7 +68,12 @@ const char *_convert_error_to_string(wifi_aware_error_e error); wifi_aware_peer_h __create_dummy_peer(); void __destroy_dummy_peer(wifi_aware_peer_h peer); -wifi_aware_session_h __create_dummy_session(wifi_aware_session_type_e type); +wifi_aware_publish_h __create_dummy_publish_config(); +void __destroy_dummy_publish_config(wifi_aware_publish_h config); +wifi_aware_subscribe_h __create_dummy_subscribe_config(); +void __destroy_dummy_subscribe_config(wifi_aware_subscribe_h config); +wifi_aware_session_h __create_dummy_session(wifi_aware_session_type_e type, bool is_created); void __destroy_dummy_session(wifi_aware_session_h session); +void __set_subscribe_config(wifi_aware_session_h session, wifi_aware_subscribe_h config); wifi_aware_data_path_h __create_dummy_data_path(wifi_aware_session_h session, wifi_aware_peer_h peer); void __destroy_dummy_data_path(wifi_aware_data_path_h data_path); |