[K/N] Migrate more cinterop tests

^KT-61259
This commit is contained in:
Vladimir Sukharev
2024-01-13 12:23:35 +01:00
committed by Space Team
parent 8ed7e31b5f
commit 5f51f5e1fc
37 changed files with 1268 additions and 601 deletions
@@ -0,0 +1,36 @@
/*
* 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.
*/
// OUTPUT_DATA_FILE: fprintf.out
// TARGET_BACKEND: NATIVE
// MODULE: cinterop
// FILE: cstdio.def
headers = stdio.h
compilerOpts.osx = -D_ANSI_SOURCE
---
static inline FILE* getStdout() {
return stdout;
}
// MODULE: main(cinterop)
// FILE: main.kt
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import cstdio.*
import kotlinx.cinterop.*
val stdout
get() = getStdout()
fun main(args: Array<String>) {
fprintf(stdout, "%s %s %d %d %d %lld %.1f %.1lf %d %d\n",
"a", "b".cstr, (-1).toByte(), 2.toShort(), 3, Long.MAX_VALUE, 0.1.toFloat(), 0.2, true, false)
memScoped {
val aVar = alloc<IntVar>()
val bVar = alloc<IntVar>()
val sscanfResult = sscanf("42", "%d%d", aVar.ptr, bVar.ptr)
printf("%d %d\n", sscanfResult, aVar.value)
}
}
@@ -0,0 +1,2 @@
a b -1 2 3 9223372036854775807 0.1 0.2 1 0
1 42
@@ -0,0 +1,14 @@
/*
* 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.
*/
// OUTPUT_DATA_FILE: printf.out
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import platform.posix.printf
val golden = immutableBlobOf(0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x21, 0x00).asCPointer(0)
fun main(args: Array<String>) {
printf("%s\n", golden)
}
@@ -0,0 +1 @@
Hello!
+18
View File
@@ -0,0 +1,18 @@
/*
* 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.
*/
// OUTPUT_DATA_FILE: puts.out
// TARGET_BACKEND: NATIVE
// MODULE: cinterop
// FILE: cstdio.def
headers = stdio.h
// MODULE: main(cinterop)
// FILE: main.kt
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import cstdio.*
fun main(args: Array<String>) {
puts("Hello")
}
@@ -0,0 +1 @@
Hello