This commit is contained in:
Igor Chevdar
2020-02-10 20:11:20 +03:00
parent dc5297f3ce
commit d97f00f0eb
5 changed files with 93 additions and 0 deletions
+41
View File
@@ -3374,6 +3374,11 @@ if (PlatformInfo.isAppleTarget(project)) {
def includePath = file("interop/objc/kt34467").absolutePath
it.compilerOpts "-fmodule-map-file=$moduleMap", "-I$includePath"
}
createInterop("objcGh3343") {
it.defFile 'framework/gh3343/objclib.def'
it.headers "$projectDir/framework/gh3343/objclib.h"
it.linkerOpts "-L$buildDir", "-lobjcgh3343"
}
}
createInterop("withSpaces") {
@@ -3876,6 +3881,42 @@ if (isAppleTarget(project)) {
}
swiftSources = ['framework/multiple/multiple.swift']
}
task testGh3343Framework(type: FrameworkTest) {
final String frameworkName = 'Gh3343'
testName = frameworkName
frameworkNames = [frameworkName]
def mainTask = it
konanArtifacts {
def lib = "objcGh3343"
def libTask = "compileKonan${lib.capitalize()}${target.name.capitalize()}"
UtilsKt.dependsOnDist(project, libTask)
UtilsKt.sameDependenciesAs(libTask, mainTask)
mainTask.dependsOn(libTask)
def lnOpts = (project.tasks.getByName(libTask)).linkerOpts
framework(frameworkName, targets: [ target ]) {
libraries {
artifact lib
}
srcDir 'framework/gh3343'
baseDir "$testOutputFramework/$testName"
if (!useCustomDist) {
dependsOn ":${target}CrossDistRuntime", ':commonDistRuntime', ':distCompiler'
}
linkerOpts lnOpts
extraOpts "-Xembed-bitcode-marker"
extraOpts project.globalTestArgs
}
}
swiftSources = ['framework/gh3343/uselib.swift']
}
}
/**
@@ -0,0 +1,15 @@
import kotlinx.cinterop.*
import objclib.*
import kotlin.native.ref.*
fun run(): List<Any?> {
val result = mutableListOf<Any?>()
result.add(foo1(42))
val list = foo2(117)
if (list != null) {
result.add(list.size)
for (x in list)
result.add(x)
}
return result
}
@@ -0,0 +1,3 @@
language = Objective-C
headers = Foundation/NSArray.h Foundation/NSValue.h Foundation/NSString.h
headerFilter = **/objclib.h Foundation/NSArray.h Foundation/NSValue.h Foundation/NSString.h
@@ -0,0 +1,11 @@
#import <Foundation/Foundation.h>
NSString* foo1(int x) {
return [NSString stringWithFormat:@"%d", x];
}
NSArray* foo2(int x) {
NSValue* xx = @(x);
NSString* s = @"zzz";
return [NSArray arrayWithObjects: xx, s, nil];
}
@@ -0,0 +1,23 @@
import Foundation
import Gh3343
func testGh3343() throws {
let list = KtlibKt.run()
try assertEquals(actual: list[0] as? String, expected: "42")
try assertEquals(actual: list[1] as? Int, expected: 2)
try assertEquals(actual: list[2] as? Int, expected: 117)
try assertEquals(actual: list[3] as? String, expected: "zzz")
}
// -------- Execution of the test --------
class Gh3343Tests : TestProvider {
var tests: [TestCase] = []
init() {
providers.append(self)
tests = [
TestCase(name: "Gh3343", method: withAutorelease(testGh3343)),
]
}
}