2011-04-12 Adrienne Walker <enne@google.com>
[WebKit-https.git] / Source / WebKit / chromium / tests / TilingDataTest.cpp
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
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
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(1, TilingData(2,  2,  2, false).numTiles());
64     EXPECT_EQ(1, TilingData(3,  3,  3, false).numTiles());
65
66     EXPECT_EQ(1, TilingData(4,  1,  4, false).numTiles());
67     EXPECT_EQ(1, TilingData(4,  2,  4, false).numTiles());
68     EXPECT_EQ(1, TilingData(4,  3,  4, false).numTiles());
69     EXPECT_EQ(1, TilingData(4,  4,  4, false).numTiles());
70     EXPECT_EQ(2, TilingData(4,  5,  4, false).numTiles());
71     EXPECT_EQ(2, TilingData(4,  6,  4, false).numTiles());
72     EXPECT_EQ(2, TilingData(4,  7,  4, false).numTiles());
73     EXPECT_EQ(2, TilingData(4,  8,  4, false).numTiles());
74     EXPECT_EQ(3, TilingData(4,  9,  4, false).numTiles());
75     EXPECT_EQ(3, TilingData(4, 10,  4, false).numTiles());
76     EXPECT_EQ(3, TilingData(4, 11,  4, false).numTiles());
77
78     EXPECT_EQ(1, TilingData(5,  1,  5, false).numTiles());
79     EXPECT_EQ(1, TilingData(5,  2,  5, false).numTiles());
80     EXPECT_EQ(1, TilingData(5,  3,  5, false).numTiles());
81     EXPECT_EQ(1, TilingData(5,  4,  5, false).numTiles());
82     EXPECT_EQ(1, TilingData(5,  5,  5, false).numTiles());
83     EXPECT_EQ(2, TilingData(5,  6,  5, false).numTiles());
84     EXPECT_EQ(2, TilingData(5,  7,  5, false).numTiles());
85     EXPECT_EQ(2, TilingData(5,  8,  5, false).numTiles());
86     EXPECT_EQ(2, TilingData(5,  9,  5, false).numTiles());
87     EXPECT_EQ(2, TilingData(5, 10,  5, false).numTiles());
88     EXPECT_EQ(3, TilingData(5, 11,  5, false).numTiles());
89
90     EXPECT_EQ(1, TilingData(16, 16, 16, false).numTiles());
91     EXPECT_EQ(1, TilingData(17, 16, 16, false).numTiles());
92     EXPECT_EQ(4, TilingData(15, 16, 16, false).numTiles());
93     EXPECT_EQ(4, TilingData(8, 16, 16, false).numTiles());
94     EXPECT_EQ(6, TilingData(8, 17, 16, false).numTiles());
95 }
96
97 TEST(TilingDataTest, numTiles_TilingWithBorders)
98 {
99     EXPECT_EQ(0, TilingData(0,  0,  0, true).numTiles());
100     EXPECT_EQ(0, TilingData(0,  4,  0, true).numTiles());
101     EXPECT_EQ(0, TilingData(0,  0,  4, true).numTiles());
102     EXPECT_EQ(0, TilingData(4,  4,  0, true).numTiles());
103     EXPECT_EQ(0, TilingData(4,  0,  4, true).numTiles());
104     EXPECT_EQ(0, TilingData(-8, 1,  1, true).numTiles());
105     EXPECT_EQ(0, TilingData(-1, 1,  1, true).numTiles());
106     EXPECT_EQ(0, TilingData(0,  1,  1, true).numTiles());
107
108     EXPECT_EQ(0, TilingData(1,  1,  1, true).numTiles());
109     EXPECT_EQ(0, TilingData(1,  1,  2, true).numTiles());
110     EXPECT_EQ(0, TilingData(2,  2,  2, true).numTiles());
111
112     EXPECT_EQ(1, TilingData(3,  1,  3, true).numTiles());
113     EXPECT_EQ(1, TilingData(3,  2,  3, true).numTiles());
114     EXPECT_EQ(1, TilingData(3,  3,  3, true).numTiles());
115     EXPECT_EQ(2, TilingData(3,  4,  3, true).numTiles());
116     EXPECT_EQ(3, TilingData(3,  5,  3, true).numTiles());
117     EXPECT_EQ(4, TilingData(3,  6,  3, true).numTiles());
118     EXPECT_EQ(5, TilingData(3,  7,  3, true).numTiles());
119
120     EXPECT_EQ(1, TilingData(4,  1,  4, true).numTiles());
121     EXPECT_EQ(1, TilingData(4,  2,  4, true).numTiles());
122     EXPECT_EQ(1, TilingData(4,  3,  4, true).numTiles());
123     EXPECT_EQ(1, TilingData(4,  4,  4, true).numTiles());
124     EXPECT_EQ(2, TilingData(4,  5,  4, true).numTiles());
125     EXPECT_EQ(2, TilingData(4,  6,  4, true).numTiles());
126     EXPECT_EQ(3, TilingData(4,  7,  4, true).numTiles());
127     EXPECT_EQ(3, TilingData(4,  8,  4, true).numTiles());
128     EXPECT_EQ(4, TilingData(4,  9,  4, true).numTiles());
129     EXPECT_EQ(4, TilingData(4, 10,  4, true).numTiles());
130     EXPECT_EQ(5, TilingData(4, 11,  4, true).numTiles());
131
132     EXPECT_EQ(1, TilingData(5,  1,  5, true).numTiles());
133     EXPECT_EQ(1, TilingData(5,  2,  5, true).numTiles());
134     EXPECT_EQ(1, TilingData(5,  3,  5, true).numTiles());
135     EXPECT_EQ(1, TilingData(5,  4,  5, true).numTiles());
136     EXPECT_EQ(1, TilingData(5,  5,  5, true).numTiles());
137     EXPECT_EQ(2, TilingData(5,  6,  5, true).numTiles());
138     EXPECT_EQ(2, TilingData(5,  7,  5, true).numTiles());
139     EXPECT_EQ(2, TilingData(5,  8,  5, true).numTiles());
140     EXPECT_EQ(3, TilingData(5,  9,  5, true).numTiles());
141     EXPECT_EQ(3, TilingData(5, 10,  5, true).numTiles());
142     EXPECT_EQ(3, TilingData(5, 11,  5, true).numTiles());
143 }
144
145 TEST(TilingDataTest, tileXIndexFromSrcCoord)
146 {
147     EXPECT_EQ(0, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(0));
148     EXPECT_EQ(0, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(1));
149     EXPECT_EQ(0, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(2));
150     EXPECT_EQ(1, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(3));
151     EXPECT_EQ(1, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(4));
152     EXPECT_EQ(1, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(5));
153     EXPECT_EQ(2, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(6));
154     EXPECT_EQ(2, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(7));
155     EXPECT_EQ(2, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(8));
156     EXPECT_EQ(3, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(9));
157     EXPECT_EQ(3, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(10));
158     EXPECT_EQ(3, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(11));
159
160     EXPECT_EQ(0, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(0));
161     EXPECT_EQ(0, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(1));
162     EXPECT_EQ(1, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(2));
163     EXPECT_EQ(2, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(3));
164     EXPECT_EQ(3, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(4));
165     EXPECT_EQ(4, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(5));
166     EXPECT_EQ(5, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(6));
167     EXPECT_EQ(6, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(7));
168     EXPECT_EQ(7, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(8));
169     EXPECT_EQ(7, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(9));
170     EXPECT_EQ(7, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(10));
171     EXPECT_EQ(7, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(11));
172 }
173 TEST(TilingDataTest, tileYIndexFromSrcCoord)
174 {
175     EXPECT_EQ(0, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(0));
176     EXPECT_EQ(0, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(1));
177     EXPECT_EQ(0, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(2));
178     EXPECT_EQ(1, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(3));
179     EXPECT_EQ(1, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(4));
180     EXPECT_EQ(1, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(5));
181     EXPECT_EQ(2, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(6));
182     EXPECT_EQ(2, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(7));
183     EXPECT_EQ(2, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(8));
184     EXPECT_EQ(3, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(9));
185     EXPECT_EQ(3, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(10));
186     EXPECT_EQ(3, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(11));
187
188     EXPECT_EQ(0, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(0));
189     EXPECT_EQ(0, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(1));
190     EXPECT_EQ(1, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(2));
191     EXPECT_EQ(2, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(3));
192     EXPECT_EQ(3, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(4));
193     EXPECT_EQ(4, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(5));
194     EXPECT_EQ(5, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(6));
195     EXPECT_EQ(6, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(7));
196     EXPECT_EQ(7, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(8));
197     EXPECT_EQ(7, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(9));
198     EXPECT_EQ(7, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(10));
199     EXPECT_EQ(7, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(11));
200 }
201
202 TEST(TilingDataTest, tileSizeX)
203 {
204     EXPECT_EQ(5, TilingData(5,  5,  5, false).tileSizeX(0));
205     EXPECT_EQ(5, TilingData(5,  5,  5, true).tileSizeX(0));
206
207     EXPECT_EQ(5, TilingData(5,  6,  6, false).tileSizeX(0));
208     EXPECT_EQ(1, TilingData(5,  6,  6, false).tileSizeX(1));
209     EXPECT_EQ(4, TilingData(5,  6,  6, true).tileSizeX(0));
210     EXPECT_EQ(2, TilingData(5,  6,  6, true).tileSizeX(1));
211
212     EXPECT_EQ(5, TilingData(5,  8,  8, false).tileSizeX(0));
213     EXPECT_EQ(3, TilingData(5,  8,  8, false).tileSizeX(1));
214     EXPECT_EQ(4, TilingData(5,  8,  8, true).tileSizeX(0));
215     EXPECT_EQ(4, TilingData(5,  8,  8, true).tileSizeX(1));
216
217     EXPECT_EQ(5, TilingData(5, 10, 10, false).tileSizeX(0));
218     EXPECT_EQ(5, TilingData(5, 10, 10, false).tileSizeX(1));
219     EXPECT_EQ(4, TilingData(5, 10, 10, true).tileSizeX(0));
220     EXPECT_EQ(3, TilingData(5, 10, 10, true).tileSizeX(1));
221     EXPECT_EQ(3, TilingData(5, 10, 10, true).tileSizeX(2));
222
223     EXPECT_EQ(4, TilingData(5, 11, 11, true).tileSizeX(2));
224     EXPECT_EQ(3, TilingData(5, 12, 12, true).tileSizeX(2));
225 }
226 TEST(TilingDataTest, tileSizeY)
227 {
228     EXPECT_EQ(5, TilingData(5,  5,  5, false).tileSizeY(0));
229     EXPECT_EQ(5, TilingData(5,  5,  5, true).tileSizeY(0));
230
231     EXPECT_EQ(5, TilingData(5,  6,  6, false).tileSizeY(0));
232     EXPECT_EQ(1, TilingData(5,  6,  6, false).tileSizeY(1));
233     EXPECT_EQ(4, TilingData(5,  6,  6, true).tileSizeY(0));
234     EXPECT_EQ(2, TilingData(5,  6,  6, true).tileSizeY(1));
235
236     EXPECT_EQ(5, TilingData(5,  8,  8, false).tileSizeY(0));
237     EXPECT_EQ(3, TilingData(5,  8,  8, false).tileSizeY(1));
238     EXPECT_EQ(4, TilingData(5,  8,  8, true).tileSizeY(0));
239     EXPECT_EQ(4, TilingData(5,  8,  8, true).tileSizeY(1));
240
241     EXPECT_EQ(5, TilingData(5, 10, 10, false).tileSizeY(0));
242     EXPECT_EQ(5, TilingData(5, 10, 10, false).tileSizeY(1));
243     EXPECT_EQ(4, TilingData(5, 10, 10, true).tileSizeY(0));
244     EXPECT_EQ(3, TilingData(5, 10, 10, true).tileSizeY(1));
245     EXPECT_EQ(3, TilingData(5, 10, 10, true).tileSizeY(2));
246
247     EXPECT_EQ(4, TilingData(5, 11, 11, true).tileSizeY(2));
248     EXPECT_EQ(3, TilingData(5, 12, 12, true).tileSizeY(2));
249 }
250
251 TEST(TilingDataTest, tileSizeX_and_tilePositionX)
252 {
253     // Single tile cases:
254     EXPECT_EQ(1, TilingData(3, 1,   1, false).tileSizeX(0));
255     EXPECT_EQ(0, TilingData(3, 1,   1, false).tilePositionX(0));
256     EXPECT_EQ(1, TilingData(3, 1, 100, false).tileSizeX(0));
257     EXPECT_EQ(0, TilingData(3, 1, 100, false).tilePositionX(0));
258     EXPECT_EQ(3, TilingData(3, 3,   1, false).tileSizeX(0));
259     EXPECT_EQ(0, TilingData(3, 3,   1, false).tilePositionX(0));
260     EXPECT_EQ(3, TilingData(3, 3, 100, false).tileSizeX(0));
261     EXPECT_EQ(0, TilingData(3, 3, 100, false).tilePositionX(0));
262     EXPECT_EQ(1, TilingData(3, 1,   1, true).tileSizeX(0));
263     EXPECT_EQ(0, TilingData(3, 1,   1, true).tilePositionX(0));
264     EXPECT_EQ(1, TilingData(3, 1, 100, true).tileSizeX(0));
265     EXPECT_EQ(0, TilingData(3, 1, 100, true).tilePositionX(0));
266     EXPECT_EQ(3, TilingData(3, 3,   1, true).tileSizeX(0));
267     EXPECT_EQ(0, TilingData(3, 3,   1, true).tilePositionX(0));
268     EXPECT_EQ(3, TilingData(3, 3, 100, true).tileSizeX(0));
269     EXPECT_EQ(0, TilingData(3, 3, 100, true).tilePositionX(0));
270
271     // Multiple tiles:
272     // no border
273     // positions 0, 3
274     EXPECT_EQ(2, TilingData(3, 6,   1, false).numTiles());
275     EXPECT_EQ(3, TilingData(3, 6,   1, false).tileSizeX(0));
276     EXPECT_EQ(3, TilingData(3, 6,   1, false).tileSizeX(1));
277     EXPECT_EQ(0, TilingData(3, 6,   1, false).tilePositionX(0));
278     EXPECT_EQ(3, TilingData(3, 6,   1, false).tilePositionX(1));
279     EXPECT_EQ(3, TilingData(3, 6, 100, false).tileSizeX(0));
280     EXPECT_EQ(3, TilingData(3, 6, 100, false).tileSizeX(1));
281     EXPECT_EQ(0, TilingData(3, 6, 100, false).tilePositionX(0));
282     EXPECT_EQ(3, TilingData(3, 6, 100, false).tilePositionX(1));
283
284     // Multiple tiles:
285     // with border
286     // positions 0, 2, 3, 4
287     EXPECT_EQ(4, TilingData(3, 6,   1, true).numTiles());
288     EXPECT_EQ(2, TilingData(3, 6,   1, true).tileSizeX(0));
289     EXPECT_EQ(1, TilingData(3, 6,   1, true).tileSizeX(1));
290     EXPECT_EQ(1, TilingData(3, 6,   1, true).tileSizeX(2));
291     EXPECT_EQ(2, TilingData(3, 6,   1, true).tileSizeX(3));
292     EXPECT_EQ(0, TilingData(3, 6,   1, true).tilePositionX(0));
293     EXPECT_EQ(2, TilingData(3, 6,   1, true).tilePositionX(1));
294     EXPECT_EQ(3, TilingData(3, 6,   1, true).tilePositionX(2));
295     EXPECT_EQ(4, TilingData(3, 6,   1, true).tilePositionX(3));
296     EXPECT_EQ(2, TilingData(3, 6, 100, true).tileSizeX(0));
297     EXPECT_EQ(1, TilingData(3, 6, 100, true).tileSizeX(1));
298     EXPECT_EQ(1, TilingData(3, 6, 100, true).tileSizeX(2));
299     EXPECT_EQ(2, TilingData(3, 6, 100, true).tileSizeX(3));
300     EXPECT_EQ(0, TilingData(3, 6, 100, true).tilePositionX(0));
301     EXPECT_EQ(2, TilingData(3, 6, 100, true).tilePositionX(1));
302     EXPECT_EQ(3, TilingData(3, 6, 100, true).tilePositionX(2));
303     EXPECT_EQ(4, TilingData(3, 6, 100, true).tilePositionX(3));
304 }
305
306 TEST(TilingDataTest, tileSizeY_and_tilePositionY)
307 {
308     // Single tile cases:
309     EXPECT_EQ(1, TilingData(3,   1, 1, false).tileSizeY(0));
310     EXPECT_EQ(0, TilingData(3,   1, 1, false).tilePositionY(0));
311     EXPECT_EQ(1, TilingData(3, 100, 1, false).tileSizeY(0));
312     EXPECT_EQ(0, TilingData(3, 100, 1, false).tilePositionY(0));
313     EXPECT_EQ(3, TilingData(3,   1, 3, false).tileSizeY(0));
314     EXPECT_EQ(0, TilingData(3,   1, 3, false).tilePositionY(0));
315     EXPECT_EQ(3, TilingData(3, 100, 3, false).tileSizeY(0));
316     EXPECT_EQ(0, TilingData(3, 100, 3, false).tilePositionY(0));
317     EXPECT_EQ(1, TilingData(3,   1, 1, true).tileSizeY(0));
318     EXPECT_EQ(0, TilingData(3,   1, 1, true).tilePositionY(0));
319     EXPECT_EQ(1, TilingData(3, 100, 1, true).tileSizeY(0));
320     EXPECT_EQ(0, TilingData(3, 100, 1, true).tilePositionY(0));
321     EXPECT_EQ(3, TilingData(3,   1, 3, true).tileSizeY(0));
322     EXPECT_EQ(0, TilingData(3,   1, 3, true).tilePositionY(0));
323     EXPECT_EQ(3, TilingData(3, 100, 3, true).tileSizeY(0));
324     EXPECT_EQ(0, TilingData(3, 100, 3, true).tilePositionY(0));
325
326     // Multiple tiles:
327     // no border
328     // positions 0, 3
329     EXPECT_EQ(2, TilingData(3,   1, 6, false).numTiles());
330     EXPECT_EQ(3, TilingData(3,   1, 6, false).tileSizeY(0));
331     EXPECT_EQ(3, TilingData(3,   1, 6, false).tileSizeY(1));
332     EXPECT_EQ(0, TilingData(3,   1, 6, false).tilePositionY(0));
333     EXPECT_EQ(3, TilingData(3,   1, 6, false).tilePositionY(1));
334     EXPECT_EQ(3, TilingData(3, 100, 6, false).tileSizeY(0));
335     EXPECT_EQ(3, TilingData(3, 100, 6, false).tileSizeY(1));
336     EXPECT_EQ(0, TilingData(3, 100, 6, false).tilePositionY(0));
337     EXPECT_EQ(3, TilingData(3, 100, 6, false).tilePositionY(1));
338
339     // Multiple tiles:
340     // with border
341     // positions 0, 2, 3, 4
342     EXPECT_EQ(4, TilingData(3,   1, 6, true).numTiles());
343     EXPECT_EQ(2, TilingData(3,   1, 6, true).tileSizeY(0));
344     EXPECT_EQ(1, TilingData(3,   1, 6, true).tileSizeY(1));
345     EXPECT_EQ(1, TilingData(3,   1, 6, true).tileSizeY(2));
346     EXPECT_EQ(2, TilingData(3,   1, 6, true).tileSizeY(3));
347     EXPECT_EQ(0, TilingData(3,   1, 6, true).tilePositionY(0));
348     EXPECT_EQ(2, TilingData(3,   1, 6, true).tilePositionY(1));
349     EXPECT_EQ(3, TilingData(3,   1, 6, true).tilePositionY(2));
350     EXPECT_EQ(4, TilingData(3,   1, 6, true).tilePositionY(3));
351     EXPECT_EQ(2, TilingData(3, 100, 6, true).tileSizeY(0));
352     EXPECT_EQ(1, TilingData(3, 100, 6, true).tileSizeY(1));
353     EXPECT_EQ(1, TilingData(3, 100, 6, true).tileSizeY(2));
354     EXPECT_EQ(2, TilingData(3, 100, 6, true).tileSizeY(3));
355     EXPECT_EQ(0, TilingData(3, 100, 6, true).tilePositionY(0));
356     EXPECT_EQ(2, TilingData(3, 100, 6, true).tilePositionY(1));
357     EXPECT_EQ(3, TilingData(3, 100, 6, true).tilePositionY(2));
358     EXPECT_EQ(4, TilingData(3, 100, 6, true).tilePositionY(3));
359 }
360
361 TEST(TilingDataTest, setTotalSize)
362 {
363     TilingData data(5, 5, 5, false);
364     EXPECT_EQ(5, data.totalSizeX());
365     EXPECT_EQ(5, data.totalSizeY());
366     EXPECT_EQ(1, data.numTilesX());
367     EXPECT_EQ(5, data.tileSizeX(0));
368     EXPECT_EQ(1, data.numTilesY());
369     EXPECT_EQ(5, data.tileSizeY(0));
370
371     data.setTotalSize(6, 5);
372     EXPECT_EQ(6, data.totalSizeX());
373     EXPECT_EQ(5, data.totalSizeY());
374     EXPECT_EQ(2, data.numTilesX());
375     EXPECT_EQ(5, data.tileSizeX(0));
376     EXPECT_EQ(1, data.tileSizeX(1));
377     EXPECT_EQ(1, data.numTilesY());
378     EXPECT_EQ(5, data.tileSizeY(0));
379
380     data.setTotalSize(5, 12);
381     EXPECT_EQ(5, data.totalSizeX());
382     EXPECT_EQ(12, data.totalSizeY());
383     EXPECT_EQ(1, data.numTilesX());
384     EXPECT_EQ(5, data.tileSizeX(0));
385     EXPECT_EQ(3, data.numTilesY());
386     EXPECT_EQ(5, data.tileSizeY(0));
387     EXPECT_EQ(5, data.tileSizeY(1));
388     EXPECT_EQ(2, data.tileSizeY(2));
389 }
390
391 TEST(TilingDataTest, setMaxTextureSizeNoBorders)
392 {
393     TilingData data(8, 16, 32, false);
394     EXPECT_EQ(2, data.numTilesX());
395     EXPECT_EQ(4, data.numTilesY());
396
397     data.setMaxTextureSize(32);
398     EXPECT_EQ(32, data.maxTextureSize());
399     EXPECT_EQ(1, data.numTilesX());
400     EXPECT_EQ(1, data.numTilesY());
401
402     data.setMaxTextureSize(2);
403     EXPECT_EQ(2, data.maxTextureSize());
404     EXPECT_EQ(8, data.numTilesX());
405     EXPECT_EQ(16, data.numTilesY());
406
407     data.setMaxTextureSize(5);
408     EXPECT_EQ(5, data.maxTextureSize());
409     EXPECT_EQ(4, data.numTilesX());
410     EXPECT_EQ(7, data.numTilesY());
411 }
412
413 TEST(TilingDataTest, setMaxTextureSizeBorders)
414 {
415     TilingData data(8, 16, 32, true);
416     EXPECT_EQ(3, data.numTilesX());
417     EXPECT_EQ(5, data.numTilesY());
418
419     data.setMaxTextureSize(32);
420     EXPECT_EQ(32, data.maxTextureSize());
421     EXPECT_EQ(1, data.numTilesX());
422     EXPECT_EQ(1, data.numTilesY());
423
424     data.setMaxTextureSize(2);
425     EXPECT_EQ(2, data.maxTextureSize());
426     EXPECT_EQ(0, data.numTilesX());
427     EXPECT_EQ(0, data.numTilesY());
428
429     data.setMaxTextureSize(5);
430     EXPECT_EQ(5, data.maxTextureSize());
431     EXPECT_EQ(5, data.numTilesX());
432     EXPECT_EQ(10, data.numTilesY());
433 }
434
435 } // namespace