Skip to content

Commit

Permalink
Merge branch 'main' into takahirom/refactor-plugable/2024-12-01
Browse files Browse the repository at this point in the history
  • Loading branch information
takahirom authored Dec 3, 2024
2 parents a899893 + 21d5de0 commit f1a9c47
Show file tree
Hide file tree
Showing 27 changed files with 173 additions and 38 deletions.
18 changes: 12 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,20 @@ allprojects {
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
compilerOptions {
jvmTarget.set(jvmTargetVersion)

freeCompilerArgs.addAll(
"-Xopt-in=com.github.takahirom.roborazzi.InternalRoborazziApi",
"-Xopt-in=com.github.takahirom.roborazzi.ExperimentalRoborazziApi",
)
allWarningsAsErrors = true
}
}

if(project.name.startsWith("roborazzi") &&
project.name != "roborazzi-idea-plugin") {
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
compilerOptions {
freeCompilerArgs.addAll(
"-Xopt-in=com.github.takahirom.roborazzi.InternalRoborazziApi",
"-Xopt-in=com.github.takahirom.roborazzi.ExperimentalRoborazziApi",
)
}
}
}
plugins.withId('com.vanniktech.maven.publish') {
project.group = "io.github.takahirom.roborazzi"
mavenPublishing {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=1.33.0
VERSION_NAME=1.34.0
GROUP=io.github.takahirom.roborazzi
# Project-wide Gradle settings.

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ androidx-appcompat = "1.7.0"
androidx-compose-material = "1.7.5"
androidx-compose-material3 = "1.3.1"
androidx-compose-foundation = "1.7.5"
androidx-compose-runtime = "1.6.8"
androidx-compose-runtime = "1.7.5"
androidx-compose-ui = "1.4.0"
androidx-compose-ui-test = "1.6.8"
androidx-compose-ui-test-junit4 = "1.7.5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ data class RoborazziOptions(
val compareOptions: CompareOptions = CompareOptions(),
val recordOptions: RecordOptions = RecordOptions(),
) {
// Stable parameters
constructor(
captureType: CaptureType = if (canScreenshot()) CaptureType.Screenshot() else defaultCaptureType(),
reportOptions: ReportOptions = ReportOptions(),
compareOptions: CompareOptions = CompareOptions(),
recordOptions: RecordOptions = RecordOptions(),
) : this(
taskType = roborazziSystemPropertyTaskType(),
contextData = emptyMap(),
captureType = captureType,
reportOptions = reportOptions,
compareOptions = compareOptions,
recordOptions = recordOptions,
)

interface CaptureType {
class Screenshot : CaptureType {
override fun shouldTakeScreenshot(): Boolean {
Expand All @@ -91,10 +106,14 @@ data class RoborazziOptions(
companion object
}

@ExperimentalRoborazziApi
data class ReportOptions(
val captureResultReporter: CaptureResultReporter = CaptureResultReporter(),
)
) {
// Stable parameters
constructor() : this(
captureResultReporter = CaptureResultReporter()
)
}

data class CompareOptions(
val outputDirectoryPath: String = roborazziSystemPropertyOutputDirectory(),
Expand All @@ -103,6 +122,15 @@ data class RoborazziOptions(
val aiAssertionOptions: AiAssertionOptions? = null,
val resultValidator: (result: ImageComparator.ComparisonResult) -> Boolean = DefaultResultValidator,
) {
// Stable parameters
constructor(
imageComparator: ImageComparator = DefaultImageComparator,
resultValidator: (result: ImageComparator.ComparisonResult) -> Boolean = DefaultResultValidator,
): this(
outputDirectoryPath = roborazziSystemPropertyOutputDirectory(),
imageComparator = imageComparator,
resultValidator = resultValidator,
)

@ExperimentalRoborazziApi
sealed interface ComparisonStyle {
Expand Down Expand Up @@ -236,7 +264,19 @@ data class RoborazziOptions(
val applyDeviceCrop: Boolean = false,
val pixelBitConfig: PixelBitConfig = PixelBitConfig.Argb8888,
val imageIoFormat: ImageIoFormat = ImageIoFormat(),
)
) {
// Stable parameters
constructor(
resizeScale: Double = roborazziDefaultResizeScale(),
applyDeviceCrop: Boolean = false,
pixelBitConfig: PixelBitConfig = PixelBitConfig.Argb8888,
) : this(
resizeScale = resizeScale,
applyDeviceCrop = applyDeviceCrop,
pixelBitConfig = pixelBitConfig,
imageIoFormat = ImageIoFormat(),
)
}

enum class PixelBitConfig {
Argb8888,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ abstract class GenerateComposePreviewRobolectricTestsTask : DefaultTask() {
@get:Rule
val rule = RuleChain.outerRule(
if(testLifecycleOptions is ComposePreviewTester.Options.JUnit4TestLifecycleOptions) {
(testLifecycleOptions as ComposePreviewTester.Options.JUnit4TestLifecycleOptions).testRuleFactory()
testLifecycleOptions.testRuleFactory()
} else {
object : TestWatcher() {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,27 @@ class RoborazziRule private constructor(
val roborazziOptions: RoborazziOptions = provideRoborazziContext().options,
val roborazziAccessibilityOptions: RoborazziAccessibilityOptions = provideRoborazziContext().roborazziAccessibilityOptions,
val accessibilityCheckStrategy: AccessibilityCheckStrategy = AccessibilityCheckStrategy.None,
)
) {
// Stable parameters
constructor(
captureType: CaptureType = CaptureType.None,
/**
* output directory path
*/
outputDirectoryPath: String = provideRoborazziContext().outputDirectory,

outputFileProvider: FileProvider = provideRoborazziContext().fileProvider
?: defaultFileProvider,
roborazziOptions: RoborazziOptions = provideRoborazziContext().options,
): this(
captureType = captureType,
outputDirectoryPath = outputDirectoryPath,
outputFileProvider = outputFileProvider,
roborazziOptions = roborazziOptions,
roborazziAccessibilityOptions = provideRoborazziContext().roborazziAccessibilityOptions,
accessibilityCheckStrategy = AccessibilityCheckStrategy.None
)
}

@ExperimentalRoborazziApi
interface AccessibilityCheckStrategy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class AnimatedGifEncoder {
*/
fun addFrame(canvas: AwtRoboCanvas, resizeImage: Double): Boolean {
val im = canvas.outputImage(resizeImage)
if (im == null || !started) {
if (!started) {
return false
}
var ok = true
Expand Down Expand Up @@ -219,11 +219,11 @@ class AnimatedGifEncoder {
* @return
*/
fun setQuality(quality: Int) {
var quality = quality
if (quality < 1) {
quality = 1
var localQuality = quality
if (localQuality < 1) {
localQuality = 1
}
sample = quality
sample =localQuality
}

/**
Expand Down Expand Up @@ -281,7 +281,7 @@ class AnimatedGifEncoder {
* @return false if open or initial write failed.
*/
fun start(file: String?): Boolean {
var ok = true
var ok: Boolean
try {
out = BufferedOutputStream(FileOutputStream(file))
ok = start(out)
Expand Down Expand Up @@ -367,7 +367,7 @@ class AnimatedGifEncoder {
* Extracts image pixels into byte array "pixels"
*/
private val imagePixels: Unit
private get() {
get() {
val w = image!!.width
val h = image!!.height
val type = image!!.type
Expand Down Expand Up @@ -835,7 +835,6 @@ internal class NeuQuant(thepic: ByteArray?, len: Int, sample: Int) {
*/
fun unbiasnet() {
var i: Int
var j: Int
i = 0
while (i < netsize) {
network[i]!![0] = network[i]!![0] shr netbiasshift
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class AwtRoboCanvas(width: Int, height: Int, filled: Boolean, bufferedImageType:
}

fun drawText(textPointX: Float, textPointY: Float, texts: List<String>, paint: Paint) {
bufferedImage.graphics { graphics: Graphics2D ->
bufferedImage.graphics {
val graphics2D = bufferedImage.createGraphics()
graphics2D.color = Color(paint.getColor(), true)

Expand Down Expand Up @@ -522,8 +522,6 @@ class AwtRoboCanvas(width: Int, height: Int, filled: Boolean, bufferedImageType:
val rgbComp = comparedImage.getRGB(x, y)
if (rgbOrig != rgbComp) {
diffImage.setRGB(x, y, -0x10000)
} else {
0x0
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal fun captureDump(
recordOptions: RoborazziOptions.RecordOptions,
onCanvas: (AwtRoboCanvas) -> Unit
) {
val start = System.currentTimeMillis()
// val start = System.currentTimeMillis()
val basicSize = dumpOptions.basicSize
val depthSlide = dumpOptions.depthSlideSize

Expand Down Expand Up @@ -156,7 +156,7 @@ internal fun captureDump(
}
bfs()
onCanvas(canvas)
val end = System.currentTimeMillis()
// val end = System.currentTimeMillis()
// println("roborazzi takes " + (end - start) + "ms")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
@file:Suppress("PLUGIN_IS_NOT_ENABLED")

package com.github.takahirom.roborazzi

import kotlin.math.roundToInt
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import nl.adaptivity.xmlutil.serialization.XmlElement
import nl.adaptivity.xmlutil.serialization.XmlSerialName
import kotlin.math.roundToInt

@Serializable
@XmlSerialName("devices", namespace = "http://schemas.android.com/sdk/devices/1", prefix = "d")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.takahirom.roborazzi

import kotlinx.coroutines.runBlocking
import kotlinx.serialization.decodeFromString
import nl.adaptivity.xmlutil.ExperimentalXmlUtilApi
import nl.adaptivity.xmlutil.serialization.DefaultXmlSerializationPolicy
import nl.adaptivity.xmlutil.serialization.XML
import nl.adaptivity.xmlutil.serialization.XmlConfig.Companion.IGNORING_UNKNOWN_CHILD_HANDLER
Expand All @@ -21,7 +22,9 @@ import org.w3c.dom.Node
import org.w3c.dom.NodeList


@Ignore
@Suppress("DEPRECATION")
@Ignore("We only need to run this once to generate the qualifiers")
@OptIn(ExperimentalXmlUtilApi::class)
class GenerateQualifiersTest {
val devicesTarGz =
("https://android.googlesource.com" +
Expand Down Expand Up @@ -56,7 +59,7 @@ class GenerateQualifiersTest {
)
deviceTypes.forEach { (tagId, devices) ->
writeUtf8("\n\t// Type: ${tagId ?: "default"}\n")
devices.forEach { device ->
devices.forEach device@{ device ->
// find device name
val name = device.name
.replace(" ", "")
Expand All @@ -67,11 +70,11 @@ class GenerateQualifiersTest {
.replace(".", "")
.replace("\"", "")

val shouldSkipDevice = shouldSkip(name, device)
val shouldSkipDevice = shouldSkip(name)

if (shouldSkipDevice) {
println("skip device:$name")
return@forEach
return@device
}

writeUtf8("\tconst val $name = \"${device.qualifier}\"\n")
Expand All @@ -82,7 +85,7 @@ class GenerateQualifiersTest {
}
}

private fun shouldSkip(name: String, device: Device): Boolean {
private fun shouldSkip(name: String): Boolean {
if (name[0] in '0'..'9') return true
val skippingDevicePrefixes =
listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.github.takahirom.roborazzi.ExperimentalRoborazziApi
import com.github.takahirom.roborazzi.RobolectricDeviceQualifiers
import com.github.takahirom.roborazzi.RoborazziOptions
import com.github.takahirom.roborazzi.captureRoboImage
Expand All @@ -20,6 +21,7 @@ import org.robolectric.annotation.GraphicsMode
sdk = [30],
qualifiers = RobolectricDeviceQualifiers.NexusOne
)
@OptIn(ExperimentalRoborazziApi::class)
class ComparisonStyleTest {
@get:Rule
val composeTestRule = createAndroidComposeRule<MainActivity>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.ui.test.onRoot
import androidx.compose.ui.unit.dp
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.github.takahirom.roborazzi.AccessibilityCheckAfterTestStrategy
import com.github.takahirom.roborazzi.ExperimentalRoborazziApi
import com.github.takahirom.roborazzi.RobolectricDeviceQualifiers
import com.github.takahirom.roborazzi.RoborazziATFAccessibilityCheckOptions
import com.github.takahirom.roborazzi.RoborazziATFAccessibilityChecker
Expand All @@ -39,6 +40,7 @@ import org.junit.runner.RunWith
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode

@OptIn(ExperimentalRoborazziApi::class)
@RunWith(AndroidJUnit4::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
@Config(qualifiers = RobolectricDeviceQualifiers.Pixel4, sdk = [35])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.test.onRoot
import androidx.compose.ui.unit.dp
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.github.takahirom.roborazzi.AccessibilityCheckAfterTestStrategy
import com.github.takahirom.roborazzi.ExperimentalRoborazziApi
import com.github.takahirom.roborazzi.RobolectricDeviceQualifiers
import com.github.takahirom.roborazzi.RoborazziATFAccessibilityCheckOptions
import com.github.takahirom.roborazzi.RoborazziATFAccessibilityChecker
Expand Down Expand Up @@ -44,6 +45,7 @@ import java.util.Locale
/**
* Test demonstrating a completely custom ATF Check. Expected to be a niche usecase, but critical when required.
*/
@OptIn(ExperimentalRoborazziApi::class)
@RunWith(AndroidJUnit4::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
@Config(qualifiers = RobolectricDeviceQualifiers.Pixel4, sdk = [35])
Expand Down Expand Up @@ -161,7 +163,7 @@ class ComposeA11yWithCustomCheckTest {
metadata: ResultMetadata?
) : AccessibilityHierarchyCheckResult(checkClass, type, element, resultId, metadata) {
override fun getMessage(locale: Locale?): CharSequence =
(checkClass.newInstance()).getMessageForResult(locale, this)
(checkClass.getDeclaredConstructor().newInstance()).getMessageForResult(locale, this)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.github.takahirom.roborazzi.AiAssertionOptions
import com.github.takahirom.roborazzi.DEFAULT_ROBORAZZI_OUTPUT_DIR_PATH
import com.github.takahirom.roborazzi.ExperimentalRoborazziApi
import com.github.takahirom.roborazzi.GeminiAiAssertionModel
import com.github.takahirom.roborazzi.ROBORAZZI_DEBUG
import com.github.takahirom.roborazzi.RobolectricDeviceQualifiers
Expand All @@ -22,6 +23,7 @@ import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode
import java.io.File

@OptIn(ExperimentalRoborazziApi::class)
@RunWith(AndroidJUnit4::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
@Config(
Expand Down
Loading

0 comments on commit f1a9c47

Please sign in to comment.