4 * Copyright (c) 2009-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 "subjectlayout.h"
31 #include <btron/btron.h>
38 #include <unittest_driver.h>
40 #include "subjectlist.h"
41 #include "subjectparser.h"
42 #include "subjectcache.h"
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
77 LOCAL BMP* test_sbjtlayout_util_alloc_BMP()
82 dest = malloc(sizeof(UW)+sizeof(UH)*2+sizeof(RECT)+sizeof(UB*)*1);
84 dest->pixbits = (32 << 8)|28;
85 dest->rowbytes = 100*4;
86 dest->bounds = (RECT){{0,0,100,100}};
88 size = ((dest->bounds.c.right - dest->bounds.c.left) * (dest->pixbits >> 8) + 15) / 16 * 2 * (dest->bounds.c.bottom - dest->bounds.c.top);
90 dest->baseaddr[0] = malloc(size);
95 LOCAL VOID test_sbjtlayout_util_free_BMP(BMP *bmp)
97 free(bmp->baseaddr[0]);
101 LOCAL UNITTEST_RESULT test_sbjtlayout_1()
107 sbjtlayout_t *layout;
109 sbjtlist_iterator_t *list_iter;
110 sbjtlist_tuple_t *tuple;
112 sbjtparser_t *parser;
113 sbjtparser_thread_t *thread = NULL;
114 UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
116 bmp = test_sbjtlayout_util_alloc_BMP();
118 return UNITTEST_RESULT_FAIL;
120 gid = gopn_mem(NULL, bmp, NULL);
122 return UNITTEST_RESULT_FAIL;
125 cache = sbjtcache_new();
126 sbjtcache_appenddata(cache, test_sbjtlayout_testdata_01, strlen(test_sbjtlayout_testdata_01));
128 parser = sbjtparser_new(cache);
129 list = sbjtlist_new();
130 layout = sbjtlayout_new(gid);
133 err = sbjtparser_getnextthread(parser, &thread);
137 if (thread != NULL) {
138 sbjtlist_appendthread(list, thread, 0x3eec16c0);
144 sbjtlist_sort(list, SBJTLIST_SORTBY_NUMBER, NULL, 0);
146 list_iter = sbjtlist_startread(list, False);
148 next = sbjtlist_iterator_next(list_iter, &tuple);
152 sbjtlayout_appendthread(layout, tuple);
154 sbjtlist_endread(list, list_iter);
156 sbjtlayout_delete(layout);
157 sbjtlist_delete(list);
158 sbjtparser_delete(parser);
160 sbjtcache_delete(cache);
163 test_sbjtlayout_util_free_BMP(bmp);
168 EXPORT VOID test_sbjtlayout_main(unittest_driver_t *driver)
170 UNITTEST_DRIVER_REGIST(driver, test_sbjtlayout_1);