[K/N] Migrate some cinterop tests to new test infra

This commit is contained in:
Vladimir Sukharev
2023-12-01 11:18:27 +01:00
committed by Space Team
parent 22b2c1a587
commit c5248fc5f4
47 changed files with 295 additions and 176 deletions
@@ -0,0 +1,11 @@
---
struct StructDeclared;
struct StructDefined { int x; };
int useStructDeclared(struct StructDeclared* declared) {
return -1;
}
int useStructDefined(struct StructDefined* defined) {
return -2;
}
@@ -0,0 +1,34 @@
// This test mostly checks frontend behaviour.
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import forwardDeclarations.*
import cnames.structs.StructDeclared
import kotlin.test.assertEquals
import kotlinx.cinterop.COpaque
import kotlinx.cinterop.CStructVar
import kotlinx.cinterop.ptr
// The test should also check that these references can't be resolved, but the test infra doesn't support this yet:
// import cForwardDeclarations.StructUndeclared
// import cnames.structs.StructUndeclared // Supported in K1 though.
fun <T1 : T2, T2> checkSubtype2() {}
// Here we rely on frontend reporting conflicting overloads if some of these types turn out to be the same.
fun checkDifferentTypes(s: StructDeclared?) = 1
fun checkDifferentTypes(s: StructDefined?) = 2
fun main() {
checkSubtype2<StructDeclared, COpaque>()
checkSubtype2<StructDefined, CStructVar>()
val declared: StructDeclared? = null
val defined: StructDefined? = null
assertEquals(1, checkDifferentTypes(declared))
assertEquals(2, checkDifferentTypes(defined))
assertEquals(-1, useStructDeclared(declared?.ptr))
assertEquals(-2, useStructDefined(defined?.ptr))
}