utest: Add 33 tests cases for tdm_helper
[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 extern "C" {
36 #include "tdm.h"
37 #include "tbm_bufmgr.h"
38 #include "tbm_drm_helper.h"
39 }
40
41 class TDMOutputHwc : public ::testing::Test {
42 protected:
43         tdm_display *dpy = NULL;
44         tbm_bufmgr tbm_bufmgr = NULL;
45         int master_fd = -42;
46         /*list of connected outputs*/
47         int output_count = 0;
48         const tdm_output_mode **preferred_mode_array = NULL;
49         tdm_output **outputs;
50         tdm_error error ;
51         virtual void SetEnv()
52         {
53                 setenv("TDM_DEBUG_MODULE", "all", 1);
54                 setenv("TDM_DEBUG", "1", 1);
55                 setenv("TDM_THREAD", "0", 1);
56                 setenv("TDM_COMMIT_PER_VBLANK", "1", 1);
57                 setenv("TDM_DLOG", "1", 1);
58                 setenv("TDM_HWC", "1", 1);
59                 setenv("XDG_RUNTIME_DIR", ".", 1);
60                 setenv("TBM_DLOG", "1", 1);
61                 setenv("TBM_DISPLAY_SERVER", "1", 1);
62         }
63
64         void UnsetEnv()
65         {
66                 unsetenv("TDM_DEBUG_MODULE");
67                 unsetenv("TDM_DEBUG");
68                 unsetenv("TDM_THREAD");
69                 unsetenv("TDM_COMMIT_PER_VBLANK");
70                 unsetenv("TDM_DLOG");
71                 unsetenv("TDM_HWC");
72                 unsetenv("XDG_RUNTIME_DIR");
73                 unsetenv("TBM_DLOG");
74                 unsetenv("TBM_DISPLAY_SERVER");
75         }
76
77         int IsHwcEnable(int i)
78         {
79                 tdm_output_capability capabilities = (tdm_output_capability)0;
80                 tdm_output_get_capabilities(outputs[i], &capabilities);
81                 return capabilities & TDM_OUTPUT_CAPABILITY_HWC;
82         }
83
84         tbm_surface_h CreateBufferForOutput(int i)
85         {
86                 int w = preferred_mode_array[i]->hdisplay;
87                 int h = preferred_mode_array[i]->vdisplay;
88                 return tbm_surface_internal_create_with_flags(w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
89         }
90
91         void SetUp(void)
92         {
93                 const tdm_output_mode *preferred_mode = NULL;
94                 tdm_error error = TDM_ERROR_NONE;
95                 int all_output_count = 0;
96
97                 SetEnv();
98
99                 /* FIXME: fix the error. If we initialize TBM before TDM we get fail
100                  * in the tdm_output_set_dpms */
101 #if 0
102                 tbm_bufmgr = tbm_bufmgr_init(-1);
103                 ASSERT_FALSE(tbm_bufmgr == NULL);
104 #endif
105
106                 dpy = tdm_display_init(&error);
107                 ASSERT_TRUE(error == TDM_ERROR_NONE);
108                 ASSERT_FALSE(dpy == NULL);
109
110                 master_fd = tbm_drm_helper_get_master_fd();
111                 ASSERT_TRUE(tdm_display_get_output_count(dpy, &all_output_count) == TDM_ERROR_NONE);
112
113                 outputs = (tdm_output **)calloc(all_output_count, sizeof(tdm_output *));
114                 ASSERT_FALSE(NULL == outputs);
115
116                 preferred_mode_array = (const tdm_output_mode **)calloc(all_output_count, sizeof(tdm_output_mode *));
117                 ASSERT_FALSE(NULL == preferred_mode_array);
118
119                 output_count = 0;
120
121                 for (int i = 0; i < all_output_count; i++) {
122                         tdm_output *output = tdm_display_get_output(dpy, i, &error);
123                         int output_modes_cnt = 0;
124                         const tdm_output_mode *output_modes;
125
126                         if (TDM_ERROR_NONE != error || NULL == output)
127                                 continue;
128
129                         tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
130                         if (TDM_ERROR_NONE != tdm_output_get_conn_status(output, &status))
131                                 continue;
132
133                         if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
134                                 continue;
135
136                         error = tdm_output_get_available_modes(output, &output_modes, &output_modes_cnt);
137                         if (TDM_ERROR_NONE != error)
138                                 continue;
139                         if (output_modes_cnt <= 0) {
140                                 continue;
141                         }
142
143                         for(int j = 0; j < output_modes_cnt; j++)
144                                 if(output_modes[j].type & TDM_OUTPUT_MODE_TYPE_PREFERRED)
145                                         preferred_mode = &output_modes[j];
146
147                         if (!preferred_mode)
148                                 continue;
149
150                         if (preferred_mode_array)
151                                 preferred_mode_array[output_count] = preferred_mode;
152                         if (outputs)
153                                 outputs[output_count] = output;
154                         output_count++;
155
156                         error = tdm_output_set_mode(output, preferred_mode);
157                         ASSERT_EQ(TDM_ERROR_NONE, error);
158                 }
159         }
160         void TearDown(void)
161         {
162                 tdm_display_deinit(dpy);
163                 dpy = NULL;
164                 tbm_bufmgr_deinit(tbm_bufmgr);
165                 tbm_bufmgr = NULL;
166                 if (outputs)
167                         free(outputs);
168                 if (preferred_mode_array)
169                         free(preferred_mode_array);
170                 if (master_fd > -1) {
171                         int temp_master_fd = tbm_drm_helper_get_master_fd();
172                         EXPECT_EQ(temp_master_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl;
173                         if (temp_master_fd > -1)
174                                 exit(1);
175                         close(master_fd);
176                 }
177
178                 UnsetEnv();
179         }
180
181 };
182
183 #define HWC_WIN_NUM 5
184 class TDMHwcWindow : public TDMOutputHwc {
185 protected:
186         tdm_hwc_window **hwc_wins;
187         int hwc_count;
188
189         void SetUp(void)
190         {
191                 hwc_count = 0;
192
193                 TDMOutputHwc::SetUp();
194                 hwc_wins = (tdm_hwc_window **)calloc(output_count * HWC_WIN_NUM, sizeof(tdm_hwc_window *));
195
196                 //create HWC_WIN_NUM hwc_windows for each outputs
197                 for (int i = 0; i < output_count; i++) {
198                         if (IsHwcEnable(i)) {
199                                 for (int j = 0; j < HWC_WIN_NUM; j++) {
200                                         tdm_hwc_window * hw = tdm_output_hwc_create_window(outputs[i], &error);
201                                         ASSERT_EQ(TDM_ERROR_NONE, error);
202                                         hwc_wins[hwc_count++] = hw;
203                                 }
204                         }
205                 }
206         }
207
208         void TearDown(void)
209         {
210                 for (int i = 0; i < hwc_count; i++) {
211                         tdm_output_hwc_destroy_window(outputs[0], hwc_wins[i]);
212                 }
213                 TDMOutputHwc::TearDown();
214         }
215
216 };
217
218 /* tdm_hwc_window * tdm_output_hwc_create_window(tdm_output *output, tdm_error *error); */
219 TEST_F(TDMOutputHwc, CreateWindowFailNull)
220 {
221         ASSERT_EQ(NULL, tdm_output_hwc_create_window(NULL, &error));
222         ASSERT_NE(TDM_ERROR_NONE, error);
223 }
224
225 TEST_F(TDMOutputHwc, CreateWindowSuccessful)
226 {
227         for (int i = 0; i < output_count; i++) {
228                 if (IsHwcEnable(i)) {
229                         tdm_hwc_window * hw = tdm_output_hwc_create_window(outputs[i], &error);
230                         ASSERT_EQ(TDM_ERROR_NONE, error);
231                         error = tdm_output_hwc_destroy_window(outputs[i], hw);
232                         ASSERT_EQ(TDM_ERROR_NONE, error);
233                 } else {
234                         ASSERT_EQ(NULL, tdm_output_hwc_create_window(outputs[i], &error));
235                         ASSERT_NE(TDM_ERROR_NONE, error);
236                 }
237         }
238 }
239
240
241 /* tdm_error tdm_output_hwc_destroy_window(tdm_output *output, tdm_hwc_window *hwc_window); */
242 TEST_F(TDMOutputHwc, DestroyWindowFailNull)
243 {
244         for (int i = 0; i < output_count; i++) {
245                 tdm_hwc_window * hw = NULL;
246
247                 if (IsHwcEnable(i)) {
248                         hw = tdm_output_hwc_create_window(outputs[i], &error);
249                         ASSERT_EQ(TDM_ERROR_NONE, error);
250                 }
251
252                 /* test: output is NULL*/
253                 error = tdm_output_hwc_destroy_window(NULL, hw);
254                 ASSERT_NE(TDM_ERROR_NONE, error);
255
256                 /* test: hw is NULL*/
257                 error = tdm_output_hwc_destroy_window(outputs[i], NULL);
258                 ASSERT_NE(TDM_ERROR_NONE, error);
259         }
260 }
261
262 TEST_F(TDMOutputHwc, DestroyWindowSuccessful)
263 {
264         tdm_hwc_window * hw;
265         for (int i = 0; i < output_count; i++) {
266                 if (IsHwcEnable(i)) {
267                         hw = tdm_output_hwc_create_window(outputs[i], &error);
268                         ASSERT_EQ(TDM_ERROR_NONE, error);
269                         error = tdm_output_hwc_destroy_window(outputs[i], hw);
270                         ASSERT_EQ(TDM_ERROR_NONE, error);
271                 }
272         }
273 }
274
275
276 /* tdm_error tdm_output_hwc_set_client_target_buffer(tdm_output *output,
277                                                                                  tbm_surface_h target_buffer, tdm_hwc_region damage); */
278 TEST_F(TDMOutputHwc, SetClientTargetBufferFailNullOutput)
279 {
280         tdm_hwc_region reg;
281         tbm_surface_h target_buff = CreateBufferForOutput(0);
282         error = tdm_output_hwc_set_client_target_buffer(NULL, target_buff, reg);
283         tbm_surface_internal_destroy(target_buff);
284         ASSERT_NE(TDM_ERROR_NONE, error);
285 }
286
287 TEST_F(TDMOutputHwc, SetClientTargetBufferSuccessfulSetBuff)
288 {
289         tdm_hwc_region damage;
290
291         for (int i = 0; i < output_count; i++) {
292                 tbm_surface_h target_buff = CreateBufferForOutput(i);
293                 ASSERT_NE(NULL, target_buff);
294                 if (IsHwcEnable(i)) {
295                         error = tdm_output_hwc_set_client_target_buffer(outputs[i], target_buff, damage);
296                         tbm_surface_internal_destroy(target_buff);
297                         ASSERT_EQ(TDM_ERROR_NONE, error);
298                 } else {
299                         error = tdm_output_hwc_set_client_target_buffer(outputs[i], target_buff, damage);
300                         tbm_surface_internal_destroy(target_buff);
301                         ASSERT_NE(TDM_ERROR_NONE, error);
302                 }
303         }
304 }
305
306 TEST_F(TDMOutputHwc, SetClientTargetBufferSuccessfulResetBuff)
307 {
308         tdm_hwc_region damage;
309
310         for (int i = 0; i < output_count; i++) {
311                 if (IsHwcEnable(i)) {
312                         error = tdm_output_hwc_set_client_target_buffer(outputs[i], NULL, damage);
313                         ASSERT_EQ(TDM_ERROR_NONE, error);
314                 } else {
315                         error = tdm_output_hwc_set_client_target_buffer(outputs[i], NULL, damage);
316                         ASSERT_NE(TDM_ERROR_NONE, error);
317                 }
318         }
319 }
320
321 /* tbm_surface_queue_h tdm_output_hwc_get_target_buffer_queue(tdm_output *output, tdm_error *error); */
322 TEST_F(TDMOutputHwc, GetTargetBufferQueueFailNullOutput)
323 {
324         tbm_surface_queue_h queue = NULL;
325
326         queue = tdm_output_hwc_get_target_buffer_queue(NULL, &error);
327         ASSERT_NE(TDM_ERROR_NONE, error);
328         ASSERT_EQ(NULL, queue);
329
330         queue = tdm_output_hwc_get_target_buffer_queue(NULL, NULL);
331         ASSERT_EQ(NULL, queue);
332 }
333
334 TEST_F(TDMOutputHwc, GetTargetBufferQueueSuccessful)
335 {
336         tbm_surface_queue_h queue = NULL;
337
338         for (int i = 0; i < output_count; i++) {
339                 if (IsHwcEnable(i)) {
340                         queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], &error);
341                         tbm_surface_queue_destroy(queue);
342                         ASSERT_EQ(TDM_ERROR_NONE, error);
343                         ASSERT_NE(NULL, queue);
344
345                         queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], NULL);
346                         tbm_surface_queue_destroy(queue);
347                         ASSERT_EQ(TDM_ERROR_NONE, error);
348                         ASSERT_NE(NULL, queue);
349                 } else {
350                         queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], &error);
351                         ASSERT_NE(TDM_ERROR_NONE, error);
352                         ASSERT_EQ(NULL, queue);
353
354                         queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], NULL);
355                         ASSERT_NE(TDM_ERROR_NONE, error);
356                         ASSERT_EQ(NULL, queue);
357                 }
358         }
359 }
360
361 /* tbm_surface_queue_h tdm_hwc_window_get_tbm_buffer_queue(tdm_hwc_window *hwc_window, tdm_error *error); */
362 TEST_F(TDMHwcWindow, GetBufferQueueFailNull)
363 {
364         tbm_surface_queue_h queue = NULL;
365
366         queue = tdm_hwc_window_get_tbm_buffer_queue(NULL, &error);
367         ASSERT_NE(TDM_ERROR_NONE, error);
368         ASSERT_EQ(NULL, queue);
369
370         queue = tdm_hwc_window_get_tbm_buffer_queue(NULL, NULL);
371         ASSERT_EQ(NULL, queue);
372 }
373
374 TEST_F(TDMHwcWindow, GetBufferQueueSuccessful)
375 {
376         tbm_surface_queue_h queue = NULL;
377         tdm_hwc_window_info info = { 0 };
378
379         info.src_config.format = TBM_FORMAT_ARGB8888;
380         info.src_config.size.h = info.src_config.size.v = 256;
381         info.src_config.pos.h = info.src_config.pos.w = 256;
382         info.dst_pos.h = info.dst_pos.w = 256;
383         info.transform = TDM_TRANSFORM_NORMAL;
384
385         for (int i = 0; i < hwc_count; i++) {
386                 error = tdm_hwc_window_set_info(hwc_wins[i], &info);
387                 ASSERT_EQ(TDM_ERROR_NONE, error);
388
389                 queue = tdm_hwc_window_get_tbm_buffer_queue(hwc_wins[i], &error);
390                 tbm_surface_queue_destroy(queue);
391                 ASSERT_EQ(TDM_ERROR_NONE, error);
392                 ASSERT_NE(NULL, queue);
393
394                 queue = tdm_hwc_window_get_tbm_buffer_queue(hwc_wins[i], NULL);
395                 tbm_surface_queue_destroy(queue);
396                 ASSERT_NE(NULL, queue);
397         }
398 }
399
400 /* tdm_error tdm_hwc_window_set_zpos(tdm_hwc_window *hwc_window, uint32_t zpos); */
401 TEST_F(TDMHwcWindow, SetZposFailNull)
402 {
403         error = tdm_hwc_window_set_zpos(NULL, 1);
404         ASSERT_NE(TDM_ERROR_NONE, error);
405 }
406
407 TEST_F(TDMHwcWindow, SetZposSuccessful)
408 {
409         for (int i = 0; i < hwc_count; i++) {
410                 error = tdm_hwc_window_set_zpos(hwc_wins[i], i);
411                 ASSERT_EQ(TDM_ERROR_NONE, error);
412         }
413 }
414
415 /* tdm_error tdm_hwc_window_set_composition_type(tdm_hwc_window *hwc_window,
416                                                                         tdm_hwc_window_composition composition_type); */
417 TEST_F(TDMHwcWindow, SetCompositionTypeFailNull)
418 {
419         error = tdm_hwc_window_set_composition_type(NULL, TDM_COMPOSITION_DEVICE);
420         ASSERT_NE(TDM_ERROR_NONE, error);
421 }
422
423 TEST_F(TDMHwcWindow, SetCompositionTypeSuccessful)
424 {
425         for (int i = 0; i < hwc_count; i++) {
426                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE);
427                 ASSERT_EQ(TDM_ERROR_NONE, error);
428                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_CLIENT);
429                 ASSERT_EQ(TDM_ERROR_NONE, error);
430                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_CURSOR);
431                 ASSERT_EQ(TDM_ERROR_NONE, error);
432                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_VIDEO);
433                 ASSERT_EQ(TDM_ERROR_NONE, error);
434         }
435 }
436
437 TEST_F(TDMHwcWindow, SetCompositionTypeFailInvalieCompositionType)
438 {
439         for (int i = 0; i < hwc_count; i++) {
440                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE_CANDIDATE);
441                 ASSERT_NE(TDM_ERROR_NONE, error);
442                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_CLIENT_CANDIDATE);
443                 ASSERT_NE(TDM_ERROR_NONE, error);
444                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], tdm_hwc_window_composition(TDM_COMPOSITION_CLIENT+1));
445                 ASSERT_NE(TDM_ERROR_NONE, error);
446         }
447 }
448
449 /* tdm_error tdm_hwc_window_set_buffer_damage(tdm_hwc_window *hwc_window, tdm_hwc_region damage); */
450 TEST_F(TDMHwcWindow, SetBufferDamageFailNullHwcWindow)
451 {
452         tdm_hwc_region damage;
453         error = tdm_hwc_window_set_buffer_damage(NULL, damage);
454         ASSERT_NE(TDM_ERROR_NONE, error);
455 }
456
457 TEST_F(TDMHwcWindow, SetBufferDamageFailNullDamageRects)
458 {
459         tdm_hwc_region damage = {.num_rects = 1, .rects = NULL};
460
461         for (int i = 0; i < hwc_count; i++) {
462                 error = tdm_hwc_window_set_buffer_damage(hwc_wins[i], damage);
463                 ASSERT_NE(TDM_ERROR_NONE, error);
464         }
465 }
466
467
468 TEST_F(TDMHwcWindow, SetBufferDamageSuccessful)
469 {
470         tdm_pos const rects[1] = {0};
471         tdm_hwc_region damage = {.num_rects = 1, .rects = rects};
472
473         for (int i = 0; i < hwc_count; i++) {
474                 error = tdm_hwc_window_set_buffer_damage(hwc_wins[i], damage);
475                 ASSERT_EQ(TDM_ERROR_NONE, error);
476         }
477 }
478
479
480 /* tdm_error tdm_hwc_window_set_info(tdm_hwc_window *hwc_window, tdm_hwc_window_info *info); */
481 TEST_F(TDMHwcWindow, SetInfoFailNull)
482 {
483         tdm_hwc_window_info info = { 0 };
484
485         error = tdm_hwc_window_set_info(NULL, &info);
486         ASSERT_NE(TDM_ERROR_NONE, error);
487
488         if (hwc_count > 0) {
489                 error = tdm_hwc_window_set_info(hwc_wins[0], NULL);
490                 ASSERT_NE(TDM_ERROR_NONE, error);
491         }
492 }
493 TEST_F(TDMHwcWindow, SetInfoSuccessful)
494 {
495         tdm_hwc_window_info info = { 0 };
496
497         for (int i = 0; i < hwc_count; i++) {
498                 error = tdm_hwc_window_set_info(hwc_wins[i], &info);
499                 ASSERT_EQ(TDM_ERROR_NONE, error);
500         }
501 }
502
503
504 /* tdm_error tdm_hwc_window_set_buffer(tdm_hwc_window *hwc_window, tbm_surface_h buffer); */
505 TEST_F(TDMHwcWindow, SetBufferFailNull)
506 {
507         error = tdm_hwc_window_set_buffer(NULL, NULL);
508         ASSERT_NE(TDM_ERROR_NONE, error);
509 }
510
511 TEST_F(TDMHwcWindow, SetBufferSuccessful)
512 {
513         for (int i = 0; i < hwc_count; i++) {
514
515                 tbm_surface_h buff = tbm_surface_create(256, 256, TBM_FORMAT_ARGB8888);
516
517                 /* test: set*/
518                 error = tdm_hwc_window_set_buffer(hwc_wins[i], buff);
519                 tbm_surface_destroy(buff);
520                 ASSERT_EQ(TDM_ERROR_NONE, error);
521
522                 /* test: reset*/
523                 error = tdm_hwc_window_set_buffer(hwc_wins[i], NULL);
524                 ASSERT_EQ(TDM_ERROR_NONE, error);
525         }
526 }
527
528 /* tdm_error tdm_hwc_window_set_flags(tdm_hwc_window *hwc_window, tdm_hwc_window_flag flags); */
529 TEST_F(TDMHwcWindow, SetFlagsFailNull)
530 {
531         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
532
533         error = tdm_hwc_window_set_flags(NULL, flag);
534         ASSERT_NE(TDM_ERROR_NONE, error);
535 }
536
537 TEST_F(TDMHwcWindow, SetFlagsSuccessful)
538 {
539         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
540
541         for (int i = 0; i < hwc_count; i++) {
542
543                 error = tdm_hwc_window_set_flags(hwc_wins[i], flag);
544                 ASSERT_EQ(TDM_ERROR_NONE, error);
545         }
546 }
547
548 /* tdm_error tdm_hwc_window_unset_flags(tdm_hwc_window *hwc_window, tdm_hwc_window_flag flags); */
549 TEST_F(TDMHwcWindow, UnsetFlagsFailNull)
550 {
551         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
552
553         error = tdm_hwc_window_unset_flags(NULL, flag);
554         ASSERT_NE(TDM_ERROR_NONE, error);
555 }
556
557 TEST_F(TDMHwcWindow, UnsetFlagsSuccessful)
558 {
559         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
560
561         for (int i = 0; i < hwc_count; i++) {
562
563                 error = tdm_hwc_window_unset_flags(hwc_wins[i], flag);
564                 ASSERT_EQ(TDM_ERROR_NONE, error);
565         }
566 }
567
568 /* tdm_error tdm_hwc_window_video_get_capability(tdm_hwc_window *hwc_window,
569                                                                         tdm_hwc_window_video_capability *video_capability); */
570 TEST_F(TDMHwcWindow, VideoGetCapabilityFailNull)
571 {
572         tdm_hwc_window_video_capability video_capability;
573
574         error = tdm_hwc_window_video_get_capability(NULL, &video_capability);
575         ASSERT_NE(TDM_ERROR_NONE, error);
576
577         if (hwc_count > 0) {
578                 error = tdm_hwc_window_video_get_capability(hwc_wins[0], NULL);
579                 ASSERT_NE(TDM_ERROR_NONE, error);
580         }
581
582 }
583
584 TEST_F(TDMHwcWindow, VideoGetCapabilitySuccessful)
585 {
586         tdm_hwc_window_video_capability video_capability;
587
588         for (int i = 0; i < hwc_count; i++) {
589                 /* hwc_window with TDM_COMPOSITION_CLIENT dosn't support tdm_hwc_window_video_get_capability()*/
590                 error = tdm_hwc_window_video_get_capability(hwc_wins[i],  &video_capability);
591                 ASSERT_NE(TDM_ERROR_NONE, error);
592
593                 /*TODO:: check video capability for TDM_COMPOSITION_VIDEO*/
594         }
595 }
596
597
598 /* tdm_error tdm_hwc_window_video_get_supported_format(tdm_hwc_window *hwc_window, const tbm_format **formats, int *count); */
599 TEST_F(TDMHwcWindow, VideoGetSupportedFormatFailNull)
600 {
601         const tbm_format *formats;
602         int count;
603
604         error = tdm_hwc_window_video_get_supported_format(NULL, &formats, &count);
605         ASSERT_NE(TDM_ERROR_NONE, error);
606
607         if (hwc_count > 0) {
608                 error = tdm_hwc_window_video_get_supported_format(hwc_wins[0], NULL, &count);
609                 error = tdm_hwc_window_video_get_supported_format(hwc_wins[0], &formats, NULL);
610         }
611 }
612
613 TEST_F(TDMHwcWindow, VideoGetSupportedFormatSuccessful)
614 {
615         const tbm_format *formats;
616         int count;
617
618         for (int i = 0; i < hwc_count; i++) {
619                 /* hwc_window with TDM_COMPOSITION_CLIENT dosn't support tdm_hwc_window_video_get_supported_format()*/
620                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_CLIENT);
621                 ASSERT_EQ(TDM_ERROR_NONE, error);
622                 error = tdm_hwc_window_video_get_supported_format(hwc_wins[i], &formats, &count);
623                 ASSERT_NE(TDM_ERROR_NONE, error);
624
625                 /*TODO:: check format for TDM_COMPOSITION_VIDEO*/
626         }
627 }
628
629 /* tdm_error tdm_output_hwc_validate(tdm_output *output, uint32_t *num_types); */
630 TEST_F(TDMOutputHwc, ValidateFailNull)
631 {
632         uint32_t num_types;
633         error = tdm_output_hwc_validate(NULL, &num_types);
634         ASSERT_NE(TDM_ERROR_NONE, error);
635
636         if (outputs[0]) {
637                 error = tdm_output_hwc_validate(outputs[0], NULL);
638                 ASSERT_NE(TDM_ERROR_NONE, error);
639         }
640 }
641
642 TEST_F(TDMOutputHwc, ValidateSuccessful)
643 {
644         uint32_t num_types;
645         for (int i = 0; i < output_count; i++) {
646                 if (IsHwcEnable(i)) {
647                         error = tdm_output_hwc_validate(outputs[i], &num_types);
648                         ASSERT_EQ(TDM_ERROR_NONE, error);
649                 } else {
650                         error = tdm_output_hwc_validate(outputs[i], &num_types);
651                         ASSERT_NE(TDM_ERROR_NONE, error);
652                 }
653         }
654 }
655
656 /* tdm_error tdm_output_hwc_get_changed_composition_types(tdm_output *output,
657                                                                                  uint32_t *num_elements, tdm_hwc_window **hwc_window,
658                                                                                  tdm_hwc_window_composition *composition_types); */
659
660 /* tdm_error tdm_output_hwc_accept_changes(tdm_output *output); */
661 TEST_F(TDMOutputHwc, GetChangedCompositionTypesFailNull)
662 {
663         uint32_t num_elements;
664
665         error = tdm_output_hwc_get_changed_composition_types(NULL, &num_elements, NULL, NULL);
666         ASSERT_NE(TDM_ERROR_NONE, error);
667
668         if (outputs[0]) {
669                 error = tdm_output_hwc_get_changed_composition_types(outputs[0], NULL, NULL, NULL);
670                 ASSERT_NE(TDM_ERROR_NONE, error);
671         }
672 }
673
674 TEST_F(TDMHwcWindow, GetChangedCompositionTypesSuccessful)
675 {
676         uint32_t validate_num;
677         uint32_t get_num = 0;
678
679         tdm_hwc_window_composition *composition_types;
680         tdm_hwc_window **hwc_wnds;
681
682         for (int i = 0; i < hwc_count; i++) {
683                 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE);
684                 ASSERT_EQ(TDM_ERROR_NONE, error);
685         }
686
687
688         for (int i = 0; i < output_count; i++) {
689                 if (IsHwcEnable(i)) {
690                         error = tdm_output_hwc_validate(outputs[i], &validate_num);
691                         ASSERT_EQ(TDM_ERROR_NONE, error);
692
693                         error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, NULL, NULL);
694                         ASSERT_EQ(TDM_ERROR_NONE, error);
695
696                         ASSERT_TRUE(get_num == validate_num);
697                         hwc_wnds = (tdm_hwc_window **)calloc(get_num, sizeof(tdm_hwc_window *));
698                         composition_types = (tdm_hwc_window_composition *)calloc(get_num, sizeof(tdm_hwc_window_composition));
699
700                         error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, hwc_wnds, composition_types);
701
702                         free(hwc_wnds);
703                         free(composition_types);
704                         ASSERT_EQ(TDM_ERROR_NONE, error);
705                 } else {
706                         error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, NULL, NULL);
707                         ASSERT_NE(TDM_ERROR_NONE, error);
708                 }
709         }
710 }
711
712 static void need_validate_handler(tdm_output *output)
713 {
714 }
715 /* tdm_error tdm_output_hwc_set_need_validate_handler(tdm_output *output,
716                                                                                  tdm_output_need_validate_handler hndl); */
717 TEST_F(TDMOutputHwc, SetNeedValidateHandlerFailNull)
718 {
719         error = tdm_output_hwc_set_need_validate_handler(NULL, &need_validate_handler);
720         ASSERT_NE(TDM_ERROR_NONE, error);
721
722         error = tdm_output_hwc_set_need_validate_handler(outputs[0], NULL);
723         ASSERT_NE(TDM_ERROR_NONE, error);
724
725 }
726 TEST_F(TDMOutputHwc, SetNeedValidateHandlerSuccessful)
727 {
728         for (int i = 0; i < output_count; i++) {
729                 if (IsHwcEnable(i)) {
730                         /* test: first set*/
731                         error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
732                         ASSERT_EQ(TDM_ERROR_NONE, error);
733
734                         /* test: second isn't allowed*/
735                         error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
736                         ASSERT_NE(TDM_ERROR_NONE, error);
737                 } else {
738                         error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
739                         ASSERT_NE(TDM_ERROR_NONE, error);
740                 }
741         }
742 }
743