Native: correct ObjCExport test for forward declarations

The test relies on the fact that any name can be imported from a "magic"
package like `objcnames.classes`.
This was the case for K1, but likely won't be for K2: the compiler
should allow importing only those names that are actually
forward-declared in a cinterop library.

This commit changes the test that way. In particular, moves it to a
different task that has a cinterop dependency.
This commit is contained in:
Svyatoslav Scherbina
2023-01-24 09:08:13 +01:00
committed by Space Team
parent 445d44b79a
commit 86a29a7b07
8 changed files with 62 additions and 9 deletions
@@ -4477,6 +4477,9 @@ if (PlatformInfo.isAppleTarget(project)) {
it.defFile 'interop/objc/include_categories/objc_include_categories.def'
it.headers "$projectDir/interop/objc/include_categories/objc_include_categories.h"
}
createInterop("frameworkForwardDeclarations") {
it.defFile 'framework/forwardDeclarations/clib.def'
}
}
createInterop("withSpaces") {
@@ -6058,6 +6061,14 @@ if (isAppleTarget(project)) {
}
}
}
frameworkTest("testForwardDeclarationsFramework") {
framework('ForwardDeclarations') {
sources = ['framework/forwardDeclarations']
library = 'frameworkForwardDeclarations'
}
swiftSources = ['framework/forwardDeclarations/']
}
}
/**
@@ -0,0 +1,17 @@
language=Objective-C
---
struct ForwardDeclaredStruct;
@class ForwardDeclaredClass;
@protocol ForwardDeclaredProtocol;
struct ForwardDeclaredStruct* sameStruct(struct ForwardDeclaredStruct* ptr) {
return ptr;
}
ForwardDeclaredClass* sameClass(ForwardDeclaredClass* obj) {
return obj;
}
id<ForwardDeclaredProtocol> sameProtocol(id<ForwardDeclaredProtocol> obj) {
return obj;
}
@@ -0,0 +1,9 @@
import clib.*
import cnames.structs.ForwardDeclaredStruct
import objcnames.classes.ForwardDeclaredClass
import objcnames.protocols.ForwardDeclaredProtocolProtocol
import kotlinx.cinterop.CPointer
fun sameForwardDeclaredStruct(ptr: CPointer<ForwardDeclaredStruct>?): CPointer<ForwardDeclaredStruct>? = sameStruct(ptr)
fun sameForwardDeclaredClass(obj: ForwardDeclaredClass?): ForwardDeclaredClass? = sameClass(obj)
fun sameForwardDeclaredProtocol(obj: ForwardDeclaredProtocolProtocol?): ForwardDeclaredProtocolProtocol? = sameProtocol(obj)
@@ -0,0 +1,25 @@
import ForwardDeclarations
private func test1() throws {
let ptr = UnsafeMutableRawPointer(bitPattern: 0x1234)
try assertEquals(actual: LibKt.sameForwardDeclaredStruct(ptr: ptr), expected: ptr)
// We can't actually test this, because Swift can't import neither types nor functions due to
// "interface/protocol '...' is incomplete":
//
// let classObj: ForwardDeclaredClass? = nil
// try assertNil(LibKt.sameForwardDeclaredClass(obj: classObj))
//
// let protocolObj: ForwardDeclaredProtocol? = nil
// try assertNil(LibKt.sameForwardDeclaredProtocol(obj: protocolObj))
}
// -------- Execution of the test --------
class TestTests : SimpleTestProvider {
override init() {
super.init()
test("test1", test1)
}
}
@@ -3081,8 +3081,6 @@ __attribute__((swift_name("ValuesKt")))
+ (BOOL)isBlockNullBlock:(void (^ _Nullable)(void))block __attribute__((swift_name("isBlockNull(block:)")));
+ (BOOL)isFunctionObj:(id _Nullable)obj __attribute__((swift_name("isFunction(obj:)")));
+ (BOOL)isFunction0Obj:(id _Nullable)obj __attribute__((swift_name("isFunction0(obj:)")));
+ (void)takeForwardDeclaredClassObj:(ForwardDeclaredClass *)obj __attribute__((swift_name("takeForwardDeclaredClass(obj:)")));
+ (void)takeForwardDeclaredProtocolObj:(id<ForwardDeclared>)obj __attribute__((swift_name("takeForwardDeclaredProtocol(obj:)")));
+ (void)error __attribute__((swift_name("error()"))) __attribute__((unavailable("error")));
+ (void)warning __attribute__((swift_name("warning()"))) __attribute__((deprecated("warning")));
+ (void)gc __attribute__((swift_name("gc()")));
@@ -3016,8 +3016,6 @@ __attribute__((swift_name("ValuesKt")))
+ (BOOL)isBlockNullBlock:(void (^ _Nullable)(void))block __attribute__((swift_name("isBlockNull(block:)")));
+ (BOOL)isFunctionObj:(id _Nullable)obj __attribute__((swift_name("isFunction(obj:)")));
+ (BOOL)isFunction0Obj:(id _Nullable)obj __attribute__((swift_name("isFunction0(obj:)")));
+ (void)takeForwardDeclaredClassObj:(ForwardDeclaredClass *)obj __attribute__((swift_name("takeForwardDeclaredClass(obj:)")));
+ (void)takeForwardDeclaredProtocolObj:(id<ForwardDeclared>)obj __attribute__((swift_name("takeForwardDeclaredProtocol(obj:)")));
+ (void)error __attribute__((swift_name("error()"))) __attribute__((unavailable("error")));
+ (void)warning __attribute__((swift_name("warning()"))) __attribute__((deprecated("warning")));
+ (void)gc __attribute__((swift_name("gc()")));
@@ -3016,8 +3016,6 @@ __attribute__((swift_name("ValuesKt")))
+ (BOOL)isBlockNullBlock:(void (^ _Nullable)(void))block __attribute__((swift_name("isBlockNull(block:)")));
+ (BOOL)isFunctionObj:(id _Nullable)obj __attribute__((swift_name("isFunction(obj:)")));
+ (BOOL)isFunction0Obj:(id _Nullable)obj __attribute__((swift_name("isFunction0(obj:)")));
+ (void)takeForwardDeclaredClassObj:(ForwardDeclaredClass *)obj __attribute__((swift_name("takeForwardDeclaredClass(obj:)")));
+ (void)takeForwardDeclaredProtocolObj:(id<ForwardDeclared>)obj __attribute__((swift_name("takeForwardDeclaredProtocol(obj:)")));
+ (void)error __attribute__((swift_name("error()"))) __attribute__((unavailable("error")));
+ (void)warning __attribute__((swift_name("warning()"))) __attribute__((deprecated("warning")));
+ (void)gc __attribute__((swift_name("gc()")));
@@ -536,9 +536,6 @@ fun isFunction0(obj: Any?): Boolean = obj is Function0<*>
abstract class MyAbstractList : List<Any?>
fun takeForwardDeclaredClass(obj: objcnames.classes.ForwardDeclaredClass) {}
fun takeForwardDeclaredProtocol(obj: objcnames.protocols.ForwardDeclaredProtocol) {}
class TestKClass {
fun getKotlinClass(clazz: ObjCClass) = getOriginalKotlinClass(clazz)
fun getKotlinClass(protocol: ObjCProtocol) = getOriginalKotlinClass(protocol)