ddca29271f96785847a0c92066e74bfce412f792
[apps/native/widget/widget.git] / TC / testcase / utc_livebox.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
18 #include <tet_api.h>
19 #include <stdlib.h>
20
21 #define LOG_TAG "LIVEBOX_TC"
22
23 #include <livebox-service.h>
24 #include <livebox-errno.h>
25 #include <livebox.h>
26 #include <dlog.h>
27
28 enum {
29     POSITIVE_TC_IDX = 0x01,
30     NEGATIVE_TC_IDX,
31 };
32
33 static void startup(void)
34 {
35     /* start of TC */
36     tet_printf("\n TC start");
37 }
38
39
40 static void cleanup(void)
41 {
42     /* end of TC */
43     tet_printf("\n TC end");
44 }
45
46 void (*tet_startup)(void) = startup;
47 void (*tet_cleanup)(void) = cleanup;
48
49 #define DUMMY_ID "/opt/usr/share/live_magazine/com.samsung.dummy.png"
50 #define DUMMY_INVALID_ID "/usr/share/live_magazine/com.samsung.dummy.png"
51 #define DUMMY_PKGNAME "com.samsung.dummy"
52
53 static void utc_livebox_desc_open_n(void)
54 {
55     LOGD("");
56     struct livebox_desc *handle;
57
58     handle = livebox_desc_open(DUMMY_INVALID_ID, 0);
59     if (handle) {
60         (void)livebox_desc_close(handle);
61     }
62         dts_check_eq("livebox_desc_open", handle, NULL, "Must return NULL in case of invalid id is used"); 
63 }
64
65 static void utc_livebox_desc_open_p(void)
66 {
67     LOGD("");
68     struct livebox_desc *handle;
69
70     handle = livebox_desc_open(DUMMY_ID, 0);
71         dts_check_ne("livebox_desc_open", handle, NULL, "Must return valid handle"); 
72 }
73
74 static void utc_livebox_desc_close_n(void)
75 {
76     LOGD("");
77     int ret;
78
79     ret = livebox_desc_close(NULL);
80     dts_check_eq("livebox_desc_close", ret, LB_STATUS_ERROR_INVALID, "Must returns LB_STATUS_ERROR_INVALID");
81 }
82
83 static void utc_livebox_desc_close_p(void)
84 {
85     LOGD("");
86     struct livebox_desc *handle;
87     int ret;
88
89     handle = livebox_desc_open(DUMMY_ID, 0);
90     if (!handle) {
91         dts_check_ne("livebox_desc_close", handle, NULL, "Failed to create a handle");
92         return;
93     }
94
95     ret = livebox_desc_close(handle);
96     dts_check_eq("livebox_desc_close", ret, LB_STATUS_SUCCESS, "Must returns LB_STATUS_SUCCESS");
97 }
98
99 static void utc_livebox_desc_set_category_n(void)
100 {
101     LOGD("");
102     int ret;
103     ret = livebox_desc_set_category(NULL, NULL, NULL);
104
105     dts_check_eq("livebox_desc_set_category", ret, LB_STATUS_ERROR_INVALID, "Invalid parameter used, LB_STATUS_ERROR_INVALID should be returned");
106 }
107
108 static void utc_livebox_desc_set_category_p(void)
109 {
110     LOGD("");
111     struct livebox_desc *handle;
112     int ret;
113
114     handle = livebox_desc_open(DUMMY_ID, 0);
115     if (!handle) {
116         dts_check_ne("livebox_desc_set_category", handle, NULL, "Failed to create a handle");
117         return;
118     }
119
120     ret = livebox_desc_set_category(handle, NULL, "New Category");
121     (void)livebox_desc_close(handle);
122     dts_check_eq("livebox_desc_set_category", ret, LB_STATUS_SUCCESS, "LB_STATUS_SUCCESS should be returned\n");
123 }
124
125 static void utc_livebox_desc_set_id_n(void)
126 {
127     LOGD("");
128     struct livebox_desc *handle;
129     int ret;
130
131     handle = livebox_desc_open(DUMMY_ID, 0);
132     if (!handle) {
133         dts_check_ne("livebox_desc_set_id", handle, NULL, "Failed to create a handle");
134         return;
135     }
136     ret = livebox_desc_set_id(handle, -1, NULL);
137     (void)livebox_desc_close(handle);
138     dts_check_eq("livebox_desc_set_id", ret, LB_STATUS_ERROR_NOT_EXIST, "LB_STATUS_ERROR_NOT_EXIST should be returned\n");
139 }
140
141 static void utc_livebox_desc_set_id_p(void)
142 {
143     LOGD("");
144     struct livebox_desc *handle;
145     int ret;
146     int idx;
147
148     handle = livebox_desc_open(DUMMY_ID, 0);
149     if (!handle) {
150         dts_check_ne("livebox_desc_set_id", handle, NULL, "Failed to create a handle");
151         return;
152     }
153     idx = livebox_desc_add_block(handle, NULL, LB_DESC_TYPE_SCRIPT, "swallow,part", "/usr/apps/com.samsung.test-app/res/edje/test.edj", "test,group");
154     if (idx < 0) {
155         dts_check_ge("livebox_desc_set_id", idx, 0, "Failed to add a desc block");
156         (void)livebox_desc_close(handle);
157         return;
158     }
159
160     ret = livebox_desc_set_id(handle, idx, "new,id");
161     (void)livebox_desc_close(handle);
162     dts_check_eq("livebox_desc_set_id", ret, LB_STATUS_SUCCESS, "LB_STATUS_SUCCESS should be returned\n");
163 }
164
165 static void utc_livebox_desc_add_block_n(void)
166 {
167     LOGD("");
168     int idx;
169
170     idx = livebox_desc_add_block(NULL, NULL, LB_DESC_TYPE_SCRIPT, "swallow,part", "/usr/apps/com.samsung.test-app/res/edje/test.edj", "test,group");
171     dts_check_eq("livebox_desc_add_block", idx, LB_STATUS_ERROR_INVALID, "LB_STATUS_ERROR_INVALID should be returned\n");
172 }
173
174 static void utc_livebox_desc_add_block_p(void)
175 {
176     LOGD("");
177     struct livebox_desc *handle;
178     int idx;
179
180     handle = livebox_desc_open(DUMMY_ID, 0);
181     if (!handle) {
182         dts_check_ne("livebox_desc_add_block", handle, NULL, "Failed to create a handle");
183         return;
184     }
185
186     idx = livebox_desc_add_block(handle, NULL, LB_DESC_TYPE_SCRIPT, "swallow,part", "/usr/apps/com.samsung.test-app/res/edje/test.edj", "test,group");
187     dts_check_ge("livebox_desc_add_block", idx, 0, "idx should not be less than 0\n");
188     (void)livebox_desc_close(handle);
189 }
190
191 static void utc_livebox_desc_del_block_n(void)
192 {
193     LOGD("");
194     struct livebox_desc *handle;
195     int ret;
196
197     handle = livebox_desc_open(DUMMY_ID, 0);
198     if (!handle) {
199         dts_check_ne("livebox_desc_del_block", handle, NULL, "Failed to create a handle");
200         return;
201     }
202
203     ret = livebox_desc_del_block(handle, 0);
204     dts_check_eq("livebox_desc_del_block", ret, LB_STATUS_ERROR_NOT_EXIST, "Block is not found, LB_STATUS_ERROR_NOT_EXIST should be returned\n");
205 }
206
207 static void utc_livebox_desc_del_block_p(void)
208 {
209     LOGD("");
210     struct livebox_desc *handle;
211     int idx;
212     int ret;
213
214     handle = livebox_desc_open(DUMMY_ID, 0);
215     if (handle == NULL) {
216         dts_check_ne("livebox_desc_del_block", handle, NULL, "Failed to create desc handle");
217         return;
218     }
219     idx = livebox_desc_add_block(handle, NULL, LB_DESC_TYPE_SCRIPT, "swallow,part", "/usr/apps/com.samsung.test-app/res/edje/test.edj", "test,group");
220     if (idx < 0) {
221         dts_check_ge("livebox_desc_del_block", idx, 0, "Failed to add a desc block");
222         (void)livebox_desc_close(handle);
223         return;
224     }
225     ret = livebox_desc_del_block(handle, idx);
226     (void)livebox_desc_close(handle);
227     dts_check_eq("livebox_desc_del_block", ret, LB_STATUS_SUCCESS, "del_block should returns LB_STATUS_SUCCESS\n");
228 }
229
230 int livebox_trigger_update_monitor(const char *id, int is_pd)
231 {
232     if (!id) {
233         return LB_STATUS_ERROR_INVALID;
234     }
235
236     return LB_STATUS_SUCCESS;
237 }
238
239 static void utc_livebox_content_is_updated_n(void)
240 {
241     LOGD("");
242     int ret;
243
244     ret = livebox_content_is_updated(NULL, 0);
245     dts_check_eq("livebox_content_is_updated", ret, LB_STATUS_ERROR_INVALID, "should returns LB_STATUS_ERROR_INVALID\n");
246 }
247
248 static void utc_livebox_content_is_updated_p(void)
249 {
250     LOGD("");
251     int ret;
252     ret = livebox_content_is_updated(DUMMY_ID, 0);
253     dts_check_eq("livebox_content_is_updated", ret, LB_STATUS_SUCCESS, "should returns LB_STATUS_SUCCESS\n");
254 }
255
256 static void utc_livebox_request_close_pd_n(void)
257 {
258     LOGD("");
259     int ret;
260
261     ret = livebox_request_close_pd(DUMMY_PKGNAME, DUMMY_ID, LB_STATUS_SUCCESS);
262     dts_check_eq("livebox_request_close_pd", ret, LB_STATUS_ERROR_INVALID, "should returns LB_STATUS_ERROR_INVALID\n");
263 }
264
265 static void utc_livebox_request_close_pd_p(void)
266 {
267     LOGD("");
268     /*!
269      * \note
270      * Unable to test the positive case
271      */
272     dts_pass("livebox_request_close_pd", "pass negative test");
273 }
274
275 static void utc_livebox_request_update_n(void)
276 {
277     LOGD("");
278     int ret;
279     ret = livebox_request_update(NULL);
280     dts_check_eq("livebox_request_update", ret, LB_STATUS_ERROR_INVALID, "should returns LB_STATUS_ERROR_INVALID");
281 }
282
283 static void utc_livebox_request_update_p(void)
284 {
285     LOGD("");
286     /*!
287      * \note
288      * Unable to test the positive case
289      */
290     dts_pass("livebox_request_update", "pass negative test");
291 }
292
293 static void utc_livebox_util_nl2br_n(void)
294 {
295     LOGD("");
296     char *nl2br;
297
298     nl2br = livebox_util_nl2br(NULL);
299     dts_check_eq("livebox_util_nl2br", nl2br, NULL, "should returns NULL\n");
300 }
301
302 static void utc_livebox_util_nl2br_p(void)
303 {
304     LOGD("");
305     char *nl2br;
306     nl2br = livebox_util_nl2br("hello\nworld");
307     LOGD("[%s]", nl2br);
308     dts_check_str_eq("livebox_util_nl2br", nl2br, "hello<br>world", "should returns \"hello<br>world\"");
309     LOGD("");
310 }
311
312 static void utc_livebox_acquire_buffer_n(void)
313 {
314     LOGD("");
315     struct livebox_buffer *handle;
316
317     handle = livebox_acquire_buffer(NULL, 0, 720, 200, NULL, NULL);
318     dts_check_eq("livebox_acquire_buffer", handle, NULL, "should returns NULL\n");
319 }
320
321 static void utc_livebox_acquire_buffer_p(void)
322 {
323     LOGD("");
324     /*!
325      * \note
326      * Unable to test the positive case
327      */
328     dts_pass("livebox_acquire_buffer", "pass positive test");
329 }
330
331 static void utc_livebox_acquire_buffer_NEW_n(void)
332 {
333     LOGD("");
334     struct livebox_buffer *handle;
335
336     handle = livebox_acquire_buffer_NEW(NULL, 0, 720, 200, sizeof(int), NULL, NULL);
337     dts_check_eq("livebox_acquire_buffer_NEW", handle, NULL, "should returns NULL\n");
338 }
339
340 static void utc_livebox_acquire_buffer_NEW_p(void)
341 {
342     LOGD("");
343     /*!
344      * \note
345      * Unable to test the positive case
346      */
347     dts_pass("livebox_acquire_buffer_NEW", "pass positive test");
348 }
349
350
351 static void utc_livebox_pixmap_id_n(void)
352 {
353     LOGD("");
354     unsigned long pixmap;
355
356     pixmap = livebox_pixmap_id(NULL);
357     dts_check_eq("livebox_pixmap_id", pixmap, 0, "should returns 0\n");
358 }
359
360 static void utc_livebox_pixmap_id_p(void)
361 {
362     LOGD("");
363     /*!
364      * \note
365      * Unable to test the positive case
366      */
367     dts_pass("livebox_pixmap_id", "pass positive test");
368 }
369
370 static void utc_livebox_ref_buffer_n(void)
371 {
372     LOGD("");
373     void *ret;
374     ret = livebox_ref_buffer(NULL);
375     dts_check_eq("livebox_ref_buffer", ret, NULL, "should returns NULL\n");
376 }
377
378 static void utc_livebox_ref_buffer_p(void)
379 {
380     LOGD("");
381     /*!
382      * \note
383      * Unable to test the positive case
384      */
385     dts_pass("livebox_ref_buffer", "pass positive test");
386 }
387
388 static void utc_livebox_sync_buffer_n(void)
389 {
390     LOGD("");
391     int ret;
392     ret = livebox_sync_buffer(NULL);
393     dts_check_eq("livebox_sync_buffer", ret, LB_STATUS_ERROR_INVALID, "should returns LB_STATUS_ERROR_INVALID\n");
394 }
395
396 static void utc_livebox_sync_buffer_p(void)
397 {
398     LOGD("");
399     /*!
400      * \note
401      * Unable to test the positive case
402      */
403     dts_pass("livebox_sync_buffer", "pass positive test");
404 }
405
406 static void utc_livebox_support_hw_buffer_n(void)
407 {
408     LOGD("");
409     int ret;
410     ret = livebox_support_hw_buffer(NULL);
411     dts_check_eq("livebox_support_hw_buffer", ret, LB_STATUS_ERROR_INVALID, "should returns LB_STATUS_ERROR_INVALID\n");
412 }
413
414 static void utc_livebox_support_hw_buffer_p(void)
415 {
416     LOGD("");
417     /*!
418      * \note
419      * Unable to test the positive case
420      */
421     dts_pass("livebox_support_hw_buffer", "pass positive test");
422 }
423
424 static void utc_livebox_create_hw_buffer_n(void)
425 {
426     LOGD("");
427     int ret;
428     ret = livebox_create_hw_buffer(NULL);
429     dts_check_eq("livebox_create_hw_buffer", ret, LB_STATUS_ERROR_INVALID, "should returns LB_STATUS_ERROR_INVALID\n");
430 }
431
432 static void utc_livebox_create_hw_buffer_p(void)
433 {
434     LOGD("");
435     /*!
436      * \note
437      * Unable to test the positive case
438      */
439     dts_pass("livebox_create_hw_buffer", "pass positive test");
440 }
441
442 static void utc_livebox_destroy_hw_buffer_n(void)
443 {
444     LOGD("");
445     int ret;
446     ret = livebox_destroy_hw_buffer(NULL);
447     dts_check_eq("livebox_destroy_hw_buffer", ret, LB_STATUS_ERROR_INVALID, "should returns LB_STATUS_ERROR_INVALID\n");
448 }
449
450 static void utc_livebox_destroy_hw_buffer_p(void)
451 {
452     LOGD("");
453     /*!
454      * \note
455      * Unable to test the positive case
456      */
457     dts_pass("livebox_destroy_hw_buffer", "pass positive test");
458 }
459
460 static void utc_livebox_buffer_hw_buffer_n(void)
461 {
462     LOGD("");
463     void *ret;
464     ret = livebox_buffer_hw_buffer(NULL);
465     dts_check_eq("livebox_buffer_hw_buffer", ret, NULL, "should returns LB_STATUS_ERROR_INVALID");
466 }
467
468 static void utc_livebox_buffer_hw_buffer_p(void)
469 {
470     LOGD("");
471     /*!
472      * \note
473      * Unable to test the positive case
474      */
475     dts_pass("livebox_buffer_hw_buffer", "pass positive test");
476 }
477
478 static void utc_livebox_buffer_pre_render_n(void)
479 {
480     LOGD("");
481     int ret;
482     ret = livebox_buffer_pre_render(NULL);
483     dts_check_eq("livebox_buffer_pre_render", ret, LB_STATUS_ERROR_INVALID, "should returns LB_STATUS_ERROR_INVALID\n");
484 }
485
486 static void utc_livebox_buffer_pre_render_p(void)
487 {
488     LOGD("");
489     /*!
490      * \note
491      * Unable to test the positive case
492      */
493     dts_pass("livebox_buffer_pre_render", "pass positive test");
494 }
495
496 static void utc_livebox_buffer_post_render_n(void)
497 {
498     LOGD("");
499     int ret;
500     ret = livebox_buffer_post_render(NULL);
501     dts_check_eq("livebox_buffer_post_render", ret, LB_STATUS_ERROR_INVALID, "should returns LB_STATUS_ERROR_INVALID\n");
502 }
503
504 static void utc_livebox_buffer_post_render_p(void)
505 {
506     LOGD("");
507     /*!
508      * \note
509      * Unable to test the positive case
510      */
511     dts_pass("livebox_buffer_post_render", "pass positive test");
512 }
513
514 static void utc_livebox_get_evas_object_n(void)
515 {
516     LOGD("");
517     Evas_Object *obj;
518
519     obj = livebox_get_evas_object(NULL, 1);
520     dts_check_eq("livebox_get_evas_object", obj, NULL, "should returns NULL\n");
521 }
522
523 static void utc_livebox_get_evas_object_p(void)
524 {
525     LOGD("");
526     /*!
527      * \note
528      * Unable to test the positive case
529      */
530     dts_pass("livebox_get_evas_object", "pass positve test");
531 }
532
533 struct tet_testlist tet_testlist[] = {
534     { utc_livebox_desc_open_n, NEGATIVE_TC_IDX },                        
535     { utc_livebox_desc_open_p, POSITIVE_TC_IDX },
536     { utc_livebox_desc_close_n, NEGATIVE_TC_IDX },
537     { utc_livebox_desc_close_p, POSITIVE_TC_IDX },    
538     { utc_livebox_desc_set_category_n, NEGATIVE_TC_IDX },    
539     { utc_livebox_desc_set_category_p, POSITIVE_TC_IDX },
540     { utc_livebox_desc_set_id_n, NEGATIVE_TC_IDX },
541     { utc_livebox_desc_set_id_p, POSITIVE_TC_IDX },
542     { utc_livebox_desc_add_block_n, NEGATIVE_TC_IDX },    
543     { utc_livebox_desc_add_block_p, POSITIVE_TC_IDX },
544     { utc_livebox_desc_del_block_n, NEGATIVE_TC_IDX },
545     { utc_livebox_desc_del_block_p, POSITIVE_TC_IDX },
546     { utc_livebox_content_is_updated_n, NEGATIVE_TC_IDX },
547     { utc_livebox_content_is_updated_p, POSITIVE_TC_IDX },
548     { utc_livebox_request_close_pd_n, NEGATIVE_TC_IDX },
549     { utc_livebox_request_close_pd_p, POSITIVE_TC_IDX },
550     { utc_livebox_request_update_n, NEGATIVE_TC_IDX },
551     { utc_livebox_request_update_p, POSITIVE_TC_IDX },
552     { utc_livebox_util_nl2br_n, NEGATIVE_TC_IDX },
553     { utc_livebox_util_nl2br_p, POSITIVE_TC_IDX },
554
555     { utc_livebox_acquire_buffer_n, NEGATIVE_TC_IDX },
556     { utc_livebox_acquire_buffer_p, POSITIVE_TC_IDX },
557     { utc_livebox_acquire_buffer_NEW_n, NEGATIVE_TC_IDX },
558     { utc_livebox_acquire_buffer_NEW_p, POSITIVE_TC_IDX },
559
560     { utc_livebox_pixmap_id_n, NEGATIVE_TC_IDX },
561     { utc_livebox_pixmap_id_p, POSITIVE_TC_IDX },
562
563     { utc_livebox_ref_buffer_n, NEGATIVE_TC_IDX },
564     { utc_livebox_ref_buffer_p, POSITIVE_TC_IDX },
565
566     { utc_livebox_sync_buffer_n, NEGATIVE_TC_IDX },
567     { utc_livebox_sync_buffer_p, POSITIVE_TC_IDX },
568
569     { utc_livebox_support_hw_buffer_n, NEGATIVE_TC_IDX },
570     { utc_livebox_support_hw_buffer_p, POSITIVE_TC_IDX },
571     { utc_livebox_create_hw_buffer_n, NEGATIVE_TC_IDX },
572     { utc_livebox_create_hw_buffer_p, POSITIVE_TC_IDX },
573     { utc_livebox_destroy_hw_buffer_n, NEGATIVE_TC_IDX },
574     { utc_livebox_destroy_hw_buffer_p, POSITIVE_TC_IDX },
575     { utc_livebox_buffer_hw_buffer_n, NEGATIVE_TC_IDX },
576     { utc_livebox_buffer_hw_buffer_p, POSITIVE_TC_IDX },
577     { utc_livebox_buffer_pre_render_n, NEGATIVE_TC_IDX },
578     { utc_livebox_buffer_pre_render_p, POSITIVE_TC_IDX },
579     { utc_livebox_buffer_post_render_n, NEGATIVE_TC_IDX },
580     { utc_livebox_buffer_post_render_p, POSITIVE_TC_IDX },
581     { utc_livebox_get_evas_object_n, NEGATIVE_TC_IDX },
582     { utc_livebox_get_evas_object_p, POSITIVE_TC_IDX },
583
584     { NULL, 0 },
585 };
586