add essential unittest
authorYoungjae Shin <yj99.shin@samsung.com>
Tue, 4 Feb 2020 08:09:51 +0000 (17:09 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Wed, 18 Mar 2020 08:53:50 +0000 (17:53 +0900)
example/mode/tizen_essentialEx_mode.xml [new file with mode: 0644]
plugin/CMakeLists.txt
plugin/TestPlugin.cpp
plugin/TestPluginAction.cpp
plugin/TestPluginAction.h
plugin/tizen_test_rule.xml
unittest/modes_test_noti.cpp

diff --git a/example/mode/tizen_essentialEx_mode.xml b/example/mode/tizen_essentialEx_mode.xml
new file mode 100644 (file)
index 0000000..1a6c3af
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
+  <mode name="essential_ex" type="normal">
+    <action rule="test.printBool">on</action>
+    <action rule="test.connect">Modes-JBL</action>
+    <action rule="test.changeTime" restrict="essential">3</action>
+    <action rule="test.printInt">PRINT_TWO</action>
+    <undo ID="undo1" rule="test.printBool">true</undo>
+  </mode>
+</tizenModes>
index d82e2f6546595e07a9ea1d0671564b35fc3a6f43..3323b32b36200933b59a8afb6d03debc34c751ce 100644 (file)
@@ -1,10 +1,12 @@
-pkg_check_modules(plugin_pkgs REQUIRED dlog capi-base-common)
+SET(LIB_NAME modes-plugin-test)
+
+FILE(GLOB TEST_PLUGIN_SRCS *.cpp)
+
+PKG_CHECK_MODULES(plugin_pkgs REQUIRED dlog capi-base-common glib-2.0)
 INCLUDE_DIRECTORIES(${plugin_pkgs_INCLUDE_DIRS})
 LINK_DIRECTORIES(${plugin_pkgs_LIBRARY_DIRS})
-ADD_DEFINITIONS("-DMDS_PLUGIN")
 
-SET(LIB_NAME modes-plugin-test)
-FILE(GLOB TEST_PLUGIN_SRCS *.cpp)
+ADD_DEFINITIONS("-DMDS_PLUGIN")
 
 ADD_LIBRARY(${LIB_NAME} SHARED ${TEST_PLUGIN_SRCS})
 TARGET_LINK_LIBRARIES(${LIB_NAME} ${plugin_pkgs_LIBRARIES})
index 7ff3990d762d37b8ae9bafcb2e888b8b65b9d4ba..e94526f313b2f7347bb4e9c9bc2265b70029282a 100644 (file)
@@ -15,6 +15,7 @@
  */
 #include <thread>
 #include <chrono>
+#include <glib.h>
 #include "modes_errors.h"
 #include "Plugin.h"
 #include "PluginAction.h"
@@ -43,6 +44,13 @@ public:
        double getDouble(const std::string &key) override;
        bool getBool(const std::string &key) override;
        std::string getString(const std::string &key) override;
+private:
+       static gboolean changeTimeout(gpointer data)
+       {
+               TestPluginAction *testAction = (TestPluginAction*)data;
+               testAction->callChangedCB();
+               return  G_SOURCE_REMOVE;
+       }
 };
 
 extern "C" API Plugin *objectCreate(void)
@@ -67,7 +75,7 @@ TestPlugin::~TestPlugin()
 
 int TestPlugin::set(const std::string &key, int val, PluginAction **piAction)
 {
-       TestPluginAction *testAction = new TestPluginAction();
+       TestPluginAction *testAction = new TestPluginAction(key);
 
        if ("changeAccuracy" == key) {
                DBG("set(%s, %d)", key.c_str(), val);
@@ -85,6 +93,9 @@ int TestPlugin::set(const std::string &key, int val, PluginAction **piAction)
                delete testAction;
                DBG("set(%s, %d)", key.c_str(), val);
                return MODES_ERROR_SYSTEM;
+       } else if ("changeTime" == key) {
+               g_timeout_add_seconds(val, changeTimeout, (void*)testAction);
+               DBG("set(%s, %d)", key.c_str(), val);
        } else {
                ERR("Unknown key(%s)", key.c_str());
                return MODES_ERROR_NOT_SUPPORTED;
@@ -103,7 +114,7 @@ int TestPlugin::set(const std::string &key, double val, PluginAction **piAction)
        DBG("TestPlugin::set double ( %s, %lf )", key.c_str(), val);
 
        if (piAction) {
-               TestPluginAction *testAction = new TestPluginAction();
+               TestPluginAction *testAction = new TestPluginAction(key);
                *piAction = testAction;
        }
        return MODES_ERROR_NONE;
@@ -119,7 +130,7 @@ int TestPlugin::set(const std::string &key, bool val, PluginAction **piAction)
        }
 
        if (piAction) {
-               TestPluginAction *testAction = new TestPluginAction();
+               TestPluginAction *testAction = new TestPluginAction(key);
                *piAction = testAction;
        }
        return MODES_ERROR_NONE;
@@ -130,7 +141,7 @@ int TestPlugin::set(const std::string &key, const std::string &val, PluginAction
        DBG("TestPlugin::set string ( %s, %s )", key.c_str(), val.c_str());
 
        if (piAction) {
-               TestPluginAction *testAction = new TestPluginAction();
+               TestPluginAction *testAction = new TestPluginAction(key);
                *piAction = testAction;
        }
        return MODES_ERROR_NONE;
@@ -147,7 +158,7 @@ void TestPlugin::undo(PluginAction *piAction)
 PluginAction* TestPlugin::getUndoAction(const std::string &key, const std::string &info)
 {
        // parse the key for making PluginAction
-       TestPluginAction *piAction = new TestPluginAction();
+       TestPluginAction *piAction = new TestPluginAction(key);
        piAction->parse(info);
 
        return piAction;
index cfba5b6141394c38ba91d5f4902a3b7bb0abbb15..c88fa888782282e6c7db86b275aad106d0b06f7d 100644 (file)
@@ -21,8 +21,8 @@
 
 MODES_NAMESPACE_USE;
 
-TestPluginAction::TestPluginAction()
-       : PluginAction("testAction")
+TestPluginAction::TestPluginAction(const std::string &name)
+       : PluginAction(name)
 {
 }
 
@@ -32,12 +32,12 @@ TestPluginAction::~TestPluginAction()
 
 void TestPluginAction::undo()
 {
-       DBG("TestPluginAction::undo() is Called");
+       INFO("TestPluginAction::undo(%s) is Called", getName().c_str());
 }
 
 std::string TestPluginAction::serialize()
 {
-       return "testAction";
+       return getName();
 }
 
 int TestPluginAction::parse(const std::string &info)
@@ -48,9 +48,22 @@ int TestPluginAction::parse(const std::string &info)
 
 int TestPluginAction::setChangedCallback(valueChangedCB callback, void *userData)
 {
+       cb = callback;
+       cbData = userData;
+
        return MODES_ERROR_NONE;
 }
 
 void TestPluginAction::unSetChangedCallback(valueChangedCB callback, void *userData)
 {
+       cb = NULL;
+       cbData = NULL;
+}
+
+void TestPluginAction::callChangedCB()
+{
+       INFO("%s is changed", getName().c_str());
+
+       if (cb)
+               cb(cbData);
 }
index 9cdc722d0011341264d2143a8e6b125ba15dbe2a..2a35c3979e5ce86bf629b52893c1d92ee0e7435b 100644 (file)
@@ -23,7 +23,7 @@ MODES_NAMESPACE_BEGIN
 
 class TestPluginAction : public PluginAction {
 public:
-       TestPluginAction();
+       TestPluginAction(const std::string &name);
        ~TestPluginAction() override;
 
        void undo() override;
@@ -31,6 +31,10 @@ public:
        int parse(const std::string &data) override;
        int setChangedCallback(valueChangedCB callback, void *userData) override;
        void unSetChangedCallback(valueChangedCB callback, void *userData) override;
+       void callChangedCB();
+private:
+       valueChangedCB cb;
+       void *cbData;
 };
 
 MODES_NAMESPACE_END
index 597f6180509d263f535232c193cd3509763b25df..1d04312651f56ecf361e350541d64781a5626fb8 100644 (file)
@@ -68,5 +68,9 @@
       <desc>Sleep and return error after value seconds</desc>
       <domain>System</domain>
     </rule>
+    <rule name="test.changeTime" type="int" since="6.0" plugin="test">
+      <desc>Call Change callback after value seconds</desc>
+      <domain>System</domain>
+    </rule>
   </actionRule>
 </tizenModes>
index 97d27d64f3be8d6f7087e443118b0ee4fc15d78e..f488def54688cb7ab4ee8030f2dcee915afc2d53 100644 (file)
@@ -56,6 +56,19 @@ protected:
                return MODES_ERROR_NONE;
        }
 
+       static int changeFn(const char *modeName, int state, void *user_data)
+       {
+               char *requestMode = (char*)user_data;
+
+               std::cout << "Changed Mode : " << modeName << std::endl;
+               EXPECT_EQ(requestMode, std::string(modeName));
+               std::cout << "state : " << state << std::endl;
+
+               if (0 == state)
+                       g_main_loop_quit(loop);
+
+               return MODES_ERROR_NONE;
+       }
        static modes_h handle;
        static int expectedState;
        static GMainLoop *loop;
@@ -81,3 +94,17 @@ TEST_F(ClientNotiTest, notiConnect)
 
        modes_unsubscribe_mode_changes(handle);
 }
+
+TEST_F(ClientNotiTest, essential)
+{
+       const char *testMode = "essential_ex";
+       int ret = modes_subscribe_mode_changes(handle, changeFn, (void*)testMode);
+       EXPECT_EQ(MODES_ERROR_NONE, ret);
+
+       ret = modes_apply_mode(handle, testMode);
+       EXPECT_EQ(MODES_ERROR_NONE, ret);
+
+       g_main_loop_run(loop);
+
+       modes_unsubscribe_mode_changes(handle);
+}