• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package android.graphics;
2 
3 import static com.google.common.truth.Truth.assertThat;
4 
5 import androidx.test.ext.junit.runners.AndroidJUnit4;
6 import org.junit.Test;
7 import org.junit.runner.RunWith;
8 
9 /** Compatibility test for {@link Path} */
10 @RunWith(AndroidJUnit4.class)
11 public class PathTest {
12 
13   // Test constants
14   private static final float LEFT = 10.0f;
15   private static final float RIGHT = 50.0f;
16   private static final float TOP = 10.0f;
17   private static final float BOTTOM = 50.0f;
18   private static final float XCOORD = 40.0f;
19   private static final float YCOORD = 40.0f;
20 
21   @Test
moveTo()22   public void moveTo() {
23     Path path = new Path();
24     assertThat(path.isEmpty()).isTrue();
25 
26     path.moveTo(0, 0);
27     assertThat(path.isEmpty()).isFalse();
28   }
29 
30   @Test
lineTo()31   public void lineTo() {
32     Path path = new Path();
33     assertThat(path.isEmpty()).isTrue();
34     path.lineTo(XCOORD, YCOORD);
35     assertThat(path.isEmpty()).isFalse();
36   }
37 
38   @Test
quadTo()39   public void quadTo() {
40     Path path = new Path();
41     assertThat(path.isEmpty()).isTrue();
42     path.quadTo(20.0f, 20.0f, 40.0f, 40.0f);
43     assertThat(path.isEmpty()).isFalse();
44   }
45 
46   @Test
addRect1()47   public void addRect1() {
48     Path path = new Path();
49     assertThat(path.isEmpty()).isTrue();
50     RectF rect = new RectF(LEFT, TOP, RIGHT, BOTTOM);
51     path.addRect(rect, Path.Direction.CW);
52     assertThat(path.isEmpty()).isFalse();
53   }
54 
55   @Test
addRect2()56   public void addRect2() {
57     Path path = new Path();
58     assertThat(path.isEmpty()).isTrue();
59     path.addRect(LEFT, TOP, RIGHT, BOTTOM, Path.Direction.CW);
60     assertThat(path.isEmpty()).isFalse();
61   }
62 
63   @Test
getFillType()64   public void getFillType() {
65     Path path = new Path();
66     path.setFillType(Path.FillType.EVEN_ODD);
67     assertThat(path.getFillType()).isEqualTo(Path.FillType.EVEN_ODD);
68   }
69 
70   @Test
transform()71   public void transform() {
72     Path path = new Path();
73     assertThat(path.isEmpty()).isTrue();
74 
75     Path dst = new Path();
76     path.addRect(new RectF(LEFT, TOP, RIGHT, BOTTOM), Path.Direction.CW);
77     path.transform(new Matrix(), dst);
78 
79     assertThat(dst.isEmpty()).isFalse();
80   }
81 
82   @Test
testAddCircle()83   public void testAddCircle() {
84     // new the Path instance
85     Path path = new Path();
86     assertThat(path.isEmpty()).isTrue();
87     path.addCircle(XCOORD, YCOORD, 10.0f, Path.Direction.CW);
88     assertThat(path.isEmpty()).isFalse();
89   }
90 
91   @Test
arcTo1()92   public void arcTo1() {
93     Path path = new Path();
94     assertThat(path.isEmpty()).isTrue();
95     RectF oval = new RectF(LEFT, TOP, RIGHT, BOTTOM);
96     path.arcTo(oval, 0.0f, 30.0f, true);
97     assertThat(path.isEmpty()).isFalse();
98   }
99 
100   @Test
arcTo2()101   public void arcTo2() {
102     Path path = new Path();
103     assertThat(path.isEmpty()).isTrue();
104     RectF oval = new RectF(LEFT, TOP, RIGHT, BOTTOM);
105     path.arcTo(oval, 0.0f, 30.0f);
106     assertThat(path.isEmpty()).isFalse();
107   }
108 
109   @Test
close()110   public void close() {
111     Path path = new Path();
112     assertThat(path.isEmpty()).isTrue();
113     path.close();
114   }
115 
116   @Test
invalidArc_doesNotNPE()117   public void invalidArc_doesNotNPE() {
118     Path path = new Path();
119     // This arc is invalid because the bounding rectangle has left > right and top > bottom.
120     path.arcTo(new RectF(1, 1, 0, 0), 0, 30);
121     assertThat(path.isEmpty()).isTrue();
122   }
123 }
124