From: Youngjae Shin Date: Fri, 4 Oct 2019 05:06:25 +0000 (+0900) Subject: move unittests related plugins from Modes X-Git-Tag: submit/tizen/20200406.072014~40 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=632bec1947bd9dfdac7ef6c5a76ce5dd00369c7c;p=platform%2Fcore%2Fsystem%2Fmodes-plugins.git move unittests related plugins from Modes --- diff --git a/packaging/modes-plugins.spec b/packaging/modes-plugins.spec index eeeb681..931dd2a 100644 --- a/packaging/modes-plugins.spec +++ b/packaging/modes-plugins.spec @@ -10,7 +10,6 @@ Source0: %{name}-%{version}.tar.gz Source1001: %{name}.manifest BuildRequires: cmake -BuildRequires: pkgconfig(modes) BuildRequires: modes-plugin-devel BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(capi-appfw-application) @@ -33,6 +32,7 @@ Plugin Libraries for Mode Supervisor %package unittests Summary: Test Programs for %{name} Group: System/Testing +Requires: %{name} = %{version} %description unittests The %{name}-unittests pacakge contains programs for checking quality the %{name}. @@ -59,6 +59,7 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` -DCMAKE_VERBOSE_MAKEFILE=OFF \ -DTEST_INSTALL_DIR:PATH=%{modes_plugin_test_dir} \ -DMODES_PLUGIN_DEFAULT_DIR:PATH=%{modes_plugin_dir} \ + -DMODES_MODE_DEFAULT_DIR:PATH=%{modes_data_dir}/mode \ -DMODES_ACTIONRULE_DEFAULT_DIR:PATH=%{modes_data_dir}/rule \ -DBUILD_GCOV=%{?gcov:1}%{!?gcov:0} \ -DSTDOUT_LOG=%{?stdlog:1}%{!?stdlog:0} @@ -74,14 +75,22 @@ xmllint --noout --schema %{modes_data_dir}/schema/tizen_action_rule.xsd %{buildr /sbin/ldconfig systemctl restart modes.service -%post unittests +%posttrans unittests +systemctl restart modes.service export XDG_RUNTIME_DIR=/run -%{modes_plugin_test_dir}/modes-gtest-pkg -%{modes_plugin_test_dir}/modes-gtest-vconf -%{modes_plugin_test_dir}/modes-gtest-media +%{modes_plugin_test_dir}/modes-plugintest-app +%{modes_plugin_test_dir}/modes-plugintest-vconf +%{modes_plugin_test_dir}/modes-plugintest-media +%{modes_plugin_test_dir}/modes-plugintest-wifi +%{modes_plugin_test_dir}/modes-plugintest-bt +%{modes_plugin_test_dir}/modes-plugintest-mode +%{modes_plugin_test_dir}/modes-plugintest-pkg %postun -p /sbin/ldconfig +%postun unittests +systemctl restart modes.service + %files %manifest %{name}.manifest %{modes_plugin_dir}/*.so @@ -91,4 +100,5 @@ export XDG_RUNTIME_DIR=/run %files unittests %manifest %{name}.manifest %{modes_plugin_test_dir}/* +%{modes_data_dir}/mode/*.xml %license LICENSE.APLv2 diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index 79b59c2..0f0e016 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -9,24 +9,34 @@ PKG_CHECK_MODULES(test_pkgs REQUIRED modes dlog gmock capi-network-wifi-manager 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-gtest-modemgr") -SET(WIFI_SRCS ${WIFI_SRC_DIR}/WifiAction.cpp "mdsp_test_wifi.cpp") +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-gtest-bt") -SET(BT_SRCS ${BT_SRC_DIR}/BtAction.cpp "mdsp_test_bt.cpp") +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-gtest-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") @@ -35,7 +45,7 @@ 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-gtest-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") @@ -44,7 +54,7 @@ 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-gtest-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") @@ -53,7 +63,7 @@ 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-gtest-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") diff --git a/unittests/mdsp_test_app.cpp b/unittests/mdsp_test_app.cpp index e5f750d..1c59402 100644 --- a/unittests/mdsp_test_app.cpp +++ b/unittests/mdsp_test_app.cpp @@ -27,7 +27,7 @@ MODES_NAMESPACE_USE; extern "C" API Plugin *objectCreate(void); extern "C" API void objectDelete(Plugin *plugin); -class PluginTest : public ::testing::Test { +class AppPluginTest : public ::testing::Test { protected: void SetUp() override { @@ -46,11 +46,11 @@ protected: static gboolean appPluginUndoConflictIdler(gpointer data) { PluginAction *action; - result = plugin->set("launch", std::string("org.tizen.w-stopwatch"), &action); + result = plugin->set("launch", std::string("org.tizen.net-popup"), &action); EXPECT_EQ(MODES_ERROR_NONE, result); app_context_h runAppContext; - app_manager_get_app_context("org.tizen.w-stopwatch", &runAppContext); + app_manager_get_app_context("org.tizen.net-popup", &runAppContext); app_manager_terminate_app(runAppContext); result = plugin->undo(action); EXPECT_EQ(MODES_ERROR_NONE, result); @@ -71,10 +71,14 @@ protected: static gboolean appPluginSetUndoIdler(gpointer data) { PluginAction *action; - result = plugin->set("launch", std::string("org.tizen.w-stopwatch"), &action); + result = plugin->set("launch", std::string("org.tizen.net-popup"), &action); EXPECT_EQ(MODES_ERROR_NONE, result); - g_timeout_add(1000, appPluginSetUndoTimeout, action); + if (MODES_ERROR_NONE == result) + g_timeout_add(1000, appPluginSetUndoTimeout, action); + else + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; } @@ -84,17 +88,17 @@ protected: static Plugin *plugin; }; -int PluginTest::result = 0; -Plugin *PluginTest::plugin = NULL; -GMainLoop *PluginTest::loop = NULL; +int AppPluginTest::result = 0; +Plugin *AppPluginTest::plugin = NULL; +GMainLoop *AppPluginTest::loop = NULL; -TEST_F(PluginTest, setUndoPluginApp) +TEST_F(AppPluginTest, setUndoPluginApp) { g_idle_add(appPluginSetUndoIdler, plugin); g_main_loop_run(loop); } -TEST_F(PluginTest, undoConflictPluginApp) +TEST_F(AppPluginTest, undoConflictPluginApp) { g_idle_add(appPluginUndoConflictIdler, nullptr); g_main_loop_run(loop); diff --git a/unittests/mdsp_test_bt.cpp b/unittests/mdsp_test_bt.cpp index 1b98398..23d3bc3 100644 --- a/unittests/mdsp_test_bt.cpp +++ b/unittests/mdsp_test_bt.cpp @@ -14,18 +14,29 @@ * 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); } void TearDown() override { + objectDelete(plugin); + plugin = NULL; g_main_loop_unref(loop); loop = NULL; } @@ -51,6 +62,7 @@ protected: static int result; static GMainLoop *loop; + Plugin *plugin; }; int BtPluginTest::result = 0; @@ -78,6 +90,26 @@ TEST_F(BtPluginTest, btAudioConnect) EXPECT_EQ(MODES_ERROR_NONE, result); } +TEST_F(BtPluginTest, btTest) +{ + int ret; + + ASSERT_TRUE(plugin != NULL); + + ret = plugin->set("power", false, nullptr); + EXPECT_EQ(ret, MODES_ERROR_NONE); + + ret = plugin->set("power", true, nullptr); + EXPECT_EQ(ret, MODES_ERROR_NONE); + + ret = plugin->set("power", std::string("on"), nullptr); + EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); + + ret = plugin->set("abcdefg", true, nullptr); + EXPECT_EQ(ret, MODES_ERROR_INVALID_PARAMETER); +} + + int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); diff --git a/unittests/mdsp_test_integration.cpp b/unittests/mdsp_test_integration.cpp new file mode 100644 index 0000000..0f232e4 --- /dev/null +++ b/unittests/mdsp_test_integration.cpp @@ -0,0 +1,99 @@ +/* + * 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 +#include +#include + +class IntegrationTest : public ::testing::Test { +protected: + void SetUp() override + { + loop = g_main_loop_new(NULL, FALSE); + } + + void TearDown() override + { + g_main_loop_unref(loop); + loop = NULL; + } + + static gboolean check_mode_idler(gpointer data) + { + modes_undo_mode((const char*)data); + result = modes_apply_mode((const char*)data); + EXPECT_EQ(MODES_ERROR_NONE, result); + sleep(2); + result = modes_undo_mode((const char*)data); + + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } + + static int result; + static GMainLoop *loop; +}; + +int IntegrationTest::result = 0; +GMainLoop *IntegrationTest::loop = 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)"powerSave"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); +} + +TEST_F(IntegrationTest, runMode_waterlock) +{ + g_idle_add(check_mode_idler, (gpointer)"waterlock"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); +} + +TEST_F(IntegrationTest, runMode_wifiOn) +{ + g_idle_add(check_mode_idler, (gpointer)"wifiOn"); + 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 index 8e2c129..119986f 100644 --- a/unittests/mdsp_test_media.cpp +++ b/unittests/mdsp_test_media.cpp @@ -25,7 +25,7 @@ MODES_NAMESPACE_USE; extern "C" API Plugin *objectCreate(void); extern "C" API void objectDelete(Plugin *plugin); -class PluginTest : public ::testing::Test { +class MediaPluginTest : public ::testing::Test { protected: void SetUp() override { @@ -53,10 +53,17 @@ protected: static gboolean mediaPluginSetUndoIdler(gpointer data) { PluginAction *action; - result = plugin->set("player", std::string("/opt/usr/data/settings/Previews/Media_preview_Over_the_horizon_B2.ogg"), &action); + result = plugin->set("player", std::string("/opt/usr/data/settings/Ringtones/ringtone_sdk.mp3"), &action); + if (MODES_ERROR_NONE != result) + result = plugin->set("player", std::string("/opt/usr/data/settings/Previews/Media_preview_Over_the_horizon_B2.ogg"), &action); + EXPECT_EQ(MODES_ERROR_NONE, result); - g_timeout_add(1000, mediaPluginSetUndoTimeout, action); + if (MODES_ERROR_NONE == result) + g_timeout_add(1000, mediaPluginSetUndoTimeout, action); + else + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; } @@ -65,11 +72,11 @@ protected: static Plugin *plugin; }; -int PluginTest::result = 0; -Plugin *PluginTest::plugin = NULL; -GMainLoop *PluginTest::loop = NULL; +int MediaPluginTest::result = 0; +Plugin *MediaPluginTest::plugin = NULL; +GMainLoop *MediaPluginTest::loop = NULL; -TEST_F(PluginTest, setUndoPluginmedia) +TEST_F(MediaPluginTest, setUndoPluginmedia) { g_idle_add(mediaPluginSetUndoIdler, plugin); g_main_loop_run(loop); diff --git a/unittests/mdsp_test_wifi.cpp b/unittests/mdsp_test_wifi.cpp index e083c6b..5e3a725 100644 --- a/unittests/mdsp_test_wifi.cpp +++ b/unittests/mdsp_test_wifi.cpp @@ -13,7 +13,66 @@ * 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 = NULL; + } + + Plugin *plugin; +}; + +TEST_F(WifiPluginTest, wifiTest) +{ + int ret; + + ASSERT_TRUE(plugin != NULL); + + ret = plugin->set("power", false, nullptr); + EXPECT_EQ(ret, MODES_ERROR_NONE); + + ret = plugin->set("power", true, nullptr); + EXPECT_EQ(ret, MODES_ERROR_NONE); + + ret = plugin->set("power", 0, nullptr); + EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); + + ret = plugin->set("power", 1, nullptr); + EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); + + ret = plugin->set("power", 0.0, nullptr); + EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); + + ret = plugin->set("power", 1.0, nullptr); + EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); + + ret = plugin->set("power", std::string("off"), nullptr); + EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); + + ret = plugin->set("power", std::string("on"), nullptr); + EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); + + ret = plugin->set("abcdefg", true, nullptr); + EXPECT_EQ(ret, MODES_ERROR_INVALID_PARAMETER); +} int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); diff --git a/unittests/mode/tizen_btAudioConnect_mode.xml b/unittests/mode/tizen_btAudioConnect_mode.xml new file mode 100644 index 0000000..d45e639 --- /dev/null +++ b/unittests/mode/tizen_btAudioConnect_mode.xml @@ -0,0 +1,7 @@ + + + + on + 08:AE:D6:5E:AE:16 + + diff --git a/unittests/mode/tizen_btOff_mode.xml b/unittests/mode/tizen_btOff_mode.xml new file mode 100644 index 0000000..0c29375 --- /dev/null +++ b/unittests/mode/tizen_btOff_mode.xml @@ -0,0 +1,6 @@ + + + + off + + diff --git a/unittests/mode/tizen_btOn_mode.xml b/unittests/mode/tizen_btOn_mode.xml new file mode 100644 index 0000000..14ee9e2 --- /dev/null +++ b/unittests/mode/tizen_btOn_mode.xml @@ -0,0 +1,6 @@ + + + + on + + diff --git a/unittests/mode/tizen_powerSave_mode.xml b/unittests/mode/tizen_powerSave_mode.xml new file mode 100644 index 0000000..5ece2f8 --- /dev/null +++ b/unittests/mode/tizen_powerSave_mode.xml @@ -0,0 +1,7 @@ + + + + SETTING_PSMODE_WEARABLE_ENHANCED + VCONFKEY_BT_STATUS_OFF + + diff --git a/unittests/mode/tizen_waterlock_mode.xml b/unittests/mode/tizen_waterlock_mode.xml new file mode 100644 index 0000000..f4bac82 --- /dev/null +++ b/unittests/mode/tizen_waterlock_mode.xml @@ -0,0 +1,10 @@ + + + + off + off + SETTING_PSMODE_WEARABLE_ENHANCED + SETTING_PSMODE_WEARABLE + /opt/usr/data/settings/Alarms/Alarms_on_call.ogg + + diff --git a/unittests/mode/tizen_wifiOn_mode.xml b/unittests/mode/tizen_wifiOn_mode.xml new file mode 100644 index 0000000..0491aad --- /dev/null +++ b/unittests/mode/tizen_wifiOn_mode.xml @@ -0,0 +1,6 @@ + + + + on + +