[K/N][tests] Move some more native tests to new testing infra
^KT-61259
This commit is contained in:
committed by
Space Team
parent
4080776fe3
commit
0a0da76a56
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.
|
||||
*/
|
||||
|
||||
import kotlin.native.internal.*
|
||||
import kotlin.test.*
|
||||
|
||||
value class BoxInt(val x: Int)
|
||||
value class BoxBoxInt(val x: BoxInt)
|
||||
data class A(val x: Int)
|
||||
value class BoxA(val x: A)
|
||||
value class BoxBoxA(val x: BoxA)
|
||||
|
||||
|
||||
class X(
|
||||
val a: Int,
|
||||
val b: List<Int>,
|
||||
val c: IntArray,
|
||||
val d: Array<Int>,
|
||||
val e: Array<Any>,
|
||||
val f: BoxInt,
|
||||
val g: BoxBoxInt,
|
||||
val h: A,
|
||||
val i: BoxA,
|
||||
val j: BoxBoxA,
|
||||
val k: Any?,
|
||||
val l: Any?,
|
||||
val m: Any?,
|
||||
val n: Any?,
|
||||
val o: IntArray?
|
||||
) {
|
||||
val p by lazy { 1 }
|
||||
lateinit var q: IntArray
|
||||
lateinit var r: IntArray
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `big class with mixed values`() {
|
||||
val lst = listOf(1, 2, 3)
|
||||
val ia = intArrayOf(1, 2, 3)
|
||||
val ia2 = intArrayOf(3, 4, 5)
|
||||
val ai = arrayOf(1, 2, 3)
|
||||
val astr: Array<Any> = arrayOf("123", "456", 1, 2, 3)
|
||||
val bi = BoxInt(2)
|
||||
val bbi = BoxBoxInt(BoxInt(3))
|
||||
val a1 = A(1)
|
||||
val a2 = A(2)
|
||||
val a3 = A(3)
|
||||
val a6 = A(3)
|
||||
val x = X(
|
||||
1, lst, ia, ai, astr, bi, bbi,
|
||||
a1, BoxA(a2), BoxBoxA(BoxA(a3)),
|
||||
4, BoxInt(5), BoxA(a6), null, null
|
||||
)
|
||||
x.r = ia2
|
||||
val fields = x.collectReferenceFieldValues()
|
||||
assertEquals(12, fields.size)
|
||||
// not using assertContains because of ===
|
||||
assertTrue(fields.any { it === lst }, "Should contain list $lst")
|
||||
assertTrue(fields.any { it === ia }, "Should contain int array $ia")
|
||||
assertTrue(fields.any { it === ia2 }, "Should contain int array $ia2")
|
||||
assertTrue(fields.any { it === ai }, "Should contain array of int $ai")
|
||||
assertTrue(fields.any { it === astr }, "Should contain array of string $astr")
|
||||
assertTrue(fields.any { it === a1 }, "Should contain A(1)")
|
||||
assertTrue(fields.any { it === a2 }, "Should contain A(2)")
|
||||
assertTrue(fields.any { it === a3 }, "Should contain A(3)")
|
||||
assertTrue(fields.any { it.toString().startsWith("Lazy value not initialized yet") }, "Should contain lazy delegate")
|
||||
assertContains(fields, 4)
|
||||
assertContains(fields, BoxInt(5))
|
||||
assertContains(fields, BoxA(a6))}
|
||||
|
||||
@Test
|
||||
fun `call on primitive`() {
|
||||
assertEquals(1.collectReferenceFieldValues(), emptyList<Any>())
|
||||
assertEquals(123456.collectReferenceFieldValues(), emptyList<Any>())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `call on value over primitive class`() {
|
||||
assertEquals(BoxInt(1).collectReferenceFieldValues(), emptyList<Any>())
|
||||
assertEquals(BoxBoxInt(BoxInt(1)).collectReferenceFieldValues(), emptyList<Any>())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `call on value class`() {
|
||||
val a1 = A(1)
|
||||
assertEquals(BoxA(a1).collectReferenceFieldValues(), listOf(a1))
|
||||
assertEquals(BoxBoxA(BoxA(a1)).collectReferenceFieldValues(), listOf(a1))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `call on String`() {
|
||||
assertEquals("1234".collectReferenceFieldValues(), emptyList<Any>())
|
||||
assertEquals("".collectReferenceFieldValues(), emptyList<Any>())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `call on primitive array`() {
|
||||
assertEquals(intArrayOf(1, 2, 3).collectReferenceFieldValues(), emptyList<Any>())
|
||||
assertEquals(intArrayOf().collectReferenceFieldValues(), emptyList<Any>())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `call on array`() {
|
||||
assertEquals(arrayOf(1, 2, 3).collectReferenceFieldValues(), listOf<Any>(1, 2, 3))
|
||||
assertEquals(arrayOf(null, "10", null, 3).collectReferenceFieldValues(), listOf<Any>("10", 3))
|
||||
assertEquals(arrayOf<Any>().collectReferenceFieldValues(), emptyList<Any>())
|
||||
assertEquals(emptyArray<Any>().collectReferenceFieldValues(), emptyList<Any>())
|
||||
assertEquals(emptyArray<Any?>().collectReferenceFieldValues(), emptyList<Any>())
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
* 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 runtime.basic.enum_equals
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
enum class EnumA {
|
||||
A, B
|
||||
}
|
||||
|
||||
enum class EnumB {
|
||||
B
|
||||
}
|
||||
|
||||
fun main() {
|
||||
println(EnumA.A == EnumA.A)
|
||||
println(EnumA.A == EnumA.B)
|
||||
println(EnumA.A == EnumB.B)
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
true
|
||||
false
|
||||
false
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* 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 runtime.basic.initializers0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class A {
|
||||
init{
|
||||
println ("A::init")
|
||||
}
|
||||
|
||||
val a = 1
|
||||
|
||||
companion object :B(1) {
|
||||
init {
|
||||
println ("A::companion")
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
println("A::companion::foo")
|
||||
}
|
||||
}
|
||||
|
||||
object AObj : B(){
|
||||
init {
|
||||
println("A::Obj")
|
||||
}
|
||||
fun foo() {
|
||||
println("A::AObj::foo")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println("main")
|
||||
A.foo()
|
||||
A.foo()
|
||||
A.AObj.foo()
|
||||
A.AObj.foo()
|
||||
}
|
||||
|
||||
open class B(val a:Int, val b:Int) {
|
||||
constructor(a:Int):this (a, 0) {
|
||||
println("B::constructor(" + a.toString()+ ")")
|
||||
}
|
||||
constructor():this(0) {
|
||||
println("B::constructor()")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
main
|
||||
B::constructor(1)
|
||||
A::companion
|
||||
A::companion::foo
|
||||
A::companion::foo
|
||||
B::constructor(0)
|
||||
B::constructor()
|
||||
A::Obj
|
||||
A::AObj::foo
|
||||
A::AObj::foo
|
||||
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
* 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 runtime.basic.initializers1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class TestClass {
|
||||
companion object {
|
||||
init {
|
||||
println("Init Test")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val t1 = TestClass()
|
||||
val t2 = TestClass()
|
||||
println("Done")
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
Init Test
|
||||
Done
|
||||
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
class A(val msg: String) {
|
||||
init {
|
||||
println("init $msg")
|
||||
}
|
||||
override fun toString(): String = msg
|
||||
}
|
||||
|
||||
val globalValue1 = 1
|
||||
val globalValue2 = A("globalValue2")
|
||||
val globalValue3 = A("globalValue3")
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println(globalValue1.toString())
|
||||
println(globalValue2.toString())
|
||||
println(globalValue3.toString())
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
init globalValue2
|
||||
init globalValue3
|
||||
1
|
||||
globalValue2
|
||||
globalValue3
|
||||
@@ -1,16 +0,0 @@
|
||||
/*
|
||||
* 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 runtime.basic.initializers3
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class Foo(val bar: Int)
|
||||
|
||||
var x = Foo(42)
|
||||
|
||||
@Test fun runTest() {
|
||||
println(x.bar)
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
42
|
||||
@@ -1,16 +0,0 @@
|
||||
/*
|
||||
* 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 runtime.basic.initializers4
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
const val INT_MAX_POWER_OF_TWO: Int = Int.MAX_VALUE / 2 + 1
|
||||
val DOUBLE = Double.MAX_VALUE - 1.0
|
||||
|
||||
@Test fun runTest() {
|
||||
println(INT_MAX_POWER_OF_TWO)
|
||||
println(DOUBLE > 0.0)
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
1073741824
|
||||
true
|
||||
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* 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 runtime.basic.initializers5
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
object A {
|
||||
val a = 42
|
||||
val b = A.a
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(A.b)
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
42
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* 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 runtime.basic.initializers7
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
object A {
|
||||
init {
|
||||
assertAUninitialized()
|
||||
}
|
||||
val a1 = 7
|
||||
val a2 = 12
|
||||
}
|
||||
|
||||
// Check that A is initialized dynamically.
|
||||
fun assertAUninitialized() {
|
||||
assertEquals(0, A.a1)
|
||||
assertEquals(0, A.a2)
|
||||
}
|
||||
|
||||
object B {
|
||||
init {
|
||||
assertBUninitialized()
|
||||
}
|
||||
val b1 = A.a2
|
||||
val b2 = C.c1
|
||||
}
|
||||
|
||||
// Check that B is initialized dynamically.
|
||||
fun assertBUninitialized() {
|
||||
assertEquals(0, B.b1)
|
||||
assertEquals(0, B.b2)
|
||||
}
|
||||
|
||||
object C {
|
||||
init {
|
||||
assertCUninitialized()
|
||||
}
|
||||
val c1 = 42
|
||||
val c2 = A.a1
|
||||
val c3 = B.b1
|
||||
val c4 = B.b2
|
||||
}
|
||||
|
||||
// Check that C is initialized dynamically.
|
||||
fun assertCUninitialized() {
|
||||
assertEquals(0, C.c1)
|
||||
assertEquals(0, C.c2)
|
||||
assertEquals(0, C.c3)
|
||||
assertEquals(0, C.c4)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
assertEquals(A.a1, C.c2)
|
||||
assertEquals(A.a2, C.c3)
|
||||
assertEquals(C.c1, C.c4)
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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 runtime.basic.initializers8
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
var globalString = "abc"
|
||||
|
||||
@Test fun runTest() {
|
||||
assertEquals("abc", globalString)
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* 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 runtime.basic.interface0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface A {
|
||||
fun b() = c()
|
||||
fun c()
|
||||
}
|
||||
|
||||
class B(): A {
|
||||
override fun c() {
|
||||
println("PASSED")
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val a:A = B()
|
||||
a.b()
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
PASSED
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* 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 runtime.basic.statements0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun simple() {
|
||||
var a = 238
|
||||
a++
|
||||
println(a)
|
||||
--a
|
||||
println(a)
|
||||
}
|
||||
|
||||
class Foo() {
|
||||
val j = 2
|
||||
var i = 29
|
||||
|
||||
fun more() {
|
||||
i++
|
||||
}
|
||||
|
||||
fun less() {
|
||||
--i
|
||||
}
|
||||
}
|
||||
|
||||
fun fields() {
|
||||
val foo = Foo()
|
||||
foo.more()
|
||||
println(foo.i)
|
||||
foo.less()
|
||||
println(foo.i)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
simple()
|
||||
fields()
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
239
|
||||
238
|
||||
30
|
||||
29
|
||||
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* 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 runtime.basic.throw0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val cond = 1
|
||||
if (cond == 2) throw RuntimeException()
|
||||
if (cond == 3) throw NoSuchElementException("no such element")
|
||||
if (cond == 4) throw Error("error happens")
|
||||
|
||||
println("Done")
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
Done
|
||||
Reference in New Issue
Block a user