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