From 3d70be0c5fa2cadeee325d5d666ebbb5257df00c Mon Sep 17 00:00:00 2001 From: Vladimir Sukharev Date: Fri, 16 Feb 2024 14:34:29 +0100 Subject: [PATCH] [K/N][Tests] Migrate test kt40426 ^KT-61259 --- .../backend.native/tests/build.gradle | 7 ------- .../tests/interop/objc/kt40426/main.out | 2 -- .../testData/codegen/cinterop/kt40426.kt | 20 ++++++++++++++----- .../FirNativeCodegenLocalTestGenerated.java | 6 ++++++ .../NativeCodegenLocalTestGenerated.java | 6 ++++++ 5 files changed, 27 insertions(+), 14 deletions(-) delete mode 100644 kotlin-native/backend.native/tests/interop/objc/kt40426/main.out rename kotlin-native/backend.native/tests/interop/objc/kt40426/main.kt => native/native.tests/testData/codegen/cinterop/kt40426.kt (54%) diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index f0ab53253e8..cb7dd9a76fc 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -1112,13 +1112,6 @@ if (PlatformInfo.isAppleTarget(project)) { UtilsKt.dependsOnPlatformLibs(it) } - standaloneTest("interop_kt40426") { - // Test depends on iOS-specific UIKit - enabled = (project.testTarget == 'ios_x64' || project.testTarget == 'ios_simulator_arm64' || project.testTarget == 'ios_arm64') - source = "interop/objc/kt40426/main.kt" - useGoldenData = true - UtilsKt.dependsOnPlatformLibs(it) - } interopTest("interop_objc_kt63423_dispose_on_main_stress") { // Test depends on macOS-specific AppKit diff --git a/kotlin-native/backend.native/tests/interop/objc/kt40426/main.out b/kotlin-native/backend.native/tests/interop/objc/kt40426/main.out deleted file mode 100644 index 54d057726b4..00000000000 --- a/kotlin-native/backend.native/tests/interop/objc/kt40426/main.out +++ /dev/null @@ -1,2 +0,0 @@ -SmileView::drawRect -SmileView::layoutSubviews diff --git a/kotlin-native/backend.native/tests/interop/objc/kt40426/main.kt b/native/native.tests/testData/codegen/cinterop/kt40426.kt similarity index 54% rename from kotlin-native/backend.native/tests/interop/objc/kt40426/main.kt rename to native/native.tests/testData/codegen/cinterop/kt40426.kt index e9ca41a7fc4..00992840d96 100644 --- a/kotlin-native/backend.native/tests/interop/objc/kt40426/main.kt +++ b/native/native.tests/testData/codegen/cinterop/kt40426.kt @@ -2,32 +2,42 @@ * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ - +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) +// UIView is available on iOS & tvOS: https://developer.apple.com/documentation/uikit/uiview?language=objc +// DISABLE_NATIVE: isAppleTarget=false +// DISABLE_NATIVE: targetFamily=OSX +// DISABLE_NATIVE: targetFamily=WATCHOS import kotlinx.cinterop.* import platform.UIKit.* import platform.CoreGraphics.* import platform.Foundation.NSString +var drawRectInvoked = false +var layoutSubviewsInvoked = false + class SmileView(frame: CValue): UIView(frame = frame) { override fun drawRect(rect: CValue) { super.drawRect(rect) val smile = ":)" as NSString smile.drawInRect(rect, withAttributes = null) - println("SmileView::drawRect") + drawRectInvoked = true } override fun layoutSubviews() { super.layoutSubviews() - println("SmileView::layoutSubviews") + layoutSubviewsInvoked = true } } -fun main() { - memScoped { +fun box(): String { + return memScoped { val frame = alloc() val x = SmileView(frame.readValue()) x.drawRect(frame.readValue()) + if (!drawRectInvoked) return@memScoped "FAIL: SmileView::drawRect() was not invoked" x.layoutSubviews() + if (!layoutSubviewsInvoked) return@memScoped "FAIL: SmileView::layoutSubviews() was not invoked" + "OK" } } \ No newline at end of file diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenLocalTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenLocalTestGenerated.java index 2c4999722dc..420041e1bea 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenLocalTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenLocalTestGenerated.java @@ -897,6 +897,12 @@ public class FirNativeCodegenLocalTestGenerated extends AbstractNativeCodegenBox runTest("native/native.tests/testData/codegen/cinterop/incompleteTypes.kt"); } + @Test + @TestMetadata("kt40426.kt") + public void testKt40426() { + runTest("native/native.tests/testData/codegen/cinterop/kt40426.kt"); + } + @Test @TestMetadata("kt43265.kt") public void testKt43265() { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenLocalTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenLocalTestGenerated.java index 7f7d656c515..1d418064e60 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenLocalTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenLocalTestGenerated.java @@ -875,6 +875,12 @@ public class NativeCodegenLocalTestGenerated extends AbstractNativeCodegenBoxTes runTest("native/native.tests/testData/codegen/cinterop/incompleteTypes.kt"); } + @Test + @TestMetadata("kt40426.kt") + public void testKt40426() { + runTest("native/native.tests/testData/codegen/cinterop/kt40426.kt"); + } + @Test @TestMetadata("kt43265.kt") public void testKt43265() {