turn on the utests bulding and fix svace issues
[platform/core/uifw/libtdm.git] / utests / src / ut_tdm_pp.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 <list>
42 #include <limits.h>
43
44 #define SIZE_ALIGN(value, base) (((value) + ((base) - 1)) & ~((base) - 1))
45
46 class TDMPPWithoutCreation : public testing::Test {
47 protected:
48         tdm_display *dpy = NULL;
49         tbm_bufmgr bufmgr;
50         tdm_display_capability display_capability = (tdm_display_capability)0;
51         bool has_pp = false;
52         std::list<tbm_surface_h> buffers_list;
53
54         virtual void SetEnvs()
55         {
56                 setenv("TDM_DLOG", "1", 1);
57                 setenv("XDG_RUNTIME_DIR", ".", 1);
58                 setenv("TBM_DLOG", "1", 1);
59                 setenv("TDM_DEBUG_MODULE", "all", 1);
60                 setenv("TDM_DEBUG", "1", 1);
61                 setenv("TBM_DISPLAY_SERVER", "1", 1);
62         }
63
64         virtual void UnsetEnvs()
65         {
66                 unsetenv("TDM_DLOG");
67                 unsetenv("XDG_RUNTIME_DIR");
68                 unsetenv("TBM_DLOG");
69                 unsetenv("TDM_DEBUG_MODULE");
70                 unsetenv("TDM_DEBUG");
71                 unsetenv("TBM_DISPLAY_SERVER");
72         }
73
74         void SetUp(void)
75         {
76                 tdm_error error = TDM_ERROR_NONE;
77
78                 SetEnvs();
79
80                 bufmgr = tbm_bufmgr_init(-1);
81                 ASSERT_FALSE(bufmgr == NULL);
82
83                 dpy = tdm_display_init(&error);
84                 ASSERT_TRUE(error == TDM_ERROR_NONE);
85                 ASSERT_FALSE(dpy == NULL);
86
87                 error = tdm_display_get_capabilities(dpy, &display_capability);
88 #ifdef FAIL_ON_UNSUPPORTED
89                 ASSERT_TRUE(display_capability & TDM_DISPLAY_CAPABILITY_PP);
90 #endif
91                 ASSERT_TRUE(error == TDM_ERROR_NONE);
92
93                 if (display_capability & TDM_DISPLAY_CAPABILITY_PP)
94                         has_pp = true;
95         }
96
97         void TearDown(void)
98         {
99                 if (dpy)
100                         tdm_display_deinit(dpy);
101                 if (bufmgr)
102                         tbm_bufmgr_deinit(bufmgr);
103
104                 UnsetEnvs();
105         }
106 };
107
108 class TDMPP : public TDMPPWithoutCreation {
109 protected:
110         tdm_pp *pp = NULL;
111         const tbm_format *formats = NULL;
112         int format_count = 0;
113         int min_w = 0;
114         int min_h = 0;
115         int max_w = 0;
116         int max_h = 0;
117         int preferred_align = 0;
118         int default_src_w = 128;
119         int default_src_h = 256;
120         int default_dst_w = 512;
121         int default_dst_h = 1024;
122
123         void SetUp(void)
124         {
125                 tdm_error error;
126
127                 ASSERT_NO_FATAL_FAILURE(TDMPPWithoutCreation::SetUp());
128
129                 if (!has_pp)
130                         return;
131
132                 pp = tdm_display_create_pp(dpy, &error);
133                 ASSERT_NE(NULL, pp);
134                 ASSERT_EQ(TDM_ERROR_NONE, error);
135
136                 error =
137                         tdm_display_get_pp_available_formats(dpy, &formats, &format_count);
138                 ASSERT_EQ(TDM_ERROR_NONE, error);
139                 ASSERT_NE(NULL, formats);
140                 ASSERT_GE(format_count, 0);
141
142                 error =
143                                 tdm_display_get_pp_available_size(dpy, &min_w, &min_h,
144                                                                                                   &max_w, &max_h, &preferred_align);
145                 ASSERT_EQ(TDM_ERROR_NONE, error);
146                 if (preferred_align > 0) {
147                         default_src_w = SIZE_ALIGN(default_src_w, preferred_align);
148                         default_src_h = SIZE_ALIGN(default_src_h, preferred_align);
149                         default_dst_w = SIZE_ALIGN(default_dst_w, preferred_align);
150                         default_dst_h = SIZE_ALIGN(default_dst_h, preferred_align);
151                 }
152                 if (min_w > default_src_w)
153                         default_src_w = min_w;
154                 if (min_h > default_src_h)
155                         default_src_h = min_h;
156                 if (max_w > 0 && max_w < default_dst_w)
157                         default_dst_w = max_w;
158                 if (max_h > 0 && max_h < default_dst_h)
159                         default_dst_h = max_h;
160         }
161
162         void TearDown(void)
163         {
164                 if (pp)
165                         tdm_pp_destroy(pp);
166
167                 for (auto it = buffers_list.begin(); it != buffers_list.end(); ++it) {
168                         tbm_surface_destroy(*it);
169                 }
170
171                 buffers_list.clear();
172
173                 TDMPPWithoutCreation::TearDown();
174         }
175
176         void UtGetPPInfoWithScale(tdm_info_pp *info)
177         {
178                 memset((void *)info, 0, sizeof(tdm_info_pp));
179
180                 info->src_config.size.h = default_src_w;
181                 info->src_config.size.v = default_src_h;
182                 info->src_config.pos.x = 0;
183                 info->src_config.pos.y = 0;
184                 info->src_config.pos.w = default_src_w;
185                 info->src_config.pos.h = default_src_h;
186                 info->src_config.format = formats[0];
187                 info->dst_config.size.h = default_dst_w;
188                 info->dst_config.size.v = default_dst_h;
189                 info->dst_config.pos.x = 0;
190                 info->dst_config.pos.y = 0;
191                 info->dst_config.pos.w = default_dst_w;
192                 info->dst_config.pos.h = default_dst_h;
193                 info->dst_config.format = formats[0];
194         }
195
196         void UtGetPPInfoWithScaleAndTransform(tdm_info_pp *info)
197         {
198                 UtGetPPInfoWithScale(info);
199
200                 info->transform = TDM_TRANSFORM_180;
201         }
202
203         void UtGetPPInfoWithWrongInfo(tdm_info_pp *info)
204         {
205                 info->src_config.size.h = UINT_MAX;
206                 info->src_config.size.v = UINT_MAX;
207                 info->src_config.pos.x = 0;
208                 info->src_config.pos.y = 0;
209                 info->src_config.pos.w = UINT_MAX;
210                 info->src_config.pos.h = UINT_MAX;
211                 info->src_config.format = INT_MAX;
212                 info->dst_config.size.h = UINT_MAX;
213                 info->dst_config.size.v = UINT_MAX;
214                 info->dst_config.pos.x = 0;
215                 info->dst_config.pos.y = 0;
216                 info->dst_config.pos.w = UINT_MAX;
217                 info->dst_config.pos.h = UINT_MAX;
218                 info->dst_config.format = INT_MAX;
219         }
220
221         tbm_surface_h
222         UtCreateBuffer(int w, int h, tbm_format format)
223         {
224                 tbm_surface_h buffer;
225
226                 buffer = tbm_surface_create(w, h, format);
227                 if (buffer)
228                         buffers_list.push_back(buffer);
229
230                 return buffer;
231         }
232 };
233
234 void UtPpDoneHandler(tdm_pp *pp, tbm_surface_h src,
235                                                         tbm_surface_h dst, void *user_data);
236
237 class TDMPPCommit : public TDMPP {
238 public:
239         friend void UtPpDoneHandler(tdm_pp *pp, tbm_surface_h src,
240                                                                 tbm_surface_h dst, void *user_data);
241 private:
242         int epFd = -1;
243         int timerFd = -1;
244         int tdmFd = -1;
245         static const int timeLimitSec = 0;
246         static const int timeLimitNsec = 100000000;
247 protected:
248         int utPpDoneHandlerSuccessCounter = 0;
249
250         void SetUp(void)
251         {
252                 struct epoll_event ep;
253
254                 ASSERT_NO_FATAL_FAILURE(TDMPP::SetUp());
255
256                 epFd = epoll_create1(0);
257                 ASSERT_TRUE(epFd != -1);
258
259                 timerFd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
260                 ASSERT_TRUE(timerFd != -1);
261
262                 memset(&ep, 0, sizeof ep);
263                 ep.events |= EPOLLIN;
264                 ep.data.fd = timerFd;
265                 ASSERT_TRUE(epoll_ctl(epFd, EPOLL_CTL_ADD, timerFd, &ep) == 0);
266
267                 ASSERT_TRUE(tdm_display_get_fd(dpy, &tdmFd) == TDM_ERROR_NONE);
268
269                 memset(&ep, 0, sizeof ep);
270                 ep.events |= EPOLLIN;
271                 ep.data.fd = tdmFd;
272                 ASSERT_TRUE(epoll_ctl(epFd, EPOLL_CTL_ADD, tdmFd, &ep) == 0);
273         }
274
275         void TearDown(void)
276         {
277                 if (epFd)
278                         close(epFd);
279                 if (timerFd)
280                         close(timerFd);
281
282                 TDMPP::TearDown();
283         }
284
285         void UtHandlePPEvent(int num_attached_buffers)
286         {
287                 struct itimerspec its;
288                 int count;
289                 struct epoll_event ep_event[2];
290
291                 if (utPpDoneHandlerSuccessCounter == num_attached_buffers)
292                         return;
293
294                 its.it_interval.tv_sec = 0;
295                 its.it_interval.tv_nsec = 0;
296                 its.it_value.tv_sec = timeLimitSec;
297                 its.it_value.tv_nsec = timeLimitNsec;
298
299                 ASSERT_TRUE(timerfd_settime(timerFd, 0, &its, NULL) == 0);
300
301                 while (1) {
302                         count = epoll_wait(epFd, ep_event, sizeof(ep_event), -1);
303                         ASSERT_TRUE(count >= 0);
304
305                         for (int i = 0; i < count; i++) {
306                                 if (ep_event[i].data.fd == timerFd) {
307                                         return;
308                                 } else {
309                                         ASSERT_TRUE(tdm_display_handle_events(dpy) == TDM_ERROR_NONE);
310                                         if (utPpDoneHandlerSuccessCounter == num_attached_buffers)
311                                                 return;
312                                 }
313                         }
314                 }
315         }
316
317         int UtPrepareToPP(tdm_info_pp *info)
318         {
319                 tdm_error error;
320                 tbm_surface_h src_buf, dst_buf;
321
322                 error = tdm_pp_set_done_handler(pp, UtPpDoneHandler, this);
323                 EXPECT_EQ(TDM_ERROR_NONE, error);
324                 if (error != TDM_ERROR_NONE)
325                         return -1;
326
327                 error = tdm_pp_set_info(pp, info);
328                 EXPECT_EQ(TDM_ERROR_NONE, error);
329                 if (error != TDM_ERROR_NONE)
330                         return -1;
331
332                 src_buf = UtCreateBuffer(info->src_config.pos.w, info->src_config.pos.h,
333                                                                  info->src_config.format);
334                 EXPECT_NE(NULL, src_buf);
335                 if (!src_buf)
336                         return -1;
337
338                 dst_buf = UtCreateBuffer(info->dst_config.pos.w, info->dst_config.pos.h,
339                                                                  info->dst_config.format);
340                 EXPECT_NE(NULL, dst_buf);
341                 if (!dst_buf)
342                         return -1;
343
344                 error = tdm_pp_attach(pp, src_buf, dst_buf);
345                 EXPECT_EQ(TDM_ERROR_NONE, error);
346                 if (error != TDM_ERROR_NONE)
347                         return -1;
348
349                 return 0;
350         }
351
352         int UtPrepareToPPWithScale()
353         {
354                 tdm_info_pp info = {0};
355
356                 UtGetPPInfoWithScale(&info);
357
358                 return UtPrepareToPP(&info);
359         }
360
361         int UtPrepareToPPWithScaleAndTransform()
362         {
363                 tdm_info_pp info = {0};
364
365                 UtGetPPInfoWithScaleAndTransform(&info);
366
367                 return UtPrepareToPP(&info);
368         }
369
370         int UtPrepareToPPWithWrongInfo()
371         {
372                 tdm_info_pp info = {0};
373                 tdm_error error;
374                 int ret;
375
376                 UtGetPPInfoWithScale(&info);
377
378                 ret = UtPrepareToPP(&info);
379                 if (ret < 0)
380                         return ret;
381
382                 UtGetPPInfoWithWrongInfo(&info);
383
384                 error = tdm_pp_set_info(pp, &info);
385                 EXPECT_EQ(TDM_ERROR_NONE, error);
386                 if (error != TDM_ERROR_NONE)
387                         return -1;
388
389                 return 0;
390         }
391
392 };
393
394 class TDMPPCommitThread : public TDMPPCommit {
395 protected:
396         void SetEnvs()
397         {
398                 TDMPPCommit::SetEnvs();
399                 setenv("TDM_THREAD", "1", 1);
400         }
401         void UnsetEnvs()
402         {
403                 TDMPPCommit::UnsetEnvs();
404                 unsetenv("TDM_THREAD");
405         }
406 };
407
408 void UtPpDoneHandler(tdm_pp *pp, tbm_surface_h src,
409                                                         tbm_surface_h dst, void *user_data)
410 {
411         TDMPPCommit *pp_commit = (TDMPPCommit *)user_data;
412         bool src_valid = false, dst_valid = false;
413
414         if (!pp_commit)
415                 return;
416
417         for (auto it = pp_commit->buffers_list.begin(); it != pp_commit->buffers_list.end(); ++it) {
418                 if (*it == src)
419                         src_valid = true;
420                 if (*it == dst)
421                         dst_valid = true;
422         }
423
424         if (src_valid && dst_valid)
425                 pp_commit->utPpDoneHandlerSuccessCounter++;
426 }
427
428 TEST_F(TDMPPWithoutCreation, DisplayGetPPAvailableFormatsSuccessful)
429 {
430         SKIP_FLAG(has_pp);
431         const tbm_format *formats = NULL;
432         int count = -42;
433         ASSERT_TRUE(TDM_ERROR_NONE == tdm_display_get_pp_available_formats(dpy, &formats, &count));
434         ASSERT_FALSE(-42 == count);
435         ASSERT_FALSE(NULL == formats);
436 }
437
438 /* tdm_display_create_pp() */
439
440 TEST_F(TDMPPWithoutCreation, DisplayCreatePPNullAll)
441 {
442         SKIP_FLAG(has_pp);
443         tdm_pp *pp;
444
445         pp = tdm_display_create_pp(NULL, NULL);
446         ASSERT_EQ(NULL, pp);
447 }
448
449 TEST_F(TDMPPWithoutCreation, DisplayCreatePPNullDpy)
450 {
451         SKIP_FLAG(has_pp);
452         tdm_pp *pp;
453         tdm_error error;
454
455         pp = tdm_display_create_pp(NULL, &error);
456         ASSERT_EQ(NULL, pp);
457         ASSERT_NE(TDM_ERROR_NONE, error);
458 }
459
460 TEST_F(TDMPPWithoutCreation, DisplayCreatePPSuccessNullError)
461 {
462         SKIP_FLAG(has_pp);
463         tdm_pp *pp;
464
465         pp = tdm_display_create_pp(dpy, NULL);
466         ASSERT_NE(NULL, pp);
467 }
468
469 TEST_F(TDMPPWithoutCreation, DisplayCreatePPSuccess)
470 {
471         SKIP_FLAG(has_pp);
472         tdm_pp *pp;
473         tdm_error error;
474
475         pp = tdm_display_create_pp(dpy, &error);
476         ASSERT_NE(NULL, pp);
477         ASSERT_EQ(TDM_ERROR_NONE, error);
478 }
479
480 /* tdm_pp_set_info() */
481
482 TEST_F(TDMPP, PpSetInfoNullAll)
483 {
484         SKIP_FLAG(has_pp);
485         tdm_error error;
486
487         error = tdm_pp_set_info(NULL, NULL);
488         ASSERT_NE(TDM_ERROR_NONE, error);
489 }
490
491 TEST_F(TDMPP, PpSetInfoNullPP)
492 {
493         SKIP_FLAG(has_pp);
494         tdm_error error;
495         tdm_info_pp info;
496
497         error = tdm_pp_set_info(NULL, &info);
498         ASSERT_NE(TDM_ERROR_NONE, error);
499 }
500
501 TEST_F(TDMPP, PpSetInfoNullInfo)
502 {
503         SKIP_FLAG(has_pp);
504         tdm_error error;
505
506         error = tdm_pp_set_info(pp, NULL);
507         ASSERT_NE(TDM_ERROR_NONE, error);
508 }
509
510 TEST_F(TDMPP, PpSetInfoSuccess)
511 {
512         SKIP_FLAG(has_pp);
513         tdm_error error;
514         tdm_info_pp info;
515
516         UtGetPPInfoWithScale(&info);
517
518         error = tdm_pp_set_info(pp, &info);
519         ASSERT_EQ(TDM_ERROR_NONE, error);
520 }
521
522 /* tdm_pp_set_done_handler() */
523
524 TEST_F(TDMPP, PpSetDoneHandlerFailNullAll)
525 {
526         SKIP_FLAG(has_pp);
527         tdm_error error;
528
529         error = tdm_pp_set_done_handler(NULL, NULL, NULL);
530         ASSERT_NE(TDM_ERROR_NONE, error);
531 }
532
533 TEST_F(TDMPP, PpSetDoneHandlerFailNullPP)
534 {
535         SKIP_FLAG(has_pp);
536         tdm_error error;
537
538         error = tdm_pp_set_done_handler(NULL, UtPpDoneHandler, this);
539         ASSERT_NE(TDM_ERROR_NONE, error);
540 }
541
542 TEST_F(TDMPP, PpSetDoneHandlerSuccessNullFailNullFunc)
543 {
544         SKIP_FLAG(has_pp);
545         tdm_error error;
546         int data;
547
548         error = tdm_pp_set_done_handler(pp, NULL, &data);
549         ASSERT_NE(TDM_ERROR_NONE, error);
550 }
551
552 TEST_F(TDMPP, PpSetDoneHandlerSuccessNullData)
553 {
554         SKIP_FLAG(has_pp);
555         tdm_error error;
556
557         error = tdm_pp_set_done_handler(pp, UtPpDoneHandler, this);
558         ASSERT_EQ(TDM_ERROR_NONE, error);
559 }
560
561 TEST_F(TDMPP, PpSetDoneHandlerSuccess)
562 {
563         SKIP_FLAG(has_pp);
564         tdm_error error;
565
566         error = tdm_pp_set_done_handler(pp, UtPpDoneHandler, this);
567         ASSERT_EQ(TDM_ERROR_NONE, error);
568 }
569
570 /* tdm_pp_attach() */
571
572 TEST_F(TDMPP, PpAttachFailNullAll)
573 {
574         SKIP_FLAG(has_pp);
575         tdm_error error;
576
577         error = tdm_pp_attach(NULL, NULL, NULL);
578         ASSERT_NE(TDM_ERROR_NONE, error);
579 }
580
581 TEST_F(TDMPP, PpAttachFailNullPp)
582 {
583         SKIP_FLAG(has_pp);
584         tdm_error error;
585         tbm_surface_h dst_buf, src_buf;
586
587         src_buf = UtCreateBuffer(default_src_w, default_src_h, formats[0]);
588         ASSERT_NE(NULL, src_buf);
589
590         dst_buf = UtCreateBuffer(default_dst_w, default_dst_h, formats[0]);
591         ASSERT_NE(NULL, dst_buf);
592
593         error = tdm_pp_attach(NULL, src_buf, dst_buf);
594         ASSERT_NE(TDM_ERROR_NONE, error);
595 }
596
597 TEST_F(TDMPP, PpAttachFailNullSrc)
598 {
599         SKIP_FLAG(has_pp);
600         tdm_error error;
601         tbm_surface_h dst_buf;
602
603         dst_buf = UtCreateBuffer(default_dst_w, default_dst_h, formats[0]);
604         ASSERT_NE(NULL, dst_buf);
605
606         error = tdm_pp_attach(pp, NULL, dst_buf);
607         ASSERT_NE(TDM_ERROR_NONE, error);
608 }
609
610 TEST_F(TDMPP, PpAttachFailNullDst)
611 {
612         SKIP_FLAG(has_pp);
613         tdm_error error;
614         tbm_surface_h src_buf;
615
616         src_buf = UtCreateBuffer(default_src_w, default_src_h, formats[0]);
617         ASSERT_NE(NULL, src_buf);
618
619         error = tdm_pp_attach(pp, src_buf, NULL);
620         ASSERT_NE(TDM_ERROR_NONE, error);
621 }
622
623 TEST_F(TDMPP, PpAttachSuccess)
624 {
625         SKIP_FLAG(has_pp);
626         tdm_error error;
627         tbm_surface_h dst_buf, src_buf;
628
629         src_buf = UtCreateBuffer(default_src_w, default_src_h, formats[0]);
630         ASSERT_NE(NULL, src_buf);
631
632         dst_buf = UtCreateBuffer(default_dst_w, default_dst_h, formats[0]);
633         ASSERT_NE(NULL, dst_buf);
634
635         error = tdm_pp_attach(pp, src_buf, dst_buf);
636         ASSERT_EQ(TDM_ERROR_NONE, error);
637 }
638
639 /* tdm_pp_commit() */
640
641 TEST_F(TDMPP, PpCommitFailNullPP)
642 {
643         SKIP_FLAG(has_pp);
644         tdm_error error;
645
646         error = tdm_pp_commit(NULL);
647         ASSERT_NE(TDM_ERROR_NONE, error);
648 }
649
650 TEST_F(TDMPPCommit, PpCommitFailWrongInfo)
651 {
652         SKIP_FLAG(has_pp);
653         tdm_error error;
654
655         ASSERT_NE(-1, UtPrepareToPPWithWrongInfo());
656
657         error = tdm_pp_commit(pp);
658         ASSERT_NE(TDM_ERROR_NONE, error);
659 }
660
661 TEST_F(TDMPPCommit, PpCommitSuccessScale)
662 {
663         SKIP_FLAG(has_pp);
664         tdm_error error;
665
666         ASSERT_NE(-1, UtPrepareToPPWithScale());
667
668         error = tdm_pp_commit(pp);
669         ASSERT_EQ(TDM_ERROR_NONE, error);
670
671         UtHandlePPEvent(1);
672
673         ASSERT_EQ(1, utPpDoneHandlerSuccessCounter);
674 }
675
676 TEST_F(TDMPPCommit, PpCommitSuccessScaleAndTransform)
677 {
678         SKIP_FLAG(has_pp);
679         tdm_error error;
680
681         ASSERT_NE(-1, UtPrepareToPPWithScale());
682
683         error = tdm_pp_commit(pp);
684         ASSERT_EQ(TDM_ERROR_NONE, error);
685
686         UtHandlePPEvent(1);
687
688         ASSERT_EQ(1, utPpDoneHandlerSuccessCounter);
689 }
690
691 TEST_F(TDMPPCommitThread, PpCommitSuccessScale)
692 {
693         SKIP_FLAG(has_pp);
694         tdm_error error;
695
696         ASSERT_NE(-1, UtPrepareToPPWithScale());
697
698         error = tdm_pp_commit(pp);
699         ASSERT_EQ(TDM_ERROR_NONE, error);
700
701         UtHandlePPEvent(1);
702
703         ASSERT_EQ(1, utPpDoneHandlerSuccessCounter);
704 }
705
706 TEST_F(TDMPPCommitThread, PpCommitSuccessScaleAndTransform)
707 {
708         SKIP_FLAG(has_pp);
709         tdm_error error;
710
711         ASSERT_NE(-1, UtPrepareToPPWithScale());
712
713         error = tdm_pp_commit(pp);
714         ASSERT_EQ(TDM_ERROR_NONE, error);
715
716         UtHandlePPEvent(1);
717
718         ASSERT_EQ(1, utPpDoneHandlerSuccessCounter);
719 }
720
721 /* tdm_pp_destroy() */
722
723 void UtBufferReleaseHandler(tbm_surface_h buffer,
724                                                            void *user_data)
725 {
726         int *data = (int *)user_data;
727         if (!data)
728                 return;
729
730         (*data)++;
731 }
732
733 TEST_F(TDMPPCommit, PPDestroySuccessAfterCommit)
734 {
735         SKIP_FLAG(has_pp);
736         tdm_error error;
737         int release_data = 0;
738
739         ASSERT_NE(-1, UtPrepareToPPWithScale());
740
741         for (auto it = buffers_list.begin(); it != buffers_list.end(); ++it) {
742                 tdm_buffer_add_release_handler((tbm_surface_h)*it, UtBufferReleaseHandler, &release_data);
743         }
744
745         error = tdm_pp_commit(pp);
746         ASSERT_EQ(TDM_ERROR_NONE, error);
747
748         tdm_pp_destroy(pp);
749         pp = NULL;
750
751         ASSERT_EQ(2, release_data);
752 }