utest: rename the ut to the utests
[platform/core/uifw/libtdm.git] / utests / src / ut_tdm_helper.cpp
1 /**************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
4  *
5  * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sub license, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice (including the
16  * next paragraph) shall be included in all copies or substantial portions
17  * of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
23  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  *
27 **************************************************************************/
28
29 #include "gtest/gtest.h"
30 #include <png.h>
31
32 /*------ stubs -----------------*/
33 #include "tbm_stubs.h"
34 #include "stub_pthread.h"
35 #include "stub_stdlib.h"
36 #include "stub_unistd.h"
37 #include "stub_fcntl.h"
38 #include "stub_dlfcn.h"
39 #include "stub_stdio.h"
40 #include "tdm_event_loop_stubs.h"
41
42 #define png_write_info(p1, p2)
43 #define png_write_image(p1, p2)
44 #define png_write_end(p1, p2)
45 /*------ stubs ----------------*/
46
47 #pragma GCC optimize(0)
48
49 extern "C"  int
50 tbm_drm_helper_get_master_fd(void)
51 {
52         return 20;
53 }
54
55 #include "tdm_helper.c"
56
57 static void _init_test()
58 {
59         stub_stdio_init();
60         stub_fcntl_init();
61         stub_pthread_init();
62         stub_unistd_init();
63         stub_tbm_init();
64         stub_stdlib_init();
65 }
66
67 /* UNIT TESTS */
68
69 /* tdm_helper_get_fd() */
70
71 TEST(tdm_helper_get_fd, work_flow_success_5)
72 {
73         const char *env = "env";
74         int fd;
75
76         _init_test();
77
78         stub_getenv_name = env;
79         stub_getenv_return_value = "getenv";
80
81         fd = tdm_helper_get_fd(env);
82
83         ASSERT_EQ(fd, 5);
84 }
85
86 TEST(tdm_helper_get_fd, work_flow_success_4)
87 {
88         const char *env = "env";
89         int expected_fd = -1;
90         int fd;
91
92         _init_test();
93
94         stub_dub_error = 1;
95
96         stub_getenv_name = env;
97         stub_getenv_return_value = "getenv";
98
99         fd = tdm_helper_get_fd(env);
100
101         ASSERT_EQ(fd, expected_fd);
102 }
103
104 TEST(tdm_helper_get_fd, work_flow_success_3)
105 {
106         const char *env = "env";
107         int fd;
108         int expected_fd = -1;
109
110         _init_test();
111
112         FCNTL_ERROR = 1;
113
114         stub_getenv_name = env;
115         stub_getenv_return_value = "getenv";
116
117         fd = tdm_helper_get_fd(env);
118
119         ASSERT_EQ(fd, expected_fd);
120 }
121
122 TEST(tdm_helper_get_fd, work_flow_success_2)
123 {
124         const char *env = "env";
125         int expected_fd = -1;
126         int fd;
127
128         _init_test();
129
130         SSCANF_ERROR = 1;
131
132         stub_getenv_name = env;
133         stub_getenv_return_value = "getenv";
134
135         fd = tdm_helper_get_fd(env);
136
137         ASSERT_EQ(fd, expected_fd);
138 }
139
140 TEST(tdm_helper_get_fd, work_flow_success_1)
141 {
142         const char *env = "env";
143         int fd;
144         int expected_fd = -1;
145
146         _init_test();
147
148         GETENV_ERROR = 1;
149
150         fd = tdm_helper_get_fd(env);
151
152         ASSERT_EQ(fd, expected_fd);
153 }
154
155 /* tdm_helper_set_fd */
156 TEST(tdm_helper_set_fd, work_flow_success_1)
157 {
158         _init_test();
159         tdm_helper_set_fd("TEST_ENV", 7);
160
161         ASSERT_STREQ(stub_getenv_name, "TEST_ENV");
162 }
163
164 TEST(tdm_helper_set_fd, work_flow_error_1__setenv_error)
165 {
166         _init_test();
167         SETENV_ERROR = 1;
168
169         tdm_helper_set_fd("TEST_ENV", 7);
170
171         ASSERT_EQ(stub_getenv_name, 0);
172         ASSERT_EQ(stub_getenv_return_value, 0);
173 }
174
175 /* tdm_helper_dump_start */
176 TEST(tdm_helper_dump_start, work_flow_success_1)
177 {
178         _init_test();
179         int count = 0;
180         tdm_dump_enable = 0;
181         tdm_helper_dump_start("test_str1", &count);
182         ASSERT_EQ(tdm_dump_enable, 1);
183 }
184
185 TEST(tdm_helper_dump_start, work_flow_error_1__NULL)
186 {
187         _init_test();
188         int count = 0;
189         tdm_dump_enable = 0;
190         tdm_helper_dump_start("test_str1", NULL);
191         ASSERT_EQ(tdm_dump_enable, 0);
192         tdm_helper_dump_start(NULL, &count);
193         ASSERT_EQ(tdm_dump_enable, 0);
194 }
195
196 /* tdm_helper_dump_start */
197 TEST(tdm_helper_dump_stop, work_flow_success_1)
198 {
199         _init_test();
200         tdm_dump_enable = 0;
201         tdm_helper_dump_stop();
202         ASSERT_EQ(tdm_dump_enable, 0);
203 }
204
205 tdm_error stub_output_get_mode(tdm_output *output, const tdm_output_mode **mode)
206 {
207         static tdm_output_mode cmode;
208         *mode = &cmode;
209         return TDM_ERROR_NONE;
210 }
211
212 tdm_error stub_output_get_property(tdm_output *output, unsigned int id, tdm_value *value)
213 {
214         (tdm_output *)output;
215         (unsigned int)id;
216         value->s32 = 1;
217         return TDM_ERROR_NONE;
218 }
219
220 tdm_error stub_layer_get_property(tdm_layer *layer, unsigned int id, tdm_value *value)
221 {
222         (tdm_layer *)layer;
223         (unsigned int)id;
224         value->s32 = 1;
225         return TDM_ERROR_NONE;
226 }
227
228 tdm_error stub_layer_get_info(tdm_layer *layer, tdm_info_layer *info)
229 {
230         (tdm_layer *)layer;
231         (tdm_info_layer *)info;
232         return TDM_ERROR_NONE;
233 }
234
235
236 /* tdm_helper_get_display_information */
237 TEST(tdm_helper_get_display_information, work_flow_success_1)
238 {
239         tdm_private_display disp;
240         tdm_backend_module module;
241         tdm_private_output output;
242         tdm_private_layer layer;
243         tdm_private_pp pp;
244         tdm_private_capture capture;
245         tdm_output_mode output_mode;
246         tdm_prop prop;
247         tdm_info_layer info;
248         tdm_private_display *private_display = &disp;
249         tbm_format formats[2] = {TBM_FORMAT_ABGR8888, 0};
250
251         memset(&disp, 0, sizeof(disp));
252         memset(&module, 0, sizeof(module));
253         memset(&output, 0, sizeof(output));
254         memset(&layer, 0, sizeof(layer));
255         memset(&pp, 0, sizeof(pp));
256         memset(&capture, 0, sizeof(capture));
257         memset(&output_mode, 0, sizeof(output_mode));
258         memset(&prop, 0, sizeof(prop));
259         memset(&info, 0, sizeof(info));
260
261         int  len = 1024;
262         char rep[len];
263
264         _init_test();
265
266         //init disp
267         private_display->capabilities =  TDM_DISPLAY_CAPABILITY_PP | TDM_DISPLAY_CAPABILITY_CAPTURE;
268         LIST_INITHEAD(&private_display->output_list);
269         LIST_INITHEAD(&private_display->pp_list);
270         LIST_INITHEAD(&private_display->capture_list);
271
272         //init module
273         private_display->module_data = &module;
274         module.abi_version = 0x00010001;
275         module.name = "test";
276         module.vendor = "test";
277
278         //init output
279         LIST_ADDTAIL(&output.link, &private_display->output_list);
280         LIST_INITHEAD(&output.capture_list);
281         LIST_INITHEAD(&output.layer_list);
282         output.caps.mode_count = 1;
283         output.caps.modes = &output_mode;
284         output.caps.prop_count = 1;
285         output.caps.props = &prop;
286         memset(&output_mode, 0, sizeof(output_mode));
287         private_display->func_output.output_get_mode = stub_output_get_mode;
288         private_display->func_output.output_get_property = stub_output_get_property;
289
290         //init layer
291         LIST_ADDTAIL(&layer.link, &output.layer_list);
292         layer.usable = 0;
293         layer.caps.format_count = 2;
294         layer.caps.formats = formats;
295         layer.caps.prop_count = 1;
296         layer.caps.props = &prop;
297         private_display->func_layer.layer_get_info = stub_layer_get_info;
298         private_display->func_layer.layer_get_property = stub_layer_get_property;
299
300         //init pp
301         LIST_ADDTAIL(&pp.link, &private_display->pp_list);
302         private_display->caps_pp.format_count = 2;
303         private_display->caps_pp.formats = formats;
304
305         //init capture
306         LIST_ADDTAIL(&capture.link, &private_display->capture_list);
307         private_display->caps_capture.format_count = 2;
308         private_display->caps_capture.formats = formats;
309
310         tdm_helper_get_display_information(private_display, rep, &len);
311 }
312
313 static int stub_tdm_helper_capture_handler_is_called = 0;
314 static void stub_tdm_helper_capture_handler(tbm_surface_h buffer, void *user_data)
315 {
316         stub_tdm_helper_capture_handler_is_called = 1;
317 }
318
319 /* tdm_helper_capture_output */
320 TEST(tdm_helper_capture_output, work_flow_success_1)
321 {
322         tdm_error error;
323         tdm_private_display display;
324         tdm_private_output output;
325         tdm_private_layer layer;
326         int src_mem[100][100];
327         int dst_mem[100][100];
328         struct _tbm_surface src_surface;
329         struct _tbm_surface dst_surface;
330         memset(&output, 0, sizeof(output));
331         memset(&layer, 0, sizeof(layer));
332
333         src_surface.info.format = TBM_FORMAT_ARGB8888;
334         src_surface.info.width = 100;
335         src_surface.info.height = 100;
336         src_surface.info.num_planes = 1;
337         src_surface.info.planes[0].ptr = (unsigned char*)src_mem;
338         src_surface.info.planes[0].stride = src_surface.info.width * 4;
339
340         dst_surface.info.format = TBM_FORMAT_XRGB8888;
341         dst_surface.info.width = 100;
342         dst_surface.info.height = 100;
343         dst_surface.info.num_planes = 1;
344         dst_surface.info.planes[0].ptr = (unsigned char*)dst_mem;
345         dst_surface.info.planes[0].stride = dst_surface.info.width * 4;
346
347         _init_test();
348
349         //init output
350         LIST_INITHEAD(&output.layer_list);
351         LIST_ADDTAIL(&layer.link, &output.layer_list);
352         output.private_display = &display;
353 //      layer.showing_buffer = (tbm_surface_h)&src_surface;
354         layer.private_output = &output;
355         layer.private_display = &display;
356
357
358         error = tdm_helper_capture_output(&output, (tbm_surface_h)&dst_surface, 0, 0, 10, 10, stub_tdm_helper_capture_handler, &layer);
359
360         ASSERT_EQ(TDM_ERROR_NONE, error);
361         ASSERT_EQ(1, stub_tdm_helper_capture_handler_is_called);
362 }
363
364 TEST(tdm_helper_capture_output, work_flow_error_1___no_layer)
365 {
366         tdm_error error;
367         tdm_private_display display;
368         tdm_private_output output;
369         tdm_private_layer layer;
370         int src_mem[100][100];
371         int dst_mem[100][100];
372         struct _tbm_surface src_surface;
373         struct _tbm_surface dst_surface;
374         memset(&output, 0, sizeof(output));
375         memset(&layer, 0, sizeof(layer));
376
377         src_surface.info.format = TBM_FORMAT_ARGB8888;
378         src_surface.info.width = 100;
379         src_surface.info.height = 100;
380         src_surface.info.num_planes = 1;
381         src_surface.info.planes[0].ptr = (unsigned char*)src_mem;
382         src_surface.info.planes[0].stride = src_surface.info.width * 4;
383
384         dst_surface.info.format = TBM_FORMAT_XRGB8888;
385         dst_surface.info.width = 100;
386         dst_surface.info.height = 100;
387         dst_surface.info.num_planes = 1;
388         dst_surface.info.planes[0].ptr = (unsigned char*)dst_mem;
389         dst_surface.info.planes[0].stride = dst_surface.info.width * 4;
390
391         _init_test();
392
393         //init output
394         LIST_INITHEAD(&output.layer_list);
395         output.private_display = &display;
396 //      layer.showing_buffer = (tbm_surface_h)&src_surface;
397         layer.private_output = &output;
398         layer.private_display = &display;
399
400
401         error = tdm_helper_capture_output(&output, (tbm_surface_h)&dst_surface, 0, 0, 10, 10, stub_tdm_helper_capture_handler, &layer);
402
403         ASSERT_NE(TDM_ERROR_NONE, error);
404 }
405
406 TEST(tdm_helper_capture_output, work_flow_error_2___wrong_buffer_format)
407 {
408         tdm_error error;
409         tdm_private_display display;
410         tdm_private_output output;
411         tdm_private_layer layer;
412         int src_mem[100][100];
413         int dst_mem[100][100];
414         struct _tbm_surface src_surface;
415         struct _tbm_surface dst_surface;
416         memset(&output, 0, sizeof(output));
417         memset(&layer, 0, sizeof(layer));
418
419         src_surface.info.format = TBM_FORMAT_XRGB8888;
420         src_surface.info.width = 100;
421         src_surface.info.height = 100;
422         src_surface.info.num_planes = 1;
423         src_surface.info.planes[0].ptr = (unsigned char*)src_mem;
424         src_surface.info.planes[0].stride = src_surface.info.width * 4;
425
426         src_surface.info.format = TBM_FORMAT_XRGB8888;
427         dst_surface.info.width = 100;
428         dst_surface.info.height = 100;
429         dst_surface.info.num_planes = 1;
430         dst_surface.info.planes[0].ptr = (unsigned char*)dst_mem;
431         dst_surface.info.planes[0].stride = dst_surface.info.width * 4;
432
433         _init_test();
434
435         //init output
436         LIST_INITHEAD(&output.layer_list);
437         LIST_ADDTAIL(&layer.link, &output.layer_list);
438         output.private_display = &display;
439 //      layer.showing_buffer = (tbm_surface_h)&src_surface;
440         layer.private_output = &output;
441         layer.private_display = &display;
442
443         dst_surface.info.format = TBM_FORMAT_YUV410;
444         error = tdm_helper_capture_output(&output, (tbm_surface_h)&dst_surface, 0, 0, 10, 10, stub_tdm_helper_capture_handler, &layer);
445         ASSERT_EQ(TDM_ERROR_NONE, error);
446 }
447
448 TEST(tdm_helper_capture_output, work_flow_error_2___tbm_surface_map)
449 {
450         tdm_error error;
451         tdm_private_display display;
452         tdm_private_output output;
453         tdm_private_layer layer;
454         int src_mem[100][100];
455         int dst_mem[100][100];
456         struct _tbm_surface src_surface;
457         struct _tbm_surface dst_surface;
458         memset(&output, 0, sizeof(output));
459         memset(&layer, 0, sizeof(layer));
460
461         src_surface.info.format = TBM_FORMAT_ARGB8888;
462         src_surface.info.width = 100;
463         src_surface.info.height = 100;
464         src_surface.info.num_planes = 1;
465         src_surface.info.planes[0].ptr = (unsigned char*)src_mem;
466         src_surface.info.planes[0].stride = src_surface.info.width * 4;
467
468         dst_surface.info.format = TBM_FORMAT_XRGB8888;
469         dst_surface.info.width = 100;
470         dst_surface.info.height = 100;
471         dst_surface.info.num_planes = 1;
472         dst_surface.info.planes[0].ptr = (unsigned char*)dst_mem;
473         dst_surface.info.planes[0].stride = dst_surface.info.width * 4;
474
475         _init_test();
476
477         //init output
478         LIST_INITHEAD(&output.layer_list);
479         LIST_ADDTAIL(&layer.link, &output.layer_list);
480         output.private_display = &display;
481 //      layer.showing_buffer = (tbm_surface_h)&src_surface;
482         layer.private_output = &output;
483         layer.private_display = &display;
484
485
486         dst_surface.info.num_planes = 0;
487         error = tdm_helper_capture_output(&output, (tbm_surface_h)&dst_surface, 0, 0, 10, 10, stub_tdm_helper_capture_handler, &layer);
488         ASSERT_EQ(TDM_ERROR_NONE, error);
489         dst_surface.info.num_planes = 1;
490
491         src_surface.info.num_planes = 0;
492         error = tdm_helper_capture_output(&output, (tbm_surface_h)&dst_surface, 0, 0, 10, 10, stub_tdm_helper_capture_handler, &layer);
493         ASSERT_EQ(TDM_ERROR_NONE, error);
494 }
495
496 /* tdm_helper_convert_buffer */
497 TEST(tdm_helper_convert_buffer, work_flow_success_1)
498 {
499         tdm_error error;
500         int src_mem[100][100];
501         int dst_mem[100][100];
502         struct _tbm_surface src_surface;
503         struct _tbm_surface dst_surface;
504         tdm_pos src_pos = {0, 0, 100, 100};
505         tdm_pos dst_pos = {0, 0, 100, 100};
506
507         src_surface.info.format = TBM_FORMAT_ARGB8888;
508         src_surface.info.width = 100;
509         src_surface.info.height = 100;
510         src_surface.info.num_planes = 1;
511         src_surface.info.planes[0].ptr = (unsigned char*)src_mem;
512         src_surface.info.planes[0].stride = src_surface.info.width * 4;
513
514         dst_surface.info.format = TBM_FORMAT_XRGB8888;
515         dst_surface.info.width = 100;
516         dst_surface.info.height = 100;
517         dst_surface.info.num_planes = 1;
518         dst_surface.info.planes[0].ptr = (unsigned char*)dst_mem;
519         dst_surface.info.planes[0].stride = dst_surface.info.width * 4;
520
521         _init_test();
522
523         error = tdm_helper_convert_buffer(&src_surface, &dst_surface, &src_pos, &dst_pos, TDM_TRANSFORM_FLIPPED, 0);
524         ASSERT_EQ(TDM_ERROR_NONE, error);
525
526         error = tdm_helper_convert_buffer(&src_surface, &dst_surface, &src_pos, &dst_pos, TDM_TRANSFORM_90, 0);
527         ASSERT_EQ(TDM_ERROR_NONE, error);
528
529         error = tdm_helper_convert_buffer(&src_surface, &dst_surface, &src_pos, &dst_pos, TDM_TRANSFORM_180, 0);
530         ASSERT_EQ(TDM_ERROR_NONE, error);
531
532         error = tdm_helper_convert_buffer(&src_surface, &dst_surface, &src_pos, &dst_pos, TDM_TRANSFORM_FLIPPED_270, 0);
533         ASSERT_EQ(TDM_ERROR_NONE, error);
534 }
535
536
537 TEST(tdm_helper_convert_buffer, work_flow_error_1__NULL)
538 {
539         tdm_error error;
540         int src_mem[100][100];
541         int dst_mem[100][100];
542         struct _tbm_surface src_surface;
543         struct _tbm_surface dst_surface;
544         tdm_pos src_pos = {0, 0, 100, 100};
545         tdm_pos dst_pos = {0, 0, 100, 100};
546
547         src_surface.info.format = TBM_FORMAT_ARGB8888;
548         src_surface.info.width = 100;
549         src_surface.info.height = 100;
550         src_surface.info.num_planes = 1;
551         src_surface.info.planes[0].ptr = (unsigned char*)src_mem;
552         src_surface.info.planes[0].stride = src_surface.info.width * 4;
553
554         dst_surface.info.format = TBM_FORMAT_XRGB8888;
555         dst_surface.info.width = 100;
556         dst_surface.info.height = 100;
557         dst_surface.info.num_planes = 1;
558         dst_surface.info.planes[0].ptr = (unsigned char*)dst_mem;
559         dst_surface.info.planes[0].stride = dst_surface.info.width * 4;
560
561         _init_test();
562         error = tdm_helper_convert_buffer(NULL, &dst_surface, &src_pos, &dst_pos, TDM_TRANSFORM_FLIPPED, 0);
563         ASSERT_NE(TDM_ERROR_NONE, error);
564         error = tdm_helper_convert_buffer(&src_surface, NULL, &src_pos, &dst_pos, TDM_TRANSFORM_FLIPPED, 0);
565         ASSERT_NE(TDM_ERROR_NONE, error);
566 }
567
568 TEST(tdm_helper_convert_buffer, work_flow_error_1___wrong_buffers)
569 {
570         tdm_error error;
571         int src_mem[100][100];
572         int dst_mem[100][100];
573         struct _tbm_surface src_surface;
574         struct _tbm_surface dst_surface;
575         tdm_pos src_pos = {0, 0, 100, 100};
576         tdm_pos dst_pos = {0, 0, 100, 100};
577
578         src_surface.info.format = TBM_FORMAT_ARGB8888;
579         src_surface.info.width = 100;
580         src_surface.info.height = 100;
581         src_surface.info.num_planes = 1;
582         src_surface.info.planes[0].ptr = (unsigned char*)src_mem;
583         src_surface.info.planes[0].stride = src_surface.info.width * 4;
584
585         dst_surface.info.format = TBM_FORMAT_XRGB8888;
586         dst_surface.info.width = 100;
587         dst_surface.info.height = 100;
588         dst_surface.info.num_planes = 1;
589         dst_surface.info.planes[0].ptr = (unsigned char*)dst_mem;
590         dst_surface.info.planes[0].stride = dst_surface.info.width * 4;
591
592         _init_test();
593
594         //fail map of src buffer
595         src_surface.info.num_planes = 0;
596         error = tdm_helper_convert_buffer(&src_surface, &dst_surface, &src_pos, &dst_pos, TDM_TRANSFORM_FLIPPED, 0);
597         ASSERT_NE(TDM_ERROR_NONE, error);
598         src_surface.info.num_planes = 1;
599
600         //fail map of dst buffer
601         dst_surface.info.num_planes = 0;
602         error = tdm_helper_convert_buffer(&src_surface, &dst_surface, &src_pos, &dst_pos, TDM_TRANSFORM_FLIPPED, 0);
603         ASSERT_NE(TDM_ERROR_NONE, error);
604         dst_surface.info.num_planes = 1;
605
606         //wrong format of src buffer
607         src_surface.info.format = TBM_FORMAT_YUV410;
608         error = tdm_helper_convert_buffer(&src_surface, &dst_surface, &src_pos, &dst_pos, TDM_TRANSFORM_FLIPPED, 0);
609         ASSERT_NE(TDM_ERROR_NONE, error);
610         src_surface.info.format = TBM_FORMAT_ARGB8888;
611
612         //wrong format of dst buffer
613         dst_surface.info.format = TBM_FORMAT_YUV410;
614         error = tdm_helper_convert_buffer(&src_surface, &dst_surface, &src_pos, &dst_pos, TDM_TRANSFORM_FLIPPED, 0);
615         ASSERT_NE(TDM_ERROR_NONE, error);
616         dst_surface.info.format = TBM_FORMAT_ARGB8888;
617 }
618
619
620 /* tdm_helper_clear_buffer_pos */
621 TEST(tdm_helper_clear_buffer_pos, work_flow_success_1)
622 {
623         int mem1[100*100*3];
624         int mem2[100*100*3];
625         int mem3[100*100*3];
626         struct _tbm_surface surface;
627         tdm_pos pos = {1, 0, 9, 10};
628
629         surface.info.width = 10;
630         surface.info.height = 10;
631         surface.info.num_planes = 1;
632         surface.info.planes[0].ptr = (unsigned char*)mem1;
633         surface.info.planes[0].stride = surface.info.width * 4;
634         surface.info.planes[1].ptr = (unsigned char*)mem2;
635         surface.info.planes[1].stride = surface.info.width * 4;
636         surface.info.planes[2].ptr = (unsigned char*)mem3;
637         surface.info.planes[2].stride = surface.info.width * 4;
638
639         _init_test();
640
641         surface.info.format = TBM_FORMAT_ARGB8888;
642         memset(mem1, 0x77, sizeof(mem1));
643         memset(mem2, 0x77, sizeof(mem2));
644         memset(mem3, 0x77, sizeof(mem3));
645         tdm_helper_clear_buffer_pos(&surface, &pos);
646         EXPECT_EQ(0, mem1[100+1]);
647         EXPECT_EQ(0x77777777, mem1[0]);
648         EXPECT_EQ(0x77777777, mem2[0]);
649         EXPECT_EQ(0x77777777, mem3[0]);
650
651
652         surface.info.format = TBM_FORMAT_YVU420;
653         memset(mem1, 0x77, sizeof(mem1));
654         memset(mem2, 0x77, sizeof(mem2));
655         memset(mem3, 0x77, sizeof(mem3));
656         tdm_helper_clear_buffer_pos(&surface, NULL);
657         EXPECT_EQ(0x10101010, mem1[0]);
658         EXPECT_EQ(0x80808080, mem2[0]);
659         EXPECT_EQ(0x80808080, mem3[0]);
660
661         surface.info.format = TBM_FORMAT_NV12;
662         memset(mem1, 0x77, sizeof(mem1));
663         memset(mem2, 0x77, sizeof(mem2));
664         memset(mem3, 0x77, sizeof(mem3));
665         tdm_helper_clear_buffer_pos(&surface, NULL);
666         EXPECT_EQ(0x10101010, mem1[0]);
667         EXPECT_EQ(0x80808080, mem2[0]);
668         EXPECT_EQ(0x77777777, mem3[0]);
669
670         surface.info.format = TBM_FORMAT_UYVY;
671         memset(mem2, 0x77, sizeof(mem2));
672         memset(mem3, 0x77, sizeof(mem3));
673         tdm_helper_clear_buffer_pos(&surface, NULL);
674         EXPECT_EQ(0x80108010, mem1[0]);
675         EXPECT_EQ(0x77777777, mem2[0]);
676         EXPECT_EQ(0x77777777, mem3[0]);
677
678         surface.info.format = TBM_FORMAT_YUYV;
679         memset(mem1, 0x77, sizeof(mem1));
680         memset(mem2, 0x77, sizeof(mem2));
681         memset(mem3, 0x77, sizeof(mem3));
682         tdm_helper_clear_buffer_pos(&surface, NULL);
683         EXPECT_EQ(0x10801080, mem1[0]);
684         EXPECT_EQ(0x77777777, mem2[0]);
685         EXPECT_EQ(0x77777777, mem3[0]);
686
687         surface.info.format = TBM_FORMAT_YVU411;
688         memset(mem1, 0x77, sizeof(mem1));
689         memset(mem2, 0x77, sizeof(mem2));
690         memset(mem3, 0x77, sizeof(mem3));
691         tdm_helper_clear_buffer_pos(&surface, NULL);
692         EXPECT_EQ(0x77777777, mem1[0]);
693         EXPECT_EQ(0x77777777, mem2[0]);
694         EXPECT_EQ(0x77777777, mem3[0]);
695 }
696
697
698 /* tdm_helper_clear_buffer */
699 TEST(tdm_helper_clear_buffer, work_flow_success_1)
700 {
701         int mem1[100*100*3];
702         struct _tbm_surface surface;
703
704         surface.info.width = 10;
705         surface.info.height = 10;
706         surface.info.num_planes = 1;
707         surface.info.planes[0].ptr = (unsigned char*)mem1;
708         surface.info.planes[0].stride = surface.info.width * 4;
709
710         _init_test();
711
712         surface.info.format = TBM_FORMAT_ARGB8888;
713         memset(mem1, 0x77, sizeof(mem1));
714         tdm_helper_clear_buffer(&surface);
715         EXPECT_EQ(0, mem1[0]);
716 }
717
718 /* tdm_helper_dump_buffer */
719 //TEST(tdm_helper_dump_buffer, work_flow_success_1)
720 //{
721 //      int mem1[10*10*3];
722 //      int mem2[10*10*3];
723 //      int mem3[10*10*3];
724 //      struct _tbm_surface surface;
725 //
726 //      surface.info.width = 10;
727 //      surface.info.height = 10;
728 //      surface.info.num_planes = 1;
729 //      surface.info.planes[0].ptr = (unsigned char*)mem1;
730 //      surface.info.planes[0].stride = surface.info.width * 4;
731 //      surface.info.planes[1].ptr = (unsigned char*)mem2;
732 //      surface.info.planes[1].stride = surface.info.width * 4;
733 //      surface.info.planes[2].ptr = (unsigned char*)mem3;
734 //      surface.info.planes[2].stride = surface.info.width * 4;
735 //
736 //      _init_test();
737 //
738 //      surface.info.format = TBM_FORMAT_ARGB8888;
739 //      tdm_helper_dump_buffer(&surface, "tmp.png");
740 //
741 //      surface.info.format = TBM_FORMAT_YVU420;
742 //      tdm_helper_dump_buffer(&surface, "tmp.yuv");
743 //
744 //      surface.info.format = TBM_FORMAT_NV12;
745 //      tdm_helper_dump_buffer(&surface, "tmp.yuv");
746 //
747 //      surface.info.format = TBM_FORMAT_YUYV;
748 //      tdm_helper_dump_buffer(&surface, "tmp.yuv");
749 //
750 //      surface.info.format = TBM_FORMAT_YVU411;
751 //      tdm_helper_dump_buffer(&surface, "tmp.yuv");
752 //
753 //}
754
755 /* tdm_helper_dump_buffer */
756 TEST(tdm_helper_dump_buffer, work_flow_error_1___NULL)
757 {
758         struct _tbm_surface surface;
759         char str[1024] = {'t', 'm', 'p', 0};
760
761         _init_test();
762
763         tdm_helper_dump_buffer(&surface, "tmp.yuv");
764         tdm_helper_dump_buffer(NULL, str);
765 }
766