1 /* EINA - EFL data type library
2 * Copyright (C) 2008 Cedric Bail
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.
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.
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/>.
25 #include "eina_suite.h"
28 START_TEST(eina_array_simple)
32 Eina_Array_Iterator it;
37 ea = eina_array_new(11);
40 for (i = 0; i < 201; ++i)
42 tmp = malloc(sizeof(char) * 10);
44 eina_convert_itoa(i, tmp);
46 eina_array_push(ea, tmp);
49 fail_if(eina_array_data_get(ea, 10) == NULL);
50 fail_if(atoi(eina_array_data_get(ea, 10)) != 10);
51 tmp = eina_array_pop(ea);
53 fail_if(atoi(tmp) != 200);
56 EINA_ARRAY_ITER_NEXT(ea, i, tmp, it)
58 fail_if((unsigned int)atoi(tmp) != i);
72 START_TEST(eina_array_static)
76 Eina_Array_Iterator it;
81 eina_array_step_set(&sea, sizeof(sea), 10);
83 for (i = 0; i < 200; ++i)
85 tmp = malloc(sizeof(char) * 10);
87 eina_convert_itoa(i, tmp);
89 eina_array_push(&sea, tmp);
92 fail_if(eina_array_data_get(&sea, 10) == NULL);
93 fail_if(atoi(eina_array_data_get(&sea, 10)) != 10);
95 EINA_ARRAY_ITER_NEXT(&sea, i, tmp, it)
97 fail_if((unsigned int)atoi(tmp) != i);
103 eina_array_clean(&sea);
104 eina_array_flush(&sea);
111 keep_int(void *data, void *gdata)
124 START_TEST(eina_array_remove_stuff)
128 Eina_Array_Iterator it;
133 ea = eina_array_new(64);
136 for (i = 0; i < 1000; ++i)
138 tmp = malloc(sizeof(int));
142 eina_array_push(ea, tmp);
145 // Remove the first 10 items
146 for (i = 0; i < 10; ++i)
148 tmp = eina_array_data_get(ea, i);
152 fail_if(eina_array_remove(ea, keep_int, NULL) != EINA_TRUE);
154 fail_if(eina_array_count(ea) != 990);
155 EINA_ARRAY_ITER_NEXT(ea, i, tmp, it)
158 // Remove the last items
159 for (i = 980; i < 990; ++i)
161 tmp = eina_array_data_get(ea, i);
165 eina_array_remove(ea, keep_int, NULL);
168 fail_if(eina_array_count(ea) != 980);
169 EINA_ARRAY_ITER_NEXT(ea, i, tmp, it)
175 eina_array_remove(ea, keep_int, NULL);
177 fail_if(eina_array_count(ea) != 0);
186 eina_test_array(TCase *tc)
188 tcase_add_test(tc, eina_array_simple);
189 tcase_add_test(tc, eina_array_static);
190 tcase_add_test(tc, eina_array_remove_stuff);