ADD_SUBDIRECTORY(supervisor)
ADD_SUBDIRECTORY(plugin)
ADD_SUBDIRECTORY(test)
+ADD_SUBDIRECTORY(unittest)
BuildRequires: pkgconfig(capi-base-common)
BuildRequires: pkgconfig(libxml-2.0)
BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(gmock)
%description
The modes(Mode Supervisor) manages configurations which is described at a mode.
xmllint --noout --schema tizen_mode_actions.xsd tizen_mode_actions.xml
xmllint --noout --schema tizen_mode.xsd tizen_*_mode.xml
popd
+pushd ./unittest
+./gtest-modes-modemgr
+./gtest-modes-plugin
+./gtest-modes-parser
+popd
%post -p /sbin/ldconfig
%license LICENSE.APLv2
%{_datadir}/%{name}/*.xml
%{_datadir}/%{name}/*.xsd
+%{_bindir}/gtest-modes-*
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common)
-
FILE(GLOB DAEMON_SRCS *.cpp ${CMAKE_SOURCE_DIR}/common/*.c)
SET(DAEMON_SRCS ${DAEMON_SRCS} ${CMAKE_SOURCE_DIR}/common/dbus.c)
#pragma once
#include <string>
-#include "dbus.h"
+#include "common/dbus.h"
#include "mdss.h"
MODES_NAMESPACE_BEGIN
void addModeName(ModeParser *parser, std::string &path);
ModeParser* getParser(const std::string &path);
PluginManager pluginManager;
+
+#ifdef MDS_TEST
+ friend class TestModeManager;
+#endif
};
MODES_NAMESPACE_END
PluginPair loadClass(std::string libraryName);
int unloadClass(PluginPair object);
+#ifdef MDS_TEST
+ friend class TestPluginManager;
+#endif
+
public:
PluginManager() {};
~PluginManager() {};
--- /dev/null
+LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE")
+
+SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/common/dbus.c
+ PROPERTIES GENERATED TRUE)
+
+pkg_check_modules(gtest_pkgs REQUIRED dlog glib-2.0 gio-2.0 gio-unix-2.0 libxml-2.0 gmock)
+
+INCLUDE_DIRECTORIES(${gtest_pkgs_INCLUDE_DIRS})
+LINK_DIRECTORIES(${gtest_pkgs_LIBRARY_DIRS})
+ADD_DEFINITIONS("-DMDS_TEST")
+
+SET(SUPERVISOR_DIR "${CMAKE_SOURCE_DIR}/supervisor/" )
+FILE(GLOB SRC "modes_test_main.cpp")
+FILE(GLOB GTEST_EXAMPLE
+ ${CMAKE_SOURCE_DIR}/example/tizen_A_mode.xml
+ ${CMAKE_SOURCE_DIR}/example/tizen_mode.xsd
+ )
+INSTALL(FILES ${GTEST_EXAMPLE} DESTINATION ${MODE_DESCRIPTION_DIR})
+#=======================================================================================#
+SET(GTEST_MODEMGR "gtest-modes-modemgr")
+FILE(GLOB GTEST_MODEMGR_SRCS
+ ${SUPERVISOR_DIR}/ModeManager.cpp
+ ${SUPERVISOR_DIR}/ModeXMLParser.cpp
+ ${SUPERVISOR_DIR}/Action.cpp
+ ${SUPERVISOR_DIR}/Mode.cpp
+ ${SUPERVISOR_DIR}/ModesEx.cpp
+ ${SUPERVISOR_DIR}/PluginManager.cpp
+ "modes_test_modemgr.cpp"
+ )
+ADD_EXECUTABLE(${GTEST_MODEMGR} ${SRC} ${GTEST_MODEMGR_SRCS})
+TARGET_LINK_LIBRARIES(${GTEST_MODEMGR} ${gtest_pkgs_LIBRARIES} dl)
+INSTALL(TARGETS ${GTEST_MODEMGR} DESTINATION ${BIN_INSTALL_DIR})
+#=======================================================================================#
+SET(GTEST_PLUGIN "gtest-modes-plugin")
+FILE(GLOB GTEST_PLUGIN_SRCS
+ ${SUPERVISOR_DIR}/PluginManager.cpp
+ "modes_test_plugin.cpp"
+ )
+ADD_EXECUTABLE(${GTEST_PLUGIN} ${SRC} ${GTEST_PLUGIN_SRCS})
+TARGET_LINK_LIBRARIES(${GTEST_PLUGIN} ${gtest_pkgs_LIBRARIES} dl)
+INSTALL(TARGETS ${GTEST_PLUGIN} DESTINATION ${BIN_INSTALL_DIR})
+#=======================================================================================#
+SET(GTEST_PARSER "gtest-modes-parser")
+FILE(GLOB GTEST_PARSER_SRCS
+ ${SUPERVISOR_DIR}/PluginManager.cpp
+ ${SUPERVISOR_DIR}/ModeXMLParser.cpp
+ ${SUPERVISOR_DIR}/ModesEx.cpp
+ ${SUPERVISOR_DIR}/Action.cpp
+ ${SUPERVISOR_DIR}/Mode.cpp
+ "modes_test_parser.cpp"
+ )
+ADD_EXECUTABLE(${GTEST_PARSER} ${SRC} ${GTEST_PARSER_SRCS})
+TARGET_LINK_LIBRARIES(${GTEST_PARSER} ${gtest_pkgs_LIBRARIES} dl)
+INSTALL(TARGETS ${GTEST_PARSER} DESTINATION ${BIN_INSTALL_DIR})
+#=======================================================================================#
+SET(GTEST_CLIENT "gtest-modes-client")
+SET(GTEST_CLIENT_SRCS
+ ${SUPERVISOR_DIR}/ModeManager.cpp
+ ${SUPERVISOR_DIR}/ModeXMLParser.cpp
+ ${SUPERVISOR_DIR}/Action.cpp
+ ${SUPERVISOR_DIR}/Mode.cpp
+ ${SUPERVISOR_DIR}/ModesEx.cpp
+ ${SUPERVISOR_DIR}/PluginManager.cpp
+ ${SUPERVISOR_DIR}/Supervisor.cpp
+ ${SUPERVISOR_DIR}/RequestHandler.cpp
+ ${SUPERVISOR_DIR}/ClientConnection.cpp
+ ${CMAKE_SOURCE_DIR}/client/mdsc.c
+ ${CMAKE_SOURCE_DIR}/common/dbus.c
+ "modes_test_client.cpp"
+ )
+ADD_EXECUTABLE(${GTEST_CLIENT} ${SRC} ${GTEST_CLIENT_SRCS})
+ADD_DEPENDENCIES(${GTEST_CLIENT} GENERATED_DBUS_CODE)
+TARGET_LINK_LIBRARIES(${GTEST_CLIENT} ${gtest_pkgs_LIBRARIES} dl)
+INSTALL(TARGETS ${GTEST_CLIENT} DESTINATION ${BIN_INSTALL_DIR})
+#=======================================================================================#
--- /dev/null
+#include <iostream>
+#include <glib.h>
+#include <gtest/gtest.h>
+#include "modes.h"
+#include "supervisor/Supervisor.h"
+
+MODES_NAMESPACE_USE;
+
+void *client_test(void *data)
+{
+ int ret = 0;
+ GMainLoop *main_loop = (GMainLoop *)data;
+ ret = modes_apply_mode("A");
+ EXPECT_EQ(0, ret);
+ g_main_loop_quit(main_loop);
+
+ return 0;
+}
+
+TEST(client, applyMode) {
+ Supervisor supervisor("/usr/share/modes");
+ supervisor.registerHandler();
+
+ GMainLoop *main_loop = g_main_loop_new(NULL, FALSE);
+ GThread *my_thread = g_thread_new(NULL, client_test, main_loop);
+ g_main_loop_run(main_loop);
+
+ g_thread_join(my_thread);
+ g_main_loop_unref(main_loop);
+}
--- /dev/null
+#include <gtest/gtest.h>
+
+int main(int argc, char **argv) {
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
--- /dev/null
+#include <iostream>
+#include <gtest/gtest.h>
+#include "supervisor/ModeManager.h"
+
+MODES_NAMESPACE_USE;
+using namespace std;
+
+MODES_NAMESPACE_BEGIN
+class TestModeManager {
+public:
+ string getDir(ModeManager& m);
+ map<string, string> getModeMap(ModeManager& m);
+};
+MODES_NAMESPACE_END
+
+string TestModeManager::getDir(ModeManager& m)
+{
+ return m.directoryOfMode;
+}
+
+map<string, string> TestModeManager::getModeMap(ModeManager& m)
+{
+ return m.modeMap;
+}
+
+TEST(modemanager, getdir) {
+ string dir = "../example";
+
+ ModeManager md_mgr(dir);
+ TestModeManager mdmgrT;
+
+ EXPECT_EQ(dir, mdmgrT.getDir(md_mgr));
+}
+
+TEST(modemanager, getmodemap) {
+ string dir = "../example";
+
+ ModeManager md_mgr(dir);
+ TestModeManager mdmgrT;
+
+ map<string, string> map = mdmgrT.getModeMap(md_mgr);
+ EXPECT_FALSE(map.empty());
+
+ if (!map.empty()) {
+ std::map<string, string>::iterator it;
+ printf("| %-15.15s | %s\n", "Mode Name", "ModeXML file Path");
+
+ for(it = map.begin(); it != map.end(); it++)
+ printf("| %-15.15s | %s\n", it->first.c_str(), it->second.c_str());
+ }
+}
--- /dev/null
+#include <iostream>
+#include <gtest/gtest.h>
+#include "supervisor/Mode.h"
+#include "supervisor/ModeXMLParser.h"
+
+MODES_NAMESPACE_USE;
+using namespace std;
+
+MODES_NAMESPACE_BEGIN
+class TestParser {
+ public:
+ void parserTest(const string &fileName);
+ list<Action> getActionList(Mode& m);
+ private:
+};
+MODES_NAMESPACE_END
+
+list<Action> TestParser::getActionList(Mode& m)
+{
+ return m.actionList;
+}
+
+TEST(XMLParser, getModeName) {
+ PluginManager pluginManager;
+ ModeXMLParser modeparser("../example/tizen_A_mode.xml", pluginManager);
+ string modename = modeparser.getModeName();
+
+ EXPECT_EQ("A", modeparser.getModeName());
+}
+
+TEST(XMLParser, getMode) {
+ PluginManager pluginManager;
+ ModeXMLParser modeparser("../example/tizen_A_mode.xml", pluginManager);
+ Mode mode = modeparser.getMode();
+
+ //EXPECT_TRUE(mode.empty());
+}
+
+TEST(Mode, getModeName) {
+ PluginManager pluginManager;
+ ModeXMLParser modeparser("../example/tizen_A_mode.xml", pluginManager);
+ Mode mode = modeparser.getMode();
+ EXPECT_EQ("A", mode.getName());
+}
+
+TEST(Mode, getTransparent) {
+ PluginManager pluginManager;
+ ModeXMLParser modeparser("../example/tizen_A_mode.xml", pluginManager);
+ Mode mode = modeparser.getMode();
+ EXPECT_EQ("No", mode.getTransparent());
+}
+
+TEST(Mode, printAction) {
+ PluginManager pluginManager;
+ ModeXMLParser modeparser("../example/tizen_A_mode.xml", pluginManager);
+ Mode mode = modeparser.getMode();
+ TestParser parserT;
+
+ list<Action> actList = parserT.getActionList(mode);
+ EXPECT_FALSE(actList.empty());
+
+ for (list<Action>::iterator it = actList.begin(); it != actList.end(); ++it) {
+ cout << "* Action : " << it->getName() << endl;
+ cout << "\t- Achieve : " << it->getAchieve() << endl;
+ cout << "\t- Changeable : " << it->getChangeable() << endl;
+ cout << "\t- Content : " << it->getValue() << endl;
+ }
+}
--- /dev/null
+#include <iostream>
+#include <gtest/gtest.h>
+#include "supervisor/PluginManager.h"
+
+MODES_NAMESPACE_USE;
+using namespace std;
+
+MODES_NAMESPACE_BEGIN
+class TestPluginManager {
+public:
+ PluginMap getPluginMap(PluginManager& p);
+};
+MODES_NAMESPACE_END
+
+
+PluginMap TestPluginManager::getPluginMap(PluginManager& p){
+ return p.pluginMap;
+}
+
+TEST(pluginmanager, readLibraryList) {
+ PluginManager pluginManager;
+
+ string path = "../plugin/";
+ pluginManager.setPluginDir(path);
+
+ list<string> list = pluginManager.readLibraryList();
+ EXPECT_FALSE(list.empty());
+
+ if (!list.empty()) {
+ for (auto it = list.begin(); it != list.end(); ++it)
+ printf("library : %s\n", it->c_str());
+ }
+}
+
+TEST(PluginManager, setPluginDir) {
+ PluginManager pluginManager;
+
+ string path = "../plugin/";
+ pluginManager.setPluginDir(path);
+
+ string getPath = pluginManager.getPluginDir();
+
+ EXPECT_EQ(path, getPath);
+}
+
+TEST(PluginManager, loadClassMap) {
+ PluginManager pluginManager;
+ std::string path = "../plugin";
+ pluginManager.setPluginDir(path);
+ pluginManager.readLibraryList();
+
+ int ret = pluginManager.loadClassMap();
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+}
+
+TEST(PluginManager, unloadClassMap) {
+ PluginManager pluginManager;
+ int ret = pluginManager.unloadClassMap();
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+
+ TestPluginManager pmgrT;
+ PluginMap pm = pmgrT.getPluginMap(pluginManager);
+ EXPECT_TRUE(pm.empty());
+}
+
+TEST(PluginManager, getClassList) {
+ PluginManager pluginManager;
+ std::string path = "../plugin";
+ pluginManager.setPluginDir(path);
+ pluginManager.readLibraryList();
+
+ pluginManager.loadClassMap();
+
+ list<string> list = pluginManager.getClassList();
+ EXPECT_FALSE(list.empty());
+
+ for (auto it = list.begin(); it != list.end(); ++it) {
+ printf("Class : %s\n", it->c_str());
+ }
+}
+
+TEST(PluginManager, getPlugin) {
+ PluginManager pluginManager;
+ pluginManager.loadClassMap();
+
+ list<string> list = pluginManager.getClassList();
+
+ for (auto it = list.begin(); it != list.end(); ++it) {
+ string key1 = "Happy";
+ string key2 = "1004";
+ string key3 = "true";
+ bool b = (key3 == "true");
+
+ /* Call plugin get */
+ string value = pluginManager.getPlugin(*it)->getString(key1);
+ EXPECT_EQ("Happy", value);
+
+ int valueInt = pluginManager.getPlugin(*it)->getInt(key2);
+ EXPECT_EQ(stoi(key2), valueInt);
+
+ bool valueBool = pluginManager.getPlugin(*it)->getBool(key3);
+ EXPECT_EQ(b, valueBool);
+ }
+}
+
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" xmlns:o="http://www.tizen.org" targetNamespace="http://www.tizen.org">
+ <xs:element name="tizen">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element maxOccurs="1" minOccurs="1" ref="o:mode"/>
+ </xs:sequence>
+ <xs:attribute name="version" use="required" type="o:versionT"/>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="mode">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element maxOccurs="unbounded" ref="o:action"/>
+ </xs:sequence>
+ <xs:attribute name="name" use="required" type="xs:string"/>
+ <xs:attribute name="Transparent" use="required" type="o:yesnoT"/>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="action">
+ <xs:complexType>
+ <xs:simpleContent>
+ <xs:extension base="xs:string">
+ <xs:attribute name="name" use="required" type="xs:string"/>
+ <xs:attribute name="Achieve" use="optional" type="xs:string"/>
+ <xs:attribute name="Changeable" use="required" type="xs:string"/>
+ </xs:extension>
+ </xs:simpleContent>
+ </xs:complexType>
+ </xs:element>
+ <xs:simpleType name="versionT">
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="5.5"/>
+ <xs:enumeration value="6.0"/>
+ </xs:restriction>
+ </xs:simpleType>
+ <xs:simpleType name="yesnoT">
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="Yes"/>
+ <xs:enumeration value="No"/>
+ </xs:restriction>
+ </xs:simpleType>
+</xs:schema>