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