OSDN Git Service

fix copyright filename.
[bbk/bchanf.git] / src / tad / test_tadstack.c
1 /*
2  * test_tadstack.c
3  *
4  * Copyright (c) 2012 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 "test_tad.h"
28
29 #include "tadstack.h"
30
31 #include        <basic.h>
32 #include        <bstdio.h>
33 #include        <bstdlib.h>
34 #include        <bstring.h>
35
36 #include "taditerator.h"
37
38 #include    <unittest_driver.h>
39
40 LOCAL UB test_tadstack_testdata01[] = {
41         0xe0, 0xff, 0x06, 0x00, 0x00, 0x00, 0x02, 0x00,
42         0x22, 0x01, 0xe1, 0xff, 0x18, 0x00, 0x00, 0x00,
43         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0xff,
45         0x88, 0xff, 0x21, 0x00, 0x00, 0x00, 0xa0, 0xff,
46         0x0e, 0x00, 0x00, 0x00, 0x7b, 0x05, 0xe0, 0x03,
47         0x5e, 0x00, 0x46, 0x00, 0x6c, 0x00, 0x55, 0x00,
48         0xa0, 0xff, 0x0a, 0x00, 0x00, 0x01, 0x5e, 0x00,
49         0x76, 0x00, 0x6c, 0x00, 0x55, 0x00, 0xa0, 0xff,
50         0x22, 0x00, 0x00, 0x03, 0xa0, 0xff, 0x02, 0x00,
51         0x00, 0x08, 0xa1, 0xff, 0x04, 0x00, 0x00, 0x00,
52         0x00, 0x80, 0xa1, 0xff, 0x02, 0x00, 0x01, 0x01,
53         0x5d, 0x21, 0xad, 0xff, 0x04, 0x00, 0x00, 0x00,
54         0xc8, 0x00, 0x5d, 0x21, 0xa0, 0xff, 0x04, 0x00,
55         0x00, 0x04, 0x00, 0x80, 0xa4, 0xff, 0x24, 0x00,
56         0x11, 0x08, 0x22, 0x21, 0x23, 0x21, 0x24, 0x21,
57         0x25, 0x21, 0x2b, 0x21, 0x2c, 0x21, 0x47, 0x21,
58         0x49, 0x21, 0x4b, 0x21, 0x4d, 0x21, 0x4f, 0x21,
59         0x51, 0x21, 0x53, 0x21, 0x55, 0x21, 0x57, 0x21,
60         0x59, 0x21, 0x5b, 0x21, 0xa4, 0xff, 0x18, 0x00,
61         0x11, 0x09, 0x46, 0x21, 0x48, 0x21, 0x4a, 0x21,
62         0x4c, 0x21, 0x4e, 0x21, 0x50, 0x21, 0x52, 0x21,
63         0x54, 0x21, 0x56, 0x21, 0x58, 0x21, 0x5a, 0x21,
64         0xa1, 0xff, 0x24, 0x00, 0x00, 0x02, 0x04, 0x01,
65         0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
66         0x0b, 0x00, 0x48, 0x00, 0x90, 0x00, 0xd8, 0x00,
67         0x20, 0x01, 0x68, 0x01, 0xb0, 0x01, 0xf8, 0x01,
68         0x40, 0x02, 0x88, 0x02, 0xd0, 0x02, 0x18, 0x03,
69         0xa1, 0xff, 0x04, 0x00, 0x01, 0x00, 0x04, 0x01,
70         0x46, 0x23, 0x52, 0x23, 0x4f, 0x23, 0x4d, 0x23,
71         0x27, 0x21, 0x21, 0x21, 0x6e, 0x23, 0x61, 0x23,
72         0x6d, 0x23, 0x65, 0x23, 0x0a, 0x00, 0x6d, 0x23,
73         0x61, 0x23, 0x69, 0x23, 0x6c, 0x23, 0x27, 0x21,
74         0x21, 0x21, 0x6d, 0x23, 0x61, 0x23, 0x69, 0x23,
75         0x6c, 0x23, 0x0a, 0x00, 0x0a, 0x00, 0x62, 0x23,
76         0x6f, 0x23, 0x64, 0x23, 0x79, 0x23, 0xe2, 0xff,
77         0x00, 0x00,
78 };
79
80 LOCAL UNITTEST_RESULT test_tadstack_1()
81 {
82         tadstack_t stack;
83         taditerator_t iter;
84         taditerator_result result;
85         TADSTACK_RESULT stk_result;
86         UNITTEST_RESULT ok = UNITTEST_RESULT_PASS;
87
88         tadstack_initialize(&stack);
89         taditerator_initialize(&iter, (TC*)test_tadstack_testdata01, sizeof(test_tadstack_testdata01)/sizeof(TC));
90
91         for (;;) {
92                 taditerator_next2(&iter, &result);
93                 if (result.type == TADITERATOR_RESULTTYPE_END) {
94                         break;
95                 }
96                 if (result.type == TADITERATOR_RESULTTYPE_CHARCTOR) {
97                         
98                         stk_result = tadstack_inputcharactor(&stack, result.segment);
99                 } else if (result.type == TADITERATOR_RESULTTYPE_SEGMENT) {
100                         stk_result = tadstack_inputvsegment(&stack, result.segment, result.data, result.segsize);
101                 }
102                 if (stk_result == TADSTACK_RESULT_FORMAT_ERROR) {
103                         printf("format error\n");
104                         ok = UNITTEST_RESULT_FAIL;
105                 }
106         }
107
108         taditerator_finalize(&iter);
109         tadstack_finalize(&stack);
110
111         return ok;
112 }
113
114 EXPORT VOID test_tadstack_main(unittest_driver_t *driver)
115 {
116         UNITTEST_DRIVER_REGIST(driver, test_tadstack_1);
117 }