From d029e3b730fec052c66c06916d66fd7c7f18baf2 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Tue, 16 Apr 2019 11:29:19 +0300 Subject: [PATCH] Add trivial tests for compositions of ObjCExport and overriding --- .../tests/framework/values/values.kt | 58 +++++++++++++++++++ .../tests/framework/values/values.swift | 31 ++++++++++ 2 files changed, 89 insertions(+) diff --git a/backend.native/tests/framework/values/values.kt b/backend.native/tests/framework/values/values.kt index 24a5f816347..f3c762f7161 100644 --- a/backend.native/tests/framework/values/values.kt +++ b/backend.native/tests/framework/values/values.kt @@ -280,3 +280,61 @@ class Deeply { } data class CKeywords(val float: Float, val `enum`: Int, var goto: Boolean) + +interface Base1 { + fun same(value: Int?): Int? +} + +interface ExtendedBase1 : Base1 { + override fun same(value: Int?): Int? +} + +interface Base2 { + fun same(value: Int?): Int? +} + +internal interface Base3 { + fun same(value: Int?): Int +} + +open class Base23 : Base2, Base3 { + override fun same(value: Int?): Int = error("should not reach here") +} + +fun call(base1: Base1, value: Int?) = base1.same(value) +fun call(extendedBase1: ExtendedBase1, value: Int?) = extendedBase1.same(value) +fun call(base2: Base2, value: Int?) = base2.same(value) +fun call(base3: Any, value: Int?) = (base3 as Base3).same(value) +fun call(base23: Base23, value: Int?) = base23.same(value) + +interface Transform { + fun map(value: T): R +} + +interface TransformWithDefault : Transform { + override fun map(value: T): T = value +} + +class TransformInheritingDefault : TransformWithDefault + +interface TransformIntString { + fun map(intValue: Int): String +} + +abstract class TransformIntToString : Transform, TransformIntString { + override abstract fun map(intValue: Int): String +} + +open class TransformIntToDecimalString : TransformIntToString() { + override fun map(intValue: Int): String = intValue.toString() +} + +private class TransformDecimalStringToInt : Transform { + override fun map(stringValue: String): Int = stringValue.toInt() +} + +fun createTransformDecimalStringToInt(): Transform = TransformDecimalStringToInt() + +open class TransformIntToLong : Transform { + override fun map(value: Int): Long = value.toLong() +} \ No newline at end of file diff --git a/backend.native/tests/framework/values/values.swift b/backend.native/tests/framework/values/values.swift index 348b4390eaa..2086a41a57f 100644 --- a/backend.native/tests/framework/values/values.swift +++ b/backend.native/tests/framework/values/values.swift @@ -496,6 +496,35 @@ func testNames() throws { try assertEquals(actual: CKeywords(float: 1.0, enum : 42, goto: true).goto_, expected: true) } +class Base123 : Base23, ExtendedBase1 { + override func same(value: KotlinInt?) -> KotlinInt { + return value! + } +} + +func testSwiftOverride() throws { + let impl = Base123() + try assertEquals(actual: ValuesKt.call(base1: impl, value: 1), expected: 1) + try assertEquals(actual: ValuesKt.call(extendedBase1: impl, value: 2), expected: 2) + try assertEquals(actual: ValuesKt.call(base2: impl, value: 3), expected: 3) + try assertEquals(actual: ValuesKt.call(base3: impl, value: 4), expected: 4) + try assertEquals(actual: ValuesKt.call(base23: impl, value: 5), expected: 5) +} + +class TransformIntToLongCallingSuper : TransformIntToLong { + override func map(value: KotlinInt) -> KotlinLong { + return super.map(value: value) + } +} + +func testKotlinOverride() throws { + try assertEquals(actual: TransformInheritingDefault().map(value: 1) as! Int32, expected: 1) + try assertEquals(actual: TransformIntToDecimalString().map(value: 2), expected: "2") + try assertEquals(actual: TransformIntToDecimalString().map(intValue: 3), expected: "3") + try assertEquals(actual: ValuesKt.createTransformDecimalStringToInt().map(value: "4") as! Int32, expected: 4) + try assertEquals(actual: TransformIntToLongCallingSuper().map(value: 5), expected: 5) +} + // -------- Execution of the test -------- class ValuesTests : TestProvider { @@ -533,6 +562,8 @@ class ValuesTests : TestProvider { TestCase(name: "TestShared", method: withAutorelease(testShared)), TestCase(name: "TestPureSwiftClasses", method: withAutorelease(testPureSwiftClasses)), TestCase(name: "TestNames", method: withAutorelease(testNames)), + TestCase(name: "TestSwiftOverride", method: withAutorelease(testSwiftOverride)), + TestCase(name: "TestKotlinOverride", method: withAutorelease(testKotlinOverride)), ] } }