• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.graphics.cts;
18 
19 import junit.framework.TestCase;
20 import android.graphics.Matrix;
21 import android.graphics.Path;
22 import android.graphics.RectF;
23 
24 public class PathTest extends TestCase {
25 
26     // Test constants
27     private static final float LEFT = 10.0f;
28     private static final float RIGHT = 50.0f;
29     private static final float TOP = 10.0f;
30     private static final float BOTTOM = 50.0f;
31     private static final float XCOORD = 40.0f;
32     private static final float YCOORD = 40.0f;
33 
testConstructor()34     public void testConstructor() {
35         // new the Path instance
36         new Path();
37 
38         // another the Path instance with different params
39         new Path(new Path());
40     }
41 
testAddRect1()42     public void testAddRect1() {
43 
44         // new the Path instance
45         Path path = new Path();
46         assertTrue(path.isEmpty());
47         RectF rect = new RectF(LEFT, TOP, RIGHT, BOTTOM);
48         path.addRect(rect, Path.Direction.CW);
49         assertFalse(path.isEmpty());
50     }
51 
testAddRect2()52     public void testAddRect2() {
53 
54         // new the Path instance
55         Path path = new Path();
56         assertTrue(path.isEmpty());
57         path.addRect(LEFT, TOP, RIGHT, BOTTOM, Path.Direction.CW);
58         assertFalse(path.isEmpty());
59     }
60 
testMoveTo()61     public void testMoveTo() {
62         // new the Path instance
63         Path path = new Path();
64         path.moveTo(10.0f, 10.0f);
65     }
66 
testSet()67     public void testSet() {
68         // new the Path instance
69         Path path = new Path();
70         assertTrue(path.isEmpty());
71         Path path1 = new Path();
72         setPath(path1);
73         path.set(path1);
74         assertFalse(path.isEmpty());
75     }
76 
testAccessFillType()77     public void testAccessFillType() {
78         // set the expected value
79         Path.FillType expected1 = Path.FillType.EVEN_ODD;
80         Path.FillType expected2 = Path.FillType.INVERSE_EVEN_ODD;
81         Path.FillType expected3 = Path.FillType.INVERSE_WINDING;
82         Path.FillType expected4 = Path.FillType.WINDING;
83 
84         // new the Path instance
85         Path path = new Path();
86         // set FillType by {@link Path#setFillType(FillType)}
87         path.setFillType(Path.FillType.EVEN_ODD);
88         assertEquals(expected1, path.getFillType());
89         path.setFillType(Path.FillType.INVERSE_EVEN_ODD);
90         assertEquals(expected2, path.getFillType());
91         path.setFillType(Path.FillType.INVERSE_WINDING);
92         assertEquals(expected3, path.getFillType());
93         path.setFillType(Path.FillType.WINDING);
94         assertEquals(expected4, path.getFillType());
95     }
96 
testRQuadTo()97     public void testRQuadTo() {
98         // new the Path instance
99         Path path = new Path();
100         assertTrue(path.isEmpty());
101         path.rQuadTo(5.0f, 5.0f, 10.0f, 10.0f);
102         assertFalse(path.isEmpty());
103     }
104 
testTransform1()105     public void testTransform1() {
106         // new the Path instance
107         Path path = new Path();
108         assertTrue(path.isEmpty());
109         Path dst = new Path();
110         setPath(path);
111         path.transform(new Matrix(), dst);
112         assertFalse(dst.isEmpty());
113     }
114 
testTransform2()115     public void testTransform2() {
116 
117     }
118 
testLineTo()119     public void testLineTo() {
120         // new the Path instance
121         Path path = new Path();
122         assertTrue(path.isEmpty());
123         path.lineTo(XCOORD, YCOORD);
124         assertFalse(path.isEmpty());
125     }
126 
testClose()127     public void testClose() {
128         // new the Path instance
129         Path path = new Path();
130         assertTrue(path.isEmpty());
131         setPath(path);
132         path.close();
133     }
134 
testQuadTo()135     public void testQuadTo() {
136         // new the Path instance
137         Path path = new Path();
138         assertTrue(path.isEmpty());
139         path.quadTo(20.0f, 20.0f, 40.0f, 40.0f);
140         assertFalse(path.isEmpty());
141     }
142 
testAddCircle()143     public void testAddCircle() {
144         // new the Path instance
145         Path path = new Path();
146         assertTrue(path.isEmpty());
147         path.addCircle(XCOORD, YCOORD, 10.0f, Path.Direction.CW);
148         assertFalse(path.isEmpty());
149     }
150 
testArcTo1()151     public void testArcTo1() {
152         // new the Path instance
153         Path path = new Path();
154         assertTrue(path.isEmpty());
155         RectF oval = new RectF(LEFT, TOP, RIGHT, BOTTOM);
156         path.arcTo(oval, 0.0f, 30.0f, true);
157         assertFalse(path.isEmpty());
158     }
159 
testArcTo2()160     public void testArcTo2() {
161         // new the Path instance
162         Path path = new Path();
163         assertTrue(path.isEmpty());
164         RectF oval = new RectF(LEFT, TOP, RIGHT, BOTTOM);
165         path.arcTo(oval, 0.0f, 30.0f);
166         assertFalse(path.isEmpty());
167     }
168 
testComputeBounds1()169     public void testComputeBounds1() {
170 
171         RectF expected = new RectF(0.0f, 0.0f, 0.0f, 0.0f);
172         // new the Path instance
173         Path path = new Path();
174         assertTrue(path.isEmpty());
175         RectF bounds = new RectF();
176         path.computeBounds(bounds, true);
177         assertEquals(expected.width(), bounds.width());
178         assertEquals(expected.height(), bounds.height());
179         path.computeBounds(bounds, false);
180         assertEquals(expected.width(), bounds.width());
181         assertEquals(expected.height(), bounds.height());
182     }
183 
testComputeBounds2()184     public void testComputeBounds2() {
185 
186         RectF expected = new RectF(LEFT, TOP, RIGHT, BOTTOM);
187         // new the Path instance
188         Path path = new Path();
189         assertTrue(path.isEmpty());
190         RectF bounds = new RectF(LEFT, TOP, RIGHT, BOTTOM);
191         path.addRect(bounds, Path.Direction.CW);
192         path.computeBounds(bounds, true);
193         assertEquals(expected.width(), bounds.width());
194         assertEquals(expected.height(), bounds.height());
195         path.computeBounds(bounds, false);
196         assertEquals(expected.width(), bounds.width());
197         assertEquals(expected.height(), bounds.height());
198     }
199 
testRMoveTo()200     public void testRMoveTo() {
201         // new the Path instance
202     }
203 
testSetLastPoint()204     public void testSetLastPoint() {
205         // new the Path instance
206         Path path = new Path();
207         path.setLastPoint(10.0f, 10.0f);
208     }
209 
testRLineTo()210     public void testRLineTo() {
211         // new the Path instance
212         Path path = new Path();
213         assertTrue(path.isEmpty());
214         path.rLineTo(10.0f, 10.0f);
215         assertFalse(path.isEmpty());
216     }
217 
testIsEmpty()218     public void testIsEmpty() {
219 
220         // new the Path instance
221         Path path = new Path();
222         assertTrue(path.isEmpty());
223         setPath(path);
224         assertFalse(path.isEmpty());
225     }
226 
testRewind()227     public void testRewind() {
228 
229         // set the expected value
230         Path.FillType expected = Path.FillType.EVEN_ODD;
231 
232         // new the Path instance
233         Path path = new Path();
234         assertTrue(path.isEmpty());
235         setPath(path);
236         path.rewind();
237         path.setFillType(Path.FillType.EVEN_ODD);
238         assertTrue(path.isEmpty());
239         assertEquals(expected, path.getFillType());
240     }
241 
testAddOval()242     public void testAddOval() {
243         // new the Path instance
244         Path path = new Path();
245         assertTrue(path.isEmpty());
246         RectF oval = new RectF(LEFT, TOP, RIGHT, BOTTOM);
247         path.addOval(oval, Path.Direction.CW);
248         assertFalse(path.isEmpty());
249     }
250 
testIsRect()251     public void testIsRect() {
252 
253         // new the Path instance
254         Path path = new Path();
255         assertTrue(path.isEmpty());
256         setPath(path);
257     }
258 
testIncReserve()259     public void testIncReserve() {
260     }
261 
testAddPath1()262     public void testAddPath1() {
263         // new the Path instance
264         Path path = new Path();
265         assertTrue(path.isEmpty());
266         Path src = new Path();
267         setPath(src);
268         path.addPath(src, 10.0f, 10.0f);
269         assertFalse(path.isEmpty());
270     }
271 
testAddPath2()272     public void testAddPath2() {
273         // new the Path instance
274         Path path = new Path();
275         assertTrue(path.isEmpty());
276         Path src = new Path();
277         setPath(src);
278         path.addPath(src);
279         assertFalse(path.isEmpty());
280     }
281 
testAddPath3()282     public void testAddPath3() {
283         // new the Path instance
284         Path path = new Path();
285         assertTrue(path.isEmpty());
286         Path src = new Path();
287         setPath(src);
288         Matrix matrix = new Matrix();
289         path.addPath(src, matrix);
290         assertFalse(path.isEmpty());
291     }
292 
testAddRoundRect1()293     public void testAddRoundRect1() {
294         // new the Path instance
295         Path path = new Path();
296         assertTrue(path.isEmpty());
297         RectF rect = new RectF(LEFT, TOP, RIGHT, BOTTOM);
298         path.addRoundRect(rect, XCOORD, YCOORD, Path.Direction.CW);
299         assertFalse(path.isEmpty());
300     }
301 
testAddRoundRect2()302     public void testAddRoundRect2() {
303         // new the Path instance
304         Path path = new Path();
305         assertTrue(path.isEmpty());
306         RectF rect = new RectF(LEFT, TOP, RIGHT, BOTTOM);
307         float[] radii = new float[8];
308         for (int i = 0; i < 8; i++) {
309             radii[i] = 10.0f + i * 5.0f;
310         }
311         path.addRoundRect(rect, radii, Path.Direction.CW);
312         assertFalse(path.isEmpty());
313     }
314 
testIsInverseFillType()315     public void testIsInverseFillType() {
316 
317         // new the Path instance
318         Path path = new Path();
319         assertFalse(path.isInverseFillType());
320         path.setFillType(Path.FillType.INVERSE_EVEN_ODD);
321         assertTrue(path.isInverseFillType());
322     }
323 
testOffset1()324     public void testOffset1() {
325         // new the Path instance
326         Path path = new Path();
327         assertTrue(path.isEmpty());
328         setPath(path);
329         Path dst = new Path();
330         path.offset(XCOORD, YCOORD, dst);
331         assertFalse(dst.isEmpty());
332     }
333 
testOffset2()334     public void testOffset2() {
335         // new the Path instance
336     }
337 
testCubicTo()338     public void testCubicTo() {
339         // new the Path instance
340         Path path = new Path();
341         assertTrue(path.isEmpty());
342         path.cubicTo(10.0f, 10.0f, 20.0f, 20.0f, 30.0f, 30.0f);
343         assertFalse(path.isEmpty());
344     }
345 
testReset()346     public void testReset() {
347         // new the Path instance
348         Path path = new Path();
349         assertTrue(path.isEmpty());
350         Path path1 = new Path();
351         setPath(path1);
352         path.set(path1);
353         assertFalse(path.isEmpty());
354         path.reset();
355         assertTrue(path.isEmpty());
356     }
357 
testToggleInverseFillType()358     public void testToggleInverseFillType() {
359         // new the Path instance
360         Path path = new Path();
361         assertTrue(path.isEmpty());
362         path.toggleInverseFillType();
363         assertTrue(path.isInverseFillType());
364     }
365 
testAddArc()366     public void testAddArc() {
367         // new the Path instance
368         Path path = new Path();
369         assertTrue(path.isEmpty());
370         RectF oval = new RectF(LEFT, TOP, RIGHT, BOTTOM);
371         path.addArc(oval, 0.0f, 30.0f);
372         assertFalse(path.isEmpty());
373     }
374 
testRCubicTo()375     public void testRCubicTo() {
376         // new the Path instance
377         Path path = new Path();
378         assertTrue(path.isEmpty());
379         path.rCubicTo(10.0f, 10.0f, 11.0f, 11.0f, 12.0f, 12.0f);
380         assertFalse(path.isEmpty());
381     }
382 
setPath(Path path)383     private void setPath(Path path) {
384         RectF rect = new RectF(LEFT, TOP, RIGHT, BOTTOM);
385         path.addRect(rect, Path.Direction.CW);
386     }
387 }
388