From 5c2ff4d34d120d8a777f029cdc6eddb65aa4c0c3 Mon Sep 17 00:00:00 2001 From: Michal Wolski Date: Thu, 19 Jan 2023 13:40:46 +0100 Subject: [PATCH] Add test for correct alpha and color values --- .../photoeditor/DrawingViewApiTest.kt | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/photoeditor/src/androidTest/java/ja/burhanrashid52/photoeditor/DrawingViewApiTest.kt b/photoeditor/src/androidTest/java/ja/burhanrashid52/photoeditor/DrawingViewApiTest.kt index ff1f5bfa..bef43283 100644 --- a/photoeditor/src/androidTest/java/ja/burhanrashid52/photoeditor/DrawingViewApiTest.kt +++ b/photoeditor/src/androidTest/java/ja/burhanrashid52/photoeditor/DrawingViewApiTest.kt @@ -121,6 +121,48 @@ internal class DrawingViewApiTest : BaseDrawingViewTest() { assertTrue(drawingView.isDrawingEnabled) } + @Test + fun testCorrectAlphaAndColorValues() { + val drawingView = setupDrawingView() + val currentShapeBuilder = drawingView.currentShapeBuilder + + val shapeOpacity = 120 + val colorAlpha1 = 11 + val colorAlpha2 = 22 + + currentShapeBuilder.withShapeColor(Color.argb(colorAlpha1, 33, 44, 55)) + touchView(drawingView, MotionEvent.ACTION_DOWN) + + drawingView.currentShape!!.paint.also { paint -> + assertEquals(colorAlpha1, paint.alpha) + assertEquals(Color.argb(colorAlpha1, 33, 44, 55), paint.color) + } + + currentShapeBuilder.withShapeOpacity(shapeOpacity) + touchView(drawingView, MotionEvent.ACTION_DOWN) + + drawingView.currentShape!!.paint.also { paint -> + assertEquals(shapeOpacity, paint.alpha) + assertEquals(Color.argb(shapeOpacity, 33, 44, 55), paint.color) + } + + currentShapeBuilder.withShapeColor(Color.argb(colorAlpha2, 44, 55, 66)) + touchView(drawingView, MotionEvent.ACTION_DOWN) + + drawingView.currentShape!!.paint.also { paint -> + assertEquals(shapeOpacity, paint.alpha) + assertEquals(Color.argb(shapeOpacity, 44, 55, 66), paint.color) + } + + currentShapeBuilder.withShapeOpacity(null) + touchView(drawingView, MotionEvent.ACTION_DOWN) + + drawingView.currentShape!!.paint.also { paint -> + assertEquals(colorAlpha2, paint.alpha) + assertEquals(Color.argb(colorAlpha2, 44, 55, 66), paint.color) + } + } + @Test fun testDefaultBrushColorValue() { val drawingView = setupDrawingView()