OSDN Git Service

implement parser for rfc733 format date text.
[bbk/bchan.git] / src / test_residhash.c
1 /*
2  * test_residhash.c
3  *
4  * Copyright (c) 2010 project bchan
5  *
6  * This software is provided 'as-is', without any express or implied
7  * warranty. In no event will the authors be held liable for any damages
8  * arising from the use of this software.
9  *
10  * Permission is granted to anyone to use this software for any purpose,
11  * including commercial applications, and to alter it and redistribute it
12  * freely, subject to the following restrictions:
13  *
14  * 1. The origin of this software must not be misrepresented; you must not
15  *    claim that you wrote the original software. If you use this software
16  *    in a product, an acknowledgment in the product documentation would be
17  *    appreciated but is not required.
18  *
19  * 2. Altered source versions must be plainly marked as such, and must not be
20  *    misrepresented as being the original software.
21  *
22  * 3. This notice may not be removed or altered from any source
23  *    distribution.
24  *
25  */
26
27 #include    <btron/btron.h>
28 #include    <bstdio.h>
29 #include    <bstring.h>
30 #include    <tstring.h>
31
32 #include    "test.h"
33
34 #include    "residhash.h"
35
36 LOCAL TEST_RESULT test_residhash_1()
37 {
38         residhash_t residhash;
39         W ret;
40
41         ret = residhash_initialize(&residhash);
42         if (ret < 0) {
43                 printf("residhash_initialize fail\n");
44                 return TEST_RESULT_FAIL;
45         }
46         residhash_finalize(&residhash);
47
48         return TEST_RESULT_PASS;
49 }
50
51 LOCAL TEST_RESULT test_residhash_2()
52 {
53         residhash_t residhash;
54         UB idstr[] = "yZXmy7Om0";
55         TC idstr_tc[9];
56         W ret, idstr_len = strlen(idstr);
57         UW attr;
58         COLOR color;
59         TEST_RESULT result = TEST_RESULT_PASS;
60
61         sjstotcs(idstr_tc, idstr);
62
63         ret = residhash_initialize(&residhash);
64         if (ret < 0) {
65                 printf("residhash_initialize fail\n");
66                 return TEST_RESULT_FAIL;
67         }
68         ret = residhash_searchdata(&residhash, idstr_tc, idstr_len, &attr, &color);
69         if (ret != RESIDHASH_SEARCHDATA_NOTFOUND) {
70                 printf("residhash_searchdata fail\n");
71                 result = TEST_RESULT_FAIL;
72         }
73         residhash_finalize(&residhash);
74
75         return result;
76 }
77
78 LOCAL TEST_RESULT test_residhash_3()
79 {
80         residhash_t residhash;
81         UB idstr[] = "yZXmy7Om0";
82         TC idstr_tc[9];
83         W ret, idstr_len = strlen(idstr);
84         UW attr, attr1 = 0x01010101;
85         COLOR color, color1 = 0x10FF00FF;
86         TEST_RESULT result = TEST_RESULT_PASS;
87
88         sjstotcs(idstr_tc, idstr);
89
90         ret = residhash_initialize(&residhash);
91         if (ret < 0) {
92                 printf("residhash_initialize fail\n");
93                 return TEST_RESULT_FAIL;
94         }
95         ret = residhash_adddata(&residhash, idstr_tc, idstr_len, attr1, color1);
96         if (ret < 0) {
97                 printf("residhash_adddata fail\n");
98                 result = TEST_RESULT_FAIL;
99         }
100         ret = residhash_searchdata(&residhash, idstr_tc, idstr_len, &attr, &color);
101         if (ret != RESIDHASH_SEARCHDATA_FOUND) {
102                 printf("residhash_searchdata fail\n");
103                 result = TEST_RESULT_FAIL;
104         }
105         if (attr != attr1) {
106                 printf("residhash_searchdata result fail\n");
107                 result = TEST_RESULT_FAIL;
108         }
109         if (color != color1) {
110                 printf("residhash_searchdata result fail\n");
111                 result = TEST_RESULT_FAIL;
112         }
113         residhash_finalize(&residhash);
114
115         return result;
116 }
117
118 LOCAL TEST_RESULT test_residhash_4()
119 {
120         residhash_t residhash;
121         UB idstr[] = "yZXmy7Om0";
122         TC idstr_tc[9];
123         W ret, idstr_len = strlen(idstr);
124         UW attr, attr1 = 0x01010101, attr2 = 0x10101010;
125         COLOR color, color1 = 0x10FF00FF, color2 = 0x1000FF00;
126         TEST_RESULT result = TEST_RESULT_PASS;
127
128         sjstotcs(idstr_tc, idstr);
129
130         ret = residhash_initialize(&residhash);
131         if (ret < 0) {
132                 printf("residhash_initialize fail\n");
133                 return TEST_RESULT_FAIL;
134         }
135         ret = residhash_adddata(&residhash, idstr_tc, idstr_len, attr1, color1);
136         if (ret < 0) {
137                 printf("residhash_adddata fail\n");
138                 result = TEST_RESULT_FAIL;
139         }
140         ret = residhash_adddata(&residhash, idstr_tc, idstr_len, attr2, color2);
141         if (ret < 0) {
142                 printf("residhash_adddata fail\n");
143                 result = TEST_RESULT_FAIL;
144         }
145         ret = residhash_searchdata(&residhash, idstr_tc, idstr_len, &attr, &color);
146         if (ret != RESIDHASH_SEARCHDATA_FOUND) {
147                 printf("residhash_searchdata fail\n");
148                 result = TEST_RESULT_FAIL;
149         }
150         if (attr != attr2) {
151                 printf("residhash_searchdata result fail\n");
152                 result = TEST_RESULT_FAIL;
153         }
154         if (color != color2) {
155                 printf("residhash_searchdata result fail\n");
156                 result = TEST_RESULT_FAIL;
157         }
158         residhash_finalize(&residhash);
159
160         return result;
161 }
162
163 LOCAL TEST_RESULT test_residhash_5()
164 {
165         residhash_t residhash;
166         UB idstr[] = "yZXmy7Om0";
167         TC idstr_tc[9];
168         W ret, idstr_len = strlen(idstr);
169         UW attr, attr1 = 0x01010101;
170         COLOR color, color1 = 0x10FF00FF;
171         TEST_RESULT result = TEST_RESULT_PASS;
172
173         sjstotcs(idstr_tc, idstr);
174
175         ret = residhash_initialize(&residhash);
176         if (ret < 0) {
177                 printf("residhash_initialize fail\n");
178                 return TEST_RESULT_FAIL;
179         }
180         ret = residhash_adddata(&residhash, idstr_tc, idstr_len, attr1, color1);
181         if (ret < 0) {
182                 printf("residhash_adddata fail\n");
183                 result = TEST_RESULT_FAIL;
184         }
185         residhash_removedata(&residhash, idstr_tc, idstr_len);
186         ret = residhash_searchdata(&residhash, idstr_tc, idstr_len, &attr, &color);
187         if (ret != RESIDHASH_SEARCHDATA_NOTFOUND) {
188                 printf("residhash_searchdata fail\n");
189                 result = TEST_RESULT_FAIL;
190         }
191         residhash_finalize(&residhash);
192
193         return result;
194 }
195
196 LOCAL TEST_RESULT test_residhash_6()
197 {
198         residhash_t residhash;
199         UB idstr[] = "yZXmy7Om0";
200         TC idstr_tc[9];
201         W ret, idstr_len = strlen(idstr);
202         TEST_RESULT result = TEST_RESULT_PASS;
203
204         sjstotcs(idstr_tc, idstr);
205
206         ret = residhash_initialize(&residhash);
207         if (ret < 0) {
208                 printf("residhash_initialize fail\n");
209                 return TEST_RESULT_FAIL;
210         }
211         residhash_removedata(&residhash, idstr_tc, idstr_len);
212         residhash_finalize(&residhash);
213
214         return result;
215 }
216
217 LOCAL TEST_RESULT test_residhash_7()
218 {
219         residhash_t residhash;
220         UB idstr1[] = "yZXmy7Om0", idstr2[] = "GCQJ44Ao";
221         TC idstr1_tc[9], idstr2_tc[8];
222         W ret, idstr1_len = strlen(idstr1), idstr2_len = strlen(idstr2);
223         UW attr, attr1 = 0x01010101, attr2 = 0x10101010;
224         COLOR color, color1 = 0x10FF00FF, color2 = 0x1000FF00;
225         TEST_RESULT result = TEST_RESULT_PASS;
226
227         sjstotcs(idstr1_tc, idstr1);
228         sjstotcs(idstr2_tc, idstr2);
229
230         ret = residhash_initialize(&residhash);
231         if (ret < 0) {
232                 printf("residhash_initialize fail\n");
233                 return TEST_RESULT_FAIL;
234         }
235         ret = residhash_adddata(&residhash, idstr1_tc, idstr1_len, attr1, color1);
236         if (ret < 0) {
237                 printf("residhash_adddata fail\n");
238                 result = TEST_RESULT_FAIL;
239         }
240         ret = residhash_adddata(&residhash, idstr2_tc, idstr2_len, attr2, color2);
241         if (ret < 0) {
242                 printf("residhash_adddata fail\n");
243                 result = TEST_RESULT_FAIL;
244         }
245         ret = residhash_searchdata(&residhash, idstr1_tc, idstr1_len, &attr, &color);
246         if (ret != RESIDHASH_SEARCHDATA_FOUND) {
247                 printf("residhash_searchdata 1 fail\n");
248                 result = TEST_RESULT_FAIL;
249         }
250         if (attr != attr1) {
251                 printf("residhash_searchdata 1 result fail\n");
252                 result = TEST_RESULT_FAIL;
253         }
254         if (color != color1) {
255                 printf("residhash_searchdata 1 result fail\n");
256                 result = TEST_RESULT_FAIL;
257         }
258         ret = residhash_searchdata(&residhash, idstr2_tc, idstr2_len, &attr, &color);
259         if (ret != RESIDHASH_SEARCHDATA_FOUND) {
260                 printf("residhash_searchdata fail\n");
261                 result = TEST_RESULT_FAIL;
262         }
263         if (attr != attr2) {
264                 printf("residhash_searchdata 2 result fail\n");
265                 result = TEST_RESULT_FAIL;
266         }
267         if (color != color2) {
268                 printf("residhash_searchdata 2 result fail\n");
269                 result = TEST_RESULT_FAIL;
270         }
271         residhash_finalize(&residhash);
272
273         return result;
274 }
275
276 LOCAL TEST_RESULT test_residhash_8()
277 {
278         residhash_t residhash;
279         residhash_iterator_t iterator;
280         TC *idstr;
281         W ret, num, idstr_len;
282         UW attr;
283         COLOR color;
284         Bool next;
285         TEST_RESULT result = TEST_RESULT_PASS;
286
287         ret = residhash_initialize(&residhash);
288         if (ret < 0) {
289                 printf("residhash_initialize fail\n");
290                 return TEST_RESULT_FAIL;
291         }
292
293
294         residhash_iterator_initialize(&iterator, &residhash);
295         num = 0;
296         for (;;) {
297                 next = residhash_iterator_next(&iterator, &idstr, &idstr_len, &attr, &color);
298                 if (next == False) {
299                         break;
300                 }
301                 num++;
302         }
303         if (num != 0) {
304                 printf("residhash_iterator unexpected length\n");
305                 result = TEST_RESULT_FAIL;
306         }
307         residhash_iterator_finalize(&iterator);
308
309
310         residhash_finalize(&residhash);
311
312         return result;
313 }
314
315 LOCAL TEST_RESULT test_residhash_9()
316 {
317         residhash_t residhash;
318         residhash_iterator_t iterator;
319         UB idstr1[] = "yZXmy7Om0";
320         TC idstr1_tc[9];
321         TC *idstr;
322         W ret, num, idstr_len, idstr1_len = strlen(idstr1);
323         UW attr, attr1 = 0x01010101;
324         COLOR color, color1 = 0x10FF00FF;
325         Bool next;
326         TEST_RESULT result = TEST_RESULT_PASS;
327
328         sjstotcs(idstr1_tc, idstr1);
329
330         ret = residhash_initialize(&residhash);
331         if (ret < 0) {
332                 printf("residhash_initialize fail\n");
333                 return TEST_RESULT_FAIL;
334         }
335         ret = residhash_adddata(&residhash, idstr1_tc, idstr1_len, attr1, color1);
336         if (ret < 0) {
337                 printf("residhash_adddata fail\n");
338                 result = TEST_RESULT_FAIL;
339         }
340
341
342         residhash_iterator_initialize(&iterator, &residhash);
343         num = 0;
344         for (;;) {
345                 next = residhash_iterator_next(&iterator, &idstr, &idstr_len, &attr, &color);
346                 if (next == False) {
347                         break;
348                 }
349                 num++;
350                 if ((idstr_len == idstr1_len)
351                         &&(tc_strncmp(idstr, idstr1_tc, idstr1_len) == 0)) {
352                         if (attr != attr1) {
353                                 result = TEST_RESULT_FAIL;
354                         }
355                         if (color != color1) {
356                                 result = TEST_RESULT_FAIL;
357                         }
358                 } else {
359                         result = TEST_RESULT_FAIL;
360                 }
361         }
362         if (num != 1) {
363                 printf("residhash_iterator unexpected length\n");
364                 result = TEST_RESULT_FAIL;
365         }
366         residhash_iterator_finalize(&iterator);
367
368
369         residhash_finalize(&residhash);
370
371         return result;
372 }
373
374 LOCAL TEST_RESULT test_residhash_10()
375 {
376         residhash_t residhash;
377         residhash_iterator_t iterator;
378         UB idstr1[] = "yZXmy7Om0", idstr2[] = "GCQJ44Ao";
379         TC idstr1_tc[9], idstr2_tc[8];
380         TC *idstr;
381         W ret, num, idstr_len, idstr1_len = strlen(idstr1), idstr2_len = strlen(idstr2);
382         UW attr, attr1 = 0x01010101, attr2 = 0x10101010;
383         COLOR color, color1 = 0x10FF00FF, color2 = 0x1000FF00;
384         Bool next;
385         TEST_RESULT result = TEST_RESULT_PASS;
386
387         sjstotcs(idstr1_tc, idstr1);
388         sjstotcs(idstr2_tc, idstr2);
389
390         ret = residhash_initialize(&residhash);
391         if (ret < 0) {
392                 printf("residhash_initialize fail\n");
393                 return TEST_RESULT_FAIL;
394         }
395         ret = residhash_adddata(&residhash, idstr1_tc, idstr1_len, attr1, color1);
396         if (ret < 0) {
397                 printf("residhash_adddata fail\n");
398                 result = TEST_RESULT_FAIL;
399         }
400         ret = residhash_adddata(&residhash, idstr2_tc, idstr2_len, attr2, color2);
401         if (ret < 0) {
402                 printf("residhash_adddata fail\n");
403                 result = TEST_RESULT_FAIL;
404         }
405
406
407         residhash_iterator_initialize(&iterator, &residhash);
408         num = 0;
409         for (;;) {
410                 next = residhash_iterator_next(&iterator, &idstr, &idstr_len, &attr, &color);
411                 if (next == False) {
412                         break;
413                 }
414                 num++;
415                 if ((idstr_len == idstr1_len)
416                         &&(tc_strncmp(idstr, idstr1_tc, idstr1_len) == 0)) {
417                         if (attr != attr1) {
418                                 result = TEST_RESULT_FAIL;
419                         }
420                         if (color != color1) {
421                                 result = TEST_RESULT_FAIL;
422                         }
423                 } else if ((idstr_len == idstr2_len)
424                                    &&(tc_strncmp(idstr, idstr2_tc, idstr2_len) == 0)) {
425                         if (attr != attr2) {
426                                 result = TEST_RESULT_FAIL;
427                         }
428                         if (color != color2) {
429                                 result = TEST_RESULT_FAIL;
430                         }
431                 } else {
432                         result = TEST_RESULT_FAIL;
433                 }
434         }
435         if (num != 2) {
436                 printf("residhash_iterator unexpected length\n");
437                 result = TEST_RESULT_FAIL;
438         }
439         residhash_iterator_finalize(&iterator);
440
441
442         residhash_finalize(&residhash);
443
444         return result;
445 }
446
447 LOCAL VOID test_residhash_printresult(TEST_RESULT (*proc)(), B *test_name)
448 {
449         TEST_RESULT result;
450
451         printf("test_residhash: %s\n", test_name);
452         printf("---------------------------------------------\n");
453         result = proc();
454         if (result == TEST_RESULT_PASS) {
455                 printf("--pass---------------------------------------\n");
456         } else {
457                 printf("--fail---------------------------------------\n");
458         }
459         printf("---------------------------------------------\n");
460 }
461
462 EXPORT VOID test_residhash_main()
463 {
464         test_residhash_printresult(test_residhash_1, "test_residhash_1");
465         test_residhash_printresult(test_residhash_2, "test_residhash_2");
466         test_residhash_printresult(test_residhash_3, "test_residhash_3");
467         test_residhash_printresult(test_residhash_4, "test_residhash_4");
468         test_residhash_printresult(test_residhash_5, "test_residhash_5");
469         test_residhash_printresult(test_residhash_6, "test_residhash_6");
470         test_residhash_printresult(test_residhash_7, "test_residhash_7");
471         test_residhash_printresult(test_residhash_8, "test_residhash_8");
472         test_residhash_printresult(test_residhash_9, "test_residhash_9");
473         test_residhash_printresult(test_residhash_10, "test_residhash_10");
474 }