utest: fix protex issue
[platform/core/uifw/libtdm.git] / utests / src / ut_tdm_hwc_window.cpp
1 /**************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
4  *
5  * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
6  * Contact: Andrii Sokolenko <a.sokolenko@samsung.com>
7  * Contact: Roman Marchenko <r.marchenko@samsung.com>
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sub license, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice (including the
18  * next paragraph) shall be included in all copies or substantial portions
19  * of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
24  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
25  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28  *
29 **************************************************************************/
30
31 #include "gtest/gtest.h"
32 #include "ut_common.h"
33 #include "stdint.h"
34
35 #include "tdm.h"
36 #include "tdm_backend.h"
37 extern "C" {
38 #include "tbm_bufmgr.h"
39 #include "tbm_drm_helper.h"
40 }
41
42 class TDMOutputHwc : public ::testing::Test {
43 protected:
44         tdm_display *dpy = NULL;
45         tbm_bufmgr tbm_bufmgr = NULL;
46         int master_fd = -42;
47         /*list of connected outputs*/
48         int output_count = 0;
49         const tdm_output_mode **preferred_mode_array = NULL;
50         tdm_output **outputs;
51         tdm_error error ;
52         virtual void SetEnv()
53         {
54                 setenv("TDM_DEBUG_MODULE", "all", 1);
55                 setenv("TDM_DEBUG", "1", 1);
56                 setenv("TDM_THREAD", "1", 1);
57                 setenv("TDM_COMMIT_PER_VBLANK", "1", 1);
58                 setenv("TDM_DLOG", "1", 1);
59                 setenv("TDM_HWC", "1", 1);
60                 setenv("XDG_RUNTIME_DIR", ".", 1);
61                 setenv("TBM_DLOG", "1", 1);
62                 setenv("TBM_DISPLAY_SERVER", "1", 1);
63         }
64
65         void UnsetEnv()
66         {
67                 unsetenv("TDM_DEBUG_MODULE");
68                 unsetenv("TDM_DEBUG");
69                 unsetenv("TDM_THREAD");
70                 unsetenv("TDM_COMMIT_PER_VBLANK");
71                 unsetenv("TDM_DLOG");
72                 unsetenv("TDM_HWC");
73                 unsetenv("XDG_RUNTIME_DIR");
74                 unsetenv("TBM_DLOG");
75                 unsetenv("TBM_DISPLAY_SERVER");
76         }
77
78         int IsHwcEnable(int i)
79         {
80                 tdm_output_capability capabilities = (tdm_output_capability)0;
81                 tdm_output_get_capabilities(outputs[i], &capabilities);
82                 return capabilities & TDM_OUTPUT_CAPABILITY_HWC;
83         }
84
85         tbm_surface_h CreateBufferForOutput(int i)
86         {
87                 int w = preferred_mode_array[i]->hdisplay;
88                 int h = preferred_mode_array[i]->vdisplay;
89                 return tbm_surface_internal_create_with_flags(w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
90         }
91
92         void SetUp(void)
93         {
94                 const tdm_output_mode *preferred_mode = NULL;
95                 tdm_error error = TDM_ERROR_NONE;
96                 int all_output_count = 0;
97
98                 SetEnv();
99
100                 /* FIXME: fix the error. If we initialize TBM before TDM we get fail
101                  * in the tdm_output_set_dpms */
102 #if 0
103                 tbm_bufmgr = tbm_bufmgr_init(-1);
104                 ASSERT_FALSE(tbm_bufmgr == NULL);
105 #endif
106
107                 dpy = tdm_display_init(&error);
108                 ASSERT_TRUE(error == TDM_ERROR_NONE);
109                 ASSERT_FALSE(dpy == NULL);
110
111                 master_fd = tbm_drm_helper_get_master_fd();
112                 ASSERT_TRUE(tdm_display_get_output_count(dpy, &all_output_count) == TDM_ERROR_NONE);
113
114                 outputs = (tdm_output **)calloc(all_output_count, sizeof(tdm_output *));
115                 ASSERT_FALSE(NULL == outputs);
116
117                 preferred_mode_array = (const tdm_output_mode **)calloc(all_output_count, sizeof(tdm_output_mode *));
118                 ASSERT_FALSE(NULL == preferred_mode_array);
119
120                 output_count = 0;
121
122                 for (int i = 0; i < all_output_count; i++) {
123                         tdm_output *output = tdm_display_get_output(dpy, i, &error);
124                         int output_modes_cnt = 0;
125                         const tdm_output_mode *output_modes;
126
127                         if (TDM_ERROR_NONE != error || NULL == output)
128                                 continue;
129
130                         tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
131                         if (TDM_ERROR_NONE != tdm_output_get_conn_status(output, &status))
132                                 continue;
133
134                         if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
135                                 continue;
136
137                         error = tdm_output_get_available_modes(output, &output_modes, &output_modes_cnt);
138                         if (TDM_ERROR_NONE != error)
139                                 continue;
140                         if (output_modes_cnt <= 0) {
141                                 continue;
142                         }
143
144                         for(int j = 0; j < output_modes_cnt; j++)
145                                 if(output_modes[j].type & TDM_OUTPUT_MODE_TYPE_PREFERRED)
146                                         preferred_mode = &output_modes[j];
147
148                         if (!preferred_mode)
149                                 continue;
150
151                         if (preferred_mode_array)
152                                 preferred_mode_array[output_count] = preferred_mode;
153                         if (outputs)
154                                 outputs[output_count] = output;
155                         output_count++;
156
157                         error = tdm_output_set_mode(output, preferred_mode);
158                         ASSERT_EQ(TDM_ERROR_NONE, error);
159                 }
160         }
161         void TearDown(void)
162         {
163                 tdm_display_deinit(dpy);
164                 dpy = NULL;
165                 tbm_bufmgr_deinit(tbm_bufmgr);
166                 tbm_bufmgr = NULL;
167                 if (outputs)
168                         free(outputs);
169                 if (preferred_mode_array)
170                         free(preferred_mode_array);
171                 if (master_fd > -1) {
172                         int temp_master_fd = tbm_drm_helper_get_master_fd();
173                         EXPECT_EQ(temp_master_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl;
174                         if (temp_master_fd > -1)
175                                 exit(1);
176                         close(master_fd);
177                 }
178
179                 UnsetEnv();
180         }
181 };
182
183 class TDMOutputHwcWithoutHwcCap : public TDMOutputHwc {
184         void SetEnv()
185         {
186                 TDMOutputHwc::SetEnv();
187                 setenv("TDM_HWC", "0", 1);
188         }
189 };
190
191 #define HWC_WIN_NUM 5
192 class TDMHwcWindow : public TDMOutputHwc {
193 protected:
194         tdm_hwc_window **hwc_wins;
195         int hwc_count;
196
197         void SetUp(void)
198         {
199                 hwc_count = 0;
200
201                 TDMOutputHwc::SetUp();
202                 hwc_wins = (tdm_hwc_window **)calloc(output_count * HWC_WIN_NUM, sizeof(tdm_hwc_window *));
203
204                 //create HWC_WIN_NUM hwc_windows for each outputs
205                 for (int i = 0; i < output_count; i++) {
206                         if (IsHwcEnable(i)) {
207                                 for (int j = 0; j < HWC_WIN_NUM; j++) {
208                                         tdm_hwc_window * hw = tdm_output_hwc_create_window(outputs[i], &error);
209                                         ASSERT_EQ(TDM_ERROR_NONE, error);
210                                         hwc_wins[hwc_count++] = hw;
211                                 }
212                         }
213                 }
214         }
215
216         void TearDown(void)
217         {
218                 for (int i = 0; i < hwc_count; i++) {
219                         tdm_output_hwc_destroy_window(outputs[0], hwc_wins[i]);
220                 }
221                 TDMOutputHwc::TearDown();
222         }
223
224 };
225
226 /* tdm_hwc_window * tdm_output_hwc_create_window(tdm_output *output, tdm_error *error); */
227 TEST_F(TDMOutputHwc, CreateWindowFailNull)
228 {
229         ASSERT_EQ(NULL, tdm_output_hwc_create_window(NULL, &error));
230         ASSERT_NE(TDM_ERROR_NONE, error);
231 }
232
233 TEST_F(TDMOutputHwc, CreateWindowSuccessful)
234 {
235         for (int i = 0; i < output_count; i++) {
236                 if (IsHwcEnable(i)) {
237                         tdm_hwc_window * hw = tdm_output_hwc_create_window(outputs[i], &error);
238                         ASSERT_EQ(TDM_ERROR_NONE, error);
239                         error = tdm_output_hwc_destroy_window(outputs[i], hw);
240                         ASSERT_EQ(TDM_ERROR_NONE, error);
241                 } else {
242                         ASSERT_EQ(NULL, tdm_output_hwc_create_window(outputs[i], &error));
243                         ASSERT_NE(TDM_ERROR_NONE, error);
244                 }
245         }
246 }
247
248
249 /* tdm_error tdm_output_hwc_destroy_window(tdm_output *output, tdm_hwc_window *hwc_window); */
250 TEST_F(TDMOutputHwc, DestroyWindowFailNull)
251 {
252         for (int i = 0; i < output_count; i++) {
253                 tdm_hwc_window * hw = NULL;
254
255                 if (IsHwcEnable(i)) {
256                         hw = tdm_output_hwc_create_window(outputs[i], &error);
257                         ASSERT_EQ(TDM_ERROR_NONE, error);
258                 }
259
260                 /* test: output is NULL*/
261                 error = tdm_output_hwc_destroy_window(NULL, hw);
262                 ASSERT_NE(TDM_ERROR_NONE, error);
263
264                 /* test: hw is NULL*/
265                 error = tdm_output_hwc_destroy_window(outputs[i], NULL);
266                 ASSERT_NE(TDM_ERROR_NONE, error);
267         }
268 }
269
270 TEST_F(TDMOutputHwc, DestroyWindowSuccessful)
271 {
272         tdm_hwc_window * hw;
273         for (int i = 0; i < output_count; i++) {
274                 if (IsHwcEnable(i)) {
275                         hw = tdm_output_hwc_create_window(outputs[i], &error);
276                         ASSERT_EQ(TDM_ERROR_NONE, error);
277                         error = tdm_output_hwc_destroy_window(outputs[i], hw);
278                         ASSERT_EQ(TDM_ERROR_NONE, error);
279                 }
280         }
281 }
282
283
284 /* tdm_error tdm_output_hwc_set_client_target_buffer(tdm_output *output,
285                                                                                  tbm_surface_h target_buffer, tdm_hwc_region damage,
286                                                                                  tdm_hwc_window *composited_wnds, uint32_t num_wnds); */
287 TEST_F(TDMOutputHwc, DISABLED_SetClientTargetBufferFailNullOutput)
288 {
289         tdm_hwc_region reg;
290         tbm_surface_h target_buff = CreateBufferForOutput(0);
291         error = tdm_output_hwc_set_client_target_buffer(NULL, target_buff, reg, NULL, 0 /* TODO: sergs_ut */);
292         tbm_surface_internal_destroy(target_buff);
293         ASSERT_NE(TDM_ERROR_NONE, error);
294 }
295
296 TEST_F(TDMOutputHwcWithoutHwcCap, DISABLED_SetClientTargetBufferFailNoHwc)
297 {
298         tdm_hwc_region damage;
299
300         for (int i = 0; i < output_count; i++) {
301                 tbm_surface_h target_buff = CreateBufferForOutput(i);
302                 ASSERT_NE(NULL, target_buff);
303                 error = tdm_output_hwc_set_client_target_buffer(outputs[i], target_buff, damage,
304                                 NULL, 0 /* TODO: sergs_ut */);
305                 tbm_surface_internal_destroy(target_buff);
306                 ASSERT_NE(TDM_ERROR_NONE, error);
307         }
308 }
309
310 TEST_F(TDMOutputHwc, DISABLED_SetClientTargetBufferSuccessfulSetBuff)
311 {
312         tdm_hwc_region damage;
313
314         for (int i = 0; i < output_count; i++) {
315                 tbm_surface_h target_buff = CreateBufferForOutput(i);
316                 ASSERT_NE(NULL, target_buff);
317                 if (IsHwcEnable(i)) {
318                         error = tdm_output_hwc_set_client_target_buffer(outputs[i], target_buff, damage,
319                                         NULL, 0 /* TODO: sergs_ut_ut */);
320                         tbm_surface_internal_destroy(target_buff);
321                         ASSERT_EQ(TDM_ERROR_NONE, error);
322                 } else {
323                         error = tdm_output_hwc_set_client_target_buffer(outputs[i], target_buff, damage,
324                                         NULL, 0 /* TODO: sergs_ut */);
325                         tbm_surface_internal_destroy(target_buff);
326                         ASSERT_NE(TDM_ERROR_NONE, error);
327                 }
328         }
329 }
330
331 TEST_F(TDMOutputHwc, DISABLED_SetClientTargetBufferSuccessfulResetBuff)
332 {
333         tdm_hwc_region damage = {.num_rects = 0, .rects = NULL};
334
335         for (int i = 0; i < output_count; i++) {
336                 if (IsHwcEnable(i)) {
337                         error = tdm_output_hwc_set_client_target_buffer(outputs[i], NULL, damage,
338                                         NULL, 0 /* TODO: sergs_ut */);
339                         ASSERT_EQ(TDM_ERROR_NONE, error);
340                 } else {
341                         error = tdm_output_hwc_set_client_target_buffer(outputs[i], NULL, damage,
342                                         NULL, 0 /* TODO: sergs_ut */);
343                         ASSERT_NE(TDM_ERROR_NONE, error);
344                 }
345         }
346 }
347
348 /* tbm_surface_queue_h tdm_output_hwc_get_target_buffer_queue(tdm_output *output, tdm_error *error); */
349 TEST_F(TDMOutputHwc, GetTargetBufferQueueFailNullOutput)
350 {
351         tbm_surface_queue_h queue = NULL;
352
353         queue = tdm_output_hwc_get_target_buffer_queue(NULL, &error);
354         ASSERT_NE(TDM_ERROR_NONE, error);
355         ASSERT_EQ(NULL, queue);
356
357         queue = tdm_output_hwc_get_target_buffer_queue(NULL, NULL);
358         ASSERT_EQ(NULL, queue);
359 }
360
361 TEST_F(TDMOutputHwcWithoutHwcCap, GetTargetBufferQueueFainNoHwc)
362 {
363         tbm_surface_queue_h queue = NULL;
364
365         for (int i = 0; i < output_count; i++) {
366                 queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], &error);
367                 ASSERT_NE(TDM_ERROR_NONE, error);
368                 ASSERT_EQ(NULL, queue);
369         }
370 }
371
372 TEST_F(TDMOutputHwc, GetTargetBufferQueueSuccessful)
373 {
374         tbm_surface_queue_h queue = NULL;
375
376         for (int i = 0; i < output_count; i++) {
377                 if (IsHwcEnable(i)) {
378                         queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], &error);
379                         tbm_surface_queue_destroy(queue);
380                         ASSERT_EQ(TDM_ERROR_NONE, error);
381                         ASSERT_NE(NULL, queue);
382
383                         queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], NULL);
384                         tbm_surface_queue_destroy(queue);
385                         ASSERT_EQ(TDM_ERROR_NONE, error);
386                         ASSERT_NE(NULL, queue);
387                 } else {
388                         queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], &error);
389                         ASSERT_NE(TDM_ERROR_NONE, error);
390                         ASSERT_EQ(NULL, queue);
391
392                         queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], NULL);
393                         ASSERT_NE(TDM_ERROR_NONE, error);
394                         ASSERT_EQ(NULL, queue);
395                 }
396         }
397 }
398
399 /* tbm_surface_queue_h tdm_hwc_window_get_tbm_buffer_queue(tdm_hwc_window *hwc_window, tdm_error *error); */
400 TEST_F(TDMHwcWindow, GetBufferQueueFailNull)
401 {
402         tbm_surface_queue_h queue = NULL;
403
404         queue = tdm_hwc_window_get_tbm_buffer_queue(NULL, &error);
405         ASSERT_NE(TDM_ERROR_NONE, error);
406         ASSERT_EQ(NULL, queue);
407
408         queue = tdm_hwc_window_get_tbm_buffer_queue(NULL, NULL);
409         ASSERT_EQ(NULL, queue);
410 }
411
412 TEST_F(TDMHwcWindow, GetBufferQueueSuccessful)
413 {
414         tbm_surface_queue_h queue = NULL;
415         tdm_hwc_window_info info = { 0 };
416
417         info.src_config.format = TBM_FORMAT_ARGB8888;
418         info.src_config.size.h = info.src_config.size.v = 256;
419         info.src_config.pos.h = info.src_config.pos.w = 256;
420         info.dst_pos.h = info.dst_pos.w = 256;
421         info.transform = TDM_TRANSFORM_NORMAL;
422
423         for (int i = 0; i < hwc_count; i++) {
424                 error = tdm_hwc_window_set_info(hwc_wins[i], &info);
425                 ASSERT_EQ(TDM_ERROR_NONE, error);
426
427                 queue = tdm_hwc_window_get_tbm_buffer_queue(hwc_wins[i], &error);
428                 tbm_surface_queue_destroy(queue);
429                 ASSERT_EQ(TDM_ERROR_NONE, error);
430                 ASSERT_NE(NULL, queue);
431
432                 queue = tdm_hwc_window_get_tbm_buffer_queue(hwc_wins[i], NULL);
433                 tbm_surface_queue_destroy(queue);
434                 ASSERT_NE(NULL, queue);
435         }
436 }
437
438 /* tdm_error tdm_hwc_window_set_zpos(tdm_hwc_window *hwc_window, uint32_t zpos); */
439 TEST_F(TDMHwcWindow, SetZposFailNull)
440 {
441         error = tdm_hwc_window_set_zpos(NULL, 1);
442         ASSERT_NE(TDM_ERROR_NONE, error);
443 }
444
445 TEST_F(TDMHwcWindow, SetZposSuccessful)
446 {
447         for (int i = 0; i < hwc_count; i++) {
448                 error = tdm_hwc_window_set_zpos(hwc_wins[i], i);
449                 ASSERT_EQ(TDM_ERROR_NONE, error);
450         }
451 }
452
453 /* tdm_error tdm_hwc_window_set_composition_type(tdm_hwc_window *hwc_window,
454                                                                         tdm_hwc_window_composition composition_type); */
455 TEST_F(TDMHwcWindow, SetCompositionTypeFailNull)
456 {
457         error = tdm_hwc_window_set_composition_type(NULL, TDM_COMPOSITION_DEVICE);
458         ASSERT_NE(TDM_ERROR_NONE, error);
459 }
460
461 TEST_F(TDMHwcWindow, SetCompositionTypeSuccessful)
462 {
463         for (int i = 0; i < hwc_count; i++) {
464                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE);
465                 ASSERT_EQ(TDM_ERROR_NONE, error);
466                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_CLIENT);
467                 ASSERT_EQ(TDM_ERROR_NONE, error);
468                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_CURSOR);
469                 ASSERT_EQ(TDM_ERROR_NONE, error);
470         }
471 }
472
473 TEST_F(TDMHwcWindow, SetCompositionTypeFailInvalieCompositionType)
474 {
475         for (int i = 0; i < hwc_count; i++) {
476                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE_CANDIDATE);
477                 ASSERT_NE(TDM_ERROR_NONE, error);
478                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], tdm_hwc_window_composition(TDM_COMPOSITION_NONE-1));
479                 ASSERT_NE(TDM_ERROR_NONE, error);
480         }
481 }
482
483 /* tdm_error tdm_hwc_window_set_buffer_damage(tdm_hwc_window *hwc_window, tdm_hwc_region damage); */
484 TEST_F(TDMHwcWindow, SetBufferDamageFailNullHwcWindow)
485 {
486         tdm_hwc_region damage;
487         error = tdm_hwc_window_set_buffer_damage(NULL, damage);
488         ASSERT_NE(TDM_ERROR_NONE, error);
489 }
490
491 TEST_F(TDMHwcWindow, SetBufferDamageFailNullDamageRects)
492 {
493         tdm_hwc_region damage = {.num_rects = 1, .rects = NULL};
494
495         for (int i = 0; i < hwc_count; i++) {
496                 error = tdm_hwc_window_set_buffer_damage(hwc_wins[i], damage);
497                 ASSERT_NE(TDM_ERROR_NONE, error);
498         }
499 }
500
501
502 TEST_F(TDMHwcWindow, SetBufferDamageSuccessful)
503 {
504         tdm_pos const rects[1] = {0};
505         tdm_hwc_region damage = {.num_rects = 1, .rects = rects};
506
507         for (int i = 0; i < hwc_count; i++) {
508                 error = tdm_hwc_window_set_buffer_damage(hwc_wins[i], damage);
509                 ASSERT_EQ(TDM_ERROR_NONE, error);
510         }
511 }
512
513
514 /* tdm_error tdm_hwc_window_set_info(tdm_hwc_window *hwc_window, tdm_hwc_window_info *info); */
515 TEST_F(TDMHwcWindow, SetInfoFailNull)
516 {
517         tdm_hwc_window_info info = { 0 };
518
519         error = tdm_hwc_window_set_info(NULL, &info);
520         ASSERT_NE(TDM_ERROR_NONE, error);
521
522         if (hwc_count > 0) {
523                 error = tdm_hwc_window_set_info(hwc_wins[0], NULL);
524                 ASSERT_NE(TDM_ERROR_NONE, error);
525         }
526 }
527 TEST_F(TDMHwcWindow, SetInfoSuccessful)
528 {
529         tdm_hwc_window_info info = { 0 };
530
531         for (int i = 0; i < hwc_count; i++) {
532                 error = tdm_hwc_window_set_info(hwc_wins[i], &info);
533                 ASSERT_EQ(TDM_ERROR_NONE, error);
534         }
535 }
536
537
538 /* tdm_error tdm_hwc_window_set_buffer(tdm_hwc_window *hwc_window, tbm_surface_h buffer); */
539 TEST_F(TDMHwcWindow, SetBufferFailNull)
540 {
541         error = tdm_hwc_window_set_buffer(NULL, NULL);
542         ASSERT_NE(TDM_ERROR_NONE, error);
543 }
544
545 TEST_F(TDMHwcWindow, SetBufferSuccessful)
546 {
547         for (int i = 0; i < hwc_count; i++) {
548
549                 tbm_surface_h buff = tbm_surface_create(256, 256, TBM_FORMAT_ARGB8888);
550
551                 /* test: set*/
552                 error = tdm_hwc_window_set_buffer(hwc_wins[i], buff);
553                 tbm_surface_destroy(buff);
554                 ASSERT_EQ(TDM_ERROR_NONE, error);
555
556                 /* test: reset*/
557                 error = tdm_hwc_window_set_buffer(hwc_wins[i], NULL);
558                 ASSERT_EQ(TDM_ERROR_NONE, error);
559         }
560 }
561
562 /* tdm_error tdm_hwc_window_set_flags(tdm_hwc_window *hwc_window, tdm_hwc_window_flag flags); */
563 TEST_F(TDMHwcWindow, SetFlagsFailNull)
564 {
565         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
566
567         error = tdm_hwc_window_set_flags(NULL, flag);
568         ASSERT_NE(TDM_ERROR_NONE, error);
569 }
570
571 TEST_F(TDMHwcWindow, SetFlagsSuccessful)
572 {
573         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
574
575         for (int i = 0; i < hwc_count; i++) {
576
577                 error = tdm_hwc_window_set_flags(hwc_wins[i], flag);
578                 ASSERT_EQ(TDM_ERROR_NONE, error);
579         }
580 }
581
582 /* tdm_error tdm_hwc_window_unset_flags(tdm_hwc_window *hwc_window, tdm_hwc_window_flag flags); */
583 TEST_F(TDMHwcWindow, UnsetFlagsFailNull)
584 {
585         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
586
587         error = tdm_hwc_window_unset_flags(NULL, flag);
588         ASSERT_NE(TDM_ERROR_NONE, error);
589 }
590
591 TEST_F(TDMHwcWindow, UnsetFlagsSuccessful)
592 {
593         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
594
595         for (int i = 0; i < hwc_count; i++) {
596
597                 error = tdm_hwc_window_unset_flags(hwc_wins[i], flag);
598                 ASSERT_EQ(TDM_ERROR_NONE, error);
599         }
600 }
601
602 /* tdm_error tdm_hwc_window_video_get_capability(tdm_hwc_window *hwc_window,
603                                                                         tdm_hwc_window_video_capability *video_capability); */
604 TEST_F(TDMHwcWindow, VideoGetCapabilityFailNull)
605 {
606         tdm_hwc_window_video_capability video_capability;
607
608         error = tdm_hwc_window_video_get_capability(NULL, &video_capability);
609         ASSERT_NE(TDM_ERROR_NONE, error);
610
611         if (hwc_count > 0) {
612                 error = tdm_hwc_window_video_get_capability(hwc_wins[0], NULL);
613                 ASSERT_NE(TDM_ERROR_NONE, error);
614         }
615
616 }
617
618 TEST_F(TDMHwcWindow, VideoGetCapabilitySuccessful)
619 {
620         tdm_hwc_window_video_capability video_capability;
621
622         for (int i = 0; i < hwc_count; i++) {
623                 /* hwc_window with TDM_COMPOSITION_CLIENT dosn't support tdm_hwc_window_video_get_capability()*/
624                 error = tdm_hwc_window_video_get_capability(hwc_wins[i],  &video_capability);
625                 ASSERT_NE(TDM_ERROR_NONE, error);
626
627                 /*TODO:: check video capability for TDM_COMPOSITION_VIDEO*/
628         }
629 }
630
631 /* tdm_error tdm_output_hwc_validate(tdm_output *output, uint32_t *num_types); */
632 TEST_F(TDMOutputHwc, ValidateFailNull)
633 {
634         uint32_t num_types;
635         error = tdm_output_hwc_validate(NULL, &num_types);
636         ASSERT_NE(TDM_ERROR_NONE, error);
637
638         if (outputs[0]) {
639                 error = tdm_output_hwc_validate(outputs[0], NULL);
640                 ASSERT_NE(TDM_ERROR_NONE, error);
641         }
642 }
643
644 TEST_F(TDMOutputHwcWithoutHwcCap, ValidateFailNoHwc)
645 {
646         uint32_t num_types;
647
648         for (int i = 0; i < output_count; i++) {
649                 error = tdm_output_hwc_validate(outputs[i], &num_types);
650                 ASSERT_NE(TDM_ERROR_NONE, error);
651         }
652 }
653
654 TEST_F(TDMOutputHwc, ValidateSuccessful)
655 {
656         uint32_t num_types;
657         for (int i = 0; i < output_count; i++) {
658                 if (IsHwcEnable(i)) {
659                         error = tdm_output_hwc_validate(outputs[i], &num_types);
660                         ASSERT_EQ(TDM_ERROR_NONE, error);
661                 } else {
662                         error = tdm_output_hwc_validate(outputs[i], &num_types);
663                         ASSERT_NE(TDM_ERROR_NONE, error);
664                 }
665         }
666 }
667
668 /* tdm_error tdm_output_hwc_get_changed_composition_types(tdm_output *output,
669                                                                                  uint32_t *num_elements, tdm_hwc_window **hwc_window,
670                                                                                  tdm_hwc_window_composition *composition_types); */
671
672 TEST_F(TDMOutputHwc, GetChangedCompositionTypesFailNull)
673 {
674         uint32_t num_elements;
675
676         error = tdm_output_hwc_get_changed_composition_types(NULL, &num_elements, NULL, NULL);
677         ASSERT_NE(TDM_ERROR_NONE, error);
678
679         if (outputs[0]) {
680                 error = tdm_output_hwc_get_changed_composition_types(outputs[0], NULL, NULL, NULL);
681                 ASSERT_NE(TDM_ERROR_NONE, error);
682         }
683 }
684
685 TEST_F(TDMOutputHwcWithoutHwcCap, GetChangedCompositionTypesFailNoHwc)
686 {
687         uint32_t get_num = 10;
688
689         for (int i = 0; i < output_count; i++) {
690                 error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, NULL, NULL);
691                 ASSERT_NE(TDM_ERROR_NONE, error);
692         }
693 }
694
695 TEST_F(TDMHwcWindow, GetChangedCompositionTypesSuccessful)
696 {
697         uint32_t validate_num;
698         uint32_t get_num = 0;
699
700         tdm_hwc_window_composition *composition_types;
701         tdm_hwc_window **hwc_wnds;
702
703         for (int i = 0; i < hwc_count; i++) {
704                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE);
705                 ASSERT_EQ(TDM_ERROR_NONE, error);
706         }
707
708
709         for (int i = 0; i < output_count; i++) {
710                 if (IsHwcEnable(i)) {
711                         error = tdm_output_hwc_validate(outputs[i], &validate_num);
712                         ASSERT_EQ(TDM_ERROR_NONE, error);
713
714                         error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, NULL, NULL);
715                         ASSERT_EQ(TDM_ERROR_NONE, error);
716
717                         ASSERT_TRUE(get_num == validate_num);
718                         hwc_wnds = (tdm_hwc_window **)calloc(get_num, sizeof(tdm_hwc_window *));
719                         composition_types = (tdm_hwc_window_composition *)calloc(get_num, sizeof(tdm_hwc_window_composition));
720
721                         error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, hwc_wnds, composition_types);
722
723                         free(hwc_wnds);
724                         free(composition_types);
725
726                         ASSERT_EQ(TDM_ERROR_NONE, error);
727                 } else {
728                         error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, NULL, NULL);
729                         ASSERT_NE(TDM_ERROR_NONE, error);
730                 }
731         }
732 }
733
734 /* tdm_error tdm_output_hwc_accept_changes(tdm_output *output); */
735
736 TEST_F(TDMOutputHwc, AcceptChangesFailNull)
737 {
738         error = tdm_output_hwc_accept_changes(NULL);
739         ASSERT_NE(TDM_ERROR_NONE, error);
740 }
741
742 TEST_F(TDMOutputHwcWithoutHwcCap, AcceptChangesFailNoHwc)
743 {
744         for (int i = 0; i < output_count; i++) {
745                 error = tdm_output_hwc_accept_changes(outputs[i]);
746                 ASSERT_NE(TDM_ERROR_NONE, error);
747         }
748 }
749
750 TEST_F(TDMHwcWindow, AcceptChangesSuccessful)
751 {
752         uint32_t validate_num;
753
754         for (int i = 0; i < hwc_count; i++) {
755                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE);
756                 ASSERT_EQ(TDM_ERROR_NONE, error);
757         }
758
759         for (int i = 0; i < output_count; i++) {
760                 if (IsHwcEnable(i)) {
761                         error = tdm_output_hwc_validate(outputs[i], &validate_num);
762                         ASSERT_EQ(TDM_ERROR_NONE, error);
763
764                         if (validate_num > 0) {
765                                 error =  tdm_output_hwc_accept_changes(outputs[i]);
766                                 ASSERT_EQ(TDM_ERROR_NONE, error);
767                         }
768                 }
769         }
770 }
771
772 static int need_validate_handler_is_called = 0;
773 static void need_validate_handler(tdm_output *output)
774 {
775         need_validate_handler_is_called = 1;
776 }
777 /* tdm_error tdm_output_hwc_set_need_validate_handler(tdm_output *output,
778                                                                                  tdm_output_need_validate_handler hndl); */
779 TEST_F(TDMOutputHwc, SetNeedValidateHandlerFailNull)
780 {
781         error = tdm_output_hwc_set_need_validate_handler(NULL, &need_validate_handler);
782         ASSERT_NE(TDM_ERROR_NONE, error);
783
784         error = tdm_output_hwc_set_need_validate_handler(outputs[0], NULL);
785         ASSERT_NE(TDM_ERROR_NONE, error);
786
787 }
788
789 TEST_F(TDMOutputHwcWithoutHwcCap, SetNeedValidateHandlerFailNoHwc)
790 {
791         for (int i = 0; i < output_count; i++) {
792                 error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
793                 ASSERT_NE(TDM_ERROR_NONE, error);
794         }
795 }
796
797 TEST_F(TDMOutputHwc, SetNeedValidateHandlerSuccessful)
798 {
799         for (int i = 0; i < output_count; i++) {
800                 if (IsHwcEnable(i)) {
801                         /* test: first set*/
802                         error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
803                         ASSERT_EQ(TDM_ERROR_NONE, error);
804
805                         error = tdm_backend_trigger_need_validate_event(outputs[i]);
806                         ASSERT_EQ(TDM_ERROR_NONE, error);
807
808                         error = tdm_display_handle_events(dpy);
809                         ASSERT_EQ(TDM_ERROR_NONE, error);
810
811                         ASSERT_EQ(1, need_validate_handler_is_called);
812
813                         /* test: second isn't allowed*/
814                         error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
815                         ASSERT_NE(TDM_ERROR_NONE, error);
816                 } else {
817                         error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
818                         ASSERT_NE(TDM_ERROR_NONE, error);
819                 }
820         }
821 }
822