SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE")
ADD_DEFINITIONS("-DMDS_TEST")
-pkg_check_modules(test_pkgs REQUIRED modes dlog capi-network-wifi-manager capi-network-bluetooth gmock capi-appfw-application)
+pkg_check_modules(test_pkgs REQUIRED modes dlog capi-network-wifi-manager capi-network-bluetooth gmock capi-appfw-application vconf)
INCLUDE_DIRECTORIES(${test_pkgs_INCLUDE_DIRS})
LINK_DIRECTORIES(${test_pkgs_LIBRARY_DIRS})
SET(WIFI_SRC_DIR "${CMAKE_SOURCE_DIR}/wifi" )
SET(WIFI_PLUGIN_TEST "modes-gtest-modemgr")
-SET(WIFI_SRCS ${WIFI_SRC_DIR}/WifiAction.cpp "mdsp_wifi_main.cpp")
+SET(WIFI_SRCS ${WIFI_SRC_DIR}/WifiAction.cpp "mdsp_test_wifi.cpp")
ADD_EXECUTABLE(${WIFI_PLUGIN_TEST} ${WIFI_SRCS})
-TARGET_LINK_LIBRARIES(${WIFI_PLUGIN_TEST} ${test_pkgs_LIBRARIES} dl)
+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_bt_main.cpp")
+SET(BT_SRCS ${BT_SRC_DIR}/BtAction.cpp "mdsp_test_bt.cpp")
ADD_EXECUTABLE(${BT_PLUGIN_TEST} ${BT_SRCS})
-TARGET_LINK_LIBRARIES(${BT_PLUGIN_TEST} ${test_pkgs_LIBRARIES} dl)
+TARGET_LINK_LIBRARIES(${BT_PLUGIN_TEST} ${test_pkgs_LIBRARIES})
INSTALL(TARGETS ${BT_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR})
#===================================================================#
SET(APPFW_SRC_DIR "${CMAKE_SOURCE_DIR}/appfw" )
SET(APPFW_PLUGIN_TEST "modes-gtest-appfw")
FILE(GLOB APPFW_SRCS ${APPFW_SRC_DIR}/*.cpp)
-SET(APPFW_SRCS ${APPFW_SRCS} "mdsp_appfw_main.cpp")
+SET(APPFW_SRCS ${APPFW_SRCS} "mdsp_test_appfw.cpp")
ADD_EXECUTABLE(${APPFW_PLUGIN_TEST} ${APPFW_SRCS})
-TARGET_LINK_LIBRARIES(${APPFW_PLUGIN_TEST} ${test_pkgs_LIBRARIES} dl)
+TARGET_LINK_LIBRARIES(${APPFW_PLUGIN_TEST} ${test_pkgs_LIBRARIES})
INSTALL(TARGETS ${APPFW_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR})
+#===================================================================#
+SET(VCONF_SRC_DIR "${CMAKE_SOURCE_DIR}/vconf" )
+SET(VCONF_PLUGIN_TEST "modes-gtest-vconf")
+FILE(GLOB VCONF_SRCS ${VCONF_SRC_DIR}/*.cpp)
+SET(VCONF_SRCS ${VCONF_SRCS} "mdsp_test_vconf.cpp")
+
+ADD_EXECUTABLE(${VCONF_PLUGIN_TEST} ${VCONF_SRCS})
+TARGET_LINK_LIBRARIES(${VCONF_PLUGIN_TEST} ${test_pkgs_LIBRARIES})
+INSTALL(TARGETS ${VCONF_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR})
--- /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 <gtest/gtest.h>
+#include <Plugin.h>
+#include <modes_errors.h>
+#include "plugin-def.h"
+
+MODES_NAMESPACE_USE;
+
+extern "C" Plugin *objectCreate(void);
+extern "C" void objectDelete(Plugin *plugin);
+
+TEST(PluginTest, setPluginVconfInt)
+{
+ int ret;
+ int oldval;
+ Plugin *plugin = objectCreate();
+
+ ret = plugin->set("db.setting.psmode", 3, nullptr);
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ ret = plugin->set("db.setting.psmode", 1, &oldval);
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ EXPECT_EQ(oldval, 3);
+
+ objectDelete(plugin);
+}
+
+TEST(PluginTest, setPluginVconfDouble)
+{
+ int ret;
+ double oldval;
+ Plugin *plugin = objectCreate();
+
+ ret = plugin->set("db.system.timechange_external", 1.0, nullptr);
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ ret = plugin->set("db.system.timechange_external", 0.0, &oldval);
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ EXPECT_EQ(oldval, 1.0);
+
+ objectDelete(plugin);
+}
+
+TEST(PluginTest, setPluginVconfBool)
+{
+ int ret;
+ bool oldval;
+ Plugin *plugin = objectCreate();
+
+ ret = plugin->set("db.setting.sound.button_sounds", false, nullptr);
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ ret = plugin->set("db.setting.sound.button_sounds", true, &oldval);
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ EXPECT_EQ(oldval, false);
+
+ objectDelete(plugin);
+}
+
+TEST(PluginTest, setPluginVconfStr)
+{
+ int ret;
+ std::string oldval;
+ Plugin *plugin = objectCreate();
+
+ std::string testVal = "org.tizen.menu-screen.test";
+ ret = plugin->set("db.setting.menuscreen.package_name", testVal, nullptr);
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ ret = plugin->set("db.setting.menuscreen.package_name", "org.tizen.menu-screen", &oldval);
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ EXPECT_EQ(oldval.compare(testVal), 0);
+
+ objectDelete(plugin);
+}
+
+int main(int argc, char **argv) {
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
int VconfPlugin::set(const std::string &key, int val, int *oldVal)
{
+ int ret;
DBG("set<int>(%s, %d)", key.c_str(), val);
std::string newKey(key);
std::replace(newKey.begin(), newKey.end(), '.', '/');
- int ret = vconf_set_int(newKey.c_str(), val);
+ if (oldVal) {
+ ret = vconf_get_int(newKey.c_str(), oldVal);
+ if (0 != ret) {
+ ERR("vconf_get_int(%s) Fail(%d)", newKey.c_str(), ret);
+ return MODES_ERROR_SYSTEM;
+ }
+ }
+
+ ret = vconf_set_int(newKey.c_str(), val);
if (0 != ret) {
ERR("vconf_set_int(%s, %d) Fail(%d)", newKey.c_str(), val, ret);
return MODES_ERROR_SYSTEM;
int VconfPlugin::set(const std::string &key, double val, double *oldVal)
{
+ int ret;
DBG("set<double>(%s, %lf)", key.c_str(), val);
std::string newKey(key);
std::replace(newKey.begin(), newKey.end(), '.', '/');
- int ret = vconf_set_dbl(newKey.c_str(), val);
+ if (oldVal) {
+ ret = vconf_get_dbl(newKey.c_str(), oldVal);
+ if (0 != ret) {
+ ERR("vconf_get_dbl(%s) Fail(%d)", newKey.c_str(), ret);
+ return MODES_ERROR_SYSTEM;
+ }
+ }
+
+ ret = vconf_set_dbl(newKey.c_str(), val);
if (0 != ret) {
ERR("vconf_set_int(%s, %lf) Fail(%d)", newKey.c_str(), val, ret);
return MODES_ERROR_SYSTEM;
}
return MODES_ERROR_NONE;
}
+
int VconfPlugin::set(const std::string &key, bool val, bool *oldVal)
{
+ int ret;
DBG("set<bool>(%s, %d)", key.c_str(), val);
std::string newKey(key);
std::replace(newKey.begin(), newKey.end(), '.', '/');
- int ret = vconf_set_bool(newKey.c_str(), val);
+ if (oldVal) {
+ int prev;
+ ret = vconf_get_bool(newKey.c_str(), &prev);
+ if (0 != ret) {
+ ERR("vconf_get_bool(%s) Fail(%d)", newKey.c_str(), ret);
+ return MODES_ERROR_SYSTEM;
+ }
+ *oldVal = prev;
+ }
+
+ ret = vconf_set_bool(newKey.c_str(), val);
if (0 != ret) {
ERR("vconf_set_bool(%s, %d) Fail(%d)", newKey.c_str(), val, ret);
return MODES_ERROR_SYSTEM;
std::string newKey(key);
std::replace(newKey.begin(), newKey.end(), '.', '/');
+ if (oldVal) {
+ char *prevStr = vconf_get_str(newKey.c_str());
+ if (NULL == prevStr) {
+ ERR("vconf_get_str(%s) Fail()", newKey.c_str());
+ return MODES_ERROR_SYSTEM;
+ }
+ *oldVal = std::string(prevStr);
+ free(prevStr);
+ }
+
+
int ret = vconf_set_str(newKey.c_str(), val.c_str());
if (0 != ret) {
ERR("vconf_set_str(%s, %s) Fail(%d)", newKey.c_str(), val.c_str(), ret);