From: JinWang An Date: Wed, 7 Aug 2019 06:27:42 +0000 (+0900) Subject: Update undo vconf X-Git-Tag: submit/tizen/20200406.072014~51 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=289db67ca476f191cd6873a779b1474c4e216234;p=platform%2Fcore%2Fsystem%2Fmodes-plugins.git Update undo vconf --- diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index 425c352..dd008b7 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -2,31 +2,40 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE") 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}) diff --git a/unittests/mdsp_appfw_main.cpp b/unittests/mdsp_appfw_main.cpp deleted file mode 100644 index a1f97b0..0000000 --- a/unittests/mdsp_appfw_main.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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 -#include -#include -#include -#include -#include -#include "plugin-log.h" -#include "plugin-def.h" - -MODES_NAMESPACE_USE; - -extern "C" API Plugin *objectCreate(void); -extern "C" API void objectDelete(Plugin *plugin); - -TEST(PluginTest, setPluginAppfw) -{ - int ret; - Plugin *plugin = objectCreate(); - - ret = plugin->set("launch", std::string("org.tizen.w-stopwatch"), nullptr); - EXPECT_EQ(ret, MODES_ERROR_NONE); - - objectDelete(plugin); -} - -int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/unittests/mdsp_bt_main.cpp b/unittests/mdsp_bt_main.cpp deleted file mode 100644 index e083c6b..0000000 --- a/unittests/mdsp_bt_main.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 - -int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/unittests/mdsp_test_appfw.cpp b/unittests/mdsp_test_appfw.cpp new file mode 100644 index 0000000..a1f97b0 --- /dev/null +++ b/unittests/mdsp_test_appfw.cpp @@ -0,0 +1,44 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include "plugin-log.h" +#include "plugin-def.h" + +MODES_NAMESPACE_USE; + +extern "C" API Plugin *objectCreate(void); +extern "C" API void objectDelete(Plugin *plugin); + +TEST(PluginTest, setPluginAppfw) +{ + int ret; + Plugin *plugin = objectCreate(); + + ret = plugin->set("launch", std::string("org.tizen.w-stopwatch"), nullptr); + EXPECT_EQ(ret, MODES_ERROR_NONE); + + objectDelete(plugin); +} + +int main(int argc, char **argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/unittests/mdsp_test_bt.cpp b/unittests/mdsp_test_bt.cpp new file mode 100644 index 0000000..e083c6b --- /dev/null +++ b/unittests/mdsp_test_bt.cpp @@ -0,0 +1,21 @@ +/* + * 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 + +int main(int argc, char **argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/unittests/mdsp_test_vconf.cpp b/unittests/mdsp_test_vconf.cpp new file mode 100644 index 0000000..398852d --- /dev/null +++ b/unittests/mdsp_test_vconf.cpp @@ -0,0 +1,90 @@ +/* + * 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 +#include +#include +#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(); +} diff --git a/unittests/mdsp_test_wifi.cpp b/unittests/mdsp_test_wifi.cpp new file mode 100644 index 0000000..e083c6b --- /dev/null +++ b/unittests/mdsp_test_wifi.cpp @@ -0,0 +1,21 @@ +/* + * 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 + +int main(int argc, char **argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/unittests/mdsp_wifi_main.cpp b/unittests/mdsp_wifi_main.cpp deleted file mode 100644 index e083c6b..0000000 --- a/unittests/mdsp_wifi_main.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 - -int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/vconf/VconfPlugin.cpp b/vconf/VconfPlugin.cpp index 66559b2..d362ce5 100644 --- a/vconf/VconfPlugin.cpp +++ b/vconf/VconfPlugin.cpp @@ -58,12 +58,21 @@ VconfPlugin::VconfPlugin() int VconfPlugin::set(const std::string &key, int val, int *oldVal) { + int ret; DBG("set(%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; @@ -73,26 +82,47 @@ int VconfPlugin::set(const std::string &key, int val, int *oldVal) int VconfPlugin::set(const std::string &key, double val, double *oldVal) { + int ret; DBG("set(%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(%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; @@ -107,6 +137,17 @@ int VconfPlugin::set(const std::string &key, const std::string &val, std::string 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);