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