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