Skip to content

Commit b1ed1e6

Browse files
committed
Added some tests on interface check for ObjC
1 parent 2fe3952 commit b1ed1e6

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

backend.native/tests/framework/values/expectedLazy.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,11 @@ __attribute__((swift_name("ClassForTypeCheck")))
989989
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
990990
@end;
991991

992+
__attribute__((swift_name("InterfaceForTypeCheck")))
993+
@protocol ValuesInterfaceForTypeCheck
994+
@required
995+
@end;
996+
992997
@interface ValuesEnumeration (ValuesKt)
993998
- (ValuesEnumeration *)getAnswer __attribute__((swift_name("getAnswer()")));
994999
@end;
@@ -1069,6 +1074,7 @@ __attribute__((swift_name("ValuesKt")))
10691074
+ (void)warning __attribute__((swift_name("warning()"))) __attribute__((deprecated("warning")));
10701075
+ (void)gc __attribute__((swift_name("gc()")));
10711076
+ (BOOL)testClassTypeCheckX:(id)x __attribute__((swift_name("testClassTypeCheck(x:)")));
1077+
+ (BOOL)testInterfaceTypeCheckX:(id)x __attribute__((swift_name("testInterfaceTypeCheck(x:)")));
10721078
@property (class, readonly) double dbl __attribute__((swift_name("dbl")));
10731079
@property (class, readonly) float flt __attribute__((swift_name("flt")));
10741080
@property (class, readonly) int32_t integer __attribute__((swift_name("integer")));

backend.native/tests/framework/values/values.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,4 +777,8 @@ class SharedRefs {
777777

778778
open class ClassForTypeCheck
779779

780-
fun testClassTypeCheck(x: Any) = x is ClassForTypeCheck
780+
fun testClassTypeCheck(x: Any) = x is ClassForTypeCheck
781+
782+
interface InterfaceForTypeCheck
783+
784+
fun testInterfaceTypeCheck(x: Any) = x is InterfaceForTypeCheck

backend.native/tests/framework/values/values.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,18 @@ func testClassTypeCheck() throws {
10041004
try assertTrue(ValuesKt.testClassTypeCheck(x: ClassForTypeCheckInheritor()))
10051005
}
10061006

1007+
class ClassForInterfaceTypeCheckInheritor1 : InterfaceForTypeCheck { }
1008+
class ClassForInterfaceTypeCheckInheritor2 : Base23, InterfaceForTypeCheck { }
1009+
class ClassForInterfaceTypeCheckInheritor3 : Base23, ExtendedBase1, InterfaceForTypeCheck { }
1010+
class ClassForInterfaceTypeCheck_Fail : Base23 { }
1011+
1012+
func testInterfaceTypeCheck() throws {
1013+
try assertTrue(ValuesKt.testInterfaceTypeCheck(x: ClassForInterfaceTypeCheckInheritor1()))
1014+
try assertTrue(ValuesKt.testInterfaceTypeCheck(x: ClassForInterfaceTypeCheckInheritor2()))
1015+
try assertTrue(ValuesKt.testInterfaceTypeCheck(x: ClassForInterfaceTypeCheckInheritor3()))
1016+
try assertFalse(ValuesKt.testInterfaceTypeCheck(x: ClassForInterfaceTypeCheck_Fail()))
1017+
}
1018+
10071019
// -------- Execution of the test --------
10081020

10091021
class ValuesTests : TestProvider {
@@ -1054,6 +1066,7 @@ class ValuesTests : TestProvider {
10541066
TestCase(name: "TestWeakRefs", method: withAutorelease(testWeakRefs)),
10551067
TestCase(name: "TestSharedRefs", method: withAutorelease(TestSharedRefs().test)),
10561068
TestCase(name: "TestClassTypeCheck", method: withAutorelease(testClassTypeCheck)),
1069+
TestCase(name: "TestInterfaceTypeCheck", method: withAutorelease(testInterfaceTypeCheck)),
10571070
TestCase(name: "TestGH2931", method: withAutorelease(testGH2931)),
10581071
]
10591072
}

backend.native/tests/interop/objc/smoke.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ class MutablePairImpl(first: Int, second: Int) : NSObject(), MutablePairProtocol
141141
constructor() : this(123, 321)
142142
}
143143

144+
interface Zzz
145+
144146
fun testTypeOps() {
145147
assertTrue(99.asAny() is NSNumber)
146148
assertTrue(null.asAny() is NSNumber?)
@@ -149,6 +151,7 @@ fun testTypeOps() {
149151
assertTrue("bar".asAny() is NSString)
150152

151153
assertTrue(Foo.asAny() is FooMeta)
154+
assertFalse(Foo.asAny() is Zzz)
152155
assertTrue(Foo.asAny() is NSObjectMeta)
153156
assertTrue(Foo.asAny() is NSObject)
154157
assertFalse(Foo.asAny() is Foo)

0 commit comments

Comments
 (0)