rename to tdm_log_printf
[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 "ut_tdm.h"
32
33 #define HWC_WIN_NUM 5
34
35 class TDMHwcWindow : public TDMOutput
36 {
37 public:
38         TDMHwcWindow();
39         void SetUp(void);
40         void TearDown(void);
41
42         tdm_error error;
43         tdm_hwc_window **hwc_wins;
44         tdm_hwc_window *video_hwc_win;
45         int hwc_count;
46 };
47
48 TDMHwcWindow::TDMHwcWindow()
49 {
50         error = TDM_ERROR_NONE;
51         hwc_wins = NULL;
52         hwc_count = 0;
53         video_hwc_win = NULL;
54 }
55
56 void TDMHwcWindow::SetUp(void)
57 {
58         tdm_hwc_window *hw = NULL;
59
60         TDMOutput::SetUp();
61
62         hwc_wins = (tdm_hwc_window **)calloc(output_count * HWC_WIN_NUM, sizeof(tdm_hwc_window *));
63
64         //create HWC_WIN_NUM hwc_windows for each outputs
65         for (int o = 0; o < output_count; o++) {
66                 if (ut_tdm_output_is_hwc_enable(outputs[o])) {
67                         for (int w = 0; w < HWC_WIN_NUM; w++) {
68                                 hw = tdm_output_hwc_create_window(outputs[w], &error);
69                                 ASSERT_EQ(TDM_ERROR_NONE, error);
70                                 hwc_wins[hwc_count++] = hw;
71                         }
72
73                         if (!video_hwc_win)
74                                 video_hwc_win = tdm_output_hwc_create_video_window(outputs[o], &error);
75                 }
76         }
77 }
78
79 void TDMHwcWindow::TearDown(void)
80 {
81         for (int w = 0; w < hwc_count; w++)
82                 tdm_output_hwc_destroy_window(outputs[0], hwc_wins[w]);
83
84         if (video_hwc_win)
85                 tdm_output_hwc_destroy_window(outputs[0], video_hwc_win);
86
87         TDMOutput::TearDown();
88 }
89
90 /* tdm_error tdm_output_hwc_destroy_window(tdm_output *output, tdm_hwc_window *hwc_window); */
91 TEST_P(TDMHwcWindow, DestroyWindowFailNull)
92 {
93         TDM_UT_SKIP_FLAG(has_outputs);
94
95         for (int o = 0; o < output_count; o++) {
96                 if (ut_tdm_output_is_hwc_enable(outputs[o])) {
97                         /* test: hw is NULL*/
98                         error = tdm_output_hwc_destroy_window(outputs[o], NULL);
99                         ASSERT_NE(TDM_ERROR_NONE, error);
100                 }
101         }
102 }
103
104 TEST_P(TDMHwcWindow, DestroyWindowSuccessful)
105 {
106         TDM_UT_SKIP_FLAG(has_outputs);
107
108         tdm_hwc_window *hw = NULL;
109
110         for (int o = 0; o < output_count; o++) {
111                 if (ut_tdm_output_is_hwc_enable(outputs[o])) {
112                         hw = tdm_output_hwc_create_window(outputs[o], &error);
113                         ASSERT_EQ(TDM_ERROR_NONE, error);
114                         error = tdm_output_hwc_destroy_window(outputs[o], hw);
115                         ASSERT_EQ(TDM_ERROR_NONE, error);
116                 }
117         }
118 }
119
120
121 /* tbm_surface_queue_h tdm_hwc_window_get_tbm_buffer_queue(tdm_hwc_window *hwc_window, tdm_error *error); */
122 TEST_P(TDMHwcWindow, GetBufferQueueFailNull)
123 {
124         TDM_UT_SKIP_FLAG(has_outputs);
125
126         tbm_surface_queue_h queue = NULL;
127
128         queue = tdm_hwc_window_get_tbm_buffer_queue(NULL, &error);
129         ASSERT_NE(TDM_ERROR_NONE, error);
130         ASSERT_EQ(NULL, queue);
131
132         queue = tdm_hwc_window_get_tbm_buffer_queue(NULL, NULL);
133         ASSERT_EQ(NULL, queue);
134 }
135
136 TEST_P(TDMHwcWindow, GetBufferQueueSuccessful)
137 {
138         TDM_UT_SKIP_FLAG(has_outputs);
139
140         tbm_surface_queue_h queue = NULL;
141         tdm_hwc_window_info info = { 0 };
142
143         info.src_config.format = TBM_FORMAT_ARGB8888;
144         info.src_config.size.h = info.src_config.size.v = 256;
145         info.src_config.pos.h = info.src_config.pos.w = 256;
146         info.dst_pos.h = info.dst_pos.w = 256;
147         info.transform = TDM_TRANSFORM_NORMAL;
148
149         for (int w = 0; w < hwc_count; w++) {
150                 error = tdm_hwc_window_set_info(hwc_wins[w], &info);
151                 ASSERT_EQ(TDM_ERROR_NONE, error);
152
153                 queue = tdm_hwc_window_get_tbm_buffer_queue(hwc_wins[w], &error);
154                 tbm_surface_queue_destroy(queue);
155                 ASSERT_EQ(TDM_ERROR_NONE, error);
156                 ASSERT_NE(NULL, queue);
157
158                 queue = tdm_hwc_window_get_tbm_buffer_queue(hwc_wins[w], NULL);
159                 tbm_surface_queue_destroy(queue);
160                 ASSERT_NE(NULL, queue);
161         }
162 }
163
164 /* tdm_error tdm_hwc_window_set_composition_type(tdm_hwc_window *hwc_window,
165                                                                         tdm_hwc_window_composition composition_type); */
166 TEST_P(TDMHwcWindow, SetCompositionTypeFailNull)
167 {
168         TDM_UT_SKIP_FLAG(has_outputs);
169
170         error = tdm_hwc_window_set_composition_type(NULL, TDM_COMPOSITION_DEVICE);
171         ASSERT_NE(TDM_ERROR_NONE, error);
172 }
173
174 TEST_P(TDMHwcWindow, SetCompositionTypeSuccessful)
175 {
176         TDM_UT_SKIP_FLAG(has_outputs);
177
178         for (int w = 0; w < hwc_count; w++) {
179                 error = tdm_hwc_window_set_composition_type(hwc_wins[w], TDM_COMPOSITION_DEVICE);
180                 ASSERT_EQ(TDM_ERROR_NONE, error);
181                 error = tdm_hwc_window_set_composition_type(hwc_wins[w], TDM_COMPOSITION_CLIENT);
182                 ASSERT_EQ(TDM_ERROR_NONE, error);
183                 error = tdm_hwc_window_set_composition_type(hwc_wins[w], TDM_COMPOSITION_CURSOR);
184                 ASSERT_EQ(TDM_ERROR_NONE, error);
185         }
186 }
187
188 TEST_P(TDMHwcWindow, SetCompositionTypeFailInvalieCompositionType)
189 {
190         TDM_UT_SKIP_FLAG(has_outputs);
191
192         for (int w = 0; w < hwc_count; w++) {
193                 error = tdm_hwc_window_set_composition_type(hwc_wins[w], tdm_hwc_window_composition(TDM_COMPOSITION_NONE - 1));
194                 ASSERT_NE(TDM_ERROR_NONE, error);
195         }
196 }
197
198 /* tdm_error tdm_hwc_window_set_buffer_damage(tdm_hwc_window *hwc_window, tdm_hwc_region damage); */
199 TEST_P(TDMHwcWindow, SetBufferDamageFailNullHwcWindow)
200 {
201         TDM_UT_SKIP_FLAG(has_outputs);
202
203         tdm_hwc_region damage = {.num_rects = 0, .rects = NULL};
204
205         error = tdm_hwc_window_set_buffer_damage(NULL, damage);
206         ASSERT_NE(TDM_ERROR_NONE, error);
207 }
208
209 TEST_P(TDMHwcWindow, SetBufferDamageFailNullDamageRects)
210 {
211         TDM_UT_SKIP_FLAG(has_outputs);
212
213         tdm_hwc_region damage = {.num_rects = 1, .rects = NULL};
214
215         for (int w = 0; w < hwc_count; w++) {
216                 error = tdm_hwc_window_set_buffer_damage(hwc_wins[w], damage);
217                 ASSERT_NE(TDM_ERROR_NONE, error);
218         }
219 }
220
221
222 TEST_P(TDMHwcWindow, SetBufferDamageSuccessful)
223 {
224         TDM_UT_SKIP_FLAG(has_outputs);
225
226         tdm_pos const rects[1] = {0};
227         tdm_hwc_region damage = {.num_rects = 1, .rects = rects};
228
229         for (int w = 0; w < hwc_count; w++) {
230                 error = tdm_hwc_window_set_buffer_damage(hwc_wins[w], damage);
231                 ASSERT_EQ(TDM_ERROR_NONE, error);
232         }
233 }
234
235
236 /* tdm_error tdm_hwc_window_set_info(tdm_hwc_window *hwc_window, tdm_hwc_window_info *info); */
237 TEST_P(TDMHwcWindow, SetInfoFailNull)
238 {
239         TDM_UT_SKIP_FLAG(has_outputs);
240
241         tdm_hwc_window_info info = { 0 };
242
243         error = tdm_hwc_window_set_info(NULL, &info);
244         ASSERT_NE(TDM_ERROR_NONE, error);
245
246         if (hwc_count > 0) {
247                 error = tdm_hwc_window_set_info(hwc_wins[0], NULL);
248                 ASSERT_NE(TDM_ERROR_NONE, error);
249         }
250 }
251
252 TEST_P(TDMHwcWindow, SetInfoSuccessful)
253 {
254         TDM_UT_SKIP_FLAG(has_outputs);
255
256         tdm_hwc_window_info info = { 0 };
257
258         for (int w = 0; w < hwc_count; w++) {
259                 error = tdm_hwc_window_set_info(hwc_wins[w], &info);
260                 ASSERT_EQ(TDM_ERROR_NONE, error);
261         }
262 }
263
264
265 /* tdm_error tdm_hwc_window_set_buffer(tdm_hwc_window *hwc_window, tbm_surface_h buffer); */
266 TEST_P(TDMHwcWindow, SetBufferFailNull)
267 {
268         TDM_UT_SKIP_FLAG(has_outputs);
269
270         error = tdm_hwc_window_set_buffer(NULL, NULL);
271         ASSERT_NE(TDM_ERROR_NONE, error);
272 }
273
274 TEST_P(TDMHwcWindow, SetBufferSuccessful)
275 {
276         TDM_UT_SKIP_FLAG(has_outputs);
277
278         for (int w = 0; w < hwc_count; w++) {
279
280                 tbm_surface_h buff = tbm_surface_create(256, 256, TBM_FORMAT_ARGB8888);
281
282                 /* test: set*/
283                 error = tdm_hwc_window_set_buffer(hwc_wins[w], buff);
284                 tbm_surface_destroy(buff);
285                 ASSERT_EQ(TDM_ERROR_NONE, error);
286
287                 /* test: reset*/
288                 error = tdm_hwc_window_set_buffer(hwc_wins[w], NULL);
289                 ASSERT_EQ(TDM_ERROR_NONE, error);
290         }
291 }
292
293 /* tdm_error tdm_hwc_window_set_flags(tdm_hwc_window *hwc_window, tdm_hwc_window_flag flags); */
294 TEST_P(TDMHwcWindow, SetFlagsFailNull)
295 {
296         TDM_UT_SKIP_FLAG(has_outputs);
297
298         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
299
300         error = tdm_hwc_window_set_flags(NULL, flag);
301         ASSERT_NE(TDM_ERROR_NONE, error);
302 }
303
304 TEST_P(TDMHwcWindow, SetFlagsSuccessful)
305 {
306         TDM_UT_SKIP_FLAG(has_outputs);
307
308         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
309
310         for (int w = 0; w < hwc_count; w++) {
311
312                 error = tdm_hwc_window_set_flags(hwc_wins[w], flag);
313                 ASSERT_TRUE(TDM_ERROR_NONE == error || TDM_ERROR_NOT_IMPLEMENTED == error);
314         }
315 }
316
317 /* tdm_error tdm_hwc_window_unset_flags(tdm_hwc_window *hwc_window, tdm_hwc_window_flag flags); */
318 TEST_P(TDMHwcWindow, UnsetFlagsFailNull)
319 {
320         TDM_UT_SKIP_FLAG(has_outputs);
321
322         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
323
324         error = tdm_hwc_window_unset_flags(NULL, flag);
325         ASSERT_NE(TDM_ERROR_NONE, error);
326 }
327
328 TEST_P(TDMHwcWindow, UnsetFlagsSuccessful)
329 {
330         TDM_UT_SKIP_FLAG(has_outputs);
331
332         tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
333
334         for (int w = 0; w < hwc_count; w++) {
335
336                 error = tdm_hwc_window_unset_flags(hwc_wins[w], flag);
337                 ASSERT_TRUE(TDM_ERROR_NONE == error || TDM_ERROR_NOT_IMPLEMENTED == error);
338         }
339 }
340
341 /* tdm_error tdm_hwc_window_video_get_capability(tdm_hwc_window *hwc_window,
342                                                                         tdm_hwc_window_video_capability *video_capability); */
343 TEST_P(TDMHwcWindow, VideoGetCapabilityFailNull)
344 {
345         TDM_UT_SKIP_FLAG(has_outputs);
346
347         tdm_hwc_window_video_capability video_capability;
348
349         error = tdm_hwc_window_video_get_capability(NULL, &video_capability);
350         ASSERT_NE(TDM_ERROR_NONE, error);
351
352         if (hwc_count > 0) {
353                 error = tdm_hwc_window_video_get_capability(hwc_wins[0], NULL);
354                 ASSERT_NE(TDM_ERROR_NONE, error);
355         }
356
357 }
358
359 TEST_P(TDMHwcWindow, VideoGetCapabilitySuccessful)
360 {
361         TDM_UT_SKIP_FLAG(has_outputs);
362
363         tdm_hwc_window_video_capability video_capability;
364
365         for (int w = 0; w < hwc_count; w++) {
366                 /* hwc_window with TDM_COMPOSITION_CLIENT dosn't support tdm_hwc_window_video_get_capability()*/
367                 error = tdm_hwc_window_video_get_capability(hwc_wins[w], &video_capability);
368                 ASSERT_NE(TDM_ERROR_NONE, error);
369
370                 if (video_hwc_win != NULL) {
371                         error = tdm_hwc_window_video_get_capability(video_hwc_win, &video_capability);
372                         ASSERT_TRUE(TDM_ERROR_NONE == error || TDM_ERROR_NOT_IMPLEMENTED == error);
373                 }
374         }
375 }
376
377
378 /* tdm_hwc_window_video_get_available_properties() */
379 TEST_P(TDMHwcWindow, GetAvailablePropertiesFailNullWin)
380 {
381         TDM_UT_SKIP_FLAG(has_outputs);
382
383         TDM_UT_SKIP_FLAG(video_hwc_win != NULL);
384         const tdm_prop *props;
385         int count;
386
387         error = tdm_hwc_window_video_get_available_properties(NULL, &props, &count);
388         ASSERT_NE(TDM_ERROR_NONE, error);
389
390         error = tdm_hwc_window_video_get_available_properties(video_hwc_win, NULL, &count);
391         ASSERT_NE(TDM_ERROR_NONE, error);
392
393         error = tdm_hwc_window_video_get_available_properties(video_hwc_win, &props, NULL);
394         ASSERT_NE(TDM_ERROR_NONE, error);
395 }
396
397 TEST_P(TDMHwcWindow, GetAvailablePropertiesSuccess)
398 {
399         TDM_UT_SKIP_FLAG(has_outputs);
400
401         TDM_UT_SKIP_FLAG(video_hwc_win != NULL);
402
403         const tdm_prop *props;
404         int count;
405
406         error = tdm_hwc_window_video_get_available_properties(video_hwc_win, &props, &count);
407         ASSERT_TRUE(TDM_ERROR_NONE == error || TDM_ERROR_NOT_IMPLEMENTED == error);
408 }
409
410 /* tdm_hwc_window_video_get_property() */
411 TEST_P(TDMHwcWindow, GetPropertyFailNull)
412 {
413         TDM_UT_SKIP_FLAG(has_outputs);
414         TDM_UT_SKIP_FLAG(video_hwc_win != NULL);
415
416         tdm_value value;
417         int id = 1;
418
419         error = tdm_hwc_window_video_get_property(NULL, id, &value);
420         ASSERT_NE(TDM_ERROR_NONE, error);
421
422         error = tdm_hwc_window_video_get_property(video_hwc_win, id, NULL);
423         ASSERT_NE(TDM_ERROR_NONE, error);
424 }
425
426 TEST_P(TDMHwcWindow, GetPropertyFailWrongId)
427 {
428         TDM_UT_SKIP_FLAG(has_outputs);
429         TDM_UT_SKIP_FLAG(video_hwc_win != NULL);
430
431         tdm_value value;
432         int id = INT_MAX;
433
434         error = tdm_hwc_window_video_get_property(video_hwc_win, id, &value);
435         ASSERT_NE(TDM_ERROR_NONE, error);
436 }
437
438 /* tdm_hwc_window_video_set_property() */
439 TEST_P(TDMHwcWindow, SetPropertyFailNull)
440 {
441         TDM_UT_SKIP_FLAG(has_outputs);
442         TDM_UT_SKIP_FLAG(video_hwc_win != NULL);
443
444         tdm_value value;
445         int id = 1;
446
447         error = tdm_hwc_window_video_set_property(NULL, id, value);
448         ASSERT_NE(TDM_ERROR_NONE, error);
449 }
450
451 TEST_P(TDMHwcWindow, SetPropertyFailWrongId)
452 {
453         TDM_UT_SKIP_FLAG(has_outputs);
454         TDM_UT_SKIP_FLAG(video_hwc_win != NULL);
455
456         tdm_value value;
457         int id = INT_MAX;
458
459         error = tdm_hwc_window_video_set_property(video_hwc_win, id, value);
460         ASSERT_NE(TDM_ERROR_NONE, error);
461 }
462
463 #ifdef TDM_UT_TEST_WITH_PARAMS
464 INSTANTIATE_TEST_CASE_P(TDMHwcWindowParams,
465                                                 TDMHwcWindow,
466                                                 Combine(Bool(), Bool(), Values(TDM_DEFAULT_MODULE)));
467 #else
468 INSTANTIATE_TEST_CASE_P(TDMHwcWindowParams,
469                                                 TDMHwcWindow,
470                                                 Values(TDM_DEFAULT_MODULE));
471 #endif