From: Youngjae Shin Date: Mon, 11 May 2020 05:46:40 +0000 (+0900) Subject: change unit tests folder name X-Git-Tag: submit/tizen/20200513.090930~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a2d40ca799d152f5766db704b410fee0c18944bb;p=platform%2Fcore%2Fsystem%2Fmodes-plugins.git change unit tests folder name from unittests to tests --- diff --git a/CMakeLists.txt b/CMakeLists.txt index fd4247e..b494da5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,4 +22,4 @@ ADD_SUBDIRECTORY(pkg) ADD_SUBDIRECTORY(bluetooth) ADD_SUBDIRECTORY(media) ADD_SUBDIRECTORY(display) -ADD_SUBDIRECTORY(unittests) +ADD_SUBDIRECTORY(tests) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..65d9a7f --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,83 @@ +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE") +ADD_DEFINITIONS("-DMDS_TEST") +ADD_DEFINITIONS("-DEFL_BETA_API_SUPPORT") + +PKG_CHECK_MODULES(test_pkgs REQUIRED modes dlog gmock capi-network-wifi-manager capi-network-bluetooth vconf + capi-appfw-application capi-appfw-app-manager aul + capi-media-sound-manager capi-media-player + pkgmgr pkgmgr-info capi-system-device + evas elementary ecore ecore-wl2 capi-ui-efl-util) +INCLUDE_DIRECTORIES(${test_pkgs_INCLUDE_DIRS}) +LINK_DIRECTORIES(${test_pkgs_LIBRARY_DIRS}) + +SET(INTEGRATION_TEST "modes-plugintest-mode") +SET(INTEGRATION_SRCS "mdsp_test_integration.cpp") +ADD_EXECUTABLE(${INTEGRATION_TEST} ${INTEGRATION_SRCS}) +TARGET_LINK_LIBRARIES(${INTEGRATION_TEST} ${test_pkgs_LIBRARIES}) +INSTALL(TARGETS ${INTEGRATION_TEST} DESTINATION ${TEST_INSTALL_DIR}) +FILE(GLOB MODE_EX mode/*.xml) +INSTALL(FILES ${MODE_EX} DESTINATION ${MODES_MODE_DEFAULT_DIR}) +#===================================================================# +SET(WIFI_SRC_DIR "${CMAKE_SOURCE_DIR}/wifi" ) +SET(WIFI_PLUGIN_TEST "modes-plugintest-wifi") +FILE(GLOB WIFI_SRCS ${WIFI_SRC_DIR}/*.cpp) +SET(WIFI_SRCS ${WIFI_SRCS} "mdsp_test_wifi.cpp") + +ADD_EXECUTABLE(${WIFI_PLUGIN_TEST} ${WIFI_SRCS}) +TARGET_LINK_LIBRARIES(${WIFI_PLUGIN_TEST} ${test_pkgs_LIBRARIES}) +INSTALL(TARGETS ${WIFI_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR}) +#===================================================================# +SET(BT_SRC_DIR "${CMAKE_SOURCE_DIR}/bluetooth" ) +SET(BT_PLUGIN_TEST "modes-plugintest-bt") +FILE(GLOB BT_SRCS ${BT_SRC_DIR}/*.cpp) +SET(BT_SRCS ${BT_SRCS} "mdsp_test_bt.cpp") + +ADD_EXECUTABLE(${BT_PLUGIN_TEST} ${BT_SRCS}) +TARGET_LINK_LIBRARIES(${BT_PLUGIN_TEST} ${test_pkgs_LIBRARIES}) +INSTALL(TARGETS ${BT_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR}) +#===================================================================# +SET(APP_SRC_DIR "${CMAKE_SOURCE_DIR}/app" ) +SET(APP_PLUGIN_TEST "modes-plugintest-app") +FILE(GLOB APP_SRCS ${APP_SRC_DIR}/*.cpp) +SET(APP_SRCS ${APP_SRCS} "mdsp_test_app.cpp") + +ADD_EXECUTABLE(${APP_PLUGIN_TEST} ${APP_SRCS}) +TARGET_LINK_LIBRARIES(${APP_PLUGIN_TEST} ${test_pkgs_LIBRARIES}) +INSTALL(TARGETS ${APP_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR}) +#===================================================================# +SET(PKG_SRC_DIR "${CMAKE_SOURCE_DIR}/pkg" ) +SET(PKG_PLUGIN_TEST "modes-plugintest-pkg") +FILE(GLOB PKG_SRCS ${PKG_SRC_DIR}/*.cpp) +SET(PKG_SRCS ${PKG_SRCS} "mdsp_test_pkg.cpp") + +ADD_EXECUTABLE(${PKG_PLUGIN_TEST} ${PKG_SRCS}) +TARGET_LINK_LIBRARIES(${PKG_PLUGIN_TEST} ${test_pkgs_LIBRARIES}) +INSTALL(TARGETS ${PKG_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR}) +#===================================================================# +SET(VCONF_SRC_DIR "${CMAKE_SOURCE_DIR}/vconf" ) +SET(VCONF_PLUGIN_TEST "modes-plugintest-vconf") +FILE(GLOB VCONF_SRCS ${VCONF_SRC_DIR}/*.cpp) +SET(VCONF_SRCS ${VCONF_SRCS} "mdsp_test_vconf.cpp") + +ADD_EXECUTABLE(${VCONF_PLUGIN_TEST} ${VCONF_SRCS}) +TARGET_LINK_LIBRARIES(${VCONF_PLUGIN_TEST} ${test_pkgs_LIBRARIES}) +INSTALL(TARGETS ${VCONF_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR}) +#===================================================================# +SET(MEDIA_SRC_DIR "${CMAKE_SOURCE_DIR}/media" ) +SET(MEDIA_PLUGIN_TEST "modes-plugintest-media") +FILE(GLOB MEDIA_SRCS ${MEDIA_SRC_DIR}/*.cpp) +SET(MEDIA_SRCS ${MEDIA_SRCS} "mdsp_test_media.cpp") + +ADD_EXECUTABLE(${MEDIA_PLUGIN_TEST} ${MEDIA_SRCS}) +TARGET_LINK_LIBRARIES(${MEDIA_PLUGIN_TEST} ${test_pkgs_LIBRARIES}) +INSTALL(TARGETS ${MEDIA_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR}) +#===================================================================# +SET(DISPLAY_SRC_DIR "${CMAKE_SOURCE_DIR}/display" ) +SET(DISPLAY_PLUGIN_TEST "modes-plugintest-display") +FILE(GLOB DISPLAY_SRCS ${DISPLAY_SRC_DIR}/*.cpp) +SET(DISPLAY_SRCS ${DISPLAY_SRCS} "mdsp_test_display.cpp") + +ADD_EXECUTABLE(${DISPLAY_PLUGIN_TEST} ${DISPLAY_SRCS}) +TARGET_LINK_LIBRARIES(${DISPLAY_PLUGIN_TEST} ${test_pkgs_LIBRARIES}) +INSTALL(TARGETS ${DISPLAY_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR}) diff --git a/tests/mdsp_test_app.cpp b/tests/mdsp_test_app.cpp new file mode 100644 index 0000000..e25e87a --- /dev/null +++ b/tests/mdsp_test_app.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2019-2020 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 +#include + +#include +#include +#include +#include +#include +#include +#include "plugin-def.h" + +MODES_NAMESPACE_USE; + +extern "C" Plugin* objectCreate(void); +extern "C" void objectDelete(Plugin *plugin); + +class AppPluginTest : public ::testing::Test { +protected: + void SetUp() override + { + loop = g_main_loop_new(NULL, FALSE); + plugin = objectCreate(); + } + + void TearDown() override + { + g_main_loop_unref(loop); + loop = NULL; + objectDelete(plugin); + plugin = nullptr; + } + + static gboolean appUndoTimeout(gpointer data) + { + PluginAction *action = (PluginAction*)data; + action->undo(); + g_main_loop_quit(loop); + plugin->deleteAction(action); + + return G_SOURCE_REMOVE; + } + + static gboolean checkSetUndoIdler(gpointer data) + { + PluginAction *action = plugin->newAction("launch"); + EXPECT_FALSE(action->IsCurrentValue(std::string(testApp))); + result = action->set(std::string(testApp)); + EXPECT_EQ(MODES_ERROR_NONE, result); + + if (MODES_ERROR_NONE == result) { + g_timeout_add(1000, appUndoTimeout, action); + } else { + g_main_loop_quit(loop); + plugin->deleteAction(action); + } + return G_SOURCE_REMOVE; + } + + static void changedCB(void *userData) + { + PluginAction *action = (PluginAction*)userData; + + cbCalled = true; + std::cout << ">>>>>>>> changedCB: Terminated <<<<<<<<" << std::endl; + appUndoTimeout(action); + } + + static gboolean checkChangedCBIdler(gpointer data) + { + sleep(1); + PluginAction *action = plugin->newAction("launch"); + EXPECT_FALSE(action->IsCurrentValue(std::string(testApp))); + result = action->set(std::string(testApp)); + EXPECT_EQ(MODES_ERROR_NONE, result); + + if (MODES_ERROR_NONE == result) { + int ret = action->setChangedCallback(changedCB, action); + EXPECT_EQ(MODES_ERROR_NONE, ret); + g_timeout_add(20000, appUndoTimeout, action); //For running continue + } else { + g_main_loop_quit(loop); + plugin->deleteAction(action); + } + + sleep(1); + app_context_h runAppContext = NULL; + int ret = app_manager_get_app_context(testApp, &runAppContext); + if (APP_MANAGER_ERROR_NONE != ret) + std::cout << testApp << " get_app_context() Fail:" << ret << std::endl; + else + app_manager_terminate_app(runAppContext); + + return G_SOURCE_REMOVE; + } + + static const char *testApp; + static int result; + static bool cbCalled; + static GMainLoop *loop; + static GThread *my_thread; + static Plugin *plugin; +}; + +const char *AppPluginTest::testApp = "org.tizen.setting"; +int AppPluginTest::result = 0; +bool AppPluginTest::cbCalled = false; +Plugin *AppPluginTest::plugin = nullptr; +GMainLoop *AppPluginTest::loop = NULL; + +TEST_F(AppPluginTest, CheckSetUndo) +{ + g_idle_add(checkSetUndoIdler, plugin); + g_main_loop_run(loop); +} + +TEST_F(AppPluginTest, checkChangedCB) +{ + cbCalled = false; + g_idle_add(checkChangedCBIdler, NULL); + g_main_loop_run(loop); + //TODO: at posttrans of unittest, changedCB is not called + //EXPECT_EQ(cbCalled, true); +} + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/tests/mdsp_test_bt.cpp b/tests/mdsp_test_bt.cpp new file mode 100644 index 0000000..4fc5d24 --- /dev/null +++ b/tests/mdsp_test_bt.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2019-2020 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 +#include +#include +#include +#include +#include "plugin-def.h" + +MODES_NAMESPACE_USE; + +extern "C" Plugin* objectCreate(void); +extern "C" void objectDelete(Plugin *plugin); + +class BtPluginTest : public ::testing::Test { +protected: + void SetUp() override + { + plugin = objectCreate(); + loop = g_main_loop_new(NULL, FALSE); + handle = modes_connect(); + } + + void TearDown() override + { + objectDelete(plugin); + plugin = nullptr; + g_main_loop_unref(loop); + loop = NULL; + modes_disconnect(handle); + handle = NULL; + } + + static gboolean apply_mode_idler(gpointer data) + { + result = modes_apply_mode(handle, (const char*)data); + + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } + + static gboolean undo_mode_idler(gpointer data) + { + result = modes_apply_mode(handle, (const char*)data); + EXPECT_EQ(MODES_ERROR_NONE, result); + sleep(5); + result = modes_undo_mode(handle, (const char*)data); + + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } + + static modes_h handle; + static int result; + static GMainLoop *loop; + Plugin *plugin; +}; + +int BtPluginTest::result = 0; +GMainLoop *BtPluginTest::loop = NULL; +modes_h BtPluginTest::handle = NULL; + +TEST_F(BtPluginTest, undoModebtOff) +{ + g_idle_add(undo_mode_idler, (gpointer)"btOff"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); +} + +TEST_F(BtPluginTest, undoModebtOn) +{ + g_idle_add(undo_mode_idler, (gpointer)"btOn"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); +} + +// btAudioConnect does not support undo mode +TEST_F(BtPluginTest, btAudioConnect) +{ + g_idle_add(apply_mode_idler, (gpointer)"btAudioConnect"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); +} + +TEST_F(BtPluginTest, btTest) +{ + int ret; + + ASSERT_TRUE(nullptr != plugin); + + PluginAction *action = plugin->newAction("power"); + ret = action->set(false); + EXPECT_EQ(ret, MODES_ERROR_NONE); + sleep(3);//for avoiding the NOW_IN_PROGRESS error + + ret = action->set(true); + EXPECT_EQ(ret, MODES_ERROR_NONE); + + ret = action->set(std::string("on")); + EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); + plugin->deleteAction(action); + + action = plugin->newAction("abcdefg"); + EXPECT_EQ(action, nullptr); +} + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + diff --git a/tests/mdsp_test_display.cpp b/tests/mdsp_test_display.cpp new file mode 100644 index 0000000..c038d5a --- /dev/null +++ b/tests/mdsp_test_display.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2019-2020 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 displaylicable 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 +#include +#include +#include "plugin-def.h" + +MODES_NAMESPACE_USE; + +extern "C" Plugin* objectCreate(void); +extern "C" void objectDelete(Plugin *plugin); + +class displayPluginTest : public ::testing::Test { +protected: + void SetUp() override + { + loop = g_main_loop_new(NULL, FALSE); + plugin = objectCreate(); + } + + void TearDown() override + { + g_main_loop_unref(loop); + loop = NULL; + objectDelete(plugin); + plugin = nullptr; + } + + static gboolean displayPluginBrightnessIdler(gpointer data) + { + PluginAction *action = plugin->newAction("brightness"); + int value = 100; + if (action->IsCurrentValue(value)) + value--; + result = action->set(value); + EXPECT_EQ(MODES_ERROR_NONE, result); + + action->undo(); + + plugin->deleteAction(action); + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } + + static gboolean displayPluginDenyPalmTouchIdler(gpointer data) + { + PluginAction *action = plugin->newAction("denyPalmTouch"); + EXPECT_FALSE(action->IsCurrentValue(true)); + result = action->set(true); + EXPECT_EQ(MODES_ERROR_NONE, result); + + action->undo(); + + plugin->deleteAction(action); + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } + + static gboolean displayPluginAlwaysOnIdler(gpointer data) + { + PluginAction *action = plugin->newAction("timeout"); + EXPECT_FALSE(action->IsCurrentValue(0)); + result = action->set(0); + EXPECT_EQ(MODES_ERROR_NONE, result); + + action->undo(); + + plugin->deleteAction(action); + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } + + static gboolean displayPluginAutoBrightnessIdler(gpointer data) + { + PluginAction *action = plugin->newAction("autoBrightness"); + EXPECT_FALSE(action->IsCurrentValue(1)); + result = action->set(1); + EXPECT_EQ(MODES_ERROR_NONE, result); + + action->undo(); + + result = action->set(2); + EXPECT_EQ(MODES_ERROR_NONE, result); + + plugin->deleteAction(action); + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } + static int result; + static GMainLoop *loop; + static Plugin *plugin; +}; + +int displayPluginTest::result = 0; +Plugin *displayPluginTest::plugin = nullptr; +GMainLoop *displayPluginTest::loop = NULL; + +TEST_F(displayPluginTest, setBrightness) +{ + g_idle_add(displayPluginBrightnessIdler, plugin); + g_main_loop_run(loop); +} + +TEST_F(displayPluginTest, setAutoBrightness) +{ + g_idle_add(displayPluginAutoBrightnessIdler, plugin); + g_main_loop_run(loop); +} + +TEST_F(displayPluginTest, setAlwaysOn) +{ + g_idle_add(displayPluginAlwaysOnIdler, plugin); + g_main_loop_run(loop); +} + +TEST_F(displayPluginTest, setDenyPalmTouch) +{ + g_idle_add(displayPluginDenyPalmTouchIdler, plugin); + g_main_loop_run(loop); +} + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/tests/mdsp_test_integration.cpp b/tests/mdsp_test_integration.cpp new file mode 100644 index 0000000..825ad59 --- /dev/null +++ b/tests/mdsp_test_integration.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2019-2020 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 +#include +#include + +class IntegrationTest : public ::testing::Test { +protected: + void SetUp() override + { + loop = g_main_loop_new(NULL, FALSE); + handle = modes_connect(); + } + + void TearDown() override + { + g_main_loop_unref(loop); + loop = NULL; + modes_disconnect(handle); + handle = NULL; + } + + static gboolean check_mode_idler(gpointer data) + { + modes_undo_mode(handle, (const char*)data); + result = modes_apply_mode(handle, (const char*)data); + EXPECT_EQ(MODES_ERROR_NONE, result); + sleep(2); + result = modes_undo_mode(handle, (const char*)data); + + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } + + static modes_h handle; + static int result; + static GMainLoop *loop; +}; + +int IntegrationTest::result = 0; +GMainLoop *IntegrationTest::loop = NULL; +modes_h IntegrationTest::handle = NULL; + +TEST_F(IntegrationTest, runMode_btAudioConnect) +{ + g_idle_add(check_mode_idler, (gpointer)"btAudioConnect"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); +} + +TEST_F(IntegrationTest, runMode_btOff) +{ + g_idle_add(check_mode_idler, (gpointer)"btOff"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); +} + +TEST_F(IntegrationTest, runMode_btOn) +{ + g_idle_add(check_mode_idler, (gpointer)"btOn"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); +} + +TEST_F(IntegrationTest, runMode_powerSave) +{ + g_idle_add(check_mode_idler, (gpointer)"Power-Save"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); +} + +TEST_F(IntegrationTest, runMode_displayBlock) +{ + g_idle_add(check_mode_idler, (gpointer)"displayBlock"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); +} + +TEST_F(IntegrationTest, runMode_wifiOn) +{ + g_idle_add(check_mode_idler, (gpointer)"wifi-on"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); +} + +TEST_F(IntegrationTest, runMode_waterlock) +{ + g_idle_add(check_mode_idler, (gpointer)"Water-Lock"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); +} + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/tests/mdsp_test_media.cpp b/tests/mdsp_test_media.cpp new file mode 100644 index 0000000..8bed4ad --- /dev/null +++ b/tests/mdsp_test_media.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2019-2020 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 medialicable 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 +#include +#include +#include +#include "plugin-def.h" + +MODES_NAMESPACE_USE; + +extern "C" Plugin* objectCreate(void); +extern "C" void objectDelete(Plugin *plugin); + +class MediaPluginTest : public ::testing::Test { +protected: + void SetUp() override + { + loop = g_main_loop_new(NULL, FALSE); + plugin = objectCreate(); + } + + void TearDown() override + { + g_main_loop_unref(loop); + loop = NULL; + objectDelete(plugin); + plugin = nullptr; + } + + static gboolean mediaPlaySetUndoTimeout(gpointer data) + { + PluginAction *action = (PluginAction*)data; + action->undo(); + g_main_loop_quit(loop); + return false; + } + + static gboolean mediaPlaySetUndoIdler(gpointer data) + { + PluginAction *action = (PluginAction*)data; + const std::string file = "/opt/usr/data/settings/Ringtones/ringtone_sdk.mp3"; + EXPECT_FALSE(action->IsCurrentValue(file)); + result = action->set(file); + if (MODES_ERROR_NONE != result) { + const std::string wearableFile = "/opt/usr/data/settings/Previews/Media_preview_Over_the_horizon_B2.ogg"; + EXPECT_FALSE(action->IsCurrentValue(wearableFile)); + result = action->set(wearableFile); + } + + EXPECT_EQ(MODES_ERROR_NONE, result); + + if (MODES_ERROR_NONE == result) + g_timeout_add(1000, mediaPlaySetUndoTimeout, action); + else + g_main_loop_quit(loop); + + return G_SOURCE_REMOVE; + } + + static gboolean VolumeSetUndoIdler(gpointer data) + { + PluginAction *action; + action = plugin->newAction("mediaVolume"); + EXPECT_FALSE(action->IsCurrentValue(5)); + result = action->set(5); + EXPECT_EQ(MODES_ERROR_NONE, result); + action->undo(); + plugin->deleteAction(action); + + action = plugin->newAction("systemVolume"); + EXPECT_FALSE(action->IsCurrentValue(2)); + result = action->set(2); + EXPECT_EQ(MODES_ERROR_NONE, result); + action->undo(); + plugin->deleteAction(action); + + action = plugin->newAction("ringtoneVolume"); + EXPECT_FALSE(action->IsCurrentValue(9)); + result = action->set(9); + EXPECT_EQ(MODES_ERROR_NONE, result); + action->undo(); + plugin->deleteAction(action); + + action = plugin->newAction("notificationVolume"); + EXPECT_FALSE(action->IsCurrentValue(1)); + result = action->set(1); + EXPECT_EQ(MODES_ERROR_NONE, result); + action->undo(); + plugin->deleteAction(action); + + action = plugin->newAction("mediaVolume"); + EXPECT_FALSE(action->IsCurrentValue(-1)); + result = action->set(-1); + EXPECT_EQ(MODES_ERROR_NONE, result); + action->undo(); + plugin->deleteAction(action); + + action = plugin->newAction("systemVolume"); + EXPECT_FALSE(action->IsCurrentValue(-1)); + result = action->set(-1); + EXPECT_EQ(MODES_ERROR_NONE, result); + action->undo(); + plugin->deleteAction(action); + + action = plugin->newAction("ringtoneVolume"); + EXPECT_FALSE(action->IsCurrentValue(-1)); + result = action->set(-1); + EXPECT_EQ(MODES_ERROR_NONE, result); + action->undo(); + plugin->deleteAction(action); + + action = plugin->newAction("notificationVolume"); + EXPECT_FALSE(action->IsCurrentValue(-1)); + result = action->set(-1); + EXPECT_EQ(MODES_ERROR_NONE, result); + action->undo(); + plugin->deleteAction(action); + + g_main_loop_quit(loop); + + return G_SOURCE_REMOVE; + } + + static int result; + static GMainLoop *loop; + static Plugin *plugin; +}; + +int MediaPluginTest::result = 0; +Plugin *MediaPluginTest::plugin = nullptr; +GMainLoop *MediaPluginTest::loop = nullptr; + +TEST_F(MediaPluginTest, setUndoMediaPlay) +{ + PluginAction *action = plugin->newAction("player"); + g_idle_add(mediaPlaySetUndoIdler, action); + g_main_loop_run(loop); + plugin->deleteAction(action); +} + +TEST_F(MediaPluginTest, setUndoMediaVolume) +{ + g_idle_add(VolumeSetUndoIdler, NULL); + g_main_loop_run(loop); +} + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/tests/mdsp_test_pkg.cpp b/tests/mdsp_test_pkg.cpp new file mode 100644 index 0000000..936a05b --- /dev/null +++ b/tests/mdsp_test_pkg.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2019-2020 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 +#include +#include +#include +#include +#include "plugin-def.h" + +MODES_NAMESPACE_USE; + +extern "C" Plugin* objectCreate(void); +extern "C" void objectDelete(Plugin *plugin); + +class PkgPluginTest : public ::testing::Test { +protected: + void SetUp() override + { + loop = g_main_loop_new(NULL, FALSE); + plugin = objectCreate(); + } + + void TearDown() override + { + g_main_loop_unref(loop); + loop = NULL; + objectDelete(plugin); + plugin = nullptr; + vconf_set_str("db/setting/menuscreen/package_name", "org.tizen.homescreen-efl"); + } + + static gboolean pkgPluginIdler(gpointer data) + { + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } + + static int result; + static GMainLoop *loop; + Plugin *plugin; +}; + +GMainLoop *PkgPluginTest::loop = NULL; + +TEST_F(PkgPluginTest, setUndoTest) +{ + PluginAction *action = plugin->newAction("supportMode"); + EXPECT_FALSE(action->IsCurrentValue(1)); + int ret = action->set(1); + EXPECT_EQ(MODES_ERROR_NONE, ret); + + g_idle_add(pkgPluginIdler, plugin); + g_main_loop_run(loop); + + action->undo(); + + g_idle_add(pkgPluginIdler, plugin); + g_main_loop_run(loop); + plugin->deleteAction(action); +} + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/tests/mdsp_test_vconf.cpp b/tests/mdsp_test_vconf.cpp new file mode 100644 index 0000000..13fc138 --- /dev/null +++ b/tests/mdsp_test_vconf.cpp @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2019-2020 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 +#include +#include +#include +#include "plugin-log.h" +#include "plugin-def.h" + +MODES_NAMESPACE_USE; + +extern "C" Plugin* objectCreate(void); +extern "C" void objectDelete(Plugin *plugin); + +class VconfPluginTest : public ::testing::Test { +protected: + void SetUp() override + { + plugin = objectCreate(); + loop = g_main_loop_new(NULL, FALSE); + } + + void TearDown() override + { + objectDelete(plugin); + g_main_loop_unref(loop); + loop = NULL; + cb1Called = false; + cb2Called = false; + } + + static void shouldNotBeCalled(void *userData) + { + ERR("This Callback(%s) should not be called", (char*)userData); + g_main_loop_quit(loop); + GTEST_FAIL(); + } + + static void valChangedCb(void *userData) + { + DBG("%s changed callback called!", (char*)userData); + g_main_loop_quit(loop); + } + + static void callback1(void *userData) + { + PluginAction *action = (PluginAction*)userData; + DBG("%s changed callback called!", action->getKey().c_str()); + + //In practice, it is handled by Action. refer to Action.cpp + action->unSetChangedCallback(callback1); + + cb1Called = true; + } + + static void callback2(void *userData) + { + DBG("%s changed callback called!", (char*)userData); + cb2Called = true; + g_main_loop_quit(loop); + } + + static gboolean changedCallbackidler(gpointer data) + { + DBG("start change the value db/setting/psmode"); + vconf_set_int("db/setting/psmode", 7); + return G_SOURCE_REMOVE; + } + + static GMainLoop *loop; + static Plugin *plugin; + static bool cb1Called; + static bool cb2Called; +}; + +bool VconfPluginTest::cb1Called = false; +bool VconfPluginTest::cb2Called = false; +Plugin *VconfPluginTest::plugin = nullptr; +GMainLoop *VconfPluginTest::loop = NULL; + + +TEST_F(VconfPluginTest, VconfInt) +{ + int ret; + const char *key = "db.setting.psmode"; + + PluginAction *action = plugin->newAction(key);; + ret = action->set(0); + EXPECT_EQ(ret, MODES_ERROR_NONE); + + EXPECT_FALSE(action->IsCurrentValue(1)); + ret = action->set(1); + EXPECT_EQ(ret, MODES_ERROR_NONE); + + action->undo(); + plugin->deleteAction(action); +} + +TEST_F(VconfPluginTest, VconfDouble) +{ + int ret; + const char *key = "db.system.timechange_external"; + + PluginAction *action = plugin->newAction(key);; + ret = action->set(0.0); + EXPECT_EQ(ret, MODES_ERROR_NONE); + + EXPECT_FALSE(action->IsCurrentValue(1.0)); + ret = action->set(1.0); + EXPECT_EQ(ret, MODES_ERROR_NONE); + + action->undo(); + plugin->deleteAction(action); +} + +TEST_F(VconfPluginTest, VconfBool) +{ + int ret; + const char *key = "db.setting.sound.button_sounds"; + + PluginAction *action = plugin->newAction(key);; + ret = action->set(true); + EXPECT_EQ(ret, MODES_ERROR_NONE); + + EXPECT_FALSE(action->IsCurrentValue(false)); + ret = action->set(false); + EXPECT_EQ(ret, MODES_ERROR_NONE); + + action->undo(); + plugin->deleteAction(action); +} + +TEST_F(VconfPluginTest, VconfStr) +{ + int ret; + const char *key = "db.setting.device_name"; + const std::string devName = "Tizen"; + const std::string tmpName = "ModesTest"; + + PluginAction *action = plugin->newAction(key); + ret = action->set(devName); + EXPECT_EQ(ret, MODES_ERROR_NONE); + + EXPECT_FALSE(action->IsCurrentValue(tmpName)); + ret = action->set(tmpName); + EXPECT_EQ(ret, MODES_ERROR_NONE); + + action->undo(); + plugin->deleteAction(action); +} + +TEST_F(VconfPluginTest, callbackPluginVconf) +{ + int oldVal = 0; + const char *key = "db.setting.psmode"; + int ret = vconf_get_int("db/setting/psmode", &oldVal); + EXPECT_EQ(ret, 0); + + PluginAction *action = plugin->newAction(key); + ret = action->set(0); + EXPECT_EQ(ret, MODES_ERROR_NONE); + + ret = action->setChangedCallback(valChangedCb, (void*)key); + EXPECT_EQ(ret, MODES_ERROR_NONE); + g_idle_add(changedCallbackidler, nullptr); + g_main_loop_run(loop); + + // It should be removed by the changed callback procedure. + action->unSetChangedCallback(valChangedCb); + + ret = action->setChangedCallback(shouldNotBeCalled, (void*)key); + EXPECT_EQ(ret, MODES_ERROR_NONE); + action->unSetChangedCallback(shouldNotBeCalled); + plugin->deleteAction(action); + vconf_set_int("db/setting/psmode", oldVal); +} + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/tests/mdsp_test_wifi.cpp b/tests/mdsp_test_wifi.cpp new file mode 100644 index 0000000..9605663 --- /dev/null +++ b/tests/mdsp_test_wifi.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2019-2020 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 +#include +#include +#include +#include "plugin-def.h" + +MODES_NAMESPACE_USE; + +extern "C" Plugin* objectCreate(void); +extern "C" void objectDelete(Plugin *plugin); + +class WifiPluginTest : public ::testing::Test { +protected: + void SetUp() override + { + plugin = objectCreate(); + } + + void TearDown() override + { + objectDelete(plugin); + plugin = nullptr; + } + + static gboolean timer(gpointer data) + { + GMainLoop *loop = (GMainLoop*)data; + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } + + Plugin *plugin; +}; + +TEST_F(WifiPluginTest, wifiTest) +{ + int ret; + + ASSERT_TRUE(nullptr != plugin); + + bool val; + PluginAction *action = plugin->newAction("power"); + val = action->IsCurrentValue(false); + ret = action->set(val); + EXPECT_EQ(ret, MODES_ERROR_NONE); + + GMainLoop *loop = g_main_loop_new(NULL, FALSE); + g_timeout_add(1000, timer, (gpointer)loop); + g_main_loop_run(loop); + + ret = action->set(!val); + EXPECT_EQ(ret, MODES_ERROR_NONE); + + ret = action->set(0); + EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); + + ret = action->set(1); + EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); + + ret = action->set(0.0); + EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); + + ret = action->set(1.0); + EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); + + ret = action->set(std::string("off")); + EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); + + ret = action->set(std::string("on")); + EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); + plugin->deleteAction(action); + + action = plugin->newAction("abcdefg"); + EXPECT_EQ(action, nullptr); +} + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/tests/mode/tizen_Power-Save_mode.xml b/tests/mode/tizen_Power-Save_mode.xml new file mode 100644 index 0000000..6e47222 --- /dev/null +++ b/tests/mode/tizen_Power-Save_mode.xml @@ -0,0 +1,14 @@ + + + + ULTRA_POWER_SAVING + off + off + 30 + 0 + 0 + 0 + org.tizen.menu-screen + org.tizen.homescreen-efl + + diff --git a/tests/mode/tizen_Quick-Panel_mode.xml b/tests/mode/tizen_Quick-Panel_mode.xml new file mode 100644 index 0000000..0773ef0 --- /dev/null +++ b/tests/mode/tizen_Quick-Panel_mode.xml @@ -0,0 +1,10 @@ + + + + on + 1 + 1 + 1 + 1 + + diff --git a/tests/mode/tizen_Water-Lock_mode.xml b/tests/mode/tizen_Water-Lock_mode.xml new file mode 100644 index 0000000..d499433 --- /dev/null +++ b/tests/mode/tizen_Water-Lock_mode.xml @@ -0,0 +1,10 @@ + + + + false + true + /opt/usr/data/settings/Alarms/Alarms_on_call.ogg + + + + diff --git a/tests/mode/tizen_appLaunch_mode.xml b/tests/mode/tizen_appLaunch_mode.xml new file mode 100644 index 0000000..f286dac --- /dev/null +++ b/tests/mode/tizen_appLaunch_mode.xml @@ -0,0 +1,8 @@ + + + + org.tizen.modesupervisor + off + off + + diff --git a/tests/mode/tizen_btAudioConnect_mode.xml b/tests/mode/tizen_btAudioConnect_mode.xml new file mode 100644 index 0000000..6359800 --- /dev/null +++ b/tests/mode/tizen_btAudioConnect_mode.xml @@ -0,0 +1,7 @@ + + + + on + 08:AE:D6:5E:AE:16 + + diff --git a/tests/mode/tizen_btOff_mode.xml b/tests/mode/tizen_btOff_mode.xml new file mode 100644 index 0000000..5d3d3b1 --- /dev/null +++ b/tests/mode/tizen_btOff_mode.xml @@ -0,0 +1,6 @@ + + + + off + + diff --git a/tests/mode/tizen_btOn_mode.xml b/tests/mode/tizen_btOn_mode.xml new file mode 100644 index 0000000..40e64a3 --- /dev/null +++ b/tests/mode/tizen_btOn_mode.xml @@ -0,0 +1,6 @@ + + + + on + + diff --git a/tests/mode/tizen_displayBlock_mode.xml b/tests/mode/tizen_displayBlock_mode.xml new file mode 100644 index 0000000..66a027d --- /dev/null +++ b/tests/mode/tizen_displayBlock_mode.xml @@ -0,0 +1,7 @@ + + + + ALWAYS_ON + on + + diff --git a/tests/mode/tizen_wifi-on_mode.xml b/tests/mode/tizen_wifi-on_mode.xml new file mode 100644 index 0000000..d2aad8d --- /dev/null +++ b/tests/mode/tizen_wifi-on_mode.xml @@ -0,0 +1,6 @@ + + + + on + + diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt deleted file mode 100644 index 65d9a7f..0000000 --- a/unittests/CMakeLists.txt +++ /dev/null @@ -1,83 +0,0 @@ -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE") -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE") -ADD_DEFINITIONS("-DMDS_TEST") -ADD_DEFINITIONS("-DEFL_BETA_API_SUPPORT") - -PKG_CHECK_MODULES(test_pkgs REQUIRED modes dlog gmock capi-network-wifi-manager capi-network-bluetooth vconf - capi-appfw-application capi-appfw-app-manager aul - capi-media-sound-manager capi-media-player - pkgmgr pkgmgr-info capi-system-device - evas elementary ecore ecore-wl2 capi-ui-efl-util) -INCLUDE_DIRECTORIES(${test_pkgs_INCLUDE_DIRS}) -LINK_DIRECTORIES(${test_pkgs_LIBRARY_DIRS}) - -SET(INTEGRATION_TEST "modes-plugintest-mode") -SET(INTEGRATION_SRCS "mdsp_test_integration.cpp") -ADD_EXECUTABLE(${INTEGRATION_TEST} ${INTEGRATION_SRCS}) -TARGET_LINK_LIBRARIES(${INTEGRATION_TEST} ${test_pkgs_LIBRARIES}) -INSTALL(TARGETS ${INTEGRATION_TEST} DESTINATION ${TEST_INSTALL_DIR}) -FILE(GLOB MODE_EX mode/*.xml) -INSTALL(FILES ${MODE_EX} DESTINATION ${MODES_MODE_DEFAULT_DIR}) -#===================================================================# -SET(WIFI_SRC_DIR "${CMAKE_SOURCE_DIR}/wifi" ) -SET(WIFI_PLUGIN_TEST "modes-plugintest-wifi") -FILE(GLOB WIFI_SRCS ${WIFI_SRC_DIR}/*.cpp) -SET(WIFI_SRCS ${WIFI_SRCS} "mdsp_test_wifi.cpp") - -ADD_EXECUTABLE(${WIFI_PLUGIN_TEST} ${WIFI_SRCS}) -TARGET_LINK_LIBRARIES(${WIFI_PLUGIN_TEST} ${test_pkgs_LIBRARIES}) -INSTALL(TARGETS ${WIFI_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR}) -#===================================================================# -SET(BT_SRC_DIR "${CMAKE_SOURCE_DIR}/bluetooth" ) -SET(BT_PLUGIN_TEST "modes-plugintest-bt") -FILE(GLOB BT_SRCS ${BT_SRC_DIR}/*.cpp) -SET(BT_SRCS ${BT_SRCS} "mdsp_test_bt.cpp") - -ADD_EXECUTABLE(${BT_PLUGIN_TEST} ${BT_SRCS}) -TARGET_LINK_LIBRARIES(${BT_PLUGIN_TEST} ${test_pkgs_LIBRARIES}) -INSTALL(TARGETS ${BT_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR}) -#===================================================================# -SET(APP_SRC_DIR "${CMAKE_SOURCE_DIR}/app" ) -SET(APP_PLUGIN_TEST "modes-plugintest-app") -FILE(GLOB APP_SRCS ${APP_SRC_DIR}/*.cpp) -SET(APP_SRCS ${APP_SRCS} "mdsp_test_app.cpp") - -ADD_EXECUTABLE(${APP_PLUGIN_TEST} ${APP_SRCS}) -TARGET_LINK_LIBRARIES(${APP_PLUGIN_TEST} ${test_pkgs_LIBRARIES}) -INSTALL(TARGETS ${APP_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR}) -#===================================================================# -SET(PKG_SRC_DIR "${CMAKE_SOURCE_DIR}/pkg" ) -SET(PKG_PLUGIN_TEST "modes-plugintest-pkg") -FILE(GLOB PKG_SRCS ${PKG_SRC_DIR}/*.cpp) -SET(PKG_SRCS ${PKG_SRCS} "mdsp_test_pkg.cpp") - -ADD_EXECUTABLE(${PKG_PLUGIN_TEST} ${PKG_SRCS}) -TARGET_LINK_LIBRARIES(${PKG_PLUGIN_TEST} ${test_pkgs_LIBRARIES}) -INSTALL(TARGETS ${PKG_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR}) -#===================================================================# -SET(VCONF_SRC_DIR "${CMAKE_SOURCE_DIR}/vconf" ) -SET(VCONF_PLUGIN_TEST "modes-plugintest-vconf") -FILE(GLOB VCONF_SRCS ${VCONF_SRC_DIR}/*.cpp) -SET(VCONF_SRCS ${VCONF_SRCS} "mdsp_test_vconf.cpp") - -ADD_EXECUTABLE(${VCONF_PLUGIN_TEST} ${VCONF_SRCS}) -TARGET_LINK_LIBRARIES(${VCONF_PLUGIN_TEST} ${test_pkgs_LIBRARIES}) -INSTALL(TARGETS ${VCONF_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR}) -#===================================================================# -SET(MEDIA_SRC_DIR "${CMAKE_SOURCE_DIR}/media" ) -SET(MEDIA_PLUGIN_TEST "modes-plugintest-media") -FILE(GLOB MEDIA_SRCS ${MEDIA_SRC_DIR}/*.cpp) -SET(MEDIA_SRCS ${MEDIA_SRCS} "mdsp_test_media.cpp") - -ADD_EXECUTABLE(${MEDIA_PLUGIN_TEST} ${MEDIA_SRCS}) -TARGET_LINK_LIBRARIES(${MEDIA_PLUGIN_TEST} ${test_pkgs_LIBRARIES}) -INSTALL(TARGETS ${MEDIA_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR}) -#===================================================================# -SET(DISPLAY_SRC_DIR "${CMAKE_SOURCE_DIR}/display" ) -SET(DISPLAY_PLUGIN_TEST "modes-plugintest-display") -FILE(GLOB DISPLAY_SRCS ${DISPLAY_SRC_DIR}/*.cpp) -SET(DISPLAY_SRCS ${DISPLAY_SRCS} "mdsp_test_display.cpp") - -ADD_EXECUTABLE(${DISPLAY_PLUGIN_TEST} ${DISPLAY_SRCS}) -TARGET_LINK_LIBRARIES(${DISPLAY_PLUGIN_TEST} ${test_pkgs_LIBRARIES}) -INSTALL(TARGETS ${DISPLAY_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR}) diff --git a/unittests/mdsp_test_app.cpp b/unittests/mdsp_test_app.cpp deleted file mode 100644 index e25e87a..0000000 --- a/unittests/mdsp_test_app.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2019-2020 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 -#include - -#include -#include -#include -#include -#include -#include -#include "plugin-def.h" - -MODES_NAMESPACE_USE; - -extern "C" Plugin* objectCreate(void); -extern "C" void objectDelete(Plugin *plugin); - -class AppPluginTest : public ::testing::Test { -protected: - void SetUp() override - { - loop = g_main_loop_new(NULL, FALSE); - plugin = objectCreate(); - } - - void TearDown() override - { - g_main_loop_unref(loop); - loop = NULL; - objectDelete(plugin); - plugin = nullptr; - } - - static gboolean appUndoTimeout(gpointer data) - { - PluginAction *action = (PluginAction*)data; - action->undo(); - g_main_loop_quit(loop); - plugin->deleteAction(action); - - return G_SOURCE_REMOVE; - } - - static gboolean checkSetUndoIdler(gpointer data) - { - PluginAction *action = plugin->newAction("launch"); - EXPECT_FALSE(action->IsCurrentValue(std::string(testApp))); - result = action->set(std::string(testApp)); - EXPECT_EQ(MODES_ERROR_NONE, result); - - if (MODES_ERROR_NONE == result) { - g_timeout_add(1000, appUndoTimeout, action); - } else { - g_main_loop_quit(loop); - plugin->deleteAction(action); - } - return G_SOURCE_REMOVE; - } - - static void changedCB(void *userData) - { - PluginAction *action = (PluginAction*)userData; - - cbCalled = true; - std::cout << ">>>>>>>> changedCB: Terminated <<<<<<<<" << std::endl; - appUndoTimeout(action); - } - - static gboolean checkChangedCBIdler(gpointer data) - { - sleep(1); - PluginAction *action = plugin->newAction("launch"); - EXPECT_FALSE(action->IsCurrentValue(std::string(testApp))); - result = action->set(std::string(testApp)); - EXPECT_EQ(MODES_ERROR_NONE, result); - - if (MODES_ERROR_NONE == result) { - int ret = action->setChangedCallback(changedCB, action); - EXPECT_EQ(MODES_ERROR_NONE, ret); - g_timeout_add(20000, appUndoTimeout, action); //For running continue - } else { - g_main_loop_quit(loop); - plugin->deleteAction(action); - } - - sleep(1); - app_context_h runAppContext = NULL; - int ret = app_manager_get_app_context(testApp, &runAppContext); - if (APP_MANAGER_ERROR_NONE != ret) - std::cout << testApp << " get_app_context() Fail:" << ret << std::endl; - else - app_manager_terminate_app(runAppContext); - - return G_SOURCE_REMOVE; - } - - static const char *testApp; - static int result; - static bool cbCalled; - static GMainLoop *loop; - static GThread *my_thread; - static Plugin *plugin; -}; - -const char *AppPluginTest::testApp = "org.tizen.setting"; -int AppPluginTest::result = 0; -bool AppPluginTest::cbCalled = false; -Plugin *AppPluginTest::plugin = nullptr; -GMainLoop *AppPluginTest::loop = NULL; - -TEST_F(AppPluginTest, CheckSetUndo) -{ - g_idle_add(checkSetUndoIdler, plugin); - g_main_loop_run(loop); -} - -TEST_F(AppPluginTest, checkChangedCB) -{ - cbCalled = false; - g_idle_add(checkChangedCBIdler, NULL); - g_main_loop_run(loop); - //TODO: at posttrans of unittest, changedCB is not called - //EXPECT_EQ(cbCalled, true); -} - -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/unittests/mdsp_test_bt.cpp b/unittests/mdsp_test_bt.cpp deleted file mode 100644 index 4fc5d24..0000000 --- a/unittests/mdsp_test_bt.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2019-2020 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 -#include -#include -#include -#include -#include "plugin-def.h" - -MODES_NAMESPACE_USE; - -extern "C" Plugin* objectCreate(void); -extern "C" void objectDelete(Plugin *plugin); - -class BtPluginTest : public ::testing::Test { -protected: - void SetUp() override - { - plugin = objectCreate(); - loop = g_main_loop_new(NULL, FALSE); - handle = modes_connect(); - } - - void TearDown() override - { - objectDelete(plugin); - plugin = nullptr; - g_main_loop_unref(loop); - loop = NULL; - modes_disconnect(handle); - handle = NULL; - } - - static gboolean apply_mode_idler(gpointer data) - { - result = modes_apply_mode(handle, (const char*)data); - - g_main_loop_quit(loop); - return G_SOURCE_REMOVE; - } - - static gboolean undo_mode_idler(gpointer data) - { - result = modes_apply_mode(handle, (const char*)data); - EXPECT_EQ(MODES_ERROR_NONE, result); - sleep(5); - result = modes_undo_mode(handle, (const char*)data); - - g_main_loop_quit(loop); - return G_SOURCE_REMOVE; - } - - static modes_h handle; - static int result; - static GMainLoop *loop; - Plugin *plugin; -}; - -int BtPluginTest::result = 0; -GMainLoop *BtPluginTest::loop = NULL; -modes_h BtPluginTest::handle = NULL; - -TEST_F(BtPluginTest, undoModebtOff) -{ - g_idle_add(undo_mode_idler, (gpointer)"btOff"); - g_main_loop_run(loop); - EXPECT_EQ(MODES_ERROR_NONE, result); -} - -TEST_F(BtPluginTest, undoModebtOn) -{ - g_idle_add(undo_mode_idler, (gpointer)"btOn"); - g_main_loop_run(loop); - EXPECT_EQ(MODES_ERROR_NONE, result); -} - -// btAudioConnect does not support undo mode -TEST_F(BtPluginTest, btAudioConnect) -{ - g_idle_add(apply_mode_idler, (gpointer)"btAudioConnect"); - g_main_loop_run(loop); - EXPECT_EQ(MODES_ERROR_NONE, result); -} - -TEST_F(BtPluginTest, btTest) -{ - int ret; - - ASSERT_TRUE(nullptr != plugin); - - PluginAction *action = plugin->newAction("power"); - ret = action->set(false); - EXPECT_EQ(ret, MODES_ERROR_NONE); - sleep(3);//for avoiding the NOW_IN_PROGRESS error - - ret = action->set(true); - EXPECT_EQ(ret, MODES_ERROR_NONE); - - ret = action->set(std::string("on")); - EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); - plugin->deleteAction(action); - - action = plugin->newAction("abcdefg"); - EXPECT_EQ(action, nullptr); -} - -int main(int argc, char **argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - diff --git a/unittests/mdsp_test_display.cpp b/unittests/mdsp_test_display.cpp deleted file mode 100644 index c038d5a..0000000 --- a/unittests/mdsp_test_display.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2019-2020 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 displaylicable 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 -#include -#include -#include "plugin-def.h" - -MODES_NAMESPACE_USE; - -extern "C" Plugin* objectCreate(void); -extern "C" void objectDelete(Plugin *plugin); - -class displayPluginTest : public ::testing::Test { -protected: - void SetUp() override - { - loop = g_main_loop_new(NULL, FALSE); - plugin = objectCreate(); - } - - void TearDown() override - { - g_main_loop_unref(loop); - loop = NULL; - objectDelete(plugin); - plugin = nullptr; - } - - static gboolean displayPluginBrightnessIdler(gpointer data) - { - PluginAction *action = plugin->newAction("brightness"); - int value = 100; - if (action->IsCurrentValue(value)) - value--; - result = action->set(value); - EXPECT_EQ(MODES_ERROR_NONE, result); - - action->undo(); - - plugin->deleteAction(action); - g_main_loop_quit(loop); - return G_SOURCE_REMOVE; - } - - static gboolean displayPluginDenyPalmTouchIdler(gpointer data) - { - PluginAction *action = plugin->newAction("denyPalmTouch"); - EXPECT_FALSE(action->IsCurrentValue(true)); - result = action->set(true); - EXPECT_EQ(MODES_ERROR_NONE, result); - - action->undo(); - - plugin->deleteAction(action); - g_main_loop_quit(loop); - return G_SOURCE_REMOVE; - } - - static gboolean displayPluginAlwaysOnIdler(gpointer data) - { - PluginAction *action = plugin->newAction("timeout"); - EXPECT_FALSE(action->IsCurrentValue(0)); - result = action->set(0); - EXPECT_EQ(MODES_ERROR_NONE, result); - - action->undo(); - - plugin->deleteAction(action); - g_main_loop_quit(loop); - return G_SOURCE_REMOVE; - } - - static gboolean displayPluginAutoBrightnessIdler(gpointer data) - { - PluginAction *action = plugin->newAction("autoBrightness"); - EXPECT_FALSE(action->IsCurrentValue(1)); - result = action->set(1); - EXPECT_EQ(MODES_ERROR_NONE, result); - - action->undo(); - - result = action->set(2); - EXPECT_EQ(MODES_ERROR_NONE, result); - - plugin->deleteAction(action); - g_main_loop_quit(loop); - return G_SOURCE_REMOVE; - } - static int result; - static GMainLoop *loop; - static Plugin *plugin; -}; - -int displayPluginTest::result = 0; -Plugin *displayPluginTest::plugin = nullptr; -GMainLoop *displayPluginTest::loop = NULL; - -TEST_F(displayPluginTest, setBrightness) -{ - g_idle_add(displayPluginBrightnessIdler, plugin); - g_main_loop_run(loop); -} - -TEST_F(displayPluginTest, setAutoBrightness) -{ - g_idle_add(displayPluginAutoBrightnessIdler, plugin); - g_main_loop_run(loop); -} - -TEST_F(displayPluginTest, setAlwaysOn) -{ - g_idle_add(displayPluginAlwaysOnIdler, plugin); - g_main_loop_run(loop); -} - -TEST_F(displayPluginTest, setDenyPalmTouch) -{ - g_idle_add(displayPluginDenyPalmTouchIdler, plugin); - g_main_loop_run(loop); -} - -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/unittests/mdsp_test_integration.cpp b/unittests/mdsp_test_integration.cpp deleted file mode 100644 index 825ad59..0000000 --- a/unittests/mdsp_test_integration.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2019-2020 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 -#include -#include - -class IntegrationTest : public ::testing::Test { -protected: - void SetUp() override - { - loop = g_main_loop_new(NULL, FALSE); - handle = modes_connect(); - } - - void TearDown() override - { - g_main_loop_unref(loop); - loop = NULL; - modes_disconnect(handle); - handle = NULL; - } - - static gboolean check_mode_idler(gpointer data) - { - modes_undo_mode(handle, (const char*)data); - result = modes_apply_mode(handle, (const char*)data); - EXPECT_EQ(MODES_ERROR_NONE, result); - sleep(2); - result = modes_undo_mode(handle, (const char*)data); - - g_main_loop_quit(loop); - return G_SOURCE_REMOVE; - } - - static modes_h handle; - static int result; - static GMainLoop *loop; -}; - -int IntegrationTest::result = 0; -GMainLoop *IntegrationTest::loop = NULL; -modes_h IntegrationTest::handle = NULL; - -TEST_F(IntegrationTest, runMode_btAudioConnect) -{ - g_idle_add(check_mode_idler, (gpointer)"btAudioConnect"); - g_main_loop_run(loop); - EXPECT_EQ(MODES_ERROR_NONE, result); -} - -TEST_F(IntegrationTest, runMode_btOff) -{ - g_idle_add(check_mode_idler, (gpointer)"btOff"); - g_main_loop_run(loop); - EXPECT_EQ(MODES_ERROR_NONE, result); -} - -TEST_F(IntegrationTest, runMode_btOn) -{ - g_idle_add(check_mode_idler, (gpointer)"btOn"); - g_main_loop_run(loop); - EXPECT_EQ(MODES_ERROR_NONE, result); -} - -TEST_F(IntegrationTest, runMode_powerSave) -{ - g_idle_add(check_mode_idler, (gpointer)"Power-Save"); - g_main_loop_run(loop); - EXPECT_EQ(MODES_ERROR_NONE, result); -} - -TEST_F(IntegrationTest, runMode_displayBlock) -{ - g_idle_add(check_mode_idler, (gpointer)"displayBlock"); - g_main_loop_run(loop); - EXPECT_EQ(MODES_ERROR_NONE, result); -} - -TEST_F(IntegrationTest, runMode_wifiOn) -{ - g_idle_add(check_mode_idler, (gpointer)"wifi-on"); - g_main_loop_run(loop); - EXPECT_EQ(MODES_ERROR_NONE, result); -} - -TEST_F(IntegrationTest, runMode_waterlock) -{ - g_idle_add(check_mode_idler, (gpointer)"Water-Lock"); - g_main_loop_run(loop); - EXPECT_EQ(MODES_ERROR_NONE, result); -} - -int main(int argc, char **argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/unittests/mdsp_test_media.cpp b/unittests/mdsp_test_media.cpp deleted file mode 100644 index 8bed4ad..0000000 --- a/unittests/mdsp_test_media.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 2019-2020 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 medialicable 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 -#include -#include -#include -#include "plugin-def.h" - -MODES_NAMESPACE_USE; - -extern "C" Plugin* objectCreate(void); -extern "C" void objectDelete(Plugin *plugin); - -class MediaPluginTest : public ::testing::Test { -protected: - void SetUp() override - { - loop = g_main_loop_new(NULL, FALSE); - plugin = objectCreate(); - } - - void TearDown() override - { - g_main_loop_unref(loop); - loop = NULL; - objectDelete(plugin); - plugin = nullptr; - } - - static gboolean mediaPlaySetUndoTimeout(gpointer data) - { - PluginAction *action = (PluginAction*)data; - action->undo(); - g_main_loop_quit(loop); - return false; - } - - static gboolean mediaPlaySetUndoIdler(gpointer data) - { - PluginAction *action = (PluginAction*)data; - const std::string file = "/opt/usr/data/settings/Ringtones/ringtone_sdk.mp3"; - EXPECT_FALSE(action->IsCurrentValue(file)); - result = action->set(file); - if (MODES_ERROR_NONE != result) { - const std::string wearableFile = "/opt/usr/data/settings/Previews/Media_preview_Over_the_horizon_B2.ogg"; - EXPECT_FALSE(action->IsCurrentValue(wearableFile)); - result = action->set(wearableFile); - } - - EXPECT_EQ(MODES_ERROR_NONE, result); - - if (MODES_ERROR_NONE == result) - g_timeout_add(1000, mediaPlaySetUndoTimeout, action); - else - g_main_loop_quit(loop); - - return G_SOURCE_REMOVE; - } - - static gboolean VolumeSetUndoIdler(gpointer data) - { - PluginAction *action; - action = plugin->newAction("mediaVolume"); - EXPECT_FALSE(action->IsCurrentValue(5)); - result = action->set(5); - EXPECT_EQ(MODES_ERROR_NONE, result); - action->undo(); - plugin->deleteAction(action); - - action = plugin->newAction("systemVolume"); - EXPECT_FALSE(action->IsCurrentValue(2)); - result = action->set(2); - EXPECT_EQ(MODES_ERROR_NONE, result); - action->undo(); - plugin->deleteAction(action); - - action = plugin->newAction("ringtoneVolume"); - EXPECT_FALSE(action->IsCurrentValue(9)); - result = action->set(9); - EXPECT_EQ(MODES_ERROR_NONE, result); - action->undo(); - plugin->deleteAction(action); - - action = plugin->newAction("notificationVolume"); - EXPECT_FALSE(action->IsCurrentValue(1)); - result = action->set(1); - EXPECT_EQ(MODES_ERROR_NONE, result); - action->undo(); - plugin->deleteAction(action); - - action = plugin->newAction("mediaVolume"); - EXPECT_FALSE(action->IsCurrentValue(-1)); - result = action->set(-1); - EXPECT_EQ(MODES_ERROR_NONE, result); - action->undo(); - plugin->deleteAction(action); - - action = plugin->newAction("systemVolume"); - EXPECT_FALSE(action->IsCurrentValue(-1)); - result = action->set(-1); - EXPECT_EQ(MODES_ERROR_NONE, result); - action->undo(); - plugin->deleteAction(action); - - action = plugin->newAction("ringtoneVolume"); - EXPECT_FALSE(action->IsCurrentValue(-1)); - result = action->set(-1); - EXPECT_EQ(MODES_ERROR_NONE, result); - action->undo(); - plugin->deleteAction(action); - - action = plugin->newAction("notificationVolume"); - EXPECT_FALSE(action->IsCurrentValue(-1)); - result = action->set(-1); - EXPECT_EQ(MODES_ERROR_NONE, result); - action->undo(); - plugin->deleteAction(action); - - g_main_loop_quit(loop); - - return G_SOURCE_REMOVE; - } - - static int result; - static GMainLoop *loop; - static Plugin *plugin; -}; - -int MediaPluginTest::result = 0; -Plugin *MediaPluginTest::plugin = nullptr; -GMainLoop *MediaPluginTest::loop = nullptr; - -TEST_F(MediaPluginTest, setUndoMediaPlay) -{ - PluginAction *action = plugin->newAction("player"); - g_idle_add(mediaPlaySetUndoIdler, action); - g_main_loop_run(loop); - plugin->deleteAction(action); -} - -TEST_F(MediaPluginTest, setUndoMediaVolume) -{ - g_idle_add(VolumeSetUndoIdler, NULL); - g_main_loop_run(loop); -} - -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/unittests/mdsp_test_pkg.cpp b/unittests/mdsp_test_pkg.cpp deleted file mode 100644 index 936a05b..0000000 --- a/unittests/mdsp_test_pkg.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2019-2020 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 -#include -#include -#include -#include -#include "plugin-def.h" - -MODES_NAMESPACE_USE; - -extern "C" Plugin* objectCreate(void); -extern "C" void objectDelete(Plugin *plugin); - -class PkgPluginTest : public ::testing::Test { -protected: - void SetUp() override - { - loop = g_main_loop_new(NULL, FALSE); - plugin = objectCreate(); - } - - void TearDown() override - { - g_main_loop_unref(loop); - loop = NULL; - objectDelete(plugin); - plugin = nullptr; - vconf_set_str("db/setting/menuscreen/package_name", "org.tizen.homescreen-efl"); - } - - static gboolean pkgPluginIdler(gpointer data) - { - g_main_loop_quit(loop); - return G_SOURCE_REMOVE; - } - - static int result; - static GMainLoop *loop; - Plugin *plugin; -}; - -GMainLoop *PkgPluginTest::loop = NULL; - -TEST_F(PkgPluginTest, setUndoTest) -{ - PluginAction *action = plugin->newAction("supportMode"); - EXPECT_FALSE(action->IsCurrentValue(1)); - int ret = action->set(1); - EXPECT_EQ(MODES_ERROR_NONE, ret); - - g_idle_add(pkgPluginIdler, plugin); - g_main_loop_run(loop); - - action->undo(); - - g_idle_add(pkgPluginIdler, plugin); - g_main_loop_run(loop); - plugin->deleteAction(action); -} - -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/unittests/mdsp_test_vconf.cpp b/unittests/mdsp_test_vconf.cpp deleted file mode 100644 index 13fc138..0000000 --- a/unittests/mdsp_test_vconf.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (c) 2019-2020 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 -#include -#include -#include -#include "plugin-log.h" -#include "plugin-def.h" - -MODES_NAMESPACE_USE; - -extern "C" Plugin* objectCreate(void); -extern "C" void objectDelete(Plugin *plugin); - -class VconfPluginTest : public ::testing::Test { -protected: - void SetUp() override - { - plugin = objectCreate(); - loop = g_main_loop_new(NULL, FALSE); - } - - void TearDown() override - { - objectDelete(plugin); - g_main_loop_unref(loop); - loop = NULL; - cb1Called = false; - cb2Called = false; - } - - static void shouldNotBeCalled(void *userData) - { - ERR("This Callback(%s) should not be called", (char*)userData); - g_main_loop_quit(loop); - GTEST_FAIL(); - } - - static void valChangedCb(void *userData) - { - DBG("%s changed callback called!", (char*)userData); - g_main_loop_quit(loop); - } - - static void callback1(void *userData) - { - PluginAction *action = (PluginAction*)userData; - DBG("%s changed callback called!", action->getKey().c_str()); - - //In practice, it is handled by Action. refer to Action.cpp - action->unSetChangedCallback(callback1); - - cb1Called = true; - } - - static void callback2(void *userData) - { - DBG("%s changed callback called!", (char*)userData); - cb2Called = true; - g_main_loop_quit(loop); - } - - static gboolean changedCallbackidler(gpointer data) - { - DBG("start change the value db/setting/psmode"); - vconf_set_int("db/setting/psmode", 7); - return G_SOURCE_REMOVE; - } - - static GMainLoop *loop; - static Plugin *plugin; - static bool cb1Called; - static bool cb2Called; -}; - -bool VconfPluginTest::cb1Called = false; -bool VconfPluginTest::cb2Called = false; -Plugin *VconfPluginTest::plugin = nullptr; -GMainLoop *VconfPluginTest::loop = NULL; - - -TEST_F(VconfPluginTest, VconfInt) -{ - int ret; - const char *key = "db.setting.psmode"; - - PluginAction *action = plugin->newAction(key);; - ret = action->set(0); - EXPECT_EQ(ret, MODES_ERROR_NONE); - - EXPECT_FALSE(action->IsCurrentValue(1)); - ret = action->set(1); - EXPECT_EQ(ret, MODES_ERROR_NONE); - - action->undo(); - plugin->deleteAction(action); -} - -TEST_F(VconfPluginTest, VconfDouble) -{ - int ret; - const char *key = "db.system.timechange_external"; - - PluginAction *action = plugin->newAction(key);; - ret = action->set(0.0); - EXPECT_EQ(ret, MODES_ERROR_NONE); - - EXPECT_FALSE(action->IsCurrentValue(1.0)); - ret = action->set(1.0); - EXPECT_EQ(ret, MODES_ERROR_NONE); - - action->undo(); - plugin->deleteAction(action); -} - -TEST_F(VconfPluginTest, VconfBool) -{ - int ret; - const char *key = "db.setting.sound.button_sounds"; - - PluginAction *action = plugin->newAction(key);; - ret = action->set(true); - EXPECT_EQ(ret, MODES_ERROR_NONE); - - EXPECT_FALSE(action->IsCurrentValue(false)); - ret = action->set(false); - EXPECT_EQ(ret, MODES_ERROR_NONE); - - action->undo(); - plugin->deleteAction(action); -} - -TEST_F(VconfPluginTest, VconfStr) -{ - int ret; - const char *key = "db.setting.device_name"; - const std::string devName = "Tizen"; - const std::string tmpName = "ModesTest"; - - PluginAction *action = plugin->newAction(key); - ret = action->set(devName); - EXPECT_EQ(ret, MODES_ERROR_NONE); - - EXPECT_FALSE(action->IsCurrentValue(tmpName)); - ret = action->set(tmpName); - EXPECT_EQ(ret, MODES_ERROR_NONE); - - action->undo(); - plugin->deleteAction(action); -} - -TEST_F(VconfPluginTest, callbackPluginVconf) -{ - int oldVal = 0; - const char *key = "db.setting.psmode"; - int ret = vconf_get_int("db/setting/psmode", &oldVal); - EXPECT_EQ(ret, 0); - - PluginAction *action = plugin->newAction(key); - ret = action->set(0); - EXPECT_EQ(ret, MODES_ERROR_NONE); - - ret = action->setChangedCallback(valChangedCb, (void*)key); - EXPECT_EQ(ret, MODES_ERROR_NONE); - g_idle_add(changedCallbackidler, nullptr); - g_main_loop_run(loop); - - // It should be removed by the changed callback procedure. - action->unSetChangedCallback(valChangedCb); - - ret = action->setChangedCallback(shouldNotBeCalled, (void*)key); - EXPECT_EQ(ret, MODES_ERROR_NONE); - action->unSetChangedCallback(shouldNotBeCalled); - plugin->deleteAction(action); - vconf_set_int("db/setting/psmode", oldVal); -} - -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/unittests/mdsp_test_wifi.cpp b/unittests/mdsp_test_wifi.cpp deleted file mode 100644 index 9605663..0000000 --- a/unittests/mdsp_test_wifi.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2019-2020 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 -#include -#include -#include -#include "plugin-def.h" - -MODES_NAMESPACE_USE; - -extern "C" Plugin* objectCreate(void); -extern "C" void objectDelete(Plugin *plugin); - -class WifiPluginTest : public ::testing::Test { -protected: - void SetUp() override - { - plugin = objectCreate(); - } - - void TearDown() override - { - objectDelete(plugin); - plugin = nullptr; - } - - static gboolean timer(gpointer data) - { - GMainLoop *loop = (GMainLoop*)data; - g_main_loop_quit(loop); - return G_SOURCE_REMOVE; - } - - Plugin *plugin; -}; - -TEST_F(WifiPluginTest, wifiTest) -{ - int ret; - - ASSERT_TRUE(nullptr != plugin); - - bool val; - PluginAction *action = plugin->newAction("power"); - val = action->IsCurrentValue(false); - ret = action->set(val); - EXPECT_EQ(ret, MODES_ERROR_NONE); - - GMainLoop *loop = g_main_loop_new(NULL, FALSE); - g_timeout_add(1000, timer, (gpointer)loop); - g_main_loop_run(loop); - - ret = action->set(!val); - EXPECT_EQ(ret, MODES_ERROR_NONE); - - ret = action->set(0); - EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); - - ret = action->set(1); - EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); - - ret = action->set(0.0); - EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); - - ret = action->set(1.0); - EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); - - ret = action->set(std::string("off")); - EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); - - ret = action->set(std::string("on")); - EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); - plugin->deleteAction(action); - - action = plugin->newAction("abcdefg"); - EXPECT_EQ(action, nullptr); -} - -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/unittests/mode/tizen_Power-Save_mode.xml b/unittests/mode/tizen_Power-Save_mode.xml deleted file mode 100644 index 6e47222..0000000 --- a/unittests/mode/tizen_Power-Save_mode.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - ULTRA_POWER_SAVING - off - off - 30 - 0 - 0 - 0 - org.tizen.menu-screen - org.tizen.homescreen-efl - - diff --git a/unittests/mode/tizen_Quick-Panel_mode.xml b/unittests/mode/tizen_Quick-Panel_mode.xml deleted file mode 100644 index 0773ef0..0000000 --- a/unittests/mode/tizen_Quick-Panel_mode.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - on - 1 - 1 - 1 - 1 - - diff --git a/unittests/mode/tizen_Water-Lock_mode.xml b/unittests/mode/tizen_Water-Lock_mode.xml deleted file mode 100644 index d499433..0000000 --- a/unittests/mode/tizen_Water-Lock_mode.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - false - true - /opt/usr/data/settings/Alarms/Alarms_on_call.ogg - - - - diff --git a/unittests/mode/tizen_appLaunch_mode.xml b/unittests/mode/tizen_appLaunch_mode.xml deleted file mode 100644 index f286dac..0000000 --- a/unittests/mode/tizen_appLaunch_mode.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - org.tizen.modesupervisor - off - off - - diff --git a/unittests/mode/tizen_btAudioConnect_mode.xml b/unittests/mode/tizen_btAudioConnect_mode.xml deleted file mode 100644 index 6359800..0000000 --- a/unittests/mode/tizen_btAudioConnect_mode.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - on - 08:AE:D6:5E:AE:16 - - diff --git a/unittests/mode/tizen_btOff_mode.xml b/unittests/mode/tizen_btOff_mode.xml deleted file mode 100644 index 5d3d3b1..0000000 --- a/unittests/mode/tizen_btOff_mode.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - off - - diff --git a/unittests/mode/tizen_btOn_mode.xml b/unittests/mode/tizen_btOn_mode.xml deleted file mode 100644 index 40e64a3..0000000 --- a/unittests/mode/tizen_btOn_mode.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - on - - diff --git a/unittests/mode/tizen_displayBlock_mode.xml b/unittests/mode/tizen_displayBlock_mode.xml deleted file mode 100644 index 66a027d..0000000 --- a/unittests/mode/tizen_displayBlock_mode.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - ALWAYS_ON - on - - diff --git a/unittests/mode/tizen_wifi-on_mode.xml b/unittests/mode/tizen_wifi-on_mode.xml deleted file mode 100644 index d2aad8d..0000000 --- a/unittests/mode/tizen_wifi-on_mode.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - on - -