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 static int memory_for_invalid_param;
78 static tbm_surface_h invalid_surface = (tbm_surface_h)&memory_for_invalid_param;
80 /* tbm_surface_h tbm_surface_internal_create_with_flags(int width, int height, int format, int flags) */
81 TEST_F(TBMSurfaceInternal, SurfaceInternalCeateDestroyTest)
83 tbm_surface_h surface1 = NULL;
85 for (uint32_t i = 0; i < 1; i++) {
86 surface1 = tbm_surface_internal_create_with_flags(720, 1024, formats[i], TBM_BO_DEFAULT);
87 EXPECT_NE(surface1, nullptr);
88 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
89 tbm_surface_internal_destroy(surface1);
90 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
94 TEST_F(TBMSurfaceInternal, SurfaceInternalCeatewithParamsTest)
96 tbm_surface_h surface1 = NULL;
98 surface1 = tbm_surface_internal_create_with_flags(-1, 1024, TBM_FORMAT_ARGB8888, TBM_BO_DEFAULT);
99 EXPECT_EQ(nullptr, surface1); // Expected Value: NULL
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, -1, TBM_FORMAT_ARGB8888, 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_DEFAULT);
105 EXPECT_EQ(nullptr, surface1);
106 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
107 surface1 = tbm_surface_internal_create_with_flags(720, 1024, 0, (TBM_BO_WC << 1));
108 EXPECT_EQ(nullptr, surface1);
109 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
112 /* void tbm_surface_internal_destroy(tbm_surface_h surface) */
113 TEST_F(TBMSurfaceInternal, SurfaceInternalSurfaceInteranlDestroyWithParamsTest)
115 tbm_surface_internal_destroy(NULL);
116 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
119 TEST_F(TBMSurfaceInternal, SurfaceInteranlDestroyTwiceTest)
121 tbm_surface_h surface1 = NULL;
123 surface1 = tbm_surface_internal_create_with_flags(720, 1024, TBM_FORMAT_ARGB8888, TBM_BO_DEFAULT);
124 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
125 tbm_surface_internal_destroy(surface1);
126 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
127 tbm_surface_internal_destroy(surface1);
128 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
131 /* tbm_surface_internal_is_valid(tbm_surface_h surface) */
132 TEST_F(TBMSurfaceInternal, SurfaceInteranlIsValid)
134 EXPECT_TRUE(tbm_surface_internal_is_valid(surface));
135 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
137 EXPECT_FALSE(tbm_surface_internal_is_valid(NULL));
138 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
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)
171 /* invalid surface */
172 bo = tbm_surface_internal_get_bo(invalid_surface, 0);
173 EXPECT_EQ(nullptr, bo);
174 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
176 /* invalid index of bo */
177 bo = tbm_surface_internal_get_bo(surface, -1);
178 EXPECT_EQ(nullptr, bo);
179 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
182 TEST_F(TBMSurfaceInternal, GetBoSuccess)
187 num = tbm_surface_internal_get_num_bos(surface);
189 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
191 for (int i = 0; i < num; i++) {
192 bo = tbm_surface_internal_get_bo(surface, i);
193 EXPECT_NE(nullptr, bo);
194 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
198 /* tbm_surface_h tbm_surface_internal_create_with_bos(tbm_surface_info_s *info, tbm_bo *bos, int num) */
199 TEST_F(TBMSurfaceInternal, CreateWithBosNullInput)
201 tbm_surface_h surf = NULL;
202 tbm_surface_info_s info = { 0 };
203 tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE;
206 result = (tbm_surface_error_e)tbm_surface_get_info(surface, &info);
207 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_ERROR_NONE));
209 surf = tbm_surface_internal_create_with_bos(NULL, NULL, 1);
210 EXPECT_EQ(nullptr, surf);
211 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
213 surf = tbm_surface_internal_create_with_bos(&info, NULL, 1);
214 EXPECT_EQ(nullptr, surf);
215 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
217 surf = tbm_surface_internal_create_with_bos(NULL, bos, 1);
218 EXPECT_EQ(nullptr, surf);
219 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
222 TEST_F(TBMSurfaceInternal, CreateWithBosFailInvalidInput)
224 tbm_surface_h surf = NULL;
225 tbm_surface_info_s info;
226 tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE;
227 tbm_bo bos[4] = { NULL };
230 result = (tbm_surface_error_e)tbm_surface_get_info(surface, &info);
231 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_ERROR_NONE));
233 num = tbm_surface_internal_get_num_bos(surface);
236 for (int i = 0; i < num; i++) {
237 bos[i] = tbm_surface_internal_get_bo(surface, i);
238 EXPECT_NE(nullptr, bos[i]);
239 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
242 /* wrong number of bo */
243 surf = tbm_surface_internal_create_with_bos(&info, bos, num + 1);
244 EXPECT_EQ(nullptr, surf);
245 EXPECT_STRNE(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
246 surf = tbm_surface_internal_create_with_bos(&info, bos, num - 1);
247 EXPECT_EQ(nullptr, surf);
248 EXPECT_STRNE(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
252 surf = tbm_surface_internal_create_with_bos(&info, bos, num);
253 EXPECT_EQ(nullptr, surf);
254 EXPECT_STRNE(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
257 TEST_F(TBMSurfaceInternal, CreateWithBosSuccess)
259 tbm_surface_h surf = NULL;
260 tbm_surface_info_s info;
261 tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE;
262 tbm_bo bos[4] = { NULL };
265 result = (tbm_surface_error_e)tbm_surface_get_info(surface, &info);
266 EXPECT_EQ(TBM_SURFACE_ERROR_NONE, result);
267 EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_ERROR_NONE));
269 num = tbm_surface_internal_get_num_bos(surface);
271 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
273 for (int i = 0; i < num; i++) {
274 bos[i] = tbm_surface_internal_get_bo(surface, i);
275 EXPECT_NE(nullptr, bos[i]);
276 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
279 surf = tbm_surface_internal_create_with_bos(&info, bos, num);
280 EXPECT_NE(nullptr, surf);
281 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
282 tbm_surface_internal_destroy(surf);
283 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
285 /* set size plane to zero*/
286 info.planes[0].size = 0;
287 surf = tbm_surface_internal_create_with_bos(&info, bos, num);
288 EXPECT_NE(nullptr, surf);
289 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
290 tbm_surface_internal_destroy(surf);
291 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
295 surf = tbm_surface_internal_create_with_bos(&info, bos, num);
296 EXPECT_NE(nullptr, surf);
297 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
298 tbm_surface_internal_destroy(surf);
299 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
301 /* set size to zero*/
303 surf = tbm_surface_internal_create_with_bos(&info, bos, num);
304 EXPECT_NE(nullptr, surf);
305 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
306 tbm_surface_internal_destroy(surf);
307 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
310 /* void tbm_surface_internal_unref(tbm_surface_h surface) */
311 TEST_F(TBMSurfaceInternal, UnrefFailNull)
313 tbm_surface_internal_unref(NULL);
314 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
317 TEST_F(TBMSurfaceInternal, UnrefFailInvaildInput)
320 tbm_surface_internal_unref((tbm_surface_h)&surf);
321 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
324 TEST_F(TBMSurfaceInternal, UnrefSuccess)
326 tbm_surface_internal_unref(surface);
327 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
329 EXPECT_FALSE(tbm_surface_internal_is_valid(surface)) ;
334 /* void tbm_surface_internal_ref(tbm_surface_h surface) */
335 TEST_F(TBMSurfaceInternal, RefFailNull)
337 tbm_surface_internal_ref(NULL);
338 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
341 TEST_F(TBMSurfaceInternal, RefFailInvaildInput)
344 tbm_surface_internal_ref((tbm_surface_h)&surf);
345 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
348 TEST_F(TBMSurfaceInternal, RefSuccess)
350 tbm_surface_internal_ref(surface);
351 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
352 tbm_surface_internal_unref(surface);
353 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
354 EXPECT_TRUE(tbm_surface_internal_is_valid(surface));
357 /* tbm_surface_internal_get_num_planes() */
358 TEST_F(TBMSurfaceInternal, GetNumPlanes)
361 num = tbm_surface_internal_get_num_planes(0);
363 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
365 num = tbm_surface_internal_get_num_planes(TBM_FORMAT_ARGB8888);
367 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
369 num = tbm_surface_internal_get_num_planes(TBM_FORMAT_NV12);
371 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
373 num = tbm_surface_internal_get_num_planes(TBM_FORMAT_YUV410);
375 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
378 /* tbm_surface_internal_get_size() */
379 TEST_F(TBMSurfaceInternal, GetSizeFailNull)
381 int size = tbm_surface_internal_get_size(NULL);
383 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
386 TEST_F(TBMSurfaceInternal, GetSizeFailInvaildInput)
389 int size = tbm_surface_internal_get_size((tbm_surface_h)&surf);
391 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
394 TEST_F(TBMSurfaceInternal, GetSizeSuccess)
396 int size = tbm_surface_internal_get_size(surface);
398 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
401 /* tbm_surface_internal_get_plane_data(tbm_surface_h surface, int plane_idx, uint32_t *size, uint32_t *offset, uint32_t *pitch) */
402 TEST_F(TBMSurfaceInternal, GetPlaneDataFailNull)
404 EXPECT_FALSE(tbm_surface_internal_get_plane_data(NULL, 0, NULL, NULL, NULL));
405 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
408 TEST_F(TBMSurfaceInternal, GetPlaneDataFailInvaildInput)
412 EXPECT_FALSE(tbm_surface_internal_get_plane_data((tbm_surface_h)&surf, 0, NULL, NULL, NULL));
413 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
414 EXPECT_FALSE(tbm_surface_internal_get_plane_data(surface, -1, NULL, NULL, NULL));
415 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
416 EXPECT_FALSE(tbm_surface_internal_get_plane_data(surface, 3, NULL, NULL, NULL));
417 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
420 TEST_F(TBMSurfaceInternal, GetPlaneDataSuccess)
422 uint32_t size = 0, offset = 0, pitch = 0;
424 EXPECT_TRUE(tbm_surface_internal_get_plane_data(surface, 0, &size, NULL, NULL));
426 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
428 EXPECT_TRUE(tbm_surface_internal_get_plane_data(surface, 0, NULL, &offset, NULL));
429 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
431 EXPECT_TRUE(tbm_surface_internal_get_plane_data(surface, 0, NULL, NULL, &pitch));
433 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
436 /* tbm_surface_internal_get_bpp(tbm_format format) */
437 TEST_F(TBMSurfaceInternal, GetBpp)
440 bpp = tbm_surface_internal_get_bpp(0);
442 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
444 bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_RGB332);
446 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
448 bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_RGB565);
450 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
452 bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_RGB888);
454 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
456 bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_ARGB8888);
458 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
460 bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_NV12);
462 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
464 bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_NV16);
466 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
468 bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_YUV410);
470 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
472 bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_YUV411);
474 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
476 bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_YUV422);
478 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
480 bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_YUV444);
482 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
484 /* tbm_surface_internal_get_plane_bo_idx(tbm_surface_h surface, int plane_idx) */
485 TEST_F(TBMSurfaceInternal, GetPlaneBoIndexFailNull)
487 int idx = tbm_surface_internal_get_plane_bo_idx(NULL, 0);
489 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
492 TEST_F(TBMSurfaceInternal, GetPlaneBoIndexFailInvaildInput)
497 idx = tbm_surface_internal_get_plane_bo_idx((tbm_surface_h)&surf, 0);
499 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
501 idx = tbm_surface_internal_get_plane_bo_idx(surface, -1);
503 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
506 TEST_F(TBMSurfaceInternal, GetPlaneBoIndexSuccess)
510 idx = tbm_surface_internal_get_plane_bo_idx(surface, 0);
512 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
515 static int tbm_data_free_is_called = 0;
516 void data_free_handle(void *user_data)
518 ASSERT_TRUE(user_data == &tbm_data_free_is_called);
519 int *is_called = (int *)user_data;
523 /* tbm_surface_internal_add_user_data(tbm_surface_h surface, unsigned long key, tbm_data_free data_free_func) */
524 TEST_F(TBMSurfaceInternal, AddUserDataFailNull)
526 static const unsigned long key_ud = 0;
527 EXPECT_EQ(tbm_surface_internal_add_user_data(NULL, key_ud, NULL), 0);
528 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
531 TEST_F(TBMSurfaceInternal, AddUserDataFailInvaildInput)
533 static const unsigned long key_ud = 0;
535 EXPECT_EQ(tbm_surface_internal_add_user_data((tbm_surface_h)&invalid_surf, key_ud, NULL), 0);
536 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
539 TEST_F(TBMSurfaceInternal, AddUserDataSuccess)
541 unsigned long key_ud = 157;
542 EXPECT_EQ(tbm_surface_internal_add_user_data(surface, key_ud, NULL), 1);
543 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
546 TEST_F(TBMSurfaceInternal, AddUserDataFailDoubleKey)
548 unsigned long key_ud = 5487;
549 EXPECT_EQ(tbm_surface_internal_add_user_data(surface, key_ud, NULL), 1);
550 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
552 EXPECT_EQ(tbm_surface_internal_add_user_data(surface, key_ud, NULL), 0);
553 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
556 /* tbm_surface_internal_set_user_data(tbm_surface_h surface, unsigned long key, void *data) */
557 TEST_F(TBMSurfaceInternal, SetUserDataFailNull)
559 static const unsigned long key_ud = 0;
560 EXPECT_EQ(tbm_surface_internal_set_user_data(NULL, key_ud, &tbm_data_free_is_called), 0);
561 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
564 TEST_F(TBMSurfaceInternal, SetUserDataFailInvaildInput)
566 static const unsigned long key_ud = 0;
569 EXPECT_EQ(tbm_surface_internal_set_user_data(surface,
570 key_ud, &tbm_data_free_is_called), 0) << "invalid key";
571 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
573 EXPECT_EQ(tbm_surface_internal_set_user_data((tbm_surface_h)&surf,
574 key_ud, &tbm_data_free_is_called), 0) << "invalid surface";
575 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
578 TEST_F(TBMSurfaceInternal, SetUserDataSuccess)
580 unsigned long key_ud = 87947;
581 EXPECT_EQ(tbm_surface_internal_add_user_data(surface, key_ud, data_free_handle), 1);
582 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
585 EXPECT_EQ(tbm_surface_internal_set_user_data(surface, key_ud, &tbm_data_free_is_called), 1);
586 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
588 /*the second call: previous data has to be released*/
589 tbm_data_free_is_called = 0;
590 EXPECT_EQ(tbm_surface_internal_set_user_data(surface, key_ud, NULL), 1);
591 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
592 EXPECT_EQ(tbm_data_free_is_called, 1);
594 /*the third call: previous data(NULL) hasn't to be released*/
595 tbm_data_free_is_called = 0;
596 EXPECT_EQ(tbm_surface_internal_set_user_data(surface, key_ud, NULL), 1);
597 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
598 EXPECT_EQ(tbm_data_free_is_called, 0);
601 /* tbm_surface_internal_get_user_data(tbm_surface_h surface, unsigned long key, void **data) */
602 TEST_F(TBMSurfaceInternal, GetUserDataFailNull)
604 static const unsigned long key_ud = 0;
606 EXPECT_EQ(tbm_surface_internal_get_user_data(NULL, key_ud, (void **)&data), 0);
607 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
609 EXPECT_EQ(tbm_surface_internal_get_user_data(surface, key_ud, NULL), 0);
610 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
613 TEST_F(TBMSurfaceInternal, GetUserDataFailInvaildInput)
615 static const unsigned long key_ud = 0;
619 EXPECT_EQ(tbm_surface_internal_get_user_data(surface,
620 key_ud, (void **)&data), 0) << "invalid key" << std::endl;
621 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
623 EXPECT_EQ(tbm_surface_internal_get_user_data((tbm_surface_h)&surf,
624 key_ud, (void **)&data), 0) << "invalid surface" << std::endl;
625 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
628 TEST_F(TBMSurfaceInternal, GetUserDataSuccess)
630 unsigned long key_ud = 97456789;
633 EXPECT_EQ(tbm_surface_internal_add_user_data(surface, key_ud, data_free_handle), 1);
634 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
635 EXPECT_EQ(tbm_surface_internal_set_user_data(surface, key_ud, &tbm_data_free_is_called), 1);
636 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
639 EXPECT_EQ(tbm_surface_internal_get_user_data(surface, key_ud, (void **)&data), 1);
640 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
641 EXPECT_EQ(data == &tbm_data_free_is_called, 1);
643 /* check if data is NULL */
644 EXPECT_EQ(tbm_surface_internal_set_user_data(surface, key_ud, NULL), 1);
645 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
646 EXPECT_EQ(tbm_surface_internal_get_user_data(surface, key_ud, (void **)&data), 1);
647 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
648 EXPECT_EQ(data == NULL, 1);
651 /* tbm_surface_internal_delete_user_data(tbm_surface_h surface, unsigned long key) */
652 TEST_F(TBMSurfaceInternal, DeleteUserDataFailNull)
654 static const int key_ud = 0;
655 EXPECT_EQ(tbm_surface_internal_delete_user_data(NULL, key_ud), 0);
656 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
659 TEST_F(TBMSurfaceInternal, DeleteUserDataFailInvaildInput)
661 static const int key_ud = 0;
663 EXPECT_EQ(tbm_surface_internal_delete_user_data(surface, key_ud), 0) << "invalid key";
664 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
666 EXPECT_EQ(tbm_surface_internal_delete_user_data((tbm_surface_h)&surf, key_ud), 0) << "invalid surface";
667 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
670 TEST_F(TBMSurfaceInternal, DeleteUserDataSuccess)
672 unsigned long key_ud = UINT_MAX;
674 EXPECT_EQ(tbm_surface_internal_add_user_data(surface, key_ud, data_free_handle), 1);
675 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
676 EXPECT_EQ(tbm_surface_internal_set_user_data(surface, key_ud, &tbm_data_free_is_called), 1);
677 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
679 tbm_data_free_is_called = 0;
680 EXPECT_EQ(tbm_surface_internal_delete_user_data(surface, key_ud), 1);
681 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
682 EXPECT_EQ(tbm_data_free_is_called, 1);
683 EXPECT_EQ(tbm_surface_internal_set_user_data(surface, key_ud, &tbm_data_free_is_called), 0);
684 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));