Cleanup the testsuite 23/137823/4
authorMu-Woong Lee <muwoong.lee@samsung.com>
Mon, 10 Jul 2017 03:15:44 +0000 (12:15 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Mon, 10 Jul 2017 04:26:22 +0000 (13:26 +0900)
- Remove context-provider dependency
- Rename functions & variables to camelCase (partial)

Change-Id: Ib7542709e4f8b57748fca55113f9a0129039ffbc
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
testsuite/CMakeLists.txt
testsuite/src/app-history/history.cpp [moved from testsuite/src/history/history.cpp with 65% similarity]
testsuite/src/app-history/history.h [moved from testsuite/src/history/history.h with 95% similarity]
testsuite/src/main.cpp
testsuite/src/shared.cpp
testsuite/src/shared.h
testsuite/src/trigger/condition.cpp
testsuite/src/trigger/event.cpp

index 2469f29..e834f40 100644 (file)
@@ -3,7 +3,7 @@ PROJECT(capi-context-test)
 SET(TEST_EXEC context-test)
 
 # Source List
-FILE(GLOB_RECURSE TEST_SRCS src/*.cpp)
+FILE(GLOB TEST_SRCS src/*.cpp src/app-history/*.cpp)
 INCLUDE_DIRECTORIES(
        ${CMAKE_SOURCE_DIR}/src
 )
similarity index 65%
rename from testsuite/src/history/history.cpp
rename to testsuite/src/app-history/history.cpp
index 5738baa..5d0168b 100644 (file)
  */
 
 #include <context_history.h>
-#include <ProviderTypes.h>
-
 #include "../shared.h"
 #include "history.h"
 
-using namespace ctx::test;
+#define KEY_RESULT_SIZE                "ResultSize"
+#define KEY_TIME_SPAN          "TimeSpan"
+#define KEY_START_TIME         "StartTime"
+#define KEY_END_TIME           "EndTime"
+#define KEY_DAY_OF_WEEK                "DayOfWeek"
+#define KEY_APP_ID                     "AppId"
+#define KEY_AUDIO_JACK         "AudioJack"
+#define KEY_BSSID                      "BSSID"
+#define KEY_COMMUNICATION_TYPE "CommunicationType"
+
+using namespace test;
 
 static context_history_h history_h = NULL;
 static context_history_list_h list_h = NULL;
@@ -39,15 +47,15 @@ static void __release_resource()
        filter_h = NULL;
 }
 
-int test_history(int *argc, char ***argv)
+int testAppHistory(int *argc, char ***argv)
 {
-       err = context_history_create(&history_h);
-       if (err != ERR_NONE) {
+       lastError = context_history_create(&history_h);
+       if (lastError != E_NONE) {
                g_print(RED("Memory allocation failed\n"));
                return 0;
        }
 
-       ctx::test::newline_after_tcname = true;
+       flag::newlineAfterTestCaseName = true;
 
        while (true) {
                g_print("\nSelect the target item...\n");
@@ -58,44 +66,44 @@ int test_history(int *argc, char ***argv)
                g_print("   9. Common Setting for Video   10. Frequently Communicated Address\n");
                g_print("  11. Battery Usage              12. Recent Battery Usage\n");
 
-               while (!get_input_int("(to exit, ctrl-c)? ")) {;}
+               while (!getInputInt("(to exit, ctrl-c)? ")) {;}
 
-               switch (int_val) {
+               switch (value::int32) {
                case 1:
-                       run_testcase("/history/recently_used_app", _history_app_recently);
+                       runTestCase("/history/recently_used_app", _history_app_recently);
                        break;
                case 2:
-                       run_testcase("/history/frequently_used_app", _history_app_frequently);
+                       runTestCase("/history/frequently_used_app", _history_app_frequently);
                        break;
                case 3:
-                       run_testcase("/history/rarely_used_app", _history_app_rarely);
+                       runTestCase("/history/rarely_used_app", _history_app_rarely);
                        break;
                case 4:
-                       run_testcase("/history/peak_time_for_app", _history_app_peak_time);
+                       runTestCase("/history/peak_time_for_app", _history_app_peak_time);
                        break;
                case 5:
-                       run_testcase("/history/peak_time_for_music", _history_music_peak_time);
+                       runTestCase("/history/peak_time_for_music", _history_music_peak_time);
                        break;
                case 6:
-                       run_testcase("/history/peak_time_for_video", _history_video_peak_time);
+                       runTestCase("/history/peak_time_for_video", _history_video_peak_time);
                        break;
                case 7:
-                       run_testcase("/history/common_setting_for_app", _history_app_setting);
+                       runTestCase("/history/common_setting_for_app", _history_app_setting);
                        break;
                case 8:
-                       run_testcase("/history/common_setting_for_music", _history_music_setting);
+                       runTestCase("/history/common_setting_for_music", _history_music_setting);
                        break;
                case 9:
-                       run_testcase("/history/common_setting_for_video", _history_video_setting);
+                       runTestCase("/history/common_setting_for_video", _history_video_setting);
                        break;
                case 10:
-                       run_testcase("/history/frequently_communicated_address", _history_comm_frequently);
+                       runTestCase("/history/frequently_communicated_address", _history_comm_frequently);
                        break;
                case 11:
-                       run_testcase("/history/battery_usage", _history_battery);
+                       runTestCase("/history/battery_usage", _history_battery);
                        break;
                case 12:
-                       run_testcase("/history/recent_battery_usage", _history_battery_recent);
+                       runTestCase("/history/recent_battery_usage", _history_battery_recent);
                        break;
                default:
                        g_print("Invalid number\n");
@@ -117,8 +125,8 @@ static void __filter_set_int(context_history_filter_e type, const char *key)
        std::string msg = " ";
        msg = msg + key + "? ";
 
-       if (get_input_int(msg.c_str()))
-               context_history_filter_set_int(filter_h, type, int_val);
+       if (getInputInt(msg.c_str()))
+               context_history_filter_set_int(filter_h, type, value::int32);
 }
 
 static void __filter_set_str(context_history_filter_e type, const char *key)
@@ -129,65 +137,65 @@ static void __filter_set_str(context_history_filter_e type, const char *key)
        std::string msg = " ";
        msg = msg + key + "? ";
 
-       if (get_input_str(msg.c_str()))
-               context_history_filter_set_string(filter_h, type, str_val.c_str());
+       if (getInputStr(msg.c_str()))
+               context_history_filter_set_string(filter_h, type, value::str.c_str());
 }
 
 static bool __get_list(context_history_data_e type)
 {
-       err = context_history_get_list(history_h, type, filter_h, &list_h);
+       lastError = context_history_get_list(history_h, type, filter_h, &list_h);
 
-       if (err == ERR_NOT_SUPPORTED) {
+       if (lastError == E_SUPPORT) {
                g_print(YELLOW("Not Supported") "\n");
                return false;
        }
 
-       if (err == ERR_NO_DATA) {
+       if (lastError == E_NO_DATA) {
                g_print(YELLOW("No Data") "\n");
                return false;
        }
 
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
        return true;
 }
 
 static bool __iterate_list(const char *int_attr[], const char *double_attr[], const char *str_attr[])
 {
        int cnt = 0;
-       err = context_history_list_get_count(list_h, &cnt);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = context_history_list_get_count(list_h, &cnt);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        for (int i = 0; i < cnt; ++i) {
-               err = context_history_list_get_current(list_h, &record_h);
-               ASSERT_CMPINT(err, ==, ERR_NONE);
+               lastError = context_history_list_get_current(list_h, &record_h);
+               ASSERT_CMPINT(lastError, ==, E_NONE);
                g_print("[%d] ", i);
 
                /* Integer attributes */
                for (int j = 0; int_attr[j] != NULL; ++j) {
-                       err = context_history_record_get_int(record_h, int_attr[j], &int_val);
-                       ASSERT_CMPINT(err, ==, ERR_NONE);
-                       g_print("%s(%d) ", int_attr[j], int_val);
+                       lastError = context_history_record_get_int(record_h, int_attr[j], &value::int32);
+                       ASSERT_CMPINT(lastError, ==, E_NONE);
+                       g_print("%s(%d) ", int_attr[j], value::int32);
                }
 
                /* Double attributes */
                for (int j = 0; double_attr[j] != NULL; ++j) {
-                       err = context_history_record_get_double(record_h, double_attr[j], &double_val);
-                       ASSERT_CMPINT(err, ==, ERR_NONE);
-                       g_print("%s(%f) ", double_attr[j], double_val);
+                       lastError = context_history_record_get_double(record_h, double_attr[j], &value::dbl);
+                       ASSERT_CMPINT(lastError, ==, E_NONE);
+                       g_print("%s(%f) ", double_attr[j], value::dbl);
                }
 
                /* String attributes */
                for (int j = 0; str_attr[j] != NULL; ++j) {
                        char *tmp = NULL;
-                       err = context_history_record_get_string(record_h, str_attr[j], &tmp);
-                       ASSERT_CMPINT(err, ==, ERR_NONE);
+                       lastError = context_history_record_get_string(record_h, str_attr[j], &tmp);
+                       ASSERT_CMPINT(lastError, ==, E_NONE);
                        g_print("%s(%s) ", str_attr[j], tmp);
                        g_free(tmp);
                }
 
                if (i < cnt - 1) {
-                       err = context_history_list_move_next(list_h);
-                       ASSERT_CMPINT(err, ==, ERR_NONE);
+                       lastError = context_history_list_move_next(list_h);
+                       ASSERT_CMPINT(lastError, ==, E_NONE);
                }
 
                context_history_record_destroy(record_h);
@@ -211,11 +219,11 @@ bool _history_app_recently()
        __filter_set_int(CONTEXT_HISTORY_FILTER_AUDIO_JACK, KEY_AUDIO_JACK);
        __filter_set_str(CONTEXT_HISTORY_FILTER_WIFI_BSSID, KEY_BSSID);
 
-       bool_val = __get_list(CONTEXT_HISTORY_RECENTLY_USED_APP);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __get_list(CONTEXT_HISTORY_RECENTLY_USED_APP);
+       IF_FAIL_RETURN(value::boolean, false);
 
-       bool_val = __iterate_list(int_attr, double_attr, str_attr);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __iterate_list(int_attr, double_attr, str_attr);
+       IF_FAIL_RETURN(value::boolean, false);
 
        return true;
 }
@@ -233,11 +241,11 @@ bool _history_app_frequently()
        __filter_set_int(CONTEXT_HISTORY_FILTER_AUDIO_JACK, KEY_AUDIO_JACK);
        __filter_set_str(CONTEXT_HISTORY_FILTER_WIFI_BSSID, KEY_BSSID);
 
-       bool_val = __get_list(CONTEXT_HISTORY_FREQUENTLY_USED_APP);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __get_list(CONTEXT_HISTORY_FREQUENTLY_USED_APP);
+       IF_FAIL_RETURN(value::boolean, false);
 
-       bool_val = __iterate_list(int_attr, double_attr, str_attr);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __iterate_list(int_attr, double_attr, str_attr);
+       IF_FAIL_RETURN(value::boolean, false);
 
        return true;
 }
@@ -253,11 +261,11 @@ bool _history_app_rarely()
        __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, KEY_START_TIME);
        __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, KEY_END_TIME);
 
-       bool_val = __get_list(CONTEXT_HISTORY_RARELY_USED_APP);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __get_list(CONTEXT_HISTORY_RARELY_USED_APP);
+       IF_FAIL_RETURN(value::boolean, false);
 
-       bool_val = __iterate_list(int_attr, double_attr, str_attr);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __iterate_list(int_attr, double_attr, str_attr);
+       IF_FAIL_RETURN(value::boolean, false);
 
        return true;
 }
@@ -275,11 +283,11 @@ bool _history_app_peak_time()
        __filter_set_int(CONTEXT_HISTORY_FILTER_DAY_OF_WEEK, KEY_DAY_OF_WEEK);
        __filter_set_str(CONTEXT_HISTORY_FILTER_APP_ID, KEY_APP_ID);
 
-       bool_val = __get_list(CONTEXT_HISTORY_PEAK_TIME_FOR_APP);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __get_list(CONTEXT_HISTORY_PEAK_TIME_FOR_APP);
+       IF_FAIL_RETURN(value::boolean, false);
 
-       bool_val = __iterate_list(int_attr, double_attr, str_attr);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __iterate_list(int_attr, double_attr, str_attr);
+       IF_FAIL_RETURN(value::boolean, false);
 
        return true;
 }
@@ -295,11 +303,11 @@ bool _history_app_setting()
        __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, KEY_END_TIME);
        __filter_set_str(CONTEXT_HISTORY_FILTER_APP_ID, KEY_APP_ID);
 
-       bool_val = __get_list(CONTEXT_HISTORY_COMMON_SETTING_FOR_APP);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __get_list(CONTEXT_HISTORY_COMMON_SETTING_FOR_APP);
+       IF_FAIL_RETURN(value::boolean, false);
 
-       bool_val = __iterate_list(int_attr, double_attr, str_attr);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __iterate_list(int_attr, double_attr, str_attr);
+       IF_FAIL_RETURN(value::boolean, false);
 
        return true;
 }
@@ -316,11 +324,11 @@ bool _history_music_peak_time()
        __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, KEY_END_TIME);
        __filter_set_int(CONTEXT_HISTORY_FILTER_DAY_OF_WEEK, KEY_DAY_OF_WEEK);
 
-       bool_val = __get_list(CONTEXT_HISTORY_PEAK_TIME_FOR_MUSIC);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __get_list(CONTEXT_HISTORY_PEAK_TIME_FOR_MUSIC);
+       IF_FAIL_RETURN(value::boolean, false);
 
-       bool_val = __iterate_list(int_attr, double_attr, str_attr);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __iterate_list(int_attr, double_attr, str_attr);
+       IF_FAIL_RETURN(value::boolean, false);
 
        return true;
 }
@@ -335,11 +343,11 @@ bool _history_music_setting()
        __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, KEY_START_TIME);
        __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, KEY_END_TIME);
 
-       bool_val = __get_list(CONTEXT_HISTORY_COMMON_SETTING_FOR_MUSIC);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __get_list(CONTEXT_HISTORY_COMMON_SETTING_FOR_MUSIC);
+       IF_FAIL_RETURN(value::boolean, false);
 
-       bool_val = __iterate_list(int_attr, double_attr, str_attr);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __iterate_list(int_attr, double_attr, str_attr);
+       IF_FAIL_RETURN(value::boolean, false);
 
        return true;
 }
@@ -356,11 +364,11 @@ bool _history_video_peak_time()
        __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, KEY_END_TIME);
        __filter_set_int(CONTEXT_HISTORY_FILTER_DAY_OF_WEEK, KEY_DAY_OF_WEEK);
 
-       bool_val = __get_list(CONTEXT_HISTORY_PEAK_TIME_FOR_VIDEO);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __get_list(CONTEXT_HISTORY_PEAK_TIME_FOR_VIDEO);
+       IF_FAIL_RETURN(value::boolean, false);
 
-       bool_val = __iterate_list(int_attr, double_attr, str_attr);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __iterate_list(int_attr, double_attr, str_attr);
+       IF_FAIL_RETURN(value::boolean, false);
 
        return true;
 }
@@ -375,11 +383,11 @@ bool _history_video_setting()
        __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, KEY_START_TIME);
        __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, KEY_END_TIME);
 
-       bool_val = __get_list(CONTEXT_HISTORY_COMMON_SETTING_FOR_VIDEO);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __get_list(CONTEXT_HISTORY_COMMON_SETTING_FOR_VIDEO);
+       IF_FAIL_RETURN(value::boolean, false);
 
-       bool_val = __iterate_list(int_attr, double_attr, str_attr);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __iterate_list(int_attr, double_attr, str_attr);
+       IF_FAIL_RETURN(value::boolean, false);
 
        return true;
 }
@@ -396,11 +404,11 @@ bool _history_comm_frequently()
        __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, KEY_END_TIME);
        __filter_set_int(CONTEXT_HISTORY_FILTER_COMMUNICATION_TYPE, KEY_COMMUNICATION_TYPE);
 
-       bool_val = __get_list(CONTEXT_HISTORY_FREQUENTLY_COMMUNICATED_ADDRESS);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __get_list(CONTEXT_HISTORY_FREQUENTLY_COMMUNICATED_ADDRESS);
+       IF_FAIL_RETURN(value::boolean, false);
 
-       bool_val = __iterate_list(int_attr, double_attr, str_attr);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __iterate_list(int_attr, double_attr, str_attr);
+       IF_FAIL_RETURN(value::boolean, false);
 
        return true;
 }
@@ -415,11 +423,11 @@ bool _history_battery()
        __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, KEY_START_TIME);
        __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, KEY_END_TIME);
 
-       bool_val = __get_list(CONTEXT_HISTORY_BATTERY_USAGE);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __get_list(CONTEXT_HISTORY_BATTERY_USAGE);
+       IF_FAIL_RETURN(value::boolean, false);
 
-       bool_val = __iterate_list(int_attr, double_attr, str_attr);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __iterate_list(int_attr, double_attr, str_attr);
+       IF_FAIL_RETURN(value::boolean, false);
 
        return true;
 }
@@ -433,11 +441,11 @@ bool _history_battery_recent()
        __filter_set_int(CONTEXT_HISTORY_FILTER_RESULT_SIZE, KEY_RESULT_SIZE);
        __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, KEY_END_TIME);
 
-       bool_val = __get_list(CONTEXT_HISTORY_RECENT_BATTERY_USAGE);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __get_list(CONTEXT_HISTORY_RECENT_BATTERY_USAGE);
+       IF_FAIL_RETURN(value::boolean, false);
 
-       bool_val = __iterate_list(int_attr, double_attr, str_attr);
-       IF_FAIL_RETURN(bool_val, false);
+       value::boolean = __iterate_list(int_attr, double_attr, str_attr);
+       IF_FAIL_RETURN(value::boolean, false);
 
        return true;
 }
similarity index 95%
rename from testsuite/src/history/history.h
rename to testsuite/src/app-history/history.h
index 52aa2f0..dc3c0d7 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef __CONTEXT_TEST_HISTORY_H__
 #define __CONTEXT_TEST_HISTORY_H__
 
-int test_history(int *argc, char ***argv);
+int testAppHistory(int *argc, char ***argv);
 
 bool _history_app_recently();
 bool _history_app_frequently();
index 11f7ae9..2faa967 100644 (file)
  */
 
 #include "shared.h"
-#include "trigger/condition.h"
-#include "trigger/event.h"
-#include "history/history.h"
+#include "app-history/history.h"
 
-static void signal_handler(int signo)
+using namespace test;
+
+static void __signalHandler(int signo)
 {
-       if (signo == SIGINT && ctx::test::is_mainloop_running()) {
+       if (signo == SIGINT && isMainloopRunning()) {
                g_print(PURPLE("\nskipping the testcase..."));
-               ctx::test::stop_mainloop();
+               stopMainloop();
        } else {
                g_print(PURPLE("\nterminating... (SIGNAL %d)\n"), signo);
                exit(EXIT_SUCCESS);
        }
 }
 
-static void print_usage()
+static void __printUsage()
 {
        g_print("Usage: context-test TESTSUITE\n\n");
        g_print("TESTSUITE can be one of the followings:\n");
-       g_print("  h\t for testing all contextual history items\n");
-       g_print("  c\t for testing all contextual trigger conditions\n");
-       g_print("  e\t for testing all contextual trigger events\n");
+       g_print("  a\t to test app-history\n");
+       g_print("  j\t to test job-scheduler\n");
 }
 
 int main(int argc, char** argv)
 {
-       signal(SIGINT,  signal_handler);
-       signal(SIGHUP,  signal_handler);
-       signal(SIGTERM, signal_handler);
-       signal(SIGQUIT, signal_handler);
-       signal(SIGABRT, signal_handler);
+       signal(SIGINT,  __signalHandler);
+       signal(SIGHUP,  __signalHandler);
+       signal(SIGTERM, __signalHandler);
+       signal(SIGQUIT, __signalHandler);
+       signal(SIGABRT, __signalHandler);
 
        if (argc < 2) {
-               print_usage();
+               __printUsage();
                return EXIT_SUCCESS;
        }
 
        switch (argv[1][0]) {
-       case 'h':
-               return test_history(&argc, &argv);
-       case 'c':
-               return test_trigger_condition(&argc, &argv);
-       case 'e':
-               return test_trigger_event(&argc, &argv);
+       case 'a':
+               return testAppHistory(&argc, &argv);
+       case 'j':
+               return EXIT_SUCCESS;
        default:
-               print_usage();
+               __printUsage();
                return EXIT_SUCCESS;
        }
 }
index 7e36952..38c5d6d 100644 (file)
 
 #include "shared.h"
 
-static bool __is_mainloop_running = false;
+static GMainLoop* __mainloop = NULL;
 
-namespace ctx {
-       namespace test {
-               GMainLoop *mainloop = NULL;
-               int callback_count = 0;
-               int err = 0;
-               int req_id = 0;
-               int int_val = 0;
-               double double_val = 0;
-               bool bool_val = false;
-               bool skip_tc = false;
-               bool newline_after_tcname = false;
-               ctx::CtxJson1 json_val = EMPTY_JSON_OBJECT;
-               std::string str_val = "";
+namespace test {
+       namespace value {
+               int int32 = 0;
+               double dbl = 0;
+               bool boolean = false;
+               std::string str = "";
        }
+       namespace flag {
+               bool skipTestCase = false;
+               bool newlineAfterTestCaseName = false;
+       }
+       int lastError = 0;
 }
 
-void ctx::test::start_mainloop()
+void test::startMainloop()
 {
-       if (!__is_mainloop_running) {
-               __is_mainloop_running = true;
-               mainloop = g_main_loop_new(NULL, FALSE);
-               g_main_loop_run(mainloop);
+       if (!__mainloop) {
+               __mainloop = g_main_loop_new(NULL, FALSE);
+               g_main_loop_run(__mainloop);
        }
 }
 
-void ctx::test::stop_mainloop()
+void test::stopMainloop()
 {
-       if (__is_mainloop_running) {
-               g_main_loop_quit(mainloop);
-               g_main_loop_unref(mainloop);
-               ctx::test::skip_tc = true;
-               __is_mainloop_running = false;
+       if (__mainloop) {
+               g_main_loop_quit(__mainloop);
+               g_main_loop_unref(__mainloop);
+               test::flag::skipTestCase = true;
+               __mainloop = NULL;
        }
 }
 
-bool ctx::test::is_mainloop_running()
+bool test::isMainloopRunning()
 {
-       return __is_mainloop_running;
+       return (__mainloop != NULL);
 }
 
-void ctx::test::cleanup_vars()
+void test::cleanupVars()
 {
-       ctx::test::callback_count = 5;
-       ctx::test::err = -1;
-       ctx::test::req_id = -1;
-       ctx::test::json_val = EMPTY_JSON_OBJECT;
-       ctx::test::bool_val = false;
-       ctx::test::int_val = 0;
-       ctx::test::double_val = 0;
-       ctx::test::str_val = "";
-       ctx::test::skip_tc = false;
+       test::lastError = -1;
+       test::value::boolean = false;
+       test::value::int32 = 0;
+       test::value::dbl = 0;
+       test::value::str = "";
+       test::flag::skipTestCase = false;
 }
 
-bool ctx::test::get_input_int(const char *msg)
+bool test::getInputInt(const char *msg)
 {
        std::cout << msg;
-       std::getline(std::cin, str_val);
-       IF_FAIL_RETURN(!str_val.empty(), false);
-       int_val = atoi(str_val.c_str());
+       std::getline(std::cin, test::value::str);
+       IF_FAIL_RETURN(!test::value::str.empty(), false);
+       test::value::int32 = atoi(test::value::str.c_str());
        return true;
 }
 
-bool ctx::test::get_input_str(const char *msg)
+bool test::getInputStr(const char *msg)
 {
        std::cout << msg;
-       std::getline(std::cin, str_val);
-       IF_FAIL_RETURN(!str_val.empty(), false);
+       std::getline(std::cin, test::value::str);
+       IF_FAIL_RETURN(!test::value::str.empty(), false);
        return true;
 }
 
-void ctx::test::run_testcase(const char *tc_name, bool (*tc_func)(void))
+void test::runTestCase(const char *tcName, bool (*tcFunc)(void))
 {
-       IF_FAIL_VOID(tc_name && tc_func);
+       IF_FAIL_VOID(tcName && tcFunc);
 
-       g_print(CYAN("%s") ": ", tc_name);
-       if (newline_after_tcname)
+       g_print(CYAN("%s") ": ", tcName);
+       if (test::flag::newlineAfterTestCaseName)
                g_print("\n");
 
-       cleanup_vars();
-       bool result = tc_func();
+       test::cleanupVars();
+       bool result = tcFunc();
        if (result)
                g_print(GREEN("PASS") "\n");
 }
index 55356dc..905a550 100644 (file)
 #include <iostream>
 #include <string>
 #include <glib.h>
-#include <Types.h>
-#include <CtxJson1.h>
-
-#define CALLBACK_COUNT 5
+#include <ContextTypes.h>
+#include <SharedUtil.h>
 
 #define ASSERT(condition) \
        do { \
                if (!(condition)) { \
                        g_print("\n"); \
-                       if (!ctx::test::skip_tc) \
+                       if (!test::flag::skipTestCase) \
                                g_print(RED("FAIL") ": %s(%d) > %s\n", __FUNCTION__, __LINE__, #condition); \
                        return false; \
                } \
        do { \
                if (!((left) comp (right))) { \
                        g_print("\n"); \
-                       if (!ctx::test::skip_tc) \
+                       if (!test::flag::skipTestCase) \
                                g_print(RED("FAIL") ": %s(%d) > %s(%d) %s %s(%d)\n", __FUNCTION__, __LINE__, #left, (left), #comp, #right, (right)); \
                        return false; \
                } \
        } while (0)
 
-#define ASSERT_CONTAIN_STR(JSONOBJ, VKEY) \
-       do { \
-               ctx::test::bool_val = (JSONOBJ).get(NULL, (VKEY), &ctx::test::str_val); \
-               if (!ctx::test::bool_val) { \
-                       g_print("\n"); \
-                       if (!ctx::test::skip_tc) \
-                               g_print(RED("FAIL") ": %s(%d) > Getting the string '%s'\n", __FUNCTION__, __LINE__, (VKEY)); \
-                       return false; \
-               } \
-               g_print("%s(%s) ", (VKEY), ctx::test::str_val.c_str()); \
-       } while (0)
-
-#define ASSERT_CONTAIN_INT(JSONOBJ, VKEY) \
-       do { \
-               ctx::test::bool_val = (JSONOBJ).get(NULL, (VKEY), &ctx::test::int_val); \
-               if (!ctx::test::bool_val) { \
-                       g_print("\n"); \
-                       if (!ctx::test::skip_tc) \
-                               g_print(RED("FAIL") ": %s(%d) > Getting the integer '%s'\n", __FUNCTION__, __LINE__, (VKEY)); \
-                       return false; \
-               } \
-               g_print("%s(%d) ", (VKEY), ctx::test::int_val); \
-       } while (0)
-
-namespace ctx {
-       namespace test {
-               extern GMainLoop *mainloop;
-               extern int callback_count;
-               extern int err;
-               extern int req_id;
-               extern int int_val;
-               extern double double_val;
-               extern bool bool_val;
-               extern bool skip_tc;
-               extern bool newline_after_tcname;
-               extern ctx::CtxJson1 json_val;
-               extern std::string str_val;
+namespace test {
+       namespace value {
+               extern int int32;
+               extern double dbl;
+               extern bool boolean;
+               extern std::string str;
+       }
+       namespace flag {
+               extern bool skipTestCase;
+               extern bool newlineAfterTestCaseName;
+       }
+       extern int lastError;
 
-               void start_mainloop();
-               void stop_mainloop();
-               bool is_mainloop_running();
+       void startMainloop();
+       void stopMainloop();
+       bool isMainloopRunning();
 
-               void cleanup_vars();
-               bool get_input_int(const char *msg);
-               bool get_input_str(const char *msg);
+       void cleanupVars();
+       bool getInputInt(const char *msg);
+       bool getInputStr(const char *msg);
 
-               void run_testcase(const char *tc_name, bool (*tc_func)(void));
-       }
+       void runTestCase(const char *tcName, bool (*tcFunc)(void));
 }
 
 #endif
index 063ece3..851ffec 100644 (file)
@@ -26,45 +26,45 @@ using namespace ctx::test;
 
 int test_trigger_condition(int *argc, char ***argv)
 {
-       run_testcase("/trigger/cond/battery", _trigger_cond_battery);
-       run_testcase("/trigger/cond/charger", _trigger_cond_charger);
-       run_testcase("/trigger/cond/gps", _trigger_cond_gps);
-       run_testcase("/trigger/cond/headphone", _trigger_cond_headphone);
-       run_testcase("/trigger/cond/usb", _trigger_cond_usb);
-       run_testcase("/trigger/cond/wifi", _trigger_cond_wifi);
-       run_testcase("/trigger/cond/psmode", _trigger_cond_psmode);
-       run_testcase("/trigger/cond/call", _trigger_cond_call);
-       run_testcase("/trigger/cond/time", _trigger_cond_time);
-
-       run_testcase("/trigger/cond/app_freq1", _trigger_cond_app_use_freq1);
-       run_testcase("/trigger/cond/app_freq2", _trigger_cond_app_use_freq2);
-       run_testcase("/trigger/cond/app_freq3", _trigger_cond_app_use_freq3);
-       run_testcase("/trigger/cond/app_freq4", _trigger_cond_app_use_freq4);
-
-       run_testcase("/trigger/cond/comm_freq1", _trigger_cond_comm_freq1);
-       run_testcase("/trigger/cond/comm_freq2", _trigger_cond_comm_freq2);
-       run_testcase("/trigger/cond/comm_freq3", _trigger_cond_comm_freq3);
-       run_testcase("/trigger/cond/comm_freq4", _trigger_cond_comm_freq4);
-
-       run_testcase("/trigger/cond/music_freq1", _trigger_cond_music_freq1);
-       run_testcase("/trigger/cond/music_freq2", _trigger_cond_music_freq2);
-       run_testcase("/trigger/cond/music_freq3", _trigger_cond_music_freq3);
-       run_testcase("/trigger/cond/music_freq4", _trigger_cond_music_freq4);
-
-       run_testcase("/trigger/cond/video_freq1", _trigger_cond_video_freq1);
-       run_testcase("/trigger/cond/video_freq2", _trigger_cond_video_freq2);
-       run_testcase("/trigger/cond/video_freq3", _trigger_cond_video_freq3);
-       run_testcase("/trigger/cond/video_freq4", _trigger_cond_video_freq4);
+       runTestCase("/trigger/cond/battery", _trigger_cond_battery);
+       runTestCase("/trigger/cond/charger", _trigger_cond_charger);
+       runTestCase("/trigger/cond/gps", _trigger_cond_gps);
+       runTestCase("/trigger/cond/headphone", _trigger_cond_headphone);
+       runTestCase("/trigger/cond/usb", _trigger_cond_usb);
+       runTestCase("/trigger/cond/wifi", _trigger_cond_wifi);
+       runTestCase("/trigger/cond/psmode", _trigger_cond_psmode);
+       runTestCase("/trigger/cond/call", _trigger_cond_call);
+       runTestCase("/trigger/cond/time", _trigger_cond_time);
+
+       runTestCase("/trigger/cond/app_freq1", _trigger_cond_app_use_freq1);
+       runTestCase("/trigger/cond/app_freq2", _trigger_cond_app_use_freq2);
+       runTestCase("/trigger/cond/app_freq3", _trigger_cond_app_use_freq3);
+       runTestCase("/trigger/cond/app_freq4", _trigger_cond_app_use_freq4);
+
+       runTestCase("/trigger/cond/comm_freq1", _trigger_cond_comm_freq1);
+       runTestCase("/trigger/cond/comm_freq2", _trigger_cond_comm_freq2);
+       runTestCase("/trigger/cond/comm_freq3", _trigger_cond_comm_freq3);
+       runTestCase("/trigger/cond/comm_freq4", _trigger_cond_comm_freq4);
+
+       runTestCase("/trigger/cond/music_freq1", _trigger_cond_music_freq1);
+       runTestCase("/trigger/cond/music_freq2", _trigger_cond_music_freq2);
+       runTestCase("/trigger/cond/music_freq3", _trigger_cond_music_freq3);
+       runTestCase("/trigger/cond/music_freq4", _trigger_cond_music_freq4);
+
+       runTestCase("/trigger/cond/video_freq1", _trigger_cond_video_freq1);
+       runTestCase("/trigger/cond/video_freq2", _trigger_cond_video_freq2);
+       runTestCase("/trigger/cond/video_freq3", _trigger_cond_video_freq3);
+       runTestCase("/trigger/cond/video_freq4", _trigger_cond_video_freq4);
 
        return 0;
 }
 
 static bool __support(context_trigger_condition_e cond)
 {
-       err = context_trigger_rule_condition_is_supported(cond, &bool_val);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = context_trigger_rule_condition_is_supported(cond, &value::boolean);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
-       if (!bool_val) {
+       if (!value::boolean) {
                g_print(YELLOW("Not Supported") "\n");
                return false;
        }
@@ -76,8 +76,8 @@ bool _trigger_cond_battery()
 {
        if (!__support(CONTEXT_TRIGGER_CONDITION_BATTERY)) return false;
 
-       err = ctx::request_handler::read_sync(SUBJ_STATE_BATTERY, NULL, &req_id, &json_val);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::read_sync(SUBJ_STATE_BATTERY, NULL, &req_id, &json_val);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_LEVEL);
        ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_IS_CHARGING);
@@ -89,8 +89,8 @@ bool _trigger_cond_charger()
 {
        if (!__support(CONTEXT_TRIGGER_CONDITION_CHARGER)) return false;
 
-       err = ctx::request_handler::read_sync(SUBJ_STATE_CHARGER, NULL, &req_id, &json_val);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::read_sync(SUBJ_STATE_CHARGER, NULL, &req_id, &json_val);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
        ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_IS_CONNECTED);
 
        return true;
@@ -100,8 +100,8 @@ bool _trigger_cond_gps()
 {
        if (!__support(CONTEXT_TRIGGER_CONDITION_GPS)) return false;
 
-       err = ctx::request_handler::read_sync(SUBJ_STATE_GPS, NULL, &req_id, &json_val);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::read_sync(SUBJ_STATE_GPS, NULL, &req_id, &json_val);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_STATE);
 
@@ -112,11 +112,11 @@ bool _trigger_cond_headphone()
 {
        if (!__support(CONTEXT_TRIGGER_CONDITION_HEADPHONE)) return false;
 
-       err = ctx::request_handler::read_sync(SUBJ_STATE_HEADPHONE, NULL, &req_id, &json_val);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::read_sync(SUBJ_STATE_HEADPHONE, NULL, &req_id, &json_val);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_IS_CONNECTED);
-       if (int_val == CONTEXT_TRIGGER_FALSE) return true;
+       if (value::int32 == CONTEXT_TRIGGER_FALSE) return true;
 
        ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_TYPE);
 
@@ -127,8 +127,8 @@ bool _trigger_cond_usb()
 {
        if (!__support(CONTEXT_TRIGGER_CONDITION_USB)) return false;
 
-       err = ctx::request_handler::read_sync(SUBJ_STATE_USB, NULL, &req_id, &json_val);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::read_sync(SUBJ_STATE_USB, NULL, &req_id, &json_val);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_IS_CONNECTED);
 
@@ -139,12 +139,12 @@ bool _trigger_cond_wifi()
 {
        if (!__support(CONTEXT_TRIGGER_CONDITION_WIFI)) return false;
 
-       err = ctx::request_handler::read_sync(SUBJ_STATE_WIFI, NULL, &req_id, &json_val);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::read_sync(SUBJ_STATE_WIFI, NULL, &req_id, &json_val);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_STATE);
 
-       if (str_val == CONTEXT_TRIGGER_CONNECTED)
+       if (value::str == CONTEXT_TRIGGER_CONNECTED)
                ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_BSSID);
 
        return true;
@@ -154,8 +154,8 @@ bool _trigger_cond_psmode()
 {
        if (!__support(CONTEXT_TRIGGER_CONDITION_POWER_SAVING_MODE)) return false;
 
-       err = ctx::request_handler::read_sync(SUBJ_STATE_PSMODE, NULL, &req_id, &json_val);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::read_sync(SUBJ_STATE_PSMODE, NULL, &req_id, &json_val);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_IS_ENABLED);
 
@@ -166,11 +166,11 @@ bool _trigger_cond_call()
 {
        if (!__support(CONTEXT_TRIGGER_CONDITION_CALL)) return false;
 
-       err = ctx::request_handler::read_sync(SUBJ_STATE_CALL, NULL, &req_id, &json_val);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::read_sync(SUBJ_STATE_CALL, NULL, &req_id, &json_val);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_STATE);
-       if (str_val == CONTEXT_TRIGGER_IDLE) return true;
+       if (value::str == CONTEXT_TRIGGER_IDLE) return true;
 
        ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_MEDIUM);
        ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_ADDRESS);
@@ -182,8 +182,8 @@ bool _trigger_cond_time()
 {
        if (!__support(CONTEXT_TRIGGER_CONDITION_TIME)) return false;
 
-       err = ctx::request_handler::read_sync(SUBJ_STATE_TIME, NULL, &req_id, &json_val);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::read_sync(SUBJ_STATE_TIME, NULL, &req_id, &json_val);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_TIME_OF_DAY);
        ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_DAY_OF_MONTH);
@@ -236,12 +236,12 @@ static bool __trigger_cond_app_use_freq_base(ctx::CtxJson1 option)
 {
        if (!__support(CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY)) return false;
 
-       err = ctx::request_handler::read_sync(SUBJ_APP_FREQUENCY, &option, &req_id, &json_val);
-       if (err == ERR_NO_DATA) {
+       lastError = ctx::request_handler::read_sync(SUBJ_APP_FREQUENCY, &option, &req_id, &json_val);
+       if (lastError == E_NO_DATA) {
                g_print(RED("No Data "));
                return true;
        }
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_APP_ID);
        ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_RANK);
@@ -334,12 +334,12 @@ static bool __trigger_cond_comm_freq_base(ctx::CtxJson1 option)
 {
        if (!__support(CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY)) return false;
 
-       err = ctx::request_handler::read_sync(SUBJ_SOCIAL_FREQUENCY, &option, &req_id, &json_val);
-       if (err == ERR_NO_DATA) {
+       lastError = ctx::request_handler::read_sync(SUBJ_SOCIAL_FREQUENCY, &option, &req_id, &json_val);
+       if (lastError == E_NO_DATA) {
                g_print(RED("No Data "));
                return true;
        }
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_ADDRESS);
        ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_RANK);
@@ -392,12 +392,12 @@ static bool __trigger_cond_media_freq_base(context_trigger_condition_e item, con
 {
        if (!__support(item)) return false;
 
-       err = ctx::request_handler::read_sync(item_str, &option, &req_id, &json_val);
-       if (err == ERR_NO_DATA) {
+       lastError = ctx::request_handler::read_sync(item_str, &option, &req_id, &json_val);
+       if (lastError == E_NO_DATA) {
                g_print(YELLOW("No Data "));
                return true;
        }
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
        ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_TOTAL_COUNT);
 
        return true;
index f36fe70..1f19e82 100644 (file)
@@ -30,7 +30,7 @@ static void __domain_cb(const char *item, int rid, int error, ctx::CtxJson1 data
 
        if (callback_count == 0) {
                json_val = data;
-               stop_mainloop();
+               stopMainloop();
        }
 }
 
@@ -55,29 +55,29 @@ int test_trigger_event(int *argc, char ***argv)
        ctx::request_handler::register_callback(SUBJ_ACTIVITY_IN_VEHICLE, __domain_cb);
        ctx::request_handler::register_callback(SUBJ_PLACE_GEOFENCE, __domain_cb);
 
-       run_testcase("/trigger/event/battery", _trigger_event_battery);
-       run_testcase("/trigger/event/charger", _trigger_event_charger);
-       run_testcase("/trigger/event/gps", _trigger_event_gps);
-       run_testcase("/trigger/event/headphone", _trigger_event_headphone);
-       run_testcase("/trigger/event/usb", _trigger_event_usb);
-       run_testcase("/trigger/event/wifi", _trigger_event_wifi);
-       run_testcase("/trigger/event/psmode", _trigger_event_psmode);
-       run_testcase("/trigger/event/call", _trigger_event_call);
-       run_testcase("/trigger/event/time", _trigger_event_time);
-       run_testcase("/trigger/event/email", _trigger_event_email);
-       run_testcase("/trigger/event/message", _trigger_event_message);
-       run_testcase("/trigger/event/activity", _trigger_event_activity);
-       run_testcase("/trigger/event/place", _trigger_event_place);
+       runTestCase("/trigger/event/battery", _trigger_event_battery);
+       runTestCase("/trigger/event/charger", _trigger_event_charger);
+       runTestCase("/trigger/event/gps", _trigger_event_gps);
+       runTestCase("/trigger/event/headphone", _trigger_event_headphone);
+       runTestCase("/trigger/event/usb", _trigger_event_usb);
+       runTestCase("/trigger/event/wifi", _trigger_event_wifi);
+       runTestCase("/trigger/event/psmode", _trigger_event_psmode);
+       runTestCase("/trigger/event/call", _trigger_event_call);
+       runTestCase("/trigger/event/time", _trigger_event_time);
+       runTestCase("/trigger/event/email", _trigger_event_email);
+       runTestCase("/trigger/event/message", _trigger_event_message);
+       runTestCase("/trigger/event/activity", _trigger_event_activity);
+       runTestCase("/trigger/event/place", _trigger_event_place);
 
        return g_test_run();
 }
 
 static bool __support(context_trigger_event_e ev)
 {
-       err = context_trigger_rule_event_is_supported(ev, &bool_val);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = context_trigger_rule_event_is_supported(ev, &value::boolean);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
-       if (!bool_val) {
+       if (!value::boolean) {
                g_print(YELLOW("Not Supported") "\n");
                return false;
        }
@@ -89,11 +89,11 @@ bool _trigger_event_battery()
 {
        if (!__support(CONTEXT_TRIGGER_EVENT_BATTERY)) return false;
 
-       err = ctx::request_handler::subscribe(SUBJ_STATE_BATTERY, NULL, &req_id, NULL);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::subscribe(SUBJ_STATE_BATTERY, NULL, &req_id, NULL);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        g_print("\n> Change the battery lavel (or charging status) %d times.\n", CALLBACK_COUNT);
-       start_mainloop();
+       startMainloop();
 
        ctx::request_handler::unsubscribe(SUBJ_STATE_BATTERY, req_id);
 
@@ -107,11 +107,11 @@ bool _trigger_event_charger()
 {
        if (!__support(CONTEXT_TRIGGER_EVENT_CHARGER)) return false;
 
-       err = ctx::request_handler::subscribe(SUBJ_STATE_CHARGER, NULL, &req_id, NULL);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::subscribe(SUBJ_STATE_CHARGER, NULL, &req_id, NULL);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        g_print("\n> Change the charger connection state %d times.\n", CALLBACK_COUNT);
-       start_mainloop();
+       startMainloop();
 
        ctx::request_handler::unsubscribe(SUBJ_STATE_CHARGER, req_id);
 
@@ -124,11 +124,11 @@ bool _trigger_event_gps()
 {
        if (!__support(CONTEXT_TRIGGER_EVENT_GPS)) return false;
 
-       err = ctx::request_handler::subscribe(SUBJ_STATE_GPS, NULL, &req_id, NULL);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::subscribe(SUBJ_STATE_GPS, NULL, &req_id, NULL);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        g_print("\n> Change the GPS status %d times.\n", CALLBACK_COUNT);
-       start_mainloop();
+       startMainloop();
 
        ctx::request_handler::unsubscribe(SUBJ_STATE_GPS, req_id);
 
@@ -141,16 +141,16 @@ bool _trigger_event_headphone()
 {
        if (!__support(CONTEXT_TRIGGER_EVENT_HEADPHONE)) return false;
 
-       err = ctx::request_handler::subscribe(SUBJ_STATE_HEADPHONE, NULL, &req_id, NULL);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::subscribe(SUBJ_STATE_HEADPHONE, NULL, &req_id, NULL);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        g_print("\n> Connect/disconnect a headphone %d times.\n", CALLBACK_COUNT);
-       start_mainloop();
+       startMainloop();
 
        ctx::request_handler::unsubscribe(SUBJ_STATE_HEADPHONE, req_id);
 
        ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_IS_CONNECTED);
-       if (int_val == CONTEXT_TRIGGER_FALSE) return true;
+       if (value::int32 == CONTEXT_TRIGGER_FALSE) return true;
 
        ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_TYPE);
 
@@ -161,11 +161,11 @@ bool _trigger_event_usb()
 {
        if (!__support(CONTEXT_TRIGGER_EVENT_USB)) return false;
 
-       err = ctx::request_handler::subscribe(SUBJ_STATE_USB, NULL, &req_id, NULL);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::subscribe(SUBJ_STATE_USB, NULL, &req_id, NULL);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        g_print("\n> Connect/disconnect USB %d times.\n", CALLBACK_COUNT);
-       start_mainloop();
+       startMainloop();
 
        ctx::request_handler::unsubscribe(SUBJ_STATE_USB, req_id);
 
@@ -178,17 +178,17 @@ bool _trigger_event_wifi()
 {
        if (!__support(CONTEXT_TRIGGER_EVENT_WIFI)) return false;
 
-       err = ctx::request_handler::subscribe(SUBJ_STATE_WIFI, NULL, &req_id, NULL);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::subscribe(SUBJ_STATE_WIFI, NULL, &req_id, NULL);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        g_print("\n> Change the WiFi state %d times.\n", CALLBACK_COUNT);
-       start_mainloop();
+       startMainloop();
 
        ctx::request_handler::unsubscribe(SUBJ_STATE_WIFI, req_id);
 
        ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_STATE);
 
-       if (str_val == CONTEXT_TRIGGER_CONNECTED)
+       if (value::str == CONTEXT_TRIGGER_CONNECTED)
                ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_BSSID);
 
        return true;
@@ -198,11 +198,11 @@ bool _trigger_event_psmode()
 {
        if (!__support(CONTEXT_TRIGGER_EVENT_POWER_SAVING_MODE)) return false;
 
-       err = ctx::request_handler::subscribe(SUBJ_STATE_PSMODE, NULL, &req_id, NULL);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::subscribe(SUBJ_STATE_PSMODE, NULL, &req_id, NULL);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        g_print("\n> Turn on/off the power-saving mode %d times.\n", CALLBACK_COUNT);
-       start_mainloop();
+       startMainloop();
 
        ctx::request_handler::unsubscribe(SUBJ_STATE_PSMODE, req_id);
 
@@ -215,16 +215,16 @@ bool _trigger_event_call()
 {
        if (!__support(CONTEXT_TRIGGER_EVENT_CALL)) return false;
 
-       err = ctx::request_handler::subscribe(SUBJ_STATE_CALL, NULL, &req_id, NULL);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::subscribe(SUBJ_STATE_CALL, NULL, &req_id, NULL);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        g_print("\n> Make a phone call to this device to change call state %d times.\n", CALLBACK_COUNT);
-       start_mainloop();
+       startMainloop();
 
        ctx::request_handler::unsubscribe(SUBJ_STATE_CALL, req_id);
 
        ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_STATE);
-       if (str_val == CONTEXT_TRIGGER_IDLE) return true;
+       if (value::str == CONTEXT_TRIGGER_IDLE) return true;
 
        ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_MEDIUM);
        ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_ADDRESS);
@@ -276,12 +276,12 @@ bool _trigger_event_time()
        option.append(NULL, CONTEXT_TRIGGER_DAY_OF_WEEK, dow_str);
        option.append(NULL, CONTEXT_TRIGGER_TIME_OF_DAY, tod);
 
-       err = ctx::request_handler::subscribe(SUBJ_STATE_ALARM, &option, &req_id, NULL);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::subscribe(SUBJ_STATE_ALARM, &option, &req_id, NULL);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        callback_count = 1;
        g_print("\n> Wait until %02d:%02d %s.\n", tod / 60, tod % 60, dow_str.c_str());
-       start_mainloop();
+       startMainloop();
 
        ctx::request_handler::unsubscribe(SUBJ_STATE_CALL, req_id);
 
@@ -295,11 +295,11 @@ bool _trigger_event_email()
 {
        if (!__support(CONTEXT_TRIGGER_EVENT_EMAIL)) return false;
 
-       err = ctx::request_handler::subscribe(SUBJ_STATE_EMAIL, NULL, &req_id, NULL);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::subscribe(SUBJ_STATE_EMAIL, NULL, &req_id, NULL);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        g_print("\n> Send/receive emails %d times.\n", CALLBACK_COUNT);
-       start_mainloop();
+       startMainloop();
 
        ctx::request_handler::unsubscribe(SUBJ_STATE_EMAIL, req_id);
 
@@ -312,11 +312,11 @@ bool _trigger_event_message()
 {
        if (!__support(CONTEXT_TRIGGER_EVENT_MESSAGE)) return false;
 
-       err = ctx::request_handler::subscribe(SUBJ_STATE_MESSAGE, NULL, &req_id, NULL);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::subscribe(SUBJ_STATE_MESSAGE, NULL, &req_id, NULL);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        g_print("\n> Receive SMS/MMS %d times.\n", CALLBACK_COUNT);
-       start_mainloop();
+       startMainloop();
 
        ctx::request_handler::unsubscribe(SUBJ_STATE_MESSAGE, req_id);
 
@@ -335,20 +335,20 @@ bool _trigger_event_activity()
 
        int req_ids[4];
 
-       err = ctx::request_handler::subscribe(SUBJ_ACTIVITY_STATIONARY, NULL, &req_ids[0], NULL);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::subscribe(SUBJ_ACTIVITY_STATIONARY, NULL, &req_ids[0], NULL);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
-       err = ctx::request_handler::subscribe(SUBJ_ACTIVITY_WALKING, NULL, &req_ids[1], NULL);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::subscribe(SUBJ_ACTIVITY_WALKING, NULL, &req_ids[1], NULL);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
-       err = ctx::request_handler::subscribe(SUBJ_ACTIVITY_RUNNING, NULL, &req_ids[2], NULL);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::subscribe(SUBJ_ACTIVITY_RUNNING, NULL, &req_ids[2], NULL);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
-       err = ctx::request_handler::subscribe(SUBJ_ACTIVITY_IN_VEHICLE, NULL, &req_ids[3], NULL);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::subscribe(SUBJ_ACTIVITY_IN_VEHICLE, NULL, &req_ids[3], NULL);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        g_print("\n> Mimic any type of activity %d times.\n", CALLBACK_COUNT);
-       start_mainloop();
+       startMainloop();
 
        ctx::request_handler::unsubscribe(SUBJ_ACTIVITY_STATIONARY, req_ids[0]);
        ctx::request_handler::unsubscribe(SUBJ_ACTIVITY_WALKING, req_ids[1]);
@@ -368,11 +368,11 @@ bool _trigger_event_place()
        ctx::CtxJson1 option;
        option.set(NULL, CONTEXT_TRIGGER_PLACE_ID, 2);  /* 2 => office */
 
-       err = ctx::request_handler::subscribe(SUBJ_PLACE_GEOFENCE, &option, &req_id, NULL);
-       ASSERT_CMPINT(err, ==, ERR_NONE);
+       lastError = ctx::request_handler::subscribe(SUBJ_PLACE_GEOFENCE, &option, &req_id, NULL);
+       ASSERT_CMPINT(lastError, ==, E_NONE);
 
        g_print("\n> Mimic fence in/out event to office %d times.\n", CALLBACK_COUNT);
-       start_mainloop();
+       startMainloop();
 
        ctx::request_handler::unsubscribe(SUBJ_PLACE_GEOFENCE, req_id);