From 4835aa3e748333836c8a658ff34ce591768cb836 Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Tue, 21 Feb 2017 17:14:13 +0300 Subject: [PATCH] Added tests on bridges --- backend.native/tests/build.gradle | 19 ++++++++ .../tests/codegen/bridges/test14.kt | 44 +++++++++++++++++++ .../tests/codegen/bridges/test15.kt | 35 +++++++++++++++ .../tests/codegen/bridges/test16.kt | 20 +++++++++ 4 files changed, 118 insertions(+) create mode 100644 backend.native/tests/codegen/bridges/test14.kt create mode 100644 backend.native/tests/codegen/bridges/test15.kt create mode 100644 backend.native/tests/codegen/bridges/test16.kt diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 40b1630bca8..83978b417b5 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -89,6 +89,10 @@ task slackReport(type:Reporter) { reportHome = rootProject.file("test.output").absoluteFile } +task bridges_all() { + dependsOn(tasks.withType(KonanTest).matching { !(it instanceof RunExternalTestGroup) && it.enabled && it.name.startsWith("bridges_") }) +} + task sum (type:RunKonanTest) { source = "codegen/function/sum.kt" } @@ -537,6 +541,21 @@ task bridges_test13(type: RunKonanTest) { source = "codegen/bridges/test13.kt" } +task bridges_test14(type: RunKonanTest) { + goldValue = "42\n56\n42\n56\n56\n42\n156\n142\n" + source = "codegen/bridges/test14.kt" +} + +task bridges_test15(type: RunKonanTest) { + goldValue = "OK\n" + source = "codegen/bridges/test15.kt" +} + +task bridges_test16(type: RunKonanTest) { + goldValue = "OK\nOK\n" + source = "codegen/bridges/test16.kt" +} + task array0(type: RunKonanTest) { goldValue = "5\n6\n7\n8\n9\n10\n11\n12\n13\n" source = "runtime/collections/array0.kt" diff --git a/backend.native/tests/codegen/bridges/test14.kt b/backend.native/tests/codegen/bridges/test14.kt new file mode 100644 index 00000000000..26d94b08a75 --- /dev/null +++ b/backend.native/tests/codegen/bridges/test14.kt @@ -0,0 +1,44 @@ +open class A { + open fun foo(x: T, y: U) { + println(x.toString()) + println(y.toString()) + } +} + +interface I1 { + fun foo(x: Int, y: T) +} + +interface I2 { + fun foo(x: T, y: Int) +} + +class B : A(), I1, I2 { + var z: Int = 5 + var q: Int = 7 + override fun foo(x: Int, y: Int) { + z = x + q = y + } +} + +fun zzz(a: A) { + a.foo(42, 56) +} + +fun main(args: Array) { + val b = B() + zzz(b) + val a = A() + zzz(a) + println(b.z) + println(b.q) + val i1: I1 = b + i1.foo(56, 42) + println(b.z) + println(b.q) + val i2: I2 = b + i2.foo(156, 142) + println(b.z) + println(b.q) +} \ No newline at end of file diff --git a/backend.native/tests/codegen/bridges/test15.kt b/backend.native/tests/codegen/bridges/test15.kt new file mode 100644 index 00000000000..a29e6f9a958 --- /dev/null +++ b/backend.native/tests/codegen/bridges/test15.kt @@ -0,0 +1,35 @@ +// non-generic interface, generic impl, vtable call + interface call +open class A { + open var size: T = 56 as T +} + +interface C { + var size: Int +} + +open class B : C, A() + +open class D: B() { + override var size: Int = 117 +} + +fun foo(a: A) { + a.size = 42 as T +} + +fun box(): String { + val b = B() + + foo(b) + if (b.size != 42) return "fail 1" + val d = D() + if (d.size != 117) return "fail 2" + foo(d) + if (d.size != 42) return "fail 3" + + return "OK" +} + +fun main(args: Array) { + println(box()) +} \ No newline at end of file diff --git a/backend.native/tests/codegen/bridges/test16.kt b/backend.native/tests/codegen/bridges/test16.kt new file mode 100644 index 00000000000..7a9aa8219cf --- /dev/null +++ b/backend.native/tests/codegen/bridges/test16.kt @@ -0,0 +1,20 @@ +interface A { + fun foo(): String +} + +abstract class C: A + +open class B: C() { + override fun foo(): String { + return "OK" + } +} + +fun bar(c: C) = c.foo() + +fun main(args: Array) { + val b = B() + val c: C = b + println(bar(b)) + println(bar(c)) +} \ No newline at end of file