Unverified Commit c3bdfc3f authored by Igor Demin's avatar Igor Demin Committed by GitHub

Move tests from SkijaInjectSample to skiko (#145)

They will run if system property skiko.test.window.test.enabled != false
parent df274e55
......@@ -69,17 +69,6 @@ tasks.register("runSoftware") {
dependsOn(casualRun)
}
tasks.withType<Test> {
systemProperty("skiko.test.screenshots.dir", File(project.projectDir, "src/test/screenshots").absolutePath)
// Tests should be deterministic, so disable scaling.
// On MacOs we need the actual scale, otherwise we will have aliased screenshots because of scaling.
if (System.getProperty("os.name") != "Mac OS X") {
systemProperty("sun.java2d.dpiaware", "false")
systemProperty("sun.java2d.uiScale", "1")
}
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}
import de.undercouch.gradle.tasks.download.Download
import org.gradle.crypto.checksum.Checksum
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.tasks.KotlinTest
import org.jetbrains.kotlin.gradle.tasks.CInteropProcess
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
plugins {
......@@ -605,6 +604,16 @@ tasks.withType<Test>().configureEach {
systemProperty("skiko.library.path", dir)
val jar = skikoJvmRuntimeJar.get().outputs.files.files.single { it.name.endsWith(".jar")}
systemProperty("skiko.jar.path", jar.absolutePath)
systemProperty("skiko.test.screenshots.dir", File(project.projectDir, "src/jvmTest/screenshots").absolutePath)
systemProperty("skiko.test.window.test.enabled", System.getProperty("skiko.test.window.test.enabled", "false"))
// Tests should be deterministic, so disable scaling.
// On MacOs we need the actual scale, otherwise we will have aliased screenshots because of scaling.
if (System.getProperty("os.name") != "Mac OS X") {
systemProperty("sun.java2d.dpiaware", "false")
systemProperty("sun.java2d.uiScale", "1")
}
}
}
......
......@@ -3,7 +3,7 @@ package org.jetbrains.skiko
import org.jetbrains.skija.Bitmap
import org.junit.Test
internal class BaseTest {
internal class LibraryTest {
@Test
fun `load library`() {
Library.load()
......
package org.jetbrains.skiko
import kotlinx.coroutines.*
import kotlinx.coroutines.swing.Swing
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.delay
import org.jetbrains.skija.*
import org.jetbrains.skiko.util.swingTest
import org.junit.Test
import java.awt.Point
import java.awt.event.WindowEvent
......@@ -262,12 +263,6 @@ j org.jetbrains.skiko.redrawer.MacOsRedrawer$drawLayer$1.draw()V+7
restore()
}
private fun swingTest(block: suspend CoroutineScope.() -> Unit) {
runBlocking(Dispatchers.Swing) {
block()
}
}
private class FPSCounter(
private val count: Int
) {
......
package org.jetbrains.skiko
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.swing.Swing
import org.jetbrains.skija.Canvas
import org.jetbrains.skija.FontMgr
import org.jetbrains.skija.Paint
......@@ -14,12 +10,13 @@ import org.jetbrains.skija.paragraph.FontCollection
import org.jetbrains.skija.paragraph.ParagraphBuilder
import org.jetbrains.skija.paragraph.ParagraphStyle
import org.jetbrains.skija.paragraph.TextStyle
import org.jetbrains.skiko.util.ScreenshotTestRule
import org.jetbrains.skiko.util.swingTest
import org.junit.Assume.assumeTrue
import org.junit.Rule
import org.junit.Test
import java.awt.Color
import java.awt.Dimension
import java.awt.Robot
import java.awt.event.WindowEvent
import javax.swing.JFrame
import javax.swing.WindowConstants
......@@ -29,8 +26,6 @@ import kotlin.test.assertTrue
@Suppress("BlockingMethodInNonBlockingContext", "SameParameterValue")
class SkiaWindowTest {
private val robot = Robot()
private val fontManager = FontMgr.getDefault()
private val fontCollection = FontCollection()
.setDefaultFontManager(fontManager)
......@@ -47,7 +42,7 @@ class SkiaWindowTest {
.build()
@get:Rule
val screenshots = ScreenshotTestRule(robot)
val screenshots = ScreenshotTestRule()
@Test
fun `render single window`() = swingTest {
......@@ -313,12 +308,6 @@ class SkiaWindowTest {
}
}
private fun swingTest(block: suspend CoroutineScope.() -> Unit) {
runBlocking(Dispatchers.Swing) {
block()
}
}
private class RectRenderer(
private val layer: SkiaLayer,
var rectWidth: Int,
......
package org.jetbrains.skiko
package org.jetbrains.skiko.util
import org.jetbrains.skiko.OS
import org.jetbrains.skiko.hostOs
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
......@@ -12,7 +14,9 @@ import javax.imageio.ImageIO
// macOS has wrong colors ([128, 128, 128] isn't [128, 128, 128] on screenshot). Only white, black, red and green are correct.
// So use only these color for cross-platform screenshots tests.
// TODO fix colors on macOS
class ScreenshotTestRule(private val robot: Robot) : TestRule {
class ScreenshotTestRule : TestRule {
private val robot by lazy { Robot() }
private lateinit var testIdentifier: String
private val subDir = if (hostOs == OS.MacOS) "macos" else "windows_linux"
private val screenshotsDir = File(System.getProperty("skiko.test.screenshots.dir")!!).resolve(subDir)
......
package org.jetbrains.skiko
package org.jetbrains.skiko.util
import org.jetbrains.skiko.Library
import org.junit.Test
import java.net.URL
import java.net.URLClassLoader
......
package org.jetbrains.skiko.util
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.swing.Swing
import org.junit.Assume.assumeFalse
import org.junit.Assume.assumeTrue
import java.awt.GraphicsEnvironment
fun swingTest(block: suspend CoroutineScope.() -> Unit) {
assumeFalse(GraphicsEnvironment.isHeadless())
assumeTrue(System.getProperty("skiko.test.window.test.enabled") != "false")
runBlocking(Dispatchers.Swing) {
block()
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment