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 class TBMSurfaceInternal : public TBMBufmgr
41 tbm_format argb8888_format;
43 tbm_surface_h surface;
46 void TBMSurfaceInternal::SetUp()
52 ret = tbm_surface_internal_query_supported_formats(&formats, &num_formats);
53 ASSERT_TRUE(ret == 1);
55 for (uint32_t i = 0; i < num_formats; i++)
56 if (formats[i] == TBM_FORMAT_ARGB8888)
57 argb8888_format = TBM_FORMAT_ARGB8888;
59 /* fail if there is no TBM_FORMAT_ARGB8888 format */
60 ASSERT_TRUE(argb8888_format == TBM_FORMAT_ARGB8888);
62 surface = tbm_surface_internal_create_with_flags(720, 1024, argb8888_format, TBM_BO_DEFAULT);
63 ASSERT_TRUE(surface != NULL);
66 void TBMSurfaceInternal::TearDown()
69 tbm_surface_internal_destroy(surface);
74 TBMBufmgr::TearDown();
77 /* tbm_surface_h tbm_surface_internal_create_with_flags(int width, int height, int format, int flags) */
78 TEST_F(TBMSurfaceInternal, SurfaceInternalCeateDestroyTest)
80 tbm_surface_h surface1 = NULL;
82 for (uint32_t i = 0; i < 1; i++) {
83 surface1 = tbm_surface_internal_create_with_flags(720, 1024, formats[i], TBM_BO_DEFAULT);
84 EXPECT_NE(surface1, nullptr);
85 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
86 tbm_surface_internal_destroy(surface1);
87 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
91 TEST_F(TBMSurfaceInternal, SurfaceInternalCeatewithParamsTest)
93 tbm_surface_h surface1 = NULL;
95 surface1 = tbm_surface_internal_create_with_flags(-1, 1024, TBM_FORMAT_ARGB8888, TBM_BO_DEFAULT);
96 EXPECT_EQ(nullptr, surface1); // Expected Value: NULL
97 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
98 surface1 = tbm_surface_internal_create_with_flags(720, -1, TBM_FORMAT_ARGB8888, TBM_BO_DEFAULT);
99 EXPECT_EQ(nullptr, surface1);
100 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
101 surface1 = tbm_surface_internal_create_with_flags(720, 1024, 0, TBM_BO_DEFAULT);
102 EXPECT_EQ(nullptr, surface1);
103 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
104 surface1 = tbm_surface_internal_create_with_flags(720, 1024, 0, (TBM_BO_WC << 1));
105 EXPECT_EQ(nullptr, surface1);
106 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
109 /* void tbm_surface_internal_destroy(tbm_surface_h surface) */
110 TEST_F(TBMSurfaceInternal, SurfaceInternalSurfaceInteranlDestroyWithParamsTest)
112 tbm_surface_internal_destroy(NULL);
113 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
116 TEST_F(TBMSurfaceInternal, SurfaceInteranlDestroyTwiceTest)
118 tbm_surface_h surface1 = NULL;
120 surface1 = tbm_surface_internal_create_with_flags(720, 1024, TBM_FORMAT_ARGB8888, TBM_BO_DEFAULT);
121 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
122 tbm_surface_internal_destroy(surface1);
123 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
124 tbm_surface_internal_destroy(surface1);
125 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
128 /* tbm_surface_internal_is_valid(tbm_surface_h surface) */
129 TEST_F(TBMSurfaceInternal, SurfaceInteranlIsValid)
131 tbm_surface_h invalid_surface;
133 EXPECT_TRUE(tbm_surface_internal_is_valid(surface));
134 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
136 EXPECT_FALSE(tbm_surface_internal_is_valid(NULL));
137 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
139 invalid_surface = (tbm_surface_h)UT_TBM_INVALID_VALUE;
140 EXPECT_FALSE(tbm_surface_internal_is_valid((tbm_surface_h)&invalid_surface));
141 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
144 /* int tbm_surface_internal_get_num_bos(tbm_surface_h surface) */
145 TEST_F(TBMSurfaceInternal, GetNumBosFailNULL)
147 int num = tbm_surface_internal_get_num_bos(NULL);
149 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
152 TEST_F(TBMSurfaceInternal, GetNumBosSuccess)
154 int num = tbm_surface_internal_get_num_bos(surface);
156 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
159 /* tbm_bo tbm_surface_internal_get_bo(tbm_surface_h surface, int bo_idx) */
160 TEST_F(TBMSurfaceInternal, GetBoFailNULL)
162 tbm_bo bo = tbm_surface_internal_get_bo(NULL, 0);
163 EXPECT_EQ(nullptr, bo);
164 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
167 TEST_F(TBMSurfaceInternal, GetBoFailInvalideInput)
169 tbm_surface_h invalide_surface = (tbm_surface_h)1;
172 /* invalid surface */
173 bo = tbm_surface_internal_get_bo(invalide_surface, 0);
174 EXPECT_EQ(nullptr, bo);
175 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
177 /* invalid index of bo */
178 bo = tbm_surface_internal_get_bo(surface, -1);
179 EXPECT_EQ(nullptr, bo);
180 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
183 TEST_F(TBMSurfaceInternal, GetBoSuccess)
188 num = tbm_surface_internal_get_num_bos(surface);
190 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
192 for (int i = 0; i < num; i++) {
193 bo = tbm_surface_internal_get_bo(surface, i);
194 EXPECT_NE(nullptr, bo);
195 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
199 /* tbm_surface_h tbm_surface_internal_create_with_bos(tbm_surface_info_s *info, tbm_bo *bos, int num) */
200 TEST_F(TBMSurfaceInternal, CreateWithBosNullInput)
202 tbm_surface_h surf = NULL;
203 tbm_surface_info_s info = { 0 };
204 tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE;
207 result = (tbm_surface_error_e)tbm_surface_get_info(surface, &info);
208 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_ERROR_NONE));
210 surf = tbm_surface_internal_create_with_bos(NULL, NULL, 1);
211 EXPECT_EQ(nullptr, surf);
212 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
214 surf = tbm_surface_internal_create_with_bos(&info, NULL, 1);
215 EXPECT_EQ(nullptr, surf);
216 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
218 surf = tbm_surface_internal_create_with_bos(NULL, bos, 1);
219 EXPECT_EQ(nullptr, surf);
220 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
223 TEST_F(TBMSurfaceInternal, CreateWithBosFailInvalidInput)
225 tbm_surface_h surf = NULL;
226 tbm_surface_info_s info;
227 tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE;
228 tbm_bo bos[4] = { NULL };
231 result = (tbm_surface_error_e)tbm_surface_get_info(surface, &info);
232 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_ERROR_NONE));
234 num = tbm_surface_internal_get_num_bos(surface);
237 for (int i = 0; i < num; i++) {
238 bos[i] = tbm_surface_internal_get_bo(surface, i);
239 EXPECT_NE(nullptr, bos[i]);
240 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
243 /* wrong number of bo */
244 surf = tbm_surface_internal_create_with_bos(&info, bos, num + 1);
245 EXPECT_EQ(nullptr, surf);
246 EXPECT_STRNE(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
247 surf = tbm_surface_internal_create_with_bos(&info, bos, num - 1);
248 EXPECT_EQ(nullptr, surf);
249 EXPECT_STRNE(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
253 surf = tbm_surface_internal_create_with_bos(&info, bos, num);
254 EXPECT_EQ(nullptr, surf);
255 EXPECT_STRNE(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
258 TEST_F(TBMSurfaceInternal, CreateWithBosSuccess)
260 tbm_surface_h surf = NULL;
261 tbm_surface_info_s info;
262 tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE;
263 tbm_bo bos[4] = { NULL };
266 result = (tbm_surface_error_e)tbm_surface_get_info(surface, &info);
267 EXPECT_EQ(TBM_SURFACE_ERROR_NONE, result);
268 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_ERROR_NONE));
270 num = tbm_surface_internal_get_num_bos(surface);
272 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
274 for (int i = 0; i < num; i++) {
275 bos[i] = tbm_surface_internal_get_bo(surface, i);
276 EXPECT_NE(nullptr, bos[i]);
277 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
280 surf = tbm_surface_internal_create_with_bos(&info, bos, num);
281 EXPECT_NE(nullptr, surf);
282 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
283 tbm_surface_internal_destroy(surf);
284 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
286 /* set size plane to zero*/
287 info.planes[0].size = 0;
288 surf = tbm_surface_internal_create_with_bos(&info, bos, num);
289 EXPECT_NE(nullptr, surf);
290 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
291 tbm_surface_internal_destroy(surf);
292 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
296 surf = tbm_surface_internal_create_with_bos(&info, bos, num);
297 EXPECT_NE(nullptr, surf);
298 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
299 tbm_surface_internal_destroy(surf);
300 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
302 /* set size to zero*/
304 surf = tbm_surface_internal_create_with_bos(&info, bos, num);
305 EXPECT_NE(nullptr, surf);
306 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
307 tbm_surface_internal_destroy(surf);
308 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
311 /* void tbm_surface_internal_unref(tbm_surface_h surface) */
312 TEST_F(TBMSurfaceInternal, UnrefFailNull)
314 tbm_surface_internal_unref(NULL);
315 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
318 TEST_F(TBMSurfaceInternal, UnrefFailInvaildInput)
321 tbm_surface_internal_unref((tbm_surface_h)&surf);
322 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
325 TEST_F(TBMSurfaceInternal, UnrefSuccess)
327 tbm_surface_internal_unref(surface);
328 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
330 EXPECT_FALSE(tbm_surface_internal_is_valid(surface)) ;
335 /* void tbm_surface_internal_ref(tbm_surface_h surface) */
336 TEST_F(TBMSurfaceInternal, RefFailNull)
338 tbm_surface_internal_ref(NULL);
339 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
342 TEST_F(TBMSurfaceInternal, RefFailInvaildInput)
345 tbm_surface_internal_ref((tbm_surface_h)&surf);
346 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
349 TEST_F(TBMSurfaceInternal, RefSuccess)
351 tbm_surface_internal_ref(surface);
352 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
353 tbm_surface_internal_unref(surface);
354 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
355 EXPECT_TRUE(tbm_surface_internal_is_valid(surface));
358 /* tbm_surface_internal_get_num_planes() */
359 TEST_F(TBMSurfaceInternal, GetNumPlanes)
362 num = tbm_surface_internal_get_num_planes(0);
364 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
366 num = tbm_surface_internal_get_num_planes(TBM_FORMAT_ARGB8888);
368 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
370 num = tbm_surface_internal_get_num_planes(TBM_FORMAT_NV12);
372 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
374 num = tbm_surface_internal_get_num_planes(TBM_FORMAT_YUV410);
376 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
379 /* tbm_surface_internal_get_size() */
380 TEST_F(TBMSurfaceInternal, GetSizeFailNull)
382 int size = tbm_surface_internal_get_size(NULL);
384 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
387 TEST_F(TBMSurfaceInternal, GetSizeFailInvaildInput)
390 int size = tbm_surface_internal_get_size((tbm_surface_h)&surf);
392 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
395 TEST_F(TBMSurfaceInternal, GetSizeSuccess)
397 int size = tbm_surface_internal_get_size(surface);
399 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
402 /* tbm_surface_internal_get_plane_data(tbm_surface_h surface, int plane_idx, uint32_t *size, uint32_t *offset, uint32_t *pitch) */
403 TEST_F(TBMSurfaceInternal, GetPlaneDataFailNull)
405 EXPECT_FALSE(tbm_surface_internal_get_plane_data(NULL, 0, NULL, NULL, NULL));
406 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
409 TEST_F(TBMSurfaceInternal, GetPlaneDataFailInvaildInput)
413 EXPECT_FALSE(tbm_surface_internal_get_plane_data((tbm_surface_h)&surf, 0, NULL, NULL, NULL));
414 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
415 EXPECT_FALSE(tbm_surface_internal_get_plane_data(surface, -1, NULL, NULL, NULL));
416 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
417 EXPECT_FALSE(tbm_surface_internal_get_plane_data(surface, 3, NULL, NULL, NULL));
418 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
421 TEST_F(TBMSurfaceInternal, GetPlaneDataSuccess)
423 uint32_t size = 0, offset = 0, pitch = 0;
425 EXPECT_TRUE(tbm_surface_internal_get_plane_data(surface, 0, &size, NULL, NULL));
427 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
429 EXPECT_TRUE(tbm_surface_internal_get_plane_data(surface, 0, NULL, &offset, NULL));
430 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
432 EXPECT_TRUE(tbm_surface_internal_get_plane_data(surface, 0, NULL, NULL, &pitch));
434 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
437 /* tbm_surface_internal_get_bpp(tbm_format format) */
438 TEST_F(TBMSurfaceInternal, GetBpp)
441 bpp = tbm_surface_internal_get_bpp(0);
443 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
445 bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_RGB332);
447 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
449 bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_RGB565);
451 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
453 bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_RGB888);
455 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
457 bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_ARGB8888);
459 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
461 bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_NV12);
463 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
465 bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_NV16);
467 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
469 bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_YUV410);
471 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
473 bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_YUV411);
475 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
477 bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_YUV422);
479 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
481 bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_YUV444);
483 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
485 /* tbm_surface_internal_get_plane_bo_idx(tbm_surface_h surface, int plane_idx) */
486 TEST_F(TBMSurfaceInternal, GetPlaneBoIndexFailNull)
488 int idx = tbm_surface_internal_get_plane_bo_idx(NULL, 0);
490 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
493 TEST_F(TBMSurfaceInternal, GetPlaneBoIndexFailInvaildInput)
498 idx = tbm_surface_internal_get_plane_bo_idx((tbm_surface_h)&surf, 0);
500 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
502 idx = tbm_surface_internal_get_plane_bo_idx(surface, -1);
504 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
507 TEST_F(TBMSurfaceInternal, GetPlaneBoIndexSuccess)
511 idx = tbm_surface_internal_get_plane_bo_idx(surface, 0);
513 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
516 static int tbm_data_free_is_called = 0;
517 void data_free_handle(void *user_data)
519 ASSERT_TRUE(user_data == &tbm_data_free_is_called);
520 int *is_called = (int *)user_data;
524 /* tbm_surface_internal_add_user_data(tbm_surface_h surface, unsigned long key, tbm_data_free data_free_func) */
525 TEST_F(TBMSurfaceInternal, AddUserDataFailNull)
527 static const unsigned long key_ud = 0;
528 EXPECT_EQ(tbm_surface_internal_add_user_data(NULL, key_ud, NULL), 0);
529 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
532 TEST_F(TBMSurfaceInternal, AddUserDataFailInvaildInput)
534 static const unsigned long key_ud = 0;
536 EXPECT_EQ(tbm_surface_internal_add_user_data((tbm_surface_h)&invalid_surf, key_ud, NULL), 0);
537 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
540 TEST_F(TBMSurfaceInternal, AddUserDataSuccess)
542 unsigned long key_ud = 157;
543 EXPECT_EQ(tbm_surface_internal_add_user_data(surface, key_ud, NULL), 1);
544 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
547 TEST_F(TBMSurfaceInternal, AddUserDataFailDoubleKey)
549 unsigned long key_ud = 5487;
550 EXPECT_EQ(tbm_surface_internal_add_user_data(surface, key_ud, NULL), 1);
551 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
553 EXPECT_EQ(tbm_surface_internal_add_user_data(surface, key_ud, NULL), 0);
554 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
557 /* tbm_surface_internal_set_user_data(tbm_surface_h surface, unsigned long key, void *data) */
558 TEST_F(TBMSurfaceInternal, SetUserDataFailNull)
560 static const unsigned long key_ud = 0;
561 EXPECT_EQ(tbm_surface_internal_set_user_data(NULL, key_ud, &tbm_data_free_is_called), 0);
562 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
565 TEST_F(TBMSurfaceInternal, SetUserDataFailInvaildInput)
567 static const unsigned long key_ud = 0;
570 EXPECT_EQ(tbm_surface_internal_set_user_data(surface,
571 key_ud, &tbm_data_free_is_called), 0) << "invalid key";
572 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
574 EXPECT_EQ(tbm_surface_internal_set_user_data((tbm_surface_h)&surf,
575 key_ud, &tbm_data_free_is_called), 0) << "invalid surface";
576 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
579 TEST_F(TBMSurfaceInternal, SetUserDataSuccess)
581 unsigned long key_ud = 87947;
582 EXPECT_EQ(tbm_surface_internal_add_user_data(surface, key_ud, data_free_handle), 1);
583 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
586 EXPECT_EQ(tbm_surface_internal_set_user_data(surface, key_ud, &tbm_data_free_is_called), 1);
587 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
589 /*the second call: previous data has to be released*/
590 tbm_data_free_is_called = 0;
591 EXPECT_EQ(tbm_surface_internal_set_user_data(surface, key_ud, NULL), 1);
592 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
593 EXPECT_EQ(tbm_data_free_is_called, 1);
595 /*the third call: previous data(NULL) hasn't to be released*/
596 tbm_data_free_is_called = 0;
597 EXPECT_EQ(tbm_surface_internal_set_user_data(surface, key_ud, NULL), 1);
598 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
599 EXPECT_EQ(tbm_data_free_is_called, 0);
602 /* tbm_surface_internal_get_user_data(tbm_surface_h surface, unsigned long key, void **data) */
603 TEST_F(TBMSurfaceInternal, GetUserDataFailNull)
605 static const unsigned long key_ud = 0;
607 EXPECT_EQ(tbm_surface_internal_get_user_data(NULL, key_ud, (void **)&data), 0);
608 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
610 EXPECT_EQ(tbm_surface_internal_get_user_data(surface, key_ud, NULL), 0);
611 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
614 TEST_F(TBMSurfaceInternal, GetUserDataFailInvaildInput)
616 static const unsigned long key_ud = 0;
620 EXPECT_EQ(tbm_surface_internal_get_user_data(surface,
621 key_ud, (void **)&data), 0) << "invalid key" << std::endl;
622 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
624 EXPECT_EQ(tbm_surface_internal_get_user_data((tbm_surface_h)&surf,
625 key_ud, (void **)&data), 0) << "invalid surface" << std::endl;
626 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
629 TEST_F(TBMSurfaceInternal, GetUserDataSuccess)
631 unsigned long key_ud = 97456789;
634 EXPECT_EQ(tbm_surface_internal_add_user_data(surface, key_ud, data_free_handle), 1);
635 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
636 EXPECT_EQ(tbm_surface_internal_set_user_data(surface, key_ud, &tbm_data_free_is_called), 1);
637 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
640 EXPECT_EQ(tbm_surface_internal_get_user_data(surface, key_ud, (void **)&data), 1);
641 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
642 EXPECT_EQ(data == &tbm_data_free_is_called, 1);
644 /* check if data is NULL */
645 EXPECT_EQ(tbm_surface_internal_set_user_data(surface, key_ud, NULL), 1);
646 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
647 EXPECT_EQ(tbm_surface_internal_get_user_data(surface, key_ud, (void **)&data), 1);
648 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
649 EXPECT_EQ(data == NULL, 1);
652 /* tbm_surface_internal_delete_user_data(tbm_surface_h surface, unsigned long key) */
653 TEST_F(TBMSurfaceInternal, DeleteUserDataFailNull)
655 static const int key_ud = 0;
656 EXPECT_EQ(tbm_surface_internal_delete_user_data(NULL, key_ud), 0);
657 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
660 TEST_F(TBMSurfaceInternal, DeleteUserDataFailInvaildInput)
662 static const int key_ud = 0;
664 EXPECT_EQ(tbm_surface_internal_delete_user_data(surface, key_ud), 0) << "invalid key";
665 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
667 EXPECT_EQ(tbm_surface_internal_delete_user_data((tbm_surface_h)&surf, key_ud), 0) << "invalid surface";
668 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
671 TEST_F(TBMSurfaceInternal, DeleteUserDataSuccess)
673 unsigned long key_ud = UINT_MAX;
675 EXPECT_EQ(tbm_surface_internal_add_user_data(surface, key_ud, data_free_handle), 1);
676 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
677 EXPECT_EQ(tbm_surface_internal_set_user_data(surface, key_ud, &tbm_data_free_is_called), 1);
678 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
680 tbm_data_free_is_called = 0;
681 EXPECT_EQ(tbm_surface_internal_delete_user_data(surface, key_ud), 1);
682 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
683 EXPECT_EQ(tbm_data_free_is_called, 1);
684 EXPECT_EQ(tbm_surface_internal_set_user_data(surface, key_ud, &tbm_data_free_is_called), 0);
685 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));