change the utests to haltests
[platform/core/uifw/libtbm.git] / haltests / tc_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 "tc_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_F(TBMBufmgr, BufmgrGetCapability)
61 {
62         unsigned int capability;
63
64         capability = tbm_bufmgr_get_capability(bufmgr);
65         EXPECT_NE(capability, TBM_BUFMGR_CAPABILITY_NONE);
66         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
67 }
68
69 TEST_F(TBMBufmgr, BufmgrGetCapabilityWithNullBufmgr)
70 {
71         unsigned int capability;
72
73         capability = tbm_bufmgr_get_capability(NULL);
74         EXPECT_EQ(capability, TBM_BUFMGR_CAPABILITY_NONE);
75         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
76 }
77
78 TEST_F(TBMBufmgr, BufmgrGetCapabilityWithWrongBufmgr)
79 {
80         tbm_bufmgr bufmgr = (tbm_bufmgr)UT_TBM_INVALID_VALUE;
81         unsigned int capability;
82
83         capability = tbm_bufmgr_get_capability(bufmgr);
84         EXPECT_EQ(capability, TBM_BUFMGR_CAPABILITY_NONE);
85         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
86 }
87
88 /* tbm_bufmgr_bind_native_display() */
89 #if 0 // TDDO:: fix the crash...
90 TEST_F(TBMBufmgr, BufmgrBindNativeDisplay)
91 {
92         int ret;
93         void *native_display = (void *)UT_TBM_INVALID_VALUE;
94
95         ret = tbm_bufmgr_bind_native_display(bufmgr, native_display);
96         ASSERT_EQ(ret, 1);
97 }
98
99 TEST_F(TBMBufmgr, BufmgrBindNativeDisplayWithNullBufmgr)
100 {
101         int ret;
102         void *native_display = (void *)UT_TBM_INVALID_VALUE;
103
104         ret = tbm_bufmgr_bind_native_display(NULL, native_display);
105         ASSERT_EQ(ret, 0);
106 }
107
108 TEST_F(TBMBufmgr, BufmgrBindNativeDisplayWithWrongBufmgr)
109 {
110         int ret;
111         void *native_display = (void *)UT_TBM_INVALID_VALUE;
112
113         ret = tbm_bufmgr_bind_native_display(NULL, native_display);
114         ASSERT_EQ(ret, 0);
115 }
116 #endif
117
118 /* tbm_bufmgr_set_bo_lock_type() */
119 TEST_F(TBMBufmgr, BufmgrSetBoLockType)
120 {
121         int ret;
122
123         ret = tbm_bufmgr_set_bo_lock_type(bufmgr, TBM_BUFMGR_BO_LOCK_TYPE_NEVER);
124         EXPECT_EQ(ret, 1);
125         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
126         ret = tbm_bufmgr_set_bo_lock_type(bufmgr, TBM_BUFMGR_BO_LOCK_TYPE_ONCE);
127         EXPECT_EQ(ret, 1);
128         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
129         ret = tbm_bufmgr_set_bo_lock_type(bufmgr, TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS);
130         EXPECT_EQ(ret, 1);
131         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
132 }
133
134 TEST_F(TBMBufmgr, BufmgrSetBoLockTypeWithBufmgrParamTest)
135 {
136         tbm_bufmgr invalid_bufmgr;
137         int ret;
138
139         ret = tbm_bufmgr_set_bo_lock_type(NULL, TBM_BUFMGR_BO_LOCK_TYPE_NEVER);
140         EXPECT_EQ(ret, 0);
141         invalid_bufmgr = (tbm_bufmgr)UT_TBM_INVALID_VALUE;
142         ret = tbm_bufmgr_set_bo_lock_type(invalid_bufmgr, TBM_BUFMGR_BO_LOCK_TYPE_NEVER);
143         EXPECT_EQ(ret, 0);
144         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
145 }
146
147 // TODO::::
148 /* tbm_bufmgr_debug_show() */
149 /* tbm_bufmgr_debug_tbm_info_get() */
150 /* tbm_bufmgr_debug_trace() */
151 /* tbm_bufmgr_debug_dump_all() */
152 /* tbm_bufmgr_debug_queue_dump() */
153 /* tbm_bufmgr_debug_dump_set_scale() */
154 /* tbm_bufmgr_debug_get_ref_count */
155
156 INSTANTIATE_TEST_CASE_P(TBMBufmgrParams,
157                                                 TBMBufmgr,
158                                                 Combine(Bool(), Bool(), Values("none")));
159