code cleanup and revise test program
authorYoungjae Shin <yj99.shin@samsung.com>
Thu, 24 Oct 2019 23:52:23 +0000 (08:52 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Wed, 18 Mar 2020 08:53:50 +0000 (17:53 +0900)
packaging/modes.spec
supervisor/TAction.h
unittest/CMakeLists.txt
unittest/modes_apply_mode.c [deleted file]
unittest/modes_mode_test.c [new file with mode: 0644]
unittest/modes_test_client.cpp

index e2a8cfc0c999ccd73a108d899c2f78455fa4ca89..f413f621821055a8883537cb631978960c0dd195 100644 (file)
@@ -162,7 +162,7 @@ systemctl restart %{name}.service
 %manifest %{name}.manifest
 %{modes_plugin_dir}/*test.so
 %{modes_test_dir}/modes-gtest-*
-%{modes_test_dir}/modes-apply-mode-test
+%{modes_test_dir}/modes-mode-test
 %{modes_data_dir}/mode/*
 %{modes_data_dir}/rule/*
 %{modes_test_dir}/*.xml
index 0d45885bbaf10b68fc89a58f15fe6615a2a02697..a2cda93da2a57ee702168f56471735f6b58ac736 100644 (file)
@@ -45,12 +45,10 @@ public:
 
        std::string getStringOfValue()
        {
-               std::string val;
                std::ostringstream ostr;
 
                ostr << value;
-               val = ostr.str();
-               return val;
+               return ostr.str();
        }
 
        int setValue(const std::string &val) override
index 93614ad43795438b7d00a812deb94e0d06eb00dc..994eb02672a4cb7f23869e86aece1d5d57d0486d 100644 (file)
@@ -25,8 +25,8 @@ ADD_EXECUTABLE(${GTEST_CLIENT} ${SRC} ${GTEST_CLIENT_SRCS})
 TARGET_LINK_LIBRARIES(${GTEST_CLIENT} ${CLIENT} ${gtest_pkgs_LIBRARIES})
 INSTALL(TARGETS ${GTEST_CLIENT} DESTINATION ${TEST_INSTALL_DIR})
 #=======================================================================================#
-SET(TEST_APPLY_MODE "modes-apply-mode-test")
-SET(TEST_APPLY_MODE_SRC modes_apply_mode.c)
+SET(TEST_APPLY_MODE "modes-mode-test")
+SET(TEST_APPLY_MODE_SRC modes_mode_test.c)
 ADD_EXECUTABLE(${TEST_APPLY_MODE} ${TEST_APPLY_MODE_SRC})
 TARGET_LINK_LIBRARIES(${TEST_APPLY_MODE} ${CLIENT})
 INSTALL(TARGETS ${TEST_APPLY_MODE} DESTINATION ${TEST_INSTALL_DIR})
diff --git a/unittest/modes_apply_mode.c b/unittest/modes_apply_mode.c
deleted file mode 100644 (file)
index 06ccefc..0000000
+++ /dev/null
@@ -1,50 +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 <glib.h>
-#include <modes.h>
-
-#ifndef MDS_STDOUT
-#define MDS_STDOUT
-#endif
-#include "common/log.h"
-
-static GMainLoop *t_apply_loop;
-
-static gboolean request_idler(gpointer data)
-{
-       int ret = modes_apply_mode(data);
-       if (MODES_ERROR_NONE != ret)
-               ERR("modes_apply_mode() Fail(%d)", ret);
-
-       g_main_loop_quit(t_apply_loop);
-       return G_SOURCE_REMOVE;
-}
-
-int main(int argc, char **argv)
-{
-       if (2 != argc) {
-               ERR("Usage) %s ModeName", argv[0]);
-               return -1;
-       }
-
-       t_apply_loop = g_main_loop_new(NULL, FALSE);
-       g_idle_add(request_idler, argv[1]);
-
-       g_main_loop_run(t_apply_loop);
-
-       g_main_loop_unref(t_apply_loop);
-       return 0;
-}
diff --git a/unittest/modes_mode_test.c b/unittest/modes_mode_test.c
new file mode 100644 (file)
index 0000000..5c24119
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * 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 <glib.h>
+#include <modes.h>
+
+#ifndef MDS_STDOUT
+#define MDS_STDOUT
+#endif
+#include "common/log.h"
+
+static GMainLoop *_modes_loop;
+
+#define PRINT(fmt, arg...) printf("\033[31m %d:" fmt "\n \033[0m", __LINE__, ##arg)
+
+static gboolean apply_idler(gpointer data)
+{
+       int ret = modes_apply_mode(data);
+       if (MODES_ERROR_NONE != ret)
+               PRINT("modes_apply_mode() Fail(%d)", ret);
+
+       g_main_loop_quit(_modes_loop);
+       return G_SOURCE_REMOVE;
+}
+
+static gboolean undo_idler(gpointer data)
+{
+       int ret = modes_undo_mode(data);
+       if (MODES_ERROR_NONE != ret)
+               PRINT("modes_undo_mode() Fail(%d)", ret);
+
+       g_main_loop_quit(_modes_loop);
+       return G_SOURCE_REMOVE;
+}
+
+static void print_usage(const char *exec_name)
+{
+       printf("Usage)\n");
+       printf("\t%s apply ModeName\n", exec_name);
+       printf("\t%s undo ModeName\n", exec_name);
+}
+
+int main(int argc, char **argv)
+{
+       if (3 != argc) {
+               print_usage(argv[0]);
+               return -1;
+       }
+
+       _modes_loop = g_main_loop_new(NULL, FALSE);
+       if (0 == strcasecmp(argv[1], "apply")) {
+               g_idle_add(apply_idler, argv[1]);
+       } else if (0 == strcasecmp(argv[1], "undo")) {
+               g_idle_add(undo_idler, argv[1]);
+       } else {
+               PRINT("Invalid option(%s)", argv[1]);
+               print_usage(argv[0]);
+       }
+
+       g_main_loop_run(_modes_loop);
+
+       g_main_loop_unref(_modes_loop);
+       return 0;
+}
index a8308a3ddca5112adb1c96f39d41f1ba77a2b8fb..823178591d4caf3685c34f258e6e53978299ac36 100644 (file)
@@ -78,6 +78,7 @@ GMainLoop *ClientTest::loop = NULL;
 
 TEST_F(ClientTest, applyModeP)
 {
+       modes_undo_mode("ex1");
        g_idle_add(applyModeIdler, (gpointer)"ex1");
        g_main_loop_run(loop);
        EXPECT_EQ(MODES_ERROR_NONE, result);