Tizen 2.1 base
[platform/core/system/sync-agent.git] / TC / testcase / utc_sync_agent_framework_engine_controller.c
1 /*
2  * sync-agent
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include <tet_api.h>
19
20 #include <sync_agent.h>
21
22 enum {
23         POSITIVE_TC_IDX = 0x01,
24         NEGATIVE_TC_IDX,
25 };
26
27 static void startup(void);
28 static void cleanup(void);
29
30 void (*tet_startup) (void) = startup;
31 void (*tet_cleanup) (void) = cleanup;
32
33 #define TEST_FW_CONFIG_FILE     "../../../testcase/fw-test-cfg/test_fw_config.xml"
34
35 #define API_NAME_SYNC_START_UP  "startup"
36
37 #define API_NAME_SYNC_AGENT_ALLOC_PARAM_SPEC_INT "sync_agent_alloc_param_spec_int"
38 #define API_NAME_SYNC_AGENT_ALLOC_PARAM_SPEC_STRUCTURE "sync_agent_alloc_param_spec_structure"
39
40 #define API_NAME_SYNC_AGENT_CREATE_QUEUING_RULE_SPEC_OUTLINE "sync_agent_create_queuing_rule_spec_outline"
41 #define API_NAME_SYNC_AGENT_ADD_PROGRESS_BLOCKING_ELEMENT "sync_agent_add_progress_blocking_element"
42
43 #define API_NAME_SYNC_AGENT_ALLOC_SIMPLE_TASK_SPEC "sync_agent_alloc_simple_task_spec"
44
45 static void utc_sync_agent_framework_sync_agent_alloc_param_spec_int_p(void);
46 static void utc_sync_agent_framework_sync_agent_alloc_param_spec_int_n(void);
47 static void utc_sync_agent_framework_sync_agent_alloc_param_spec_structure_p(void);
48 static void utc_sync_agent_framework_sync_agent_alloc_param_spec_structure_n(void);
49 static void utc_sync_agent_framework_sync_agent_create_queuing_rule_spec_outline_p(void);
50 static void utc_sync_agent_framework_sync_agent_create_queuing_rule_spec_outline_n(void);
51 static void utc_sync_agent_framework_sync_agent_add_progress_blocking_element_p(void);
52 static void utc_sync_agent_framework_sync_agent_add_progress_blocking_element_n(void);
53 static void utc_sync_agent_framework_sync_agent_alloc_simple_task_spec_p(void);
54 static void utc_sync_agent_framework_sync_agent_alloc_simple_task_spec_n(void);
55
56 struct tet_testlist tet_testlist[] = {
57         {utc_sync_agent_framework_sync_agent_alloc_param_spec_int_p, POSITIVE_TC_IDX},
58         {utc_sync_agent_framework_sync_agent_alloc_param_spec_int_n, NEGATIVE_TC_IDX},
59         {utc_sync_agent_framework_sync_agent_alloc_param_spec_structure_p, POSITIVE_TC_IDX},
60         {utc_sync_agent_framework_sync_agent_alloc_param_spec_structure_n, NEGATIVE_TC_IDX},
61
62         {utc_sync_agent_framework_sync_agent_create_queuing_rule_spec_outline_p, POSITIVE_TC_IDX},
63         {utc_sync_agent_framework_sync_agent_create_queuing_rule_spec_outline_n, NEGATIVE_TC_IDX},
64         {utc_sync_agent_framework_sync_agent_add_progress_blocking_element_p, POSITIVE_TC_IDX},
65         {utc_sync_agent_framework_sync_agent_add_progress_blocking_element_n, NEGATIVE_TC_IDX},
66
67         {utc_sync_agent_framework_sync_agent_alloc_simple_task_spec_p, POSITIVE_TC_IDX},
68         {utc_sync_agent_framework_sync_agent_alloc_simple_task_spec_n, NEGATIVE_TC_IDX},
69
70         {NULL, 0}
71 };
72
73 #define EC_MSG_TYPE_SIMPLE_TASK         1
74 #define EC_MSG_TYPE_NAME_SIMPLE_TASK    "simple_task"
75
76 sync_agent_ec_task_error_e simple_task(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
77 {
78
79         return SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
80 }
81
82 static void startup(void)
83 {
84         /* start of TC */
85         sync_agent_init_error_e init_error = sync_agent_init(TEST_FW_CONFIG_FILE);
86         if (init_error != SYNC_AGENT_INIT_SUCCESS) {
87                 dts_message(API_NAME_SYNC_START_UP, "sync_agent_init : %d", init_error);
88                 dts_fail(API_NAME_SYNC_START_UP);
89         } else {
90                 dts_pass(API_NAME_SYNC_START_UP);
91         }
92 }
93
94 static void cleanup(void)
95 {
96         /* start of TC */
97 }
98
99 static void utc_sync_agent_framework_sync_agent_alloc_param_spec_int_p(void)
100 {
101         char *api_name = API_NAME_SYNC_AGENT_ALLOC_PARAM_SPEC_INT;
102         sync_agent_ec_param_spec_s *param_spec = NULL;
103
104         param_spec = sync_agent_alloc_param_spec_int("param_int", true, false, false, 0, 0, false, 0, false, 0, 0);
105         if (param_spec != NULL) {
106                 dts_pass(api_name);
107         } else {
108                 dts_message(api_name, "sync_agent_alloc_param_spec_int");
109                 dts_fail(api_name);
110         }
111 }
112
113 static void utc_sync_agent_framework_sync_agent_alloc_param_spec_int_n(void)
114 {
115         char *api_name = API_NAME_SYNC_AGENT_ALLOC_PARAM_SPEC_INT;
116         sync_agent_ec_param_spec_s *param_spec = NULL;
117
118         param_spec = sync_agent_alloc_param_spec_int(NULL, true, false, false, 0, 0, false, 0, false, 0, 0);
119         if (param_spec == NULL) {
120                 dts_pass(api_name);
121         } else {
122                 dts_message(api_name, "sync_agent_alloc_param_spec_int");
123                 dts_fail(api_name);
124         }
125 }
126
127 static void utc_sync_agent_framework_sync_agent_alloc_param_spec_structure_p(void)
128 {
129         char *api_name = API_NAME_SYNC_AGENT_ALLOC_PARAM_SPEC_STRUCTURE;
130         sync_agent_ec_param_spec_s *param_spec = NULL;
131
132         param_spec = sync_agent_alloc_param_spec_structure("param_struct", NULL, NULL, true, false, false, NULL, false, NULL, false, NULL);
133         if (param_spec != NULL) {
134                 dts_pass(api_name);
135         } else {
136                 dts_message(api_name, "sync_agent_alloc_param_spec_structure");
137                 dts_fail(api_name);
138         }
139 }
140
141 static void utc_sync_agent_framework_sync_agent_alloc_param_spec_structure_n(void)
142 {
143         char *api_name = API_NAME_SYNC_AGENT_ALLOC_PARAM_SPEC_STRUCTURE;
144         sync_agent_ec_param_spec_s *param_spec = NULL;
145
146         param_spec = sync_agent_alloc_param_spec_structure(NULL, NULL, NULL, true, false, false, NULL, false, NULL, false, NULL);
147         if (param_spec == NULL) {
148                 dts_pass(api_name);
149         } else {
150                 dts_message(api_name, "sync_agent_alloc_param_spec_structure");
151                 dts_fail(api_name);
152         }
153 }
154
155 static void utc_sync_agent_framework_sync_agent_create_queuing_rule_spec_outline_p(void)
156 {
157         char *api_name = API_NAME_SYNC_AGENT_CREATE_QUEUING_RULE_SPEC_OUTLINE;
158         sync_agent_ec_queuing_rule_spec_s *queuing_rule = NULL;
159
160         queuing_rule = sync_agent_create_queuing_rule_spec_outline("queuing_rule_name");
161         if (queuing_rule != NULL) {
162                 dts_pass(api_name);
163         } else {
164                 dts_message(api_name, "sync_agent_create_queuing_rule_spec_outline");
165                 dts_fail(api_name);
166         }
167 }
168
169 static void utc_sync_agent_framework_sync_agent_create_queuing_rule_spec_outline_n(void)
170 {
171         char *api_name = API_NAME_SYNC_AGENT_CREATE_QUEUING_RULE_SPEC_OUTLINE;
172         sync_agent_ec_queuing_rule_spec_s *queuing_rule = NULL;
173
174         queuing_rule = sync_agent_create_queuing_rule_spec_outline(NULL);
175         if (queuing_rule == NULL) {
176                 dts_pass(api_name);
177         } else {
178                 dts_message(api_name, "sync_agent_create_queuing_rule_spec_outline");
179                 dts_fail(api_name);
180         }
181 }
182
183 static void utc_sync_agent_framework_sync_agent_add_progress_blocking_element_p(void)
184 {
185         char *api_name = API_NAME_SYNC_AGENT_ADD_PROGRESS_BLOCKING_ELEMENT;
186         sync_agent_ec_error_e ec_err = SYNC_AGENT_EC_OK;
187         sync_agent_ec_queuing_rule_spec_s *queuing_rule = NULL;
188         sync_agent_ec_task_spec_s *task_spec = NULL;
189
190         sync_agent_ec_param_spec_s *param_spec = sync_agent_alloc_param_spec_int("param", true, false, false, 0, 0, false, 0, false, 0, 0);
191         if (param_spec == NULL) {
192                 dts_message(api_name, "sync_agent_alloc_param_spec_int");
193                 dts_fail(api_name);
194         }
195
196         sync_agent_ec_param_spec_s *param_spec_array[1] = { param_spec };
197
198         task_spec = sync_agent_alloc_simple_task_spec("simple_task", simple_task, NULL, NULL, 1, param_spec_array);
199         if (task_spec == NULL) {
200                 dts_message(api_name, "sync_agent_alloc_simple_task_spec");
201                 dts_fail(api_name);
202         }
203
204         sync_agent_unref_param_spec(param_spec);
205
206         queuing_rule = sync_agent_create_queuing_rule_spec_outline("queuing_rule_name");
207         if (queuing_rule == NULL) {
208                 dts_message(api_name, "sync_agent_create_queuing_rule_spec_outline");
209                 dts_fail(api_name);
210         }
211
212         ec_err = sync_agent_add_progress_blocking_element(queuing_rule, EC_MSG_TYPE_SIMPLE_TASK, task_spec, 0);
213         if (ec_err == SYNC_AGENT_EC_OK) {
214                 dts_pass(api_name);
215         } else {
216                 dts_message(api_name, "sync_agent_add_progress_blocking_element");
217                 dts_fail(api_name);
218         }
219 }
220
221 static void utc_sync_agent_framework_sync_agent_add_progress_blocking_element_n(void)
222 {
223         char *api_name = API_NAME_SYNC_AGENT_ADD_PROGRESS_BLOCKING_ELEMENT;
224         sync_agent_ec_error_e ec_err = SYNC_AGENT_EC_OK;
225         sync_agent_ec_queuing_rule_spec_s *queuing_rule = NULL;
226         sync_agent_ec_task_spec_s *task_spec = NULL;
227
228         ec_err = sync_agent_add_progress_blocking_element(queuing_rule, EC_MSG_TYPE_SIMPLE_TASK, task_spec, 0);
229         if (ec_err != SYNC_AGENT_EC_OK) {
230                 dts_pass(api_name);
231         } else {
232                 dts_message(api_name, "sync_agent_add_progress_blocking_element");
233                 dts_fail(api_name);
234         }
235 }
236
237 static void utc_sync_agent_framework_sync_agent_alloc_simple_task_spec_p(void)
238 {
239         char *api_name = API_NAME_SYNC_AGENT_ALLOC_SIMPLE_TASK_SPEC;
240         sync_agent_ec_task_spec_s *task_spec = NULL;
241
242         sync_agent_ec_param_spec_s *param_spec = sync_agent_alloc_param_spec_int("param", true, false, false, 0, 0, false, 0, false, 0, 0);
243         if (param_spec == NULL) {
244                 dts_message(api_name, "sync_agent_alloc_param_spec_int");
245                 dts_fail(api_name);
246         }
247
248         sync_agent_ec_param_spec_s *param_spec_array[1] = { param_spec };
249
250         task_spec = sync_agent_alloc_simple_task_spec("simple_task", simple_task, NULL, NULL, 1, param_spec_array);
251         if (task_spec != NULL) {
252                 dts_pass(api_name);
253         } else {
254                 dts_message(api_name, "sync_agent_alloc_simple_task_spec");
255                 dts_fail(api_name);
256         }
257 }
258
259 static void utc_sync_agent_framework_sync_agent_alloc_simple_task_spec_n(void)
260 {
261         char *api_name = API_NAME_SYNC_AGENT_ALLOC_SIMPLE_TASK_SPEC;
262         sync_agent_ec_task_spec_s *task_spec = NULL;
263
264         task_spec = sync_agent_alloc_simple_task_spec(NULL, NULL, NULL, NULL, 1, NULL);
265         if (task_spec == NULL) {
266                 dts_pass(api_name);
267         } else {
268                 dts_message(api_name, "sync_agent_alloc_simple_task_spec");
269                 dts_fail(api_name);
270         }
271 }