Add default testcases for testing the public API's availability 59/140859/1
authorMu-Woong Lee <muwoong.lee@samsung.com>
Thu, 27 Jul 2017 02:34:04 +0000 (11:34 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Thu, 27 Jul 2017 02:34:04 +0000 (11:34 +0900)
Change-Id: I124a195f57d74b612832b46483a68b0c9dda23c3
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
testsuite/CMakeLists.txt
testsuite/src/default/DefaultTest.cpp [new file with mode: 0644]
testsuite/src/default/DefaultTest.h [new file with mode: 0644]
testsuite/src/job-scheduler/JobSchedulerTest.h
testsuite/src/main.cpp
testsuite/src/shared.cpp
testsuite/src/shared.h

index f8d0518..2469f29 100644 (file)
@@ -3,7 +3,7 @@ PROJECT(capi-context-test)
 SET(TEST_EXEC context-test)
 
 # Source List
-FILE(GLOB TEST_SRCS src/*.cpp src/app-history/*.cpp src/job-scheduler/*.cpp)
+FILE(GLOB_RECURSE TEST_SRCS src/*.cpp)
 INCLUDE_DIRECTORIES(
        ${CMAKE_SOURCE_DIR}/src
 )
diff --git a/testsuite/src/default/DefaultTest.cpp b/testsuite/src/default/DefaultTest.cpp
new file mode 100644 (file)
index 0000000..da82829
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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 <vector>
+#include <context_history.h>
+#include <context_trigger.h>
+#include "../shared.h"
+#include "DefaultTest.h"
+
+using namespace test;
+
+static bool __verify_context_history();
+static bool __verify_context_trigger();
+
+int test_default(int *argc, char ***argv)
+{
+       g_print("\n");
+       run_test_case("/api-availability/context-history", __verify_context_history);
+
+       g_print("\n");
+       run_test_case("/api-availability/context-trigger", __verify_context_trigger);
+
+       return 0;
+}
+
+bool __verify_context_history()
+{
+       context_history_h history = NULL;
+       context_history_filter_h filter = NULL;
+       context_history_list_h queryResult = NULL;
+
+       context_history_create(&history);
+       context_history_filter_create(&filter);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, 5);
+
+       int error = context_history_get_list(history, CONTEXT_HISTORY_RECENTLY_USED_APP, filter, &queryResult);
+
+       context_history_list_destroy(queryResult);
+       context_history_filter_destroy(filter);
+       context_history_destroy(history);
+
+       ASSERT(error == CONTEXT_HISTORY_ERROR_NONE || error == CONTEXT_HISTORY_ERROR_NO_DATA);
+
+       return true;
+}
+
+bool __verify_context_trigger()
+{
+       std::vector<context_trigger_event_e> events({
+               CONTEXT_TRIGGER_EVENT_BATTERY,
+               CONTEXT_TRIGGER_EVENT_CHARGER,
+               CONTEXT_TRIGGER_EVENT_GPS,
+               CONTEXT_TRIGGER_EVENT_HEADPHONE,
+               CONTEXT_TRIGGER_EVENT_USB
+       });
+
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       bool supported = false;
+       context_trigger_rule_entry_h entry = NULL;
+
+       for (context_trigger_event_e event : events) {
+               error = context_trigger_rule_event_is_supported(event, &supported);
+               ASSERT_CMPINT(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+               if (!supported)
+                       continue;
+
+               error = context_trigger_rule_event_create(event, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &entry);
+               context_trigger_rule_entry_destroy(entry);
+               entry = NULL;
+               ASSERT_CMPINT(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+       }
+
+       return true;
+}
diff --git a/testsuite/src/default/DefaultTest.h b/testsuite/src/default/DefaultTest.h
new file mode 100644 (file)
index 0000000..00f827a
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#ifndef __CONTEXT_DEFAULT_TEST_H__
+#define __CONTEXT_DEFAULT_TEST_H__
+
+int test_default(int *argc, char ***argv);
+
+#endif /* __CONTEXT_CONTEXT_DEFAULT_TEST_H__ */
index eb9f97f..e4b61e8 100644 (file)
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef __CONTEXT_CONTEXT_JOB_SCHEDULER_TEST_H__
-#define __CONTEXT_CONTEXT_JOB_SCHEDULER_TEST_H__
+#ifndef __CONTEXT_JOB_SCHEDULER_TEST_H__
+#define __CONTEXT_JOB_SCHEDULER_TEST_H__
 
 #include <job_scheduler_internal.h>
 
@@ -25,4 +25,4 @@ namespace sched {
        ctx_sched_job_h create_job(ctx_sched_h scheduler, int num);
 }
 
-#endif /* __CONTEXT_CONTEXT_JOB_SCHEDULER_TEST_H__ */
+#endif /* __CONTEXT_JOB_SCHEDULER_TEST_H__ */
index 4c32689..04d76c1 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include "shared.h"
+#include "default/DefaultTest.h"
 #include "app-history/history.h"
 #include "job-scheduler/JobSchedulerTest.h"
 
@@ -46,6 +47,9 @@ int main(int argc, char** argv)
        signal(SIGTERM, __signal_handler);
        signal(SIGQUIT, __signal_handler);
 
+       test_default(&argc, &argv);
+       g_print("\n");
+
        if (argc < 2) {
                __print_usage();
                return EXIT_SUCCESS;
index b93805d..77e5185 100644 (file)
@@ -80,5 +80,5 @@ void test::run_test_case(const char *tcName, bool (*tcFunc)(void))
 
        bool result = tcFunc();
        if (result)
-               g_print("\n>> " GREEN("PASS") "\n");
+               g_print(">> " GREEN("PASS") "\n");
 }
index 7359057..094b583 100644 (file)
@@ -27,7 +27,7 @@
 #define ASSERT_RETURN(condition, ret) \
        do { \
                if (!(condition)) { \
-                       g_print("\n>> " RED("FAIL") ": %s(%d) > %s\n", __FUNCTION__, __LINE__, #condition); \
+                       g_print(">> " RED("FAIL") ": %s(%d) > %s\n", __FUNCTION__, __LINE__, #condition); \
                        return ret; \
                } \
        } while (0)
@@ -37,7 +37,7 @@
 #define ASSERT_CMPINT(left, comp, right) \
        do { \
                if (!((left) comp (right))) { \
-                       g_print("\n>> " RED("FAIL") ": %s(%d) > %s(%d) %s %s(%d)\n", __FUNCTION__, __LINE__, #left, (left), #comp, #right, (right)); \
+                       g_print(">> " RED("FAIL") ": %s(%d) > %s(%d) %s %s(%d)\n", __FUNCTION__, __LINE__, #left, (left), #comp, #right, (right)); \
                        return false; \
                } \
        } while (0)