[K/N][Tests] Migrate test forwardDeclarationsCast.kt

^KT-61259
This commit is contained in:
Vladimir Sukharev
2024-01-19 22:35:15 +01:00
committed by Space Team
parent 2f3705f0eb
commit e958e57c42
12 changed files with 137 additions and 108 deletions
@@ -0,0 +1,113 @@
// TARGET_BACKEND: NATIVE
// `import objcnames` somehow works only with NATIVE_STANDALONE test directive
// NATIVE_STANDALONE
// DISABLE_NATIVE: isAppleTarget=false
// MODULE: a
// FILE: a.def
language = Objective-C
---
#import <Foundation/Foundation.h>
#include <stdio.h>
struct ForwardDeclaredStruct;
@class ForwardDeclaredClass;
@protocol ForwardDeclaredProtocol;
NSString* consumeProtocol(id<ForwardDeclaredProtocol> s) {
return [NSString stringWithUTF8String:"Protocol"];
}
NSString* consumeClass(ForwardDeclaredClass* s) {
return [NSString stringWithUTF8String:"Class"];
}
NSString* consumeStruct(struct ForwardDeclaredStruct* s) {
return [NSString stringWithUTF8String:"Struct"];
}
// MODULE: b
// FILE: b.def
language = Objective-C
headers = b.h
---
// FILE: b.h
#define NS_FORMAT_ARGUMENT(X)
#import <Foundation/Foundation.h>
@protocol ForwardDeclaredProtocol
@end
@interface ForwardDeclaredProtocolImpl : NSObject<ForwardDeclaredProtocol>
@end;
@interface ForwardDeclaredClass : NSObject
@end;
struct ForwardDeclaredStruct {};
id<ForwardDeclaredProtocol> produceProtocol();
ForwardDeclaredClass* produceClass();
struct ForwardDeclaredStruct* produceStruct();
// FILE: b.m
#import "b.h"
@implementation ForwardDeclaredProtocolImpl : NSObject
@end;
@implementation ForwardDeclaredClass : NSObject
@end;
id<ForwardDeclaredProtocol> produceProtocol() {
return [ForwardDeclaredProtocolImpl new];
}
ForwardDeclaredClass* produceClass() {
return [ForwardDeclaredClass new];
}
struct ForwardDeclaredStruct S;
struct ForwardDeclaredStruct* produceStruct() {
return &S;
}
// MODULE: lib(a)
// FILE: lib.kt
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import cnames.structs.ForwardDeclaredStruct
import objcnames.classes.ForwardDeclaredClass
import objcnames.protocols.ForwardDeclaredProtocolProtocol
import a.*
import kotlinx.cinterop.*
fun testStruct(s: Any?) = consumeStruct(s as CPointer<ForwardDeclaredStruct>)
fun testClass(s: Any?) = consumeClass(s as ForwardDeclaredClass)
fun testProtocol(s: Any?) = consumeProtocol(s as ForwardDeclaredProtocolProtocol)
fun <T : ForwardDeclaredClass> testClass2Impl(s: Any?) = consumeClass(s as T)
fun <T : ForwardDeclaredProtocolProtocol> testProtocol2Impl(s: Any?) = consumeProtocol(s as T)
fun testClass2(s: Any?) = testClass2Impl<ForwardDeclaredClass>(s)
fun testProtocol2(s: Any?) = testProtocol2Impl<ForwardDeclaredProtocolProtocol>(s)
// MODULE: main(lib, b)
// FILE: main.kt
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import a.*
import b.*
fun box(): String {
if (testStruct(produceStruct()) != "Struct") throw IllegalStateException()
if (testClass(produceClass()) != "Class") throw IllegalStateException()
if (testProtocol(produceProtocol()) != "Protocol") throw IllegalStateException()
if (testClass2(produceClass()) != "Class") throw IllegalStateException()
if (testProtocol2(produceProtocol()) != "Protocol") throw IllegalStateException()
return "OK"
}
@@ -1094,16 +1094,6 @@ createInterop("workerSignals") {
}
if (PlatformInfo.isAppleTarget(project)) {
createInterop("forwardDeclarationsCastA") {
it.defFile "interop/forwardDeclarationsCast/a.def"
}
createInterop("forwardDeclarationsCastB") {
it.defFile "interop/forwardDeclarationsCast/b.def"
it.headers "$projectDir/interop/forwardDeclarationsCast/b.h"
it.extraOpts "-Xcompile-source", "$projectDir/interop/forwardDeclarationsCast/b.m"
}
createInterop("objcSmoke") {
it.defFile 'interop/objc/objcSmoke.def'
it.headers "$projectDir/interop/objc/smoke.h"
@@ -1275,14 +1265,6 @@ interopTest("interop_withSpaces") {
}
}
interopTestBase("interop_forwardDeclarationsCast", false, true) {
enabled = PlatformInfo.isAppleTarget(project)
interop = 'forwardDeclarationsCastA'
interop2 = 'forwardDeclarationsCastB'
lib = 'interop/forwardDeclarationsCast/lib.kt'
source = 'interop/forwardDeclarationsCast/main.kt'
}
dynamicTest("interop_kt43502") {
interop = "kt43502"
source = "interop/kt43502/main.kt"
@@ -1,18 +0,0 @@
language = Objective-C
---
#import <Foundation/Foundation.h>
#include <stdio.h>
struct ForwardDeclaredStruct;
@class ForwardDeclaredClass;
@protocol ForwardDeclaredProtocol;
NSString* consumeProtocol(id<ForwardDeclaredProtocol> s) {
return [NSString stringWithUTF8String:"Protocol"];
}
NSString* consumeClass(ForwardDeclaredClass* s) {
return [NSString stringWithUTF8String:"Class"];
}
NSString* consumeStruct(struct ForwardDeclaredStruct* s) {
return [NSString stringWithUTF8String:"Struct"];
}
@@ -1,2 +0,0 @@
language = Objective-C
---
@@ -1,18 +0,0 @@
#define NS_FORMAT_ARGUMENT(X)
#import <Foundation/Foundation.h>
@protocol ForwardDeclaredProtocol
@end
@interface ForwardDeclaredProtocolImpl : NSObject<ForwardDeclaredProtocol>
@end;
@interface ForwardDeclaredClass : NSObject
@end;
struct ForwardDeclaredStruct {};
id<ForwardDeclaredProtocol> produceProtocol();
ForwardDeclaredClass* produceClass();
struct ForwardDeclaredStruct* produceStruct();
@@ -1,21 +0,0 @@
#import "b.h"
@implementation ForwardDeclaredProtocolImpl : NSObject
@end;
@implementation ForwardDeclaredClass : NSObject
@end;
id<ForwardDeclaredProtocol> produceProtocol() {
return [ForwardDeclaredProtocolImpl new];
}
ForwardDeclaredClass* produceClass() {
return [ForwardDeclaredClass new];
}
struct ForwardDeclaredStruct S;
struct ForwardDeclaredStruct* produceStruct() {
return &S;
}
@@ -1,18 +0,0 @@
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import cnames.structs.ForwardDeclaredStruct
import objcnames.classes.ForwardDeclaredClass
import objcnames.protocols.ForwardDeclaredProtocolProtocol
import a.*
import kotlinx.cinterop.*
fun testStruct(s: Any?) = consumeStruct(s as CPointer<ForwardDeclaredStruct>)
fun testClass(s: Any?) = consumeClass(s as ForwardDeclaredClass)
fun testProtocol(s: Any?) = consumeProtocol(s as ForwardDeclaredProtocolProtocol)
fun <T : ForwardDeclaredClass> testClass2Impl(s: Any?) = consumeClass(s as T)
fun <T : ForwardDeclaredProtocolProtocol> testProtocol2Impl(s: Any?) = consumeProtocol(s as T)
fun testClass2(s: Any?) = testClass2Impl<ForwardDeclaredClass>(s)
fun testProtocol2(s: Any?) = testProtocol2Impl<ForwardDeclaredProtocolProtocol>(s)
@@ -1,13 +0,0 @@
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import a.*
import b.*
fun main() {
if (testStruct(produceStruct()) != "Struct") throw IllegalStateException()
if (testClass(produceClass()) != "Class") throw IllegalStateException()
if (testProtocol(produceProtocol()) != "Protocol") throw IllegalStateException()
if (testClass2(produceClass()) != "Class") throw IllegalStateException()
if (testProtocol2(produceProtocol()) != "Protocol") throw IllegalStateException()
}
@@ -5074,6 +5074,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe
runTest("compiler/testData/codegen/box/cinterop/objc/direct.kt");
}
@Test
@TestMetadata("forwardDeclarationsCast.kt")
public void testForwardDeclarationsCast() throws Exception {
runTest("compiler/testData/codegen/box/cinterop/objc/forwardDeclarationsCast.kt");
}
@Test
@TestMetadata("kt34467.kt")
public void testKt34467() throws Exception {
@@ -5190,6 +5190,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB
runTest("compiler/testData/codegen/box/cinterop/objc/direct.kt");
}
@Test
@TestMetadata("forwardDeclarationsCast.kt")
public void testForwardDeclarationsCast() throws Exception {
runTest("compiler/testData/codegen/box/cinterop/objc/forwardDeclarationsCast.kt");
}
@Test
@TestMetadata("kt34467.kt")
public void testKt34467() throws Exception {
@@ -4958,6 +4958,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
runTest("compiler/testData/codegen/box/cinterop/objc/direct.kt");
}
@Test
@TestMetadata("forwardDeclarationsCast.kt")
public void testForwardDeclarationsCast() throws Exception {
runTest("compiler/testData/codegen/box/cinterop/objc/forwardDeclarationsCast.kt");
}
@Test
@TestMetadata("kt34467.kt")
public void testKt34467() throws Exception {
@@ -5075,6 +5075,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT
runTest("compiler/testData/codegen/box/cinterop/objc/direct.kt");
}
@Test
@TestMetadata("forwardDeclarationsCast.kt")
public void testForwardDeclarationsCast() throws Exception {
runTest("compiler/testData/codegen/box/cinterop/objc/forwardDeclarationsCast.kt");
}
@Test
@TestMetadata("kt34467.kt")
public void testKt34467() throws Exception {