Source1001: %{name}.manifest
BuildRequires: cmake
-BuildRequires: pkgconfig(modes)
BuildRequires: modes-plugin-devel
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(capi-appfw-application)
%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}.
-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}
/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
%files unittests
%manifest %{name}.manifest
%{modes_plugin_test_dir}/*
+%{modes_data_dir}/mode/*.xml
%license LICENSE.APLv2
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")
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")
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")
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")
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
{
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);
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;
}
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);
* limitations under the License.
*/
#include <glib.h>
+#include <string>
#include <gtest/gtest.h>
#include <modes.h>
+#include <Plugin.h>
+#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;
}
static int result;
static GMainLoop *loop;
+ Plugin *plugin;
};
int BtPluginTest::result = 0;
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);
--- /dev/null
+/*
+ * 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 <glib.h>
+#include <gtest/gtest.h>
+#include <modes.h>
+
+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();
+}
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
{
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;
}
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);
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include <glib.h>
+#include <string>
#include <gtest/gtest.h>
+#include <Plugin.h>
+#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);
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
+ <mode name="btAudioConnect" type="exclusive">
+ <action rule="bluetooth.power">on</action>
+ <action rule="bluetooth.audioConnect">08:AE:D6:5E:AE:16</action>
+ </mode>
+</tizenModes>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
+ <mode name="btOff" type="exclusive">
+ <action rule="bluetooth.power">off</action>
+ </mode>
+</tizenModes>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
+ <mode name="btOn" type="exclusive">
+ <action rule="bluetooth.power">on</action>
+ </mode>
+</tizenModes>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
+ <mode name="powerSave" type="exclusive">
+ <action rule="vconf.db.setting.psmode">SETTING_PSMODE_WEARABLE_ENHANCED</action>
+ <action rule="vconf.db.bluetooth.status">VCONFKEY_BT_STATUS_OFF</action>
+ </mode>
+</tizenModes>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
+ <mode name="waterlock" type="exclusive">
+ <action rule="bluetooth.power">off</action>
+ <action ID="wifiOff" rule="wifi.power" restrict="lock" priority="-100">off</action>
+ <action ID="1" rule="vconf.db.setting.psmode" restrict="lock" priority="-100">SETTING_PSMODE_WEARABLE_ENHANCED</action>
+ <undo ID="2" rule="vconf.db.setting.psmode" restrict="lock" priority="-100">SETTING_PSMODE_WEARABLE</undo>
+ <undo ID="3" rule="media.player">/opt/usr/data/settings/Alarms/Alarms_on_call.ogg</undo>
+ </mode>
+</tizenModes>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
+ <mode name="wifiOn" type="exclusive">
+ <action rule="wifi.power">on</action>
+ </mode>
+</tizenModes>