Initialize Tizen 2.3
[framework/system/deviced.git] / test / testcase / utc_system_deviced_deviced_managed.c
1 /*
2  *
3  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4  * PROPRIETARY/CONFIDENTIAL
5  *
6  * This software is the confidential and proprietary information of SAMSUNG
7  * ELECTRONICS ("Confidential Information"). You agree and acknowledge that
8  * this software is owned by Samsung and you shall not disclose such
9  * Confidential Information and shall use it only in accordance with the terms
10  * of the license agreement you entered into with SAMSUNG ELECTRONICS. SAMSUNG
11  * make no representations or warranties about the suitability of the software,
12  * either express or implied, including but not limited to the implied
13  * warranties of merchantability, fitness for a particular purpose, or
14  * non-infringement. SAMSUNG shall not be liable for any damages suffered by
15  * licensee arising out of or related to this software.
16  *
17  */
18 #include <tet_api.h>
19 #include <stdbool.h>
20 #include <dd-deviced-managed.h>
21
22 #define API_NAME_DEVICED_GET_PID "deviced_get_pid"
23 #define API_NAME_DEVICED_SET_DATETIME "deviced_set_datetime"
24 #define API_NAME_DEVICED_REQUEST_MOUNT_MMC "deviced_request_mount_mmc"
25 #define API_NAME_DEVICED_REQUEST_UNMOUNT_MMC "deviced_request_unmount_mmc"
26 #define API_NAME_DEVICED_REQUEST_FORMAT_MMC "deviced_request_format_mmc"
27 #define API_NAME_DEVICED_FORMAT_MMC "deviced_format_mmc"
28
29 static void startup(void);
30 static void cleanup(void);
31
32 void (*tet_startup)(void) = startup;
33 void (*tet_cleanup)(void) = cleanup;
34
35
36 static void utc_system_deviced_deviced_get_pid_p(void);
37 static void utc_system_deviced_deviced_get_pid_n(void);
38 static void utc_system_deviced_deviced_set_datetime_n(void);
39 static void utc_system_deviced_deviced_set_datetime_p(void);
40 static void utc_system_deviced_deviced_request_mount_mmc_p_1(void);
41 static void utc_system_deviced_deviced_request_mount_mmc_p_2(void);
42 static void utc_system_deviced_deviced_request_mount_mmc_p_3(void);
43 static void utc_system_deviced_deviced_request_unmount_mmc_p_1(void);
44 static void utc_system_deviced_deviced_request_unmount_mmc_p_2(void);
45 static void utc_system_deviced_deviced_request_unmount_mmc_p_3(void);
46 static void utc_system_deviced_deviced_request_unmount_mmc_p_4(void);
47 static void utc_system_deviced_deviced_request_unmount_mmc_n(void);
48 static void utc_system_deviced_deviced_request_format_mmc_p_1(void);
49 static void utc_system_deviced_deviced_request_format_mmc_p_2(void);
50 static void utc_system_deviced_deviced_request_format_mmc_p_3(void);
51 static void utc_system_deviced_deviced_format_mmc_p_1(void);
52 static void utc_system_deviced_deviced_format_mmc_p_2(void);
53 static void utc_system_deviced_deviced_format_mmc_p_3(void);
54 static void utc_system_deviced_deviced_format_mmc_p_4(void);
55 static void utc_system_deviced_deviced_format_mmc_n(void);
56
57 enum {
58         POSITIVE_TC_IDX = 0x01,
59         NEGATIVE_TC_IDX,
60 };
61
62 struct tet_testlist tet_testlist[] = {
63         /* The following TCs are for root application */
64 //      { utc_system_deviced_deviced_get_pid_p, POSITIVE_TC_IDX },
65 //      { utc_system_deviced_deviced_get_pid_n, NEGATIVE_TC_IDX },
66         { utc_system_deviced_deviced_set_datetime_n, NEGATIVE_TC_IDX },
67         { utc_system_deviced_deviced_set_datetime_p, POSITIVE_TC_IDX },
68         { utc_system_deviced_deviced_request_mount_mmc_p_1, POSITIVE_TC_IDX },
69         { utc_system_deviced_deviced_request_mount_mmc_p_2, POSITIVE_TC_IDX },
70         { utc_system_deviced_deviced_request_mount_mmc_p_3, POSITIVE_TC_IDX },
71         { utc_system_deviced_deviced_request_unmount_mmc_p_1, POSITIVE_TC_IDX },
72         { utc_system_deviced_deviced_request_unmount_mmc_p_2, POSITIVE_TC_IDX },
73         { utc_system_deviced_deviced_request_unmount_mmc_p_3, POSITIVE_TC_IDX },
74         { utc_system_deviced_deviced_request_unmount_mmc_p_4, POSITIVE_TC_IDX },
75         { utc_system_deviced_deviced_request_unmount_mmc_n, NEGATIVE_TC_IDX },
76         { utc_system_deviced_deviced_request_format_mmc_p_1, POSITIVE_TC_IDX },
77         { utc_system_deviced_deviced_request_format_mmc_p_2, POSITIVE_TC_IDX },
78         { utc_system_deviced_deviced_request_format_mmc_p_3, POSITIVE_TC_IDX },
79         { utc_system_deviced_deviced_format_mmc_p_1, POSITIVE_TC_IDX },
80         { utc_system_deviced_deviced_format_mmc_p_2, POSITIVE_TC_IDX },
81         { utc_system_deviced_deviced_format_mmc_p_3, POSITIVE_TC_IDX },
82         { utc_system_deviced_deviced_format_mmc_p_4, POSITIVE_TC_IDX },
83         { utc_system_deviced_deviced_format_mmc_n, NEGATIVE_TC_IDX },
84         { NULL, 0 },
85 };
86
87 static void startup(void)
88 {
89 }
90
91 static void cleanup(void)
92 {
93 }
94
95 /**
96  * @brief Positive test case of deviced_get_pid()
97  */
98 static void utc_system_deviced_deviced_get_pid_p(void)
99 {
100         int ret;
101
102         ret = deviced_get_pid("/usb/bin/deviced");
103         dts_check_ge(API_NAME_DEVICED_GET_PID, ret, 0);
104 }
105
106 /**
107  * @brief Negative test case of deviced_get_pid()
108  */
109 static void utc_system_deviced_deviced_get_pid_n(void)
110 {
111         int ret;
112
113         ret = deviced_get_pid(NULL);
114         dts_check_lt(API_NAME_DEVICED_GET_PID, ret, 0);
115 }
116
117 /**
118  * @brief Negative test case of deviced_set_datetime()
119  */
120 static void utc_system_deviced_deviced_set_datetime_n(void)
121 {
122         int ret;
123
124         ret = deviced_set_datetime(-1);
125         dts_check_lt(API_NAME_DEVICED_SET_DATETIME, ret, 0);
126 }
127
128 /**
129  * @brief Positive test case of deviced_set_datetime()
130  */
131 static void utc_system_deviced_deviced_set_datetime_p(void)
132 {
133         int ret;
134         time_t now;
135
136         localtime(&now);
137
138         ret = deviced_set_datetime(now);
139         dts_check_ge(API_NAME_DEVICED_SET_DATETIME, ret, 0);
140 }
141
142 static void mount_cb(int result, void *data)
143 {
144         dts_message(API_NAME_DEVICED_REQUEST_MOUNT_MMC,
145                         "mount callback result : %d", result);
146 }
147
148 /**
149  * @brief Positive test case of deviced_request_mount_mmc()
150  */
151 static void utc_system_deviced_deviced_request_mount_mmc_p_1(void)
152 {
153         int ret;
154         struct mmc_contents data = {.mmc_cb = mount_cb, .user_data = NULL};
155
156         dts_message(API_NAME_DEVICED_REQUEST_MOUNT_MMC,
157                         "This testcase is only valid when mmc is inserted");
158
159         ret = deviced_request_mount_mmc(&data);
160         dts_check_eq(API_NAME_DEVICED_REQUEST_MOUNT_MMC, ret, 0);
161
162         sleep(1);
163 }
164
165 /**
166  * @brief Positive test case of deviced_request_mount_mmc()
167  */
168 static void utc_system_deviced_deviced_request_mount_mmc_p_2(void)
169 {
170         int ret;
171         struct mmc_contents data = {.mmc_cb = NULL, .user_data = NULL};
172
173         dts_message(API_NAME_DEVICED_REQUEST_MOUNT_MMC,
174                         "This testcase is only valid when mmc is inserted");
175
176         ret = deviced_request_mount_mmc(&data);
177         dts_check_eq(API_NAME_DEVICED_REQUEST_MOUNT_MMC, ret, 0);
178
179         sleep(1);
180 }
181
182 /**
183  * @brief Positive test case of deviced_request_mount_mmc()
184  */
185 static void utc_system_deviced_deviced_request_mount_mmc_p_3(void)
186 {
187         int ret;
188
189         dts_message(API_NAME_DEVICED_REQUEST_MOUNT_MMC,
190                         "This testcase is only valid when mmc is inserted");
191
192         ret = deviced_request_mount_mmc(NULL);
193         dts_check_eq(API_NAME_DEVICED_REQUEST_MOUNT_MMC, ret, 0);
194
195         sleep(1);
196 }
197
198 static void unmount_cb(int result, void *data)
199 {
200         dts_message(API_NAME_DEVICED_REQUEST_UNMOUNT_MMC,
201                         "unmount callback result : %d", result);
202 }
203
204 /**
205  * @brief Positive test case of deviced_request_unmount_mmc()
206  */
207 static void utc_system_deviced_deviced_request_unmount_mmc_p_1(void)
208 {
209         int ret;
210         struct mmc_contents data = {.mmc_cb = unmount_cb, .user_data = NULL};
211
212         dts_message(API_NAME_DEVICED_REQUEST_UNMOUNT_MMC,
213                         "This testcase is only valid when mmc is inserted");
214
215         ret = deviced_request_unmount_mmc(&data, 0);
216         dts_check_eq(API_NAME_DEVICED_REQUEST_UNMOUNT_MMC, ret, 0);
217
218         sleep(1);
219 }
220
221 /**
222  * @brief Positive test case of deviced_request_unmount_mmc()
223  */
224 static void utc_system_deviced_deviced_request_unmount_mmc_p_2(void)
225 {
226         int ret;
227         struct mmc_contents data = {.mmc_cb = unmount_cb, .user_data = NULL};
228
229         dts_message(API_NAME_DEVICED_REQUEST_UNMOUNT_MMC,
230                         "This testcase is only valid when mmc is inserted");
231
232         ret = deviced_request_unmount_mmc(&data, 1);
233         dts_check_eq(API_NAME_DEVICED_REQUEST_UNMOUNT_MMC, ret, 0);
234
235         sleep(1);
236 }
237
238 /**
239  * @brief Positive test case of deviced_request_unmount_mmc()
240  */
241 static void utc_system_deviced_deviced_request_unmount_mmc_p_3(void)
242 {
243         int ret;
244         struct mmc_contents data = {.mmc_cb = NULL, .user_data = NULL};
245
246         dts_message(API_NAME_DEVICED_REQUEST_UNMOUNT_MMC,
247                         "This testcase is only valid when mmc is inserted");
248
249         ret = deviced_request_unmount_mmc(&data, 1);
250         dts_check_eq(API_NAME_DEVICED_REQUEST_UNMOUNT_MMC, ret, 0);
251
252         sleep(1);
253 }
254
255 /**
256  * @brief Positive test case of deviced_request_unmount_mmc()
257  */
258 static void utc_system_deviced_deviced_request_unmount_mmc_p_4(void)
259 {
260         int ret;
261
262         dts_message(API_NAME_DEVICED_REQUEST_UNMOUNT_MMC,
263                         "This testcase is only valid when mmc is inserted");
264
265         ret = deviced_request_unmount_mmc(NULL, 0);
266         dts_check_eq(API_NAME_DEVICED_REQUEST_UNMOUNT_MMC, ret, 0);
267
268         sleep(1);
269 }
270
271 /**
272  * @brief Negative test case of deviced_request_unmount_mmc()
273  */
274 static void utc_system_deviced_deviced_request_unmount_mmc_n(void)
275 {
276         int ret;
277         struct mmc_contents data = {.mmc_cb = unmount_cb, .user_data = NULL};
278
279         dts_message(API_NAME_DEVICED_REQUEST_UNMOUNT_MMC,
280                         "This testcase is only valid when mmc is inserted");
281
282         ret = deviced_request_unmount_mmc(&data, -1);
283         dts_check_ne(API_NAME_DEVICED_REQUEST_UNMOUNT_MMC, ret, 0);
284 }
285
286 static void format_cb(int result, void *data)
287 {
288         dts_message(API_NAME_DEVICED_REQUEST_FORMAT_MMC,
289                         "format callback result : %d", result);
290 }
291
292 /**
293  * @brief Positive test case of deviced_request_format_mmc()
294  */
295 static void utc_system_deviced_deviced_request_format_mmc_p_1(void)
296 {
297         int ret;
298         struct mmc_contents data = {.mmc_cb = format_cb, .user_data = NULL};
299
300         dts_message(API_NAME_DEVICED_REQUEST_FORMAT_MMC,
301                         "This testcase is only valid when mmc is inserted");
302
303         ret = deviced_request_format_mmc(&data);
304         dts_check_eq(API_NAME_DEVICED_REQUEST_FORMAT_MMC, ret, 0);
305
306         sleep(1);
307 }
308
309 /**
310  * @brief Positive test case of deviced_request_format_mmc()
311  */
312 static void utc_system_deviced_deviced_request_format_mmc_p_2(void)
313 {
314         int ret;
315         struct mmc_contents data = {.mmc_cb = NULL, .user_data = NULL};
316
317         dts_message(API_NAME_DEVICED_REQUEST_FORMAT_MMC,
318                         "This testcase is only valid when mmc is inserted");
319
320         ret = deviced_request_format_mmc(&data);
321         dts_check_eq(API_NAME_DEVICED_REQUEST_FORMAT_MMC, ret, 0);
322
323         sleep(1);
324 }
325
326 /**
327  * @brief Positive test case of deviced_request_format_mmc()
328  */
329 static void utc_system_deviced_deviced_request_format_mmc_p_3(void)
330 {
331         int ret;
332
333         dts_message(API_NAME_DEVICED_REQUEST_FORMAT_MMC,
334                         "This testcase is only valid when mmc is inserted");
335
336         ret = deviced_request_format_mmc(NULL);
337         dts_check_eq(API_NAME_DEVICED_REQUEST_FORMAT_MMC, ret, 0);
338
339         sleep(1);
340 }
341
342 /**
343  * @brief Positive test case of deviced_format_mmc()
344  */
345 static void utc_system_deviced_deviced_format_mmc_p_1(void)
346 {
347         int ret;
348         struct mmc_contents data = {.mmc_cb = format_cb, .user_data = NULL};
349
350         dts_message(API_NAME_DEVICED_REQUEST_FORMAT_MMC,
351                         "This testcase is only valid when mmc is inserted");
352
353         ret = deviced_format_mmc(&data, 0);
354         dts_check_eq(API_NAME_DEVICED_FORMAT_MMC, ret, 0);
355
356         sleep(1);
357 }
358
359 /**
360  * @brief Positive test case of deviced_format_mmc()
361  */
362 static void utc_system_deviced_deviced_format_mmc_p_2(void)
363 {
364         int ret;
365         struct mmc_contents data = {.mmc_cb = format_cb, .user_data = NULL};
366
367         dts_message(API_NAME_DEVICED_REQUEST_FORMAT_MMC,
368                         "This testcase is only valid when mmc is inserted");
369
370         ret = deviced_format_mmc(&data, 1);
371         dts_check_eq(API_NAME_DEVICED_FORMAT_MMC, ret, 0);
372
373         sleep(1);
374 }
375
376 /**
377  * @brief Positive test case of deviced_format_mmc()
378  */
379 static void utc_system_deviced_deviced_format_mmc_p_3(void)
380 {
381         int ret;
382         struct mmc_contents data = {.mmc_cb = NULL, .user_data = NULL};
383
384         dts_message(API_NAME_DEVICED_REQUEST_FORMAT_MMC,
385                         "This testcase is only valid when mmc is inserted");
386
387         ret = deviced_format_mmc(&data, 1);
388         dts_check_eq(API_NAME_DEVICED_FORMAT_MMC, ret, 0);
389
390         sleep(1);
391 }
392
393 /**
394  * @brief Positive test case of deviced_format_mmc()
395  */
396 static void utc_system_deviced_deviced_format_mmc_p_4(void)
397 {
398         int ret;
399
400         dts_message(API_NAME_DEVICED_REQUEST_FORMAT_MMC,
401                         "This testcase is only valid when mmc is inserted");
402
403         ret = deviced_format_mmc(NULL, 0);
404         dts_check_eq(API_NAME_DEVICED_FORMAT_MMC, ret, 0);
405
406         sleep(1);
407 }
408
409 /**
410  * @brief Negative test case of deviced_format_mmc()
411  */
412 static void utc_system_deviced_deviced_format_mmc_n(void)
413 {
414         int ret;
415         struct mmc_contents data = {.mmc_cb = format_cb, .user_data = NULL};
416
417         dts_message(API_NAME_DEVICED_REQUEST_FORMAT_MMC,
418                         "This testcase is only valid when mmc is inserted");
419
420         ret = deviced_format_mmc(&data, -1);
421         dts_check_ne(API_NAME_DEVICED_FORMAT_MMC, ret, 0);
422 }