From efaee508cfe5edbd397a908c93330c36335d90cf Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Thu, 27 Jul 2017 11:34:04 +0900 Subject: [PATCH] Add default testcases for testing the public API's availability Change-Id: I124a195f57d74b612832b46483a68b0c9dda23c3 Signed-off-by: Mu-Woong Lee --- testsuite/CMakeLists.txt | 2 +- testsuite/src/default/DefaultTest.cpp | 88 ++++++++++++++++++++++++++ testsuite/src/default/DefaultTest.h | 22 +++++++ testsuite/src/job-scheduler/JobSchedulerTest.h | 6 +- testsuite/src/main.cpp | 4 ++ testsuite/src/shared.cpp | 2 +- testsuite/src/shared.h | 4 +- 7 files changed, 121 insertions(+), 7 deletions(-) create mode 100644 testsuite/src/default/DefaultTest.cpp create mode 100644 testsuite/src/default/DefaultTest.h diff --git a/testsuite/CMakeLists.txt b/testsuite/CMakeLists.txt index f8d0518..2469f29 100644 --- a/testsuite/CMakeLists.txt +++ b/testsuite/CMakeLists.txt @@ -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 index 0000000..da82829 --- /dev/null +++ b/testsuite/src/default/DefaultTest.cpp @@ -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 +#include +#include +#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 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 index 0000000..00f827a --- /dev/null +++ b/testsuite/src/default/DefaultTest.h @@ -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__ */ diff --git a/testsuite/src/job-scheduler/JobSchedulerTest.h b/testsuite/src/job-scheduler/JobSchedulerTest.h index eb9f97f..e4b61e8 100644 --- a/testsuite/src/job-scheduler/JobSchedulerTest.h +++ b/testsuite/src/job-scheduler/JobSchedulerTest.h @@ -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 @@ -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__ */ diff --git a/testsuite/src/main.cpp b/testsuite/src/main.cpp index 4c32689..04d76c1 100644 --- a/testsuite/src/main.cpp +++ b/testsuite/src/main.cpp @@ -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; diff --git a/testsuite/src/shared.cpp b/testsuite/src/shared.cpp index b93805d..77e5185 100644 --- a/testsuite/src/shared.cpp +++ b/testsuite/src/shared.cpp @@ -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"); } diff --git a/testsuite/src/shared.h b/testsuite/src/shared.h index 7359057..094b583 100644 --- a/testsuite/src/shared.h +++ b/testsuite/src/shared.h @@ -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) -- 2.7.4