4 * Copyright (c) 2011 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
32 #include "tadsearch.h"
34 LOCAL TC test_tadsearch_testdata01[] = {TK_A, TK_B, TK_C, TNULL};
35 LOCAL TC test_tadsearch_testdata02[] = {TK_B, TK_C, TK_D, TNULL};
36 LOCAL TC test_tadsearch_testdata03[] = {TK_E, TK_F, TK_G, TK_E, TNULL};
37 LOCAL TC test_tadsearch_testdata04[] = {TK_a, TK_b, TK_c, TK_d, TK_e, TNULL};
38 LOCAL TC test_tadsearch_testdata05[] = {TK_a, TK_b, TK_A, TK_B, TK_C, TNULL};
40 LOCAL TEST_RESULT test_tadsearch_1()
43 tadlib_rk_result_t result;
46 set[0].buffer = test_tadsearch_testdata01;
48 set[1].buffer = test_tadsearch_testdata02;
50 set[2].buffer = test_tadsearch_testdata03;
53 err = tadlib_rabinkarpsearch(test_tadsearch_testdata05, 5, set, 3, &result);
55 printf("return value failure: %d\n", err);
56 return TEST_RESULT_FAIL;
59 printf("result failure: %d\n", result.i);
60 return TEST_RESULT_FAIL;
63 return TEST_RESULT_PASS;
66 LOCAL TEST_RESULT test_tadsearch_2()
69 tadlib_rk_result_t result;
72 set[0].buffer = test_tadsearch_testdata01;
74 set[1].buffer = test_tadsearch_testdata02;
76 set[2].buffer = test_tadsearch_testdata03;
79 err = tadlib_rabinkarpsearch(test_tadsearch_testdata04, 5, set, 3, &result);
81 printf("return value failure: %d\n", err);
82 return TEST_RESULT_FAIL;
85 return TEST_RESULT_PASS;
88 LOCAL TEST_RESULT test_tadsearch_3()
91 tadlib_rk_result_t result;
94 set[0].buffer = test_tadsearch_testdata01;
97 err = tadlib_rabinkarpsearch(test_tadsearch_testdata05, 5, set, 1, &result);
99 printf("return value failure: %d\n", err);
100 return TEST_RESULT_FAIL;
103 printf("result failure: %d\n", result.i);
104 return TEST_RESULT_FAIL;
107 return TEST_RESULT_PASS;
110 LOCAL VOID test_tadsearch_printresult(TEST_RESULT (*proc)(), B *test_name)
114 printf("test_tadsearch: %s\n", test_name);
115 printf("---------------------------------------------\n");
117 if (result == TEST_RESULT_PASS) {
118 printf("--pass---------------------------------------\n");
120 printf("--fail---------------------------------------\n");
122 printf("---------------------------------------------\n");
125 EXPORT VOID test_tadsearch_main()
127 test_tadsearch_printresult(test_tadsearch_1, "test_tadsearch_1");
128 test_tadsearch_printresult(test_tadsearch_2, "test_tadsearch_2");
129 test_tadsearch_printresult(test_tadsearch_3, "test_tadsearch_3");