aaa5d50766adf72ae8045df930f3c4c80efb5199
[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 <limits.h>
32 #include "gtest/gtest.h"
33 #include "ut_tdm.h"
34 #include "stdint.h"
35
36 #include "tdm.h"
37 #include "tdm_config.h"
38 #include "tdm_backend.h"
39 extern "C" {
40 #include "tbm_bufmgr.h"
41 #include "tbm_drm_helper.h"
42 }
43
44 class TDMOutputHwc : public ::testing::Test {
45 protected:
46         tdm_display *dpy = NULL;
47         tbm_bufmgr tbm_bufmgr = NULL;
48         int master_fd = -42;
49         /*list of connected outputs*/
50         int output_count = 0;
51         const tdm_output_mode **preferred_mode_array = NULL;
52         tdm_output **outputs;
53         tdm_error error ;
54         virtual void SetEnv()
55         {
56                 setenv("TDM_HWC", "1", 1);
57                 setenv("XDG_RUNTIME_DIR", "/run", 1);
58                 setenv("TBM_DISPLAY_SERVER", "1", 1);
59                 tdm_config_set_int(TDM_CONFIG_KEY_DEBUG_DLOG, 1);
60                 tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_THREAD, 1);
61                 tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_COMMIT_PER_VBLANK, 1);
62         }
63
64         void UnsetEnv()
65         {
66                 unsetenv("TDM_HWC");
67                 unsetenv("XDG_RUNTIME_DIR");
68                 unsetenv("TBM_DISPLAY_SERVER");
69         }
70
71         int IsHwcEnable(int i)
72         {
73                 tdm_output_capability capabilities = (tdm_output_capability)0;
74                 tdm_output_get_capabilities(outputs[i], &capabilities);
75                 return capabilities & TDM_OUTPUT_CAPABILITY_HWC;
76         }
77
78         tbm_surface_h CreateBufferForOutput(int i)
79         {
80                 int w = preferred_mode_array[i]->hdisplay;
81                 int h = preferred_mode_array[i]->vdisplay;
82                 return tbm_surface_internal_create_with_flags(w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
83         }
84
85         void SetUp(void)
86         {
87                 const tdm_output_mode *preferred_mode = NULL;
88                 tdm_error error = TDM_ERROR_NONE;
89                 int all_output_count = 0;
90                 outputs = NULL;
91
92                 SetEnv();
93
94                 /* FIXME: fix the error. If we initialize TBM before TDM we get fail
95                  * in the tdm_output_set_dpms */
96 #if 0
97                 tbm_bufmgr = tbm_bufmgr_init(-1);
98                 ASSERT_FALSE(tbm_bufmgr == NULL);
99 #endif
100
101                 dpy = tdm_display_init(&error);
102                 ASSERT_TRUE(error == TDM_ERROR_NONE);
103                 ASSERT_FALSE(dpy == NULL);
104
105                 master_fd = tbm_drm_helper_get_master_fd();
106                 ASSERT_TRUE(tdm_display_get_output_count(dpy, &all_output_count) == TDM_ERROR_NONE);
107
108                 outputs = (tdm_output **)calloc(all_output_count, sizeof(tdm_output *));
109                 ASSERT_FALSE(NULL == outputs);
110
111                 preferred_mode_array = (const tdm_output_mode **)calloc(all_output_count, sizeof(tdm_output_mode *));
112                 ASSERT_FALSE(NULL == preferred_mode_array);
113
114                 output_count = 0;
115
116                 for (int i = 0; i < all_output_count; i++) {
117                         tdm_output *output = tdm_display_get_output(dpy, i, &error);
118                         int output_modes_cnt = 0;
119                         const tdm_output_mode *output_modes;
120
121                         if (TDM_ERROR_NONE != error || NULL == output)
122                                 continue;
123
124                         tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
125                         if (TDM_ERROR_NONE != tdm_output_get_conn_status(output, &status))
126                                 continue;
127
128                         if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
129                                 continue;
130
131                         error = tdm_output_get_available_modes(output, &output_modes, &output_modes_cnt);
132                         if (TDM_ERROR_NONE != error)
133                                 continue;
134                         if (output_modes_cnt <= 0) {
135                                 continue;
136                         }
137
138                         for(int j = 0; j < output_modes_cnt; j++)
139                                 if(output_modes[j].type & TDM_OUTPUT_MODE_TYPE_PREFERRED)
140                                         preferred_mode = &output_modes[j];
141
142                         if (!preferred_mode)
143                                 continue;
144
145                         if (preferred_mode_array)
146                                 preferred_mode_array[output_count] = preferred_mode;
147                         if (outputs)
148                                 outputs[output_count] = output;
149                         output_count++;
150
151                         error = tdm_output_set_mode(output, preferred_mode);
152                         ASSERT_EQ(TDM_ERROR_NONE, error);
153                 }
154         }
155         void TearDown(void)
156         {
157                 tdm_display_deinit(dpy);
158                 dpy = NULL;
159                 tbm_bufmgr_deinit(tbm_bufmgr);
160                 tbm_bufmgr = NULL;
161                 if (outputs)
162                         free(outputs);
163                 if (preferred_mode_array)
164                         free(preferred_mode_array);
165                 if (master_fd > -1) {
166                         int temp_master_fd = tbm_drm_helper_get_master_fd();
167                         EXPECT_EQ(temp_master_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl;
168                         if (temp_master_fd > -1)
169                                 exit(1);
170                         close(master_fd);
171                 }
172
173                 UnsetEnv();
174         }
175 };
176
177 class TDMOutputHwcWithoutHwcCap : public TDMOutputHwc {
178         void SetEnv()
179         {
180                 TDMOutputHwc::SetEnv();
181                 setenv("TDM_HWC", "0", 1);
182         }
183 };
184
185 #define HWC_WIN_NUM 5
186 class TDMHwcWindow : public TDMOutputHwc {
187 protected:
188         tdm_hwc_window **hwc_wins;
189         tdm_hwc_window *video_hwc_win;
190         int hwc_count;
191
192         void SetUp(void)
193         {
194                 hwc_count = 0;
195                 video_hwc_win = NULL;
196
197                 TDMOutputHwc::SetUp();
198                 hwc_wins = (tdm_hwc_window **)calloc(output_count * HWC_WIN_NUM, sizeof(tdm_hwc_window *));
199
200                 //create HWC_WIN_NUM hwc_windows for each outputs
201                 for (int i = 0; i < output_count; i++) {
202                         if (IsHwcEnable(i)) {
203                                 for (int j = 0; j < HWC_WIN_NUM; j++) {
204                                         tdm_hwc_window * hw = tdm_output_hwc_create_window(outputs[i], &error);
205                                         ASSERT_EQ(TDM_ERROR_NONE, error);
206                                         hwc_wins[hwc_count++] = hw;
207                                 }
208                                 if (!video_hwc_win) {
209                                         video_hwc_win = tdm_output_hwc_create_video_window(outputs[i], &error);
210                                 }
211                         }
212                 }
213         }
214
215         void TearDown(void)
216         {
217                 for (int i = 0; i < hwc_count; i++) {
218                         tdm_output_hwc_destroy_window(outputs[0], hwc_wins[i]);
219                 }
220
221                 if (video_hwc_win)
222                         tdm_output_hwc_destroy_window(outputs[0], video_hwc_win);
223
224                 TDMOutputHwc::TearDown();
225         }
226
227 };
228
229 /* tdm_hwc_window * tdm_output_hwc_create_window(tdm_output *output, tdm_error *error); */
230 TEST_F(TDMOutputHwc, CreateWindowFailNull)
231 {
232         ASSERT_EQ(NULL, tdm_output_hwc_create_window(NULL, &error));
233         ASSERT_NE(TDM_ERROR_NONE, error);
234 }
235
236 TEST_F(TDMOutputHwc, CreateWindowSuccessful)
237 {
238         for (int i = 0; i < output_count; i++) {
239                 if (IsHwcEnable(i)) {
240                         tdm_hwc_window * hw = tdm_output_hwc_create_window(outputs[i], &error);
241                         ASSERT_EQ(TDM_ERROR_NONE, error);
242                         error = tdm_output_hwc_destroy_window(outputs[i], hw);
243                         ASSERT_EQ(TDM_ERROR_NONE, error);
244                 } else {
245                         ASSERT_EQ(NULL, tdm_output_hwc_create_window(outputs[i], &error));
246                         ASSERT_NE(TDM_ERROR_NONE, error);
247                 }
248         }
249 }
250
251
252 /* tdm_error tdm_output_hwc_destroy_window(tdm_output *output, tdm_hwc_window *hwc_window); */
253 TEST_F(TDMOutputHwc, DestroyWindowFailNull)
254 {
255         for (int i = 0; i < output_count; i++) {
256                 tdm_hwc_window * hw = NULL;
257
258                 if (IsHwcEnable(i)) {
259                         hw = tdm_output_hwc_create_window(outputs[i], &error);
260                         ASSERT_EQ(TDM_ERROR_NONE, error);
261                 }
262
263                 /* test: output is NULL*/
264                 error = tdm_output_hwc_destroy_window(NULL, hw);
265                 ASSERT_NE(TDM_ERROR_NONE, error);
266
267                 /* test: hw is NULL*/
268                 error = tdm_output_hwc_destroy_window(outputs[i], NULL);
269                 ASSERT_NE(TDM_ERROR_NONE, error);
270         }
271 }
272
273 TEST_F(TDMOutputHwc, DestroyWindowSuccessful)
274 {
275         tdm_hwc_window * hw;
276         for (int i = 0; i < output_count; i++) {
277                 if (IsHwcEnable(i)) {
278                         hw = tdm_output_hwc_create_window(outputs[i], &error);
279                         ASSERT_EQ(TDM_ERROR_NONE, error);
280                         error = tdm_output_hwc_destroy_window(outputs[i], hw);
281                         ASSERT_EQ(TDM_ERROR_NONE, error);
282                 }
283         }
284 }
285
286
287 /* tdm_error tdm_output_hwc_set_client_target_buffer(tdm_output *output,
288                                                                                  tbm_surface_h target_buffer, tdm_hwc_region damage,
289                                                                                  tdm_hwc_window *composited_wnds, uint32_t num_wnds); */
290 /* TDOO: need to be fixed
291 TEST_F(TDMOutputHwc, SetClientTargetBufferFailNullOutput)
292 {
293         tdm_hwc_region reg;
294         tbm_surface_h target_buff = CreateBufferForOutput(0);
295         error = tdm_output_hwc_set_client_target_buffer(NULL, target_buff, reg, NULL, 0 );
296         tbm_surface_internal_destroy(target_buff);
297         ASSERT_NE(TDM_ERROR_NONE, error);
298 }
299
300 TEST_F(TDMOutputHwcWithoutHwcCap, SetClientTargetBufferFailNoHwc)
301 {
302         tdm_hwc_region damage = {.num_rects = 0, .rects = NULL};
303
304         for (int i = 0; i < output_count; i++) {
305                 tbm_surface_h target_buff = CreateBufferForOutput(i);
306                 ASSERT_NE(NULL, target_buff);
307                 error = tdm_output_hwc_set_client_target_buffer(outputs[i], target_buff, damage, NULL, 0);
308                 tbm_surface_internal_destroy(target_buff);
309                 ASSERT_NE(TDM_ERROR_NONE, error);
310         }
311 }
312
313 TEST_F(TDMOutputHwc, SetClientTargetBufferSuccessfulSetBuff)
314 {
315         tdm_hwc_region damage = {.num_rects = 0, .rects = NULL};
316
317         for (int i = 0; i < output_count; i++) {
318                 tbm_surface_h target_buff = CreateBufferForOutput(i);
319                 ASSERT_NE(NULL, target_buff);
320                 if (IsHwcEnable(i)) {
321                         error = tdm_output_hwc_set_client_target_buffer(outputs[i], target_buff, damage,
322                                         NULL, 0);
323                         tbm_surface_internal_destroy(target_buff);
324                         ASSERT_EQ(TDM_ERROR_NONE, error);
325                 } else {
326                         error = tdm_output_hwc_set_client_target_buffer(outputs[i], target_buff, damage,
327                                         NULL, 0);
328                         tbm_surface_internal_destroy(target_buff);
329                         ASSERT_NE(TDM_ERROR_NONE, error);
330                 }
331         }
332 }
333
334 TEST_F(TDMOutputHwc, SetClientTargetBufferSuccessfulResetBuff)
335 {
336         tdm_hwc_region damage = {.num_rects = 0, .rects = NULL};
337
338         for (int i = 0; i < output_count; i++) {
339                 if (IsHwcEnable(i)) {
340                         error = tdm_output_hwc_set_client_target_buffer(outputs[i], NULL, damage,
341                                         NULL, 0);
342                         ASSERT_EQ(TDM_ERROR_NONE, error);
343                 } else {
344                         error = tdm_output_hwc_set_client_target_buffer(outputs[i], NULL, damage,
345                                         NULL, 0);
346                         ASSERT_NE(TDM_ERROR_NONE, error);
347                 }
348         }
349 }
350 */
351
352 /* tbm_surface_queue_h tdm_output_hwc_get_target_buffer_queue(tdm_output *output, tdm_error *error); */
353 TEST_F(TDMOutputHwc, GetTargetBufferQueueFailNullOutput)
354 {
355         tbm_surface_queue_h queue = NULL;
356
357         queue = tdm_output_hwc_get_target_buffer_queue(NULL, &error);
358         ASSERT_NE(TDM_ERROR_NONE, error);
359         ASSERT_EQ(NULL, queue);
360
361         queue = tdm_output_hwc_get_target_buffer_queue(NULL, NULL);
362         ASSERT_EQ(NULL, queue);
363 }
364
365 TEST_F(TDMOutputHwcWithoutHwcCap, GetTargetBufferQueueFainNoHwc)
366 {
367         tbm_surface_queue_h queue = NULL;
368
369         for (int i = 0; i < output_count; i++) {
370                 queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], &error);
371                 ASSERT_NE(TDM_ERROR_NONE, error);
372                 ASSERT_EQ(NULL, queue);
373         }
374 }
375
376 TEST_F(TDMOutputHwc, GetTargetBufferQueueSuccessful)
377 {
378         tbm_surface_queue_h queue = NULL;
379
380         for (int i = 0; i < output_count; i++) {
381                 if (IsHwcEnable(i)) {
382                         queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], &error);
383                         tbm_surface_queue_destroy(queue);
384                         ASSERT_EQ(TDM_ERROR_NONE, error);
385                         ASSERT_NE(NULL, queue);
386
387                         queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], NULL);
388                         tbm_surface_queue_destroy(queue);
389                         ASSERT_EQ(TDM_ERROR_NONE, error);
390                         ASSERT_NE(NULL, queue);
391                 } else {
392                         queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], &error);
393                         ASSERT_NE(TDM_ERROR_NONE, error);
394                         ASSERT_EQ(NULL, queue);
395
396                         queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], NULL);
397                         ASSERT_NE(TDM_ERROR_NONE, error);
398                         ASSERT_EQ(NULL, queue);
399                 }
400         }
401 }
402
403 /* tbm_surface_queue_h tdm_hwc_window_get_tbm_buffer_queue(tdm_hwc_window *hwc_window, tdm_error *error); */
404 TEST_F(TDMHwcWindow, GetBufferQueueFailNull)
405 {
406         tbm_surface_queue_h queue = NULL;
407
408         queue = tdm_hwc_window_get_tbm_buffer_queue(NULL, &error);
409         ASSERT_NE(TDM_ERROR_NONE, error);
410         ASSERT_EQ(NULL, queue);
411
412         queue = tdm_hwc_window_get_tbm_buffer_queue(NULL, NULL);
413         ASSERT_EQ(NULL, queue);
414 }
415
416 TEST_F(TDMHwcWindow, GetBufferQueueSuccessful)
417 {
418         tbm_surface_queue_h queue = NULL;
419         tdm_hwc_window_info info = { 0 };
420
421         info.src_config.format = TBM_FORMAT_ARGB8888;
422         info.src_config.size.h = info.src_config.size.v = 256;
423         info.src_config.pos.h = info.src_config.pos.w = 256;
424         info.dst_pos.h = info.dst_pos.w = 256;
425         info.transform = TDM_TRANSFORM_NORMAL;
426
427         for (int i = 0; i < hwc_count; i++) {
428                 error = tdm_hwc_window_set_info(hwc_wins[i], &info);
429                 ASSERT_EQ(TDM_ERROR_NONE, error);
430
431                 queue = tdm_hwc_window_get_tbm_buffer_queue(hwc_wins[i], &error);
432                 tbm_surface_queue_destroy(queue);
433                 ASSERT_EQ(TDM_ERROR_NONE, error);
434                 ASSERT_NE(NULL, queue);
435
436                 queue = tdm_hwc_window_get_tbm_buffer_queue(hwc_wins[i], NULL);
437                 tbm_surface_queue_destroy(queue);
438                 ASSERT_NE(NULL, queue);
439         }
440 }
441
442 /* tdm_error tdm_hwc_window_set_composition_type(tdm_hwc_window *hwc_window,
443                                                                         tdm_hwc_window_composition composition_type); */
444 TEST_F(TDMHwcWindow, SetCompositionTypeFailNull)
445 {
446         error = tdm_hwc_window_set_composition_type(NULL, TDM_COMPOSITION_DEVICE);
447         ASSERT_NE(TDM_ERROR_NONE, error);
448 }
449
450 TEST_F(TDMHwcWindow, SetCompositionTypeSuccessful)
451 {
452         for (int i = 0; i < hwc_count; i++) {
453                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE);
454                 ASSERT_EQ(TDM_ERROR_NONE, error);
455                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_CLIENT);
456                 ASSERT_EQ(TDM_ERROR_NONE, error);
457                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_CURSOR);
458                 ASSERT_EQ(TDM_ERROR_NONE, error);
459         }
460 }
461
462 TEST_F(TDMHwcWindow, SetCompositionTypeFailInvalieCompositionType)
463 {
464         for (int i = 0; i < hwc_count; i++) {
465                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], tdm_hwc_window_composition(TDM_COMPOSITION_NONE-1));
466                 ASSERT_NE(TDM_ERROR_NONE, error);
467         }
468 }
469
470 /* tdm_error tdm_hwc_window_set_buffer_damage(tdm_hwc_window *hwc_window, tdm_hwc_region damage); */
471 TEST_F(TDMHwcWindow, SetBufferDamageFailNullHwcWindow)
472 {
473         tdm_hwc_region damage = {.num_rects = 0, .rects = NULL};
474
475         error = tdm_hwc_window_set_buffer_damage(NULL, damage);
476         ASSERT_NE(TDM_ERROR_NONE, error);
477 }
478
479 TEST_F(TDMHwcWindow, SetBufferDamageFailNullDamageRects)
480 {
481         tdm_hwc_region damage = {.num_rects = 1, .rects = NULL};
482
483         for (int i = 0; i < hwc_count; i++) {
484                 error = tdm_hwc_window_set_buffer_damage(hwc_wins[i], damage);
485                 ASSERT_NE(TDM_ERROR_NONE, error);
486         }
487 }
488
489
490 TEST_F(TDMHwcWindow, SetBufferDamageSuccessful)
491 {
492         tdm_pos const rects[1] = {0};
493         tdm_hwc_region damage = {.num_rects = 1, .rects = rects};
494
495         for (int i = 0; i < hwc_count; i++) {
496                 error = tdm_hwc_window_set_buffer_damage(hwc_wins[i], damage);
497                 ASSERT_EQ(TDM_ERROR_NONE, error);
498         }
499 }
500
501
502 /* tdm_error tdm_hwc_window_set_info(tdm_hwc_window *hwc_window, tdm_hwc_window_info *info); */
503 TEST_F(TDMHwcWindow, SetInfoFailNull)
504 {
505         tdm_hwc_window_info info = { 0 };
506
507         error = tdm_hwc_window_set_info(NULL, &info);
508         ASSERT_NE(TDM_ERROR_NONE, error);
509
510         if (hwc_count > 0) {
511                 error = tdm_hwc_window_set_info(hwc_wins[0], NULL);
512                 ASSERT_NE(TDM_ERROR_NONE, error);
513         }
514 }
515 TEST_F(TDMHwcWindow, SetInfoSuccessful)
516 {
517         tdm_hwc_window_info info = { 0 };
518
519         for (int i = 0; i < hwc_count; i++) {
520                 error = tdm_hwc_window_set_info(hwc_wins[i], &info);
521                 ASSERT_EQ(TDM_ERROR_NONE, error);
522         }
523 }
524
525
526 /* tdm_error tdm_hwc_window_set_buffer(tdm_hwc_window *hwc_window, tbm_surface_h buffer); */
527 TEST_F(TDMHwcWindow, SetBufferFailNull)
528 {
529         error = tdm_hwc_window_set_buffer(NULL, NULL);
530         ASSERT_NE(TDM_ERROR_NONE, error);
531 }
532
533 TEST_F(TDMHwcWindow, SetBufferSuccessful)
534 {
535         for (int i = 0; i < hwc_count; i++) {
536
537                 tbm_surface_h buff = tbm_surface_create(256, 256, TBM_FORMAT_ARGB8888);
538
539                 /* test: set*/
540                 error = tdm_hwc_window_set_buffer(hwc_wins[i], buff);
541                 tbm_surface_destroy(buff);
542                 ASSERT_EQ(TDM_ERROR_NONE, error);
543
544                 /* test: reset*/
545                 error = tdm_hwc_window_set_buffer(hwc_wins[i], NULL);
546                 ASSERT_EQ(TDM_ERROR_NONE, error);
547         }
548 }
549
550 /* tdm_error tdm_hwc_window_set_flags(tdm_hwc_window *hwc_window, tdm_hwc_window_flag flags); */
551 TEST_F(TDMHwcWindow, SetFlagsFailNull)
552 {
553         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
554
555         error = tdm_hwc_window_set_flags(NULL, flag);
556         ASSERT_NE(TDM_ERROR_NONE, error);
557 }
558
559 TEST_F(TDMHwcWindow, SetFlagsSuccessful)
560 {
561         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
562
563         for (int i = 0; i < hwc_count; i++) {
564
565                 error = tdm_hwc_window_set_flags(hwc_wins[i], flag);
566                 ASSERT_TRUE(TDM_ERROR_NONE == error || TDM_ERROR_NOT_IMPLEMENTED == error);
567         }
568 }
569
570 /* tdm_error tdm_hwc_window_unset_flags(tdm_hwc_window *hwc_window, tdm_hwc_window_flag flags); */
571 TEST_F(TDMHwcWindow, UnsetFlagsFailNull)
572 {
573         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
574
575         error = tdm_hwc_window_unset_flags(NULL, flag);
576         ASSERT_NE(TDM_ERROR_NONE, error);
577 }
578
579 TEST_F(TDMHwcWindow, UnsetFlagsSuccessful)
580 {
581         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
582
583         for (int i = 0; i < hwc_count; i++) {
584
585                 error = tdm_hwc_window_unset_flags(hwc_wins[i], flag);
586                 ASSERT_TRUE(TDM_ERROR_NONE == error || TDM_ERROR_NOT_IMPLEMENTED == error);
587         }
588 }
589
590 /* tdm_error tdm_hwc_window_video_get_capability(tdm_hwc_window *hwc_window,
591                                                                         tdm_hwc_window_video_capability *video_capability); */
592 TEST_F(TDMHwcWindow, VideoGetCapabilityFailNull)
593 {
594         tdm_hwc_window_video_capability video_capability;
595
596         error = tdm_hwc_window_video_get_capability(NULL, &video_capability);
597         ASSERT_NE(TDM_ERROR_NONE, error);
598
599         if (hwc_count > 0) {
600                 error = tdm_hwc_window_video_get_capability(hwc_wins[0], NULL);
601                 ASSERT_NE(TDM_ERROR_NONE, error);
602         }
603
604 }
605
606 TEST_F(TDMHwcWindow, VideoGetCapabilitySuccessful)
607 {
608         tdm_hwc_window_video_capability video_capability;
609
610         for (int i = 0; i < hwc_count; i++) {
611                 /* hwc_window with TDM_COMPOSITION_CLIENT dosn't support tdm_hwc_window_video_get_capability()*/
612                 error = tdm_hwc_window_video_get_capability(hwc_wins[i], &video_capability);
613                 ASSERT_NE(TDM_ERROR_NONE, error);
614
615                 if (video_hwc_win != NULL) {
616                         error = tdm_hwc_window_video_get_capability(video_hwc_win, &video_capability);
617                         ASSERT_TRUE(TDM_ERROR_NONE == error || TDM_ERROR_NOT_IMPLEMENTED == error);
618                 }
619         }
620 }
621
622 /* tdm_error tdm_output_hwc_validate(tdm_output *output, tdm_hwc_window **composited_wnds, uint32_t num_wnds,
623                                         uint32_t *num_types); */
624 /* TODO: fix the validate test later.
625 TEST_F(TDMOutputHwc, ValidateFailNull)
626 {
627         uint32_t num_types;
628         error = tdm_output_hwc_validate(NULL, NULL, 0, &num_types);
629         ASSERT_NE(TDM_ERROR_NONE, error);
630
631         if (outputs[0]) {
632                 error = tdm_output_hwc_validate(outputs[0], NULL, 0, NULL);
633                 ASSERT_NE(TDM_ERROR_NONE, error);
634         }
635 }
636
637 TEST_F(TDMOutputHwcWithoutHwcCap, ValidateFailNoHwc)
638 {
639         uint32_t num_types;
640
641         for (int i = 0; i < output_count; i++) {
642                 error = tdm_output_hwc_validate(outputs[i], &num_types);
643                 ASSERT_NE(TDM_ERROR_NONE, error);
644         }
645 }
646
647 TEST_F(TDMOutputHwc, ValidateSuccessful)
648 {
649         uint32_t num_types;
650         for (int i = 0; i < output_count; i++) {
651                 if (IsHwcEnable(i)) {
652                         error = tdm_output_hwc_validate(outputs[i], &num_types);
653                         ASSERT_EQ(TDM_ERROR_NONE, error);
654                 } else {
655                         error = tdm_output_hwc_validate(outputs[i], &num_types);
656                         ASSERT_NE(TDM_ERROR_NONE, error);
657                 }
658         }
659 }
660 TODO: */
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 /* TODO: fix the validate test later.
690 TEST_F(TDMHwcWindow, GetChangedCompositionTypesSuccessful)
691 {
692         uint32_t validate_num;
693         uint32_t get_num = 0;
694
695         tdm_hwc_window_composition *composition_types;
696         tdm_hwc_window **hwc_wnds;
697
698         for (int i = 0; i < hwc_count; i++) {
699                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE);
700                 ASSERT_EQ(TDM_ERROR_NONE, error);
701         }
702
703
704         for (int i = 0; i < output_count; i++) {
705                 if (IsHwcEnable(i)) {
706                         error = tdm_output_hwc_validate(outputs[i], &validate_num);
707                         ASSERT_EQ(TDM_ERROR_NONE, error);
708
709                         error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, NULL, NULL);
710                         ASSERT_EQ(TDM_ERROR_NONE, error);
711
712                         ASSERT_TRUE(get_num == validate_num);
713                         hwc_wnds = (tdm_hwc_window **)calloc(get_num, sizeof(tdm_hwc_window *));
714                         composition_types = (tdm_hwc_window_composition *)calloc(get_num, sizeof(tdm_hwc_window_composition));
715
716                         error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, hwc_wnds, composition_types);
717
718                         free(hwc_wnds);
719                         free(composition_types);
720
721                         ASSERT_EQ(TDM_ERROR_NONE, error);
722                 } else {
723                         error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, NULL, NULL);
724                         ASSERT_NE(TDM_ERROR_NONE, error);
725                 }
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 /* TODO: fix the validate test later.
747 TEST_F(TDMHwcWindow, AcceptChangesSuccessful)
748 {
749         uint32_t validate_num;
750
751         for (int i = 0; i < hwc_count; i++) {
752                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE);
753                 ASSERT_EQ(TDM_ERROR_NONE, error);
754         }
755
756         for (int i = 0; i < output_count; i++) {
757                 if (IsHwcEnable(i)) {
758                         error = tdm_output_hwc_validate(outputs[i], &validate_num);
759                         ASSERT_EQ(TDM_ERROR_NONE, error);
760
761                         if (validate_num > 0) {
762                                 error =  tdm_output_hwc_accept_changes(outputs[i]);
763                                 ASSERT_EQ(TDM_ERROR_NONE, error);
764                         }
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                         /*
800                          * This event can't be generated form user side.
801                          * So just check a set and double set
802                          */
803
804                         /* test: first set*/
805                         error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
806                         ASSERT_EQ(TDM_ERROR_NONE, error);
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
817 /* tdm_hwc_window * tdm_output_hwc_create_video_window(tdm_output *output, tdm_error *error); */
818 TEST_F(TDMOutputHwc, CreateVideoWindowFailNull)
819 {
820         ASSERT_EQ(NULL, tdm_output_hwc_create_video_window(NULL, &error));
821         ASSERT_NE(TDM_ERROR_NONE, error);
822 }
823
824 TEST_F(TDMOutputHwc, CreateVideoWindowSuccessful)
825 {
826         for (int i = 0; i < output_count; i++) {
827                 if (IsHwcEnable(i)) {
828                         tdm_hwc_window * hw = tdm_output_hwc_create_video_window(outputs[i], &error);
829                         if (error != TDM_ERROR_NOT_IMPLEMENTED) {
830                                 ASSERT_EQ(TDM_ERROR_NONE, error);
831                                 ASSERT_NE(NULL, hw);
832                                 error = tdm_output_hwc_destroy_window(outputs[i], hw);
833                                 ASSERT_EQ(TDM_ERROR_NONE, error);
834                         }
835                 } else {
836                         ASSERT_EQ(NULL, tdm_output_hwc_create_video_window(outputs[i], &error));
837                         ASSERT_NE(TDM_ERROR_NONE, error);
838                 }
839         }
840 }
841
842 /* tdm_output_hwc_get_video_supported_formats() */
843 TEST_F(TDMOutputHwc, GetVideoSupportedFormatsFailNull)
844 {
845         tdm_error error;
846
847         error = tdm_output_hwc_get_video_supported_formats(NULL, NULL, NULL);
848         ASSERT_NE(TDM_ERROR_NONE, error);
849 }
850
851 TEST_F(TDMOutputHwc, GetVideoSupportedFormatsSuccessful)
852 {
853         tdm_error error;
854         const tbm_format *formats;
855         int count;
856
857         for (int i = 0; i < output_count; i++) {
858                 if (IsHwcEnable(i)) {
859                         error = tdm_output_hwc_get_video_supported_formats(outputs[i], &formats, &count);
860                         if (error != TDM_ERROR_NOT_IMPLEMENTED) {
861                                 ASSERT_EQ(TDM_ERROR_NONE, error);
862                                 if (count > 0)
863                                         ASSERT_NE(NULL, formats);
864                         }
865                 } else {
866                         error = tdm_output_hwc_get_video_supported_formats(outputs[i], &formats, &count);
867                         ASSERT_NE(TDM_ERROR_NONE, error);
868                 }
869         }
870 }
871
872 /* tdm_hwc_window_video_get_available_properties() */
873 TEST_F(TDMHwcWindow, GetAvailablePropertiesFailNullWin)
874 {
875         SKIP_FLAG(video_hwc_win != NULL);
876         const tdm_prop *props;
877         int count;
878
879         error = tdm_hwc_window_video_get_available_properties(NULL, &props, &count);
880         ASSERT_NE(TDM_ERROR_NONE, error);
881
882         error = tdm_hwc_window_video_get_available_properties(video_hwc_win, NULL, &count);
883         ASSERT_NE(TDM_ERROR_NONE, error);
884
885         error = tdm_hwc_window_video_get_available_properties(video_hwc_win, &props, NULL);
886         ASSERT_NE(TDM_ERROR_NONE, error);
887 }
888
889 TEST_F(TDMHwcWindow, GetAvailablePropertiesSuccess)
890 {
891         SKIP_FLAG(video_hwc_win != NULL);
892
893         const tdm_prop *props;
894         int count;
895
896         error = tdm_hwc_window_video_get_available_properties(video_hwc_win, &props, &count);
897         ASSERT_TRUE(TDM_ERROR_NONE == error || TDM_ERROR_NOT_IMPLEMENTED == error);
898 }
899
900 /* tdm_hwc_window_video_get_property() */
901 TEST_F(TDMHwcWindow, GetPropertyFailNull)
902 {
903         SKIP_FLAG(video_hwc_win != NULL);
904
905         tdm_value value;
906         int id = 1;
907
908         error = tdm_hwc_window_video_get_property(NULL, id, &value);
909         ASSERT_NE(TDM_ERROR_NONE, error);
910
911         error = tdm_hwc_window_video_get_property(video_hwc_win, id, NULL);
912         ASSERT_NE(TDM_ERROR_NONE, error);
913 }
914
915 TEST_F(TDMHwcWindow, GetPropertyFailWrongId)
916 {
917         SKIP_FLAG(video_hwc_win != NULL);
918
919         tdm_value value;
920         int id = INT_MAX;
921
922         error = tdm_hwc_window_video_get_property(video_hwc_win, id, &value);
923         ASSERT_NE(TDM_ERROR_NONE, error);
924 }
925
926 /* tdm_hwc_window_video_set_property() */
927 TEST_F(TDMHwcWindow, SetPropertyFailNull)
928 {
929         SKIP_FLAG(video_hwc_win != NULL);
930         tdm_value value;
931         int id = 1;
932
933         error = tdm_hwc_window_video_set_property(NULL, id, value);
934         ASSERT_NE(TDM_ERROR_NONE, error);
935 }
936
937 TEST_F(TDMHwcWindow, SetPropertyFailWrongId)
938 {
939         SKIP_FLAG(video_hwc_win != NULL);
940
941         tdm_value value;
942         int id = INT_MAX;
943
944         error = tdm_hwc_window_video_set_property(video_hwc_win, id, value);
945         ASSERT_NE(TDM_ERROR_NONE, error);
946 }
947