Add tests for overriding Kotlin methods from Swift

This commit is contained in:
Svyatoslav Scherbina
2021-02-01 16:38:07 +03:00
committed by Vasily Levchenko
parent 0a2a8a58c1
commit e305710d91
3 changed files with 168 additions and 0 deletions
@@ -663,6 +663,76 @@ __attribute__((swift_name("ArraysInitBlock")))
- (NSString *)log __attribute__((swift_name("log()")));
@end;
__attribute__((swift_name("OverrideKotlinMethods2")))
@protocol KtOverrideKotlinMethods2
@required
- (int32_t)one __attribute__((swift_name("one()")));
@end;
__attribute__((swift_name("OverrideKotlinMethods3")))
@interface KtOverrideKotlinMethods3 : KtBase
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
@end;
__attribute__((swift_name("OverrideKotlinMethods4")))
@interface KtOverrideKotlinMethods4 : KtOverrideKotlinMethods3 <KtOverrideKotlinMethods2>
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
- (int32_t)one __attribute__((swift_name("one()")));
@end;
__attribute__((swift_name("OverrideKotlinMethods5")))
@protocol KtOverrideKotlinMethods5
@required
- (int32_t)one __attribute__((swift_name("one()")));
@end;
__attribute__((swift_name("OverrideKotlinMethods6")))
@protocol KtOverrideKotlinMethods6 <KtOverrideKotlinMethods5>
@required
@end;
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("OverrideKotlinMethodsKt")))
@interface KtOverrideKotlinMethodsKt : KtBase
/**
@note This method converts all Kotlin exceptions to errors.
*/
+ (BOOL)test0Obj:(id)obj error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("test0(obj:)")));
/**
@note This method converts all Kotlin exceptions to errors.
*/
+ (BOOL)test1Obj:(id)obj error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("test1(obj:)")));
/**
@note This method converts all Kotlin exceptions to errors.
*/
+ (BOOL)test2Obj:(id<KtOverrideKotlinMethods2>)obj error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("test2(obj:)")));
/**
@note This method converts all Kotlin exceptions to errors.
*/
+ (BOOL)test3Obj:(KtOverrideKotlinMethods3 *)obj error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("test3(obj:)")));
/**
@note This method converts all Kotlin exceptions to errors.
*/
+ (BOOL)test4Obj:(KtOverrideKotlinMethods4 *)obj error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("test4(obj:)")));
/**
@note This method converts all Kotlin exceptions to errors.
*/
+ (BOOL)test5Obj:(id<KtOverrideKotlinMethods5>)obj error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("test5(obj:)")));
/**
@note This method converts all Kotlin exceptions to errors.
*/
+ (BOOL)test6Obj:(id<KtOverrideKotlinMethods6>)obj error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("test6(obj:)")));
@end;
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("OverrideMethodsOfAnyKt")))
@interface KtOverrideMethodsOfAnyKt : KtBase
@@ -0,0 +1,66 @@
package overrideKotlinMethods
import kotlin.test.*
internal interface OverrideKotlinMethods0<T> {
fun one(): T
}
internal interface OverrideKotlinMethods1<T> : OverrideKotlinMethods0<T>
interface OverrideKotlinMethods2 {
fun one(): Int
}
open class OverrideKotlinMethods3 {
internal open fun one(): Number = 3
}
open class OverrideKotlinMethods4 : OverrideKotlinMethods3(), OverrideKotlinMethods1<Int>, OverrideKotlinMethods2 {
override fun one(): Int = 2
}
interface OverrideKotlinMethods5 {
fun one(): Int
}
interface OverrideKotlinMethods6 : OverrideKotlinMethods5
// Using `Any` because Kotlin forbids internal type in public function signature.
@Throws(Throwable::class)
fun test0(obj: Any) {
val obj0 = obj as OverrideKotlinMethods0<*>
assertEquals(1, obj0.one())
}
// Using `Any` because Kotlin forbids internal type in public function signature.
@Throws(Throwable::class)
fun test1(obj: Any) {
val obj1 = obj as OverrideKotlinMethods1<*>
assertEquals(1, obj1.one())
}
@Throws(Throwable::class)
fun test2(obj: OverrideKotlinMethods2) {
assertEquals(1, obj.one())
}
@Throws(Throwable::class)
fun test3(obj: OverrideKotlinMethods3) {
assertEquals(1, obj.one())
}
@Throws(Throwable::class)
fun test4(obj: OverrideKotlinMethods4) {
assertEquals(1, obj.one())
}
@Throws(Throwable::class)
fun test5(obj: OverrideKotlinMethods5) {
assertEquals(1, obj.one())
}
@Throws(Throwable::class)
fun test6(obj: OverrideKotlinMethods6) {
assertEquals(1, obj.one())
}
@@ -0,0 +1,32 @@
/*
* 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
class OverrideKotlinMethodsImpl : OverrideKotlinMethods4, OverrideKotlinMethods6 {
override func one() -> Int32 {
return 1
}
}
private func test1() throws {
let obj = OverrideKotlinMethodsImpl()
try OverrideKotlinMethodsKt.test0(obj: obj)
try OverrideKotlinMethodsKt.test1(obj: obj)
try OverrideKotlinMethodsKt.test2(obj: obj)
try OverrideKotlinMethodsKt.test3(obj: obj)
try OverrideKotlinMethodsKt.test4(obj: obj)
try OverrideKotlinMethodsKt.test5(obj: obj)
try OverrideKotlinMethodsKt.test6(obj: obj)
}
class OverrideKotlinMethodsTests : SimpleTestProvider {
override init() {
super.init()
test("Test1", test1)
}
}