Add testcases about wifi-policy
authorSangwan Kwon <sangwan.kwon@samsung.com>
Wed, 24 Jul 2019 03:14:16 +0000 (12:14 +0900)
committer권상완/Security 2Lab(SR)/Engineer/삼성전자 <sangwan.kwon@samsung.com>
Thu, 1 Aug 2019 02:10:53 +0000 (11:10 +0900)
Signed-off-by: Sangwan Kwon <sangwan.kwon@samsung.com>
osquery/tizen/CMakeLists.txt
osquery/tizen/device-policy/wifi/CMakeLists.txt [deleted file]
osquery/tizen/device-policy/wifi/tests/wifi_tests.cpp [new file with mode: 0644]
osquery/tizen/device-policy/wifi/wifi.cpp
osquery/tizen/device-policy/wifi/wifi.h

index 9593df81b32e541112da89e14587f33776c2d968..f95192eb947308d623f8509d0e246eadb04e5dc2 100644 (file)
@@ -17,7 +17,7 @@ ADD_OSQUERY_LIBRARY(osquery_tizen property/property.cpp
                                                                  manager/manager_impl.cpp
                                                                  notification/notification.cpp)
 
-FILE(GLOB OSQUERY_TIZEN_TESTS "*/tests/*.cpp")
+FILE(GLOB OSQUERY_TIZEN_TESTS "[!d]*/tests/*.cpp")
 ADD_OSQUERY_TEST(${OSQUERY_TIZEN_TESTS})
 
 IF(DEFINED GBS_BUILD)
@@ -34,4 +34,7 @@ IF(DEFINED GBS_BUILD)
        ADD_OSQUERY_LINK(${GBS_DEPS_LIBRARIES})
        ADD_OSQUERY_LIBRARY(device_policy_wifi device-policy/wifi/wifi.cpp
                                                                                   device-policy/wifi/wifi-impl.cpp)
+
+       FILE(GLOB OSQUERY_GBS_TESTS "device-policy/*/tests/*.cpp")
+       ADD_OSQUERY_TEST(${OSQUERY_GBS_TESTS})
 ENDIF(DEFINED GBS_BUILD)
diff --git a/osquery/tizen/device-policy/wifi/CMakeLists.txt b/osquery/tizen/device-policy/wifi/CMakeLists.txt
deleted file mode 100755 (executable)
index cf1cc4d..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-#
-# Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-SET(TARGET ${PROJECT_NAME})
-SET(PC_FILE "${TARGET}.pc")
-
-SET(LIB_VERSION "${VERSION}")
-SET(LIB_SOVERSION "0")
-
-SET(API_SOURCES "wifi.cpp")
-SET(API_HEADERS "wifi.h")
-
-SET(DEPENDENCY      klay
-                                       dpm-pil
-                    capi-base-common
-                    capi-system-info
-)
-
-PKG_CHECK_MODULES(API_DEPS REQUIRED ${DEPENDENCY})
-
-SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack")
-
-ADD_LIBRARY(${TARGET} SHARED ${API_SOURCES})
-
-SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS "-fvisibility=default")
-SET_TARGET_PROPERTIES(${TARGET} PROPERTIES SOVERSION ${LIB_SOVERSION})
-SET_TARGET_PROPERTIES(${TARGET} PROPERTIES VERSION   ${LIB_VERSION})
-
-INCLUDE_DIRECTORIES(SYSTEM ${API_DEPS_INCLUDE_DIRS})
-TARGET_LINK_LIBRARIES(${TARGET} ${API_DEPS_LIBRARIES} pthread)
-
-CONFIGURE_FILE(${PC_FILE}.in ${CMAKE_BINARY_DIR}/${PC_FILE} @ONLY)
-
-INSTALL(FILES ${CMAKE_BINARY_DIR}/${PC_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-INSTALL(TARGETS ${TARGET} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
-INSTALL(FILES ${API_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/dpm)
diff --git a/osquery/tizen/device-policy/wifi/tests/wifi_tests.cpp b/osquery/tizen/device-policy/wifi/tests/wifi_tests.cpp
new file mode 100644 (file)
index 0000000..3cb0981
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#include <gtest/gtest.h>
+
+#include <osquery/logger.h>
+
+#include "../wifi.h"
+
+#include <memory>
+
+class WifiPolicyTests : public testing::Test {};
+
+TEST_F(WifiPolicyTests, Wifi) {
+       /// device_policy_manager_h is void* type
+       std::shared_ptr<void> handle(dpm_manager_create(), dpm_manager_destroy);
+       ASSERT_TRUE(handle != nullptr);
+
+       bool isAllowed = false;
+       auto ret = dpm_wifi_get_state(handle.get(), &isAllowed);
+       EXPECT_EQ(ret, DPM_ERROR_NONE);
+
+       int id = 0;
+       auto callback = [](const char* name, const char* state, void* user_data) {
+               VLOG(1) << name << " policy changed to -> " << state;
+       };
+       ret = dpm_add_policy_changed_cb(handle.get(), "wifi", callback, NULL, &id);
+       EXPECT_EQ(ret, DPM_ERROR_NONE);
+
+       ret = dpm_remove_policy_changed_cb(handle.get(), id);
+       EXPECT_EQ(ret, DPM_ERROR_NONE);
+}
+
+TEST_F(WifiPolicyTests, Hotspot) {
+       /// device_policy_manager_h is void* type
+       std::shared_ptr<void> handle(dpm_manager_create(), dpm_manager_destroy);
+       ASSERT_TRUE(handle != nullptr);
+
+       bool isAllowed = false;
+       auto ret = dpm_wifi_get_hotspot_state(handle.get(), &isAllowed);
+       EXPECT_EQ(ret, DPM_ERROR_NONE);
+
+       int id = 0;
+       auto callback = [](const char* name, const char* state, void* user_data) {
+               VLOG(1) << name << " policy changed to -> " << state;
+       };
+       ret = dpm_add_policy_changed_cb(handle.get(), "wifi_hotspot", callback, NULL, &id);
+       EXPECT_EQ(ret, DPM_ERROR_NONE);
+
+       ret = dpm_remove_policy_changed_cb(handle.get(), id);
+       EXPECT_EQ(ret, DPM_ERROR_NONE);
+}
+
+TEST_F(WifiPolicyTests, ProfileChange) {
+       /// device_policy_manager_h is void* type
+       std::shared_ptr<void> handle(dpm_manager_create(), dpm_manager_destroy);
+       ASSERT_TRUE(handle != nullptr);
+
+       bool isAllowed = false;
+       auto ret = dpm_wifi_is_profile_change_restricted(handle.get(), &isAllowed);
+       EXPECT_EQ(ret, DPM_ERROR_NONE);
+
+       int id = 0;
+       auto callback = [](const char* name, const char* state, void* user_data) {
+               VLOG(1) << name << " policy changed to -> " << state;
+       };
+       ret = dpm_add_policy_changed_cb(handle.get(), "wifi_profile_change", callback, NULL, &id);
+       EXPECT_EQ(ret, DPM_ERROR_NONE);
+
+       ret = dpm_remove_policy_changed_cb(handle.get(), id);
+       EXPECT_EQ(ret, DPM_ERROR_NONE);
+}
index 90b843ce63c02bed4d4eb6b27a26f93cc2e1b1af..d71fb8aca00a09eb0434ce4fa55457be13b59671 100644 (file)
@@ -74,7 +74,7 @@ EXPORT_API int dpm_wifi_set_hotspot_state(device_policy_manager_h handle, bool a
        }
 }
 
-EXPORT_API int dpm_wifi_get_wifi_hotspot_state(device_policy_manager_h handle, bool *is_allowed)
+EXPORT_API int dpm_wifi_get_hotspot_state(device_policy_manager_h handle, bool *is_allowed)
 {
        RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
        RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER);
index b62aaf3d61b555d818d6dd848e14cfd170584221..15095d7d2ad217071fb6e475e7a177c7606adf15 100644 (file)
@@ -14,6 +14,8 @@
  *  limitations under the License
  */
 
+/// These APIs would be deprecated.
+
 #ifndef __CAPI_DPM_WIFI_POLICY_H__
 #define __CAPI_DPM_WIFI_POLICY_H__
 
@@ -26,9 +28,6 @@
  * @brief This file provides APIs to control wifi policy
  */
 
-#ifdef __cplusplus
-extern "C" {
-#endif
 
 /**
  * @addtogroup  CAPI_DPM_WIFI_POLICY_MODULE
@@ -165,8 +164,4 @@ int dpm_wifi_is_profile_change_restricted(device_policy_manager_h handle, bool *
  * @}
  */
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif //! __CAPI_DPM_WIFI_POLICY_H__