1c92d24e3e9a4dd977839c20ec328a282a5a08d8
[platform/core/uifw/libtbm.git] / utests / ut_tbm_bufmgr.cpp
1 /**************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
4  *
5  * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
6  * Contact: Andrii Sokolenko <a.sokolenko@samsung.com>
7  * Contact: Roman Marchenko <r.marchenko@samsung.com>
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sub license, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice (including the
18  * next paragraph) shall be included in all copies or substantial portions
19  * of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
24  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
25  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28  *
29 **************************************************************************/
30
31 #include "ut_tbm.h"
32
33 /* TODO::
34  * 1. Test When there is no bufmgr.
35  *
36  */
37 TBMBufmgr::TBMBufmgr()
38 {
39         bufmgr = NULL;
40 }
41
42 void TBMBufmgr::SetUp()
43 {
44         TBMEnv::SetUp();
45
46         bufmgr = tbm_bufmgr_init(-1);
47         ASSERT_TRUE(bufmgr != NULL);
48 }
49
50 void TBMBufmgr::TearDown()
51 {
52         tbm_bufmgr_deinit(bufmgr);
53
54         ASSERT_TRUE(tbm_bufmgr_debug_get_ref_count() == 0);
55
56         TBMEnv::TearDown();
57 }
58
59 /* tbm_bufmgr_get_capability() */
60 TEST_P(TBMBufmgr, BufmgrGetCapability)
61 {
62         unsigned int capability;
63
64         capability = tbm_bufmgr_get_capability(bufmgr);
65         EXPECT_NE(capability, TBM_BUFMGR_CAPABILITY_NONE);
66 }
67
68 TEST_P(TBMBufmgr, BufmgrGetCapabilityWithNullBufmgr)
69 {
70         unsigned int capability;
71
72         capability = tbm_bufmgr_get_capability(NULL);
73         EXPECT_EQ(capability, TBM_BUFMGR_CAPABILITY_NONE);
74 }
75
76 TEST_P(TBMBufmgr, BufmgrGetCapabilityWithWrongBufmgr)
77 {
78         tbm_bufmgr bufmgr = (tbm_bufmgr)UT_TBM_INVALID_VALUE;
79         unsigned int capability;
80
81         capability = tbm_bufmgr_get_capability(bufmgr);
82         EXPECT_EQ(capability, TBM_BUFMGR_CAPABILITY_NONE);
83 }
84
85 /* tbm_bufmgr_bind_native_display() */
86 #if 0 // TDDO:: fix the crash...
87 TEST_P(TBMBufmgr, BufmgrBindNativeDisplay)
88 {
89         int ret;
90         void *native_display = (void *)UT_TBM_INVALID_VALUE;
91
92         ret = tbm_bufmgr_bind_native_display(bufmgr, native_display);
93         ASSERT_EQ(ret, 1);
94 }
95
96 TEST_P(TBMBufmgr, BufmgrBindNativeDisplayWithNullBufmgr)
97 {
98         int ret;
99         void *native_display = (void *)UT_TBM_INVALID_VALUE;
100
101         ret = tbm_bufmgr_bind_native_display(NULL, native_display);
102         ASSERT_EQ(ret, 0);
103 }
104
105 TEST_P(TBMBufmgr, BufmgrBindNativeDisplayWithWrongBufmgr)
106 {
107         int ret;
108         void *native_display = (void *)UT_TBM_INVALID_VALUE;
109
110         ret = tbm_bufmgr_bind_native_display(NULL, native_display);
111         ASSERT_EQ(ret, 0);
112 }
113 #endif
114
115 /* tbm_bufmgr_set_bo_lock_type() */
116 TEST_P(TBMBufmgr, BufmgrSetBoLockType)
117 {
118         int ret;
119
120         ret = tbm_bufmgr_set_bo_lock_type(bufmgr, TBM_BUFMGR_BO_LOCK_TYPE_NEVER);
121         ASSERT_TRUE(ret == 1);
122         ret = tbm_bufmgr_set_bo_lock_type(bufmgr, TBM_BUFMGR_BO_LOCK_TYPE_ONCE);
123         ASSERT_TRUE(ret == 1);
124         ret = tbm_bufmgr_set_bo_lock_type(bufmgr, TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS);
125         ASSERT_TRUE(ret == 1);
126 }
127
128 TEST_P(TBMBufmgr, BufmgrSetBoLockTypeWithBufmgrParamTest)
129 {
130         tbm_bufmgr invalid_bufmgr;
131         int ret;
132
133         ret = tbm_bufmgr_set_bo_lock_type(NULL, TBM_BUFMGR_BO_LOCK_TYPE_NEVER);
134         ASSERT_TRUE(ret == 0);
135         invalid_bufmgr = (tbm_bufmgr)UT_TBM_INVALID_VALUE;
136         ret = tbm_bufmgr_set_bo_lock_type(invalid_bufmgr, TBM_BUFMGR_BO_LOCK_TYPE_NEVER);
137         ASSERT_TRUE(ret == 0);
138 }
139
140 // TODO::::
141 /* tbm_bufmgr_debug_show() */
142 /* tbm_bufmgr_debug_tbm_info_get() */
143 /* tbm_bufmgr_debug_trace() */
144 /* tbm_bufmgr_debug_dump_all() */
145 /* tbm_bufmgr_debug_queue_dump() */
146 /* tbm_bufmgr_debug_dump_set_scale() */
147 /* tbm_bufmgr_debug_get_ref_count */
148
149 INSTANTIATE_TEST_CASE_P(TBMBufmgrParams,
150                                                 TBMBufmgr,
151                                                 Combine(Bool(), Bool(), Values("none")));
152