1 /* EINA - EFL data type library
2 * Copyright (C) 2009 Rafael Antognolli
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.
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.
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/>.
25 #include "eina_suite.h"
30 unsigned long col, row;
36 check_iterator(Eina_Iterator *it, struct test_rect *cur_test)
39 struct Eina_Tile_Grid_Info *tile;
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);
55 START_TEST(eina_test_tile_grid_slicer_iterator)
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}};
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);
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);
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);
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);
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);
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);
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);
130 START_TEST(eina_test_tiler_all)
140 tl = eina_tiler_new(640, 480);
142 eina_tiler_tile_size_set(tl, 32, 32);
144 EINA_RECTANGLE_SET(&r, 50, 50, 20, 20);
145 fail_if(!eina_tiler_rect_add(tl, &r));
147 EINA_RECTANGLE_SET(&r, -10, -10, 5, 5);
148 fail_if(eina_tiler_rect_add(tl, &r));
150 EINA_RECTANGLE_SET(&r, 40, 40, 20, 20);
151 eina_tiler_rect_del(tl, &r);
153 it = eina_tiler_iterator_new(tl);
156 EINA_ITERATOR_FOREACH(it, rp)
160 fail_if(rp->x < 0 || rp->x + rp->w > 640);
161 fail_if(rp->y < 0 || rp->y + rp->h > 480);
165 fail_if(eina_iterator_container_get(it) != tl);
167 eina_iterator_free(it);
171 eina_tiler_clear(tl);
180 eina_test_tiler(TCase *tc)
182 tcase_add_test(tc, eina_test_tile_grid_slicer_iterator);
183 tcase_add_test(tc, eina_test_tiler_all);