Skip to content

Commit

Permalink
Commonize SkiaLayerTest - can run on uikit and macos targets (JetBrai…
Browse files Browse the repository at this point in the history
…ns#327)

Co-authored-by: Oleksandr Karpovich <oleksandr.karpovich@jetbrains.com>
  • Loading branch information
eymar and Oleksandr Karpovich committed Jan 13, 2023
1 parent 7f28f94 commit 81629af
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 48 deletions.
23 changes: 2 additions & 21 deletions ui/ui-graphics/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,11 @@ if(AndroidXComposePlugin.isMultiplatformEnabled(project)) {
desktop()
js()
darwin()

configureDarwinFlags()
}

kotlin {
targets {
def darwinFlags = [
"-linker-option", "-framework", "-linker-option", "Metal",
"-linker-option", "-framework", "-linker-option", "CoreText",
"-linker-option", "-framework", "-linker-option", "CoreGraphics",
"-linker-option", "-framework", "-linker-option", "CoreServices"
]
configure([macosX64, macosArm64]) {
binaries.all {
freeCompilerArgs += darwinFlags
}
}
configure([uikitX64, uikitArm64]) {
binaries.all {
freeCompilerArgs += darwinFlags
freeCompilerArgs +=
["-linker-option", "-framework", "-linker-option", "UIKit"]
}
}
}

/*
* When updating dependencies, make sure to make the an an analogous update in the
* corresponding block above
Expand Down
20 changes: 19 additions & 1 deletion ui/ui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ if(AndroidXComposePlugin.isMultiplatformEnabled(project)) {
desktop()
darwin()
js()

configureDarwinFlags()
}

kotlin {
Expand Down Expand Up @@ -236,9 +238,25 @@ if(AndroidXComposePlugin.isMultiplatformEnabled(project)) {
implementation("androidx.activity:activity-compose:1.5.1")
}

skikoTest.dependencies {
implementation(libs.kotlinTest)
implementation(project(":compose:material:material"))
implementation(project(":compose:foundation:foundation"))
}

desktopTest {
dependsOn(skikoTest)
}
nativeTest {
dependsOn(skikoTest)
}
jsTest {
dependsOn(skikoTest)
}

desktopTest.dependencies {
implementation(libs.truth)
implementation(libs.junit)
implementation(libs.kotlinTest)
implementation(libs.mockitoCore)
implementation(libs.mockitoKotlin)
implementation(libs.skikoCurrentOs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,20 @@ import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.RenderEffect
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.round
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import kotlin.math.PI
import kotlin.math.cos
import kotlin.math.roundToInt
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class SkiaLayerTest {
@get:Rule
val rule = createComposeRule()

private val layer = TestSkiaLayer()
private val cos45 = cos(PI / 4)
Expand Down Expand Up @@ -73,7 +69,7 @@ class SkiaLayerTest {
}

@Test
fun `resize and move`() {
fun resize_and_move() {
layer.resize(IntSize(100, 10))
layer.move(IntOffset(10, 20))
val matrix = layer.matrix
Expand All @@ -83,7 +79,7 @@ class SkiaLayerTest {
}

@Test
fun `translation, left-top origin`() {
fun translation_left_top_origin() {
layer.resize(IntSize(100, 10))
layer.updateProperties(
translationX = 10f,
Expand All @@ -97,7 +93,7 @@ class SkiaLayerTest {
}

@Test
fun `translation, bottom-right origin`() {
fun translation_bottom_right_origin() {
layer.resize(IntSize(100, 10))
layer.updateProperties(
translationX = 10f,
Expand All @@ -111,7 +107,7 @@ class SkiaLayerTest {
}

@Test
fun `scale, left-top origin`() {
fun scale_left_top_origin() {
layer.resize(IntSize(100, 10))
layer.updateProperties(
scaleX = 2f,
Expand All @@ -125,7 +121,7 @@ class SkiaLayerTest {
}

@Test
fun `scale, bottom-right origin`() {
fun scale_bottom_right_origin() {
layer.resize(IntSize(100, 10))
layer.updateProperties(
scaleX = 2f,
Expand All @@ -139,7 +135,7 @@ class SkiaLayerTest {
}

@Test
fun `rotationX, left-top origin`() {
fun rotationX_left_top_origin() {
layer.resize(IntSize(100, 10))
layer.updateProperties(
rotationX = 45f,
Expand All @@ -153,7 +149,7 @@ class SkiaLayerTest {
}

@Test
fun `rotationX, bottom-right origin`() {
fun rotationX_bottom_right_origin() {
layer.resize(IntSize(100, 10))
layer.updateProperties(
rotationX = 45f,
Expand All @@ -167,7 +163,7 @@ class SkiaLayerTest {
}

@Test
fun `rotationY, left-top origin`() {
fun rotationY_left_top_origin() {
layer.resize(IntSize(100, 10))
layer.updateProperties(
rotationY = 45f,
Expand All @@ -181,7 +177,7 @@ class SkiaLayerTest {
}

@Test
fun `rotationY, bottom-right origin`() {
fun rotationY_bottom_right_origin() {
layer.resize(IntSize(100, 10))
layer.updateProperties(
rotationY = 45f,
Expand All @@ -195,7 +191,7 @@ class SkiaLayerTest {
}

@Test
fun `rotationZ, left-top origin`() {
fun rotationZ_left_top_origin() {
layer.resize(IntSize(100, 10))
layer.updateProperties(
rotationZ = 90f,
Expand All @@ -208,7 +204,7 @@ class SkiaLayerTest {
}

@Test
fun `rotationZ, bottom-right origin`() {
fun rotationZ_bottom_right_origin() {
layer.resize(IntSize(100, 10))
layer.updateProperties(
rotationZ = 90f,
Expand All @@ -221,7 +217,7 @@ class SkiaLayerTest {
}

@Test
fun `translation, scale, left-top origin`() {
fun translation_scale_left_top_origin() {
layer.resize(IntSize(100, 10))
layer.updateProperties(
translationX = 60f,
Expand All @@ -237,7 +233,7 @@ class SkiaLayerTest {
}

@Test
fun `translation, rotationZ, left-top origin`() {
fun translation_rotationZ_left_top_origin() {
layer.resize(IntSize(100, 10))
layer.updateProperties(
translationX = 60f,
Expand All @@ -252,7 +248,7 @@ class SkiaLayerTest {
}

@Test
fun `translation, rotationX, left-top origin`() {
fun translation_rotationX_left_top_origin() {
layer.resize(IntSize(100, 10))
layer.updateProperties(
translationX = 60f,
Expand All @@ -269,7 +265,7 @@ class SkiaLayerTest {
}

@Test
fun `translation, rotationY, left-top origin`() {
fun translation_rotationY_left_top_origi() {
layer.resize(IntSize(100, 10))
layer.updateProperties(
translationX = 60f,
Expand All @@ -286,7 +282,7 @@ class SkiaLayerTest {
}

@Test
fun `scale, rotationZ, left-top origin`() {
fun scale_rotationZ_left_top_origin() {
layer.resize(IntSize(100, 10))
layer.updateProperties(
scaleX = 2f,
Expand All @@ -301,7 +297,7 @@ class SkiaLayerTest {
}

@Test
fun `translation, scale, rotationZ, left-top origin`() {
fun translation_scale_rotationZ_left_top_origin() {
layer.resize(IntSize(100, 10))
layer.updateProperties(
translationX = 60f,
Expand All @@ -318,7 +314,7 @@ class SkiaLayerTest {
}

@Test
fun `is in layer`() {
fun is_in_layer() {
layer.resize(IntSize(0, 0))
layer.updateProperties(
clip = false
Expand Down

0 comments on commit 81629af

Please sign in to comment.