utest: Add 16 tests cases for tdm_buffer
[platform/core/uifw/libtdm.git] / utests / src / ut_tdm_capture.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 "tdm.h"
34 extern "C" {
35 #include "tbm_bufmgr.h"
36 #include "tbm_drm_helper.h"
37 }
38
39 #include <sys/epoll.h>
40 #include <sys/timerfd.h>
41 #include <vector>
42
43 class TDMCaptureWithoutCreation : public testing::Test {
44 protected:
45         tdm_display *dpy = nullptr;
46         tbm_bufmgr bufmgr = nullptr;
47         tdm_display_capability display_capability = (tdm_display_capability)0;
48         bool has_capture = false;
49         std::vector<tdm_output *> output_array;
50
51         virtual void SetEnvs()
52         {
53                 setenv("TDM_DLOG", "1", 1);
54                 setenv("XDG_RUNTIME_DIR", ".", 1);
55                 setenv("TBM_DLOG", "1", 1);
56                 setenv("TDM_DEBUG_MODULE", "all", 1);
57                 setenv("TDM_DEBUG", "1", 1);
58                 setenv("TBM_DISPLAY_SERVER", "1", 1);
59         }
60
61         virtual void UnsetEnvs()
62         {
63                 unsetenv("TDM_DLOG");
64                 unsetenv("XDG_RUNTIME_DIR");
65                 unsetenv("TBM_DLOG");
66                 unsetenv("TDM_DEBUG_MODULE");
67                 unsetenv("TDM_DEBUG");
68                 unsetenv("TBM_DISPLAY_SERVER");
69         }
70
71         void SetUp(void)
72         {
73                 tdm_error error = TDM_ERROR_NONE;
74                 int output_count;
75
76                 SetEnvs();
77
78                 /* FIXME: fix the error. If we initialize TBM before TDM we get fail
79                  * in the tdm_output_set_dpms */
80 #if 0
81                 tbm_bufmgr = tbm_bufmgr_init(-1);
82                 ASSERT_FALSE(tbm_bufmgr == NULL);
83 #endif
84
85                 dpy = tdm_display_init(&error);
86                 ASSERT_TRUE(error == TDM_ERROR_NONE);
87                 ASSERT_FALSE(dpy == nullptr);
88
89                 error = tdm_display_get_capabilities(dpy, &display_capability);
90 #ifdef FAIL_ON_UNSUPPORTED
91                 ASSERT_TRUE(display_capability & TDM_DISPLAY_CAPABILITY_CAPTURE);
92 #endif
93                 ASSERT_TRUE(error == TDM_ERROR_NONE);
94
95                 if (display_capability & TDM_DISPLAY_CAPABILITY_CAPTURE)
96                         has_capture = true;
97
98                 ASSERT_TRUE(tdm_display_get_output_count(dpy, &output_count) == TDM_ERROR_NONE);
99
100                 for (int i = 0; i < output_count; i++) {
101                         tdm_output *output = tdm_display_get_output(dpy, i, &error);
102
103                         if (TDM_ERROR_NONE != error || nullptr == output)
104                                 continue;
105
106                         tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
107                         if (TDM_ERROR_NONE != tdm_output_get_conn_status(output, &status))
108                                 continue;
109
110                         if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
111                                 continue;
112
113                         output_array.push_back(output);
114                 }
115         }
116
117         void TearDown(void)
118         {
119                 if (dpy)
120                         tdm_display_deinit(dpy);
121                 if (bufmgr)
122                         tbm_bufmgr_deinit(bufmgr);
123
124                 UnsetEnvs();
125         }
126 };
127
128 struct UtCapture
129 {
130         tdm_output *output;
131         const tdm_output_mode *output_mode;
132         tdm_capture *capture;
133         std::vector<tdm_layer *> layers;
134         UtCapture(tdm_output *, const tdm_output_mode *, tdm_capture *,  std::vector<tdm_layer *>);
135 };
136
137 UtCapture::UtCapture(tdm_output *_output, const tdm_output_mode *_output_mode,
138                                          tdm_capture *_capture, std::vector<tdm_layer *> _layers)
139 {
140         output = _output;
141         output_mode = _output_mode;
142         capture = _capture;
143         layers = _layers;
144 }
145
146 class TDMCapture : public TDMCaptureWithoutCreation {
147 protected:
148         const tbm_format *formats = nullptr;
149         int format_count = 0;
150         std::vector<UtCapture> captures;
151         std::vector<tbm_surface_h> buffers;
152         static int utCaptureDoneHandlerSuccessCounter;
153         friend void UtCaptureDoneHandler(tdm_capture *capture,
154                                                           tbm_surface_h buffer, void *user_data);
155         void SetUp(void);
156         void TearDown(void);
157         void UtCaptureGetInfo(UtCapture *capture, double scale, tdm_transform transform, tdm_info_capture *info);
158         void UtCaptureGetInfo(UtCapture *capture, tdm_info_capture *info);
159         tbm_surface_h UtCaptureCreateBuffer(UtCapture *capture);
160         tbm_surface_h UtCaptureCreateBuffer(int width, int height, tbm_format format, int scanout);
161         tbm_surface_h UtCaptureCreateBuffer(int width, int height, tbm_format format);
162 };
163
164 int TDMCapture::utCaptureDoneHandlerSuccessCounter = 0;
165
166 void UtCaptureDoneHandler(tdm_capture *capture,
167                                                   tbm_surface_h buffer, void *user_data)
168 {
169         TDMCapture *fcapture = (TDMCapture *)user_data;
170
171         if (!fcapture)
172                 return;
173
174         for (tbm_surface_h buf : fcapture->buffers) {
175                 if (buf == buffer) {
176                         fcapture->utCaptureDoneHandlerSuccessCounter++;
177                         break;
178                 }
179         }
180 }
181
182 void TDMCapture::SetUp(void)
183 {
184         tdm_error error;
185
186         utCaptureDoneHandlerSuccessCounter = 0;
187
188         ASSERT_NO_FATAL_FAILURE(TDMCaptureWithoutCreation::SetUp());
189
190         if (!has_capture)
191                 return;
192
193         for (tdm_output *output : output_array) {
194                 const tdm_output_mode *output_mode = nullptr;
195                 int output_modes_cnt = 0;
196                 const tdm_output_mode *output_modes;
197                 int temp_layer_count = 0;
198                 std::vector<tdm_layer *> layers;
199
200                 error = tdm_output_get_available_modes(output, &output_modes, &output_modes_cnt);
201                 ASSERT_EQ(TDM_ERROR_NONE, error);
202
203                 for(int j = 0; j < output_modes_cnt; j++)
204                         if(output_modes[j].type & TDM_OUTPUT_MODE_TYPE_PREFERRED)
205                                 output_mode = &output_modes[j];
206
207                 ASSERT_NE(nullptr, output_mode);
208
209                 if (TDM_ERROR_NONE != tdm_output_get_layer_count(output, &temp_layer_count))
210                         continue;
211                 if (0 == temp_layer_count)
212                         continue;
213
214                 for (int i = 0; i < temp_layer_count; ++i) {
215                         tdm_layer *layer;
216                         layer = tdm_output_get_layer(output, i, &error);
217                         ASSERT_TRUE(TDM_ERROR_NONE == error);
218                         ASSERT_FALSE(NULL == layer);
219                         layers.push_back(layer);
220                 }
221
222                 tdm_capture *capture = tdm_output_create_capture(output, &error);
223                 ASSERT_NE(nullptr, capture);
224                 ASSERT_EQ(TDM_ERROR_NONE, error);
225
226                 captures.emplace_back(output, output_mode, capture, layers);
227         }
228
229         error =
230                 tdm_display_get_catpure_available_formats(dpy, &formats, &format_count);
231         ASSERT_EQ(TDM_ERROR_NONE, error);
232         ASSERT_NE(nullptr, formats);
233         ASSERT_GE(format_count, 0);
234 }
235
236 void TDMCapture::TearDown(void)
237 {
238         for (UtCapture & utCapture : captures)
239                 tdm_capture_destroy(utCapture.capture);
240
241         for (tbm_surface_h buffer : buffers) {
242                 tbm_surface_destroy(buffer);
243         }
244
245         TDMCaptureWithoutCreation::TearDown();
246 }
247
248 void TDMCapture::UtCaptureGetInfo(UtCapture *capture, double scale,
249                                                                   tdm_transform transform, tdm_info_capture *info)
250 {
251         memset((void *)info, 0, sizeof(tdm_info_capture));
252
253         const tdm_output_mode *output_mode = capture->output_mode;
254
255         int w = output_mode->hdisplay * scale;
256         int h = output_mode->vdisplay * scale;
257
258         info->dst_config.size.h = w;
259         info->dst_config.size.v = h;
260         info->dst_config.pos.x = 0;
261         info->dst_config.pos.y = 0;
262         info->dst_config.pos.w = w;
263         info->dst_config.pos.h = h;
264         info->dst_config.format = formats[0];
265         info->transform = transform;
266         info->type = TDM_CAPTURE_TYPE_ONESHOT;
267 }
268
269 void TDMCapture::UtCaptureGetInfo(UtCapture *capture, tdm_info_capture *info)
270 {
271         UtCaptureGetInfo(capture, 1.0, TDM_TRANSFORM_NORMAL, info);
272 }
273
274 tbm_surface_h
275 TDMCapture::UtCaptureCreateBuffer(UtCapture *capture)
276 {
277         tbm_surface_h buffer;
278
279         buffer = tbm_surface_create(capture->output_mode->hdisplay,
280                                                                 capture->output_mode->vdisplay, formats[0]);
281         if (buffer)
282                 buffers.push_back(buffer);
283
284         return buffer;
285 }
286
287 tbm_surface_h
288 TDMCapture::UtCaptureCreateBuffer(int width, int height, tbm_format format, int scanout)
289 {
290         tbm_surface_h buffer;
291
292         if (scanout)
293                 buffer = tbm_surface_internal_create_with_flags(width, height, format, TBM_BO_SCANOUT);
294         else
295                 buffer = tbm_surface_internal_create_with_flags(width, height, format, TBM_BO_DEFAULT);
296
297         if (buffer)
298                 buffers.push_back(buffer);
299
300         return buffer;
301 }
302
303 tbm_surface_h
304 TDMCapture::UtCaptureCreateBuffer(int width, int height, tbm_format format)
305 {
306         return UtCaptureCreateBuffer(width, height, format, 0);
307 }
308
309 class TDMCaptureCommit : public TDMCapture {
310 public:
311 private:
312         int epFd = -1;
313         int timerFd = -1;
314         int tdmFd = -1;
315         static const int timeLimitSec = 3;
316         static const int timeLimitNsec = 0;
317 protected:
318         void SetUp(void);
319         void TearDown(void);
320         void UtHandleCaptureEvent();
321         int UtPrepareToCapture(double scale, tdm_transform transform);
322         int UtPrepareToCapture();
323 };
324
325 void TDMCaptureCommit::SetUp(void)
326 {
327         struct epoll_event ep;
328         tdm_error error;
329
330         ASSERT_NO_FATAL_FAILURE(TDMCapture::SetUp());
331
332         for (UtCapture & utCapture : captures) {
333                 error = tdm_output_set_mode(utCapture.output, utCapture.output_mode);
334                 ASSERT_TRUE(error == TDM_ERROR_NONE);
335
336                 error = tdm_output_set_dpms(utCapture.output, TDM_OUTPUT_DPMS_ON);
337                 ASSERT_TRUE(error == TDM_ERROR_NONE);
338
339                 for (tdm_layer *layer : utCapture.layers) {
340                         int w, h;
341                         tdm_layer_capability lcapabilities;
342                         tbm_surface_h buffer;
343                         tdm_info_layer layer_info = {0};
344
345                         w = utCapture.output_mode->hdisplay;
346                         h = utCapture.output_mode->vdisplay;
347
348                         error = tdm_layer_get_capabilities(layer, &lcapabilities);
349                         ASSERT_EQ(TDM_ERROR_NONE, error);
350                         if (!(lcapabilities & TDM_LAYER_CAPABILITY_PRIMARY)) {
351                                 w = w / 2;
352                                 h = h / 2;
353                         }
354
355                         buffer = UtCaptureCreateBuffer(w, h, TBM_FORMAT_ARGB8888, 1);
356                         ASSERT_NE(nullptr, buffer);
357
358                         layer_info.src_config.size.h = w;
359                         layer_info.src_config.size.v = h;
360                         layer_info.src_config.pos.x = 0;
361                         layer_info.src_config.pos.y = 0;
362                         layer_info.src_config.pos.w = w;
363                         layer_info.src_config.pos.h = h;
364                         layer_info.src_config.format = TBM_FORMAT_ARGB8888;
365                         layer_info.dst_pos.x = 0;
366                         layer_info.dst_pos.y = 0;
367                         layer_info.dst_pos.w = w;
368                         layer_info.dst_pos.h = h;
369                         layer_info.transform = TDM_TRANSFORM_NORMAL;
370
371                         error = tdm_layer_set_info(layer, &layer_info);
372                         ASSERT_EQ(TDM_ERROR_NONE, error);
373
374                         error = tdm_layer_set_buffer(layer, buffer);
375                         ASSERT_EQ(TDM_ERROR_NONE, error);
376                 }
377
378                 error = tdm_output_commit(utCapture.output, 0, nullptr, nullptr);
379                 ASSERT_EQ(TDM_ERROR_NONE, error);
380         }
381
382         /* TODO: use output_commit_handle */
383         usleep(200000);
384
385         epFd = epoll_create1(0);
386         ASSERT_TRUE(epFd != -1);
387
388         timerFd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
389         ASSERT_TRUE(timerFd != -1);
390
391         memset(&ep, 0, sizeof ep);
392         ep.events |= EPOLLIN;
393         ep.data.fd = timerFd;
394         ASSERT_TRUE(epoll_ctl(epFd, EPOLL_CTL_ADD, timerFd, &ep) == 0);
395
396         ASSERT_TRUE(tdm_display_get_fd(dpy, &tdmFd) == TDM_ERROR_NONE);
397
398         memset(&ep, 0, sizeof ep);
399         ep.events |= EPOLLIN;
400         ep.data.fd = tdmFd;
401         ASSERT_TRUE(epoll_ctl(epFd, EPOLL_CTL_ADD, tdmFd, &ep) == 0);
402 }
403
404 void TDMCaptureCommit::TearDown(void)
405 {
406         if (epFd)
407                 close(epFd);
408         if (timerFd)
409                 close(timerFd);
410
411         for (UtCapture & utCapture : captures) {
412                 for (tdm_layer *layer : utCapture.layers)
413                         tdm_layer_unset_buffer(layer);
414
415                 tdm_output_set_dpms(utCapture.output, TDM_OUTPUT_DPMS_OFF);
416         }
417
418         TDMCapture::TearDown();
419 }
420
421 void TDMCaptureCommit::UtHandleCaptureEvent()
422 {
423         struct itimerspec its;
424         int count;
425         struct epoll_event ep_event[2];
426
427         if (utCaptureDoneHandlerSuccessCounter == (int)captures.size())
428                 return;
429
430         its.it_interval.tv_sec = 0;
431         its.it_interval.tv_nsec = 0;
432         its.it_value.tv_sec = timeLimitSec;
433         its.it_value.tv_nsec = timeLimitNsec;
434
435         ASSERT_TRUE(timerfd_settime(timerFd, 0, &its, NULL) == 0);
436
437         while (1) {
438                 count = epoll_wait(epFd, ep_event, sizeof(ep_event), -1);
439                 ASSERT_TRUE(count >= 0);
440
441                 for (int i = 0; i < count; i++) {
442                         if (ep_event[i].data.fd == timerFd) {
443                                 return;
444                         } else {
445                                 ASSERT_TRUE(tdm_display_handle_events(dpy) == TDM_ERROR_NONE);
446                                 if (utCaptureDoneHandlerSuccessCounter == (int)captures.size())
447                                         return;
448                         }
449                 }
450         }
451 }
452
453 int TDMCaptureCommit::UtPrepareToCapture(double scale, tdm_transform transform)
454 {
455         tdm_error error;
456         tbm_surface_h buffer;
457
458         for (UtCapture & utCapture : captures) {
459                 tdm_info_capture info = {0};
460
461                 UtCaptureGetInfo(&utCapture, scale, transform, &info);
462
463                 error = tdm_capture_set_done_handler(utCapture.capture, UtCaptureDoneHandler, this);
464                 EXPECT_EQ(TDM_ERROR_NONE, error);
465                 if (error != TDM_ERROR_NONE)
466                         return -1;
467
468                 error = tdm_capture_set_info(utCapture.capture, &info);
469                 EXPECT_EQ(TDM_ERROR_NONE, error);
470                 if (error != TDM_ERROR_NONE)
471                         return -1;
472
473                 buffer = UtCaptureCreateBuffer(info.dst_config.size.h,
474                                                                            info.dst_config.size.v,
475                                                                            info.dst_config.format);
476                 EXPECT_NE(NULL, buffer);
477                 if (!buffer)
478                         return -1;
479
480                 error = tdm_capture_attach(utCapture.capture, buffer);
481                 EXPECT_EQ(TDM_ERROR_NONE, error);
482                 if (error != TDM_ERROR_NONE)
483                         return -1;
484         }
485
486         return 0;
487 }
488
489 int TDMCaptureCommit::UtPrepareToCapture()
490 {
491         return UtPrepareToCapture(1.0, TDM_TRANSFORM_NORMAL);
492 }
493
494 class TDMCaptureCommitThread : public TDMCaptureCommit {
495 protected:
496         void SetEnvs()
497         {
498                 TDMCaptureCommit::SetEnvs();
499                 setenv("TDM_THREAD", "1", 1);
500         }
501         void UnsetEnvs()
502         {
503                 TDMCaptureCommit::UnsetEnvs();
504                 unsetenv("TDM_THREAD");
505         }
506 };
507
508 TEST_F(TDMCaptureWithoutCreation, DisplayGetCaptureAvailableFormatsSuccessful)
509 {
510         SKIP_FLAG(has_capture);
511         const tbm_format * formats = nullptr;
512         int count = -42;
513         ASSERT_TRUE(TDM_ERROR_NONE == tdm_display_get_catpure_available_formats(dpy, &formats, &count));
514         ASSERT_FALSE(-42 == count);
515         ASSERT_FALSE(nullptr == formats);
516 }
517
518 /* tdm_display_create_pp() */
519
520 TEST_F(TDMCaptureWithoutCreation, DisplayCreateCaptureNullAll)
521 {
522         SKIP_FLAG(has_capture);
523         tdm_capture *capture;
524
525         capture = tdm_output_create_capture(nullptr, nullptr);
526         ASSERT_EQ(nullptr, capture);
527 }
528
529 TEST_F(TDMCaptureWithoutCreation, DisplayCreateCaptureNullOutput)
530 {
531         SKIP_FLAG(has_capture);
532         tdm_capture *capture;
533         tdm_error error;
534
535         capture = tdm_output_create_capture(nullptr, &error);
536         ASSERT_EQ(nullptr, capture);
537         ASSERT_NE(TDM_ERROR_NONE, error);
538 }
539
540 TEST_F(TDMCaptureWithoutCreation, DisplayCreateCaptureSuccessNullError)
541 {
542         SKIP_FLAG(has_capture);
543         tdm_capture *capture;
544
545         for (tdm_output *output : output_array) {
546                 capture = tdm_output_create_capture(output, nullptr);
547                 ASSERT_NE(nullptr, capture);
548         }
549 }
550
551 TEST_F(TDMCaptureWithoutCreation, DisplayCreateCaptureSuccess)
552 {
553         SKIP_FLAG(has_capture);
554         tdm_capture *capture;
555         tdm_error error;
556
557         for (tdm_output *output : output_array) {
558                 capture = tdm_output_create_capture(output, &error);
559                 ASSERT_NE(nullptr, capture);
560                 ASSERT_EQ(TDM_ERROR_NONE, error);
561         }
562 }
563
564 /* tdm_display_get_capture_available_size */
565
566 TEST_F(TDMCapture, DisplayGetCaptureAvailableSizeFailNullAll)
567 {
568         SKIP_FLAG(has_capture);
569         tdm_error error;
570
571         error = tdm_display_get_capture_available_size(nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
572         ASSERT_NE(TDM_ERROR_NONE, error);
573 }
574
575 TEST_F(TDMCapture, DisplayGetCaptureAvailableSizeSuccess)
576 {
577         SKIP_FLAG(has_capture);
578         tdm_error error;
579         int min_w;
580         int min_h;
581         int max_w;
582         int max_h;
583         int preferred_align;
584
585         error = tdm_display_get_capture_available_size(dpy, &min_w, &min_h,
586                                                                                                    &max_w, &max_h, &preferred_align);
587         ASSERT_EQ(TDM_ERROR_NONE, error);
588 }
589
590
591 /* tdm_capture_set_info() */
592
593 TEST_F(TDMCapture, CaptureSetInfoFailNullAll)
594 {
595         SKIP_FLAG(has_capture);
596         tdm_error error;
597
598         error = tdm_capture_set_info(nullptr, nullptr);
599         ASSERT_NE(TDM_ERROR_NONE, error);
600 }
601
602 TEST_F(TDMCapture, CaptureSetInfoFailNullCapture)
603 {
604         SKIP_FLAG(has_capture);
605         tdm_error error;
606         tdm_info_capture info;
607
608         error = tdm_capture_set_info(nullptr, &info);
609         ASSERT_NE(TDM_ERROR_NONE, error);
610 }
611
612 TEST_F(TDMCapture, CaptureSetInfoNullInfo)
613 {
614         SKIP_FLAG(has_capture);
615         tdm_error error;
616
617         for (UtCapture & utCapture : captures) {
618                 error = tdm_capture_set_info(utCapture.capture, nullptr);
619                 ASSERT_NE(TDM_ERROR_NONE, error);
620         }
621 }
622
623 TEST_F(TDMCapture, CaptureSetInfoSuccessStream)
624 {
625         SKIP_FLAG(has_capture);
626         tdm_error error;
627         tdm_info_capture info;
628
629         for (UtCapture & utCapture : captures) {
630                 error = tdm_output_set_mode(utCapture.output, utCapture.output_mode);
631                 ASSERT_EQ(TDM_ERROR_NONE, error);
632
633                 UtCaptureGetInfo(&utCapture, &info);
634
635                 info.type = TDM_CAPTURE_TYPE_STREAM;
636
637                 error = tdm_capture_set_info(utCapture.capture, &info);
638                 ASSERT_EQ(TDM_ERROR_NONE, error);
639         }
640 }
641
642 TEST_F(TDMCapture, CaptureSetInfoSuccess)
643 {
644         SKIP_FLAG(has_capture);
645         tdm_error error;
646         tdm_info_capture info;
647
648         for (UtCapture & utCapture : captures) {
649                 UtCaptureGetInfo(&utCapture, &info);
650
651                 error = tdm_capture_set_info(utCapture.capture, &info);
652                 ASSERT_EQ(TDM_ERROR_NONE, error);
653         }
654 }
655
656 /* tdm_capture_set_done_handler() */
657
658 TEST_F(TDMCapture, CaptureSetDoneHandlerFailNullAll)
659 {
660         SKIP_FLAG(has_capture);
661         tdm_error error;
662
663         error = tdm_capture_set_done_handler(nullptr, nullptr, nullptr);
664         ASSERT_NE(TDM_ERROR_NONE, error);
665 }
666
667 TEST_F(TDMCapture, CaptureSetDoneHandlerFailNullCapture)
668 {
669         SKIP_FLAG(has_capture);
670         tdm_error error;
671
672         error = tdm_capture_set_done_handler(nullptr, UtCaptureDoneHandler, this);
673         ASSERT_NE(TDM_ERROR_NONE, error);
674 }
675
676 TEST_F(TDMCapture, CaptureSetDoneHandlerSuccessNullFailNullFunc)
677 {
678         SKIP_FLAG(has_capture);
679         tdm_error error;
680
681         for (UtCapture & utCapture : captures) {
682                 error = tdm_pp_set_done_handler(utCapture.capture, nullptr, this);
683                 ASSERT_NE(TDM_ERROR_NONE, error);
684         }
685 }
686
687 TEST_F(TDMCapture, CaptureSetDoneHandlerSuccessNullData)
688 {
689         SKIP_FLAG(has_capture);
690         tdm_error error;
691
692         for (UtCapture & utCapture : captures) {
693                 error = tdm_capture_set_done_handler(utCapture.capture, UtCaptureDoneHandler, this);
694                 ASSERT_EQ(TDM_ERROR_NONE, error);
695         }
696 }
697
698 TEST_F(TDMCapture, CaptureSetDoneHandlerSuccess)
699 {
700         SKIP_FLAG(has_capture);
701         tdm_error error;
702
703         for (UtCapture & utCapture : captures) {
704                 error = tdm_capture_set_done_handler(utCapture.capture, UtCaptureDoneHandler, this);
705                 ASSERT_EQ(TDM_ERROR_NONE, error);
706         }
707 }
708
709 /* tdm_capture_attach() */
710
711 TEST_F(TDMCapture, CaptureAttachFailNullAll)
712 {
713         SKIP_FLAG(has_capture);
714         tdm_error error;
715
716         error = tdm_capture_attach(nullptr, nullptr);
717         ASSERT_NE(TDM_ERROR_NONE, error);
718 }
719
720 TEST_F(TDMCapture, CaptureAttachFailNullCapture)
721 {
722         SKIP_FLAG(has_capture);
723         tdm_error error;
724         tbm_surface_h buffer;
725
726         buffer = UtCaptureCreateBuffer(&captures[0]);
727         ASSERT_NE(nullptr, buffer);
728
729         error = tdm_capture_attach(nullptr, buffer);
730         ASSERT_NE(TDM_ERROR_NONE, error);
731 }
732
733 TEST_F(TDMCapture, CaptureAttachFailNullBuffer)
734 {
735         SKIP_FLAG(has_capture);
736         tdm_error error;
737
738         for (UtCapture & utCapture : captures) {
739                 error = tdm_capture_attach(utCapture.capture, nullptr);
740                 ASSERT_NE(TDM_ERROR_NONE, error);
741         }
742 }
743
744 TEST_F(TDMCapture, CaptureAttachSuccess)
745 {
746         SKIP_FLAG(has_capture);
747         tdm_error error;
748         tbm_surface_h buffer;
749
750         for (UtCapture & utCapture : captures) {
751                 buffer = UtCaptureCreateBuffer(&utCapture);
752                 ASSERT_NE(nullptr, buffer);
753
754                 error = tdm_capture_attach(utCapture.capture, buffer);
755                 ASSERT_EQ(TDM_ERROR_NONE, error);
756         }
757 }
758
759 /* tdm_pp_commit() */
760
761 TEST_F(TDMCapture, CaptureCommitFailNullCapture)
762 {
763         SKIP_FLAG(has_capture);
764         tdm_error error;
765
766         error = tdm_capture_commit(nullptr);
767         ASSERT_NE(TDM_ERROR_NONE, error);
768 }
769
770 TEST_F(TDMCapture, CaptureCommitFailDpmsOff)
771 {
772         SKIP_FLAG(has_capture);
773         tdm_error error;
774
775         for (UtCapture & utCapture : captures) {
776                 error = tdm_capture_commit(utCapture.capture);
777                 ASSERT_NE(TDM_ERROR_NONE, error);
778         }
779 }
780
781 TEST_F(TDMCaptureCommit, CaptureCommitSuccess)
782 {
783         SKIP_FLAG(has_capture);
784         tdm_error error;
785
786         ASSERT_NE(-1, UtPrepareToCapture());
787
788         for (UtCapture & utCapture : captures) {
789                 error = tdm_capture_commit(utCapture.capture);
790                 ASSERT_EQ(TDM_ERROR_NONE, error);
791         }
792
793         UtHandleCaptureEvent();
794
795         ASSERT_EQ(captures.size(), utCaptureDoneHandlerSuccessCounter);
796 }
797
798 TEST_F(TDMCaptureCommitThread, CaptureCommitSuccess)
799 {
800         SKIP_FLAG(has_capture);
801         tdm_error error;
802
803         ASSERT_NE(-1, UtPrepareToCapture());
804
805         for (UtCapture & utCapture : captures) {
806                 error = tdm_capture_commit(utCapture.capture);
807                 ASSERT_EQ(TDM_ERROR_NONE, error);
808         }
809
810         UtHandleCaptureEvent();
811
812         ASSERT_EQ(captures.size(), utCaptureDoneHandlerSuccessCounter);
813 }
814
815 TEST_F(TDMCaptureCommit, CaptureCommitSuccessScale)
816 {
817         SKIP_FLAG(has_capture);
818         tdm_error error;
819
820         ASSERT_NE(-1, UtPrepareToCapture(2.0, TDM_TRANSFORM_NORMAL));
821
822         for (UtCapture & utCapture : captures) {
823                 error = tdm_capture_commit(utCapture.capture);
824                 ASSERT_EQ(TDM_ERROR_NONE, error);
825         }
826
827         UtHandleCaptureEvent();
828
829         ASSERT_EQ(captures.size(), utCaptureDoneHandlerSuccessCounter);
830 }
831
832 TEST_F(TDMCaptureCommit, CaptureCommitSuccessScaleAndTransform)
833 {
834         SKIP_FLAG(has_capture);
835         tdm_error error;
836
837         ASSERT_NE(-1, UtPrepareToCapture(2.0, TDM_TRANSFORM_180));
838
839         for (UtCapture & utCapture : captures) {
840                 error = tdm_capture_commit(utCapture.capture);
841                 ASSERT_EQ(TDM_ERROR_NONE, error);
842         }
843
844         UtHandleCaptureEvent();
845
846         ASSERT_EQ(captures.size(), utCaptureDoneHandlerSuccessCounter);
847 }