[K/N] Add backend.native test for objcClassesIncludingCategories

This commit is contained in:
Sergey Bogolepov
2023-01-12 13:37:19 +02:00
committed by Space Team
parent 4ffb43c5bd
commit 3ade4fbedc
6 changed files with 118 additions and 0 deletions
@@ -4458,6 +4458,10 @@ if (PlatformInfo.isAppleTarget(project)) {
it.defFile 'interop/objc/kt49034/objcprotocol/kt49034.def'
it.headers "$projectDir/interop/objc/kt49034/objcprotocol/kt49034.h"
}
createInterop("objc_include_categories") {
it.defFile 'interop/objc/include_categories/objc_include_categories.def'
it.headers "$projectDir/interop/objc/include_categories/objc_include_categories.h"
}
}
createInterop("withSpaces") {
@@ -5205,6 +5209,23 @@ if (PlatformInfo.isAppleTarget(project)) {
useGoldenData = true
flags = ["-native-library", "$buildDir/objc_arc_contract.bc"]
}
interopTest("interop_objc_include_categories") {
useGoldenData = true
source = "interop/objc/include_categories/main.kt"
interop = "objc_include_categories"
doBeforeBuild {
mkdir(buildDir)
project.extensions.execClang.execClangForCompilerTests(project.target) {
args "$projectDir/interop/objc/include_categories/objc_include_categories.m"
args "-lobjc", '-fobjc-arc'
args '-fPIC', '-shared', '-o', "$buildDir/libobjcincludecategories.dylib"
}
if (UtilsKt.isSimulatorTarget(project, project.target)) {
UtilsKt.codesign(project, "$buildDir/libobjcincludecategories.dylib")
}
}
}
}
tasks.register("KT-50983", KonanDriverTest) {
@@ -0,0 +1,29 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
import objc_include_categories.*
class KotlinDerived : BaseClass() {
override fun multiplyBy(value: Int): Float {
return this.floatProperty * value * 100
}
}
fun main() {
val base = BaseClass()
println(base.floatProperty)
val base2 = BaseClass(float = 3.14f)
println(base2.floatProperty)
println(base.multiplyBy(2))
println()
val derived = DerivedClass()
println(derived.intProperty)
val derived2 = DerivedClass(int = 6)
println(derived2.intProperty)
println(derived.multiplyBy(2))
println()
val kotlinDerived = KotlinDerived()
println(kotlinDerived.floatProperty)
println(kotlinDerived.multiplyBy(2))
}
@@ -0,0 +1,10 @@
3.0
3.14
6.0
3
6
6.0
3.0
600.0
@@ -0,0 +1,4 @@
language = Objective-C
headerFilter = **/objc_include_categories.h
linkerOpts = -lobjcincludecategories
objcClassesIncludingCategories = BaseClass DerivedClass
@@ -0,0 +1,20 @@
#import <objc/NSObject.h>
@interface BaseClass : NSObject
- (id) init;
@property float floatProperty;
@end;
@interface BaseClass(IncludeCategory)
- (id)initWithFloat:(float)number;
- (float) multiplyBy:(int)value;
@end;
@interface DerivedClass : BaseClass
- (id) init;
@property int intProperty;
@end;
@interface DerivedClass(IncludeCategory)
- (id)initWithInt:(int)number;
@end;
@@ -0,0 +1,34 @@
#include "objc_include_categories.h"
@implementation BaseClass
-(id) init {
self.floatProperty = 3.0f;
return self;
}
@end;
@implementation BaseClass(IncludeCategory)
- (id)initWithFloat:(float)number {
self.floatProperty = number;
return self;
}
- (float) multiplyBy:(int)number {
return self.floatProperty * 2;
}
@end;
@implementation DerivedClass
-(id) init {
self = [super init];
self.intProperty = 3;
return self;
}
@end;
@implementation DerivedClass(IncludeCategory)
- (id)initWithInt:(int)number {
self = [self init];
self.intProperty = number;
return self;
}
@end;