change the utests to haltests
[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 /* tbm_surface_h tbm_surface_internal_create_with_flags(int width, int height, int format, int flags) */
78 TEST_F(TBMSurfaceInternal, SurfaceInternalCeateDestroyTest)
79 {
80         tbm_surface_h surface1 = NULL;
81
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));
88         }
89 }
90
91 TEST_F(TBMSurfaceInternal, SurfaceInternalCeatewithParamsTest)
92 {
93         tbm_surface_h surface1 = NULL;
94
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));
107 }
108
109 /* void tbm_surface_internal_destroy(tbm_surface_h surface) */
110 TEST_F(TBMSurfaceInternal, SurfaceInternalSurfaceInteranlDestroyWithParamsTest)
111 {
112         tbm_surface_internal_destroy(NULL);
113         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
114 }
115
116 TEST_F(TBMSurfaceInternal, SurfaceInteranlDestroyTwiceTest)
117 {
118         tbm_surface_h surface1 = NULL;
119
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));
126 }
127
128 /* tbm_surface_internal_is_valid(tbm_surface_h surface) */
129 TEST_F(TBMSurfaceInternal, SurfaceInteranlIsValid)
130 {
131         tbm_surface_h invalid_surface;
132
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));
135
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));
138
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));
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_surface_h invalide_surface = (tbm_surface_h)1;
170         tbm_bo bo = NULL;
171
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));
176
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));
181 }
182
183 TEST_F(TBMSurfaceInternal, GetBoSuccess)
184 {
185         tbm_bo bo = NULL;
186         int num = 0;
187
188         num = tbm_surface_internal_get_num_bos(surface);
189         EXPECT_GT(num, 0);
190         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
191
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));
196         }
197 }
198
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)
201 {
202         tbm_surface_h surf = NULL;
203         tbm_surface_info_s info = { 0 };
204         tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE;
205         tbm_bo bos[1];
206
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));
209
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));
213
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));
217
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));
221 }
222
223 TEST_F(TBMSurfaceInternal, CreateWithBosFailInvalidInput)
224 {
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 };
229         int num;
230
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));
233
234         num = tbm_surface_internal_get_num_bos(surface);
235         EXPECT_GT(num, 0);
236
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));
241         }
242
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));
250
251         /* invalid bo */
252         bos[num-1] = NULL;
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));
256 }
257
258 TEST_F(TBMSurfaceInternal, CreateWithBosSuccess)
259 {
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 };
264         int num = 0;
265
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));
269
270         num = tbm_surface_internal_get_num_bos(surface);
271         EXPECT_GT(num , 0);
272         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
273
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));
278         }
279
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));
285
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));
293
294         /* set bpp to zero*/
295         info.bpp = 0;
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));
301
302         /* set size to zero*/
303         info.size = 0;
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));
309 }
310
311 /* void tbm_surface_internal_unref(tbm_surface_h surface) */
312 TEST_F(TBMSurfaceInternal, UnrefFailNull)
313 {
314         tbm_surface_internal_unref(NULL);
315         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
316 }
317
318 TEST_F(TBMSurfaceInternal, UnrefFailInvaildInput)
319 {
320         int surf;
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));
323 }
324
325 TEST_F(TBMSurfaceInternal, UnrefSuccess)
326 {
327         tbm_surface_internal_unref(surface);
328         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
329
330         EXPECT_FALSE(tbm_surface_internal_is_valid(surface)) ;
331
332         surface = NULL;
333 }
334
335 /* void tbm_surface_internal_ref(tbm_surface_h surface) */
336 TEST_F(TBMSurfaceInternal, RefFailNull)
337 {
338         tbm_surface_internal_ref(NULL);
339         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
340 }
341
342 TEST_F(TBMSurfaceInternal, RefFailInvaildInput)
343 {
344         int surf;
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));
347 }
348
349 TEST_F(TBMSurfaceInternal, RefSuccess)
350 {
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));
356 }
357
358 /* tbm_surface_internal_get_num_planes() */
359 TEST_F(TBMSurfaceInternal, GetNumPlanes)
360 {
361         int num = 0;
362         num = tbm_surface_internal_get_num_planes(0);
363         EXPECT_EQ(0, num);
364         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
365
366         num = tbm_surface_internal_get_num_planes(TBM_FORMAT_ARGB8888);
367         EXPECT_EQ(1, num);
368         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
369
370         num = tbm_surface_internal_get_num_planes(TBM_FORMAT_NV12);
371         EXPECT_EQ(2, num);
372         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
373
374         num = tbm_surface_internal_get_num_planes(TBM_FORMAT_YUV410);
375         EXPECT_EQ(3, num);
376         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
377 }
378
379 /* tbm_surface_internal_get_size() */
380 TEST_F(TBMSurfaceInternal, GetSizeFailNull)
381 {
382         int size = tbm_surface_internal_get_size(NULL);
383         EXPECT_EQ(0, size);
384         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
385 }
386
387 TEST_F(TBMSurfaceInternal, GetSizeFailInvaildInput)
388 {
389         int surf;
390         int size = tbm_surface_internal_get_size((tbm_surface_h)&surf);
391         EXPECT_EQ(0, size);
392         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
393 }
394
395 TEST_F(TBMSurfaceInternal, GetSizeSuccess)
396 {
397         int size = tbm_surface_internal_get_size(surface);
398         ASSERT_GT(size, 0);
399         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
400 }
401
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)
404 {
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));
407 }
408
409 TEST_F(TBMSurfaceInternal, GetPlaneDataFailInvaildInput)
410 {
411         int surf;
412
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));
419 }
420
421 TEST_F(TBMSurfaceInternal, GetPlaneDataSuccess)
422 {
423         uint32_t size = 0, offset = 0, pitch = 0;
424
425         EXPECT_TRUE(tbm_surface_internal_get_plane_data(surface, 0, &size, NULL, NULL));
426         EXPECT_GT(size, 0);
427         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
428
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));
431
432         EXPECT_TRUE(tbm_surface_internal_get_plane_data(surface, 0, NULL, NULL, &pitch));
433         EXPECT_GT(pitch, 0);
434         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
435 }
436
437 /* tbm_surface_internal_get_bpp(tbm_format format) */
438 TEST_F(TBMSurfaceInternal, GetBpp)
439 {
440         int bpp = 0;
441         bpp = tbm_surface_internal_get_bpp(0);
442         EXPECT_EQ(0, bpp);
443         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
444
445         bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_RGB332);
446         EXPECT_EQ(8, bpp);
447         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
448
449         bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_RGB565);
450         EXPECT_EQ(16, bpp);
451         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
452
453         bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_RGB888);
454         EXPECT_EQ(24, bpp);
455         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
456
457         bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_ARGB8888);
458         EXPECT_EQ(32, bpp);
459         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
460
461         bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_NV12);
462         EXPECT_EQ(12, bpp);
463         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
464
465         bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_NV16);
466         EXPECT_EQ(16, bpp);
467         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
468
469         bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_YUV410);
470         EXPECT_EQ(9, bpp);
471         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
472
473         bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_YUV411);
474         EXPECT_EQ(12, bpp);
475         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
476
477         bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_YUV422);
478         EXPECT_EQ(16, bpp);
479         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
480
481         bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_YUV444);
482         EXPECT_EQ(24, bpp);
483         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
484 }
485 /* tbm_surface_internal_get_plane_bo_idx(tbm_surface_h surface, int plane_idx) */
486 TEST_F(TBMSurfaceInternal, GetPlaneBoIndexFailNull)
487 {
488         int idx = tbm_surface_internal_get_plane_bo_idx(NULL, 0);
489         EXPECT_EQ(0, idx);
490         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
491 }
492
493 TEST_F(TBMSurfaceInternal, GetPlaneBoIndexFailInvaildInput)
494 {
495         int surf;
496         int idx;
497
498         idx = tbm_surface_internal_get_plane_bo_idx((tbm_surface_h)&surf, 0);
499         EXPECT_EQ(0, idx);
500         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
501
502         idx = tbm_surface_internal_get_plane_bo_idx(surface, -1);
503         EXPECT_EQ(0, idx);
504         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
505 }
506
507 TEST_F(TBMSurfaceInternal, GetPlaneBoIndexSuccess)
508 {
509         int idx;
510
511         idx = tbm_surface_internal_get_plane_bo_idx(surface, 0);
512         EXPECT_EQ(0, idx);
513         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
514 }
515
516 static int tbm_data_free_is_called = 0;
517 void data_free_handle(void *user_data)
518 {
519         ASSERT_TRUE(user_data == &tbm_data_free_is_called);
520         int *is_called = (int *)user_data;
521         *is_called = 1;
522 }
523
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)
526 {
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));
530 }
531
532 TEST_F(TBMSurfaceInternal, AddUserDataFailInvaildInput)
533 {
534         static const unsigned long key_ud = 0;
535         int invalid_surf;
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));
538 }
539
540 TEST_F(TBMSurfaceInternal, AddUserDataSuccess)
541 {
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));
545 }
546
547 TEST_F(TBMSurfaceInternal, AddUserDataFailDoubleKey)
548 {
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));
552
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));
555 }
556
557 /* tbm_surface_internal_set_user_data(tbm_surface_h surface, unsigned long key, void *data) */
558 TEST_F(TBMSurfaceInternal, SetUserDataFailNull)
559 {
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));
563 }
564
565 TEST_F(TBMSurfaceInternal, SetUserDataFailInvaildInput)
566 {
567         static const unsigned long key_ud = 0;
568         int surf;
569
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));
573
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));
577 }
578
579 TEST_F(TBMSurfaceInternal, SetUserDataSuccess)
580 {
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));
584
585         /*the first call*/
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));
588
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);
594
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);
600 }
601
602 /* tbm_surface_internal_get_user_data(tbm_surface_h surface, unsigned long key, void **data) */
603 TEST_F(TBMSurfaceInternal, GetUserDataFailNull)
604 {
605         static const unsigned long key_ud = 0;
606         int *data = NULL;
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));
609
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));
612 }
613
614 TEST_F(TBMSurfaceInternal, GetUserDataFailInvaildInput)
615 {
616         static const unsigned long key_ud = 0;
617         int surf;
618         int *data = NULL;
619
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));
623
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));
627 }
628
629 TEST_F(TBMSurfaceInternal, GetUserDataSuccess)
630 {
631         unsigned long key_ud = 97456789;
632         int *data = NULL;
633
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));
638
639         /* check set data */
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);
643
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);
650 }
651
652 /* tbm_surface_internal_delete_user_data(tbm_surface_h surface, unsigned long key) */
653 TEST_F(TBMSurfaceInternal, DeleteUserDataFailNull)
654 {
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));
658 }
659
660 TEST_F(TBMSurfaceInternal, DeleteUserDataFailInvaildInput)
661 {
662         static const int key_ud = 0;
663         int surf;
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));
666
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));
669 }
670
671 TEST_F(TBMSurfaceInternal, DeleteUserDataSuccess)
672 {
673         unsigned long key_ud = UINT_MAX;
674
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));
679
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));
686 }