Add unittests for wifi_aware_data_path_open 27/237027/2
authorCheoleun Moon <chleun.moon@samsung.com>
Wed, 24 Jun 2020 06:28:56 +0000 (15:28 +0900)
committerCheoleun Moon <chleun.moon@samsung.com>
Wed, 24 Jun 2020 06:30:57 +0000 (15:30 +0900)
Change-Id: I966dbfc0136f4ab68ea09e3c28ffef9d28599e3e

tests/unittest/mocks/wifi-aware-mock-gdbus-internal.c
tests/unittest/mocks/wifi-aware-mock-gdbus-internal.h
tests/unittest/wifi-aware-data-path-unittest-fixture.h
tests/unittest/wifi-aware-data-path-unittest.cpp
tests/unittest/wifi-aware-unittest-util.cpp
tests/unittest/wifi-aware-unittest-util.h
tests/unittest/wifi-aware-unittest.cpp

index 5b275ec..33bcfa4 100644 (file)
@@ -99,6 +99,12 @@ static GVariant *__cancel_subscribe_handler(GVariant *parameters)
        return g_variant_new("(i)", WIFI_AWARE_ERROR_NONE);
 }
 
+static GVariant *__open_data_path_handler(GVariant *parameters)
+{
+       _emit_gdbus_signal(DATA_PATH_OPENED);
+       return g_variant_new("(i)", WIFI_AWARE_ERROR_NONE);
+}
+
 struct {
        const gchar *interface_name;
        const gchar *method_name;
@@ -154,6 +160,24 @@ struct {
                __cancel_subscribe_handler,
        },
        {
+               "net.nan.discovery",
+               "OpenDataPath",
+               NULL,
+               __open_data_path_handler,
+       },
+       {
+               "net.nan.discovery",
+               "OpenDataPathPsk",
+               NULL,
+               __open_data_path_handler,
+       },
+       {
+               "net.nan.discovery",
+               "OpenDataPathPmk",
+               NULL,
+               __open_data_path_handler,
+       },
+       {
                NULL,
                NULL,
                NULL,
@@ -271,6 +295,18 @@ static void __message_received(GDBusSignalCallback callback, gpointer user_data)
        _signal_data.user_data = user_data;
 }
 
+static void __data_path_open_result(GDBusSignalCallback callback, gpointer user_data)
+{
+       if (!callback)
+               return;
+       _signal_data.callback = callback;
+       strncpy(_signal_data.signal_name, "DataPathOpenResult", 50);
+       _signal_data.parameters = g_variant_new("(ussii)", DUMMY_NDP_ID,
+                       DUMMY_NDP_IFACE, DUMMY_PEER_IP, DUMMY_PEER_PORT,
+                       WIFI_AWARE_ERROR_NONE);
+       _signal_data.user_data = user_data;
+}
+
 struct {
        const gchar *interface_name;
        const gchar *signal_name;
@@ -286,6 +322,11 @@ struct {
                "MessageReceived",
                __message_received,
        },
+       [DATA_PATH_OPENED] = {
+               "net.nan.discovery",
+               "DataPathOpenResult",
+               __data_path_open_result,
+       },
        {
                NULL,
                NULL,
index 81243c3..6e76a0f 100644 (file)
 #define DUMMY_PUBLISH_ID 1
 #define DUMMY_SUBSCRIBE_ID 1
 #define DUMMY_PEER_ID 1
+#define DUMMY_NDP_ID 1
+#define DUMMY_NDP_IFACE "ndp0"
+#define DUMMY_PEER_IP "fe80::0"
+#define DUMMY_PEER_PORT 1234
 #define DUMMY_DISTANCE 1
 #define MAC_ADDR_LEN 6
 
 typedef enum {
        SERVICE_DISCOVERED = 0,
        MESSAGE_RECEIVED,
+       DATA_PATH_OPENED,
 } wifi_aware_gdbus_signal_e;
 
 GDBusConnection *_get_dummy_gdbus_connection();
index 2526d71..9625676 100644 (file)
@@ -27,10 +27,11 @@ class WifiAwareDataPath : public WifiAware
 protected:
        virtual void SetUp()
        {
+               g_data_path_open = false;
                WifiAware::SetUp();
                g_session = __create_dummy_session(WIFI_AWARE_SESSION_SUBSCRIBE);
                g_peer = __create_dummy_peer();
-               g_data_path = __create_dummy_data_path();
+               g_data_path = __create_dummy_data_path(g_session, g_peer);
        }
 
        virtual void TearDown()
@@ -49,4 +50,6 @@ protected:
        wifi_aware_peer_h g_peer;
        wifi_aware_data_path_h g_data_path;
 
+public:
+       static bool g_data_path_open;
 };
index 665f20f..04fc0d4 100644 (file)
 #include "wifi-aware-data-path-unittest-fixture.h"
 #include "wifi-aware.h"
 
+bool WifiAwareDataPath::g_data_path_open;
+
+static void __open_cb(wifi_aware_data_path_h data_path, wifi_aware_error_e error,
+               void *user_data)
+{
+       WifiAwareDataPath::g_data_path_open = true;
+       QUIT_GMAIN_LOOP;
+}
+
 static void __terminated_cb(wifi_aware_data_path_h data_path,
                wifi_aware_termination_reason_e reason, void *user_data)
 {
@@ -156,12 +165,72 @@ 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)
+{
+       int ret = 0;
+
+       wifi_aware_enable(WifiAware::__enabled_cb, NULL);
+       RUN_GMAIN_LOOP;
+
+       ret = wifi_aware_data_path_open(g_data_path, __open_cb, NULL);
+       CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_data_path_open");
+       RUN_GMAIN_LOOP;
+
+       ASSERT_TRUE(WifiAwareDataPath::g_data_path_open) << "FAIL Data Path Open";
+       wifi_aware_disable();
+}
+
+TEST_F(WifiAwareDataPath, wifi_aware_data_path_open_p2)
+{
+       int ret = 0;
+
+       wifi_aware_enable(WifiAware::__enabled_cb, NULL);
+       RUN_GMAIN_LOOP;
+
+       wifi_aware_data_path_set_security(g_data_path, WIFI_AWARE_SECURITY_TYPE_PSK);
+       wifi_aware_data_path_set_psk(g_data_path, "12345678");
+
+       ret = wifi_aware_data_path_open(g_data_path, __open_cb, NULL);
+       CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_data_path_open");
+       RUN_GMAIN_LOOP;
+
+       ASSERT_TRUE(WifiAwareDataPath::g_data_path_open) << "FAIL Data Path Open";
+       wifi_aware_disable();
+}
+
+TEST_F(WifiAwareDataPath, wifi_aware_data_path_open_p3)
+{
+       int ret = 0;
+       unsigned char pmk[PMK_LEN] = {0, };
+
+       wifi_aware_enable(WifiAware::__enabled_cb, NULL);
+       RUN_GMAIN_LOOP;
+
+       wifi_aware_data_path_set_security(g_data_path, WIFI_AWARE_SECURITY_TYPE_PMK);
+       wifi_aware_data_path_set_pmk(g_data_path, pmk);
+
+       ret = wifi_aware_data_path_open(g_data_path, __open_cb, NULL);
+       CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_data_path_open");
+       RUN_GMAIN_LOOP;
+
+       ASSERT_TRUE(WifiAwareDataPath::g_data_path_open) << "FAIL Data Path Open";
+       wifi_aware_disable();
+}
+
 TEST_F(WifiAwareDataPath, wifi_aware_data_path_open_n)
 {
        int ret = 0;
 
-       ret = wifi_aware_data_path_open(NULL, NULL, NULL);
+       ret = wifi_aware_data_path_open(g_data_path, NULL, NULL);
        CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_OPERATION, ret, "wifi_aware_data_path_open");
+
+       wifi_aware_enable(WifiAware::__enabled_cb, NULL);
+       RUN_GMAIN_LOOP;
+
+       ret = wifi_aware_data_path_open(NULL, NULL, NULL);
+       CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_data_path_open");
+
+       wifi_aware_disable();
 }
 
 TEST_F(WifiAwareDataPath, wifi_aware_data_path_close_n)
index 531a0c6..bfa9056 100644 (file)
@@ -61,6 +61,29 @@ typedef struct {
 } __wifi_aware_peer_s;
 
 typedef struct {
+    uint16_t ttl;
+    wifi_aware_publish_type_e publish_type;
+    char service_name[MAX_SERVICE_NAME_LEN + 1];
+    uint8_t specific_info[MAX_SERVICE_SPECIFIC_INFO_LEN];
+    uint16_t specific_info_len;
+    uint8_t match_filter[MAX_MATCH_FILTER_LEN];
+    uint16_t match_filter_len;
+    bool enable_ranging;
+} __wifi_aware_publish_request_s;
+
+typedef struct {
+    uint16_t ttl;
+    wifi_aware_subscribe_type_e subscribe_type;
+    char service_name[MAX_SERVICE_NAME_LEN + 1];
+    uint8_t specific_info[MAX_SERVICE_SPECIFIC_INFO_LEN];
+    uint16_t specific_info_len;
+    uint8_t match_filter[MAX_MATCH_FILTER_LEN];
+    uint16_t match_filter_len;
+    int max_distance;
+    int min_distance;
+} __wifi_aware_subscribe_request_s;
+
+typedef struct {
        uint16_t pub_sub_id;
        wifi_aware_session_type_e session_type;
        wifi_aware_publish_h publish_config;
@@ -118,17 +141,54 @@ typedef struct {
        bool is_open;
 } __wifi_aware_data_path_s;
 
+static 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);
+       return config;
+}
+
+static 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_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);
+       return config;
+}
+
+static 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_s *session =
                (__wifi_aware_session_s *)g_try_malloc0(sizeof(__wifi_aware_session_s));
        session->pub_sub_id = 1;
        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);
 }
 
@@ -145,7 +205,7 @@ void __destroy_dummy_peer(wifi_aware_peer_h peer)
        g_free(peer);
 }
 
-wifi_aware_data_path_h __create_dummy_data_path()
+wifi_aware_data_path_h __create_dummy_data_path(wifi_aware_session_h session, wifi_aware_peer_h peer)
 {
        __wifi_aware_data_path_s *data_path =
                (__wifi_aware_data_path_s *)g_try_malloc0(sizeof(__wifi_aware_data_path_s));
@@ -154,6 +214,8 @@ wifi_aware_data_path_h __create_dummy_data_path()
        snprintf(data_path->iface_name, IFNAMSIZ, "ndp0");
        snprintf(data_path->peer_ip, IPV6_ADDR_STR_LEN, "fe80::0");
        data_path->is_open = true;
+       data_path->session = session;
+       data_path->peer = peer;
        return data_path;
 }
 
index 2fc1127..de16da0 100644 (file)
@@ -51,6 +51,9 @@
 #define SERVICE_NAME "NanService"
 #define SERVICE_INFO "ServiceInfo"
 #define MATCH_FILTER "Match Filter"
+#define MAX_SERVICE_NAME_LEN 255
+#define MAX_MATCH_FILTER_LEN 255
+#define MAX_SERVICE_SPECIFIC_INFO_LEN 1024
 #define MAX_PSK_LEN 63
 #define PMK_LEN 32
 #define DATA_PATH_PEER_PORT 1234
@@ -65,5 +68,5 @@ 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);
 void __destroy_dummy_session(wifi_aware_session_h session);
-wifi_aware_data_path_h __create_dummy_data_path();
+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);
index c16e218..fcd0a1e 100644 (file)
@@ -39,13 +39,8 @@ gboolean WifiAware::_wifi_aware_callback_timeout(gpointer data)
 
 void WifiAware::__enabled_cb(wifi_aware_error_e error, void *user_data)
 {
-       if (error == WIFI_AWARE_ERROR_NONE) {
-       //      LOGI("Successfully Enabled");
+       if (error == WIFI_AWARE_ERROR_NONE)
                WifiAware::g_enabled = true;
-       }
-       else {
-       //      LOGE("Fail to enable %s(%d)", _wifi_aware_error_to_string(error), error);
-       }
        QUIT_GMAIN_LOOP;
 }