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