Rearrange contacts-service.service from default.target to delayed.target
[platform/core/pim/contacts-service.git] / test / test_main.c
1 /*
2  * Copyright (c) 2016 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 <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <contacts.h>
21
22 #include "test_main.h"
23 #include "test_debug.h"
24 #include "test_query.h"
25
26 int _print_errors(int argc, char **argv)
27 {
28         DBG("CONTACTS_ERROR_NONE               (%d)", CONTACTS_ERROR_NONE);
29         DBG("CONTACTS_ERROR_OUT_OF_MEMORY      (%d)", CONTACTS_ERROR_OUT_OF_MEMORY);
30         DBG("CONTACTS_ERROR_INVALID_PARAMETER  (%d)", CONTACTS_ERROR_INVALID_PARAMETER);
31         DBG("CONTACTS_ERROR_FILE_NO_SPACE      (%d)", CONTACTS_ERROR_FILE_NO_SPACE);
32         DBG("CONTACTS_ERROR_PERMISSION_DENIED  (%d)", CONTACTS_ERROR_PERMISSION_DENIED);
33         DBG("CONTACTS_ERROR_NOT_SUPPORTED      (%d)", CONTACTS_ERROR_NOT_SUPPORTED);
34         DBG("CONTACTS_ERROR_NO_DATA            (%d)", CONTACTS_ERROR_NO_DATA);
35         DBG("CONTACTS_ERROR_DB_LOCKED          (%d)", CONTACTS_ERROR_DB_LOCKED);
36         DBG("CONTACTS_ERROR_DB                 (%d)", CONTACTS_ERROR_DB);
37         DBG("CONTACTS_ERROR_IPC_NOT_AVALIABLE  (%d)", CONTACTS_ERROR_IPC_NOT_AVALIABLE);
38         DBG("CONTACTS_ERROR_IPC                (%d)", CONTACTS_ERROR_IPC);
39         DBG("CONTACTS_ERROR_SYSTEM             (%d)", CONTACTS_ERROR_SYSTEM);
40         DBG("CONTACTS_ERROR_INTERNAL           (%d)", CONTACTS_ERROR_INTERNAL);
41
42         return 0;
43 }
44
45 static const func _func[] = {
46         _print_errors,
47         test_query,
48 };
49
50 bool test_main_is_selected(int argc, char **argv, int depth, const func test_func[], int count)
51 {
52         if (argc <= depth)
53                 return false;
54
55         int select = atoi(argv[depth]);
56
57         if (0 <= select && select < count)
58                 test_func[select](argc, argv);
59         else
60                 ERR("no test func (%d)", select);
61
62         return true;
63 }
64
65 /*
66  * With no argument, all cases are tested.
67  * If argument, specific case could be tested.
68  * ex> to test all cases,
69  *   # /usr/bin/calendar-service-test
70  *   to test 4th case,
71  *   # /usr/bin/calendar-service-test 4
72  *
73  * NOTICE: each case could be tested independently.
74  *         create resource -> test -> delete resource.
75  */
76
77 int main(int argc, char **argv)
78 {
79         ENTER();
80
81         DBG("argc(%d)", argc);
82
83         int count = sizeof(_func) / sizeof(func);
84         if (true == test_main_is_selected(argc, argv, 1, _func, count))
85                 return 0;
86
87         int i = 0;
88         for (i = 0; i < count; i++) {
89                 if (_func[i](argc, argv) < 0)
90                         break;
91         }
92         return 0;
93 }