utest: rename the ut to the utests
[platform/core/uifw/libtbm.git] / utests / stubs / tbm_bufmgr_stubs.h
1 /**************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
4  *
5  * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sub license, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice (including the
16  * next paragraph) shall be included in all copies or substantial portions
17  * of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
23  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  *
27 **************************************************************************/
28
29 #ifndef TBM_BUFMGR_STUBS_H
30 #define TBM_BUFMGR_STUBS_H
31
32 #include <tbm_bufmgr.h>
33
34 /* HELPER FUNCTIONS */
35
36 static int bo_size = 100;
37 static int bo2_size = 100;
38 static void *ret_bo = (void *)"bo_alloc";
39 static int UT_TBM_ERROR = 0;
40 static int TBM_BO_ALLOC_ERROR = 0;
41 static int TBM_BO_IMPORT_ERROR = 0;
42 static int bo_ret_flags = TBM_BO_SCANOUT;
43 static int ut_tbm_bufmgr_init_error;
44 static int ut_tbm_data_free_called = 0;
45
46 static int ut_bo_size(tbm_bo __attribute__ ((unused)) bo)
47 {
48         return bo_size;
49 }
50
51 static int ut_bo2_size(tbm_bo __attribute__ ((unused)) bo)
52 {
53         return bo2_size;
54 }
55
56 static void *ut_bo_alloc(tbm_bo __attribute__ ((unused)) bo,
57                                                  int __attribute__ ((unused)) size,
58                                                  int __attribute__ ((unused)) flags)
59 {
60         if (TBM_BO_ALLOC_ERROR)
61                 return NULL;
62
63         return ret_bo;
64 }
65
66 static void *ut_bo_import(tbm_bo __attribute__ ((unused)) bo,
67                                                   unsigned int __attribute__ ((unused)) key)
68 {
69         if (TBM_BO_IMPORT_ERROR)
70                 return NULL;
71
72         return ret_bo;
73 }
74
75 static int ut_bo_get_flags(tbm_bo __attribute__ ((unused)) bo)
76 {
77         return bo_ret_flags;
78 }
79
80 static void *ut_bo_import_fd(tbm_bo __attribute__ ((unused)) bo,
81                                                          tbm_fd __attribute__ ((unused)) fd)
82 {
83         if (TBM_BO_IMPORT_ERROR)
84                 return NULL;
85
86         return ret_bo;
87 }
88
89 static unsigned int ut_bo_export(tbm_bo __attribute__ ((unused)) bo)
90 {
91         if (UT_TBM_ERROR)
92                 return 0;
93
94         return 1;
95 }
96
97 static tbm_fd ut_bo_export_fd(tbm_bo __attribute__ ((unused)) bo)
98 {
99         if (UT_TBM_ERROR)
100                 return -1;
101
102         return 1;
103 }
104
105 static tbm_bo_handle ut_bo_get_handle(tbm_bo __attribute__ ((unused)) bo,
106                                                                           int __attribute__ ((unused)) device)
107 {
108         tbm_bo_handle ret;
109
110         if (UT_TBM_ERROR)
111                 ret.ptr = NULL;
112         else
113                 ret.ptr = (void *)12;
114
115         return ret;
116 }
117
118 static tbm_bo_handle ut_bo_map(tbm_bo __attribute__ ((unused)) bo,
119                                                            int __attribute__ ((unused)) device,
120                                                            int __attribute__ ((unused)) opt)
121 {
122         tbm_bo_handle ret;
123
124         if (UT_TBM_ERROR)
125                 ret.ptr = NULL;
126         else
127                 ret.ptr = (void *)12;
128
129         return ret;
130 }
131
132 static int ut_bo_unmap(tbm_bo __attribute__ ((unused)) bo)
133 {
134         if (UT_TBM_ERROR)
135                 return 0;
136
137         return 1;
138 }
139
140 static void ut_tbm_data_free(void __attribute__ ((unused)) *user_data)
141 {
142         ut_tbm_data_free_called = 1;
143 }
144
145 static int ut_bufmgr_bind_native_display(tbm_bufmgr __attribute__ ((unused)) bufmgr,
146                                                                                  void __attribute__ ((unused)) *NativeDisplay)
147 {
148         if (UT_TBM_ERROR)
149                 return 0;
150
151         return 1;
152 }
153
154 static struct _tbm_bufmgr ut_ret_bufmgr;
155 static tbm_bufmgr ut_tbm_bufmgr_init(int fd)
156 {
157         if (ut_tbm_bufmgr_init_error)
158                 return NULL;
159
160         return &ut_ret_bufmgr;
161 }
162
163 #endif /* TBM_BUFMGR_STUBS_H */