diff options
Diffstat (limited to 'libraries/eina/src/tests/eina_test_accessor.c')
-rw-r--r-- | libraries/eina/src/tests/eina_test_accessor.c | 243 |
1 files changed, 0 insertions, 243 deletions
diff --git a/libraries/eina/src/tests/eina_test_accessor.c b/libraries/eina/src/tests/eina_test_accessor.c deleted file mode 100644 index 3c85ef0..0000000 --- a/libraries/eina/src/tests/eina_test_accessor.c +++ /dev/null | |||
@@ -1,243 +0,0 @@ | |||
1 | /* EINA - EFL data type library | ||
2 | * Copyright (C) 2008 Cedric Bail | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * This library is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * Lesser General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public | ||
15 | * License along with this library; | ||
16 | * if not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #ifdef HAVE_CONFIG_H | ||
20 | # include "config.h" | ||
21 | #endif | ||
22 | |||
23 | #include <stdio.h> | ||
24 | |||
25 | #include "eina_suite.h" | ||
26 | #include "Eina.h" | ||
27 | |||
28 | static Eina_Bool | ||
29 | eina_accessor_check(__UNUSED__ const Eina_Array *array, | ||
30 | int *data, int *fdata) | ||
31 | { | ||
32 | fail_if(*fdata > *data); | ||
33 | *fdata = *data; | ||
34 | |||
35 | return EINA_TRUE; | ||
36 | } | ||
37 | |||
38 | START_TEST(eina_accessor_array_simple) | ||
39 | { | ||
40 | Eina_Accessor *it; | ||
41 | Eina_Array *ea; | ||
42 | int *tmp; | ||
43 | int i; | ||
44 | |||
45 | eina_init(); | ||
46 | |||
47 | ea = eina_array_new(11); | ||
48 | fail_if(!ea); | ||
49 | |||
50 | for (i = 0; i < 200; ++i) | ||
51 | { | ||
52 | tmp = malloc(sizeof(int)); | ||
53 | fail_if(!tmp); | ||
54 | *tmp = i; | ||
55 | |||
56 | eina_array_push(ea, tmp); | ||
57 | } | ||
58 | |||
59 | it = eina_array_accessor_new(ea); | ||
60 | fail_if(!it); | ||
61 | |||
62 | fail_if(eina_accessor_data_get(it, 100, (void **)&tmp) != EINA_TRUE); | ||
63 | fail_if(!tmp); | ||
64 | fail_if(*tmp != 100); | ||
65 | |||
66 | i = 50; | ||
67 | eina_accessor_over(it, EINA_EACH_CB(eina_accessor_check), 50, 100, &i); | ||
68 | fail_if(i != 99); | ||
69 | |||
70 | fail_if(eina_accessor_container_get(it) != ea); | ||
71 | |||
72 | eina_accessor_free(it); | ||
73 | |||
74 | eina_array_free(ea); | ||
75 | |||
76 | eina_shutdown(); | ||
77 | } | ||
78 | END_TEST | ||
79 | |||
80 | typedef struct _Eina_Test_Inlist Eina_Test_Inlist; | ||
81 | struct _Eina_Test_Inlist | ||
82 | { | ||
83 | EINA_INLIST; | ||
84 | int i; | ||
85 | }; | ||
86 | |||
87 | static Eina_Test_Inlist * | ||
88 | _eina_test_inlist_build(int i) | ||
89 | { | ||
90 | Eina_Test_Inlist *tmp; | ||
91 | |||
92 | tmp = malloc(sizeof(Eina_Test_Inlist)); | ||
93 | fail_if(!tmp); | ||
94 | tmp->i = i; | ||
95 | |||
96 | return tmp; | ||
97 | } | ||
98 | |||
99 | static Eina_Bool | ||
100 | eina_accessor_inlist_data_check(__UNUSED__ const Eina_Inlist *in_list, | ||
101 | Eina_Test_Inlist *data, | ||
102 | int *fdata) | ||
103 | { | ||
104 | switch (*fdata) | ||
105 | { | ||
106 | case 0: fail_if(data->i != 3227); break; | ||
107 | |||
108 | case 1: fail_if(data->i != 1664); break; | ||
109 | } | ||
110 | |||
111 | (*fdata)++; | ||
112 | |||
113 | return EINA_TRUE; | ||
114 | } | ||
115 | |||
116 | START_TEST(eina_accessor_inlist_simple) | ||
117 | { | ||
118 | Eina_Inlist *lst = NULL; | ||
119 | Eina_Test_Inlist *tmp; | ||
120 | Eina_Test_Inlist *prev; | ||
121 | Eina_Accessor *it; | ||
122 | int i = 0; | ||
123 | |||
124 | tmp = _eina_test_inlist_build(42); | ||
125 | lst = eina_inlist_append(lst, EINA_INLIST_GET(tmp)); | ||
126 | fail_if(!lst); | ||
127 | |||
128 | tmp = _eina_test_inlist_build(1664); | ||
129 | lst = eina_inlist_append_relative(lst, EINA_INLIST_GET(tmp), lst); | ||
130 | fail_if(!lst); | ||
131 | fail_if(((Eina_Test_Inlist *)lst)->i != 42); | ||
132 | |||
133 | prev = tmp; | ||
134 | tmp = _eina_test_inlist_build(3227); | ||
135 | lst = eina_inlist_prepend_relative(lst, EINA_INLIST_GET( | ||
136 | tmp), EINA_INLIST_GET(prev)); | ||
137 | fail_if(!lst); | ||
138 | fail_if(((Eina_Test_Inlist *)lst)->i != 42); | ||
139 | |||
140 | tmp = _eina_test_inlist_build(27); | ||
141 | lst = eina_inlist_prepend_relative(lst, EINA_INLIST_GET(tmp), NULL); | ||
142 | |||
143 | tmp = _eina_test_inlist_build(81); | ||
144 | lst = eina_inlist_append_relative(lst, EINA_INLIST_GET(tmp), NULL); | ||
145 | |||
146 | tmp = _eina_test_inlist_build(7); | ||
147 | lst = eina_inlist_append(lst, EINA_INLIST_GET(tmp)); | ||
148 | |||
149 | it = eina_inlist_accessor_new(lst); | ||
150 | fail_if(!it); | ||
151 | fail_if(eina_accessor_container_get(it) != lst); | ||
152 | |||
153 | eina_accessor_over(it, EINA_EACH_CB(eina_accessor_inlist_data_check), 2, 4, &i); | ||
154 | |||
155 | fail_if(eina_accessor_data_get(it, 5, (void **)&tmp) != EINA_TRUE); | ||
156 | fail_if(eina_accessor_data_get(it, 3, (void **)&tmp) != EINA_TRUE); | ||
157 | fail_if(tmp->i != 1664); | ||
158 | fail_if(eina_accessor_data_get(it, 3, (void **)&tmp) != EINA_TRUE); | ||
159 | fail_if(tmp->i != 1664); | ||
160 | fail_if(eina_accessor_data_get(it, 1, (void **)&tmp) != EINA_TRUE); | ||
161 | fail_if(tmp->i != 42); | ||
162 | |||
163 | eina_accessor_free(it); | ||
164 | |||
165 | fail_if(i != 2); | ||
166 | } | ||
167 | END_TEST | ||
168 | |||
169 | static Eina_Bool | ||
170 | eina_iterator_list_data_check(__UNUSED__ const Eina_List *list, | ||
171 | int *data, | ||
172 | int *fdata) | ||
173 | { | ||
174 | switch (*fdata) | ||
175 | { | ||
176 | case 0: fail_if(*data != 9); break; | ||
177 | |||
178 | case 1: fail_if(*data != 6); break; | ||
179 | } | ||
180 | |||
181 | (*fdata)++; | ||
182 | |||
183 | return EINA_TRUE; | ||
184 | } | ||
185 | |||
186 | START_TEST(eina_accessor_list_simple) | ||
187 | { | ||
188 | Eina_List *list = NULL; | ||
189 | Eina_Accessor *it; | ||
190 | int data[] = { 6, 9, 42, 1, 7, 1337, 81, 1664 }; | ||
191 | int *j; | ||
192 | int i = 0; | ||
193 | |||
194 | eina_init(); | ||
195 | |||
196 | list = eina_list_append(list, &data[0]); | ||
197 | fail_if(list == NULL); | ||
198 | |||
199 | list = eina_list_prepend(list, &data[1]); | ||
200 | fail_if(list == NULL); | ||
201 | |||
202 | list = eina_list_append(list, &data[2]); | ||
203 | fail_if(list == NULL); | ||
204 | |||
205 | list = eina_list_append(list, &data[3]); | ||
206 | fail_if(list == NULL); | ||
207 | |||
208 | list = eina_list_prepend(list, &data[4]); | ||
209 | fail_if(list == NULL); | ||
210 | |||
211 | list = eina_list_append(list, &data[5]); | ||
212 | fail_if(list == NULL); | ||
213 | |||
214 | list = eina_list_prepend(list, &data[6]); | ||
215 | fail_if(list == NULL); | ||
216 | |||
217 | it = eina_list_accessor_new(list); | ||
218 | fail_if(!it); | ||
219 | |||
220 | eina_accessor_over(it, EINA_EACH_CB(eina_iterator_list_data_check), 2, 4, &i); | ||
221 | |||
222 | fail_if(eina_accessor_data_get(it, 5, (void **)&j) != EINA_TRUE); | ||
223 | fail_if(*j != 1); | ||
224 | fail_if(eina_accessor_data_get(it, 3, (void **)&j) != EINA_TRUE); | ||
225 | fail_if(*j != 6); | ||
226 | fail_if(eina_accessor_data_get(it, 3, (void **)&j) != EINA_TRUE); | ||
227 | fail_if(*j != 6); | ||
228 | fail_if(eina_accessor_data_get(it, 1, (void **)&j) != EINA_TRUE); | ||
229 | fail_if(*j != 7); | ||
230 | fail_if(eina_accessor_data_get(it, 5, (void **)&j) != EINA_TRUE); | ||
231 | fail_if(*j != 1); | ||
232 | |||
233 | eina_accessor_free(it); | ||
234 | } | ||
235 | END_TEST | ||
236 | |||
237 | void | ||
238 | eina_test_accessor(TCase *tc) | ||
239 | { | ||
240 | tcase_add_test(tc, eina_accessor_array_simple); | ||
241 | tcase_add_test(tc, eina_accessor_inlist_simple); | ||
242 | tcase_add_test(tc, eina_accessor_list_simple); | ||
243 | } | ||