hwc: add the API function tdm_output_hwc_create_video_window instead of TDM_COMPOSITI...
[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         }
465 }
466
467 TEST_F(TDMHwcWindow, SetCompositionTypeFailInvalieCompositionType)
468 {
469         for (int i = 0; i < hwc_count; i++) {
470                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE_CANDIDATE);
471                 ASSERT_NE(TDM_ERROR_NONE, error);
472                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_CLIENT_CANDIDATE);
473                 ASSERT_NE(TDM_ERROR_NONE, error);
474                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], tdm_hwc_window_composition(TDM_COMPOSITION_CLIENT+1));
475                 ASSERT_NE(TDM_ERROR_NONE, error);
476         }
477 }
478
479 /* tdm_error tdm_hwc_window_set_buffer_damage(tdm_hwc_window *hwc_window, tdm_hwc_region damage); */
480 TEST_F(TDMHwcWindow, SetBufferDamageFailNullHwcWindow)
481 {
482         tdm_hwc_region damage;
483         error = tdm_hwc_window_set_buffer_damage(NULL, damage);
484         ASSERT_NE(TDM_ERROR_NONE, error);
485 }
486
487 TEST_F(TDMHwcWindow, SetBufferDamageFailNullDamageRects)
488 {
489         tdm_hwc_region damage = {.num_rects = 1, .rects = NULL};
490
491         for (int i = 0; i < hwc_count; i++) {
492                 error = tdm_hwc_window_set_buffer_damage(hwc_wins[i], damage);
493                 ASSERT_NE(TDM_ERROR_NONE, error);
494         }
495 }
496
497
498 TEST_F(TDMHwcWindow, SetBufferDamageSuccessful)
499 {
500         tdm_pos const rects[1] = {0};
501         tdm_hwc_region damage = {.num_rects = 1, .rects = rects};
502
503         for (int i = 0; i < hwc_count; i++) {
504                 error = tdm_hwc_window_set_buffer_damage(hwc_wins[i], damage);
505                 ASSERT_EQ(TDM_ERROR_NONE, error);
506         }
507 }
508
509
510 /* tdm_error tdm_hwc_window_set_info(tdm_hwc_window *hwc_window, tdm_hwc_window_info *info); */
511 TEST_F(TDMHwcWindow, SetInfoFailNull)
512 {
513         tdm_hwc_window_info info = { 0 };
514
515         error = tdm_hwc_window_set_info(NULL, &info);
516         ASSERT_NE(TDM_ERROR_NONE, error);
517
518         if (hwc_count > 0) {
519                 error = tdm_hwc_window_set_info(hwc_wins[0], NULL);
520                 ASSERT_NE(TDM_ERROR_NONE, error);
521         }
522 }
523 TEST_F(TDMHwcWindow, SetInfoSuccessful)
524 {
525         tdm_hwc_window_info info = { 0 };
526
527         for (int i = 0; i < hwc_count; i++) {
528                 error = tdm_hwc_window_set_info(hwc_wins[i], &info);
529                 ASSERT_EQ(TDM_ERROR_NONE, error);
530         }
531 }
532
533
534 /* tdm_error tdm_hwc_window_set_buffer(tdm_hwc_window *hwc_window, tbm_surface_h buffer); */
535 TEST_F(TDMHwcWindow, SetBufferFailNull)
536 {
537         error = tdm_hwc_window_set_buffer(NULL, NULL);
538         ASSERT_NE(TDM_ERROR_NONE, error);
539 }
540
541 TEST_F(TDMHwcWindow, SetBufferSuccessful)
542 {
543         for (int i = 0; i < hwc_count; i++) {
544
545                 tbm_surface_h buff = tbm_surface_create(256, 256, TBM_FORMAT_ARGB8888);
546
547                 /* test: set*/
548                 error = tdm_hwc_window_set_buffer(hwc_wins[i], buff);
549                 tbm_surface_destroy(buff);
550                 ASSERT_EQ(TDM_ERROR_NONE, error);
551
552                 /* test: reset*/
553                 error = tdm_hwc_window_set_buffer(hwc_wins[i], NULL);
554                 ASSERT_EQ(TDM_ERROR_NONE, error);
555         }
556 }
557
558 /* tdm_error tdm_hwc_window_set_flags(tdm_hwc_window *hwc_window, tdm_hwc_window_flag flags); */
559 TEST_F(TDMHwcWindow, SetFlagsFailNull)
560 {
561         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
562
563         error = tdm_hwc_window_set_flags(NULL, flag);
564         ASSERT_NE(TDM_ERROR_NONE, error);
565 }
566
567 TEST_F(TDMHwcWindow, SetFlagsSuccessful)
568 {
569         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
570
571         for (int i = 0; i < hwc_count; i++) {
572
573                 error = tdm_hwc_window_set_flags(hwc_wins[i], flag);
574                 ASSERT_EQ(TDM_ERROR_NONE, error);
575         }
576 }
577
578 /* tdm_error tdm_hwc_window_unset_flags(tdm_hwc_window *hwc_window, tdm_hwc_window_flag flags); */
579 TEST_F(TDMHwcWindow, UnsetFlagsFailNull)
580 {
581         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
582
583         error = tdm_hwc_window_unset_flags(NULL, flag);
584         ASSERT_NE(TDM_ERROR_NONE, error);
585 }
586
587 TEST_F(TDMHwcWindow, UnsetFlagsSuccessful)
588 {
589         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
590
591         for (int i = 0; i < hwc_count; i++) {
592
593                 error = tdm_hwc_window_unset_flags(hwc_wins[i], flag);
594                 ASSERT_EQ(TDM_ERROR_NONE, error);
595         }
596 }
597
598 /* tdm_error tdm_hwc_window_video_get_capability(tdm_hwc_window *hwc_window,
599                                                                         tdm_hwc_window_video_capability *video_capability); */
600 TEST_F(TDMHwcWindow, VideoGetCapabilityFailNull)
601 {
602         tdm_hwc_window_video_capability video_capability;
603
604         error = tdm_hwc_window_video_get_capability(NULL, &video_capability);
605         ASSERT_NE(TDM_ERROR_NONE, error);
606
607         if (hwc_count > 0) {
608                 error = tdm_hwc_window_video_get_capability(hwc_wins[0], NULL);
609                 ASSERT_NE(TDM_ERROR_NONE, error);
610         }
611
612 }
613
614 TEST_F(TDMHwcWindow, VideoGetCapabilitySuccessful)
615 {
616         tdm_hwc_window_video_capability video_capability;
617
618         for (int i = 0; i < hwc_count; i++) {
619                 /* hwc_window with TDM_COMPOSITION_CLIENT dosn't support tdm_hwc_window_video_get_capability()*/
620                 error = tdm_hwc_window_video_get_capability(hwc_wins[i],  &video_capability);
621                 ASSERT_NE(TDM_ERROR_NONE, error);
622
623                 /*TODO:: check video capability for TDM_COMPOSITION_VIDEO*/
624         }
625 }
626
627 /* tdm_error tdm_output_hwc_validate(tdm_output *output, uint32_t *num_types); */
628 TEST_F(TDMOutputHwc, ValidateFailNull)
629 {
630         uint32_t num_types;
631         error = tdm_output_hwc_validate(NULL, &num_types);
632         ASSERT_NE(TDM_ERROR_NONE, error);
633
634         if (outputs[0]) {
635                 error = tdm_output_hwc_validate(outputs[0], NULL);
636                 ASSERT_NE(TDM_ERROR_NONE, error);
637         }
638 }
639
640 TEST_F(TDMOutputHwcWithoutHwcCap, ValidateFailNoHwc)
641 {
642         uint32_t num_types;
643
644         for (int i = 0; i < output_count; i++) {
645                 error = tdm_output_hwc_validate(outputs[i], &num_types);
646                 ASSERT_NE(TDM_ERROR_NONE, error);
647         }
648 }
649
650 TEST_F(TDMOutputHwc, ValidateSuccessful)
651 {
652         uint32_t num_types;
653         for (int i = 0; i < output_count; i++) {
654                 if (IsHwcEnable(i)) {
655                         error = tdm_output_hwc_validate(outputs[i], &num_types);
656                         ASSERT_EQ(TDM_ERROR_NONE, error);
657                 } else {
658                         error = tdm_output_hwc_validate(outputs[i], &num_types);
659                         ASSERT_NE(TDM_ERROR_NONE, error);
660                 }
661         }
662 }
663
664 /* tdm_error tdm_output_hwc_get_changed_composition_types(tdm_output *output,
665                                                                                  uint32_t *num_elements, tdm_hwc_window **hwc_window,
666                                                                                  tdm_hwc_window_composition *composition_types); */
667
668 TEST_F(TDMOutputHwc, GetChangedCompositionTypesFailNull)
669 {
670         uint32_t num_elements;
671
672         error = tdm_output_hwc_get_changed_composition_types(NULL, &num_elements, NULL, NULL);
673         ASSERT_NE(TDM_ERROR_NONE, error);
674
675         if (outputs[0]) {
676                 error = tdm_output_hwc_get_changed_composition_types(outputs[0], NULL, NULL, NULL);
677                 ASSERT_NE(TDM_ERROR_NONE, error);
678         }
679 }
680
681 TEST_F(TDMOutputHwcWithoutHwcCap, GetChangedCompositionTypesFailNoHwc)
682 {
683         uint32_t get_num = 10;
684
685         for (int i = 0; i < output_count; i++) {
686                 error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, NULL, NULL);
687                 ASSERT_NE(TDM_ERROR_NONE, error);
688         }
689 }
690
691 TEST_F(TDMHwcWindow, GetChangedCompositionTypesSuccessful)
692 {
693         uint32_t validate_num;
694         uint32_t get_num = 0;
695
696         tdm_hwc_window_composition *composition_types;
697         tdm_hwc_window **hwc_wnds;
698
699         for (int i = 0; i < hwc_count; i++) {
700                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE);
701                 ASSERT_EQ(TDM_ERROR_NONE, error);
702         }
703
704
705         for (int i = 0; i < output_count; i++) {
706                 if (IsHwcEnable(i)) {
707                         error = tdm_output_hwc_validate(outputs[i], &validate_num);
708                         ASSERT_EQ(TDM_ERROR_NONE, error);
709
710                         error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, NULL, NULL);
711                         ASSERT_EQ(TDM_ERROR_NONE, error);
712
713                         ASSERT_TRUE(get_num == validate_num);
714                         hwc_wnds = (tdm_hwc_window **)calloc(get_num, sizeof(tdm_hwc_window *));
715                         composition_types = (tdm_hwc_window_composition *)calloc(get_num, sizeof(tdm_hwc_window_composition));
716
717                         error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, hwc_wnds, composition_types);
718
719                         free(hwc_wnds);
720                         free(composition_types);
721
722                         ASSERT_EQ(TDM_ERROR_NONE, error);
723                 } else {
724                         error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, NULL, NULL);
725                         ASSERT_NE(TDM_ERROR_NONE, error);
726                 }
727         }
728 }
729
730 /* tdm_error tdm_output_hwc_accept_changes(tdm_output *output); */
731
732 TEST_F(TDMOutputHwc, AcceptChangesFailNull)
733 {
734         error = tdm_output_hwc_accept_changes(NULL);
735         ASSERT_NE(TDM_ERROR_NONE, error);
736 }
737
738 TEST_F(TDMOutputHwcWithoutHwcCap, AcceptChangesFailNoHwc)
739 {
740         for (int i = 0; i < output_count; i++) {
741                 error = tdm_output_hwc_accept_changes(outputs[i]);
742                 ASSERT_NE(TDM_ERROR_NONE, error);
743         }
744 }
745
746 TEST_F(TDMHwcWindow, AcceptChangesSuccessful)
747 {
748         uint32_t validate_num;
749
750         for (int i = 0; i < hwc_count; i++) {
751                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE);
752                 ASSERT_EQ(TDM_ERROR_NONE, error);
753         }
754
755         for (int i = 0; i < output_count; i++) {
756                 if (IsHwcEnable(i)) {
757                         error = tdm_output_hwc_validate(outputs[i], &validate_num);
758                         ASSERT_EQ(TDM_ERROR_NONE, error);
759
760                         if (validate_num > 0) {
761                                 error =  tdm_output_hwc_accept_changes(outputs[i]);
762                                 ASSERT_EQ(TDM_ERROR_NONE, error);
763                         }
764                 }
765         }
766 }
767
768 static int need_validate_handler_is_called = 0;
769 static void need_validate_handler(tdm_output *output)
770 {
771         need_validate_handler_is_called = 1;
772 }
773 /* tdm_error tdm_output_hwc_set_need_validate_handler(tdm_output *output,
774                                                                                  tdm_output_need_validate_handler hndl); */
775 TEST_F(TDMOutputHwc, SetNeedValidateHandlerFailNull)
776 {
777         error = tdm_output_hwc_set_need_validate_handler(NULL, &need_validate_handler);
778         ASSERT_NE(TDM_ERROR_NONE, error);
779
780         error = tdm_output_hwc_set_need_validate_handler(outputs[0], NULL);
781         ASSERT_NE(TDM_ERROR_NONE, error);
782
783 }
784
785 TEST_F(TDMOutputHwcWithoutHwcCap, SetNeedValidateHandlerFailNoHwc)
786 {
787         for (int i = 0; i < output_count; i++) {
788                 error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
789                 ASSERT_NE(TDM_ERROR_NONE, error);
790         }
791 }
792
793 TEST_F(TDMOutputHwc, SetNeedValidateHandlerSuccessful)
794 {
795         for (int i = 0; i < output_count; i++) {
796                 if (IsHwcEnable(i)) {
797                         /* test: first set*/
798                         error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
799                         ASSERT_EQ(TDM_ERROR_NONE, error);
800
801                         error = tdm_backend_trigger_need_validate_event(outputs[i]);
802                         ASSERT_EQ(TDM_ERROR_NONE, error);
803
804                         error = tdm_display_handle_events(dpy);
805                         ASSERT_EQ(TDM_ERROR_NONE, error);
806
807                         ASSERT_EQ(1, need_validate_handler_is_called);
808
809                         /* test: second isn't allowed*/
810                         error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
811                         ASSERT_NE(TDM_ERROR_NONE, error);
812                 } else {
813                         error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
814                         ASSERT_NE(TDM_ERROR_NONE, error);
815                 }
816         }
817 }
818