[K/N][Tests] Migrate dylib-interop-exe tests
^KT-61259
This commit is contained in:
committed by
Space Team
parent
83d851dd61
commit
2b2c685827
+3
@@ -0,0 +1,3 @@
|
||||
language = Objective-C
|
||||
headerFilter = **/objc_wrap.h
|
||||
linkerOpts = -lforeignException
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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()
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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()
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
language = Objective-C
|
||||
headerFilter = **/objc_wrap.h
|
||||
linkerOpts = -lforeignException
|
||||
foreignExceptionMode = objc-wrap
|
||||
@@ -0,0 +1,9 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
void raiseExc(id name, id reason);
|
||||
id logExc(id exception);
|
||||
|
||||
@interface Foo : NSObject
|
||||
- (void)instanceMethodThrow:(id)name reason:(id)reason;
|
||||
+ (void)classMethodThrow:(id)name reason:(id)reason;
|
||||
@end
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Test different types of callable with foreignExceptionMode=objc-wrap
|
||||
*/
|
||||
|
||||
import kotlin.test.*
|
||||
//import objcTests.*
|
||||
import objc_wrap.*
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
fun testInner(name: String, reason: String) {
|
||||
var finallyBlockTest = "FAILED"
|
||||
var catchBlockTest = "NOT EXPECTED"
|
||||
try {
|
||||
raiseExc(name, reason)
|
||||
} catch (e: RuntimeException) {
|
||||
catchBlockTest = "This shouldn't happen"
|
||||
} finally {
|
||||
finallyBlockTest = "PASSED"
|
||||
}
|
||||
assertEquals("NOT EXPECTED", catchBlockTest)
|
||||
assertEquals("PASSED", finallyBlockTest)
|
||||
}
|
||||
|
||||
typealias CallMe = (String, String) -> Unit
|
||||
|
||||
@Test fun testExceptionWrap(raise: CallMe) {
|
||||
val name = "Some native exception"
|
||||
val reason = "Illegal value"
|
||||
var finallyBlockTest = "FAILED"
|
||||
var catchBlockTest = "FAILED"
|
||||
try {
|
||||
raise(name, reason)
|
||||
} catch (e: ForeignException) {
|
||||
val ret = logExc(e.nativeException) // return NSException name
|
||||
assertEquals(name, ret)
|
||||
assertEquals("$name:: $reason", e.message)
|
||||
catchBlockTest = "PASSED"
|
||||
} finally {
|
||||
finallyBlockTest = "PASSED"
|
||||
}
|
||||
assertEquals("PASSED", catchBlockTest)
|
||||
assertEquals("PASSED", finallyBlockTest)
|
||||
}
|
||||
|
||||
class Bar() : Foo()
|
||||
|
||||
fun main() {
|
||||
testExceptionWrap(::raiseExc) // simple
|
||||
testExceptionWrap(::testInner) // nested try block
|
||||
testExceptionWrap(Foo::classMethodThrow) // class method
|
||||
testExceptionWrap(Foo()::instanceMethodThrow) // instance method
|
||||
testExceptionWrap(Bar()::instanceMethodThrow) // fake override
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "objc_wrap.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
void raiseExc(id name, id reason) {
|
||||
[NSException raise:name format:@"%@", reason];
|
||||
}
|
||||
|
||||
id logExc(id exc) {
|
||||
assert([exc isKindOfClass:[NSException class]]);
|
||||
return ((NSException*)exc).name;
|
||||
}
|
||||
|
||||
@implementation Foo : NSObject
|
||||
- (void) instanceMethodThrow:(id)name reason:(id)reason {
|
||||
raiseExc(name, reason);
|
||||
}
|
||||
+ (void) classMethodThrow:(id)name reason:(id)reason {
|
||||
raiseExc(name, reason);
|
||||
}
|
||||
@end
|
||||
Reference in New Issue
Block a user