OSDN Git Service

fix previous cache data.
[bbk/bchanl.git] / src / test_subjectlayout.c
1 /*
2  * test_subjectlayout.c
3  *
4  * Copyright (c) 2009-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.h"
28
29 #include    "subjectlayout.h"
30
31 #include    <btron/btron.h>
32 #include        <btron/dp.h>
33 #include        <tcode.h>
34 #include    <bstdio.h>
35 #include    <bstring.h>
36 #include    <bstdlib.h>
37
38 #include    <unittest_driver.h>
39
40 #include    "subjectlist.h"
41 #include    "subjectparser.h"
42 #include    "subjectcache.h"
43
44 LOCAL UB test_sbjtlayout_testdata_01[] = {
45         0x39, 0x32, 0x34, 0x30, 0x39, 0x31, 0x30, 0x30,
46         0x31, 0x31, 0x2e, 0x64, 0x61, 0x74, 0x3c, 0x3e,
47         0x81, 0x9a, 0x82, 0x51, 0x82, 0xbf, 0x82, 0xe1,
48         0x82, 0xf1, 0x82, 0xcb, 0x82, 0xe9, 0x82, 0x50,
49         0x82, 0x4f, 0x8e, 0xfc, 0x94, 0x4e, 0x8b, 0x4c,
50         0x94, 0x4f, 0x81, 0x9a, 0x81, 0x40, 0x93, 0xfa,
51         0x96, 0x7b, 0x83, 0x56, 0x83, 0x8a, 0x81, 0x5b,
52         0x83, 0x59, 0x82, 0xf0, 0x97, 0x5c, 0x91, 0x7a,
53         0x82, 0xb5, 0x82, 0xc4, 0x83, 0x76, 0x83, 0x8c,
54         0x83, 0x5b, 0x83, 0x93, 0x83, 0x67, 0x82, 0xf0,
55         0x83, 0x51, 0x83, 0x62, 0x83, 0x67, 0x21, 0x20,
56         0x28, 0x31, 0x29, 0x0d, 0x0a, 0x31, 0x32, 0x32,
57         0x39, 0x33, 0x34, 0x34, 0x30, 0x38, 0x39, 0x2e,
58         0x64, 0x61, 0x74, 0x3c, 0x3e, 0x61, 0x61, 0x61,
59         0x20, 0x62, 0x62, 0x62, 0x62, 0x20, 0x28, 0x34,
60         0x38, 0x32, 0x29, 0x0d, 0x0a, 0x31, 0x32, 0x33,
61         0x33, 0x38, 0x33, 0x33, 0x30, 0x32, 0x39, 0x2e,
62         0x64, 0x61, 0x74, 0x3c, 0x3e, 0x81, 0x79, 0x96,
63         0x88, 0x8c, 0x8e, 0x32, 0x93, 0xfa, 0x94, 0xad,
64         0x94, 0x84, 0x81, 0x7a, 0x8c, 0xea, 0x82, 0xe9,
65         0x83, 0x58, 0x83, 0x8c, 0x33, 0x20, 0x28, 0x39,
66         0x32, 0x34, 0x29, 0x0d, 0x0a, 0x31, 0x32, 0x35,
67         0x31, 0x33, 0x35, 0x35, 0x38, 0x36, 0x31, 0x2e,
68         0x64, 0x61, 0x74, 0x3c, 0x3e, 0x83, 0x58, 0x83,
69         0x8c, 0x20, 0x28, 0x31, 0x37, 0x35, 0x29, 0x0d,
70         0x0a, 0x31, 0x32, 0x30, 0x31, 0x30, 0x37, 0x36,
71         0x38, 0x34, 0x31, 0x2e, 0x64, 0x61, 0x74, 0x3c,
72         0x3e, 0x82, 0xa0, 0x82, 0xe8, 0x82, 0xaa, 0x82,
73         0xbf, 0x82, 0xc8, 0x82, 0xb1, 0x82, 0xc6, 0x20,
74         0x28, 0x35, 0x32, 0x33, 0x29
75 };
76
77 LOCAL BMP* test_sbjtlayout_util_alloc_BMP()
78 {
79         W size;
80         BMP* dest;
81
82         dest = malloc(sizeof(UW)+sizeof(UH)*2+sizeof(RECT)+sizeof(UB*)*1);
83         dest->planes = 1;
84         dest->pixbits = (32 << 8)|28;
85         dest->rowbytes = 100*4;
86         dest->bounds = (RECT){{0,0,100,100}};
87
88         size = ((dest->bounds.c.right - dest->bounds.c.left) * (dest->pixbits >> 8) + 15) / 16 * 2 * (dest->bounds.c.bottom - dest->bounds.c.top);
89
90         dest->baseaddr[0] = malloc(size);
91
92         return dest;
93 }
94
95 LOCAL VOID test_sbjtlayout_util_free_BMP(BMP *bmp)
96 {
97         free(bmp->baseaddr[0]);
98         free(bmp);
99 }
100
101 LOCAL UNITTEST_RESULT test_sbjtlayout_1()
102 {
103         BMP *bmp;
104         GID gid;
105         W err;
106         Bool next;
107         sbjtlayout_t *layout;
108         sbjtlist_t *list;
109         sbjtlist_iterator_t *list_iter;
110         sbjtlist_tuple_t *tuple;
111         sbjtcache_t *cache;
112         sbjtparser_t *parser;
113         sbjtparser_thread_t *thread = NULL;
114         UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
115
116         bmp = test_sbjtlayout_util_alloc_BMP();
117         if (bmp == NULL) {
118                 return UNITTEST_RESULT_FAIL;
119         }
120         gid = gopn_mem(NULL, bmp, NULL);
121         if (gid < 0) {
122                 return UNITTEST_RESULT_FAIL;
123         }
124
125         cache = sbjtcache_new();
126         sbjtcache_appenddata(cache, test_sbjtlayout_testdata_01, strlen(test_sbjtlayout_testdata_01));
127
128         parser = sbjtparser_new(cache);
129         list = sbjtlist_new();
130         layout = sbjtlayout_new(gid);
131
132         for (;;) {
133                 err = sbjtparser_getnextthread(parser, &thread);
134                 if (err != 1) {
135                         break;
136                 }
137                 if (thread != NULL) {
138                         sbjtlist_appendthread(list, thread, 0x3eec16c0);
139                 } else {
140                         break;
141                 }
142         }
143
144         sbjtlist_sort(list, SBJTLIST_SORTBY_NUMBER, NULL, 0);
145
146         list_iter = sbjtlist_startread(list, False);
147         for (;;) {
148                 next = sbjtlist_iterator_next(list_iter, &tuple);
149                 if (next == False) {
150                         break;
151                 }
152                 sbjtlayout_appendthread(layout, tuple);
153         }
154         sbjtlist_endread(list, list_iter);
155
156         sbjtlayout_delete(layout);
157         sbjtlist_delete(list);
158         sbjtparser_delete(parser);
159
160         sbjtcache_delete(cache);
161
162         gcls_env(gid);
163         test_sbjtlayout_util_free_BMP(bmp);
164
165         return result;
166 }
167
168 EXPORT VOID test_sbjtlayout_main(unittest_driver_t *driver)
169 {
170         UNITTEST_DRIVER_REGIST(driver, test_sbjtlayout_1);
171 }