hwc: add API function tdm_output_hwc_get_video_supported_formats
[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 TEST_F(TDMOutputHwc, SetClientTargetBufferFailNullOutput)
287 {
288         tdm_hwc_region reg;
289         tbm_surface_h target_buff = CreateBufferForOutput(0);
290         error = tdm_output_hwc_set_client_target_buffer(NULL, target_buff, reg);
291         tbm_surface_internal_destroy(target_buff);
292         ASSERT_NE(TDM_ERROR_NONE, error);
293 }
294
295 TEST_F(TDMOutputHwcWithoutHwcCap, SetClientTargetBufferFailNoHwc)
296 {
297         tdm_hwc_region damage;
298
299         for (int i = 0; i < output_count; i++) {
300                 tbm_surface_h target_buff = CreateBufferForOutput(i);
301                 ASSERT_NE(NULL, target_buff);
302                 error = tdm_output_hwc_set_client_target_buffer(outputs[i], target_buff, damage);
303                 tbm_surface_internal_destroy(target_buff);
304                 ASSERT_NE(TDM_ERROR_NONE, error);
305         }
306 }
307
308 TEST_F(TDMOutputHwc, SetClientTargetBufferSuccessfulSetBuff)
309 {
310         tdm_hwc_region damage;
311
312         for (int i = 0; i < output_count; i++) {
313                 tbm_surface_h target_buff = CreateBufferForOutput(i);
314                 ASSERT_NE(NULL, target_buff);
315                 if (IsHwcEnable(i)) {
316                         error = tdm_output_hwc_set_client_target_buffer(outputs[i], target_buff, damage);
317                         tbm_surface_internal_destroy(target_buff);
318                         ASSERT_EQ(TDM_ERROR_NONE, error);
319                 } else {
320                         error = tdm_output_hwc_set_client_target_buffer(outputs[i], target_buff, damage);
321                         tbm_surface_internal_destroy(target_buff);
322                         ASSERT_NE(TDM_ERROR_NONE, error);
323                 }
324         }
325 }
326
327 TEST_F(TDMOutputHwc, SetClientTargetBufferSuccessfulResetBuff)
328 {
329         tdm_hwc_region damage;
330
331         for (int i = 0; i < output_count; i++) {
332                 if (IsHwcEnable(i)) {
333                         error = tdm_output_hwc_set_client_target_buffer(outputs[i], NULL, damage);
334                         ASSERT_EQ(TDM_ERROR_NONE, error);
335                 } else {
336                         error = tdm_output_hwc_set_client_target_buffer(outputs[i], NULL, damage);
337                         ASSERT_NE(TDM_ERROR_NONE, error);
338                 }
339         }
340 }
341
342 /* tbm_surface_queue_h tdm_output_hwc_get_target_buffer_queue(tdm_output *output, tdm_error *error); */
343 TEST_F(TDMOutputHwc, GetTargetBufferQueueFailNullOutput)
344 {
345         tbm_surface_queue_h queue = NULL;
346
347         queue = tdm_output_hwc_get_target_buffer_queue(NULL, &error);
348         ASSERT_NE(TDM_ERROR_NONE, error);
349         ASSERT_EQ(NULL, queue);
350
351         queue = tdm_output_hwc_get_target_buffer_queue(NULL, NULL);
352         ASSERT_EQ(NULL, queue);
353 }
354
355 TEST_F(TDMOutputHwcWithoutHwcCap, GetTargetBufferQueueFainNoHwc)
356 {
357         tbm_surface_queue_h queue = NULL;
358
359         for (int i = 0; i < output_count; i++) {
360                 queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], &error);
361                 ASSERT_NE(TDM_ERROR_NONE, error);
362                 ASSERT_EQ(NULL, queue);
363         }
364 }
365
366 TEST_F(TDMOutputHwc, GetTargetBufferQueueSuccessful)
367 {
368         tbm_surface_queue_h queue = NULL;
369
370         for (int i = 0; i < output_count; i++) {
371                 if (IsHwcEnable(i)) {
372                         queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], &error);
373                         tbm_surface_queue_destroy(queue);
374                         ASSERT_EQ(TDM_ERROR_NONE, error);
375                         ASSERT_NE(NULL, queue);
376
377                         queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], NULL);
378                         tbm_surface_queue_destroy(queue);
379                         ASSERT_EQ(TDM_ERROR_NONE, error);
380                         ASSERT_NE(NULL, queue);
381                 } else {
382                         queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], &error);
383                         ASSERT_NE(TDM_ERROR_NONE, error);
384                         ASSERT_EQ(NULL, queue);
385
386                         queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], NULL);
387                         ASSERT_NE(TDM_ERROR_NONE, error);
388                         ASSERT_EQ(NULL, queue);
389                 }
390         }
391 }
392
393 /* tbm_surface_queue_h tdm_hwc_window_get_tbm_buffer_queue(tdm_hwc_window *hwc_window, tdm_error *error); */
394 TEST_F(TDMHwcWindow, GetBufferQueueFailNull)
395 {
396         tbm_surface_queue_h queue = NULL;
397
398         queue = tdm_hwc_window_get_tbm_buffer_queue(NULL, &error);
399         ASSERT_NE(TDM_ERROR_NONE, error);
400         ASSERT_EQ(NULL, queue);
401
402         queue = tdm_hwc_window_get_tbm_buffer_queue(NULL, NULL);
403         ASSERT_EQ(NULL, queue);
404 }
405
406 TEST_F(TDMHwcWindow, GetBufferQueueSuccessful)
407 {
408         tbm_surface_queue_h queue = NULL;
409         tdm_hwc_window_info info = { 0 };
410
411         info.src_config.format = TBM_FORMAT_ARGB8888;
412         info.src_config.size.h = info.src_config.size.v = 256;
413         info.src_config.pos.h = info.src_config.pos.w = 256;
414         info.dst_pos.h = info.dst_pos.w = 256;
415         info.transform = TDM_TRANSFORM_NORMAL;
416
417         for (int i = 0; i < hwc_count; i++) {
418                 error = tdm_hwc_window_set_info(hwc_wins[i], &info);
419                 ASSERT_EQ(TDM_ERROR_NONE, error);
420
421                 queue = tdm_hwc_window_get_tbm_buffer_queue(hwc_wins[i], &error);
422                 tbm_surface_queue_destroy(queue);
423                 ASSERT_EQ(TDM_ERROR_NONE, error);
424                 ASSERT_NE(NULL, queue);
425
426                 queue = tdm_hwc_window_get_tbm_buffer_queue(hwc_wins[i], NULL);
427                 tbm_surface_queue_destroy(queue);
428                 ASSERT_NE(NULL, queue);
429         }
430 }
431
432 /* tdm_error tdm_hwc_window_set_zpos(tdm_hwc_window *hwc_window, uint32_t zpos); */
433 TEST_F(TDMHwcWindow, SetZposFailNull)
434 {
435         error = tdm_hwc_window_set_zpos(NULL, 1);
436         ASSERT_NE(TDM_ERROR_NONE, error);
437 }
438
439 TEST_F(TDMHwcWindow, SetZposSuccessful)
440 {
441         for (int i = 0; i < hwc_count; i++) {
442                 error = tdm_hwc_window_set_zpos(hwc_wins[i], i);
443                 ASSERT_EQ(TDM_ERROR_NONE, error);
444         }
445 }
446
447 /* tdm_error tdm_hwc_window_set_composition_type(tdm_hwc_window *hwc_window,
448                                                                         tdm_hwc_window_composition composition_type); */
449 TEST_F(TDMHwcWindow, SetCompositionTypeFailNull)
450 {
451         error = tdm_hwc_window_set_composition_type(NULL, TDM_COMPOSITION_DEVICE);
452         ASSERT_NE(TDM_ERROR_NONE, error);
453 }
454
455 TEST_F(TDMHwcWindow, SetCompositionTypeSuccessful)
456 {
457         for (int i = 0; i < hwc_count; i++) {
458                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE);
459                 ASSERT_EQ(TDM_ERROR_NONE, error);
460                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_CLIENT);
461                 ASSERT_EQ(TDM_ERROR_NONE, error);
462                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_CURSOR);
463                 ASSERT_EQ(TDM_ERROR_NONE, error);
464                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_VIDEO);
465                 ASSERT_EQ(TDM_ERROR_NONE, error);
466         }
467 }
468
469 TEST_F(TDMHwcWindow, SetCompositionTypeFailInvalieCompositionType)
470 {
471         for (int i = 0; i < hwc_count; i++) {
472                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE_CANDIDATE);
473                 ASSERT_NE(TDM_ERROR_NONE, error);
474                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_CLIENT_CANDIDATE);
475                 ASSERT_NE(TDM_ERROR_NONE, error);
476                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], tdm_hwc_window_composition(TDM_COMPOSITION_CLIENT+1));
477                 ASSERT_NE(TDM_ERROR_NONE, error);
478         }
479 }
480
481 /* tdm_error tdm_hwc_window_set_buffer_damage(tdm_hwc_window *hwc_window, tdm_hwc_region damage); */
482 TEST_F(TDMHwcWindow, SetBufferDamageFailNullHwcWindow)
483 {
484         tdm_hwc_region damage;
485         error = tdm_hwc_window_set_buffer_damage(NULL, damage);
486         ASSERT_NE(TDM_ERROR_NONE, error);
487 }
488
489 TEST_F(TDMHwcWindow, SetBufferDamageFailNullDamageRects)
490 {
491         tdm_hwc_region damage = {.num_rects = 1, .rects = NULL};
492
493         for (int i = 0; i < hwc_count; i++) {
494                 error = tdm_hwc_window_set_buffer_damage(hwc_wins[i], damage);
495                 ASSERT_NE(TDM_ERROR_NONE, error);
496         }
497 }
498
499
500 TEST_F(TDMHwcWindow, SetBufferDamageSuccessful)
501 {
502         tdm_pos const rects[1] = {0};
503         tdm_hwc_region damage = {.num_rects = 1, .rects = rects};
504
505         for (int i = 0; i < hwc_count; i++) {
506                 error = tdm_hwc_window_set_buffer_damage(hwc_wins[i], damage);
507                 ASSERT_EQ(TDM_ERROR_NONE, error);
508         }
509 }
510
511
512 /* tdm_error tdm_hwc_window_set_info(tdm_hwc_window *hwc_window, tdm_hwc_window_info *info); */
513 TEST_F(TDMHwcWindow, SetInfoFailNull)
514 {
515         tdm_hwc_window_info info = { 0 };
516
517         error = tdm_hwc_window_set_info(NULL, &info);
518         ASSERT_NE(TDM_ERROR_NONE, error);
519
520         if (hwc_count > 0) {
521                 error = tdm_hwc_window_set_info(hwc_wins[0], NULL);
522                 ASSERT_NE(TDM_ERROR_NONE, error);
523         }
524 }
525 TEST_F(TDMHwcWindow, SetInfoSuccessful)
526 {
527         tdm_hwc_window_info info = { 0 };
528
529         for (int i = 0; i < hwc_count; i++) {
530                 error = tdm_hwc_window_set_info(hwc_wins[i], &info);
531                 ASSERT_EQ(TDM_ERROR_NONE, error);
532         }
533 }
534
535
536 /* tdm_error tdm_hwc_window_set_buffer(tdm_hwc_window *hwc_window, tbm_surface_h buffer); */
537 TEST_F(TDMHwcWindow, SetBufferFailNull)
538 {
539         error = tdm_hwc_window_set_buffer(NULL, NULL);
540         ASSERT_NE(TDM_ERROR_NONE, error);
541 }
542
543 TEST_F(TDMHwcWindow, SetBufferSuccessful)
544 {
545         for (int i = 0; i < hwc_count; i++) {
546
547                 tbm_surface_h buff = tbm_surface_create(256, 256, TBM_FORMAT_ARGB8888);
548
549                 /* test: set*/
550                 error = tdm_hwc_window_set_buffer(hwc_wins[i], buff);
551                 tbm_surface_destroy(buff);
552                 ASSERT_EQ(TDM_ERROR_NONE, error);
553
554                 /* test: reset*/
555                 error = tdm_hwc_window_set_buffer(hwc_wins[i], NULL);
556                 ASSERT_EQ(TDM_ERROR_NONE, error);
557         }
558 }
559
560 /* tdm_error tdm_hwc_window_set_flags(tdm_hwc_window *hwc_window, tdm_hwc_window_flag flags); */
561 TEST_F(TDMHwcWindow, SetFlagsFailNull)
562 {
563         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
564
565         error = tdm_hwc_window_set_flags(NULL, flag);
566         ASSERT_NE(TDM_ERROR_NONE, error);
567 }
568
569 TEST_F(TDMHwcWindow, SetFlagsSuccessful)
570 {
571         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
572
573         for (int i = 0; i < hwc_count; i++) {
574
575                 error = tdm_hwc_window_set_flags(hwc_wins[i], flag);
576                 ASSERT_EQ(TDM_ERROR_NONE, error);
577         }
578 }
579
580 /* tdm_error tdm_hwc_window_unset_flags(tdm_hwc_window *hwc_window, tdm_hwc_window_flag flags); */
581 TEST_F(TDMHwcWindow, UnsetFlagsFailNull)
582 {
583         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
584
585         error = tdm_hwc_window_unset_flags(NULL, flag);
586         ASSERT_NE(TDM_ERROR_NONE, error);
587 }
588
589 TEST_F(TDMHwcWindow, UnsetFlagsSuccessful)
590 {
591         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
592
593         for (int i = 0; i < hwc_count; i++) {
594
595                 error = tdm_hwc_window_unset_flags(hwc_wins[i], flag);
596                 ASSERT_EQ(TDM_ERROR_NONE, error);
597         }
598 }
599
600 /* tdm_error tdm_hwc_window_video_get_capability(tdm_hwc_window *hwc_window,
601                                                                         tdm_hwc_window_video_capability *video_capability); */
602 TEST_F(TDMHwcWindow, VideoGetCapabilityFailNull)
603 {
604         tdm_hwc_window_video_capability video_capability;
605
606         error = tdm_hwc_window_video_get_capability(NULL, &video_capability);
607         ASSERT_NE(TDM_ERROR_NONE, error);
608
609         if (hwc_count > 0) {
610                 error = tdm_hwc_window_video_get_capability(hwc_wins[0], NULL);
611                 ASSERT_NE(TDM_ERROR_NONE, error);
612         }
613
614 }
615
616 TEST_F(TDMHwcWindow, VideoGetCapabilitySuccessful)
617 {
618         tdm_hwc_window_video_capability video_capability;
619
620         for (int i = 0; i < hwc_count; i++) {
621                 /* hwc_window with TDM_COMPOSITION_CLIENT dosn't support tdm_hwc_window_video_get_capability()*/
622                 error = tdm_hwc_window_video_get_capability(hwc_wins[i],  &video_capability);
623                 ASSERT_NE(TDM_ERROR_NONE, error);
624
625                 /*TODO:: check video capability for TDM_COMPOSITION_VIDEO*/
626         }
627 }
628
629 /* tdm_error tdm_output_hwc_validate(tdm_output *output, uint32_t *num_types); */
630 TEST_F(TDMOutputHwc, ValidateFailNull)
631 {
632         uint32_t num_types;
633         error = tdm_output_hwc_validate(NULL, &num_types);
634         ASSERT_NE(TDM_ERROR_NONE, error);
635
636         if (outputs[0]) {
637                 error = tdm_output_hwc_validate(outputs[0], NULL);
638                 ASSERT_NE(TDM_ERROR_NONE, error);
639         }
640 }
641
642 TEST_F(TDMOutputHwcWithoutHwcCap, ValidateFailNoHwc)
643 {
644         uint32_t num_types;
645
646         for (int i = 0; i < output_count; i++) {
647                 error = tdm_output_hwc_validate(outputs[i], &num_types);
648                 ASSERT_NE(TDM_ERROR_NONE, error);
649         }
650 }
651
652 TEST_F(TDMOutputHwc, ValidateSuccessful)
653 {
654         uint32_t num_types;
655         for (int i = 0; i < output_count; i++) {
656                 if (IsHwcEnable(i)) {
657                         error = tdm_output_hwc_validate(outputs[i], &num_types);
658                         ASSERT_EQ(TDM_ERROR_NONE, error);
659                 } else {
660                         error = tdm_output_hwc_validate(outputs[i], &num_types);
661                         ASSERT_NE(TDM_ERROR_NONE, error);
662                 }
663         }
664 }
665
666 /* tdm_error tdm_output_hwc_get_changed_composition_types(tdm_output *output,
667                                                                                  uint32_t *num_elements, tdm_hwc_window **hwc_window,
668                                                                                  tdm_hwc_window_composition *composition_types); */
669
670 TEST_F(TDMOutputHwc, GetChangedCompositionTypesFailNull)
671 {
672         uint32_t num_elements;
673
674         error = tdm_output_hwc_get_changed_composition_types(NULL, &num_elements, NULL, NULL);
675         ASSERT_NE(TDM_ERROR_NONE, error);
676
677         if (outputs[0]) {
678                 error = tdm_output_hwc_get_changed_composition_types(outputs[0], NULL, NULL, NULL);
679                 ASSERT_NE(TDM_ERROR_NONE, error);
680         }
681 }
682
683 TEST_F(TDMOutputHwcWithoutHwcCap, GetChangedCompositionTypesFailNoHwc)
684 {
685         uint32_t get_num = 10;
686
687         for (int i = 0; i < output_count; i++) {
688                 error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, NULL, NULL);
689                 ASSERT_NE(TDM_ERROR_NONE, error);
690         }
691 }
692
693 TEST_F(TDMHwcWindow, GetChangedCompositionTypesSuccessful)
694 {
695         uint32_t validate_num;
696         uint32_t get_num = 0;
697
698         tdm_hwc_window_composition *composition_types;
699         tdm_hwc_window **hwc_wnds;
700
701         for (int i = 0; i < hwc_count; i++) {
702                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE);
703                 ASSERT_EQ(TDM_ERROR_NONE, error);
704         }
705
706
707         for (int i = 0; i < output_count; i++) {
708                 if (IsHwcEnable(i)) {
709                         error = tdm_output_hwc_validate(outputs[i], &validate_num);
710                         ASSERT_EQ(TDM_ERROR_NONE, error);
711
712                         error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, NULL, NULL);
713                         ASSERT_EQ(TDM_ERROR_NONE, error);
714
715                         ASSERT_TRUE(get_num == validate_num);
716                         hwc_wnds = (tdm_hwc_window **)calloc(get_num, sizeof(tdm_hwc_window *));
717                         composition_types = (tdm_hwc_window_composition *)calloc(get_num, sizeof(tdm_hwc_window_composition));
718
719                         error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, hwc_wnds, composition_types);
720
721                         free(hwc_wnds);
722                         free(composition_types);
723
724                         ASSERT_EQ(TDM_ERROR_NONE, error);
725                 } else {
726                         error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, NULL, NULL);
727                         ASSERT_NE(TDM_ERROR_NONE, error);
728                 }
729         }
730 }
731
732 /* tdm_error tdm_output_hwc_accept_changes(tdm_output *output); */
733
734 TEST_F(TDMOutputHwc, AcceptChangesFailNull)
735 {
736         error = tdm_output_hwc_accept_changes(NULL);
737         ASSERT_NE(TDM_ERROR_NONE, error);
738 }
739
740 TEST_F(TDMOutputHwcWithoutHwcCap, AcceptChangesFailNoHwc)
741 {
742         for (int i = 0; i < output_count; i++) {
743                 error = tdm_output_hwc_accept_changes(outputs[i]);
744                 ASSERT_NE(TDM_ERROR_NONE, error);
745         }
746 }
747
748 TEST_F(TDMHwcWindow, AcceptChangesSuccessful)
749 {
750         uint32_t validate_num;
751
752         for (int i = 0; i < hwc_count; i++) {
753                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE);
754                 ASSERT_EQ(TDM_ERROR_NONE, error);
755         }
756
757         for (int i = 0; i < output_count; i++) {
758                 if (IsHwcEnable(i)) {
759                         error = tdm_output_hwc_validate(outputs[i], &validate_num);
760                         ASSERT_EQ(TDM_ERROR_NONE, error);
761
762                         if (validate_num > 0) {
763                                 error =  tdm_output_hwc_accept_changes(outputs[i]);
764                                 ASSERT_EQ(TDM_ERROR_NONE, error);
765                         }
766                 }
767         }
768 }
769
770 static int need_validate_handler_is_called = 0;
771 static void need_validate_handler(tdm_output *output)
772 {
773         need_validate_handler_is_called = 1;
774 }
775 /* tdm_error tdm_output_hwc_set_need_validate_handler(tdm_output *output,
776                                                                                  tdm_output_need_validate_handler hndl); */
777 TEST_F(TDMOutputHwc, SetNeedValidateHandlerFailNull)
778 {
779         error = tdm_output_hwc_set_need_validate_handler(NULL, &need_validate_handler);
780         ASSERT_NE(TDM_ERROR_NONE, error);
781
782         error = tdm_output_hwc_set_need_validate_handler(outputs[0], NULL);
783         ASSERT_NE(TDM_ERROR_NONE, error);
784
785 }
786
787 TEST_F(TDMOutputHwcWithoutHwcCap, SetNeedValidateHandlerFailNoHwc)
788 {
789         for (int i = 0; i < output_count; i++) {
790                 error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
791                 ASSERT_NE(TDM_ERROR_NONE, error);
792         }
793 }
794
795 TEST_F(TDMOutputHwc, SetNeedValidateHandlerSuccessful)
796 {
797         for (int i = 0; i < output_count; i++) {
798                 if (IsHwcEnable(i)) {
799                         /* test: first set*/
800                         error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
801                         ASSERT_EQ(TDM_ERROR_NONE, error);
802
803                         error = tdm_backend_trigger_need_validate_event(outputs[i]);
804                         ASSERT_EQ(TDM_ERROR_NONE, error);
805
806                         error = tdm_display_handle_events(dpy);
807                         ASSERT_EQ(TDM_ERROR_NONE, error);
808
809                         ASSERT_EQ(1, need_validate_handler_is_called);
810
811                         /* test: second isn't allowed*/
812                         error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
813                         ASSERT_NE(TDM_ERROR_NONE, error);
814                 } else {
815                         error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
816                         ASSERT_NE(TDM_ERROR_NONE, error);
817                 }
818         }
819 }
820