diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index c6430455992..e95000c6637 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -3253,6 +3253,12 @@ if (PlatformInfo.isAppleTarget(project)) { it.headers "$projectDir/interop/objc/smoke.h" it.linkerOpts "-L$buildDir", "-lobjcsmoke" } + + createInterop("objcMisc") { + it.defFile 'interop/objc_with_initializer/objc_misc.def' + it.headers "$projectDir/interop/objc_with_initializer/objc_misc.h" + it.linkerOpts "-L$buildDir", "-lobjcmisc" + } } createInterop("withSpaces") { @@ -3442,6 +3448,27 @@ interopTest("interop_objc_smoke") { } } +interopTest("interop_objc_global_initializer") { + disabled = !isAppleTarget(project) + goldValue = "OK\n" + + source = "interop/objc_with_initializer/objc_test.kt" + interop = 'objcMisc' + flags = ['-g'] + + doBefore { + execKonanClang(project.target) { + args "$projectDir/interop/objc_with_initializer/objc_misc.m" + args "-lobjc", '-fobjc-arc' + args '-fPIC', '-shared', '-o', "$buildDir/libobjcmisc.dylib" + } + if (project.target instanceof KonanTarget.IOS_X64) { + UtilsKt.codesign(project, "$buildDir/libobjcmisc.dylib") + } + } +} + + standaloneTest("jsinterop_math") { doBefore { def jsinteropScript = isWindows() ? "jsinterop.bat" : "jsinterop" diff --git a/backend.native/tests/interop/objc_with_initializer/objc_misc.def b/backend.native/tests/interop/objc_with_initializer/objc_misc.def new file mode 100644 index 00000000000..24ed97ef215 --- /dev/null +++ b/backend.native/tests/interop/objc_with_initializer/objc_misc.def @@ -0,0 +1,4 @@ +language = Objective-C +headers = Foundation/NSArray.h Foundation/NSValue.h Foundation/NSString.h +headerFilter = **/objc_misc.h Foundation/NSArray.h Foundation/NSValue.h Foundation/NSString.h + diff --git a/backend.native/tests/interop/objc_with_initializer/objc_misc.h b/backend.native/tests/interop/objc_with_initializer/objc_misc.h new file mode 100644 index 00000000000..60ab23c5db7 --- /dev/null +++ b/backend.native/tests/interop/objc_with_initializer/objc_misc.h @@ -0,0 +1,11 @@ +#include +@interface A:NSObject + +@end + +@interface B:A ++(A*)giveC; +@end + +@interface C:A +@end diff --git a/backend.native/tests/interop/objc_with_initializer/objc_misc.m b/backend.native/tests/interop/objc_with_initializer/objc_misc.m new file mode 100644 index 00000000000..a186c1ef729 --- /dev/null +++ b/backend.native/tests/interop/objc_with_initializer/objc_misc.m @@ -0,0 +1,20 @@ +#import +#include "objc_misc.h" +@implementation A + +@end + +@implementation B:A ++(A*)giveC{ + return [[C alloc] init]; +} +@end + +@implementation C:A +@end + +#if 0 +int main() { + [B giveC]; +} +#endif diff --git a/backend.native/tests/interop/objc_with_initializer/objc_test.kt b/backend.native/tests/interop/objc_with_initializer/objc_test.kt new file mode 100644 index 00000000000..fdce20d8a3f --- /dev/null +++ b/backend.native/tests/interop/objc_with_initializer/objc_test.kt @@ -0,0 +1,7 @@ +import objc_misc.* + +val a = B.giveC()!! as C + +fun main() { + println("OK") +} \ No newline at end of file