ceacb27de4b7ab7a09bbc4079899ea8316a4ec7d
[platform/core/uifw/libtbm.git] / haltests / tc_tbm_surface_internal.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 class TBMSurfaceInternal : public TBMBufmgr
34 {
35 protected:
36         void SetUp();
37         void TearDown();
38 public:
39         uint32_t num_formats;
40         tbm_format *formats;
41         tbm_format argb8888_format;
42
43         tbm_surface_h surface;
44 };
45
46 void TBMSurfaceInternal::SetUp()
47 {
48         int ret = 0;
49
50         TBMBufmgr::SetUp();
51
52         ret = tbm_surface_internal_query_supported_formats(&formats, &num_formats);
53         ASSERT_TRUE(ret == 1);
54
55         for (uint32_t i = 0; i < num_formats; i++)
56                 if (formats[i] == TBM_FORMAT_ARGB8888)
57                         argb8888_format = TBM_FORMAT_ARGB8888;
58
59         /* fail if there is no TBM_FORMAT_ARGB8888 format */
60         ASSERT_TRUE(argb8888_format == TBM_FORMAT_ARGB8888);
61
62         surface = tbm_surface_internal_create_with_flags(720, 1024, argb8888_format, TBM_BO_DEFAULT);
63         ASSERT_TRUE(surface != NULL);
64 }
65
66 void TBMSurfaceInternal::TearDown()
67 {
68         if (surface)
69                 tbm_surface_internal_destroy(surface);
70
71         if (formats)
72                 free(formats);
73
74         TBMBufmgr::TearDown();
75 }
76
77 static int memory_for_invalid_param;
78 static tbm_surface_h invalid_surface = (tbm_surface_h)&memory_for_invalid_param;
79
80 /* tbm_surface_h tbm_surface_internal_create_with_flags(int width, int height, int format, int flags) */
81 TEST_F(TBMSurfaceInternal, SurfaceInternalCeateDestroyTest)
82 {
83         tbm_surface_h surface1 = NULL;
84
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));
91         }
92 }
93
94 TEST_F(TBMSurfaceInternal, SurfaceInternalCeatewithParamsTest)
95 {
96         tbm_surface_h surface1 = NULL;
97
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));
110 }
111
112 /* void tbm_surface_internal_destroy(tbm_surface_h surface) */
113 TEST_F(TBMSurfaceInternal, SurfaceInternalSurfaceInteranlDestroyWithParamsTest)
114 {
115         tbm_surface_internal_destroy(NULL);
116         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
117 }
118
119 TEST_F(TBMSurfaceInternal, SurfaceInteranlDestroyTwiceTest)
120 {
121         tbm_surface_h surface1 = NULL;
122
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));
129 }
130
131 /* tbm_surface_internal_is_valid(tbm_surface_h surface) */
132 TEST_F(TBMSurfaceInternal, SurfaceInteranlIsValid)
133 {
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));
136
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));
139
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));
142 }
143
144 /* int tbm_surface_internal_get_num_bos(tbm_surface_h surface) */
145 TEST_F(TBMSurfaceInternal, GetNumBosFailNULL)
146 {
147         int num = tbm_surface_internal_get_num_bos(NULL);
148         EXPECT_EQ(0, num);
149         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
150 }
151
152 TEST_F(TBMSurfaceInternal, GetNumBosSuccess)
153 {
154         int num = tbm_surface_internal_get_num_bos(surface);
155         EXPECT_GT(num, 0);
156         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
157 }
158
159 /* tbm_bo tbm_surface_internal_get_bo(tbm_surface_h surface, int bo_idx) */
160 TEST_F(TBMSurfaceInternal, GetBoFailNULL)
161 {
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));
165 }
166
167 TEST_F(TBMSurfaceInternal, GetBoFailInvalideInput)
168 {
169         tbm_bo bo = NULL;
170
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));
175
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));
180 }
181
182 TEST_F(TBMSurfaceInternal, GetBoSuccess)
183 {
184         tbm_bo bo = NULL;
185         int num = 0;
186
187         num = tbm_surface_internal_get_num_bos(surface);
188         EXPECT_GT(num, 0);
189         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
190
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));
195         }
196 }
197
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)
200 {
201         tbm_surface_h surf = NULL;
202         tbm_surface_info_s info = { 0 };
203         tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE;
204         tbm_bo bos[1];
205
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));
208
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));
212
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));
216
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));
220 }
221
222 TEST_F(TBMSurfaceInternal, CreateWithBosFailInvalidInput)
223 {
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 };
228         int num;
229
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));
232
233         num = tbm_surface_internal_get_num_bos(surface);
234         EXPECT_GT(num, 0);
235
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));
240         }
241
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));
249
250         /* invalid bo */
251         bos[num-1] = NULL;
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));
255 }
256
257 TEST_F(TBMSurfaceInternal, CreateWithBosSuccess)
258 {
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 };
263         int num = 0;
264
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));
268
269         num = tbm_surface_internal_get_num_bos(surface);
270         EXPECT_GT(num , 0);
271         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
272
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));
277         }
278
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));
284
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));
292
293         /* set bpp to zero*/
294         info.bpp = 0;
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));
300
301         /* set size to zero*/
302         info.size = 0;
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));
308 }
309
310 /* void tbm_surface_internal_unref(tbm_surface_h surface) */
311 TEST_F(TBMSurfaceInternal, UnrefFailNull)
312 {
313         tbm_surface_internal_unref(NULL);
314         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
315 }
316
317 TEST_F(TBMSurfaceInternal, UnrefFailInvaildInput)
318 {
319         int surf;
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));
322 }
323
324 TEST_F(TBMSurfaceInternal, UnrefSuccess)
325 {
326         tbm_surface_internal_unref(surface);
327         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
328
329         EXPECT_FALSE(tbm_surface_internal_is_valid(surface)) ;
330
331         surface = NULL;
332 }
333
334 /* void tbm_surface_internal_ref(tbm_surface_h surface) */
335 TEST_F(TBMSurfaceInternal, RefFailNull)
336 {
337         tbm_surface_internal_ref(NULL);
338         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
339 }
340
341 TEST_F(TBMSurfaceInternal, RefFailInvaildInput)
342 {
343         int surf;
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));
346 }
347
348 TEST_F(TBMSurfaceInternal, RefSuccess)
349 {
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));
355 }
356
357 /* tbm_surface_internal_get_num_planes() */
358 TEST_F(TBMSurfaceInternal, GetNumPlanes)
359 {
360         int num = 0;
361         num = tbm_surface_internal_get_num_planes(0);
362         EXPECT_EQ(0, num);
363         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
364
365         num = tbm_surface_internal_get_num_planes(TBM_FORMAT_ARGB8888);
366         EXPECT_EQ(1, num);
367         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
368
369         num = tbm_surface_internal_get_num_planes(TBM_FORMAT_NV12);
370         EXPECT_EQ(2, num);
371         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
372
373         num = tbm_surface_internal_get_num_planes(TBM_FORMAT_YUV410);
374         EXPECT_EQ(3, num);
375         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
376 }
377
378 /* tbm_surface_internal_get_size() */
379 TEST_F(TBMSurfaceInternal, GetSizeFailNull)
380 {
381         int size = tbm_surface_internal_get_size(NULL);
382         EXPECT_EQ(0, size);
383         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
384 }
385
386 TEST_F(TBMSurfaceInternal, GetSizeFailInvaildInput)
387 {
388         int surf;
389         int size = tbm_surface_internal_get_size((tbm_surface_h)&surf);
390         EXPECT_EQ(0, size);
391         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
392 }
393
394 TEST_F(TBMSurfaceInternal, GetSizeSuccess)
395 {
396         int size = tbm_surface_internal_get_size(surface);
397         ASSERT_GT(size, 0);
398         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
399 }
400
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)
403 {
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));
406 }
407
408 TEST_F(TBMSurfaceInternal, GetPlaneDataFailInvaildInput)
409 {
410         int surf;
411
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));
418 }
419
420 TEST_F(TBMSurfaceInternal, GetPlaneDataSuccess)
421 {
422         uint32_t size = 0, offset = 0, pitch = 0;
423
424         EXPECT_TRUE(tbm_surface_internal_get_plane_data(surface, 0, &size, NULL, NULL));
425         EXPECT_GT(size, 0);
426         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
427
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));
430
431         EXPECT_TRUE(tbm_surface_internal_get_plane_data(surface, 0, NULL, NULL, &pitch));
432         EXPECT_GT(pitch, 0);
433         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
434 }
435
436 /* tbm_surface_internal_get_bpp(tbm_format format) */
437 TEST_F(TBMSurfaceInternal, GetBpp)
438 {
439         int bpp = 0;
440         bpp = tbm_surface_internal_get_bpp(0);
441         EXPECT_EQ(0, bpp);
442         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
443
444         bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_RGB332);
445         EXPECT_EQ(8, bpp);
446         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
447
448         bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_RGB565);
449         EXPECT_EQ(16, bpp);
450         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
451
452         bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_RGB888);
453         EXPECT_EQ(24, bpp);
454         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
455
456         bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_ARGB8888);
457         EXPECT_EQ(32, bpp);
458         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
459
460         bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_NV12);
461         EXPECT_EQ(12, bpp);
462         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
463
464         bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_NV16);
465         EXPECT_EQ(16, bpp);
466         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
467
468         bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_YUV410);
469         EXPECT_EQ(9, bpp);
470         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
471
472         bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_YUV411);
473         EXPECT_EQ(12, bpp);
474         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
475
476         bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_YUV422);
477         EXPECT_EQ(16, bpp);
478         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
479
480         bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_YUV444);
481         EXPECT_EQ(24, bpp);
482         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
483 }
484 /* tbm_surface_internal_get_plane_bo_idx(tbm_surface_h surface, int plane_idx) */
485 TEST_F(TBMSurfaceInternal, GetPlaneBoIndexFailNull)
486 {
487         int idx = tbm_surface_internal_get_plane_bo_idx(NULL, 0);
488         EXPECT_EQ(0, idx);
489         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
490 }
491
492 TEST_F(TBMSurfaceInternal, GetPlaneBoIndexFailInvaildInput)
493 {
494         int surf;
495         int idx;
496
497         idx = tbm_surface_internal_get_plane_bo_idx((tbm_surface_h)&surf, 0);
498         EXPECT_EQ(0, idx);
499         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
500
501         idx = tbm_surface_internal_get_plane_bo_idx(surface, -1);
502         EXPECT_EQ(0, idx);
503         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
504 }
505
506 TEST_F(TBMSurfaceInternal, GetPlaneBoIndexSuccess)
507 {
508         int idx;
509
510         idx = tbm_surface_internal_get_plane_bo_idx(surface, 0);
511         EXPECT_EQ(0, idx);
512         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
513 }
514
515 static int tbm_data_free_is_called = 0;
516 void data_free_handle(void *user_data)
517 {
518         ASSERT_TRUE(user_data == &tbm_data_free_is_called);
519         int *is_called = (int *)user_data;
520         *is_called = 1;
521 }
522
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)
525 {
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));
529 }
530
531 TEST_F(TBMSurfaceInternal, AddUserDataFailInvaildInput)
532 {
533         static const unsigned long key_ud = 0;
534         int invalid_surf;
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));
537 }
538
539 TEST_F(TBMSurfaceInternal, AddUserDataSuccess)
540 {
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));
544 }
545
546 TEST_F(TBMSurfaceInternal, AddUserDataFailDoubleKey)
547 {
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));
551
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));
554 }
555
556 /* tbm_surface_internal_set_user_data(tbm_surface_h surface, unsigned long key, void *data) */
557 TEST_F(TBMSurfaceInternal, SetUserDataFailNull)
558 {
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));
562 }
563
564 TEST_F(TBMSurfaceInternal, SetUserDataFailInvaildInput)
565 {
566         static const unsigned long key_ud = 0;
567         int surf;
568
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));
572
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));
576 }
577
578 TEST_F(TBMSurfaceInternal, SetUserDataSuccess)
579 {
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));
583
584         /*the first call*/
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));
587
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);
593
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);
599 }
600
601 /* tbm_surface_internal_get_user_data(tbm_surface_h surface, unsigned long key, void **data) */
602 TEST_F(TBMSurfaceInternal, GetUserDataFailNull)
603 {
604         static const unsigned long key_ud = 0;
605         int *data = NULL;
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));
608
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));
611 }
612
613 TEST_F(TBMSurfaceInternal, GetUserDataFailInvaildInput)
614 {
615         static const unsigned long key_ud = 0;
616         int surf;
617         int *data = NULL;
618
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));
622
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));
626 }
627
628 TEST_F(TBMSurfaceInternal, GetUserDataSuccess)
629 {
630         unsigned long key_ud = 97456789;
631         int *data = NULL;
632
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));
637
638         /* check set data */
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);
642
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);
649 }
650
651 /* tbm_surface_internal_delete_user_data(tbm_surface_h surface, unsigned long key) */
652 TEST_F(TBMSurfaceInternal, DeleteUserDataFailNull)
653 {
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));
657 }
658
659 TEST_F(TBMSurfaceInternal, DeleteUserDataFailInvaildInput)
660 {
661         static const int key_ud = 0;
662         int surf;
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));
665
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));
668 }
669
670 TEST_F(TBMSurfaceInternal, DeleteUserDataSuccess)
671 {
672         unsigned long key_ud = UINT_MAX;
673
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));
678
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));
685 }