use of android.graphics.Canvas in project robolectric by robolectric.
the class ShadowCanvasTest method visualize_shouldReturnDescription.
@Test
public void visualize_shouldReturnDescription() throws Exception {
Canvas canvas = new Canvas(targetBitmap);
canvas.drawBitmap(imageBitmap, new Matrix(), new Paint());
canvas.drawBitmap(imageBitmap, new Matrix(), new Paint());
assertEquals("Bitmap for file:/an/image.jpg transformed by Matrix[pre=[], set={}, post=[]]\n" + "Bitmap for file:/an/image.jpg transformed by Matrix[pre=[], set={}, post=[]]", ShadowCanvas.visualize(canvas));
}
use of android.graphics.Canvas in project robolectric by robolectric.
the class ShadowCanvasTest method drawPath_shouldRecordThePathAndThePaint.
@Test
public void drawPath_shouldRecordThePathAndThePaint() throws Exception {
Canvas canvas = new Canvas(targetBitmap);
Path path = new Path();
path.lineTo(10, 10);
Paint paint = new Paint();
paint.setColor(Color.RED);
paint.setAlpha(7);
canvas.drawPath(path, paint);
// changing the values on this Paint shouldn't affect recorded painted path
paint.setColor(Color.BLUE);
paint.setAlpha(8);
ShadowCanvas shadow = shadowOf(canvas);
assertThat(shadow.getPathPaintHistoryCount()).isEqualTo(1);
ShadowPath drawnPath = shadowOf(shadow.getDrawnPath(0));
assertEquals(drawnPath.getPoints().get(0), new ShadowPath.Point(10, 10, LINE_TO));
Paint drawnPathPaint = shadow.getDrawnPathPaint(0);
assertThat(drawnPathPaint.getColor()).isEqualTo(Color.RED);
assertThat(drawnPathPaint.getAlpha()).isEqualTo(7);
}
use of android.graphics.Canvas in project robolectric by robolectric.
the class ShadowCanvasTest method drawCircle_shouldRecordCirclePaintHistoryEvents.
@Test
public void drawCircle_shouldRecordCirclePaintHistoryEvents() throws Exception {
Canvas canvas = new Canvas();
Paint paint0 = new Paint();
Paint paint1 = new Paint();
canvas.drawCircle(1, 2, 3, paint0);
canvas.drawCircle(4, 5, 6, paint1);
ShadowCanvas shadowCanvas = shadowOf(canvas);
assertThat(shadowCanvas.getDrawnCircle(0).centerX).isEqualTo(1);
assertThat(shadowCanvas.getDrawnCircle(0).centerY).isEqualTo(2);
assertThat(shadowCanvas.getDrawnCircle(0).radius).isEqualTo(3);
assertThat(shadowCanvas.getDrawnCircle(0).paint).isSameAs(paint0);
assertThat(shadowCanvas.getDrawnCircle(1).centerX).isEqualTo(4);
assertThat(shadowCanvas.getDrawnCircle(1).centerY).isEqualTo(5);
assertThat(shadowCanvas.getDrawnCircle(1).radius).isEqualTo(6);
assertThat(shadowCanvas.getDrawnCircle(1).paint).isSameAs(paint1);
}
use of android.graphics.Canvas in project robolectric by robolectric.
the class ShadowCanvasTest method shouldDescribeBitmapDrawing_WithMatrix.
@Test
public void shouldDescribeBitmapDrawing_WithMatrix() throws Exception {
Canvas canvas = new Canvas(targetBitmap);
canvas.drawBitmap(imageBitmap, new Matrix(), new Paint());
canvas.drawBitmap(imageBitmap, new Matrix(), new Paint());
assertEquals("Bitmap for file:/an/image.jpg transformed by Matrix[pre=[], set={}, post=[]]\n" + "Bitmap for file:/an/image.jpg transformed by Matrix[pre=[], set={}, post=[]]", shadowOf(canvas).getDescription());
assertEquals("Bitmap for file:/an/image.jpg transformed by Matrix[pre=[], set={}, post=[]]\n" + "Bitmap for file:/an/image.jpg transformed by Matrix[pre=[], set={}, post=[]]", shadowOf(targetBitmap).getDescription());
}
use of android.graphics.Canvas in project robolectric by robolectric.
the class ShadowCanvasTest method drawRect_shouldRecordRectHistoryEvents.
@Test
public void drawRect_shouldRecordRectHistoryEvents() throws Exception {
Canvas canvas = new Canvas();
Paint paint0 = new Paint();
paint0.setColor(Color.WHITE);
Paint paint1 = new Paint();
paint1.setColor(Color.BLACK);
RectF rect0 = new RectF(0f, 2f, 3f, 4f);
RectF rect1 = new RectF(5f, 6f, 7f, 8f);
canvas.drawRect(0f, 2f, 3f, 4f, paint0);
canvas.drawRect(5f, 6f, 7f, 8f, paint1);
ShadowCanvas shadowCanvas = shadowOf(canvas);
assertThat(shadowCanvas.getDrawnRect(0).left).isEqualTo(0f);
assertThat(shadowCanvas.getDrawnRect(0).top).isEqualTo(2f);
assertThat(shadowCanvas.getDrawnRect(0).right).isEqualTo(3f);
assertThat(shadowCanvas.getDrawnRect(0).bottom).isEqualTo(4f);
assertThat(shadowCanvas.getDrawnRect(0).rect).isEqualTo(rect0);
assertThat(shadowCanvas.getDrawnRect(0).paint.getColor()).isEqualTo(Color.WHITE);
assertThat(shadowCanvas.getDrawnRect(1).left).isEqualTo(5f);
assertThat(shadowCanvas.getDrawnRect(1).top).isEqualTo(6f);
assertThat(shadowCanvas.getDrawnRect(1).right).isEqualTo(7f);
assertThat(shadowCanvas.getDrawnRect(1).bottom).isEqualTo(8f);
assertThat(shadowCanvas.getDrawnRect(1).rect).isEqualTo(rect1);
assertThat(shadowCanvas.getDrawnRect(1).paint.getColor()).isEqualTo(Color.BLACK);
}
Aggregations