Files
kotlin-fork/kotlin-native/backend.native/tests/interop/objc/foreignException/objcExceptionMode.kt
T
Stanislav Erokhin f624800b84 Move everything under kotlin-native folder
I was forced to manually do update the following files, because otherwise
they would be ignored according .gitignore settings. Probably they
should be deleted from repo.

Interop/.idea/compiler.xml
Interop/.idea/gradle.xml
Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_runtime_1_0_3.xml
Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_0_3.xml
Interop/.idea/modules.xml
Interop/.idea/modules/Indexer/Indexer.iml
Interop/.idea/modules/Runtime/Runtime.iml
Interop/.idea/modules/StubGenerator/StubGenerator.iml
backend.native/backend.native.iml
backend.native/bc.frontend/bc.frontend.iml
backend.native/cli.bc/cli.bc.iml
backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt
backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt
backend.native/tests/link/lib/foo.kt
backend.native/tests/link/lib/foo2.kt
backend.native/tests/teamcity-test.property
2020-10-27 21:00:28 +03:00

47 lines
1.4 KiB
Kotlin

/*
* Test different behavior depending on foreignExceptionMode option
*/
import kotlin.test.*
import objcExceptionMode.*
import kotlinx.cinterop.*
import platform.objc.*
import kotlin.system.exitProcess
@Suppress("VARIABLE_WITH_REDUNDANT_INITIALIZER")
@Test fun testKT35056() {
val name = "Some native exception"
val reason = "Illegal value"
var finallyBlockTest = "FAILED"
var catchBlockTest = "FAILED"
try {
raiseExc(name, reason)
assertNotEquals("FAILED", catchBlockTest) // shall not get here anyway
} catch (e: ForeignException) {
val ret = logExc(e.nativeException) // return NSException name
assertEquals(name, ret)
assertEquals("$name:: $reason", e.message)
println("OK: ForeignException")
catchBlockTest = "PASSED"
} finally {
finallyBlockTest = "PASSED"
}
assertEquals("PASSED", catchBlockTest)
assertEquals("PASSED", finallyBlockTest)
}
@Suppress("UNUSED_PARAMETER")
fun abnormal_handler(x: Any?) : Unit {
println("OK: Ends with uncaught exception handler")
exitProcess(0)
}
fun main() {
// Depending on the `foreignxceptionMode` option (def file or cinterop cli) this test should ends
// normally with `ForeignException` handled or abnormally with `abnormal_handler`.
// Test shall validate output (golden value) from `abnormal_handler`.
objc_setUncaughtExceptionHandler(staticCFunction(::abnormal_handler))
testKT35056()
}