Add test case for get supported channels CAPI 95/242195/1
authorYu <jiung.yu@samsung.com>
Tue, 25 Aug 2020 02:14:29 +0000 (11:14 +0900)
committerYu <jiung.yu@samsung.com>
Tue, 25 Aug 2020 02:14:32 +0000 (11:14 +0900)
Change-Id: If31207712aebd3df3a14412f57f3104fcafc71cd
Signed-off-by: Yu jiung <jiung.yu@samsung.com>
packaging/capi-network-wifi-direct.spec
src/wifi-direct-client-proxy.c
tests/gtest-wifi-direct.cpp
tests/include/WifiDirectManager.h
tests/mocks/WifiDirectManager/WifiDirectManager.cpp

index 723cda5..446079c 100755 (executable)
@@ -3,7 +3,7 @@
 
 Name:       capi-network-wifi-direct
 Summary:    Network WiFi-Direct Library
-Version:    1.3.2
+Version:    1.3.3
 Release:    1
 Group:      Network & Connectivity/API
 License:    Apache-2.0
index dbe636c..4b6376c 100755 (executable)
@@ -2369,11 +2369,7 @@ int wifi_direct_foreach_supported_channel(wifi_direct_supported_channel_cb cb, v
        int ret = WIFI_DIRECT_ERROR_NONE;
        unsigned int channel;
 
-       if (g_client_info.is_registered == false) {
-               WDC_LOGE("Client is NOT registered");
-               __WDC_LOG_FUNC_END__;
-               return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
-       }
+       CHECK_INITIALIZED();
 
        if (!cb) {
                WDC_LOGE("NULL Param [callback]!");
index 9e41a1e..7e4a3ed 100644 (file)
@@ -2597,6 +2597,43 @@ TEST_F(WifiDirectSettingTest, wifi_direct_init_miracast_Negative)
        wifi_direct_manager_mock_generate_activation_signal();
 }
 
+bool wifi_direct_foreach_supported_channel_cb(unsigned int channel, void *user_data)
+{
+       return true;
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_foreach_supported_channel_Positive)
+{
+       int ret;
+
+       ret = wifi_direct_foreach_supported_channel(wifi_direct_foreach_supported_channel_cb, nullptr);
+       ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_foreach_supported_channel_Negative1)
+{
+       int ret = wifi_direct_foreach_supported_channel(nullptr, nullptr);
+       ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_foreach_supported_channel_Negative2)
+{
+       int ret;
+
+       ret = wifi_direct_deactivate();
+       ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+       wifi_direct_manager_mock_generate_deactivation_signal();
+
+       ret = wifi_direct_foreach_supported_channel(wifi_direct_foreach_supported_channel_cb, nullptr);
+       ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+       ret = wifi_direct_activate();
+       ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+       wifi_direct_manager_mock_generate_activation_signal();
+}
+
 class WifiDirectConnectTest : public ::testing::Test {
 protected:
        void SetUp() override
index 43a002b..b81e18e 100644 (file)
@@ -135,6 +135,7 @@ public:
        GError *disconnect(std::string &mac_addr);
        GError *getConnectedPeers(GVariant **ret);
        GError *GetConnectingPeer(GVariant **ret);
+       GError *getSupportedChannels(GVariant **ret);
 
        GVariant *getPeerInfoGvariant(void);
        GVariant *getDiscoveredPeersGvariant(void);
index 80b056f..4480982 100644 (file)
@@ -2093,7 +2093,6 @@ private:
        WifiDirectManager *mgr_;
 };
 
-
 class GetWpsPinHandler : WifiDirectMethod {
 public:
        GetWpsPinHandler(WifiDirectManager *mgr) : mgr_(mgr){};
@@ -2115,6 +2114,31 @@ private:
                        "GetWpsPin";
        WifiDirectManager *mgr_;
 };
+
+class GetSupportedChannelsHandler : WifiDirectMethod {
+public:
+       GetSupportedChannelsHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+       ~GetSupportedChannelsHandler()
+       {
+       };
+       GVariant *handleMethod(GVariant *parameters, GError **error) override
+       {
+               GVariant *ret = NULL;
+
+               *error = mgr_->getSupportedChannels(&ret);
+
+               return ret;
+       }
+       std::string getMethodName()
+       {
+               return method_name_;
+       }
+private:
+       const std::string method_name_ =
+                       "GetSupportedChannels";
+       WifiDirectManager *mgr_;
+};
+
 WifiDirectManager::WifiDirectManager()
 {
        this->group_ = nullptr;
@@ -2362,6 +2386,9 @@ WifiDirectManager::WifiDirectManager()
        GetWpsPinHandler *get_wps_pin_handler = new GetWpsPinHandler(this);
        this->method_map_[get_wps_pin_handler->getMethodName()] = (WifiDirectMethod *)get_wps_pin_handler;
 
+       GetSupportedChannelsHandler *get_supported_channels_handler = new GetSupportedChannelsHandler(this);
+       this->method_map_[get_supported_channels_handler->getMethodName()] = (WifiDirectMethod *)get_supported_channels_handler;
+
 }
 
 WifiDirectManager::~WifiDirectManager()
@@ -3082,6 +3109,25 @@ GVariant *WifiDirectManager::getDiscoveredPeersGvariant(void)
        return ret;
 }
 
+GError *WifiDirectManager::getSupportedChannels(GVariant **ret)
+{
+       if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+               return this->error_handler_.NotPermitted();
+
+       GVariantBuilder *builder = NULL;
+
+       unsigned int channel_data[] = {1, 6, 11};
+       builder = g_variant_builder_new(G_VARIANT_TYPE("au"));
+       for (int i = 0; i < 3; i++) {
+               g_variant_builder_add(builder, "u", channel_data[i]);
+       }
+
+       *ret = g_variant_new("(iau)", WIFI_DIRECT_ERROR_NONE, builder);
+       g_variant_builder_unref(builder);
+
+       return NULL;
+}
+
 GVariant *WifiDirectManager::activated(void)
 {
        this->setState(WifiDirectState::kWifiDirectStateActivated);