diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/eina/src/tests/eina_test_stringshare.c | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2 SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz |
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to 'libraries/eina/src/tests/eina_test_stringshare.c')
-rw-r--r-- | libraries/eina/src/tests/eina_test_stringshare.c | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/libraries/eina/src/tests/eina_test_stringshare.c b/libraries/eina/src/tests/eina_test_stringshare.c new file mode 100644 index 0000000..0d34aec --- /dev/null +++ b/libraries/eina/src/tests/eina_test_stringshare.c | |||
@@ -0,0 +1,201 @@ | |||
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 <stdlib.h> | ||
24 | #include <stdio.h> | ||
25 | #include <string.h> | ||
26 | #include <time.h> | ||
27 | |||
28 | #include "eina_suite.h" | ||
29 | #include "Eina.h" | ||
30 | |||
31 | #define TEST0 "test/0" | ||
32 | #define TEST1 "test/1" | ||
33 | |||
34 | START_TEST(eina_stringshare_simple) | ||
35 | { | ||
36 | const char *t0; | ||
37 | const char *t1; | ||
38 | |||
39 | eina_init(); | ||
40 | |||
41 | t0 = eina_stringshare_add(TEST0); | ||
42 | t1 = eina_stringshare_add(TEST1); | ||
43 | |||
44 | fail_if(t0 == NULL); | ||
45 | fail_if(t1 == NULL); | ||
46 | fail_if(strcmp(t0, TEST0) != 0); | ||
47 | fail_if(strcmp(t1, TEST1) != 0); | ||
48 | fail_if((int)strlen(TEST0) != eina_stringshare_strlen(t0)); | ||
49 | fail_if((int)strlen(TEST1) != eina_stringshare_strlen(t1)); | ||
50 | |||
51 | t0 = eina_stringshare_ref(t0); | ||
52 | fail_if(t0 == NULL); | ||
53 | fail_if((int)strlen(TEST0) != eina_stringshare_strlen(t0)); | ||
54 | |||
55 | eina_stringshare_del(t0); | ||
56 | eina_stringshare_del(t0); | ||
57 | eina_stringshare_del(t1); | ||
58 | |||
59 | eina_shutdown(); | ||
60 | } | ||
61 | END_TEST | ||
62 | |||
63 | START_TEST(eina_stringshare_small) | ||
64 | { | ||
65 | char buf[4]; | ||
66 | int i; | ||
67 | |||
68 | eina_init(); | ||
69 | |||
70 | for (i = 0; i < 3; i++) | ||
71 | { | ||
72 | const char *t0, *t1; | ||
73 | int j; | ||
74 | |||
75 | for (j = 0; j < i; j++) | ||
76 | { | ||
77 | char c; | ||
78 | for (c = 'a'; c <= 'z'; c++) | ||
79 | buf[j] = c; | ||
80 | } | ||
81 | buf[i] = '\0'; | ||
82 | t0 = eina_stringshare_add(buf); | ||
83 | t1 = eina_stringshare_add(buf); | ||
84 | |||
85 | fail_if(t0 == NULL); | ||
86 | fail_if(t1 == NULL); | ||
87 | fail_if(t0 != t1); | ||
88 | fail_if(strcmp(t0, buf) != 0); | ||
89 | fail_if((int)strlen(buf) != eina_stringshare_strlen(t0)); | ||
90 | fail_if((int)strlen(buf) != eina_stringshare_strlen(t1)); | ||
91 | |||
92 | eina_stringshare_del(t0); | ||
93 | eina_stringshare_del(t1); | ||
94 | } | ||
95 | |||
96 | eina_shutdown(); | ||
97 | } | ||
98 | END_TEST | ||
99 | |||
100 | |||
101 | START_TEST(eina_stringshare_test_share) | ||
102 | { | ||
103 | const char *t0; | ||
104 | const char *t1; | ||
105 | |||
106 | eina_init(); | ||
107 | |||
108 | t0 = eina_stringshare_add(TEST0); | ||
109 | t1 = eina_stringshare_add(TEST0); | ||
110 | |||
111 | fail_if(t0 == NULL); | ||
112 | fail_if(t1 == NULL); | ||
113 | fail_if(strcmp(t0, TEST0) != 0); | ||
114 | fail_if(strcmp(t1, TEST0) != 0); | ||
115 | fail_if(t0 != t1); | ||
116 | fail_if((int)strlen(t0) != eina_stringshare_strlen(t0)); | ||
117 | |||
118 | eina_stringshare_del(t0); | ||
119 | eina_stringshare_del(t1); | ||
120 | |||
121 | eina_shutdown(); | ||
122 | } | ||
123 | END_TEST | ||
124 | |||
125 | START_TEST(eina_stringshare_putstuff) | ||
126 | { | ||
127 | const char *tmp; | ||
128 | int i; | ||
129 | |||
130 | eina_init(); | ||
131 | |||
132 | for (i = 10000; i > 0; --i) | ||
133 | { | ||
134 | char build[64] = "string_"; | ||
135 | |||
136 | eina_convert_xtoa(i, build + 7); | ||
137 | tmp = eina_stringshare_add(build); | ||
138 | fail_if(tmp != eina_stringshare_add(build)); | ||
139 | } | ||
140 | |||
141 | eina_shutdown(); | ||
142 | } | ||
143 | END_TEST | ||
144 | |||
145 | START_TEST(eina_stringshare_collision) | ||
146 | { | ||
147 | Eina_Array *ea; | ||
148 | char buffer[50]; | ||
149 | int i; | ||
150 | |||
151 | srand(time(NULL)); | ||
152 | |||
153 | eina_init(); | ||
154 | |||
155 | ea = eina_array_new(256); | ||
156 | fail_if(!ea); | ||
157 | |||
158 | for (i = 0; i < 10000; ++i) | ||
159 | { | ||
160 | eina_convert_itoa(rand(), buffer); | ||
161 | eina_array_push(ea, (void *)eina_stringshare_add(buffer)); | ||
162 | if (rand() > RAND_MAX / 2) | ||
163 | { | ||
164 | const char *r = eina_stringshare_add(buffer); | ||
165 | fail_if(r == NULL); | ||
166 | } | ||
167 | } | ||
168 | |||
169 | for (i = 0; i < 10000; ++i) | ||
170 | { | ||
171 | const char *r; | ||
172 | |||
173 | eina_convert_itoa(60000 - i, buffer); | ||
174 | eina_array_push(ea, (void *)eina_stringshare_add(buffer)); | ||
175 | r = eina_stringshare_add(buffer); | ||
176 | fail_if(r == NULL); | ||
177 | r = eina_stringshare_add(buffer); | ||
178 | fail_if(r == NULL); | ||
179 | } | ||
180 | |||
181 | for (i = 0; i < 200; ++i) | ||
182 | eina_stringshare_del(eina_array_data_get(ea, i)); | ||
183 | |||
184 | for (i = 0; i < 1000; ++i) | ||
185 | eina_stringshare_del(eina_array_pop(ea)); | ||
186 | |||
187 | eina_shutdown(); | ||
188 | |||
189 | eina_array_free(ea); | ||
190 | } | ||
191 | END_TEST | ||
192 | |||
193 | void | ||
194 | eina_test_stringshare(TCase *tc) | ||
195 | { | ||
196 | tcase_add_test(tc, eina_stringshare_simple); | ||
197 | tcase_add_test(tc, eina_stringshare_small); | ||
198 | tcase_add_test(tc, eina_stringshare_test_share); | ||
199 | tcase_add_test(tc, eina_stringshare_collision); | ||
200 | tcase_add_test(tc, eina_stringshare_putstuff); | ||
201 | } | ||