Add more tests for Native ObjCExport virtual adapters machinery
This commit is contained in:
committed by
Space
parent
5d5628f56e
commit
53baef8892
@@ -605,6 +605,51 @@ __attribute__((swift_name("KdocExportKt")))
|
|||||||
+ (NSString * _Nullable)whateverA:(NSString *)a error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("whatever(a:)")));
|
+ (NSString * _Nullable)whateverA:(NSString *)a error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("whatever(a:)")));
|
||||||
@end;
|
@end;
|
||||||
|
|
||||||
|
__attribute__((swift_name("KotlinPrivateOverrideI1")))
|
||||||
|
@protocol KtKotlinPrivateOverrideI1
|
||||||
|
@required
|
||||||
|
- (int32_t)i123AbstractMethod __attribute__((swift_name("i123AbstractMethod()")));
|
||||||
|
- (int32_t)i1OpenMethod __attribute__((swift_name("i1OpenMethod()")));
|
||||||
|
@end;
|
||||||
|
|
||||||
|
__attribute__((swift_name("KotlinPrivateOverrideI2")))
|
||||||
|
@protocol KtKotlinPrivateOverrideI2
|
||||||
|
@required
|
||||||
|
- (int32_t)i123AbstractMethod __attribute__((swift_name("i123AbstractMethod()")));
|
||||||
|
- (int32_t)i234AbstractMethod __attribute__((swift_name("i234AbstractMethod()")));
|
||||||
|
- (int32_t)i2AbstractMethod __attribute__((swift_name("i2AbstractMethod()")));
|
||||||
|
@end;
|
||||||
|
|
||||||
|
__attribute__((swift_name("KotlinPrivateOverrideA1")))
|
||||||
|
@interface KtKotlinPrivateOverrideA1 : KtBase <KtKotlinPrivateOverrideI1, KtKotlinPrivateOverrideI2>
|
||||||
|
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
|
||||||
|
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||||
|
- (int32_t)a1AbstractMethod __attribute__((swift_name("a1AbstractMethod()")));
|
||||||
|
- (int32_t)a1OpenMethod __attribute__((swift_name("a1OpenMethod()")));
|
||||||
|
@end;
|
||||||
|
|
||||||
|
__attribute__((swift_name("KotlinPrivateOverrideI3")))
|
||||||
|
@protocol KtKotlinPrivateOverrideI3
|
||||||
|
@required
|
||||||
|
- (int32_t)i123AbstractMethod __attribute__((swift_name("i123AbstractMethod()")));
|
||||||
|
- (int32_t)i234AbstractMethod __attribute__((swift_name("i234AbstractMethod()")));
|
||||||
|
- (int32_t)i3AbstractMethod __attribute__((swift_name("i3AbstractMethod()")));
|
||||||
|
@end;
|
||||||
|
|
||||||
|
__attribute__((swift_name("KotlinPrivateOverrideI4")))
|
||||||
|
@protocol KtKotlinPrivateOverrideI4
|
||||||
|
@required
|
||||||
|
- (int32_t)i234AbstractMethod __attribute__((swift_name("i234AbstractMethod()")));
|
||||||
|
- (int32_t)i4AbstractMethod __attribute__((swift_name("i4AbstractMethod()")));
|
||||||
|
@end;
|
||||||
|
|
||||||
|
__attribute__((objc_subclassing_restricted))
|
||||||
|
__attribute__((swift_name("KotlinPrivateOverrideKt")))
|
||||||
|
@interface KtKotlinPrivateOverrideKt : KtBase
|
||||||
|
+ (id)createP1 __attribute__((swift_name("createP1()")));
|
||||||
|
+ (id)createP12 __attribute__((swift_name("createP12()")));
|
||||||
|
@end;
|
||||||
|
|
||||||
__attribute__((objc_subclassing_restricted))
|
__attribute__((objc_subclassing_restricted))
|
||||||
__attribute__((swift_name("Kt35940Kt")))
|
__attribute__((swift_name("Kt35940Kt")))
|
||||||
@interface KtKt35940Kt : KtBase
|
@interface KtKt35940Kt : KtBase
|
||||||
|
|||||||
@@ -547,6 +547,51 @@ __attribute__((swift_name("KdocExportKt")))
|
|||||||
+ (NSString * _Nullable)whateverA:(NSString *)a error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("whatever(a:)")));
|
+ (NSString * _Nullable)whateverA:(NSString *)a error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("whatever(a:)")));
|
||||||
@end;
|
@end;
|
||||||
|
|
||||||
|
__attribute__((swift_name("KotlinPrivateOverrideI1")))
|
||||||
|
@protocol KtKotlinPrivateOverrideI1
|
||||||
|
@required
|
||||||
|
- (int32_t)i123AbstractMethod __attribute__((swift_name("i123AbstractMethod()")));
|
||||||
|
- (int32_t)i1OpenMethod __attribute__((swift_name("i1OpenMethod()")));
|
||||||
|
@end;
|
||||||
|
|
||||||
|
__attribute__((swift_name("KotlinPrivateOverrideI2")))
|
||||||
|
@protocol KtKotlinPrivateOverrideI2
|
||||||
|
@required
|
||||||
|
- (int32_t)i123AbstractMethod __attribute__((swift_name("i123AbstractMethod()")));
|
||||||
|
- (int32_t)i234AbstractMethod __attribute__((swift_name("i234AbstractMethod()")));
|
||||||
|
- (int32_t)i2AbstractMethod __attribute__((swift_name("i2AbstractMethod()")));
|
||||||
|
@end;
|
||||||
|
|
||||||
|
__attribute__((swift_name("KotlinPrivateOverrideA1")))
|
||||||
|
@interface KtKotlinPrivateOverrideA1 : KtBase <KtKotlinPrivateOverrideI1, KtKotlinPrivateOverrideI2>
|
||||||
|
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
|
||||||
|
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||||
|
- (int32_t)a1AbstractMethod __attribute__((swift_name("a1AbstractMethod()")));
|
||||||
|
- (int32_t)a1OpenMethod __attribute__((swift_name("a1OpenMethod()")));
|
||||||
|
@end;
|
||||||
|
|
||||||
|
__attribute__((swift_name("KotlinPrivateOverrideI3")))
|
||||||
|
@protocol KtKotlinPrivateOverrideI3
|
||||||
|
@required
|
||||||
|
- (int32_t)i123AbstractMethod __attribute__((swift_name("i123AbstractMethod()")));
|
||||||
|
- (int32_t)i234AbstractMethod __attribute__((swift_name("i234AbstractMethod()")));
|
||||||
|
- (int32_t)i3AbstractMethod __attribute__((swift_name("i3AbstractMethod()")));
|
||||||
|
@end;
|
||||||
|
|
||||||
|
__attribute__((swift_name("KotlinPrivateOverrideI4")))
|
||||||
|
@protocol KtKotlinPrivateOverrideI4
|
||||||
|
@required
|
||||||
|
- (int32_t)i234AbstractMethod __attribute__((swift_name("i234AbstractMethod()")));
|
||||||
|
- (int32_t)i4AbstractMethod __attribute__((swift_name("i4AbstractMethod()")));
|
||||||
|
@end;
|
||||||
|
|
||||||
|
__attribute__((objc_subclassing_restricted))
|
||||||
|
__attribute__((swift_name("KotlinPrivateOverrideKt")))
|
||||||
|
@interface KtKotlinPrivateOverrideKt : KtBase
|
||||||
|
+ (id)createP1 __attribute__((swift_name("createP1()")));
|
||||||
|
+ (id)createP12 __attribute__((swift_name("createP12()")));
|
||||||
|
@end;
|
||||||
|
|
||||||
__attribute__((objc_subclassing_restricted))
|
__attribute__((objc_subclassing_restricted))
|
||||||
__attribute__((swift_name("Kt35940Kt")))
|
__attribute__((swift_name("Kt35940Kt")))
|
||||||
@interface KtKt35940Kt : KtBase
|
@interface KtKt35940Kt : KtBase
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kotlinPrivateOverride
|
||||||
|
|
||||||
|
import kotlin.test.*
|
||||||
|
|
||||||
|
// The intention is to test "virtual adapters" machinery of ObjCExport.
|
||||||
|
// This machinery handles the case when exported Kotlin type is subclassed
|
||||||
|
// by a non-exported (e.g. private) Kotlin type, and the instance of the latter is passed to Obj-C.
|
||||||
|
|
||||||
|
interface KotlinPrivateOverrideI1 {
|
||||||
|
fun i123AbstractMethod(): Int
|
||||||
|
fun i1OpenMethod(): Int = -1
|
||||||
|
}
|
||||||
|
|
||||||
|
interface KotlinPrivateOverrideI2 {
|
||||||
|
fun i123AbstractMethod(): Int
|
||||||
|
fun i234AbstractMethod(): Int
|
||||||
|
fun i2AbstractMethod(): Int
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface KotlinPrivateOverridePI1 {
|
||||||
|
fun pi1AbstractMethod(): Int
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class KotlinPrivateOverrideA1 : KotlinPrivateOverrideI1, KotlinPrivateOverrideI2, KotlinPrivateOverridePI1 {
|
||||||
|
abstract fun a1AbstractMethod(): Int
|
||||||
|
open fun a1OpenMethod(): Int = -2
|
||||||
|
}
|
||||||
|
|
||||||
|
interface KotlinPrivateOverrideI3 {
|
||||||
|
fun i123AbstractMethod(): Int
|
||||||
|
fun i234AbstractMethod(): Int
|
||||||
|
fun i3AbstractMethod(): Int
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface KotlinPrivateOverridePI2 {
|
||||||
|
fun pi2AbstractMethod(): Int
|
||||||
|
}
|
||||||
|
|
||||||
|
private open class KotlinPrivateOverrideP1 : KotlinPrivateOverrideA1(), KotlinPrivateOverrideI3, KotlinPrivateOverridePI2 {
|
||||||
|
override fun i123AbstractMethod(): Int = 1
|
||||||
|
override fun i1OpenMethod(): Int = 2
|
||||||
|
override fun i234AbstractMethod(): Int = 3
|
||||||
|
override fun i2AbstractMethod(): Int = 4
|
||||||
|
override fun pi1AbstractMethod(): Int = 5
|
||||||
|
override fun a1AbstractMethod(): Int = 6
|
||||||
|
override fun a1OpenMethod(): Int = 7
|
||||||
|
override fun i3AbstractMethod(): Int = 8
|
||||||
|
override fun pi2AbstractMethod(): Int = 9
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createP1(): Any = KotlinPrivateOverrideP1()
|
||||||
|
|
||||||
|
interface KotlinPrivateOverrideI4 {
|
||||||
|
fun i234AbstractMethod(): Int
|
||||||
|
fun i4AbstractMethod(): Int
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface KotlinPrivateOverridePI3 {
|
||||||
|
fun pi3AbstractMethod(): Int
|
||||||
|
}
|
||||||
|
|
||||||
|
private class KotlinPrivateOverrideP12 : KotlinPrivateOverrideP1(), KotlinPrivateOverrideI4, KotlinPrivateOverridePI3 {
|
||||||
|
override fun i123AbstractMethod(): Int = 11
|
||||||
|
override fun i1OpenMethod(): Int = 12
|
||||||
|
override fun i234AbstractMethod(): Int = 13
|
||||||
|
override fun i2AbstractMethod(): Int = 14
|
||||||
|
override fun pi1AbstractMethod(): Int = 15
|
||||||
|
override fun a1AbstractMethod(): Int = 16
|
||||||
|
override fun a1OpenMethod(): Int = 17
|
||||||
|
override fun i3AbstractMethod(): Int = 18
|
||||||
|
override fun pi2AbstractMethod(): Int = 19
|
||||||
|
override fun i4AbstractMethod(): Int = 20
|
||||||
|
override fun pi3AbstractMethod(): Int = 21
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createP12(): Any = KotlinPrivateOverrideP12()
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Kt
|
||||||
|
|
||||||
|
private func testI1Methods(p: Any, base: Int32) throws {
|
||||||
|
guard let i1 = p as? KotlinPrivateOverrideI1 else { try fail() }
|
||||||
|
try assertEquals(actual: i1.i123AbstractMethod(), expected: base + 1)
|
||||||
|
try assertEquals(actual: i1.i1OpenMethod(), expected: base + 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func testI2Methods(p: Any, base: Int32) throws {
|
||||||
|
guard let i2 = p as? KotlinPrivateOverrideI2 else { try fail() }
|
||||||
|
try assertEquals(actual: i2.i123AbstractMethod(), expected: base + 1)
|
||||||
|
try assertEquals(actual: i2.i234AbstractMethod(), expected: base + 3)
|
||||||
|
try assertEquals(actual: i2.i2AbstractMethod(), expected: base + 4)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func testA1Methods(p: Any, base: Int32) throws {
|
||||||
|
guard let a1 = p as? KotlinPrivateOverrideA1 else { try fail() }
|
||||||
|
try assertEquals(actual: a1.i123AbstractMethod(), expected: base + 1)
|
||||||
|
try assertEquals(actual: a1.i1OpenMethod(), expected: base + 2)
|
||||||
|
try assertEquals(actual: a1.i234AbstractMethod(), expected: base + 3)
|
||||||
|
try assertEquals(actual: a1.i2AbstractMethod(), expected: base + 4)
|
||||||
|
try assertEquals(actual: a1.a1AbstractMethod(), expected: base + 6)
|
||||||
|
try assertEquals(actual: a1.a1OpenMethod(), expected: base + 7)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func testI3Methods(p: Any, base: Int32) throws {
|
||||||
|
guard let i3 = p as? KotlinPrivateOverrideI3 else { try fail() }
|
||||||
|
try assertEquals(actual: i3.i123AbstractMethod(), expected: base + 1)
|
||||||
|
try assertEquals(actual: i3.i234AbstractMethod(), expected: base + 3)
|
||||||
|
try assertEquals(actual: i3.i3AbstractMethod(), expected: base + 8)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func testI4Methods(p: Any, base: Int32) throws {
|
||||||
|
guard let i4 = p as? KotlinPrivateOverrideI4 else { try fail() }
|
||||||
|
try assertEquals(actual: i4.i234AbstractMethod(), expected: base + 3)
|
||||||
|
try assertEquals(actual: i4.i4AbstractMethod(), expected: base + 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func test(p: Any, base: Int32, isI4: Bool) throws {
|
||||||
|
try testI1Methods(p: p, base: base)
|
||||||
|
try testI2Methods(p: p, base: base)
|
||||||
|
try testA1Methods(p: p, base: base)
|
||||||
|
try testI3Methods(p: p, base: base)
|
||||||
|
if isI4 {
|
||||||
|
try testI4Methods(p: p, base: base)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func test1() throws {
|
||||||
|
try test(p: KotlinPrivateOverrideKt.createP1(), base: 0, isI4: false)
|
||||||
|
try test(p: KotlinPrivateOverrideKt.createP12(), base: 10, isI4: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class KotlinPrivateOverrideTests : SimpleTestProvider {
|
||||||
|
override init() {
|
||||||
|
super.init()
|
||||||
|
|
||||||
|
test("Test1", test1)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user