[utest] Add 34 test cases
[platform/core/uifw/libtdm.git] / utests / src / ut_tdm_output.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 <climits>
34 extern "C" {
35 #include "tdm.h"
36 #include "tbm_bufmgr.h"
37 #include "tbm_drm_helper.h"
38 }
39
40 class TDMOutput : public ::testing::Test {
41 protected:
42         tdm_display *dpy = NULL;
43         int output_count = -42, master_fd = -42, tbm_fd = -42;
44         bool has_output = false;
45         tbm_bufmgr tbm_bufmgr = NULL;
46         static unsigned int handle_call;
47         static void tdm_output_change_handler_test_func(tdm_output *output,
48                                                                                                         tdm_output_change_type type,
49                                                                                                         tdm_value value,
50                                                                                                         void *u_data)
51         {
52                 if ( ((int) u_data) < -100) {
53                         TDMOutput::handle_call++;
54                 }
55         }
56         void SetUp(void)
57         {
58                 setenv("TDM_DLOG", "1", 1);
59                 setenv("XDG_RUNTIME_DIR", ".", 1);
60                 setenv("TBM_DLOG", "1", 1);
61                 setenv("TBM_DISPLAY_SERVER", "1", 1);
62                 tbm_bufmgr = tbm_bufmgr_init(-1);
63                 ASSERT_FALSE(tbm_bufmgr == NULL);
64                 tdm_error error = TDM_ERROR_NONE;
65                 dpy = tdm_display_init(&error);
66                 ASSERT_TRUE(error == TDM_ERROR_NONE);
67                 ASSERT_FALSE(dpy == NULL);
68                 master_fd = tbm_drm_helper_get_master_fd();
69                 tbm_fd = tbm_drm_helper_get_fd();
70                 error = tdm_display_get_output_count(dpy, &output_count);
71 #ifdef FAIL_ON_UNSUPPORTED
72                 ASSERT_GT(output_count, 0);
73 #endif
74                 if (output_count > 0)
75                         has_output = true;
76                 handle_call = 0;
77         }
78         void TearDown(void)
79         {
80                 tdm_display_deinit(dpy);
81                 dpy = NULL;
82                 tbm_bufmgr_deinit(tbm_bufmgr);
83                 tbm_bufmgr = NULL;
84                 if (master_fd > -1) {
85                         int temp_master_fd = tbm_drm_helper_get_master_fd();
86                         EXPECT_EQ(temp_master_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl;
87                         if (temp_master_fd > -1)
88                                 exit(1);
89                         close(master_fd);
90                 }
91                 if (tbm_fd > -1) {
92                         int temp_tbm_fd = tbm_drm_helper_get_fd();
93                         EXPECT_EQ(temp_tbm_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl;
94                         if (temp_tbm_fd > -1)
95                                 exit(1);
96                         close(tbm_fd);
97                 }
98                 unsetenv("TDM_DLOG");
99                 unsetenv("XDG_RUNTIME_DIR");
100                 unsetenv("TBM_DLOG");
101                 unsetenv("TBM_DISPLAY_SERVER");
102         }
103 };
104
105 unsigned int TDMOutput::handle_call = 0;
106
107 TEST_F(TDMOutput, DisplayGetOutputSuccessful)
108 {
109         SKIP_FLAG(has_output);
110         for (int i = 0; i < output_count; i++) {
111                 tdm_error error = TDM_ERROR_NONE;
112                 ASSERT_FALSE(NULL == tdm_display_get_output(dpy, i, &error));
113                 ASSERT_TRUE(TDM_ERROR_NONE == error);
114         }
115 }
116
117 TEST_F(TDMOutput, DisplayGetOutputSuccessfulWrongIndex)
118 {
119         SKIP_FLAG(has_output);
120         tdm_error error = TDM_ERROR_NONE;
121         ASSERT_TRUE(NULL == tdm_display_get_output(dpy, -1, &error));
122         ASSERT_TRUE(TDM_ERROR_NONE == error);
123 }
124
125 TEST_F(TDMOutput, DisplayGetOutputSuccessfulBigIndex)
126 {
127         SKIP_FLAG(has_output);
128         tdm_error error = TDM_ERROR_NONE;
129         ASSERT_TRUE(NULL == tdm_display_get_output(dpy, INT_MAX, &error));
130         ASSERT_TRUE(TDM_ERROR_NONE == error);
131 }
132
133 TEST_F(TDMOutput, DisplayGetOutputSuccessfulSmallIndex)
134 {
135         SKIP_FLAG(has_output);
136         tdm_error error = TDM_ERROR_NONE;
137         ASSERT_TRUE(NULL == tdm_display_get_output(dpy, INT_MIN, &error));
138         ASSERT_TRUE(TDM_ERROR_NONE == error);
139 }
140
141 TEST_F(TDMOutput, DisplayGetOutputSuccessfulErrorNull)
142 {
143         SKIP_FLAG(has_output);
144         ASSERT_FALSE(NULL == tdm_display_get_output(dpy, 0, NULL));
145 }
146
147 TEST_F(TDMOutput, DisplayOutputGetCapabilitiesSuccessful)
148 {
149         SKIP_FLAG(has_output);
150         for (int i = 0; i < output_count; i++) {
151                 tdm_error error = TDM_ERROR_NONE;
152                 tdm_output_capability capabilities = (tdm_output_capability) -42;
153                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
154                 ASSERT_FALSE(NULL == output);
155                 ASSERT_TRUE(TDM_ERROR_NONE == error);
156                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_capabilities(output, &capabilities));
157                 ASSERT_FALSE(-42 == capabilities);
158         }
159 }
160
161 TEST_F(TDMOutput, DisplayOutputGetCapabilitiesFailAllNull)
162 {
163         SKIP_FLAG(has_output);
164         ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_capabilities(NULL, NULL));
165 }
166
167 TEST_F(TDMOutput, DisplayOutputGetCapabilitiesFailOnlyOutput)
168 {
169         SKIP_FLAG(has_output);
170         for (int i = 0; i < output_count; i++) {
171                 tdm_error error = TDM_ERROR_NONE;
172                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
173                 ASSERT_FALSE(NULL == output);
174                 ASSERT_TRUE(TDM_ERROR_NONE == error);
175                 ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_capabilities(output, NULL));
176         }
177 }
178
179 TEST_F(TDMOutput, OutputGetModelInfoSuccessful)
180 {
181         SKIP_FLAG(has_output);
182         for (int i = 0; i < output_count; i++) {
183                 tdm_error error = TDM_ERROR_NONE;
184                 const char * maker = NULL, * model = NULL, * name = NULL;
185                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
186                 ASSERT_FALSE(NULL == output);
187                 ASSERT_TRUE(TDM_ERROR_NONE == error);
188                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_model_info(output, &maker, &model, &name));
189                 ASSERT_FALSE(NULL == maker);
190                 ASSERT_FALSE(NULL == model);
191                 ASSERT_FALSE(NULL == name);
192         }
193 }
194
195 TEST_F(TDMOutput, OutputGetModelInfoFailAllNull)
196 {
197         SKIP_FLAG(has_output);
198         ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_model_info(NULL, NULL, NULL, NULL));
199 }
200
201 TEST_F(TDMOutput, OutputGetModelInfoSuccessfulOnlyOutput)
202 {
203         SKIP_FLAG(has_output);
204         for (int i = 0; i < output_count; i++) {
205                 tdm_error error = TDM_ERROR_NONE;
206                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
207                 ASSERT_FALSE(NULL == output);
208                 ASSERT_TRUE(TDM_ERROR_NONE == error);
209                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_model_info(output, NULL, NULL, NULL));
210         }
211 }
212
213 TEST_F(TDMOutput, OutputGetConnStatusSuccessful)
214 {
215         SKIP_FLAG(has_output);
216         for (int i = 0; i < output_count; i++) {
217                 tdm_error error = TDM_ERROR_NONE;
218                 tdm_output_conn_status status = (tdm_output_conn_status) -42;
219                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
220                 ASSERT_FALSE(NULL == output);
221                 ASSERT_TRUE(TDM_ERROR_NONE == error);
222                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status));
223                 ASSERT_FALSE(-42 == status);
224         }
225 }
226
227 TEST_F(TDMOutput, OutputGetConnStatusFailAllNull)
228 {
229         SKIP_FLAG(has_output);
230         ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_conn_status(NULL, NULL));
231 }
232
233 TEST_F(TDMOutput, OutputGetConnStatusFailOnlyOutput)
234 {
235         SKIP_FLAG(has_output);
236         for (int i = 0; i < output_count; i++) {
237                 tdm_error error = TDM_ERROR_NONE;
238                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
239                 ASSERT_FALSE(NULL == output);
240                 ASSERT_TRUE(TDM_ERROR_NONE == error);
241                 ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, NULL));
242         }
243 }
244
245 TEST_F(TDMOutput, OutputSetDPMSSuccessful)
246 {
247         SKIP_FLAG(has_output);
248         bool checked = false;
249         for (int i = 0; i < output_count; i++) {
250                 tdm_error error = TDM_ERROR_NONE;
251                 tdm_output_conn_status status;
252                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
253                 ASSERT_FALSE(NULL == output);
254                 ASSERT_TRUE(TDM_ERROR_NONE == error);
255                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status));
256                 if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
257                         continue;
258                 checked = true;
259                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
260                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_STANDBY));
261                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_SUSPEND));
262                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
263         }
264         if (false == checked) {
265                 FAIL() << "All outputs are disconnected. Testcase skipped" << std::endl;
266         }
267 }
268
269 TEST_F(TDMOutput, OutputAddChangeHandlerSuccessful)
270 {
271         SKIP_FLAG(has_output);
272         bool checked = false;
273         for (int i = 0; i < output_count; i++) {
274                 tdm_error error = TDM_ERROR_NONE;
275                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
276                 ASSERT_FALSE(NULL == output);
277                 ASSERT_TRUE(TDM_ERROR_NONE == error);
278                 tdm_output_conn_status status;
279                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status));
280                 if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
281                         continue;
282                 checked = true;
283                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output,
284                                                                                                                                         tdm_output_change_handler_test_func,
285                                                                                                                                         (void *) -101));
286                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
287                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
288                 ASSERT_GT(handle_call, 0);
289         }
290         if (false == checked) {
291                 FAIL() << "All outputs are disconnected. Testcase skipped" << std::endl;
292         }
293 }
294
295 TEST_F(TDMOutput, OutputAddChangeHandlerSuccessfulFewFuncs)
296 {
297         SKIP_FLAG(has_output);
298         bool checked = false;
299         for (int i = 0; i < output_count; i++) {
300                 tdm_error error = TDM_ERROR_NONE;
301                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
302                 ASSERT_FALSE(NULL == output);
303                 ASSERT_TRUE(TDM_ERROR_NONE == error);
304                 tdm_output_conn_status status;
305                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status));
306                 if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
307                         continue;
308                 checked = true;
309                 for (int k = 0; k < 20; k++) {
310                         ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output,
311                                                                                                                                                 tdm_output_change_handler_test_func,
312                                                                                                                                                 (void *) (-101-k)));
313                 }
314                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
315                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
316                 ASSERT_GT(handle_call, 20);
317         }
318         if (false == checked) {
319                 FAIL() << "All outputs are disconnected. Testcase skipped" << std::endl;
320         }
321 }
322
323
324 TEST_F(TDMOutput, OutputAddChangeHandlerFailAllNull)
325 {
326         SKIP_FLAG(has_output);
327         ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_add_change_handler(NULL, NULL, NULL));
328 }
329
330 TEST_F(TDMOutput, OutputAddChangeHandlerFailOnlyOutput)
331 {
332         SKIP_FLAG(has_output);
333         for (int i = 0; i < output_count; i++) {
334                 tdm_error error = TDM_ERROR_NONE;
335                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
336                 ASSERT_FALSE(NULL == output);
337                 ASSERT_TRUE(TDM_ERROR_NONE == error);
338                 ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_add_change_handler(output, NULL, NULL));
339         }
340 }
341
342 TEST_F(TDMOutput, OutputAddChangeHandlerFailWrongOutput)
343 {
344         SKIP_FLAG(has_output);
345         ASSERT_EXIT({tdm_output *output = (tdm_output *) 0xBEAF;
346                                  tdm_output_add_change_handler(output,
347                                                                                            tdm_output_change_handler_test_func,
348                                                                                            (void *) -101);
349                                  exit(0);}, ::testing::ExitedWithCode(0), "");
350 }
351
352 TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessful)
353 {
354         SKIP_FLAG(has_output);
355         bool checked = false;
356         for (int i = 0; i < output_count; i++) {
357                 tdm_error error = TDM_ERROR_NONE;
358                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
359                 ASSERT_FALSE(NULL == output);
360                 ASSERT_TRUE(TDM_ERROR_NONE == error);
361                 tdm_output_conn_status status;
362                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status));
363                 if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
364                         continue;
365                 checked = true;
366                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output,
367                                                                                                                                         tdm_output_change_handler_test_func,
368                                                                                                                                         (void *) -101));
369                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
370                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
371                 ASSERT_GT(handle_call, 0);
372                 handle_call = 0;
373                 tdm_output_remove_change_handler(output, tdm_output_change_handler_test_func, (void *) -101);
374                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
375                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
376                 ASSERT_EQ(handle_call, 0);
377         }
378         if (false == checked) {
379                 FAIL() << "All outputs are disconnected. Testcase skipped" << std::endl;
380         }
381 }
382
383 TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessfulFewFuncs)
384 {
385         SKIP_FLAG(has_output);
386         bool checked = false;
387         for (int i = 0; i < output_count; i++) {
388                 tdm_error error = TDM_ERROR_NONE;
389                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
390                 ASSERT_FALSE(NULL == output);
391                 ASSERT_TRUE(TDM_ERROR_NONE == error);
392                 tdm_output_conn_status status;
393                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status));
394                 if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
395                         continue;
396                 checked = true;
397                 for (int k = 0; k < 20; k++) {
398                         ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output,
399                                                                                                                                                 tdm_output_change_handler_test_func,
400                                                                                                                                                 (void *) (-101-k)));
401                 }
402                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
403                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
404                 ASSERT_GT(handle_call, 20);
405                 handle_call = 0;
406                 for (int k = 0; k < 20; k++) {
407                         tdm_output_remove_change_handler(output, tdm_output_change_handler_test_func, (void *) (-101-k));
408                 }
409                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
410                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
411                 ASSERT_EQ(handle_call, 0);
412         }
413         if (false == checked) {
414                 FAIL() << "All outputs are disconnected. Testcase skipped" << std::endl;
415         }
416 }
417
418 TEST_F(TDMOutput, OutputRemoveChangeHandlerFailAllNull)
419 {
420         SKIP_FLAG(has_output);
421         ASSERT_EXIT({tdm_output_remove_change_handler(NULL, NULL, NULL);
422                                  exit(0);}, ::testing::ExitedWithCode(0), "");
423 }
424
425 TEST_F(TDMOutput, OutputRemoveChangeHandlerFailOnlyOutput)
426 {
427         SKIP_FLAG(has_output);
428         ASSERT_EXIT({for (int i = 0; i < output_count; i++) {
429                                          tdm_error error = TDM_ERROR_NONE;
430                                          tdm_output * output = tdm_display_get_output(dpy, i, &error);
431                                          if (NULL == output) exit(1);
432                                          if (TDM_ERROR_NONE != error) exit(1);
433                                          tdm_output_remove_change_handler(output, NULL, NULL);
434                                  } exit(0);}, ::testing::ExitedWithCode(0), "");
435 }
436
437 TEST_F(TDMOutput, OutputRemoveChangeHandlerFailWrongOutput)
438 {
439         SKIP_FLAG(has_output);
440         ASSERT_EXIT({tdm_output *output = (tdm_output *) 0xBEAF;
441                                  tdm_output_remove_change_handler(output,
442                                                                                            tdm_output_change_handler_test_func,
443                                                                                            (void *) -101);
444                                  exit(0);}, ::testing::ExitedWithCode(0), "");
445 }
446
447 TEST_F(TDMOutput, OutputGetOutputTypeSuccessful)
448 {
449         SKIP_FLAG(has_output);
450         for (int i = 0; i < output_count; i++) {
451                 tdm_error error = TDM_ERROR_NONE;
452                 tdm_output_type type = (tdm_output_type) -42;
453                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
454                 ASSERT_FALSE(NULL == output);
455                 ASSERT_TRUE(TDM_ERROR_NONE == error);
456                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_output_type(output, &type));
457                 ASSERT_NE(type, -42);
458         }
459 }
460
461 TEST_F(TDMOutput, OutputGetOutputTypeFailNullAll)
462 {
463         SKIP_FLAG(has_output);
464         ASSERT_EXIT({if (tdm_output_get_output_type(NULL, NULL) == TDM_ERROR_NONE) exit(1);
465                                  exit(0);}, ::testing::ExitedWithCode(0), "");
466 }
467
468 TEST_F(TDMOutput, OutputGetOutputTypeFailOnlyOutput)
469 {
470         SKIP_FLAG(has_output);
471         ASSERT_EXIT({for (int i = 0; i < output_count; i++) {
472                                          tdm_error error = TDM_ERROR_NONE;
473                                          tdm_output * output = tdm_display_get_output(dpy, i, &error);
474                                          if (NULL == output) exit(1);
475                                          if (TDM_ERROR_NONE != error) exit(1);
476                                          if (tdm_output_get_output_type(output, NULL) == TDM_ERROR_NONE) exit(1);
477                                 }
478                                 exit(0);}, ::testing::ExitedWithCode(0), "");
479 }
480
481 TEST_F(TDMOutput, OutputGetLayerCountSuccessful)
482 {
483         SKIP_FLAG(has_output);
484         for (int i = 0; i < output_count; i++) {
485                 tdm_error error = TDM_ERROR_NONE;
486                 int count = -42;
487                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
488                 ASSERT_FALSE(NULL == output);
489                 ASSERT_TRUE(TDM_ERROR_NONE == error);
490                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_layer_count(output, &count));
491                 ASSERT_NE(count, -42);
492         }
493 }
494
495 TEST_F(TDMOutput, OutputGetLayerCountFailNullAll)
496 {
497         SKIP_FLAG(has_output);
498         ASSERT_EXIT({if (tdm_output_get_layer_count(NULL, NULL) == TDM_ERROR_NONE) exit(1);
499                                  exit(0);}, ::testing::ExitedWithCode(0), "");
500 }
501
502 TEST_F(TDMOutput, OutputGetLayerCountFailOnlyOutput)
503 {
504         SKIP_FLAG(has_output);
505         ASSERT_EXIT({for (int i = 0; i < output_count; i++) {
506                                          tdm_error error = TDM_ERROR_NONE;
507                                          tdm_output * output = tdm_display_get_output(dpy, i, &error);
508                                          if (NULL == output) exit(1);
509                                          if (TDM_ERROR_NONE != error) exit(1);
510                                          if (TDM_ERROR_NONE == tdm_output_get_layer_count(output, NULL)) exit(1);
511                                 }
512                                 exit(0);}, ::testing::ExitedWithCode(0), "");
513 }
514
515 TEST_F(TDMOutput, OutputGetAvailablePropertiesSuccessful)
516 {
517         SKIP_FLAG(has_output);
518         for (int i = 0; i < output_count; i++) {
519                 tdm_error error = TDM_ERROR_NONE;
520                 int count = -42;
521                 const tdm_prop *tdm_prop_array = (const tdm_prop *) 0xBEAF;
522                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
523                 ASSERT_FALSE(NULL == output);
524                 ASSERT_TRUE(TDM_ERROR_NONE == error);
525                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_available_properties(output,
526                                                                                                                                                   &tdm_prop_array,
527                                                                                                                                                   &count));
528                 ASSERT_NE(count, -42);
529                 ASSERT_NE(tdm_prop_array, 0xBEAF);
530         }
531 }
532
533 TEST_F(TDMOutput, OutputGetAvailablePropertiesFailNullAll)
534 {
535         SKIP_FLAG(has_output);
536         ASSERT_EXIT({if (tdm_output_get_available_properties(NULL, NULL, NULL) == TDM_ERROR_NONE) exit(1);
537                                  exit(0);}, ::testing::ExitedWithCode(0), "");
538 }
539
540 TEST_F(TDMOutput, OutputGetAvailablePropertiesFailOnlyOutput)
541 {
542         SKIP_FLAG(has_output);
543         ASSERT_EXIT({for (int i = 0; i < output_count; i++) {
544                                          tdm_error error = TDM_ERROR_NONE;
545                                          tdm_output * output = tdm_display_get_output(dpy, i, &error);
546                                          if (NULL == output) exit(1);
547                                          if (TDM_ERROR_NONE != error) exit(1);
548                                          if (TDM_ERROR_NONE == tdm_output_get_available_properties(output, NULL, NULL)) exit(1);
549                                 }
550                                 exit(0);}, ::testing::ExitedWithCode(0), "");
551 }
552
553 TEST_F(TDMOutput, OutputGetAvailablePropertiesFailNullCount)
554 {
555         SKIP_FLAG(has_output);
556         ASSERT_EXIT({for (int i = 0; i < output_count; i++) {
557                                          tdm_error error = TDM_ERROR_NONE;
558                                          const tdm_prop *tdm_prop_array = NULL;
559                                          tdm_output * output = tdm_display_get_output(dpy, i, &error);
560                                          if (NULL == output) exit(1);
561                                          if (TDM_ERROR_NONE != error) exit(1);
562                                          if (TDM_ERROR_NONE == tdm_output_get_available_properties(output,
563                                                                                                                                                            &tdm_prop_array,
564                                                                                                                                                            NULL)) exit(1);
565                                 }
566                                 exit(0);}, ::testing::ExitedWithCode(0), "");
567 }
568
569 TEST_F(TDMOutput, OutputGetAvailablePropertiesFailNullProperty)
570 {
571         SKIP_FLAG(has_output);
572         ASSERT_EXIT({for (int i = 0; i < output_count; i++) {
573                                          tdm_error error = TDM_ERROR_NONE;
574                                          int count = -42;
575                                          tdm_output * output = tdm_display_get_output(dpy, i, &error);
576                                          if (NULL == output) exit(1);
577                                          if (TDM_ERROR_NONE != error) exit(1);
578                                          if (TDM_ERROR_NONE == tdm_output_get_available_properties(output,
579                                                                                                                                                            NULL,
580                                                                                                                                                            &count)) exit(1);
581                                 }
582                                 exit(0);}, ::testing::ExitedWithCode(0), "");
583 }
584
585 TEST_F(TDMOutput, OutputGetAvailableModesSuccessful)
586 {
587         SKIP_FLAG(has_output);
588         for (int i = 0; i < output_count; i++) {
589                 tdm_error error = TDM_ERROR_NONE;
590                 int count = -42;
591                 const tdm_output_mode *modes_array = (const tdm_output_mode *) 0xBEAF;
592                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
593                 ASSERT_FALSE(NULL == output);
594                 ASSERT_TRUE(TDM_ERROR_NONE == error);
595                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_available_modes(output,
596                                                                                                                                          &modes_array,
597                                                                                                                                          &count));
598                 ASSERT_NE(count, -42);
599                 ASSERT_NE(modes_array, 0xBEAF);
600         }
601 }
602
603 TEST_F(TDMOutput, OutputGetAvailableModesFailNullAll)
604 {
605         SKIP_FLAG(has_output);
606         ASSERT_EXIT({if (tdm_output_get_available_modes(NULL, NULL, NULL) == TDM_ERROR_NONE) exit(1);
607                                  exit(0);}, ::testing::ExitedWithCode(0), "");
608 }
609
610 TEST_F(TDMOutput, OutputGetAvailableModesFailOnlyOutput)
611 {
612         SKIP_FLAG(has_output);
613         ASSERT_EXIT({for (int i = 0; i < output_count; i++) {
614                                          tdm_error error = TDM_ERROR_NONE;
615                                          tdm_output * output = tdm_display_get_output(dpy, i, &error);
616                                          if (NULL == output) exit(1);
617                                          if (TDM_ERROR_NONE != error) exit(1);
618                                          if (TDM_ERROR_NONE == tdm_output_get_available_modes(output, NULL, NULL)) exit(1);
619                                 }
620                                 exit(0);}, ::testing::ExitedWithCode(0), "");
621 }
622
623 TEST_F(TDMOutput, OutputGetAvailableModesFailNullCount)
624 {
625         SKIP_FLAG(has_output);
626         ASSERT_EXIT({for (int i = 0; i < output_count; i++) {
627                                          tdm_error error = TDM_ERROR_NONE;
628                                          const tdm_output_mode *modes_array = NULL;
629                                          tdm_output * output = tdm_display_get_output(dpy, i, &error);
630                                          if (NULL == output) exit(1);
631                                          if (TDM_ERROR_NONE != error) exit(1);
632                                          if (TDM_ERROR_NONE == tdm_output_get_available_modes(output,
633                                                                                                                                                   &modes_array,
634                                                                                                                                                   NULL)) exit(1);
635                                 }
636                                 exit(0);}, ::testing::ExitedWithCode(0), "");
637 }
638
639 TEST_F(TDMOutput, OutputGetAvailableModesFailNullModes)
640 {
641         SKIP_FLAG(has_output);
642         ASSERT_EXIT({for (int i = 0; i < output_count; i++) {
643                                          tdm_error error = TDM_ERROR_NONE;
644                                          int count = -42;
645                                          tdm_output * output = tdm_display_get_output(dpy, i, &error);
646                                          if (NULL == output) exit(1);
647                                          if (TDM_ERROR_NONE != error) exit(1);
648                                          if (TDM_ERROR_NONE == tdm_output_get_available_modes(output,
649                                                                                                                                                   NULL,
650                                                                                                                                                   &count)) exit(1);
651                                 }
652                                 exit(0);}, ::testing::ExitedWithCode(0), "");
653 }
654
655 TEST_F(TDMOutput, OutputGetAvailableSizeSuccessful)
656 {
657         SKIP_FLAG(has_output);
658         for (int i = 0; i < output_count; i++) {
659                 tdm_error error = TDM_ERROR_NONE;
660                 int min_w = -42, min_h = -42, max_w = -42, max_h = -42, preferred_align = -42;
661                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
662                 ASSERT_FALSE(NULL == output);
663                 ASSERT_TRUE(TDM_ERROR_NONE == error);
664                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_available_size(output, &min_w, &min_h,
665                                                                                                                                         &max_w, &max_h, &preferred_align));
666                 ASSERT_NE(min_w, -42);
667                 ASSERT_NE(min_h, -42);
668                 ASSERT_NE(max_w, -42);
669                 ASSERT_NE(max_h, -42);
670                 ASSERT_NE(preferred_align, -42);
671         }
672 }
673
674 TEST_F(TDMOutput, OutputGetAvailableSizeFailNullAll)
675 {
676         SKIP_FLAG(has_output);
677         ASSERT_EXIT({if (tdm_output_get_available_size(NULL, NULL, NULL,
678                                                                                                    NULL, NULL, NULL) == TDM_ERROR_NONE) exit(1);
679                                  exit(0);}, ::testing::ExitedWithCode(0), "");
680 }
681
682 TEST_F(TDMOutput, OutputGetAvailableSizeSuccessfulOnlyOutput)
683 {
684         SKIP_FLAG(has_output);
685         ASSERT_EXIT({for (int i = 0; i < output_count; i++) {
686                                          tdm_error error = TDM_ERROR_NONE;
687                                          tdm_output * output = tdm_display_get_output(dpy, i, &error);
688                                          if (NULL == output) exit(1);
689                                          if (TDM_ERROR_NONE != error) exit(1);
690                                          if (tdm_output_get_available_size(output, NULL, NULL,
691                                                                                                                 NULL, NULL, NULL) != TDM_ERROR_NONE) exit(1);
692                                 }
693                                 exit(0);}, ::testing::ExitedWithCode(0), "");
694 }
695
696 TEST_F(TDMOutput, OutputGetCursorAvailableSizeSuccessful)
697 {
698         SKIP_FLAG(has_output);
699         for (int i = 0; i < output_count; i++) {
700                 tdm_error error = TDM_ERROR_NONE;
701                 int min_w = -42, min_h = -42, max_w = -42, max_h = -42, preferred_align = -42;
702                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
703                 ASSERT_FALSE(NULL == output);
704                 ASSERT_TRUE(TDM_ERROR_NONE == error);
705                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_cursor_available_size(output, &min_w, &min_h,
706                                                                                                                                                    &max_w, &max_h, &preferred_align));
707                 ASSERT_NE(min_w, -42);
708                 ASSERT_NE(min_h, -42);
709                 ASSERT_NE(max_w, -42);
710                 ASSERT_NE(max_h, -42);
711                 ASSERT_NE(preferred_align, -42);
712         }
713 }
714
715 TEST_F(TDMOutput, OutputGetCursorAvailableSizeFailNullAll)
716 {
717         SKIP_FLAG(has_output);
718         ASSERT_EXIT({if (tdm_output_get_cursor_available_size(NULL, NULL, NULL,
719                                                                                                                   NULL, NULL, NULL) == TDM_ERROR_NONE) exit(1);
720                                  exit(0);}, ::testing::ExitedWithCode(0), "");
721 }
722
723 TEST_F(TDMOutput, OutputGetCursorAvailableSizeSuccessfulOnlyOutput)
724 {
725         SKIP_FLAG(has_output);
726         ASSERT_EXIT({for (int i = 0; i < output_count; i++) {
727                                          tdm_error error = TDM_ERROR_NONE;
728                                          tdm_output * output = tdm_display_get_output(dpy, i, &error);
729                                          if (NULL == output) exit(1);
730                                          if (TDM_ERROR_NONE != error) exit(1);
731                                          if (tdm_output_get_cursor_available_size(output, NULL, NULL,
732                                                                                                                           NULL, NULL, NULL) != TDM_ERROR_NONE) exit(1);
733                                 }
734                                 exit(0);}, ::testing::ExitedWithCode(0), "");
735 }
736
737 TEST_F(TDMOutput, OutputGetPhysicalSizeSuccessful)
738 {
739         SKIP_FLAG(has_output);
740         for (int i = 0; i < output_count; i++) {
741                 tdm_error error = TDM_ERROR_NONE;
742                 unsigned int mmWidth = UINT_MAX, mmHeight = UINT_MAX;
743                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
744                 ASSERT_FALSE(NULL == output);
745                 ASSERT_TRUE(TDM_ERROR_NONE == error);
746                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_physical_size(output, &mmWidth, &mmHeight));
747                 ASSERT_NE(mmWidth, UINT_MAX);
748                 ASSERT_NE(mmHeight, UINT_MAX);
749         }
750 }
751
752 TEST_F(TDMOutput, OutputGetPhysicalSizeFailNullAll)
753 {
754         SKIP_FLAG(has_output);
755         ASSERT_EXIT({if (tdm_output_get_physical_size(NULL, NULL, NULL) == TDM_ERROR_NONE) exit(1);
756                                  exit(0);}, ::testing::ExitedWithCode(0), "");
757 }
758
759 TEST_F(TDMOutput, OutputGetPhysicalSuccessfulOnlyOutput)
760 {
761         SKIP_FLAG(has_output);
762         ASSERT_EXIT({for (int i = 0; i < output_count; i++) {
763                                          tdm_error error = TDM_ERROR_NONE;
764                                          tdm_output * output = tdm_display_get_output(dpy, i, &error);
765                                          if (NULL == output) exit(1);
766                                          if (TDM_ERROR_NONE != error) exit(1);
767                                          if (tdm_output_get_physical_size(output, NULL, NULL) != TDM_ERROR_NONE) exit(1);
768                                 }
769                                 exit(0);}, ::testing::ExitedWithCode(0), "");
770 }
771
772 TEST_F(TDMOutput, OutputGetSubpixelSuccessful)
773 {
774         SKIP_FLAG(has_output);
775         for (int i = 0; i < output_count; i++) {
776                 tdm_error error = TDM_ERROR_NONE;
777                 unsigned int subpixel = UINT_MAX;
778                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
779                 ASSERT_FALSE(NULL == output);
780                 ASSERT_TRUE(TDM_ERROR_NONE == error);
781                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_subpixel(output, &subpixel));
782                 ASSERT_NE(subpixel, UINT_MAX);
783         }
784 }
785
786 TEST_F(TDMOutput, OutputGetSubpixelFailNullAll)
787 {
788         SKIP_FLAG(has_output);
789         ASSERT_EXIT({if (tdm_output_get_subpixel(NULL, NULL) == TDM_ERROR_NONE) exit(1);
790                                  exit(0);}, ::testing::ExitedWithCode(0), "");
791 }
792
793 TEST_F(TDMOutput, OutputGetSubpixelFailOnlyOutput)
794 {
795         SKIP_FLAG(has_output);
796         ASSERT_EXIT({for (int i = 0; i < output_count; i++) {
797                                          tdm_error error = TDM_ERROR_NONE;
798                                          tdm_output * output = tdm_display_get_output(dpy, i, &error);
799                                          if (NULL == output) exit(1);
800                                          if (TDM_ERROR_NONE != error) exit(1);
801                                          if (tdm_output_get_subpixel(output, NULL) == TDM_ERROR_NONE) exit(1);
802                                 }
803                                 exit(0);}, ::testing::ExitedWithCode(0), "");
804 }
805
806 TEST_F(TDMOutput, OutputGetPipeSuccessful)
807 {
808         SKIP_FLAG(has_output);
809         for (int i = 0; i < output_count; i++) {
810                 tdm_error error = TDM_ERROR_NONE;
811                 unsigned int pipe = UINT_MAX;
812                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
813                 ASSERT_FALSE(NULL == output);
814                 ASSERT_TRUE(TDM_ERROR_NONE == error);
815                 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_pipe(output, &pipe));
816                 ASSERT_NE(pipe, UINT_MAX);
817         }
818 }
819
820 TEST_F(TDMOutput, OutputGetPipeFailNullAll)
821 {
822         SKIP_FLAG(has_output);
823         ASSERT_EXIT({if (tdm_output_get_pipe(NULL, NULL) == TDM_ERROR_NONE) exit(1);
824                                  exit(0);}, ::testing::ExitedWithCode(0), "");
825 }
826
827 TEST_F(TDMOutput, OutputGetPipeFailOnlyOutput)
828 {
829         SKIP_FLAG(has_output);
830         ASSERT_EXIT({for (int i = 0; i < output_count; i++) {
831                                          tdm_error error = TDM_ERROR_NONE;
832                                          tdm_output * output = tdm_display_get_output(dpy, i, &error);
833                                          if (NULL == output) exit(1);
834                                          if (TDM_ERROR_NONE != error) exit(1);
835                                          if (tdm_output_get_pipe(output, NULL) == TDM_ERROR_NONE) exit(1);
836                                 }
837                                 exit(0);}, ::testing::ExitedWithCode(0), "");
838 }
839
840 TEST_F(TDMOutput, OutputSetPropertySuccessful)
841 {
842         SKIP_FLAG(has_output);
843         for (int i = 0; i < output_count; i++) {
844                 tdm_error error = TDM_ERROR_NONE;
845                 tdm_value value = {.u32 = 0};
846                 tdm_output * output = tdm_display_get_output(dpy, i, &error);
847                 ASSERT_FALSE(NULL == output);
848                 ASSERT_TRUE(TDM_ERROR_NONE == error);
849                 error = tdm_output_set_property(output, UINT_MAX, value);
850                 ASSERT_TRUE(error == TDM_ERROR_NOT_IMPLEMENTED || error == TDM_ERROR_OPERATION_FAILED);
851         }
852 }
853
854 TEST_F(TDMOutput, OutputSetPropertyFailNullAll)
855 {
856         SKIP_FLAG(has_output);
857         ASSERT_EXIT({tdm_error error = TDM_ERROR_NONE;
858                                  tdm_value value = {.u32 = 0};
859                                  error = tdm_output_set_property(NULL, 0, value);
860                                  if (error == TDM_ERROR_NONE || error == TDM_ERROR_NOT_IMPLEMENTED ||
861                                         error == TDM_ERROR_OPERATION_FAILED) exit(1);
862                                  exit(0);}, ::testing::ExitedWithCode(0), "");
863 }