From 0109e6cafb383ee4671598519d5712bccb400ebb Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Wed, 6 Nov 2019 18:28:15 +0300 Subject: [PATCH] Add test for @ExportObjCClass --- backend.native/tests/interop/objc/objcSmoke.def | 3 ++- backend.native/tests/interop/objc/smoke.kt | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/backend.native/tests/interop/objc/objcSmoke.def b/backend.native/tests/interop/objc/objcSmoke.def index 5615106c2ad..7dfc9ef78bc 100644 --- a/backend.native/tests/interop/objc/objcSmoke.def +++ b/backend.native/tests/interop/objc/objcSmoke.def @@ -1,3 +1,4 @@ language = Objective-C headers = Foundation/NSArray.h Foundation/NSValue.h Foundation/NSString.h Foundation/NSStream.h -headerFilter = **/smoke.h Foundation/NSArray.h Foundation/NSValue.h Foundation/NSString.h Foundation/NSStream.h +headerFilter = **/smoke.h Foundation/NSArray.h Foundation/NSValue.h Foundation/NSString.h Foundation/NSStream.h \ + objc/objc.h diff --git a/backend.native/tests/interop/objc/smoke.kt b/backend.native/tests/interop/objc/smoke.kt index aab0cf03676..6506cbf234c 100644 --- a/backend.native/tests/interop/objc/smoke.kt +++ b/backend.native/tests/interop/objc/smoke.kt @@ -28,6 +28,7 @@ fun run() { testInitWithCustomSelector() testAllocNoRetain() testNSOutputStreamToMemoryConstructor() + testExportObjCClass() assertEquals(2, ForwardDeclaredEnum.TWO.value) @@ -439,6 +440,19 @@ fun testNSOutputStreamToMemoryConstructor() { assertTrue(stream is NSOutputStream) } +private const val TestExportObjCClass1Name = "TestExportObjCClass" +@ExportObjCClass(TestExportObjCClass1Name) class TestExportObjCClass1 : NSObject() + +@ExportObjCClass class TestExportObjCClass2 : NSObject() + +fun testExportObjCClass() { + assertEquals(TestExportObjCClass1Name, TestExportObjCClass1().objCClassName) + assertEquals("TestExportObjCClass2", TestExportObjCClass2().objCClassName) +} + +private val Any.objCClassName: String + get() = object_getClassName(this)!!.toKString() + fun nsArrayOf(vararg elements: Any): NSArray = NSMutableArray().apply { elements.forEach { this.addObject(it as ObjCObject)