1 /**************************************************************************
3 * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
5 * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
6 * Contact: Andrii Sokolenko <a.sokolenko@samsung.com>
7 * Contact: Roman Marchenko <r.marchenko@samsung.com>
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:
17 * The above copyright notice and this permission notice (including the
18 * next paragraph) shall be included in all copies or substantial portions
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.
29 **************************************************************************/
33 /* The tbm_surface.h contains the public APIs. Therefore, the error values has TBM_SURFACE_ prefix,
34 * but the values of the TBM_SURFACE_ prefix error types has the same vaules as TBM_ERROR_ prefix types.
35 * We check the two error types in this TBMSurface testcase.
38 class TBMSurface : public TBMBufmgr
49 tbm_surface_h surface;
52 void TBMSurface::SetUp()
54 tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE;
58 result = (tbm_surface_error_e)tbm_surface_query_formats(&formats, &num_formats);
59 ASSERT_STREQ(tbm_error_str(result), tbm_error_str(TBM_SURFACE_ERROR_NONE));
60 ASSERT_STREQ(tbm_error_str(result), tbm_error_str(TBM_ERROR_NONE));
62 for (uint32_t i = 0; i < num_formats; i++)
63 if (formats[i] == TBM_FORMAT_ARGB8888)
64 format = TBM_FORMAT_ARGB8888;
66 /* fail if there is no TBM_FORMAT_ARGB8888 format */
67 ASSERT_TRUE(format == TBM_FORMAT_ARGB8888);
71 surface = tbm_surface_internal_create_with_flags(width, height, format, TBM_BO_DEFAULT);
72 ASSERT_TRUE(surface != NULL);
73 ASSERT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_SURFACE_ERROR_NONE));
74 ASSERT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
77 void TBMSurface::TearDown()
80 tbm_surface_internal_destroy(surface);
81 ASSERT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_SURFACE_ERROR_NONE));
82 ASSERT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
87 TBMBufmgr::TearDown();
90 TEST_F(TBMSurface, SurfaceCeateFailInvalidGeometry)
92 tbm_surface_h surf1 = NULL;
94 surf1 = tbm_surface_create(-1, 1024, TBM_FORMAT_ARGB8888);
95 EXPECT_EQ(nullptr, surf1); // Expected Value: NULL
96 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_SURFACE_ERROR_INVALID_PARAMETER));
97 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
99 surf1 = tbm_surface_create(720, -1, TBM_FORMAT_ARGB8888);
100 EXPECT_EQ(nullptr, surf1);
101 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_SURFACE_ERROR_INVALID_PARAMETER));
102 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
104 surf1 = tbm_surface_create(720, 1024, 0);
105 EXPECT_EQ(nullptr, surf1);
106 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_SURFACE_ERROR_INVALID_PARAMETER));
107 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
110 TEST_F(TBMSurface, SurfaceCeateSuccess)
112 tbm_surface_h surf1 = NULL;
113 tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE;
115 for (uint32_t i = 0; i < num_formats; i++) {
116 surf1 = tbm_surface_create(720, 1024, formats[i]);
117 EXPECT_NE((tbm_surface_h)NULL, surf1);
118 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_SURFACE_ERROR_NONE));
119 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
120 result = (tbm_surface_error_e)tbm_surface_destroy(surf1);
121 EXPECT_EQ(TBM_SURFACE_ERROR_NONE, result);
122 EXPECT_EQ(TBM_ERROR_NONE, result);
126 TEST_F(TBMSurface, SurfaceGetFormatFailInvalidInput)
128 tbm_surface_h invalid_surface = (tbm_surface_h)1;
129 tbm_format fmt = tbm_surface_get_format(invalid_surface);
131 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_SURFACE_ERROR_INVALID_PARAMETER));
132 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
135 TEST_F(TBMSurface, SurfaceGetFormatFailNull)
137 tbm_format fmt = tbm_surface_get_format(NULL);
139 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_SURFACE_ERROR_INVALID_PARAMETER));
140 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
143 TEST_F(TBMSurface, SurfaceGetFormatSuccess)
145 tbm_format fmt = tbm_surface_get_format(surface);
146 EXPECT_EQ(this->format, fmt);
147 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_SURFACE_ERROR_NONE));
148 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
151 TEST_F(TBMSurface, SurfaceGetWidthFailInvalidInput)
153 tbm_surface_h invalid_surface = (tbm_surface_h)1;
154 int width = tbm_surface_get_width(invalid_surface);
155 EXPECT_EQ(width, TBM_SURFACE_ERROR_INVALID_PARAMETER);
156 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_SURFACE_ERROR_INVALID_PARAMETER));
157 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
160 TEST_F(TBMSurface, SurfaceGetWidthFailNull)
162 int width = tbm_surface_get_width(NULL);
163 EXPECT_EQ(width, TBM_SURFACE_ERROR_INVALID_PARAMETER);
164 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_SURFACE_ERROR_INVALID_PARAMETER));
165 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
168 TEST_F(TBMSurface, SurfaceGetWidthSuccess)
170 int width = tbm_surface_get_width(surface);
171 EXPECT_EQ(this->width, width);
172 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_SURFACE_ERROR_NONE));
173 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
176 TEST_F(TBMSurface, SurfaceGetHeightFailInvalidInput)
178 tbm_surface_h invalid_surface = (tbm_surface_h)1;
179 int height = tbm_surface_get_height(invalid_surface);
180 EXPECT_EQ(height, TBM_SURFACE_ERROR_INVALID_PARAMETER);
181 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_SURFACE_ERROR_INVALID_PARAMETER));
182 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
185 TEST_F(TBMSurface, SurfaceGetHeightFailNull)
187 int height = tbm_surface_get_height(NULL);
188 EXPECT_EQ(height, TBM_SURFACE_ERROR_INVALID_PARAMETER);
189 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_SURFACE_ERROR_INVALID_PARAMETER));
190 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
193 TEST_F(TBMSurface, SurfaceGetHeightSuccess)
195 int height = tbm_surface_get_height(surface);
196 EXPECT_EQ(this->height, height);
197 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_SURFACE_ERROR_NONE));
198 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
201 TEST_F(TBMSurface, SurfaceGetInfoInvalidInput)
203 tbm_surface_h invalid_surface = (tbm_surface_h)1;
204 tbm_surface_info_s info;
205 tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE;
207 result = (tbm_surface_error_e)tbm_surface_get_info(invalid_surface, &info);
208 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_SURFACE_ERROR_INVALID_PARAMETER));
209 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
212 TEST_F(TBMSurface, SurfaceGetInfoFailNull)
214 tbm_surface_info_s info;
215 tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE;
217 result = (tbm_surface_error_e)tbm_surface_get_info(surface, NULL);
218 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_SURFACE_ERROR_INVALID_PARAMETER));
219 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
221 result = (tbm_surface_error_e)tbm_surface_get_info(NULL, &info);
222 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_SURFACE_ERROR_INVALID_PARAMETER));
223 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
225 result = (tbm_surface_error_e)tbm_surface_get_info(NULL, NULL);
226 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_SURFACE_ERROR_INVALID_PARAMETER));
227 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
230 TEST_F(TBMSurface, SurfaceGetInfoSuccess)
232 tbm_surface_info_s info;
233 tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE;
235 result = (tbm_surface_error_e)tbm_surface_get_info(surface, &info);
236 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_SURFACE_ERROR_NONE));
237 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_ERROR_NONE));
238 EXPECT_EQ(this->format, info.format);
239 EXPECT_EQ(this->height, info.height);
240 EXPECT_EQ(this->width, info.width);
241 EXPECT_GT(info.num_planes, 0);
242 EXPECT_GT(info.bpp, 0);
243 EXPECT_GT(info.size, 0);
246 TEST_F(TBMSurface, SurfaceMapFailInvalidInput)
248 tbm_surface_info_s info;
249 tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE;
250 tbm_surface_h invalid_surface = (tbm_surface_h)1;
252 result = (tbm_surface_error_e)tbm_surface_map(invalid_surface, 0, &info);
253 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_SURFACE_ERROR_INVALID_PARAMETER));
254 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
257 TEST_F(TBMSurface, SurfaceMapFailNull)
259 tbm_surface_info_s info;
260 tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE;
262 result = (tbm_surface_error_e)tbm_surface_map(surface, 0, NULL);
263 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_SURFACE_ERROR_INVALID_PARAMETER));
264 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
266 result = (tbm_surface_error_e)tbm_surface_map(NULL, 0, &info);
267 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_SURFACE_ERROR_INVALID_PARAMETER));
268 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
271 TEST_F(TBMSurface, SurfaceMapSuccess)
273 tbm_surface_info_s info;
274 tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE;
276 result = (tbm_surface_error_e)tbm_surface_map(surface, 0, &info);
277 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_SURFACE_ERROR_NONE));
278 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_ERROR_NONE));
279 EXPECT_EQ(this->format, info.format);
280 EXPECT_EQ(this->height, info.height);
281 EXPECT_EQ(this->width, info.width);
282 EXPECT_GT(info.num_planes, 0);
283 EXPECT_GT(info.bpp, 0);
284 EXPECT_GT(info.size, 0);
286 result = (tbm_surface_error_e)tbm_surface_unmap(surface);
287 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_SURFACE_ERROR_NONE));
288 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_ERROR_NONE));
291 TEST_F(TBMSurface, SurfaceUnmapFailInvalidInput)
293 tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE;
294 tbm_surface_h invalid_surface = (tbm_surface_h)1;
295 result = (tbm_surface_error_e)tbm_surface_unmap(invalid_surface);
296 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_SURFACE_ERROR_INVALID_PARAMETER));
297 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
300 TEST_F(TBMSurface, SurfaceUnmapFailNull)
302 tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE;
304 result = (tbm_surface_error_e)tbm_surface_unmap(NULL);
305 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_SURFACE_ERROR_INVALID_PARAMETER));
306 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));