[K/N][Tests] Move some codegen tests to new infra: annotations..coroutines

^KT-61259
This commit is contained in:
Vladimir Sukharev
2023-12-12 13:30:53 +01:00
committed by Space Team
parent a1d13f54cb
commit a5f3d5b737
269 changed files with 2207 additions and 0 deletions
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
package codegen.bridges.nativePointed
import kotlinx.cinterop.*
import kotlin.test.*
abstract class C {
abstract fun foo(x: Int): CPointer<*>?
}
class CImpl : C() {
override fun foo(x: Int) = null
}
@Test fun runTest() {
val c: C = CImpl()
assertNull(c.foo(42))
}
@@ -0,0 +1,34 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.signature
import kotlin.test.*
class A { }
class B { }
class C { }
interface Parser<in IN: Any, out OUT: Any> {
fun parse(source: IN): OUT
}
interface MultiParser<in IN: Any, out OUT: Any> {
fun parse(source: IN): Collection<OUT>
}
interface ExtendsInterface<T: Any>: Parser<A, T>, MultiParser<B, T> {
override fun parse(source: B): Collection<T> = ArrayList<T>()
}
abstract class AbstractClass(): ExtendsInterface<C> {
public override fun parse(source: A): C = C()
}
@Test fun runTest() {
val array = object : AbstractClass() { }.parse(B())
}
+46
View File
@@ -0,0 +1,46 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.special
import kotlin.test.*
private object NotEmptyMap : MutableMap<Any, Int> {
override fun containsKey(key: Any): Boolean = true
override fun containsValue(value: Int): Boolean = true
// non-special bridges get(Object)Integer -> get(Object)I
override fun get(key: Any): Int = 1
override fun remove(key: Any): Int = 1
override val size: Int get() = 0
override fun isEmpty(): Boolean = true
override fun put(key: Any, value: Int): Int? = throw UnsupportedOperationException()
override fun putAll(from: Map<out Any, Int>): Unit = throw UnsupportedOperationException()
override fun clear(): Unit = throw UnsupportedOperationException()
override val entries: MutableSet<MutableMap.MutableEntry<Any, Int>> get() = null!!
override val keys: MutableSet<Any> get() = null!!
override val values: MutableCollection<Int> get() = null!!
}
fun box(): String {
val n = NotEmptyMap as MutableMap<Any?, Any?>
if (n.get(null) != null) return "fail 1"
if (n.containsKey(null)) return "fail 2"
if (n.containsValue(null)) return "fail 3"
if (n.remove(null) != null) return "fail 4"
if (n.get(1) == null) return "fail 5"
if (!n.containsKey("")) return "fail 6"
if (!n.containsValue(3)) return "fail 7"
if (n.remove("") == null) return "fail 8"
return "Ok"
}
@Test fun runTest() {
println(box())
}
@@ -0,0 +1 @@
Ok
@@ -0,0 +1,44 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.specialGeneric
import kotlin.test.*
interface Element {
val isContained: Boolean
}
object ContainedElement : Element {
override val isContained: Boolean = true
}
object NotContainedElement : Element {
override val isContained: Boolean = false
}
internal class MySet<E : Element> : Set<E> {
override fun contains(element: E): Boolean = element.isContained
override fun equals(other: Any?): Boolean = TODO()
override fun hashCode(): Int = TODO()
override fun toString(): String = TODO()
override val size: Int get() = TODO()
override fun isEmpty(): Boolean = TODO()
override fun containsAll(elements: Collection<E>): Boolean = TODO()
override fun iterator(): Iterator<E> = TODO()
}
fun set(): Set<Any> = MySet<Element>()
@Test
fun testMySet() {
val set = set()
assertFalse(set.contains(Any()))
assertFalse(set.contains(NotContainedElement))
assertTrue(set.contains(ContainedElement))
}
+24
View File
@@ -0,0 +1,24 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.test0
import kotlin.test.*
// vtable call
open class A {
open fun foo(): Any = "A"
}
open class C : A() {
override fun foo(): Int = 42
}
@Test fun runTest() {
val c = C()
val a: A = c
println(c.foo().toString())
println(a.foo().toString())
}
@@ -0,0 +1,2 @@
42
42
+27
View File
@@ -0,0 +1,27 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.test1
import kotlin.test.*
// interface call, bridge overridden
interface Z1 {
fun foo(x: Int) : Any
}
open class A : Z1 {
override fun foo(x: Int) : Int = 5
}
open class B : A() {
override fun foo(x: Int) : Int = 42
}
@Test fun runTest() {
val z1: A = B()
println((z1.foo(1) + 1000).toString())
}
@@ -0,0 +1 @@
1042
+37
View File
@@ -0,0 +1,37 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.test10
import kotlin.test.*
open class A<T> {
open fun foo(x: T) {
println(x.toString())
}
}
interface I {
fun foo(x: Int)
}
class B : A<Int>(), I {
var z: Int = 5
override fun foo(x: Int) {
z = x
}
}
fun zzz(a: A<Int>) {
a.foo(42)
}
@Test fun runTest() {
val b = B()
zzz(b)
val a = A<Int>()
zzz(a)
println(b.z)
}
@@ -0,0 +1,2 @@
42
42
+29
View File
@@ -0,0 +1,29 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.test11
import kotlin.test.*
interface I {
fun foo(x: Int)
}
abstract class A<T> {
abstract fun foo(x: T)
}
class B : A<Int>(), I {
override fun foo(x: Int) = println(x)
}
@Test fun runTest() {
val b = B()
val a: A<Int> = b
val c: I = b
b.foo(42)
a.foo(42)
c.foo(42)
}
@@ -0,0 +1,3 @@
42
42
42
+33
View File
@@ -0,0 +1,33 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.test12
import kotlin.test.*
abstract class A<in T> {
abstract fun foo(x: T)
}
class B : A<Int>() {
override fun foo(x: Int) {
println("B: $x")
}
}
class C : A<Any>() {
override fun foo(x: Any) {
println("C: $x")
}
}
fun foo(arg: A<Int>) {
arg.foo(42)
}
@Test fun runTest() {
foo(B())
foo(C())
}
@@ -0,0 +1,2 @@
B: 42
C: 42
+31
View File
@@ -0,0 +1,31 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.test13
import kotlin.test.*
open class A<T> {
open fun T.foo() {
println(this.toString())
}
fun bar(x: T) {
x.foo()
}
}
open class B: A<Int>() {
override fun Int.foo() {
println(this)
}
}
@Test fun runTest() {
val b = B()
val a = A<Int>()
b.bar(42)
a.bar(42)
}
@@ -0,0 +1,2 @@
42
42
+53
View File
@@ -0,0 +1,53 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.test14
import kotlin.test.*
open class A<T, U> {
open fun foo(x: T, y: U) {
println(x.toString())
println(y.toString())
}
}
interface I1<T> {
fun foo(x: Int, y: T)
}
interface I2<T> {
fun foo(x: T, y: Int)
}
class B : A<Int, Int>(), I1<Int>, I2<Int> {
var z: Int = 5
var q: Int = 7
override fun foo(x: Int, y: Int) {
z = x
q = y
}
}
fun zzz(a: A<Int, Int>) {
a.foo(42, 56)
}
@Test fun runTest() {
val b = B()
zzz(b)
val a = A<Int, Int>()
zzz(a)
println(b.z)
println(b.q)
val i1: I1<Int> = b
i1.foo(56, 42)
println(b.z)
println(b.q)
val i2: I2<Int> = b
i2.foo(156, 142)
println(b.z)
println(b.q)
}
@@ -0,0 +1,8 @@
42
56
42
56
56
42
156
142
+44
View File
@@ -0,0 +1,44 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.test15
import kotlin.test.*
// non-generic interface, generic impl, vtable call + interface call
open class A<T> {
open var size: T = 56 as T
}
interface C {
var size: Int
}
open class B : C, A<Int>()
open class D: B() {
override var size: Int = 117
}
fun <T> foo(a: A<T>) {
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"
}
@Test fun runTest() {
println(box())
}
@@ -0,0 +1 @@
OK
+29
View File
@@ -0,0 +1,29 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.test16
import kotlin.test.*
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()
@Test fun runTest() {
val b = B()
val c: C = b
println(bar(b))
println(bar(c))
}
@@ -0,0 +1,2 @@
OK
OK
+34
View File
@@ -0,0 +1,34 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.test17
import kotlin.test.*
// abstract bridge
interface A<T> {
fun foo(): T
}
abstract class B<T>: A<T>
abstract class C: B<Int>()
class D: C() {
override fun foo(): Int {
return 42
}
}
@Test fun runTest() {
val d = D()
val c: C = d
val b: B<Int> = d
val a: A<Int> = d
println(d.foo())
println(c.foo())
println(b.foo())
println(a.foo())
}
@@ -0,0 +1,4 @@
42
42
42
42
+22
View File
@@ -0,0 +1,22 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.test18
import kotlin.test.*
// overriden function returns Unit
open class A {
open fun foo(): Any = 42
}
open class B: A() {
override fun foo(): Unit { }
}
@Test fun runTest() {
val a: A = B()
println(a.foo())
}
@@ -0,0 +1 @@
kotlin.Unit
+26
View File
@@ -0,0 +1,26 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.test2
import kotlin.test.*
// vtable call, bridge inherited
open class A {
open fun foo(): Any = "A"
}
open class C : A() {
override fun foo(): Int = 42
}
open class D: C()
@Test fun runTest() {
val c = D()
val a: A = c
println(c.foo().toString())
println(a.foo().toString())
}
@@ -0,0 +1,2 @@
42
42
+39
View File
@@ -0,0 +1,39 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.test3
import kotlin.test.*
// non-generic interface, generic impl, non-virtual call + interface call
open class A<T> {
var size: T = 56 as T
}
interface C {
var size: Int
}
class B : C, A<Int>()
fun box(): String {
val b = B()
if (b.size != 56) return "fail 1"
b.size = 55
if (b.size != 55) return "fail 2"
val c: C = b
if (c.size != 55) return "fail 3"
c.size = 57
if (c.size != 57) return "fail 4"
return "OK"
}
@Test fun runTest() {
println(box())
}
@@ -0,0 +1 @@
OK
+30
View File
@@ -0,0 +1,30 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.test4
import kotlin.test.*
// vtable call + interface call
interface Z {
fun foo(): Any
}
interface Y {
fun foo(): Int
}
open class A {
fun foo(): Int = 42
}
open class B: A(), Z, Y
@Test fun runTest() {
val z: Z = B()
val y: Y = z as Y
println(z.foo().toString())
println(y.foo().toString())
}
@@ -0,0 +1,2 @@
42
42
+39
View File
@@ -0,0 +1,39 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.test5
import kotlin.test.*
// non-generic interface, generic impl, vtable call + interface call
open class A<T> {
open var size: T = 56 as T
}
interface C {
var size: Int
}
open class B : C, A<Int>()
fun box(): String {
val b = B()
if (b.size != 56) return "fail 1"
b.size = 55
if (b.size != 55) return "fail 2"
val c: C = b
if (c.size != 55) return "fail 3"
c.size = 57
if (c.size != 57) return "fail 4"
return "OK"
}
@Test fun runTest() {
println(box())
}
@@ -0,0 +1 @@
OK
+40
View File
@@ -0,0 +1,40 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.test6
import kotlin.test.*
// vtable call + interface call
interface Z {
fun foo(): Any
}
interface Y {
fun foo(): Int
}
open class A {
open fun foo(): Any = "A"
}
open class C : A() {
override fun foo(): Int = 42
}
open class D: C(), Y, Z
@Test fun runTest() {
val d = D()
val y: Y = d
val z: Z = d
val c: C = d
val a: A = d
println(d.foo().toString())
println(y.foo().toString())
println(z.foo().toString())
println(c.foo().toString())
println(a.foo().toString())
}
@@ -0,0 +1,5 @@
42
42
42
42
42
+39
View File
@@ -0,0 +1,39 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.test7
import kotlin.test.*
// generic interface, non-generic impl, vtable call + interface call
open class A {
open var size: Int = 56
}
interface C<T> {
var size: T
}
open class B : C<Int>, A()
fun box(): String {
val b = B()
if (b.size != 56) return "fail 1"
b.size = 55
if (b.size != 55) return "fail 2"
val c: C<Int> = b
if (c.size != 55) return "fail 3"
c.size = 57
if (c.size != 57) return "fail 4"
return "OK"
}
@Test fun runTest() {
println(box())
}
@@ -0,0 +1 @@
OK
+39
View File
@@ -0,0 +1,39 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.test8
import kotlin.test.*
// generic interface, non-generic impl, non-virtual call + interface call
open class A {
var size: Int = 56
}
interface C<T> {
var size: T
}
class B : C<Int>, A()
fun box(): String {
val b = B()
if (b.size != 56) return "fail 1"
b.size = 55
if (b.size != 55) return "fail 2"
val c: C<Int> = b
if (c.size != 55) return "fail 3"
c.size = 57
if (c.size != 57) return "fail 4"
return "OK"
}
@Test fun runTest() {
println(box())
}
@@ -0,0 +1 @@
OK
+36
View File
@@ -0,0 +1,36 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.bridges.test9
import kotlin.test.*
// abstract class vtable call
abstract class A {
abstract fun foo(): String
}
abstract class B : A()
class Z : B() {
override fun foo() = "Z"
}
fun box(): String {
val z = Z()
val b: B = z
val a: A = z
return when {
z.foo() != "Z" -> "Fail #1"
b.foo() != "Z" -> "Fail #2"
a.foo() != "Z" -> "Fail #3"
else -> "OK"
}
}
@Test fun runTest() {
println(box())
}
@@ -0,0 +1 @@
OK