add test cases for cssrendering_box_t and cssrendering_coordinate_t.
@@ -0,0 +1,36 @@ | ||
1 | +/* | |
2 | + * test_css.h | |
3 | + * | |
4 | + * Copyright (c) 2013 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 <basic.h> | |
28 | +#include <unittest_driver.h> | |
29 | + | |
30 | +#ifndef __TEST_CSS_H__ | |
31 | +#define __TEST_CSS_H__ | |
32 | + | |
33 | +IMPORT VOID test_cssrendering_box_main(unittest_driver_t *driver); | |
34 | +IMPORT VOID test_cssrendering_coordinate_main(unittest_driver_t *driver); | |
35 | + | |
36 | +#endif |
@@ -0,0 +1,111 @@ | ||
1 | +/* | |
2 | + * test_cssrendering_coordinate.c | |
3 | + * | |
4 | + * Copyright (c) 2013 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_css.h" | |
28 | + | |
29 | +#include "cssrendering_coordinate.h" | |
30 | + | |
31 | +#include <basic.h> | |
32 | +#include <bstdio.h> | |
33 | +#include <bstdlib.h> | |
34 | +#include <bstring.h> | |
35 | + | |
36 | +#include <unittest_driver.h> | |
37 | + | |
38 | +#include "cssmetric.h" | |
39 | + | |
40 | +LOCAL UNITTEST_RESULT test_cssrendering_coordinate_1() | |
41 | +{ | |
42 | + cssrendering_coordinate_t coordinate; | |
43 | + cssmetric_rectangle_t draw = (cssmetric_rectangle_t){{0, 0, 500, 500}}; | |
44 | + RECT src; | |
45 | + cssmetric_rectangle_t dest; | |
46 | + UNITTEST_RESULT ret = UNITTEST_RESULT_PASS; | |
47 | + | |
48 | + cssrendering_coordinate_initialize(&coordinate); | |
49 | + cssrendering_coordinate_setdrawrect(&coordinate, draw); | |
50 | + cssrendering_coordinate_setviewrect(&coordinate, 100, 100, 400, 400); | |
51 | + | |
52 | + src = (RECT){{10, 10, 300, 300}}; | |
53 | + cssrendering_coordinate_getabsoluterect(&coordinate, src, &dest); | |
54 | + if ((dest.c.left != 110)||(dest.c.top != 110)||(dest.c.right != 400)||(dest.c.bottom != 400)) { | |
55 | + ret = UNITTEST_RESULT_FAIL; | |
56 | + } | |
57 | + | |
58 | + cssrendering_coordinate_finalize(&coordinate); | |
59 | + | |
60 | + return ret; | |
61 | +} | |
62 | + | |
63 | +LOCAL UNITTEST_RESULT test_cssrendering_coordinate_2() | |
64 | +{ | |
65 | + cssrendering_coordinate_t coordinate; | |
66 | + cssmetric_rectangle_t draw = (cssmetric_rectangle_t){{0, 0, 500, 500}}; | |
67 | + W x, y; | |
68 | + UNITTEST_RESULT ret = UNITTEST_RESULT_PASS; | |
69 | + | |
70 | + cssrendering_coordinate_initialize(&coordinate); | |
71 | + cssrendering_coordinate_setdrawrect(&coordinate, draw); | |
72 | + cssrendering_coordinate_setviewrect(&coordinate, 100, 100, 400, 400); | |
73 | + | |
74 | + cssrendering_coordinate_getrelativepoint(&coordinate, 110, 120, &x, &y); | |
75 | + if ((x != 10)||(y != 20)) { | |
76 | + ret = UNITTEST_RESULT_FAIL; | |
77 | + } | |
78 | + | |
79 | + cssrendering_coordinate_finalize(&coordinate); | |
80 | + | |
81 | + return ret; | |
82 | +} | |
83 | + | |
84 | +LOCAL UNITTEST_RESULT test_cssrendering_coordinate_3() | |
85 | +{ | |
86 | + cssrendering_coordinate_t coordinate; | |
87 | + cssmetric_rectangle_t draw = (cssmetric_rectangle_t){{0, 0, 500, 500}}; | |
88 | + W l, t, r, b; | |
89 | + UNITTEST_RESULT ret = UNITTEST_RESULT_PASS; | |
90 | + | |
91 | + cssrendering_coordinate_initialize(&coordinate); | |
92 | + cssrendering_coordinate_setdrawrect(&coordinate, draw); | |
93 | + cssrendering_coordinate_setviewrect(&coordinate, 100, 100, 400, 400); | |
94 | + | |
95 | + cssrendering_coordinate_scrollviewrect(&coordinate, 30, 40); | |
96 | + cssrendering_coordinate_getviewrect(&coordinate, &l, &t, &r, &b); | |
97 | + if ((l != 130)||(t != 140)||(r != 430)||(b != 440)) { | |
98 | + ret = UNITTEST_RESULT_FAIL; | |
99 | + } | |
100 | + | |
101 | + cssrendering_coordinate_finalize(&coordinate); | |
102 | + | |
103 | + return ret; | |
104 | +} | |
105 | + | |
106 | +EXPORT VOID test_cssrendering_coordinate_main(unittest_driver_t *driver) | |
107 | +{ | |
108 | + UNITTEST_DRIVER_REGIST(driver, test_cssrendering_coordinate_1); | |
109 | + UNITTEST_DRIVER_REGIST(driver, test_cssrendering_coordinate_2); | |
110 | + UNITTEST_DRIVER_REGIST(driver, test_cssrendering_coordinate_3); | |
111 | +} |
@@ -0,0 +1,121 @@ | ||
1 | +/* | |
2 | + * test_cssrendering_box.c | |
3 | + * | |
4 | + * Copyright (c) 2013 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_css.h" | |
28 | + | |
29 | +#include "cssrendering_box.h" | |
30 | + | |
31 | +#include <basic.h> | |
32 | +#include <bstdio.h> | |
33 | +#include <bstdlib.h> | |
34 | +#include <bstring.h> | |
35 | + | |
36 | +#include <unittest_driver.h> | |
37 | + | |
38 | +#include "cssmetric.h" | |
39 | + | |
40 | +LOCAL UNITTEST_RESULT test_cssrendering_drawtraversal_1() | |
41 | +{ | |
42 | + cssrendering_blockbox_t root; | |
43 | + cssrendering_anonymousbox_t anon; | |
44 | + cssrendering_linebox_t line[5]; | |
45 | + cssrendering_drawtraversal_t traversal; | |
46 | + cssrendering_drawtraversal_result result; | |
47 | + cssmetric_rectangle_t draw; | |
48 | + Bool cont, line_called[5] = {False, False, False, False, False}; | |
49 | + UNITTEST_RESULT ret = UNITTEST_RESULT_PASS; | |
50 | + | |
51 | + cssrendering_blockbox_initialize(&root); | |
52 | + cssrendering_anonymousbox_initialize(&anon); | |
53 | + cssrendering_linebox_initialize(line+0); | |
54 | + cssrendering_linebox_initialize(line+1); | |
55 | + cssrendering_linebox_initialize(line+2); | |
56 | + cssrendering_linebox_initialize(line+3); | |
57 | + cssrendering_linebox_initialize(line+4); | |
58 | + | |
59 | + cssrendering_blockbox_appendanonymouschild(&root, &anon); | |
60 | + cssrendering_anonymousbox_appendchild(&anon, line+0); | |
61 | + cssrendering_anonymousbox_appendchild(&anon, line+1); | |
62 | + cssrendering_anonymousbox_appendchild(&anon, line+2); | |
63 | + cssrendering_anonymousbox_appendchild(&anon, line+3); | |
64 | + cssrendering_anonymousbox_appendchild(&anon, line+4); | |
65 | + | |
66 | + line[0].base.content_edge = (cssmetric_rectangle_t){{0, 0, 100, 100}}; | |
67 | + cssrendering_linebox_setuserdata(line+0, line+0); | |
68 | + line[1].base.content_edge = (cssmetric_rectangle_t){{0, 100, 100, 200}}; | |
69 | + cssrendering_linebox_setuserdata(line+1, line+1); | |
70 | + line[2].base.content_edge = (cssmetric_rectangle_t){{0, 200, 100, 300}}; | |
71 | + cssrendering_linebox_setuserdata(line+2, line+2); | |
72 | + line[3].base.content_edge = (cssmetric_rectangle_t){{0, 300, 100, 400}}; | |
73 | + cssrendering_linebox_setuserdata(line+3, line+3); | |
74 | + line[4].base.content_edge = (cssmetric_rectangle_t){{0, 400, 100, 500}}; | |
75 | + cssrendering_linebox_setuserdata(line+4, line+4); | |
76 | + | |
77 | + draw = (cssmetric_rectangle_t){{25, 150, 75, 350}}; | |
78 | + cssrendering_drawtraversal_initialize(&traversal, &root, draw); | |
79 | + for (;;) { | |
80 | + cont = cssrendering_drawtraversal_next(&traversal, &result); | |
81 | + if (cont == False) { | |
82 | + break; | |
83 | + } | |
84 | + if (result.type != CSSRENDERING_DRAWTRAVERSAL_RESULTTYPE_TEXT) { | |
85 | + continue; | |
86 | + } | |
87 | + if (result.data.text.nodedata == (line+0)) { | |
88 | + line_called[0] = True; | |
89 | + } else if (result.data.text.nodedata == (line+1)) { | |
90 | + line_called[1] = True; | |
91 | + } else if (result.data.text.nodedata == (line+2)) { | |
92 | + line_called[2] = True; | |
93 | + } else if (result.data.text.nodedata == (line+3)) { | |
94 | + line_called[3] = True; | |
95 | + } else if (result.data.text.nodedata == (line+4)) { | |
96 | + line_called[4] = True; | |
97 | + } | |
98 | + } | |
99 | + cssrendering_drawtraversal_finalize(&traversal); | |
100 | + | |
101 | + if ((line_called[0] == False)&&(line_called[1] != False)&&(line_called[2] != False)&&(line_called[3] != False)&&(line_called[4] == False)) { | |
102 | + ret = UNITTEST_RESULT_PASS; | |
103 | + } else { | |
104 | + ret = UNITTEST_RESULT_FAIL; | |
105 | + } | |
106 | + | |
107 | + cssrendering_linebox_finalize(line+4); | |
108 | + cssrendering_linebox_finalize(line+3); | |
109 | + cssrendering_linebox_finalize(line+2); | |
110 | + cssrendering_linebox_finalize(line+1); | |
111 | + cssrendering_linebox_finalize(line+0); | |
112 | + cssrendering_anonymousbox_finalize(&anon); | |
113 | + cssrendering_blockbox_finalize(&root); | |
114 | + | |
115 | + return ret; | |
116 | +} | |
117 | + | |
118 | +EXPORT VOID test_cssrendering_box_main(unittest_driver_t *driver) | |
119 | +{ | |
120 | + UNITTEST_DRIVER_REGIST(driver, test_cssrendering_drawtraversal_1); | |
121 | +} |