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/>.
28 #include "eina_suite.h"
31 #define TEST0 "te\0st/0"
33 #define TEST1 "te\0st/11"
36 START_TEST(eina_binshare_simple)
43 t0 = eina_binshare_add_length(TEST0, TEST0_SIZE);
44 t1 = eina_binshare_add_length(TEST1, TEST1_SIZE);
48 fail_if(memcmp(t0, TEST0, TEST0_SIZE) != 0);
49 fail_if(memcmp(t1, TEST1, TEST1_SIZE) != 0);
51 t0 = eina_binshare_ref(t0);
53 fail_if(memcmp(t0, TEST0, TEST0_SIZE) != 0);
55 eina_binshare_del(t0);
56 eina_binshare_del(t0);
57 eina_binshare_del(t1);
63 START_TEST(eina_binshare_small)
70 for (i = 1; i < 3; i++)
75 for (j = 0; j < i; j++)
78 for (c = 'a'; c <= 'z'; c++)
82 t0 = eina_binshare_add_length(buf, i);
83 t1 = eina_binshare_add_length(buf, i);
88 fail_if(memcmp(t0, buf, i) != 0);
90 eina_binshare_del(t0);
91 eina_binshare_del(t1);
98 START_TEST(eina_binshare_test_share)
105 t0 = eina_binshare_add_length(TEST0, TEST0_SIZE);
106 t1 = eina_binshare_add_length(TEST0, TEST0_SIZE);
110 fail_if(memcmp(t0, TEST0, TEST0_SIZE) != 0);
111 fail_if(memcmp(t1, TEST0, TEST0_SIZE) != 0);
113 fail_if(TEST0_SIZE != eina_binshare_length(t0));
115 eina_binshare_del(t0);
116 eina_binshare_del(t1);
121 START_TEST(eina_binshare_putstuff)
128 for (i = 10000; i > 0; --i)
130 char build[64] = "string_";
132 eina_convert_xtoa(i, build + 7);
133 tmp = eina_binshare_add_length(build, strlen(build));
134 fail_if(tmp != eina_binshare_add_length(build, strlen(build)));
135 fail_if((int)strlen(build) != eina_binshare_length(tmp));
141 START_TEST(eina_binshare_collision)
151 ea = eina_array_new(256);
154 for (i = 0; i < 10000; ++i)
156 eina_convert_itoa(rand(), buffer);
158 (void *)eina_binshare_add_length(buffer, strlen(buffer)));
159 if (rand() > RAND_MAX / 2)
161 const char *r = eina_binshare_add_length(buffer, strlen(buffer));
166 for (i = 0; i < 10000; ++i)
170 eina_convert_itoa(60000 - i, buffer);
172 (void *)eina_binshare_add_length(buffer, strlen(buffer)));
173 r = eina_binshare_add_length(buffer, strlen(buffer));
175 r = eina_binshare_add_length(buffer, strlen(buffer));
179 for (i = 0; i < 200; ++i)
180 eina_binshare_del(eina_array_data_get(ea, i));
182 for (i = 0; i < 1000; ++i)
183 eina_binshare_del(eina_array_pop(ea));
192 eina_test_binshare(TCase *tc)
194 tcase_add_test(tc, eina_binshare_simple);
195 tcase_add_test(tc, eina_binshare_small);
196 tcase_add_test(tc, eina_binshare_test_share);
197 tcase_add_test(tc, eina_binshare_collision);
198 tcase_add_test(tc, eina_binshare_putstuff);