add value validation checker
authorYoungjae Shin <yj99.shin@samsung.com>
Thu, 26 Sep 2019 01:49:25 +0000 (10:49 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Wed, 18 Mar 2020 08:53:50 +0000 (17:53 +0900)
21 files changed:
example/mode/tizen_ex1_mode.xml
example/mode/tizen_ex2_mode.xml
example/mode/tizen_invalid1_mode.xml [new file with mode: 0644]
example/mode/tizen_invalid2_mode.xml [new file with mode: 0644]
example/rule/tizen_ex_rule.xml
example/rule/tizen_ex_rule_fail.xml [deleted file]
example/rule/tizen_fail1_rule.xml [new file with mode: 0644]
example/rule/tizen_fail2_rule.xml [new file with mode: 0644]
supervisor/Action.h
supervisor/ActionRule.h
supervisor/Mode.h
supervisor/ModeXMLParser.cpp
supervisor/RuleManager.cpp
supervisor/RuleManager.h
supervisor/TAction.h
supervisor/TActionRule.h
supervisor/ValueChecker.cpp [new file with mode: 0644]
supervisor/ValueChecker.h [new file with mode: 0644]
unittest/CMakeLists.txt
unittest/modes_test_parser.cpp
unittest/modes_test_rulemgr.cpp

index 43ee7c1e5db890ce36db650f269d18f482454cd7..9887d3a0dcc9b8ef36548e1ede2734ff6c64f17e 100644 (file)
@@ -1,13 +1,12 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="6.0">
   <mode name="ex1" type="normal">
-    <action ID="wifiOn" rule="wifi.power" priority="-100">on</action>
-    <action rule="notification.donotdisturb">on</action>
-    <action rule="application.launch" before="GoPbsKids">com.vpn.usa123</action>
-    <action ID="GoPbsKids" rule="browser.url" after="wifiOn">https://pbskids.org/</action>
-    <action ID="BMJ" rule="bluetooth.connet">Modes-JBL</action>
-    <action rule="media.music.player" after="BMJ">beatles-yesterday.mp3</action>
-    <action ID="1" rule="vconf.db.setting.psmode" priority="-100"
-         >SETTING_PSMODE_NORMAL</action>
+    <action ID="wifiOn" rule="test.printBool" priority="-100">on</action>
+    <action rule="test.launch" before="GoPbsKids">com.vpn.usa123</action>
+    <action ID="GoPbsKids" rule="test.url" after="wifiOn">https://pbskids.org/</action>
+    <action ID="BMJ" rule="test.connect">Modes-JBL</action>
+    <action rule="test.player" after="BMJ">beatles-yesterday.mp3</action>
+    <action ID="1" rule="test.printInt" priority="-100"
+         >PRINT_TWO</action>
   </mode>
 </tizenModes>
index 5f2277b4248bc0e3554c65fe290d677966a49091..bf4d7218153b1aaad618792a063c842aab2b8aad 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="6.0">
   <mode name="ex2" type="exclusive">
-    <action ID="1" rule="vconf.db.setting.psmode" stopOnErr="true" restrict="lock" priority="-100">SETTING_PSMODE_WEARABLE</action>
-    <action ID="wifiOff" rule="wifi.power" restrict="lock" priority="-100">off</action>
+    <action ID="1" rule="test.printInt" stopOnErr="true" restrict="lock" priority="-100">PRINT_FOUR</action>
+    <action ID="wifiOff" rule="test.printBool" restrict="lock" priority="-100">off</action>
   </mode>
 </tizenModes>
diff --git a/example/mode/tizen_invalid1_mode.xml b/example/mode/tizen_invalid1_mode.xml
new file mode 100644 (file)
index 0000000..c34416b
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
+  <mode name="invalid1" type="exclusive">
+    <action rule="test.printBool">123</action>
+  </mode>
+</tizenModes>
diff --git a/example/mode/tizen_invalid2_mode.xml b/example/mode/tizen_invalid2_mode.xml
new file mode 100644 (file)
index 0000000..374eef1
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
+  <mode name="invalid2" type="exclusive">
+    <action rule="test.printInt">PRINT_TREE</action>
+  </mode>
+</tizenModes>
index dfebdb7c7831203a0f5241025aa75a4ed351940d..c99b94021b8f16649f995d3c6f36ed04bbfe149c 100644 (file)
@@ -1,30 +1,49 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="6.0">
   <actionRule>
-    <rule name="sensord.changeAccuracy" type="int" since="6.0" plugin="sensor-fw">
-      <conflict>sensord.exactness</conflict>
+    <rule name="test.changeAccuracy" type="int" since="6.0" plugin="test">
+      <conflict>test.exactness</conflict>
       <desc>Sensor Accuracy</desc>
       <domain>System</domain>
     </rule>
-    <rule name="sensord.exactness" type="int" since="6.0" plugin="sensor-fw">
-      <conflict>sensord.changeAccuracy</conflict>
+    <rule name="test.exactness" type="int" since="6.0" plugin="test">
+      <conflict>test.changeAccuracy</conflict>
       <desc>Sensor Exactness</desc>
       <domain>System</domain>
     </rule>
-    <rule name="browser.url" type="string" since="6.0" plugin="web">
+    <rule name="test.url" type="string" since="6.0" plugin="test">
       <desc>browser</desc>
       <domain>Web Framework</domain>
     </rule>
-    <rule name="display.nightLight" type="int" since="6.0" plugin="display">
+    <rule name="test.nightLight" type="int" since="6.0" plugin="test">
       <conflict>display.autoLight</conflict>
       <desc>It makes the screen color warmer.</desc>
       <domain>System</domain>
     </rule>
+    <rule name="test.launch" type="string" since="6.0" plugin="test">
+      <desc>Launch App</desc>
+      <domain>App Framework</domain>
+    </rule>
+    <rule name="test.connect" type="string" since="6.0" plugin="test">
+      <desc>bluetooth Audio Connect</desc>
+      <domain>Network &amp; Connectivity</domain>
+    </rule>
+    <rule name="test.player" type="string" since="6.0" plugin="test">
+      <desc>Audio/Video player</desc>
+      <domain>Multimedia</domain>
+    </rule>
     <rule name="test.printInt" type="int" since="6.0" plugin="test">
-      <desc>It prints integerv value</desc>
+      <alias name="PRINT_ZERO">0</alias>
+      <alias name="PRINT_ONE">1</alias>
+      <alias name="PRINT_TWO">2</alias>
+      <alias name="PRINT_THREE">3</alias>
+      <alias name="PRINT_FOUR">4</alias>
+      <desc>It prints integer value</desc>
       <domain>System</domain>
     </rule>
     <rule name="test.printBool" type="bool" since="6.0" plugin="test">
+      <alias name="on">1</alias>
+      <alias name="off">0</alias>
       <desc>It prints boolean value</desc>
       <domain>System</domain>
     </rule>
diff --git a/example/rule/tizen_ex_rule_fail.xml b/example/rule/tizen_ex_rule_fail.xml
deleted file mode 100644 (file)
index 9d64a56..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<tizenModes xmlns="http://www.tizen.org" version="6.0">
-  <actionRule>
-    <rule name="sensord.changeAccuracy" type="int" since="6.0" plugin="sensor-fw">
-      <conflict>sensord.exactness</conflict>
-      <desc>Sensor Accuracy</desc>
-      <domain>System</domain>
-    </rule>
-    <rule name="sensord.exactness" type="int" since="6.0" plugin="sensor-fw">
-      <conflict>sensord.changeAccuracy</conflict>
-      <desc>Sensor Exactness</desc>
-      <domain>System</domain>
-    </rule>
-    <rule name="browser.url" type="string" since="6.0" plugin="web">
-      <desc>browser</desc>
-      <domain>Web Framework</domain>
-    </rule>
-    <rule name="display.nightLight" type="int" since="6.0" plugin="display">
-      <conflict>display.autoLight</conflict>
-      <desc>It makes the screen color warmer.</desc>
-      <domain>System</domain>
-    </rule>
-    <rule name="test.printInt" type="int" since="6.0" plugin="test">
-      <desc>It prints integerv value</desc>
-      <domain>System</domain>
-    </rule>
-    <rule name="test.printBool" type="bool" since="6.0" plugin="test">
-      <desc>It prints boolean value</desc>
-      <domain>System</domain>
-    </rule>
-    <rule name="test.printBool" type="int" since="6.0" plugin="test1">
-      <desc>It prints new boolean value</desc>
-      <domain>System</domain>
-    </rule>
-  </actionRule>
-</tizenModes>
diff --git a/example/rule/tizen_fail1_rule.xml b/example/rule/tizen_fail1_rule.xml
new file mode 100644 (file)
index 0000000..b3d3621
--- /dev/null
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
+  <actionRule>
+    <rule name="sensord.changeAccuracy" type="int" since="6.0" plugin="sensor-fw">
+      <conflict>sensord.exactness</conflict>
+      <desc>Sensor Accuracy</desc>
+      <domain>System</domain>
+    </rule>
+    <rule name="sensord.exactness" type="int" since="6.0" plugin="sensor-fw">
+      <conflict>sensord.changeAccuracy</conflict>
+      <desc>Sensor Exactness</desc>
+      <domain>System</domain>
+    </rule>
+    <rule name="browser.url" type="string" since="6.0" plugin="web">
+      <desc>browser</desc>
+      <domain>Web Framework</domain>
+    </rule>
+    <rule name="display.nightLight" type="int" since="6.0" plugin="display">
+      <conflict>display.autoLight</conflict>
+      <desc>It makes the screen color warmer.</desc>
+      <domain>System</domain>
+    </rule>
+    <rule name="test.printInt" type="int" since="6.0" plugin="test">
+      <desc>It prints integer value</desc>
+      <domain>System</domain>
+    </rule>
+    <rule name="test.printBool" type="bool" since="6.0" plugin="test">
+      <desc>It prints boolean value</desc>
+      <domain>System</domain>
+    </rule>
+    <rule name="test.printBool" type="int" since="6.0" plugin="test1">
+      <desc>It is a duplicated Rule, It Must be unique</desc>
+      <domain>System</domain>
+    </rule>
+  </actionRule>
+</tizenModes>
diff --git a/example/rule/tizen_fail2_rule.xml b/example/rule/tizen_fail2_rule.xml
new file mode 100644 (file)
index 0000000..3c5b401
--- /dev/null
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
+  <actionRule>
+    <rule name="sensord.changeAccuracy" type="int" since="6.0" plugin="sensor-fw">
+      <conflict>sensord.exactness</conflict>
+      <desc>Sensor Accuracy</desc>
+      <domain>System</domain>
+    </rule>
+    <rule name="sensord.exactness" type="int" since="6.0" plugin="sensor-fw">
+      <conflict>sensord.changeAccuracy</conflict>
+      <desc>Sensor Exactness</desc>
+      <domain>System</domain>
+    </rule>
+    <rule name="browser.url" type="string" since="6.0" plugin="web">
+      <desc>browser</desc>
+      <domain>Web Framework</domain>
+    </rule>
+    <rule name="display.nightLight" type="int" since="6.0" plugin="display">
+      <conflict>display.autoLight</conflict>
+      <desc>It makes the screen color warmer.</desc>
+      <domain>System</domain>
+    </rule>
+    <rule name="test.printInt" type="int" since="6.0" plugin="test">
+      <alias name="PRINT_ZERO">0</alias>
+      <alias name="PRINT_ONE">1</alias>
+      <alias name="PRINT_TWO">2</alias>
+      <alias name="PRINT_THREE">3</alias>
+      <alias name="PRINT_FOUR">4th</alias>
+      <desc>It prints integer value</desc>
+      <domain>System</domain>
+    </rule>
+    <rule name="test.printBool" type="bool" since="6.0" plugin="test">
+      <desc>It prints boolean value</desc>
+      <domain>System</domain>
+    </rule>
+  </actionRule>
+</tizenModes>
index 2817a62c318df6e0baa7743460a1cd297dd3087c..ac8c184fdf5fe6e5045e49044e7dac25f13e277d 100644 (file)
@@ -45,7 +45,7 @@ public:
        void setIsChanged();
        bool getIsChanged();
        void setPlugin(Plugin *pi);
-       virtual void setValue(const std::string &val) = 0;
+       virtual int setValue(const std::string &val) = 0;
        virtual std::string getStringOfValue() = 0;
        virtual int apply() = 0;
        virtual int applyOneShot() = 0;
index ee6762c3d4bc0b34569331000554494b1d03b25b..191315dc1a3d4f6d72b668d86fd45248746a7259 100644 (file)
@@ -29,7 +29,7 @@ public:
        std::string getPlugin();
        void setPlugin(const std::string &pi);
        virtual Action* makeAction() = 0;
-       virtual void addAlias(const std::string &alias, const std::string &value) = 0;
+       virtual int addAlias(const std::string &alias, const std::string &value) = 0;
 protected:
        std::string ruleName;
 private:
index 104df15c42eaf1c874c0d95d88eee0c0024a8041..7d9097435f4213ab0d8642f1a57ea8367c84a54b 100644 (file)
@@ -59,7 +59,7 @@ private:
        std::list<std::shared_ptr<Action>> actionList;
        std::list<std::shared_ptr<Action>> undoList;
 #ifdef MDS_TEST
-       friend class TestParser;
+       friend class ParserTest;
 #endif
 };
 
index 9890c32ed7f6a9ad84fda5c3c4a1b1fb562aee04..f16966abf2b7232158d1763b55bd70ccb68d4b16 100644 (file)
@@ -168,7 +168,7 @@ void ModeXMLParser::parseAction(xmlNodePtr node)
        mode.addAction(action);
 }
 
-Action *ModeXMLParser::parseActionInfo(xmlNodePtr node)
+ActionModeXMLParser::parseActionInfo(xmlNodePtr node)
 {
        char *ruleProp = (char*)xmlGetProp(node, ModeTag::RULE);
        if (ruleProp == NULL) {
@@ -192,13 +192,17 @@ Action *ModeXMLParser::parseActionInfo(xmlNodePtr node)
        parseActionAttr(node, action);
 
        char *nodeContent = (char*)xmlNodeGetContent(node);
-       if (nodeContent == NULL) {
+       if (nodeContent == NULL)
                ERR("Node Content is null!");
-       }
 
-       action->setValue(nodeContent ? nodeContent : "");
+       int ret = action->setValue(nodeContent ? nodeContent : "");
        xmlFree(nodeContent);
 
+       if (MODES_ERROR_NONE != ret) {
+               ERR("Action(%s) setValue() Fail(%d)", action->getRuleName().c_str(), ret);
+               throw ModesEx(ModesEx::PARSER_ERROR, "Invalid Action Value");
+       }
+
        action->printInfo();
        return action;
 }
index a0dd88632b74b3c260b69725b9a63ee701b3e3e9..397de55c27037507b17852d4977ab861a8abe350 100644 (file)
@@ -59,9 +59,7 @@ void RuleManager::makeRuleMap()
                        parseActionRule(fileFullPath);
                        DBG("Action Rule(size=%d) Load", ruleMap.size());
                } catch (ModesEx &e) {
-                       ERR("parseActionRule(%s) Fail(%s)", fileFullPath.c_str(), e.what());
-                       closedir(dir);
-                       throw;
+                       ERR("parseActionRule(%s) Fail(%s) : It will be ignored", fileFullPath.c_str(), e.what());
                }
        }
        closedir(dir);
@@ -92,7 +90,14 @@ void RuleManager::parseElement(xmlNodePtr cur, ActionRule *actionRule)
                        return;
                }
 
-               actionRule->addAlias(alias, value);
+               int ret = actionRule->addAlias(alias, value);
+               if (MODES_ERROR_NONE != ret) {
+                       ERR("Rule(%s) %s(%s) Fail(%d)", actionRule->getName().c_str(), alias, value, ret);
+                       xmlFree(value);
+                       xmlFree(alias);
+                       throw ModesEx(ModesEx::NO_DATA, "Invalid Alias Value");
+               }
+
                xmlFree(value);
                xmlFree(alias);
        } else if (MDS_EQUAL == xmlStrcmp(cur->name, RULE_TAGS[TagElemConflict])) {
@@ -155,7 +160,7 @@ ActionRule* RuleManager::makeRule(xmlNodePtr node)
                plugin = getProp(node, TagAttPlugin);
        } catch (ModesEx &e) {
                ERR("getProp() Fail(%s)", e.what());
-               return nullptr;
+               throw;
        }
 
        DBG("Action(%s, %s) Added", name.c_str(), type.c_str());
index 4b0ca218971b443895502aadfcd194aadc61bca4..7b82a7d6b26dee23374823e57220072c9e753b1c 100644 (file)
@@ -58,6 +58,7 @@ private:
 
 #ifdef MDS_TEST
        friend class RuleManagerTest;
+       friend class ParserTest;
 #endif
 };
 
index c0a57a16b014afabe13fc61e3424e00daf63356a..bcb1d3997539fbfdfb00f500ab99bc33644ff453 100644 (file)
@@ -20,6 +20,7 @@
 #include <sstream>
 #include "mdss.h"
 #include "Action.h"
+#include "ValueChecker.h"
 
 MODES_NAMESPACE_BEGIN
 
@@ -52,15 +53,22 @@ public:
                return val;
        }
 
-       void setValue(const std::string &val) override
+       int setValue(const std::string &val) override
        {
                auto it = valueAliases.find(val);
                if (it != valueAliases.end()) {
                        value = it->second;
                } else {
-                       std::istringstream iss(val);
-                       iss >> value;
+                       ValueChecker checker;
+                       if (checker.checkValue(T(), val)) {
+                               std::istringstream iss(val);
+                               iss >> value;
+                       } else {
+                               return MODES_ERROR_INVALID_TYPE;
+                       }
                }
+
+               return MODES_ERROR_NONE;
        }
 
        int apply() override
@@ -89,7 +97,7 @@ public:
                int ret = plugin->set(ruleName.substr(pos + 1), value, &tmpAction);
                if (MODES_ERROR_NONE != ret) {
                        ERR("plugin(%s) set Fail(%d)", plugin->getName().c_str(), ret);
-                               return ret;
+                       return ret;
                }
 
                piAction = tmpAction;
index 96081ac1fc9e1561ce19b35f00f3653d9e26fabb..920ee355449b568e08f24a5da3f5296d253492c5 100644 (file)
@@ -41,12 +41,20 @@ public:
                return action;
        }
 
-       void addAlias(const std::string &alias, const std::string &value) override
+       int addAlias(const std::string &alias, const std::string &value) override
        {
+               ValueChecker checker;
+               if (false == checker.checkValue(T(), value)) {
+                       ERR("checkValue() Fail");
+                       return MODES_ERROR_INVALID_TYPE;
+               }
+
                T realVal;
                std::istringstream iss(value);
                iss >> realVal;
                valueAliasList.insert(std::pair<std::string, T>(alias, realVal));
+
+               return MODES_ERROR_NONE;
        }
 private:
        std::map<std::string, T> valueAliasList;
diff --git a/supervisor/ValueChecker.cpp b/supervisor/ValueChecker.cpp
new file mode 100644 (file)
index 0000000..c9d9042
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * 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 "ValueChecker.h"
+
+#include "mdss.h"
+
+MODES_NAMESPACE_USE;
+
+bool ValueChecker::checkValue(int, const std::string &val)
+{
+       for (auto it = val.begin(); it != val.end(); ++it) {
+               if (*it < '0' || '9' < *it)
+                       return false;
+       }
+
+       return true;
+}
+
+bool ValueChecker::checkValue(double, const std::string &val)
+{
+       int dotNum = 0;
+       for (auto it = val.begin(); it != val.end(); ++it) {
+               if (*it < '0' || '9' < *it) {
+                       if ('.' != *it)
+                               return false;
+                       else if (dotNum)
+                               return false;
+                       else
+                               dotNum++;
+               }
+       }
+
+       return true;
+}
+
+bool ValueChecker::checkValue(bool, const std::string &val)
+{
+       if (MDS_EQUAL == val.compare("1"))
+               return true;
+       if (MDS_EQUAL == val.compare("0"))
+               return true;
+
+       return false;
+}
+
+bool ValueChecker::checkValue(std::string, const std::string &val)
+{
+       return true;
+}
diff --git a/supervisor/ValueChecker.h b/supervisor/ValueChecker.h
new file mode 100644 (file)
index 0000000..9e69906
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+#pragma once
+
+#include <string>
+#include "mdss.h"
+
+MODES_NAMESPACE_BEGIN
+
+class ValueChecker {
+public:
+       ValueChecker() = default;
+       ~ValueChecker() = default;
+
+       bool checkValue(int, const std::string &val);
+       bool checkValue(double, const std::string &val);
+       bool checkValue(bool, const std::string &val);
+       bool checkValue(std::string, const std::string &val);
+};
+
+MODES_NAMESPACE_END
index 438aa9dca639a0f6e77e3d8e1f828aa8c4b14990..43d8ee5ac927c117b5d7c92a4c6096b5f00f2525 100644 (file)
@@ -28,6 +28,7 @@ FILE(GLOB GTEST_MODEMGR_SRCS
                ${SUPERVISOR_DIR}/Mode.cpp
                ${SUPERVISOR_DIR}/ModesEx.cpp
                ${SUPERVISOR_DIR}/PluginManager.cpp
+               ${SUPERVISOR_DIR}/ValueChecker.cpp
                modes_test_modemgr.cpp
        )
 ADD_EXECUTABLE(${GTEST_MODEMGR} ${SRC} ${GTEST_MODEMGR_SRCS})
@@ -57,6 +58,7 @@ FILE(GLOB GTEST_PARSER_SRCS
                ${SUPERVISOR_DIR}/ModesEx.cpp
                ${SUPERVISOR_DIR}/Mode.cpp
                ${SUPERVISOR_DIR}/ModeTag.cpp
+               ${SUPERVISOR_DIR}/ValueChecker.cpp
                modes_test_parser.cpp
        )
 ADD_EXECUTABLE(${GTEST_PARSER} ${SRC} ${GTEST_PARSER_SRCS})
@@ -90,6 +92,7 @@ FILE(GLOB GTEST_GENERATOR_SRCS
                ${SUPERVISOR_DIR}/PluginManager.cpp
                ${SUPERVISOR_DIR}/RuleManager.cpp
                ${SUPERVISOR_DIR}/ActionRule.cpp
+               ${SUPERVISOR_DIR}/ValueChecker.cpp
                "modes_test_generator.cpp"
        )
 ADD_EXECUTABLE(${GTEST_GENERATOR} ${SRC} ${GTEST_GENERATOR_SRCS})
@@ -110,6 +113,7 @@ FILE(GLOB GTEST_CONFLICT_SRCS
                ${SUPERVISOR_DIR}/PluginManager.cpp
                ${SUPERVISOR_DIR}/RuleManager.cpp
                ${SUPERVISOR_DIR}/ActionRule.cpp
+               ${SUPERVISOR_DIR}/ValueChecker.cpp
                modes_test_conflict.cpp
        )
 ADD_EXECUTABLE(${GTEST_CONFLICT} ${SRC} ${GTEST_CONFLICT_SRCS})
@@ -124,6 +128,7 @@ FILE(GLOB GTEST_RULE_SRCS
                ${SUPERVISOR_DIR}/ModesEx.cpp
                ${SUPERVISOR_DIR}/Mode.cpp
                ${SUPERVISOR_DIR}/Action.cpp
+               ${SUPERVISOR_DIR}/ValueChecker.cpp
                modes_test_rulemgr.cpp
        )
 ADD_EXECUTABLE(${GTEST_RULEMGR} ${SRC} ${GTEST_RULE_SRCS})
index 951a46f33f05c0fb673629852425aaa1e94abb41..04c2216efb0cef5029221d62a932b2cdc680f3f1 100644 (file)
 #include <memory>
 #include <gtest/gtest.h>
 #include "supervisor/Mode.h"
-#include "supervisor/ModeXMLParser.h"
+#include "supervisor/ModesEx.h"
 #include "supervisor/RuleManager.h"
+#include "supervisor/ModeXMLParser.h"
 
 MODES_NAMESPACE_USE;
 using namespace std;
 
 MODES_NAMESPACE_BEGIN
-class TestParser {
+class ParserTest {
 public:
-       void parserTest(const string &fileName);
+       void initRuleManger();
        list<std::shared_ptr<Action>> getActionList(Mode& m);
+
+       RuleManager ruleMgr;
 private:
 };
 MODES_NAMESPACE_END
 
-list<std::shared_ptr<Action>> TestParser::getActionList(Mode& m)
+
+void ParserTest::initRuleManger()
+{
+       ruleMgr.setOptions(std::string(), "./" MODES_ACTIONRULE_DEFAULT_XSD_FILE);
+       ruleMgr.parseActionRule("./tizen_ex_rule.xml");
+}
+
+list<std::shared_ptr<Action>> ParserTest::getActionList(Mode& m)
 {
        return m.actionList;
 }
@@ -71,7 +81,7 @@ TEST(Mode, printAction)
        RuleManager ruleMgr;
        ModeXMLParser modeparser("tizen_ex1_mode.xml", ruleMgr, pluginManager);
        Mode mode = modeparser.getMode();
-       TestParser parserT;
+       ParserTest parserT;
 
        list<std::shared_ptr<Action>> actionList = parserT.getActionList(mode);
        EXPECT_FALSE(actionList.empty());
@@ -82,3 +92,16 @@ TEST(Mode, printAction)
                //cout << "\t\t- Content : " << (*it)->getValue() << endl;
        }
 }
+
+TEST(Mode, invalidActionValue)
+{
+       ParserTest parserT;
+       parserT.initRuleManger();
+
+       PluginManager piMgr;
+       ModeXMLParser modeparser1("tizen_invalid1_mode.xml", parserT.ruleMgr, piMgr);
+       EXPECT_THROW(modeparser1.getMode(), ModesEx);
+
+       ModeXMLParser modeparser2("tizen_invalid2_mode.xml", parserT.ruleMgr, piMgr);
+       EXPECT_THROW(modeparser2.getMode(), ModesEx);
+}
index 7e1967be9300dca67c007b505149cb50c5bd8561..18230f980cdbb4abd6e3734b4fc63f2b8146da2e 100644 (file)
@@ -44,7 +44,6 @@ RuleManagerTest::RuleManagerTest()
        rMgr.setOptions(config.actionRuleDir, config.actionRuleXsdFile);
 }
 
-
 TEST(RuleManagerTest, makeRuleMapP)
 {
        RuleManagerTest testBroker;
@@ -57,8 +56,14 @@ TEST(RuleManagerTest, parseActionRuleP)
        EXPECT_NO_THROW(testBroker.parseActionRule("./tizen_ex_rule.xml"));
 }
 
-TEST(RuleManagerTest, parseActionRuleN)
+TEST(RuleManagerTest, DuplicatedRule)
+{
+       RuleManagerTest testBroker;
+       EXPECT_THROW(testBroker.parseActionRule("./tizen_fail1_rule.xml"), ModesEx);
+}
+
+TEST(RuleManagerTest, InvalidValue)
 {
        RuleManagerTest testBroker;
-       EXPECT_THROW(testBroker.parseActionRule("./tizen_ex_rule_fail.xml"), ModesEx);
+       EXPECT_THROW(testBroker.parseActionRule("./tizen_fail2_rule.xml"), ModesEx);
 }