4 * Copyright (c) 2009-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>
37 LOCAL UB test_cache_testdata_01[] = {
38 0x81, 0xa0, 0x81, 0xa0, 0x81, 0xa0, 0x81, 0xa0,
39 0x28, 0x83, 0x6c, 0x81, 0x5b, 0x83, 0x80, 0x96,
40 0xb3, 0x82, 0xb5, 0x29, 0x3c, 0x3e, 0x3c, 0x3e,
41 0x32, 0x30, 0x30, 0x39, 0x2f, 0x31, 0x30, 0x2f,
42 0x31, 0x36, 0x28, 0x8b, 0xe0, 0x29, 0x20, 0x32,
43 0x31, 0x3a, 0x32, 0x38, 0x3a, 0x34, 0x31, 0x20,
44 0x3c, 0x3e, 0x20, 0x61, 0x62, 0x63, 0x20, 0x3c,
45 0x62, 0x72, 0x3e, 0x20, 0x78, 0x79, 0x7a, 0x20,
46 0x3c, 0x3e, 0x82, 0xbd, 0x82, 0xa2, 0x82, 0xc6,
47 0x82, 0xe9, 0x0a, 0x81, 0xa0, 0x81, 0xa0, 0x81,
48 0xa0, 0x81, 0xa0, 0x28, 0x83, 0x6c, 0x81, 0x5b,
49 0x83, 0x80, 0x96, 0xb3, 0x82, 0xb5, 0x29, 0x3c,
50 0x3e, 0x3c, 0x3e, 0x32, 0x30, 0x30, 0x39, 0x2f,
51 0x31, 0x30, 0x2f, 0x31, 0x36, 0x28, 0x8b, 0xe0,
52 0x29, 0x20, 0x32, 0x32, 0x3a, 0x31, 0x39, 0x3a,
53 0x34, 0x36, 0x20, 0x3c, 0x3e, 0x20, 0x3c, 0x61,
54 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, 0x2e,
55 0x2e, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x72,
56 0x65, 0x61, 0x64, 0x2e, 0x63, 0x67, 0x69, 0x2f,
57 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x2f, 0x78, 0x78,
58 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
59 0x2f, 0x31, 0x22, 0x20, 0x74, 0x61, 0x72, 0x67,
60 0x65, 0x74, 0x3d, 0x22, 0x5f, 0x62, 0x6c, 0x61,
61 0x6e, 0x6b, 0x22, 0x3e, 0x26, 0x67, 0x74, 0x3b,
62 0x26, 0x67, 0x74, 0x3b, 0x31, 0x3c, 0x2f, 0x61,
63 0x3e, 0x20, 0x3c, 0x3e, 0x0a, 0x81, 0xa0, 0x81,
64 0xa0, 0x81, 0xa0, 0x81, 0xa0, 0x28, 0x83, 0x6c,
65 0x81, 0x5b, 0x83, 0x80, 0x96, 0xb3, 0x82, 0xb5,
66 0x29, 0x3c, 0x3e, 0x3c, 0x3e, 0x32, 0x30, 0x30,
67 0x39, 0x2f, 0x31, 0x30, 0x2f, 0x31, 0x36, 0x28,
68 0x8b, 0xe0, 0x29, 0x20, 0x32, 0x32, 0x3a, 0x32,
69 0x34, 0x3a, 0x35, 0x37, 0x20, 0x3c, 0x3e, 0x20,
70 0x3c, 0x62, 0x72, 0x3e, 0x20, 0x20, 0x3c, 0x62,
71 0x72, 0x3e, 0x20, 0x20, 0x3c, 0x62, 0x72, 0x3e,
72 0x20, 0x3c, 0x3e, 0x0a, 0x81, 0xa0, 0x81, 0xa0,
73 0x81, 0xa0, 0x81, 0xa0, 0x28, 0x83, 0x6c, 0x81,
74 0x5b, 0x83, 0x80, 0x96, 0xb3, 0x82, 0xb5, 0x29,
75 0x3c, 0x3e, 0x73, 0x61, 0x67, 0x65, 0x3c, 0x3e,
76 0x32, 0x30, 0x30, 0x39, 0x2f, 0x31, 0x30, 0x2f,
77 0x31, 0x36, 0x28, 0x8b, 0xe0, 0x29, 0x20, 0x32,
78 0x32, 0x3a, 0x33, 0x32, 0x3a, 0x31, 0x36, 0x20,
79 0x3c, 0x3e, 0x20, 0x83, 0x58, 0x83, 0x8c, 0x82,
80 0xbd, 0x82, 0xc1, 0x82, 0xbd, 0x82, 0xcc, 0x82,
81 0xa9, 0x82, 0x97, 0x20, 0x3c, 0x62, 0x72, 0x3e,
82 0x20, 0x20, 0x3c, 0x62, 0x72, 0x3e, 0x20, 0x3c,
83 0x3e, 0x0a, 0x81, 0xa0, 0x81, 0xa0, 0x81, 0xa0,
84 0x81, 0xa0, 0x28, 0x83, 0x6c, 0x81, 0x5b, 0x83,
85 0x80, 0x96, 0xb3, 0x82, 0xb5, 0x29, 0x3c, 0x3e,
86 0x73, 0x61, 0x67, 0x65, 0x3c, 0x3e, 0x32, 0x30,
87 0x30, 0x39, 0x2f, 0x31, 0x30, 0x2f, 0x31, 0x37,
88 0x28, 0x93, 0x79, 0x29, 0x20, 0x30, 0x34, 0x3a,
89 0x34, 0x38, 0x3a, 0x31, 0x39, 0x20, 0x3c, 0x3e,
90 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x74, 0x65,
91 0x73, 0x74, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20,
92 0x3c, 0x3e, 0x0a, 0x00
95 LOCAL W test_parser_util_gen_file(LINK *lnk, VID *nvid)
99 TC name[] = {TK_t, TNULL};
103 0x10000000, 0x10000000, 0x10FFFFFF, 0x10FFFFFF,
107 err = get_lnk(NULL, &lnk0, F_NORM);
111 err = cre_fil(&lnk0, name, NULL, 0, F_FLOAT);
116 err = oreg_vob((VLINK*)&lnk0, (VP)&vseg, -1, V_NODISP);
119 del_fil(NULL, &lnk0, 0);
129 LOCAL TEST_RESULT test_parser_1()
136 datparser_res_t *res = NULL;
137 TEST_RESULT result = TEST_RESULT_PASS;
139 fd = test_parser_util_gen_file(&test_lnk, &vid);
141 return TEST_RESULT_FAIL;
145 cache = datcache_new(vid);
146 datcache_appenddata(cache, test_cache_testdata_01, strlen(test_cache_testdata_01));
148 parser = datparser_new(cache);
151 err = datparser_getnextres(parser, &res);
156 if (res->name != NULL) {
157 printf("name:\n%S\n", res->name);
159 if (res->mail != NULL) {
160 printf("mail:\n%S\n", res->mail);
162 if (res->date != NULL) {
163 printf("date:\n%S\n", res->date);
165 if (res->body != NULL) {
166 printf("body:\n%S\n", res->body);
168 if (res->title != NULL) {
169 printf("title:\n%S\n", res->title);
171 datparser_res_delete(res);
177 datparser_delete(parser);
179 datcache_delete(cache);
181 err = odel_vob(vid, 0);
183 printf("error odel_vob:%d\n", err >> 16);
184 result = TEST_RESULT_FAIL;
186 err = del_fil(NULL, &test_lnk, 0);
188 printf("error del_fil:%d\n", err >> 16);
189 result = TEST_RESULT_FAIL;
195 LOCAL UB test_parser_testdata_02[] = {
196 0x6e, 0x61, 0x6d, 0x65, 0x3c, 0x3e, 0x6d, 0x61,
197 0x69, 0x6c, 0x3c, 0x3e, 0x64, 0x61, 0x74, 0x65,
198 0x3c, 0x3e, 0x6d, 0x73, 0x67, 0x3c, 0x3e, 0x26,
199 0x0a, 0x26, 0x3c, 0x3e, 0x3c, 0x3e, 0x3c, 0x3e,
200 0x3c, 0x3e, 0x0a, 0x3c, 0x3e, 0x26, 0x3c, 0x3e,
201 0x3c, 0x3e, 0x3c, 0x3e, 0x0a, 0x3c, 0x3e, 0x3c,
202 0x3e, 0x26, 0x3c, 0x3e, 0x3c, 0x3e, 0x0a, 0x3c,
203 0x3e, 0x3c, 0x3e, 0x3c, 0x3e, 0x26, 0x3c, 0x3e,
204 0x0a, 0x3c, 0x3e, 0x3c, 0x3e, 0x3c, 0x3e, 0x20,
205 0x26, 0x3c, 0x62, 0x72, 0x3e, 0x20, 0x3c, 0x3e,
206 0x0a, 0x3c, 0x3e, 0x3c, 0x3e, 0x3c, 0x3e, 0x20,
207 0x26, 0x3c, 0x61, 0x3e, 0x20, 0x26, 0x3c, 0x2f,
208 0x61, 0x3e, 0x20, 0x3c, 0x3e, 0x0a, 0x3c, 0x3e,
209 0x3c, 0x3e, 0x3c, 0x3e, 0x20, 0x26, 0x61, 0x6d,
210 0x70, 0x3b, 0x20, 0x3c, 0x3e, 0x0a, 0x3c, 0x3e,
211 0x3c, 0x3e, 0x3c, 0x3e, 0x20, 0x26, 0x61, 0x61,
212 0x61, 0x20, 0x3c, 0x3e, 0x0a, 0x3c, 0x3e, 0x3c,
213 0x3e, 0x26, 0x71, 0x75, 0x6f, 0x74, 0x3b, 0x20,
214 0x3c, 0x3e, 0x3c, 0x3e, 0x0a, 0x3c, 0x3e, 0x3c,
215 0x3e, 0x3c, 0x3e, 0x20, 0x26, 0x6c, 0x74, 0x3b,
216 0x20, 0x3c, 0x3e, 0x0a, 0x3c, 0x3e, 0x3c, 0x3e,
217 0x3c, 0x3e, 0x26, 0x3c, 0x3e, 0x0a, 0x3c, 0x3e,
218 0x3c, 0x3e, 0x3c, 0x3e, 0x3c, 0x3e, 0x0a, 0x3c,
219 0x3e, 0x3c, 0x3e, 0x3c, 0x3e, 0x3b, 0x3c, 0x3e,
223 LOCAL TEST_RESULT test_parser_2()
230 datparser_res_t *res = NULL;
231 TEST_RESULT result = TEST_RESULT_PASS;
233 fd = test_parser_util_gen_file(&test_lnk, &vid);
235 return TEST_RESULT_FAIL;
239 cache = datcache_new(vid);
240 datcache_appenddata(cache, test_parser_testdata_02, strlen(test_parser_testdata_02));
242 parser = datparser_new(cache);
246 err = datparser_getnextres(parser, &res);
252 datparser_res_delete(res);
259 printf("res total number is fail\n");
260 result = TEST_RESULT_FAIL;
263 datparser_delete(parser);
265 datcache_delete(cache);
267 err = odel_vob(vid, 0);
269 printf("error odel_vob:%d\n", err >> 16);
270 result = TEST_RESULT_FAIL;
272 err = del_fil(NULL, &test_lnk, 0);
274 printf("error del_fil:%d\n", err >> 16);
275 result = TEST_RESULT_FAIL;
281 LOCAL VOID test_parser_printresult(TEST_RESULT (*proc)(), B *test_name)
285 printf("test_parser: %s\n", test_name);
286 printf("---------------------------------------------\n");
288 if (result == TEST_RESULT_PASS) {
289 printf("--pass---------------------------------------\n");
291 printf("--fail---------------------------------------\n");
293 printf("---------------------------------------------\n");
296 EXPORT VOID test_parser_main()
298 test_parser_printresult(test_parser_1, "test_parser_1");
299 test_parser_printresult(test_parser_2, "test_parser_2");