[K/N][Tests] Move codegen test sources interfaceCallsNCasts..vector

^KT-61259
This commit is contained in:
Vladimir Sukharev
2023-12-15 00:13:04 +01:00
committed by Space Team
parent 56e1c5cbc6
commit 93642020ff
182 changed files with 2023 additions and 686 deletions
@@ -0,0 +1,148 @@
@file:OptIn(ExperimentalForeignApi::class)
import kotlin.test.*
import kotlinx.cinterop.*
fun box(): String {
val values = mutableListOf<Long>()
for (value in listOf(
0L,
Byte.MIN_VALUE.toLong(), Byte.MAX_VALUE.toLong(), UByte.MAX_VALUE.toLong(),
Short.MIN_VALUE.toLong(), Short.MAX_VALUE.toLong(), UShort.MAX_VALUE.toLong(),
Int.MIN_VALUE.toLong(), Int.MAX_VALUE.toLong(), UInt.MAX_VALUE.toLong(),
Long.MIN_VALUE.toLong(), Long.MAX_VALUE.toLong(), ULong.MAX_VALUE.toLong()
)) {
values.add(value - 1)
values.add(value)
values.add(value + 1)
}
for (value in values) {
testConvertAll(value.toByte())
testConvertAll(value.toUByte())
testConvertAll(value.toShort())
testConvertAll(value.toUShort())
testConvertAll(value.toInt())
testConvertAll(value.toUInt())
testConvertAll(value.toLong())
testConvertAll(value.toULong())
}
return "OK"
}
fun testConvertAll(value: Byte) {
assertEquals(value.toByte(), value.convert<Byte>())
assertEquals(value.toUByte(), value.convert<UByte>())
assertEquals(value.toShort(), value.convert<Short>())
assertEquals(value.toUShort(), value.convert<UShort>())
assertEquals(value.toInt(), value.convert<Int>())
assertEquals(value.toUInt(), value.convert<UInt>())
assertEquals(value.toLong(), value.convert<Long>())
assertEquals(value.toULong(), value.convert<ULong>())
assertEquals(value.toByte(), value.narrow<Byte>())
assertEquals(value.toByte(), value.signExtend<Byte>())
assertEquals(value.toShort(), value.signExtend<Short>())
assertEquals(value.toInt(), value.signExtend<Int>())
assertEquals(value.toLong(), value.signExtend<Long>())
}
fun testConvertAll(value: Short) {
assertEquals(value.toByte(), value.convert<Byte>())
assertEquals(value.toUByte(), value.convert<UByte>())
assertEquals(value.toShort(), value.convert<Short>())
assertEquals(value.toUShort(), value.convert<UShort>())
assertEquals(value.toInt(), value.convert<Int>())
assertEquals(value.toUInt(), value.convert<UInt>())
assertEquals(value.toLong(), value.convert<Long>())
assertEquals(value.toULong(), value.convert<ULong>())
assertEquals(value.toByte(), value.narrow<Byte>())
assertEquals(value.toShort(), value.narrow<Short>())
assertEquals(value.toShort(), value.signExtend<Short>())
assertEquals(value.toInt(), value.signExtend<Int>())
assertEquals(value.toLong(), value.signExtend<Long>())
}
fun testConvertAll(value: Int) {
assertEquals(value.toByte(), value.convert<Byte>())
assertEquals(value.toUByte(), value.convert<UByte>())
assertEquals(value.toShort(), value.convert<Short>())
assertEquals(value.toUShort(), value.convert<UShort>())
assertEquals(value.toInt(), value.convert<Int>())
assertEquals(value.toUInt(), value.convert<UInt>())
assertEquals(value.toLong(), value.convert<Long>())
assertEquals(value.toULong(), value.convert<ULong>())
assertEquals(value.toByte(), value.narrow<Byte>())
assertEquals(value.toShort(), value.narrow<Short>())
assertEquals(value.toInt(), value.narrow<Int>())
assertEquals(value.toInt(), value.signExtend<Int>())
assertEquals(value.toLong(), value.signExtend<Long>())
}
fun testConvertAll(value: Long) {
assertEquals(value.toByte(), value.convert<Byte>())
assertEquals(value.toUByte(), value.convert<UByte>())
assertEquals(value.toShort(), value.convert<Short>())
assertEquals(value.toUShort(), value.convert<UShort>())
assertEquals(value.toInt(), value.convert<Int>())
assertEquals(value.toUInt(), value.convert<UInt>())
assertEquals(value.toLong(), value.convert<Long>())
assertEquals(value.toULong(), value.convert<ULong>())
assertEquals(value.toByte(), value.narrow<Byte>())
assertEquals(value.toShort(), value.narrow<Short>())
assertEquals(value.toInt(), value.narrow<Int>())
assertEquals(value.toLong(), value.narrow<Long>())
assertEquals(value.toLong(), value.signExtend<Long>())
}
fun testConvertAll(value: UByte) {
assertEquals(value.toByte(), value.convert<Byte>())
assertEquals(value.toUByte(), value.convert<UByte>())
assertEquals(value.toShort(), value.convert<Short>())
assertEquals(value.toUShort(), value.convert<UShort>())
assertEquals(value.toInt(), value.convert<Int>())
assertEquals(value.toUInt(), value.convert<UInt>())
assertEquals(value.toLong(), value.convert<Long>())
assertEquals(value.toULong(), value.convert<ULong>())
}
fun testConvertAll(value: UShort) {
assertEquals(value.toByte(), value.convert<Byte>())
assertEquals(value.toUByte(), value.convert<UByte>())
assertEquals(value.toShort(), value.convert<Short>())
assertEquals(value.toUShort(), value.convert<UShort>())
assertEquals(value.toInt(), value.convert<Int>())
assertEquals(value.toUInt(), value.convert<UInt>())
assertEquals(value.toLong(), value.convert<Long>())
assertEquals(value.toULong(), value.convert<ULong>())
}
fun testConvertAll(value: UInt) {
assertEquals(value.toByte(), value.convert<Byte>())
assertEquals(value.toUByte(), value.convert<UByte>())
assertEquals(value.toShort(), value.convert<Short>())
assertEquals(value.toUShort(), value.convert<UShort>())
assertEquals(value.toInt(), value.convert<Int>())
assertEquals(value.toUInt(), value.convert<UInt>())
assertEquals(value.toLong(), value.convert<Long>())
assertEquals(value.toULong(), value.convert<ULong>())
}
fun testConvertAll(value: ULong) {
assertEquals(value.toByte(), value.convert<Byte>())
assertEquals(value.toUByte(), value.convert<UByte>())
assertEquals(value.toShort(), value.convert<Short>())
assertEquals(value.toUShort(), value.convert<UShort>())
assertEquals(value.toInt(), value.convert<Int>())
assertEquals(value.toUInt(), value.convert<UInt>())
assertEquals(value.toLong(), value.convert<Long>())
assertEquals(value.toULong(), value.convert<ULong>())
}
@@ -0,0 +1,21 @@
@file:OptIn(ExperimentalForeignApi::class)
import kotlin.test.*
import kotlinx.cinterop.*
fun convertIntToShortOrNull(i: Int, b: Boolean): Short? = if (b) i.convert() else null
fun narrowIntToShortOrNull(i: Int, b: Boolean): Short? = if (b) i.narrow() else null
fun signExtendShortToIntOrNull(i: Short, b: Boolean): Int? = if (b) i.signExtend() else null
fun box(): String {
assertNull(convertIntToShortOrNull(0, false))
assertEquals(1, convertIntToShortOrNull(1, true))
assertNull(narrowIntToShortOrNull(2, false))
assertEquals(3, narrowIntToShortOrNull(3, true))
assertNull(signExtendShortToIntOrNull(4, false))
assertEquals(5, signExtendShortToIntOrNull(5, true))
return "OK"
}
@@ -0,0 +1,14 @@
@file:OptIn(ExperimentalForeignApi::class)
import kotlin.test.*
import kotlinx.cinterop.*
fun box(): String {
assertEquals(1, 257.convert<Byte>())
assertEquals(255u, (-1).convert<UByte>())
assertEquals(0, Long.MIN_VALUE.narrow<Int>())
assertEquals(-1, Long.MAX_VALUE.narrow<Short>())
assertEquals(-1L, (-1).signExtend<Long>())
return "OK"
}
@@ -0,0 +1,43 @@
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class, kotlin.native.internal.InternalForKotlinNative::class)
package codegen.intrinsics.interop_sourceCodeStruct
import kotlinx.cinterop.*
import kotlinx.cinterop.internal.*
import kotlin.test.*
// Just making sure this doesn't get accidentally forbidden or otherwise broken.
// Used by auto-generated code, user-defined structs should be declared via
// structs in C headers or .def files instead.
@CStruct("struct { int p0; int p1; }")
class S(rawPtr: NativePtr) : CStructVar(rawPtr) {
companion object : CStructVar.Type(8, 4)
var x: Int
get() = memberAt<IntVar>(0).value
set(value) {
memberAt<IntVar>(0).value = value
}
var y: Int
get() = memberAt<IntVar>(4).value
set(value) {
memberAt<IntVar>(4).value = value
}
}
@Test
fun test() = memScoped {
val s = alloc<S>()
s.x = 123
assertEquals(123, s.x)
assertEquals(123, s.ptr.reinterpret<IntVar>()[0])
s.y = 321
assertEquals(321, s.y)
assertEquals(321, s.ptr.reinterpret<IntVar>()[1])
}
@@ -0,0 +1,18 @@
/*
* Copyright 2010-2021 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(kotlin.experimental.ExperimentalNativeApi::class)
import kotlin.test.*
import kotlin.native.Platform
@Test
@OptIn(kotlin.ExperimentalStdlibApi::class)
fun testIsExperimentalMM() {
if (isExperimentalMM()) {
assertEquals(Platform.memoryModel, MemoryModel.EXPERIMENTAL)
} else {
assertNotEquals(Platform.memoryModel, MemoryModel.EXPERIMENTAL)
}
}