OSDN Git Service

disable press number action when NG by word.
[bbk/bchan.git] / src / test_parser.c
1 /*
2  * test_parser.c
3  *
4  * Copyright (c) 2009-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        <tcode.h>
29 #include    <bstdio.h>
30 #include    <bstring.h>
31
32 #include    "test.h"
33
34 #include    "parser.h"
35 #include    "cache.h"
36
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
93 };
94
95 LOCAL W test_parser_util_gen_file(LINK *lnk, VID *nvid)
96 {
97         LINK lnk0;
98         W fd, err;
99         TC name[] = {TK_t, TNULL};
100         VOBJSEG vseg = {
101                 {{0,0,100,20}},
102                 16, 16,
103                 0x10000000, 0x10000000, 0x10FFFFFF, 0x10FFFFFF,
104                 0
105         };
106
107         err = get_lnk(NULL, &lnk0, F_NORM);
108         if (err < 0) {
109                 return err;
110         }
111         err = cre_fil(&lnk0, name, NULL, 0, F_FLOAT);
112         if (err < 0) {
113                 return err;
114         }
115         fd = err;
116         err = oreg_vob((VLINK*)&lnk0, (VP)&vseg, -1, V_NODISP);
117         if (err < 0) {
118                 cls_fil(fd);
119                 del_fil(NULL, &lnk0, 0);
120                 return err;
121         }
122
123         *lnk = lnk0;
124         *nvid = err;
125
126         return fd;
127 }
128
129 LOCAL TEST_RESULT test_parser_1()
130 {
131         LINK test_lnk;
132         W fd, err;
133         VID vid;
134         datcache_t *cache;
135         datparser_t *parser;
136         datparser_res_t *res = NULL;
137         TEST_RESULT result = TEST_RESULT_PASS;
138
139         fd = test_parser_util_gen_file(&test_lnk, &vid);
140         if (fd < 0) {
141                 return TEST_RESULT_FAIL;
142         }
143         cls_fil(fd);
144
145         cache = datcache_new(vid);
146         datcache_appenddata(cache, test_cache_testdata_01, strlen(test_cache_testdata_01));
147
148         parser = datparser_new(cache);
149
150         for (;;) {
151                 err = datparser_getnextres(parser, &res);
152                 if (err != 1) {
153                         break;
154                 }
155                 if (res != NULL) {
156                         if (res->name != NULL) {
157                                 printf("name:\n%S\n", res->name);
158                         }
159                         if (res->mail != NULL) {
160                                 printf("mail:\n%S\n", res->mail);
161                         }
162                         if (res->date != NULL) {
163                                 printf("date:\n%S\n", res->date);
164                         }
165                         if (res->body != NULL) {
166                                 printf("body:\n%S\n", res->body);
167                         }
168                         if (res->title != NULL) {
169                                 printf("title:\n%S\n", res->title);
170                         }
171                         datparser_res_delete(res);
172                 } else {
173                         break;
174                 }
175         }
176
177         datparser_delete(parser);
178
179         datcache_delete(cache);
180
181         err = odel_vob(vid, 0);
182         if (err < 0) {
183                 printf("error odel_vob:%d\n", err >> 16);
184                 result = TEST_RESULT_FAIL;
185         }
186         err = del_fil(NULL, &test_lnk, 0);
187         if (err < 0) {
188                 printf("error del_fil:%d\n", err >> 16);
189                 result = TEST_RESULT_FAIL;
190         }
191
192         return result;
193 }
194
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,
220         0x0a, 0x00
221 };
222
223 LOCAL TEST_RESULT test_parser_2()
224 {
225         LINK test_lnk;
226         W fd, err, num;
227         VID vid;
228         datcache_t *cache;
229         datparser_t *parser;
230         datparser_res_t *res = NULL;
231         TEST_RESULT result = TEST_RESULT_PASS;
232
233         fd = test_parser_util_gen_file(&test_lnk, &vid);
234         if (fd < 0) {
235                 return TEST_RESULT_FAIL;
236         }
237         cls_fil(fd);
238
239         cache = datcache_new(vid);
240         datcache_appenddata(cache, test_parser_testdata_02, strlen(test_parser_testdata_02));
241
242         parser = datparser_new(cache);
243
244         num = 0;
245         for (;;) {
246                 err = datparser_getnextres(parser, &res);
247                 if (err != 1) {
248                         break;
249                 }
250                 if (res != NULL) {
251                         num++;
252                         datparser_res_delete(res);
253                 } else {
254                         break;
255                 }
256         }
257
258         if (num != 14) {
259                 printf("res total number is fail\n");
260                 result = TEST_RESULT_FAIL;
261         }
262
263         datparser_delete(parser);
264
265         datcache_delete(cache);
266
267         err = odel_vob(vid, 0);
268         if (err < 0) {
269                 printf("error odel_vob:%d\n", err >> 16);
270                 result = TEST_RESULT_FAIL;
271         }
272         err = del_fil(NULL, &test_lnk, 0);
273         if (err < 0) {
274                 printf("error del_fil:%d\n", err >> 16);
275                 result = TEST_RESULT_FAIL;
276         }
277
278         return result;
279 }
280
281 LOCAL VOID test_parser_printresult(TEST_RESULT (*proc)(), B *test_name)
282 {
283         TEST_RESULT result;
284
285         printf("test_parser: %s\n", test_name);
286         printf("---------------------------------------------\n");
287         result = proc();
288         if (result == TEST_RESULT_PASS) {
289                 printf("--pass---------------------------------------\n");
290         } else {
291                 printf("--fail---------------------------------------\n");
292         }
293         printf("---------------------------------------------\n");
294 }
295
296 EXPORT VOID test_parser_main()
297 {
298         test_parser_printresult(test_parser_1, "test_parser_1");
299         test_parser_printresult(test_parser_2, "test_parser_2");
300 }