[K/N][Tests] Migrate some cinterop tests to new infra
^KT-61259
This commit is contained in:
committed by
Space Team
parent
422128f3dc
commit
bf01cb16b4
@@ -0,0 +1,37 @@
|
||||
// TARGET_BACKEND: NATIVE
|
||||
// MODULE: cinterop
|
||||
// FILE: cCallback.def
|
||||
language = C
|
||||
---
|
||||
extern char* sb;
|
||||
void runAndCatch(void(*f)(void));
|
||||
|
||||
// FILE: cCallback.cpp
|
||||
#include <stdio.h>
|
||||
|
||||
char* sb = nullptr;
|
||||
extern "C" void runAndCatch(void(*f)(void)) {
|
||||
try {
|
||||
f();
|
||||
} catch (...) {
|
||||
sb = "OK";
|
||||
}
|
||||
}
|
||||
|
||||
// MODULE: main(cinterop)
|
||||
// FILE: main.kt
|
||||
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||
|
||||
import kotlinx.cinterop.staticCFunction
|
||||
import kotlinx.cinterop.toKString
|
||||
import cCallback.runAndCatch
|
||||
import cCallback.sb
|
||||
|
||||
fun throwingCallback() {
|
||||
throw IllegalStateException("Kotlin Exception!")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
runAndCatch(staticCFunction(::throwingCallback))
|
||||
return sb?.toKString() ?: "FAIL"
|
||||
}
|
||||
Reference in New Issue
Block a user