<?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>
<?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>
--- /dev/null
+<?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>
--- /dev/null
+<?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>
<?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 & 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>
+++ /dev/null
-<?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>
--- /dev/null
+<?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>
--- /dev/null
+<?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>
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;
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:
std::list<std::shared_ptr<Action>> actionList;
std::list<std::shared_ptr<Action>> undoList;
#ifdef MDS_TEST
- friend class TestParser;
+ friend class ParserTest;
#endif
};
mode.addAction(action);
}
-Action *ModeXMLParser::parseActionInfo(xmlNodePtr node)
+Action* ModeXMLParser::parseActionInfo(xmlNodePtr node)
{
char *ruleProp = (char*)xmlGetProp(node, ModeTag::RULE);
if (ruleProp == NULL) {
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;
}
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);
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])) {
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());
#ifdef MDS_TEST
friend class RuleManagerTest;
+ friend class ParserTest;
#endif
};
#include <sstream>
#include "mdss.h"
#include "Action.h"
+#include "ValueChecker.h"
MODES_NAMESPACE_BEGIN
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
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;
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;
--- /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 "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;
+}
--- /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.
+ */
+#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
${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})
${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})
${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})
${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})
${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})
#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;
}
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());
//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);
+}
rMgr.setOptions(config.actionRuleDir, config.actionRuleXsdFile);
}
-
TEST(RuleManagerTest, makeRuleMapP)
{
RuleManagerTest testBroker;
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);
}