aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eina/src/tests/eina_test_tiler.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/eina/src/tests/eina_test_tiler.c')
-rw-r--r--libraries/eina/src/tests/eina_test_tiler.c184
1 files changed, 184 insertions, 0 deletions
diff --git a/libraries/eina/src/tests/eina_test_tiler.c b/libraries/eina/src/tests/eina_test_tiler.c
new file mode 100644
index 0000000..f1ef8f0
--- /dev/null
+++ b/libraries/eina/src/tests/eina_test_tiler.c
@@ -0,0 +1,184 @@
1/* EINA - EFL data type library
2 * Copyright (C) 2009 Rafael Antognolli
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifdef HAVE_CONFIG_H
20# include "config.h"
21#endif
22
23#include <stdio.h>
24
25#include "eina_suite.h"
26#include "Eina.h"
27
28struct test_rect
29{
30 unsigned long col, row;
31 int x, y, w, h;
32 Eina_Bool full;
33};
34
35static void
36check_iterator(Eina_Iterator *it, struct test_rect *cur_test)
37{
38 unsigned int i = 0;
39 struct Eina_Tile_Grid_Info *tile;
40
41 EINA_ITERATOR_FOREACH(it, tile) {
42 fail_if(cur_test[i].col != tile->col ||
43 cur_test[i].row != tile->row ||
44 cur_test[i].x != tile->rect.x ||
45 cur_test[i].y != tile->rect.y ||
46 cur_test[i].w != tile->rect.w ||
47 cur_test[i].h != tile->rect.h ||
48 cur_test[i].full != tile->full);
49 i++;
50 }
51
52 fail_if(i == 0);
53}
54
55 START_TEST(eina_test_tile_grid_slicer_iterator)
56{
57 Eina_Iterator *it;
58 struct test_rect *cur_test;
59 struct test_rect test1[] = {{1, 1, 72, 82, 10, 15, 0}};
60 struct test_rect test2[] =
61 {{1, 1, 72, 82, 56, 15, 0},
62 {2, 1, 0, 82, 128, 15, 0},
63 {3, 1, 0, 82, 116, 15, 0}};
64 struct test_rect test3[] =
65 {{1, 1, 72, 82, 10, 46, 0},
66 {1, 2, 72, 0, 10, 128, 0},
67 {1, 3, 72, 0, 10, 126, 0}};
68 struct test_rect test4[] =
69 {{1, 1, 72, 82, 56, 46, 0},
70 {2, 1, 0, 82, 128, 46, 0},
71 {3, 1, 0, 82, 128, 46, 0},
72 {4, 1, 0, 82, 88, 46, 0},
73 {1, 2, 72, 0, 56, 128, 0},
74 {2, 2, 0, 0, 128, 128, 1},
75 {3, 2, 0, 0, 128, 128, 1},
76 {4, 2, 0, 0, 88, 128, 0},
77 {1, 3, 72, 0, 56, 126, 0},
78 {2, 3, 0, 0, 128, 126, 0},
79 {3, 3, 0, 0, 128, 126, 0},
80 {4, 3, 0, 0, 88, 126, 0}};
81 struct test_rect test5[] = {{1, 1, 0, 0, 128, 128, 1}};
82 struct test_rect test6[] = {{1, 1, 0, 0, 1, 1, 0}};
83 struct test_rect test7[] =
84 {{1, 1, 0, 0, 128, 128, 1},
85 {2, 1, 0, 0, 1, 128, 0},
86 {1, 2, 0, 0, 128, 1, 0},
87 {2, 2, 0, 0, 1, 1, 0}};
88
89 eina_init();
90
91 cur_test = test1;
92 it = eina_tile_grid_slicer_iterator_new(200, 210, 10, 15, 128, 128);
93 check_iterator(it, cur_test);
94 eina_iterator_free(it);
95
96 cur_test = test2;
97 it = eina_tile_grid_slicer_iterator_new(200, 210, 300, 15, 128, 128);
98 check_iterator(it, cur_test);
99 eina_iterator_free(it);
100
101 cur_test = test3;
102 it = eina_tile_grid_slicer_iterator_new(200, 210, 10, 300, 128, 128);
103 check_iterator(it, cur_test);
104 eina_iterator_free(it);
105
106 cur_test = test4;
107 it = eina_tile_grid_slicer_iterator_new(200, 210, 400, 300, 128, 128);
108 check_iterator(it, cur_test);
109 eina_iterator_free(it);
110
111 cur_test = test5;
112 it = eina_tile_grid_slicer_iterator_new(128, 128, 128, 128, 128, 128);
113 check_iterator(it, cur_test);
114 eina_iterator_free(it);
115
116 cur_test = test6;
117 it = eina_tile_grid_slicer_iterator_new(128, 128, 1, 1, 128, 128);
118 check_iterator(it, cur_test);
119 eina_iterator_free(it);
120
121 cur_test = test7;
122 it = eina_tile_grid_slicer_iterator_new(128, 128, 129, 129, 128, 128);
123 check_iterator(it, cur_test);
124 eina_iterator_free(it);
125
126 eina_shutdown();
127}
128END_TEST
129
130START_TEST(eina_test_tiler_all)
131{
132 Eina_Tiler *tl;
133 Eina_Iterator *it;
134 Eina_Rectangle *rp;
135 Eina_Rectangle r;
136 int i = 0;
137
138 eina_init();
139
140 tl = eina_tiler_new(640, 480);
141
142 eina_tiler_tile_size_set(tl, 32, 32);
143
144 EINA_RECTANGLE_SET(&r, 50, 50, 20, 20);
145 fail_if(!eina_tiler_rect_add(tl, &r));
146
147 EINA_RECTANGLE_SET(&r, -10, -10, 5, 5);
148 fail_if(eina_tiler_rect_add(tl, &r));
149
150 EINA_RECTANGLE_SET(&r, 40, 40, 20, 20);
151 eina_tiler_rect_del(tl, &r);
152
153 it = eina_tiler_iterator_new(tl);
154 fail_if(!it);
155
156 EINA_ITERATOR_FOREACH(it, rp)
157 {
158 fail_if(rp->w <= 0);
159 fail_if(rp->h <= 0);
160 fail_if(rp->x < 0 || rp->x + rp->w > 640);
161 fail_if(rp->y < 0 || rp->y + rp->h > 480);
162 ++i;
163 }
164
165 fail_if(eina_iterator_container_get(it) != tl);
166
167 eina_iterator_free(it);
168
169 fail_if(i == 0);
170
171 eina_tiler_clear(tl);
172
173 eina_tiler_free(tl);
174
175 eina_shutdown();
176}
177END_TEST
178
179void
180eina_test_tiler(TCase *tc)
181{
182 tcase_add_test(tc, eina_test_tile_grid_slicer_iterator);
183 tcase_add_test(tc, eina_test_tiler_all);
184}