4 * Copyright (c) 2010 project bchan
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.
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:
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.
19 * 2. Altered source versions must be plainly marked as such, and must not be
20 * misrepresented as being the original software.
22 * 3. This notice may not be removed or altered from any source
27 #include <btron/btron.h>
34 #include "residhash.h"
36 LOCAL TEST_RESULT test_residhash_1()
38 residhash_t residhash;
41 ret = residhash_initialize(&residhash);
43 printf("residhash_initialize fail\n");
44 return TEST_RESULT_FAIL;
46 residhash_finalize(&residhash);
48 return TEST_RESULT_PASS;
51 LOCAL TEST_RESULT test_residhash_2()
53 residhash_t residhash;
54 UB idstr[] = "yZXmy7Om0";
56 W ret, idstr_len = strlen(idstr);
59 TEST_RESULT result = TEST_RESULT_PASS;
61 sjstotcs(idstr_tc, idstr);
63 ret = residhash_initialize(&residhash);
65 printf("residhash_initialize fail\n");
66 return TEST_RESULT_FAIL;
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;
73 residhash_finalize(&residhash);
78 LOCAL TEST_RESULT test_residhash_3()
80 residhash_t residhash;
81 UB idstr[] = "yZXmy7Om0";
83 W ret, idstr_len = strlen(idstr);
84 UW attr, attr1 = 0x01010101;
85 COLOR color, color1 = 0x10FF00FF;
86 TEST_RESULT result = TEST_RESULT_PASS;
88 sjstotcs(idstr_tc, idstr);
90 ret = residhash_initialize(&residhash);
92 printf("residhash_initialize fail\n");
93 return TEST_RESULT_FAIL;
95 ret = residhash_adddata(&residhash, idstr_tc, idstr_len, attr1, color1);
97 printf("residhash_adddata fail\n");
98 result = TEST_RESULT_FAIL;
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;
106 printf("residhash_searchdata result fail\n");
107 result = TEST_RESULT_FAIL;
109 if (color != color1) {
110 printf("residhash_searchdata result fail\n");
111 result = TEST_RESULT_FAIL;
113 residhash_finalize(&residhash);
118 LOCAL TEST_RESULT test_residhash_4()
120 residhash_t residhash;
121 UB idstr[] = "yZXmy7Om0";
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;
128 sjstotcs(idstr_tc, idstr);
130 ret = residhash_initialize(&residhash);
132 printf("residhash_initialize fail\n");
133 return TEST_RESULT_FAIL;
135 ret = residhash_adddata(&residhash, idstr_tc, idstr_len, attr1, color1);
137 printf("residhash_adddata fail\n");
138 result = TEST_RESULT_FAIL;
140 ret = residhash_adddata(&residhash, idstr_tc, idstr_len, attr2, color2);
142 printf("residhash_adddata fail\n");
143 result = TEST_RESULT_FAIL;
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;
151 printf("residhash_searchdata result fail\n");
152 result = TEST_RESULT_FAIL;
154 if (color != color2) {
155 printf("residhash_searchdata result fail\n");
156 result = TEST_RESULT_FAIL;
158 residhash_finalize(&residhash);
163 LOCAL TEST_RESULT test_residhash_5()
165 residhash_t residhash;
166 UB idstr[] = "yZXmy7Om0";
168 W ret, idstr_len = strlen(idstr);
169 UW attr, attr1 = 0x01010101;
170 COLOR color, color1 = 0x10FF00FF;
171 TEST_RESULT result = TEST_RESULT_PASS;
173 sjstotcs(idstr_tc, idstr);
175 ret = residhash_initialize(&residhash);
177 printf("residhash_initialize fail\n");
178 return TEST_RESULT_FAIL;
180 ret = residhash_adddata(&residhash, idstr_tc, idstr_len, attr1, color1);
182 printf("residhash_adddata fail\n");
183 result = TEST_RESULT_FAIL;
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;
191 residhash_finalize(&residhash);
196 LOCAL TEST_RESULT test_residhash_6()
198 residhash_t residhash;
199 UB idstr[] = "yZXmy7Om0";
201 W ret, idstr_len = strlen(idstr);
202 TEST_RESULT result = TEST_RESULT_PASS;
204 sjstotcs(idstr_tc, idstr);
206 ret = residhash_initialize(&residhash);
208 printf("residhash_initialize fail\n");
209 return TEST_RESULT_FAIL;
211 residhash_removedata(&residhash, idstr_tc, idstr_len);
212 residhash_finalize(&residhash);
217 LOCAL TEST_RESULT test_residhash_7()
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;
227 sjstotcs(idstr1_tc, idstr1);
228 sjstotcs(idstr2_tc, idstr2);
230 ret = residhash_initialize(&residhash);
232 printf("residhash_initialize fail\n");
233 return TEST_RESULT_FAIL;
235 ret = residhash_adddata(&residhash, idstr1_tc, idstr1_len, attr1, color1);
237 printf("residhash_adddata fail\n");
238 result = TEST_RESULT_FAIL;
240 ret = residhash_adddata(&residhash, idstr2_tc, idstr2_len, attr2, color2);
242 printf("residhash_adddata fail\n");
243 result = TEST_RESULT_FAIL;
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;
251 printf("residhash_searchdata 1 result fail\n");
252 result = TEST_RESULT_FAIL;
254 if (color != color1) {
255 printf("residhash_searchdata 1 result fail\n");
256 result = TEST_RESULT_FAIL;
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;
264 printf("residhash_searchdata 2 result fail\n");
265 result = TEST_RESULT_FAIL;
267 if (color != color2) {
268 printf("residhash_searchdata 2 result fail\n");
269 result = TEST_RESULT_FAIL;
271 residhash_finalize(&residhash);
276 LOCAL TEST_RESULT test_residhash_8()
278 residhash_t residhash;
279 residhash_iterator_t iterator;
281 W ret, num, idstr_len;
285 TEST_RESULT result = TEST_RESULT_PASS;
287 ret = residhash_initialize(&residhash);
289 printf("residhash_initialize fail\n");
290 return TEST_RESULT_FAIL;
294 residhash_iterator_initialize(&iterator, &residhash);
297 next = residhash_iterator_next(&iterator, &idstr, &idstr_len, &attr, &color);
304 printf("residhash_iterator unexpected length\n");
305 result = TEST_RESULT_FAIL;
307 residhash_iterator_finalize(&iterator);
310 residhash_finalize(&residhash);
315 LOCAL TEST_RESULT test_residhash_9()
317 residhash_t residhash;
318 residhash_iterator_t iterator;
319 UB idstr1[] = "yZXmy7Om0";
322 W ret, num, idstr_len, idstr1_len = strlen(idstr1);
323 UW attr, attr1 = 0x01010101;
324 COLOR color, color1 = 0x10FF00FF;
326 TEST_RESULT result = TEST_RESULT_PASS;
328 sjstotcs(idstr1_tc, idstr1);
330 ret = residhash_initialize(&residhash);
332 printf("residhash_initialize fail\n");
333 return TEST_RESULT_FAIL;
335 ret = residhash_adddata(&residhash, idstr1_tc, idstr1_len, attr1, color1);
337 printf("residhash_adddata fail\n");
338 result = TEST_RESULT_FAIL;
342 residhash_iterator_initialize(&iterator, &residhash);
345 next = residhash_iterator_next(&iterator, &idstr, &idstr_len, &attr, &color);
350 if ((idstr_len == idstr1_len)
351 &&(tc_strncmp(idstr, idstr1_tc, idstr1_len) == 0)) {
353 result = TEST_RESULT_FAIL;
355 if (color != color1) {
356 result = TEST_RESULT_FAIL;
359 result = TEST_RESULT_FAIL;
363 printf("residhash_iterator unexpected length\n");
364 result = TEST_RESULT_FAIL;
366 residhash_iterator_finalize(&iterator);
369 residhash_finalize(&residhash);
374 LOCAL TEST_RESULT test_residhash_10()
376 residhash_t residhash;
377 residhash_iterator_t iterator;
378 UB idstr1[] = "yZXmy7Om0", idstr2[] = "GCQJ44Ao";
379 TC idstr1_tc[9], idstr2_tc[8];
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;
385 TEST_RESULT result = TEST_RESULT_PASS;
387 sjstotcs(idstr1_tc, idstr1);
388 sjstotcs(idstr2_tc, idstr2);
390 ret = residhash_initialize(&residhash);
392 printf("residhash_initialize fail\n");
393 return TEST_RESULT_FAIL;
395 ret = residhash_adddata(&residhash, idstr1_tc, idstr1_len, attr1, color1);
397 printf("residhash_adddata fail\n");
398 result = TEST_RESULT_FAIL;
400 ret = residhash_adddata(&residhash, idstr2_tc, idstr2_len, attr2, color2);
402 printf("residhash_adddata fail\n");
403 result = TEST_RESULT_FAIL;
407 residhash_iterator_initialize(&iterator, &residhash);
410 next = residhash_iterator_next(&iterator, &idstr, &idstr_len, &attr, &color);
415 if ((idstr_len == idstr1_len)
416 &&(tc_strncmp(idstr, idstr1_tc, idstr1_len) == 0)) {
418 result = TEST_RESULT_FAIL;
420 if (color != color1) {
421 result = TEST_RESULT_FAIL;
423 } else if ((idstr_len == idstr2_len)
424 &&(tc_strncmp(idstr, idstr2_tc, idstr2_len) == 0)) {
426 result = TEST_RESULT_FAIL;
428 if (color != color2) {
429 result = TEST_RESULT_FAIL;
432 result = TEST_RESULT_FAIL;
436 printf("residhash_iterator unexpected length\n");
437 result = TEST_RESULT_FAIL;
439 residhash_iterator_finalize(&iterator);
442 residhash_finalize(&residhash);
447 LOCAL VOID test_residhash_printresult(TEST_RESULT (*proc)(), B *test_name)
451 printf("test_residhash: %s\n", test_name);
452 printf("---------------------------------------------\n");
454 if (result == TEST_RESULT_PASS) {
455 printf("--pass---------------------------------------\n");
457 printf("--fail---------------------------------------\n");
459 printf("---------------------------------------------\n");
462 EXPORT VOID test_residhash_main()
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");