1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
/* EINA - EFL data type library
* Copyright (C) 2008 Cedric Bail
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library;
* if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <Eina.h>
#include "eina_suite.h"
#define TEST0 "te\0st/0"
#define TEST0_SIZE 7
#define TEST1 "te\0st/11"
#define TEST1_SIZE 8
EFL_START_TEST(eina_binshare_simple)
{
const char *t0;
const char *t1;
t0 = eina_binshare_add_length(TEST0, TEST0_SIZE);
t1 = eina_binshare_add_length(TEST1, TEST1_SIZE);
fail_if(t0 == NULL);
fail_if(t1 == NULL);
fail_if(memcmp(t0, TEST0, TEST0_SIZE) != 0);
fail_if(memcmp(t1, TEST1, TEST1_SIZE) != 0);
t0 = eina_binshare_ref(t0);
fail_if(t0 == NULL);
fail_if(memcmp(t0, TEST0, TEST0_SIZE) != 0);
eina_binshare_del(t0);
eina_binshare_del(t0);
eina_binshare_del(t1);
}
EFL_END_TEST
EFL_START_TEST(eina_binshare_small)
{
char buf[4];
int i;
for (i = 1; i < 3; i++)
{
const char *t0, *t1;
int j;
for (j = 0; j < i; j++)
{
char c;
for (c = 'a'; c <= 'z'; c++)
buf[j] = c;
}
buf[i] = '\0';
t0 = eina_binshare_add_length(buf, i);
t1 = eina_binshare_add_length(buf, i);
fail_if(t0 == NULL);
fail_if(t1 == NULL);
fail_if(t0 != t1);
fail_if(memcmp(t0, buf, i) != 0);
eina_binshare_del(t0);
eina_binshare_del(t1);
}
}
EFL_END_TEST
EFL_START_TEST(eina_binshare_test_share)
{
const char *t0;
const char *t1;
t0 = eina_binshare_add_length(TEST0, TEST0_SIZE);
t1 = eina_binshare_add_length(TEST0, TEST0_SIZE);
fail_if(t0 == NULL);
fail_if(t1 == NULL);
fail_if(memcmp(t0, TEST0, TEST0_SIZE) != 0);
fail_if(memcmp(t1, TEST0, TEST0_SIZE) != 0);
fail_if(t0 != t1);
fail_if(TEST0_SIZE != eina_binshare_length(t0));
eina_binshare_del(t0);
eina_binshare_del(t1);
}
EFL_END_TEST
EFL_START_TEST(eina_binshare_putstuff)
{
const char *tmp;
int i;
for (i = 100; i > 0; --i)
{
char build[64] = "string_";
unsigned int len;
eina_convert_xtoa(i, build + 7);
len = strlen(build);
tmp = eina_binshare_add_length(build, len);
ck_assert_ptr_ne(tmp, NULL);
ck_assert_ptr_eq(tmp, eina_binshare_add_length(build, len));
ck_assert_int_eq(len, eina_binshare_length(tmp));
eina_binshare_del(tmp);
eina_binshare_del(tmp);
}
}
EFL_END_TEST
EFL_START_TEST(eina_binshare_collision)
{
Eina_Array *ea;
char buffer[50];
int i;
const void *r;
ea = eina_array_new(256);
for (i = 0; i < 256; ++i)
{
unsigned int len;
eina_convert_itoa(60000 - i, buffer);
len = strlen(buffer);
r = eina_binshare_add_length(buffer, len);
ck_assert_ptr_ne(r, NULL);
eina_array_push(ea, r);
r = eina_binshare_add_length(buffer, len);
ck_assert_ptr_ne(r, NULL);
r = eina_binshare_add_length(buffer, len);
ck_assert_ptr_ne(r, NULL);
}
while (eina_array_count(ea))
{
r = eina_array_pop(ea);
eina_binshare_del(r);
eina_binshare_del(r);
eina_binshare_del(r);
}
eina_array_free(ea);
}
EFL_END_TEST
void
eina_test_binshare(TCase *tc)
{
tcase_add_test(tc, eina_binshare_simple);
tcase_add_test(tc, eina_binshare_small);
tcase_add_test(tc, eina_binshare_test_share);
tcase_add_test(tc, eina_binshare_collision);
tcase_add_test(tc, eina_binshare_putstuff);
}
|