4 * Copyright (c) 2010-2012 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
29 #include "bbsmenufilter.h"
33 #include <unittest_driver.h>
35 #include "bbsmenuparser.h"
36 #include "bbsmenucache.h"
38 LOCAL UB test_bbsmnfilter_testdata_01[] = {
42 <TITLE>BBS MENU for test</TITLE>
49 <A HREF=http://xxx.2ch.net/AAA/>AAA</A>
51 <BR><BR><B>Cat 1</B><BR>
52 <A HREF=http://xxx.2ch.net/BBB/>BBB</A><br>
53 <A HREF=http://yyy.2ch.net/CCC/>CCC</A><br>
54 <A HREF=http://yyy.2ch.net/DDD/>DDD</A><br>
55 <A HREF=http://yyy.2ch.net/EEE/>EEE</A>
57 <BR><BR><B>Cat 2</B><BR>
58 <A HREF=http://xxx.2ch.net/FFF/>FFF</A><br>
59 <A HREF=http://xxx.2ch.net/GGG/>GGG</A><br>
60 <A HREF=http://xxx.2ch.net/HHH/>HHH</A><br>
61 <A HREF=http://xxx.2ch.net/III/>III</A><br>
63 <BR><BR><B>Cat 3</B><BR>
64 <A HREF=http://xxx.2ch.net/>other</A><br>
65 <A HREF=http://yyy.2ch.net/>other2</A><br>
66 <A HREF=http://zzz.2ch.net/zzz/zzz.php>other3</A><br>
68 <BR><BR><B>Cat 4</B><BR>
69 <A HREF=http://www.chokanji.com/ TARGET=_blank>ck4</A><br>
70 <A HREF=http://www.parsonal-media.co.jp/ TARGET=_blank>ck4</A><br>
75 LOCAL UNITTEST_RESULT test_bbsmnfilter_1()
79 bbsmnparser_t *parser;
80 bbsmnparser_item_t *item = NULL;
81 bbsmnfilter_t *filter = NULL;
82 UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
84 cache = bbsmncache_new();
85 bbsmncache_appenddata(cache, test_bbsmnfilter_testdata_01, strlen(test_bbsmnfilter_testdata_01));
86 parser = bbsmnparser_new(cache);
88 filter = bbsmnfilter_new();
91 err = bbsmnparser_getnextitem(parser, &item);
95 bbsmnfilter_inputitem(filter, item);
97 ret = bbsmnfilter_outputitem(filter, &item);
99 if (item->category != NULL) {
100 printf("category:\n%S\n", item->category);
102 if (item->url != NULL) {
103 printf("url:\n%s\n", item->url);
105 if (item->title != NULL) {
106 printf("title:\n%S\n", item->title);
108 bbsmnparser_item_delete(item);
112 if (ret != BBSMNFILTER_OUTPUTITEM_CONTINUE) {
118 bbsmnfilter_delete(filter);
120 bbsmnparser_delete(parser);
121 bbsmncache_delete(cache);
126 LOCAL UNITTEST_RESULT test_bbsmnfilter_2_checkitem_index(bbsmnparser_item_t *item, W i)
131 if (item->category == NULL) {
132 return UNITTEST_RESULT_FAIL;
143 if ((item->category != NULL)||(item->url == NULL)||(item->title == NULL)) {
144 return UNITTEST_RESULT_FAIL;
148 return UNITTEST_RESULT_FAIL;
151 return UNITTEST_RESULT_PASS;
154 LOCAL UNITTEST_RESULT test_bbsmnfilter_2()
158 bbsmnparser_t *parser;
159 bbsmnparser_item_t *item = NULL;
160 bbsmnfilter_t *filter = NULL;
161 UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
163 cache = bbsmncache_new();
164 bbsmncache_appenddata(cache, test_bbsmnfilter_testdata_01, strlen(test_bbsmnfilter_testdata_01));
165 parser = bbsmnparser_new(cache);
167 filter = bbsmnfilter_new();
170 err = bbsmnparser_getnextitem(parser, &item);
174 bbsmnfilter_inputitem(filter, item);
176 ret = bbsmnfilter_outputitem(filter, &item);
178 result = test_bbsmnfilter_2_checkitem_index(item, i);
180 bbsmnparser_item_delete(item);
182 if (result == UNITTEST_RESULT_FAIL) {
183 printf("fail i = %d\n", i-1);
187 if ((ret != BBSMNFILTER_OUTPUTITEM_WAITNEXT)&&(ret != BBSMNFILTER_OUTPUTITEM_END)) {
188 printf("invalid return value\n");
189 result = UNITTEST_RESULT_FAIL;
193 if (ret != BBSMNFILTER_OUTPUTITEM_CONTINUE) {
197 if (result == UNITTEST_RESULT_FAIL) {
202 bbsmnfilter_inputitem(filter, NULL);
204 ret = bbsmnfilter_outputitem(filter, &item);
206 result = test_bbsmnfilter_2_checkitem_index(item, i);
208 bbsmnparser_item_delete(item);
210 if (result == UNITTEST_RESULT_FAIL) {
211 printf("fail i = %d\n", i-1);
215 if (ret == BBSMNFILTER_OUTPUTITEM_CONTINUE) {
218 if (ret == BBSMNFILTER_OUTPUTITEM_END) {
221 result = UNITTEST_RESULT_FAIL;
222 printf("invalid return value\n");
226 result = UNITTEST_RESULT_FAIL;
227 printf("fail: too meny items\n");
230 bbsmnfilter_delete(filter);
232 bbsmnparser_delete(parser);
233 bbsmncache_delete(cache);
238 EXPORT VOID test_bbsmnfilter_main(unittest_driver_t *driver)
240 UNITTEST_DRIVER_REGIST(driver, test_bbsmnfilter_1);
241 UNITTEST_DRIVER_REGIST(driver, test_bbsmnfilter_2);