Add default testcases for testing the public API's availability
[platform/core/api/context.git] / testsuite / src / default / DefaultTest.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <vector>
18 #include <context_history.h>
19 #include <context_trigger.h>
20 #include "../shared.h"
21 #include "DefaultTest.h"
22
23 using namespace test;
24
25 static bool __verify_context_history();
26 static bool __verify_context_trigger();
27
28 int test_default(int *argc, char ***argv)
29 {
30         g_print("\n");
31         run_test_case("/api-availability/context-history", __verify_context_history);
32
33         g_print("\n");
34         run_test_case("/api-availability/context-trigger", __verify_context_trigger);
35
36         return 0;
37 }
38
39 bool __verify_context_history()
40 {
41         context_history_h history = NULL;
42         context_history_filter_h filter = NULL;
43         context_history_list_h queryResult = NULL;
44
45         context_history_create(&history);
46         context_history_filter_create(&filter);
47         context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, 5);
48
49         int error = context_history_get_list(history, CONTEXT_HISTORY_RECENTLY_USED_APP, filter, &queryResult);
50
51         context_history_list_destroy(queryResult);
52         context_history_filter_destroy(filter);
53         context_history_destroy(history);
54
55         ASSERT(error == CONTEXT_HISTORY_ERROR_NONE || error == CONTEXT_HISTORY_ERROR_NO_DATA);
56
57         return true;
58 }
59
60 bool __verify_context_trigger()
61 {
62         std::vector<context_trigger_event_e> events({
63                 CONTEXT_TRIGGER_EVENT_BATTERY,
64                 CONTEXT_TRIGGER_EVENT_CHARGER,
65                 CONTEXT_TRIGGER_EVENT_GPS,
66                 CONTEXT_TRIGGER_EVENT_HEADPHONE,
67                 CONTEXT_TRIGGER_EVENT_USB
68         });
69
70         int error = CONTEXT_TRIGGER_ERROR_NONE;
71         bool supported = false;
72         context_trigger_rule_entry_h entry = NULL;
73
74         for (context_trigger_event_e event : events) {
75                 error = context_trigger_rule_event_is_supported(event, &supported);
76                 ASSERT_CMPINT(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
77
78                 if (!supported)
79                         continue;
80
81                 error = context_trigger_rule_event_create(event, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &entry);
82                 context_trigger_rule_entry_destroy(entry);
83                 entry = NULL;
84                 ASSERT_CMPINT(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
85         }
86
87         return true;
88 }