2 * test_texteditor_stackfilter.c
4 * Copyright (c) 2014 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 "test_control.h"
29 #include "texteditor_stackfilter.h"
38 #include <tad/taddecoder.h>
39 #include <tad/tadfragment.h>
41 #include <unittest_driver.h>
48 } test_texteditor_stackfilter_testdata_t;
50 LOCAL UNITTEST_RESULT test_texteditor_stackfilter_common(test_texteditor_stackfilter_testdata_t *testdata)
52 texteditor_stackfilter_t filter;
54 tadsegment segment, *filterd;
55 tadfragment_t fragment;
56 tadfragment_cursor_t cursor;
59 W input_result, err, len;
60 UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
62 err = tadfragment_initialize(&fragment);
64 return UNITTEST_RESULT_FAIL;
67 texteditor_stackfilter_initialize(&filter);
69 taddecoder_initialize(&decoder, testdata->src, testdata->src_len);
71 tadfragment_cursor_initialize(&cursor, &fragment);
73 cont = taddecoder_next(&decoder, &segment);
77 input_result = texteditor_stackfilter_setinput(&filter, &segment);
78 if (input_result == TEXTEDITOR_STACKFILTER_SETINPUT_RESULT_FULL) {
80 cont = texteditor_stackfilter_getoutput(&filter, &filterd);
84 tadfragment_cursor_insertsegment(&cursor, filterd);
86 input_result = texteditor_stackfilter_setinput(&filter, &segment);
88 if (input_result != TEXTEDITOR_STACKFILTER_SETINPUT_RESULT_OK) {
89 result = UNITTEST_RESULT_FAIL;
94 cont = texteditor_stackfilter_getoutput(&filter, &filterd);
98 tadfragment_cursor_insertsegment(&cursor, filterd);
100 tadfragment_cursor_finalize(&cursor);
102 taddecoder_finalize(&decoder);
104 texteditor_stackfilter_finalize(&filter);
106 buf = tadfragment_getbuffer(&fragment);
107 len = tadfragment_getbufferlength(&fragment);
109 if (len != testdata->expected_len * sizeof(TC)) {
110 printf("length error: expected = %d, result = %d\n", testdata->expected_len * sizeof(TC), len);
111 result = UNITTEST_RESULT_FAIL;
112 } else if (memcmp(buf, testdata->expected, len) != 0) {
113 printf("buffer error\n");
114 result = UNITTEST_RESULT_FAIL;
117 tadfragment_finalize(&fragment);
122 LOCAL UNITTEST_RESULT test_texteditor_stackfilter_1()
125 0xffe1, 0x0018, 0x0000, 0x0000,
126 0x0000, 0x0000, 0x0000, 0x0000,
127 0x0000, 0x0000, 0xff88, 0xff88,
128 0x0021, 0x0000, 0x2422, 0xffa2,
129 0x0006, 0x0300, 0x0101, 0x0101,
133 TC expected[] = (TC[]){
134 0xffe1, 0x0018, 0x0000, 0x0000,
135 0x0000, 0x0000, 0x0000, 0x0000,
136 0x0000, 0x0000, 0xff88, 0xff88,
137 0x0021, 0x0000, 0x2422, 0xffa2,
138 0x0006, 0x0300, 0x0101, 0x0101,
142 test_texteditor_stackfilter_testdata_t testdata = {
143 src, src_len, expected, expected_len
145 return test_texteditor_stackfilter_common(&testdata);
148 LOCAL UNITTEST_RESULT test_texteditor_stackfilter_2()
154 TC expected[] = (TC[]){
158 test_texteditor_stackfilter_testdata_t testdata = {
159 src, src_len, expected, expected_len
161 return test_texteditor_stackfilter_common(&testdata);
164 LOCAL UNITTEST_RESULT test_texteditor_stackfilter_3()
168 0xffe3, 0x0018, 0x0000, 0x0000,
169 0x0000, 0x0000, 0x0000, 0x0000,
170 0x0000, 0x0000, 0xff88, 0xff88,
172 0xffb0, 0x0012, 0x0000, 0x0000,
173 0x0000, 0x0000, 0x0000, 0x0000,
174 0x0000, 0x0000, 0x0000,
179 TC expected[] = (TC[]){
183 test_texteditor_stackfilter_testdata_t testdata = {
184 src, src_len, expected, expected_len
186 return test_texteditor_stackfilter_common(&testdata);
189 LOCAL UNITTEST_RESULT test_texteditor_stackfilter_4()
193 0xffe1, 0x0018, 0x0000, 0x0000,
194 0x0000, 0x0000, 0x0000, 0x0000,
195 0x0000, 0x0000, 0xff88, 0xff88,
202 TC expected[] = (TC[]){
206 test_texteditor_stackfilter_testdata_t testdata = {
207 src, src_len, expected, expected_len
209 return test_texteditor_stackfilter_common(&testdata);
212 EXPORT VOID test_texteditor_stackfilter_main(unittest_driver_t *driver)
214 UNITTEST_DRIVER_REGIST(driver, test_texteditor_stackfilter_1);
215 UNITTEST_DRIVER_REGIST(driver, test_texteditor_stackfilter_2);
216 UNITTEST_DRIVER_REGIST(driver, test_texteditor_stackfilter_3);
217 UNITTEST_DRIVER_REGIST(driver, test_texteditor_stackfilter_4);