From 4ee0489a4f6b5a913b5310fd938f585506f68d81 Mon Sep 17 00:00:00 2001 From: Yu Date: Tue, 25 Aug 2020 11:14:29 +0900 Subject: [PATCH] Add test case for get supported channels CAPI Change-Id: If31207712aebd3df3a14412f57f3104fcafc71cd Signed-off-by: Yu jiung --- packaging/capi-network-wifi-direct.spec | 2 +- src/wifi-direct-client-proxy.c | 6 +-- tests/gtest-wifi-direct.cpp | 37 +++++++++++++++++ tests/include/WifiDirectManager.h | 1 + .../mocks/WifiDirectManager/WifiDirectManager.cpp | 48 +++++++++++++++++++++- 5 files changed, 87 insertions(+), 7 deletions(-) diff --git a/packaging/capi-network-wifi-direct.spec b/packaging/capi-network-wifi-direct.spec index 723cda5..446079c 100755 --- a/packaging/capi-network-wifi-direct.spec +++ b/packaging/capi-network-wifi-direct.spec @@ -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 diff --git a/src/wifi-direct-client-proxy.c b/src/wifi-direct-client-proxy.c index dbe636c..4b6376c 100755 --- a/src/wifi-direct-client-proxy.c +++ b/src/wifi-direct-client-proxy.c @@ -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]!"); diff --git a/tests/gtest-wifi-direct.cpp b/tests/gtest-wifi-direct.cpp index 9e41a1e..7e4a3ed 100644 --- a/tests/gtest-wifi-direct.cpp +++ b/tests/gtest-wifi-direct.cpp @@ -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 diff --git a/tests/include/WifiDirectManager.h b/tests/include/WifiDirectManager.h index 43a002b..b81e18e 100644 --- a/tests/include/WifiDirectManager.h +++ b/tests/include/WifiDirectManager.h @@ -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); diff --git a/tests/mocks/WifiDirectManager/WifiDirectManager.cpp b/tests/mocks/WifiDirectManager/WifiDirectManager.cpp index 80b056f..4480982 100644 --- a/tests/mocks/WifiDirectManager/WifiDirectManager.cpp +++ b/tests/mocks/WifiDirectManager/WifiDirectManager.cpp @@ -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); -- 2.7.4