1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32
33 #include "TilingData.h"
34
35 #include <gtest/gtest.h>
36
37 using namespace WebCore;
38
39 namespace {
40
TEST(TilingDataTest,numTiles_NoTiling)41 TEST(TilingDataTest, numTiles_NoTiling)
42 {
43 EXPECT_EQ(1, TilingData(16, 16, 16, false).numTiles());
44 EXPECT_EQ(1, TilingData(16, 15, 15, true).numTiles());
45 EXPECT_EQ(1, TilingData(16, 16, 16, true).numTiles());
46 EXPECT_EQ(1, TilingData(16, 1, 16, false).numTiles());
47 EXPECT_EQ(1, TilingData(15, 15, 15, true).numTiles());
48 }
49
TEST(TilingDataTest,numTiles_TilingNoBorders)50 TEST(TilingDataTest, numTiles_TilingNoBorders)
51 {
52 EXPECT_EQ(0, TilingData(0, 0, 0, false).numTiles());
53 EXPECT_EQ(0, TilingData(0, 4, 0, false).numTiles());
54 EXPECT_EQ(0, TilingData(0, 0, 4, false).numTiles());
55 EXPECT_EQ(0, TilingData(4, 4, 0, false).numTiles());
56 EXPECT_EQ(0, TilingData(4, 0, 4, false).numTiles());
57 EXPECT_EQ(0, TilingData(-8, 1, 1, false).numTiles());
58 EXPECT_EQ(0, TilingData(-1, 1, 1, false).numTiles());
59 EXPECT_EQ(0, TilingData(0, 1, 1, false).numTiles());
60
61 EXPECT_EQ(1, TilingData(1, 1, 1, false).numTiles());
62 EXPECT_EQ(2, TilingData(1, 1, 2, false).numTiles());
63 EXPECT_EQ(2, TilingData(1, 2, 1, false).numTiles());
64 EXPECT_EQ(1, TilingData(2, 1, 1, false).numTiles());
65 EXPECT_EQ(1, TilingData(2, 1, 2, false).numTiles());
66 EXPECT_EQ(1, TilingData(2, 2, 1, false).numTiles());
67 EXPECT_EQ(1, TilingData(2, 2, 2, false).numTiles());
68 EXPECT_EQ(1, TilingData(3, 3, 3, false).numTiles());
69
70 EXPECT_EQ(1, TilingData(4, 1, 4, false).numTiles());
71 EXPECT_EQ(1, TilingData(4, 2, 4, false).numTiles());
72 EXPECT_EQ(1, TilingData(4, 3, 4, false).numTiles());
73 EXPECT_EQ(1, TilingData(4, 4, 4, false).numTiles());
74 EXPECT_EQ(2, TilingData(4, 5, 4, false).numTiles());
75 EXPECT_EQ(2, TilingData(4, 6, 4, false).numTiles());
76 EXPECT_EQ(2, TilingData(4, 7, 4, false).numTiles());
77 EXPECT_EQ(2, TilingData(4, 8, 4, false).numTiles());
78 EXPECT_EQ(3, TilingData(4, 9, 4, false).numTiles());
79 EXPECT_EQ(3, TilingData(4, 10, 4, false).numTiles());
80 EXPECT_EQ(3, TilingData(4, 11, 4, false).numTiles());
81
82 EXPECT_EQ(1, TilingData(5, 1, 5, false).numTiles());
83 EXPECT_EQ(1, TilingData(5, 2, 5, false).numTiles());
84 EXPECT_EQ(1, TilingData(5, 3, 5, false).numTiles());
85 EXPECT_EQ(1, TilingData(5, 4, 5, false).numTiles());
86 EXPECT_EQ(1, TilingData(5, 5, 5, false).numTiles());
87 EXPECT_EQ(2, TilingData(5, 6, 5, false).numTiles());
88 EXPECT_EQ(2, TilingData(5, 7, 5, false).numTiles());
89 EXPECT_EQ(2, TilingData(5, 8, 5, false).numTiles());
90 EXPECT_EQ(2, TilingData(5, 9, 5, false).numTiles());
91 EXPECT_EQ(2, TilingData(5, 10, 5, false).numTiles());
92 EXPECT_EQ(3, TilingData(5, 11, 5, false).numTiles());
93
94 EXPECT_EQ(1, TilingData(16, 16, 16, false).numTiles());
95 EXPECT_EQ(1, TilingData(17, 16, 16, false).numTiles());
96 EXPECT_EQ(4, TilingData(15, 16, 16, false).numTiles());
97 EXPECT_EQ(4, TilingData(8, 16, 16, false).numTiles());
98 EXPECT_EQ(6, TilingData(8, 17, 16, false).numTiles());
99 }
100
TEST(TilingDataTest,numTiles_TilingWithBorders)101 TEST(TilingDataTest, numTiles_TilingWithBorders)
102 {
103 EXPECT_EQ(0, TilingData(0, 0, 0, true).numTiles());
104 EXPECT_EQ(0, TilingData(0, 4, 0, true).numTiles());
105 EXPECT_EQ(0, TilingData(0, 0, 4, true).numTiles());
106 EXPECT_EQ(0, TilingData(4, 4, 0, true).numTiles());
107 EXPECT_EQ(0, TilingData(4, 0, 4, true).numTiles());
108 EXPECT_EQ(0, TilingData(-8, 1, 1, true).numTiles());
109 EXPECT_EQ(0, TilingData(-1, 1, 1, true).numTiles());
110 EXPECT_EQ(0, TilingData(0, 1, 1, true).numTiles());
111
112 EXPECT_EQ(1, TilingData(1, 1, 1, true).numTiles());
113 EXPECT_EQ(0, TilingData(1, 1, 2, true).numTiles());
114 EXPECT_EQ(0, TilingData(1, 2, 1, true).numTiles());
115 EXPECT_EQ(1, TilingData(2, 1, 1, true).numTiles());
116 EXPECT_EQ(1, TilingData(2, 1, 2, true).numTiles());
117 EXPECT_EQ(1, TilingData(2, 2, 1, true).numTiles());
118 EXPECT_EQ(1, TilingData(2, 2, 2, true).numTiles());
119
120 EXPECT_EQ(1, TilingData(3, 1, 3, true).numTiles());
121 EXPECT_EQ(1, TilingData(3, 2, 3, true).numTiles());
122 EXPECT_EQ(1, TilingData(3, 3, 3, true).numTiles());
123 EXPECT_EQ(2, TilingData(3, 4, 3, true).numTiles());
124 EXPECT_EQ(3, TilingData(3, 5, 3, true).numTiles());
125 EXPECT_EQ(4, TilingData(3, 6, 3, true).numTiles());
126 EXPECT_EQ(5, TilingData(3, 7, 3, true).numTiles());
127
128 EXPECT_EQ(1, TilingData(4, 1, 4, true).numTiles());
129 EXPECT_EQ(1, TilingData(4, 2, 4, true).numTiles());
130 EXPECT_EQ(1, TilingData(4, 3, 4, true).numTiles());
131 EXPECT_EQ(1, TilingData(4, 4, 4, true).numTiles());
132 EXPECT_EQ(2, TilingData(4, 5, 4, true).numTiles());
133 EXPECT_EQ(2, TilingData(4, 6, 4, true).numTiles());
134 EXPECT_EQ(3, TilingData(4, 7, 4, true).numTiles());
135 EXPECT_EQ(3, TilingData(4, 8, 4, true).numTiles());
136 EXPECT_EQ(4, TilingData(4, 9, 4, true).numTiles());
137 EXPECT_EQ(4, TilingData(4, 10, 4, true).numTiles());
138 EXPECT_EQ(5, TilingData(4, 11, 4, true).numTiles());
139
140 EXPECT_EQ(1, TilingData(5, 1, 5, true).numTiles());
141 EXPECT_EQ(1, TilingData(5, 2, 5, true).numTiles());
142 EXPECT_EQ(1, TilingData(5, 3, 5, true).numTiles());
143 EXPECT_EQ(1, TilingData(5, 4, 5, true).numTiles());
144 EXPECT_EQ(1, TilingData(5, 5, 5, true).numTiles());
145 EXPECT_EQ(2, TilingData(5, 6, 5, true).numTiles());
146 EXPECT_EQ(2, TilingData(5, 7, 5, true).numTiles());
147 EXPECT_EQ(2, TilingData(5, 8, 5, true).numTiles());
148 EXPECT_EQ(3, TilingData(5, 9, 5, true).numTiles());
149 EXPECT_EQ(3, TilingData(5, 10, 5, true).numTiles());
150 EXPECT_EQ(3, TilingData(5, 11, 5, true).numTiles());
151 }
152
TEST(TilingDataTest,tileXIndexFromSrcCoord)153 TEST(TilingDataTest, tileXIndexFromSrcCoord)
154 {
155 EXPECT_EQ(0, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(0));
156 EXPECT_EQ(0, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(1));
157 EXPECT_EQ(0, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(2));
158 EXPECT_EQ(1, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(3));
159 EXPECT_EQ(1, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(4));
160 EXPECT_EQ(1, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(5));
161 EXPECT_EQ(2, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(6));
162 EXPECT_EQ(2, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(7));
163 EXPECT_EQ(2, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(8));
164 EXPECT_EQ(3, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(9));
165 EXPECT_EQ(3, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(10));
166 EXPECT_EQ(3, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(11));
167
168 EXPECT_EQ(0, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(0));
169 EXPECT_EQ(0, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(1));
170 EXPECT_EQ(1, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(2));
171 EXPECT_EQ(2, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(3));
172 EXPECT_EQ(3, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(4));
173 EXPECT_EQ(4, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(5));
174 EXPECT_EQ(5, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(6));
175 EXPECT_EQ(6, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(7));
176 EXPECT_EQ(7, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(8));
177 EXPECT_EQ(7, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(9));
178 EXPECT_EQ(7, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(10));
179 EXPECT_EQ(7, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(11));
180 }
TEST(TilingDataTest,tileYIndexFromSrcCoord)181 TEST(TilingDataTest, tileYIndexFromSrcCoord)
182 {
183 EXPECT_EQ(0, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(0));
184 EXPECT_EQ(0, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(1));
185 EXPECT_EQ(0, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(2));
186 EXPECT_EQ(1, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(3));
187 EXPECT_EQ(1, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(4));
188 EXPECT_EQ(1, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(5));
189 EXPECT_EQ(2, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(6));
190 EXPECT_EQ(2, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(7));
191 EXPECT_EQ(2, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(8));
192 EXPECT_EQ(3, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(9));
193 EXPECT_EQ(3, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(10));
194 EXPECT_EQ(3, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(11));
195
196 EXPECT_EQ(0, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(0));
197 EXPECT_EQ(0, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(1));
198 EXPECT_EQ(1, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(2));
199 EXPECT_EQ(2, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(3));
200 EXPECT_EQ(3, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(4));
201 EXPECT_EQ(4, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(5));
202 EXPECT_EQ(5, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(6));
203 EXPECT_EQ(6, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(7));
204 EXPECT_EQ(7, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(8));
205 EXPECT_EQ(7, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(9));
206 EXPECT_EQ(7, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(10));
207 EXPECT_EQ(7, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(11));
208 }
209
TEST(TilingDataTest,tileSizeX)210 TEST(TilingDataTest, tileSizeX)
211 {
212 EXPECT_EQ(5, TilingData(5, 5, 5, false).tileSizeX(0));
213 EXPECT_EQ(5, TilingData(5, 5, 5, true).tileSizeX(0));
214
215 EXPECT_EQ(5, TilingData(5, 6, 6, false).tileSizeX(0));
216 EXPECT_EQ(1, TilingData(5, 6, 6, false).tileSizeX(1));
217 EXPECT_EQ(4, TilingData(5, 6, 6, true).tileSizeX(0));
218 EXPECT_EQ(2, TilingData(5, 6, 6, true).tileSizeX(1));
219
220 EXPECT_EQ(5, TilingData(5, 8, 8, false).tileSizeX(0));
221 EXPECT_EQ(3, TilingData(5, 8, 8, false).tileSizeX(1));
222 EXPECT_EQ(4, TilingData(5, 8, 8, true).tileSizeX(0));
223 EXPECT_EQ(4, TilingData(5, 8, 8, true).tileSizeX(1));
224
225 EXPECT_EQ(5, TilingData(5, 10, 10, false).tileSizeX(0));
226 EXPECT_EQ(5, TilingData(5, 10, 10, false).tileSizeX(1));
227 EXPECT_EQ(4, TilingData(5, 10, 10, true).tileSizeX(0));
228 EXPECT_EQ(3, TilingData(5, 10, 10, true).tileSizeX(1));
229 EXPECT_EQ(3, TilingData(5, 10, 10, true).tileSizeX(2));
230
231 EXPECT_EQ(4, TilingData(5, 11, 11, true).tileSizeX(2));
232 EXPECT_EQ(3, TilingData(5, 12, 12, true).tileSizeX(2));
233 }
TEST(TilingDataTest,tileSizeY)234 TEST(TilingDataTest, tileSizeY)
235 {
236 EXPECT_EQ(5, TilingData(5, 5, 5, false).tileSizeY(0));
237 EXPECT_EQ(5, TilingData(5, 5, 5, true).tileSizeY(0));
238
239 EXPECT_EQ(5, TilingData(5, 6, 6, false).tileSizeY(0));
240 EXPECT_EQ(1, TilingData(5, 6, 6, false).tileSizeY(1));
241 EXPECT_EQ(4, TilingData(5, 6, 6, true).tileSizeY(0));
242 EXPECT_EQ(2, TilingData(5, 6, 6, true).tileSizeY(1));
243
244 EXPECT_EQ(5, TilingData(5, 8, 8, false).tileSizeY(0));
245 EXPECT_EQ(3, TilingData(5, 8, 8, false).tileSizeY(1));
246 EXPECT_EQ(4, TilingData(5, 8, 8, true).tileSizeY(0));
247 EXPECT_EQ(4, TilingData(5, 8, 8, true).tileSizeY(1));
248
249 EXPECT_EQ(5, TilingData(5, 10, 10, false).tileSizeY(0));
250 EXPECT_EQ(5, TilingData(5, 10, 10, false).tileSizeY(1));
251 EXPECT_EQ(4, TilingData(5, 10, 10, true).tileSizeY(0));
252 EXPECT_EQ(3, TilingData(5, 10, 10, true).tileSizeY(1));
253 EXPECT_EQ(3, TilingData(5, 10, 10, true).tileSizeY(2));
254
255 EXPECT_EQ(4, TilingData(5, 11, 11, true).tileSizeY(2));
256 EXPECT_EQ(3, TilingData(5, 12, 12, true).tileSizeY(2));
257 }
258
TEST(TilingDataTest,tileSizeX_and_tilePositionX)259 TEST(TilingDataTest, tileSizeX_and_tilePositionX)
260 {
261 // Single tile cases:
262 EXPECT_EQ(1, TilingData(3, 1, 1, false).tileSizeX(0));
263 EXPECT_EQ(0, TilingData(3, 1, 1, false).tilePositionX(0));
264 EXPECT_EQ(1, TilingData(3, 1, 100, false).tileSizeX(0));
265 EXPECT_EQ(0, TilingData(3, 1, 100, false).tilePositionX(0));
266 EXPECT_EQ(3, TilingData(3, 3, 1, false).tileSizeX(0));
267 EXPECT_EQ(0, TilingData(3, 3, 1, false).tilePositionX(0));
268 EXPECT_EQ(3, TilingData(3, 3, 100, false).tileSizeX(0));
269 EXPECT_EQ(0, TilingData(3, 3, 100, false).tilePositionX(0));
270 EXPECT_EQ(1, TilingData(3, 1, 1, true).tileSizeX(0));
271 EXPECT_EQ(0, TilingData(3, 1, 1, true).tilePositionX(0));
272 EXPECT_EQ(1, TilingData(3, 1, 100, true).tileSizeX(0));
273 EXPECT_EQ(0, TilingData(3, 1, 100, true).tilePositionX(0));
274 EXPECT_EQ(3, TilingData(3, 3, 1, true).tileSizeX(0));
275 EXPECT_EQ(0, TilingData(3, 3, 1, true).tilePositionX(0));
276 EXPECT_EQ(3, TilingData(3, 3, 100, true).tileSizeX(0));
277 EXPECT_EQ(0, TilingData(3, 3, 100, true).tilePositionX(0));
278
279 // Multiple tiles:
280 // no border
281 // positions 0, 3
282 EXPECT_EQ(2, TilingData(3, 6, 1, false).numTiles());
283 EXPECT_EQ(3, TilingData(3, 6, 1, false).tileSizeX(0));
284 EXPECT_EQ(3, TilingData(3, 6, 1, false).tileSizeX(1));
285 EXPECT_EQ(0, TilingData(3, 6, 1, false).tilePositionX(0));
286 EXPECT_EQ(3, TilingData(3, 6, 1, false).tilePositionX(1));
287 EXPECT_EQ(3, TilingData(3, 6, 100, false).tileSizeX(0));
288 EXPECT_EQ(3, TilingData(3, 6, 100, false).tileSizeX(1));
289 EXPECT_EQ(0, TilingData(3, 6, 100, false).tilePositionX(0));
290 EXPECT_EQ(3, TilingData(3, 6, 100, false).tilePositionX(1));
291
292 // Multiple tiles:
293 // with border
294 // positions 0, 2, 3, 4
295 EXPECT_EQ(4, TilingData(3, 6, 1, true).numTiles());
296 EXPECT_EQ(2, TilingData(3, 6, 1, true).tileSizeX(0));
297 EXPECT_EQ(1, TilingData(3, 6, 1, true).tileSizeX(1));
298 EXPECT_EQ(1, TilingData(3, 6, 1, true).tileSizeX(2));
299 EXPECT_EQ(2, TilingData(3, 6, 1, true).tileSizeX(3));
300 EXPECT_EQ(0, TilingData(3, 6, 1, true).tilePositionX(0));
301 EXPECT_EQ(2, TilingData(3, 6, 1, true).tilePositionX(1));
302 EXPECT_EQ(3, TilingData(3, 6, 1, true).tilePositionX(2));
303 EXPECT_EQ(4, TilingData(3, 6, 1, true).tilePositionX(3));
304 EXPECT_EQ(2, TilingData(3, 6, 100, true).tileSizeX(0));
305 EXPECT_EQ(1, TilingData(3, 6, 100, true).tileSizeX(1));
306 EXPECT_EQ(1, TilingData(3, 6, 100, true).tileSizeX(2));
307 EXPECT_EQ(2, TilingData(3, 6, 100, true).tileSizeX(3));
308 EXPECT_EQ(0, TilingData(3, 6, 100, true).tilePositionX(0));
309 EXPECT_EQ(2, TilingData(3, 6, 100, true).tilePositionX(1));
310 EXPECT_EQ(3, TilingData(3, 6, 100, true).tilePositionX(2));
311 EXPECT_EQ(4, TilingData(3, 6, 100, true).tilePositionX(3));
312 }
313
TEST(TilingDataTest,tileSizeY_and_tilePositionY)314 TEST(TilingDataTest, tileSizeY_and_tilePositionY)
315 {
316 // Single tile cases:
317 EXPECT_EQ(1, TilingData(3, 1, 1, false).tileSizeY(0));
318 EXPECT_EQ(0, TilingData(3, 1, 1, false).tilePositionY(0));
319 EXPECT_EQ(1, TilingData(3, 100, 1, false).tileSizeY(0));
320 EXPECT_EQ(0, TilingData(3, 100, 1, false).tilePositionY(0));
321 EXPECT_EQ(3, TilingData(3, 1, 3, false).tileSizeY(0));
322 EXPECT_EQ(0, TilingData(3, 1, 3, false).tilePositionY(0));
323 EXPECT_EQ(3, TilingData(3, 100, 3, false).tileSizeY(0));
324 EXPECT_EQ(0, TilingData(3, 100, 3, false).tilePositionY(0));
325 EXPECT_EQ(1, TilingData(3, 1, 1, true).tileSizeY(0));
326 EXPECT_EQ(0, TilingData(3, 1, 1, true).tilePositionY(0));
327 EXPECT_EQ(1, TilingData(3, 100, 1, true).tileSizeY(0));
328 EXPECT_EQ(0, TilingData(3, 100, 1, true).tilePositionY(0));
329 EXPECT_EQ(3, TilingData(3, 1, 3, true).tileSizeY(0));
330 EXPECT_EQ(0, TilingData(3, 1, 3, true).tilePositionY(0));
331 EXPECT_EQ(3, TilingData(3, 100, 3, true).tileSizeY(0));
332 EXPECT_EQ(0, TilingData(3, 100, 3, true).tilePositionY(0));
333
334 // Multiple tiles:
335 // no border
336 // positions 0, 3
337 EXPECT_EQ(2, TilingData(3, 1, 6, false).numTiles());
338 EXPECT_EQ(3, TilingData(3, 1, 6, false).tileSizeY(0));
339 EXPECT_EQ(3, TilingData(3, 1, 6, false).tileSizeY(1));
340 EXPECT_EQ(0, TilingData(3, 1, 6, false).tilePositionY(0));
341 EXPECT_EQ(3, TilingData(3, 1, 6, false).tilePositionY(1));
342 EXPECT_EQ(3, TilingData(3, 100, 6, false).tileSizeY(0));
343 EXPECT_EQ(3, TilingData(3, 100, 6, false).tileSizeY(1));
344 EXPECT_EQ(0, TilingData(3, 100, 6, false).tilePositionY(0));
345 EXPECT_EQ(3, TilingData(3, 100, 6, false).tilePositionY(1));
346
347 // Multiple tiles:
348 // with border
349 // positions 0, 2, 3, 4
350 EXPECT_EQ(4, TilingData(3, 1, 6, true).numTiles());
351 EXPECT_EQ(2, TilingData(3, 1, 6, true).tileSizeY(0));
352 EXPECT_EQ(1, TilingData(3, 1, 6, true).tileSizeY(1));
353 EXPECT_EQ(1, TilingData(3, 1, 6, true).tileSizeY(2));
354 EXPECT_EQ(2, TilingData(3, 1, 6, true).tileSizeY(3));
355 EXPECT_EQ(0, TilingData(3, 1, 6, true).tilePositionY(0));
356 EXPECT_EQ(2, TilingData(3, 1, 6, true).tilePositionY(1));
357 EXPECT_EQ(3, TilingData(3, 1, 6, true).tilePositionY(2));
358 EXPECT_EQ(4, TilingData(3, 1, 6, true).tilePositionY(3));
359 EXPECT_EQ(2, TilingData(3, 100, 6, true).tileSizeY(0));
360 EXPECT_EQ(1, TilingData(3, 100, 6, true).tileSizeY(1));
361 EXPECT_EQ(1, TilingData(3, 100, 6, true).tileSizeY(2));
362 EXPECT_EQ(2, TilingData(3, 100, 6, true).tileSizeY(3));
363 EXPECT_EQ(0, TilingData(3, 100, 6, true).tilePositionY(0));
364 EXPECT_EQ(2, TilingData(3, 100, 6, true).tilePositionY(1));
365 EXPECT_EQ(3, TilingData(3, 100, 6, true).tilePositionY(2));
366 EXPECT_EQ(4, TilingData(3, 100, 6, true).tilePositionY(3));
367 }
368
TEST(TilingDataTest,setTotalSize)369 TEST(TilingDataTest, setTotalSize)
370 {
371 TilingData data(5, 5, 5, false);
372 EXPECT_EQ(5, data.totalSizeX());
373 EXPECT_EQ(5, data.totalSizeY());
374 EXPECT_EQ(1, data.numTilesX());
375 EXPECT_EQ(5, data.tileSizeX(0));
376 EXPECT_EQ(1, data.numTilesY());
377 EXPECT_EQ(5, data.tileSizeY(0));
378
379 data.setTotalSize(6, 5);
380 EXPECT_EQ(6, data.totalSizeX());
381 EXPECT_EQ(5, data.totalSizeY());
382 EXPECT_EQ(2, data.numTilesX());
383 EXPECT_EQ(5, data.tileSizeX(0));
384 EXPECT_EQ(1, data.tileSizeX(1));
385 EXPECT_EQ(1, data.numTilesY());
386 EXPECT_EQ(5, data.tileSizeY(0));
387
388 data.setTotalSize(5, 12);
389 EXPECT_EQ(5, data.totalSizeX());
390 EXPECT_EQ(12, data.totalSizeY());
391 EXPECT_EQ(1, data.numTilesX());
392 EXPECT_EQ(5, data.tileSizeX(0));
393 EXPECT_EQ(3, data.numTilesY());
394 EXPECT_EQ(5, data.tileSizeY(0));
395 EXPECT_EQ(5, data.tileSizeY(1));
396 EXPECT_EQ(2, data.tileSizeY(2));
397 }
398
TEST(TilingDataTest,setMaxTextureSizeNoBorders)399 TEST(TilingDataTest, setMaxTextureSizeNoBorders)
400 {
401 TilingData data(8, 16, 32, false);
402 EXPECT_EQ(2, data.numTilesX());
403 EXPECT_EQ(4, data.numTilesY());
404
405 data.setMaxTextureSize(32);
406 EXPECT_EQ(32, data.maxTextureSize());
407 EXPECT_EQ(1, data.numTilesX());
408 EXPECT_EQ(1, data.numTilesY());
409
410 data.setMaxTextureSize(2);
411 EXPECT_EQ(2, data.maxTextureSize());
412 EXPECT_EQ(8, data.numTilesX());
413 EXPECT_EQ(16, data.numTilesY());
414
415 data.setMaxTextureSize(5);
416 EXPECT_EQ(5, data.maxTextureSize());
417 EXPECT_EQ(4, data.numTilesX());
418 EXPECT_EQ(7, data.numTilesY());
419 }
420
TEST(TilingDataTest,setMaxTextureSizeBorders)421 TEST(TilingDataTest, setMaxTextureSizeBorders)
422 {
423 TilingData data(8, 16, 32, true);
424 EXPECT_EQ(3, data.numTilesX());
425 EXPECT_EQ(5, data.numTilesY());
426
427 data.setMaxTextureSize(32);
428 EXPECT_EQ(32, data.maxTextureSize());
429 EXPECT_EQ(1, data.numTilesX());
430 EXPECT_EQ(1, data.numTilesY());
431
432 data.setMaxTextureSize(2);
433 EXPECT_EQ(2, data.maxTextureSize());
434 EXPECT_EQ(0, data.numTilesX());
435 EXPECT_EQ(0, data.numTilesY());
436
437 data.setMaxTextureSize(5);
438 EXPECT_EQ(5, data.maxTextureSize());
439 EXPECT_EQ(5, data.numTilesX());
440 EXPECT_EQ(10, data.numTilesY());
441 }
442
443 } // namespace
444