[K/N][Tests] Migrate framework and objcexport tests
^KT-61259
This commit is contained in:
committed by
Space Team
parent
f00a145dd7
commit
025771460c
@@ -1087,11 +1087,6 @@ if (PlatformInfo.isAppleTarget(project)) {
|
||||
it.extraOpts '-Xforeign-exception-mode', "objc-wrap"
|
||||
}
|
||||
|
||||
createInterop("objcGh3343") {
|
||||
it.defFile 'framework/gh3343/objclib.def'
|
||||
it.headers "$projectDir/framework/gh3343/objclib.h"
|
||||
it.linkerOpts "-lobjcgh3343"
|
||||
}
|
||||
createInterop("objcKt43517") {
|
||||
it.defFile 'framework/kt43517/kt43517.def'
|
||||
}
|
||||
@@ -1877,356 +1872,6 @@ Task frameworkTest(String name, Closure<FrameworkTest> configurator) {
|
||||
}
|
||||
}
|
||||
|
||||
Task objcExportTest(
|
||||
Task allTask,
|
||||
String suffix,
|
||||
List<String> frameworkOpts,
|
||||
List<String> swiftOpts,
|
||||
Boolean isStaticFramework,
|
||||
Boolean needLazyHeaderCheck
|
||||
) {
|
||||
needLazyHeaderCheck = needLazyHeaderCheck && !PlatformInfo.isK2(project) // generating lazy headers is NYI in K2
|
||||
final String name = "testObjCExport$suffix"
|
||||
final String frameworkName = "Kt$suffix"
|
||||
final String expectedLazyHeaderName = "expectedLazy${suffix}.h"
|
||||
final Task task = frameworkTest(name) {
|
||||
final String dir = "$testOutputFramework/$name"
|
||||
final File lazyHeader = file("$dir/$target-lazy.h")
|
||||
lazyHeader.delete() // Clean up after previous runs
|
||||
|
||||
doLast {
|
||||
// Check lazy header.
|
||||
if (needLazyHeaderCheck) {
|
||||
final String expectedLazyHeaderDir = file("objcexport/")
|
||||
final File expectedLazyHeader = new File(expectedLazyHeaderDir, expectedLazyHeaderName)
|
||||
|
||||
if (!expectedLazyHeader.exists() || expectedLazyHeader.readLines() != lazyHeader.readLines()) {
|
||||
exec {
|
||||
commandLine 'diff', '-u', expectedLazyHeader, lazyHeader
|
||||
ignoreExitValue = true
|
||||
}
|
||||
|
||||
copy {
|
||||
from(lazyHeader)
|
||||
into(expectedLazyHeaderDir)
|
||||
rename { expectedLazyHeaderName }
|
||||
}
|
||||
|
||||
throw new Error("$expectedLazyHeader file patched;\nRun gradlew ${allTask.path} --continue and don't forget to commit the patch")
|
||||
}
|
||||
}
|
||||
|
||||
// Check bundle ID.
|
||||
final String frameworkPath = "$dir/$target/Kt.framework"
|
||||
final Pattern pattern = ~"<key>CFBundleIdentifier</key>\n\\s*<string>foo.bar</string>"
|
||||
final String plistPath = (target.family == Family.OSX) ?
|
||||
"$frameworkPath/Resources/Info.plist" :
|
||||
"$frameworkPath/Info.plist"
|
||||
final String plistContent = file(plistPath).text
|
||||
if (!pattern.matcher(plistContent).find()) {
|
||||
throw new Error("Unexpected Info.plist content:\n$plistContent")
|
||||
}
|
||||
}
|
||||
|
||||
def libraryName = frameworkName + "Library"
|
||||
def noEnumEntriesLibraryName = frameworkName + "NoEnumEntriesLibrary"
|
||||
File exportedKlibArtifact = null
|
||||
konanArtifacts {
|
||||
library(libraryName, targets: [target.name]) {
|
||||
srcDir "objcexport/library"
|
||||
artifactName "test-$libraryName"
|
||||
delegate.getByTarget(target.name).configure{
|
||||
UtilsKt.dependsOnDist(it)
|
||||
}
|
||||
|
||||
extraOpts "-Xshort-module-name=MyLibrary"
|
||||
extraOpts "-module-name", "org.jetbrains.kotlin.native.test-library"
|
||||
}
|
||||
library(noEnumEntriesLibraryName, targets: [target.name]) {
|
||||
srcDir "objcexport/noEnumEntries"
|
||||
artifactName "test-no-enum-entries-$libraryName"
|
||||
delegate.getByTarget(target.name).configure{
|
||||
UtilsKt.dependsOnDist(it)
|
||||
}
|
||||
|
||||
exportedKlibArtifact = getArtifactByTarget(target.name)
|
||||
extraOpts "-Xshort-module-name=NoEnumEntriesLibrary"
|
||||
extraOpts "-module-name", "org.jetbrains.kotlin.native.test-no-enum-entries-library"
|
||||
extraOpts "-XXLanguage:-EnumEntries"
|
||||
}
|
||||
}
|
||||
codesign = !isStaticFramework
|
||||
framework(frameworkName) {
|
||||
sources = ['objcexport']
|
||||
libraries = [libraryName, noEnumEntriesLibraryName]
|
||||
artifact = 'Kt'
|
||||
isStatic = isStaticFramework
|
||||
if (needLazyHeaderCheck) {
|
||||
opts += "-Xemit-lazy-objc-header=$lazyHeader"
|
||||
}
|
||||
opts += [
|
||||
"-Xexport-kdoc",
|
||||
"-Xbinary=bundleId=foo.bar",
|
||||
"-Xexport-library=$exportedKlibArtifact",
|
||||
"-module-name", "Kt"
|
||||
]
|
||||
opts += frameworkOpts
|
||||
}
|
||||
swiftSources = ['objcexport']
|
||||
swiftExtraOpts = swiftOpts
|
||||
if (isNoopGC) {
|
||||
swiftExtraOpts += ["-D", "NOOP_GC"]
|
||||
}
|
||||
if (isAggressiveGC) {
|
||||
swiftExtraOpts += ["-D", "AGGRESSIVE_GC"]
|
||||
}
|
||||
}
|
||||
allTask.dependsOn(task)
|
||||
return task
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (PlatformInfo.isAppleTarget(project)) {
|
||||
final Task ObjCExportAllTask = tasks.create("testObjCExportAll")
|
||||
objcExportTest(
|
||||
ObjCExportAllTask,
|
||||
'',
|
||||
[],
|
||||
[],
|
||||
false,
|
||||
true
|
||||
)
|
||||
objcExportTest(
|
||||
ObjCExportAllTask,
|
||||
'NoGenerics',
|
||||
["-Xno-objc-generics"],
|
||||
[ '-D', 'NO_GENERICS' ],
|
||||
false,
|
||||
true
|
||||
)
|
||||
objcExportTest(
|
||||
ObjCExportAllTask,
|
||||
'LegacySuspendUnit',
|
||||
["-Xbinary=unitSuspendFunctionObjCExport=legacy"],
|
||||
[ '-D', 'LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT' ],
|
||||
false,
|
||||
true
|
||||
)
|
||||
objcExportTest(
|
||||
ObjCExportAllTask,
|
||||
'NoSwiftMemberNameMangling',
|
||||
["-Xbinary=objcExportDisableSwiftMemberNameMangling=true"],
|
||||
[ '-D', 'DISABLE_MEMBER_NAME_MANGLING' ],
|
||||
false,
|
||||
false
|
||||
)
|
||||
objcExportTest(
|
||||
ObjCExportAllTask,
|
||||
'NoInterfaceMemberNameMangling',
|
||||
["-Xbinary=objcExportIgnoreInterfaceMethodCollisions=true"],
|
||||
[ '-D', 'DISABLE_INTERFACE_METHOD_NAME_MANGLING' ],
|
||||
false,
|
||||
false
|
||||
)
|
||||
|
||||
objcExportTest(
|
||||
ObjCExportAllTask,
|
||||
'Static',
|
||||
["-Xbinary=objcExportSuspendFunctionLaunchThreadRestriction=none"],
|
||||
[ '-D', 'ALLOW_SUSPEND_ANY_THREAD' ],
|
||||
true,
|
||||
false
|
||||
)
|
||||
|
||||
|
||||
frameworkTest('testValuesGenericsFramework') {
|
||||
framework('ValuesGenerics') {
|
||||
sources = ['objcexport/values.kt', 'framework/values_generics']
|
||||
}
|
||||
swiftSources = ['framework/values_generics/']
|
||||
}
|
||||
|
||||
frameworkTest("testStdlibFramework") {
|
||||
framework('Stdlib') {
|
||||
sources = ['framework/stdlib']
|
||||
}
|
||||
swiftSources = ['framework/stdlib/']
|
||||
}
|
||||
|
||||
if (cacheTesting != null && cacheTesting.isDynamic) {
|
||||
// testMultipleFrameworks disabled until https://youtrack.jetbrains.com/issue/KT-34262 is fixed.
|
||||
} else frameworkTest("testMultipleFrameworks") {
|
||||
framework('First') {
|
||||
sources = ['framework/multiple/framework1', 'framework/multiple/shared']
|
||||
}
|
||||
framework('Second') {
|
||||
sources = ['framework/multiple/framework2', 'framework/multiple/shared']
|
||||
}
|
||||
swiftSources = ['framework/multiple']
|
||||
}
|
||||
|
||||
frameworkTest("testMultipleFrameworksStatic") {
|
||||
// this test doesn't work with caches.
|
||||
if (cacheTesting != null && !runtimeAssertionsPanic) {
|
||||
// See https://youtrack.jetbrains.com/issue/KT-34261.
|
||||
expectedExitStatus = 134
|
||||
}
|
||||
|
||||
framework('FirstStatic') {
|
||||
artifact = 'First'
|
||||
sources = ['framework/multiple/framework1', 'framework/multiple/shared']
|
||||
isStatic = true
|
||||
opts = ['-Xstatic-framework', "-Xpre-link-caches=enable"]
|
||||
}
|
||||
framework('SecondStatic') {
|
||||
artifact = 'Second'
|
||||
sources = ['framework/multiple/framework2', 'framework/multiple/shared']
|
||||
isStatic = true
|
||||
opts = ['-Xstatic-framework', "-Xpre-link-caches=enable"]
|
||||
}
|
||||
codesign = false
|
||||
swiftSources = ['framework/multiple']
|
||||
}
|
||||
|
||||
frameworkTest("testGh3343Framework") {
|
||||
framework('Gh3343') {
|
||||
sources = ['framework/gh3343']
|
||||
libraries = ['objcGh3343']
|
||||
}
|
||||
swiftSources = ['framework/gh3343/']
|
||||
}
|
||||
|
||||
frameworkTest("testKt42397Framework") {
|
||||
enabled = !project.globalTestArgs.contains('-opt')
|
||||
framework("Kt42397") {
|
||||
sources = ['framework/kt42397']
|
||||
}
|
||||
swiftSources = ['framework/kt42397']
|
||||
}
|
||||
|
||||
frameworkTest("testKt43517Framework") {
|
||||
framework('Kt43517') {
|
||||
sources = ['framework/kt43517']
|
||||
libraries = ['objcKt43517']
|
||||
}
|
||||
swiftSources = ['framework/kt43517/']
|
||||
}
|
||||
|
||||
frameworkTest("testStackTraceFramework") {
|
||||
enabled = !project.globalTestArgs.contains('-opt')
|
||||
framework('Stacktrace') {
|
||||
sources = ['framework/stacktrace']
|
||||
opts = ['-g']
|
||||
}
|
||||
swiftSources = ['framework/stacktrace/']
|
||||
}
|
||||
|
||||
frameworkTest("testStackTraceBridgesFramework") {
|
||||
enabled = !project.globalTestArgs.contains('-opt')
|
||||
framework('StacktraceBridges') {
|
||||
sources = ['framework/stacktraceBridges']
|
||||
opts = ['-g']
|
||||
}
|
||||
swiftSources = ['framework/stacktraceBridges/']
|
||||
}
|
||||
|
||||
|
||||
frameworkTest("testStackTraceByLibbacktraceFramework") {
|
||||
enabled = !project.globalTestArgs.contains('-opt')
|
||||
framework('StacktraceByLibbacktrace') {
|
||||
sources = ['framework/stacktraceByLibbacktrace']
|
||||
opts = ['-g', '-Xbinary=sourceInfoType=libbacktrace']
|
||||
}
|
||||
swiftSources = ['framework/stacktraceByLibbacktrace/']
|
||||
}
|
||||
|
||||
frameworkTest("testAbstractInstantiationFramework") {
|
||||
framework('AbstractInstantiation') {
|
||||
sources = ['framework/abstractInstantiation']
|
||||
}
|
||||
swiftSources = ['framework/abstractInstantiation/']
|
||||
expectedExitStatus = 134
|
||||
}
|
||||
|
||||
frameworkTest("testFrameworkBundleId") {
|
||||
def currentTarget = project.target.name
|
||||
enabled = currentTarget.startsWith("mac")
|
||||
|
||||
framework("Foo") {
|
||||
sources = ["framework/bundle_id/main.kt", "framework/bundle_id/lib.kt"]
|
||||
opts = ["-Xbinary=bundleVersion=FooBundleVersion", "-Xbinary=bundleShortVersionString=FooBundleShortVersionString"]
|
||||
}
|
||||
swiftSources = []
|
||||
|
||||
doLast {
|
||||
def frameworkPath = "$testOutputFramework/testFrameworkBundleId/$target/Foo.framework"
|
||||
def bundleIdPattern = ~"<key>CFBundleIdentifier</key>\n\\s*<string>Foo</string>"
|
||||
def bundleShortVersionStringPattern = ~"<key>CFBundleShortVersionString</key>\n\\s*<string>FooBundleShortVersionString</string>"
|
||||
def bundleVersionPattern = ~"<key>CFBundleVersion</key>\n\\s*<string>FooBundleVersion</string>"
|
||||
def plistContent = file("$frameworkPath/Resources/Info.plist").text
|
||||
if (!bundleIdPattern.matcher(plistContent).find()) {
|
||||
throw new Error("Unexpected CFBundleIdentifier in Info.plist:\n$plistContent")
|
||||
}
|
||||
if (!bundleShortVersionStringPattern.matcher(plistContent).find()) {
|
||||
throw new Error("Unexpected CFBundleShortVersionString in Info.plist:\n$plistContent")
|
||||
}
|
||||
if (!bundleVersionPattern.matcher(plistContent).find()) {
|
||||
throw new Error("Unexpected CFBundleVersion in Info.plist:\n$plistContent")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
frameworkTest("testForwardDeclarationsFramework") {
|
||||
framework('ForwardDeclarations') {
|
||||
sources = ['framework/forwardDeclarations']
|
||||
libraries = ['frameworkForwardDeclarations']
|
||||
}
|
||||
swiftSources = ['framework/forwardDeclarations/']
|
||||
}
|
||||
|
||||
frameworkTest("testFrameworkUsesFoundationModule") {
|
||||
framework("Bar") {
|
||||
sources = ["framework/use_foundation_module/framework.kt"]
|
||||
}
|
||||
swiftSources = []
|
||||
doLast {
|
||||
def frameworkPath = "$testOutputFramework/testFrameworkUsesFoundationModule/$target/Bar.framework"
|
||||
def moduleMapContent = file("$frameworkPath/Modules/module.modulemap").text
|
||||
def useFoundationPattern = ~"use Foundation"
|
||||
if (!useFoundationPattern.matcher(moduleMapContent).find()) {
|
||||
throw new Error("Expected use of Foundation module:\n$moduleMapContent")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
frameworkTest("testKt56233Framework") {
|
||||
framework("Kt56233") {
|
||||
sources = ['framework/kt56233']
|
||||
}
|
||||
swiftSources = ['framework/kt56233']
|
||||
if (isAggressiveGC) {
|
||||
swiftExtraOpts += ["-D", "AGGRESSIVE_GC"]
|
||||
}
|
||||
}
|
||||
|
||||
frameworkTest("testKt57791Framework") {
|
||||
framework("Kt57791") {
|
||||
sources = ['framework/kt57791']
|
||||
}
|
||||
swiftSources = ['framework/kt57791']
|
||||
}
|
||||
|
||||
frameworkTest("testPermanentObjectsFramework") {
|
||||
enabled = !isNoopGC // Requires gc to actually happen.
|
||||
framework("PermanentObjects") {
|
||||
sources = ['framework/permanentObjects']
|
||||
opts = ['-opt-in=kotlin.native.internal.InternalForKotlinNative']
|
||||
}
|
||||
swiftSources = ['framework/permanentObjects']
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register("override_konan_properties0", KonanDriverTest) {
|
||||
disabled = isAggressiveGC // No need to test with different GC schedulers
|
||||
def overrides = PlatformInfo.isWindows()
|
||||
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
public abstract class AbstractBase(val y: Int) {
|
||||
abstract val x: Int
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
import Foundation
|
||||
import AbstractInstantiation
|
||||
|
||||
func testInstantiate() throws {
|
||||
// this is failure test, it shouldn't work
|
||||
let base = AbstractBase(y: 5)
|
||||
}
|
||||
|
||||
class AbstractInstantiationTests : TestProvider {
|
||||
var tests: [TestCase] = []
|
||||
|
||||
init() {
|
||||
providers.append(self)
|
||||
tests = [
|
||||
TestCase(name: "testInstantiate", method: withAutorelease(testInstantiate))
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
package lib
|
||||
|
||||
fun lib() {}
|
||||
@@ -1,8 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
fun main() {}
|
||||
@@ -1,17 +0,0 @@
|
||||
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;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
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)
|
||||
@@ -1,25 +0,0 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
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
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
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
|
||||
@@ -1,11 +0,0 @@
|
||||
#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];
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
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 UselibTests : TestProvider {
|
||||
var tests: [TestCase] = []
|
||||
|
||||
init() {
|
||||
providers.append(self)
|
||||
tests = [
|
||||
TestCase(name: "Gh3343", method: withAutorelease(testGh3343)),
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
import kotlin.native.Platform
|
||||
|
||||
// The following 2 singletons are unused. However, since we are generating ObjC bindings for them,
|
||||
// they should be marked as used, so that the code generator emits their deinitialization.
|
||||
|
||||
object A {
|
||||
fun foo() = 1
|
||||
}
|
||||
|
||||
class B {
|
||||
companion object {
|
||||
fun foo() = 2
|
||||
}
|
||||
}
|
||||
|
||||
fun enableMemoryChecker() {
|
||||
Platform.isMemoryLeakCheckerActive = true
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
import Kt42397
|
||||
|
||||
class Results {
|
||||
var aFoo: Int32 = 0
|
||||
var bFoo: Int32 = 0
|
||||
}
|
||||
|
||||
func runTestKt42397(pointer: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer? {
|
||||
autoreleasepool {
|
||||
KnlibraryKt.enableMemoryChecker()
|
||||
let results = pointer.bindMemory(to: Results.self, capacity: 1).pointee
|
||||
results.aFoo = A().foo()
|
||||
results.bFoo = B.Companion().foo()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func testKt42397() throws {
|
||||
let results = Results()
|
||||
let resultsPtr = UnsafeMutablePointer<Results>.allocate(capacity: 1)
|
||||
resultsPtr.initialize(to: results)
|
||||
var thread: pthread_t? = nil
|
||||
let result = pthread_create(&thread, nil, runTestKt42397, resultsPtr)
|
||||
try assertEquals(actual: result, expected: 0)
|
||||
pthread_join(thread!, nil)
|
||||
|
||||
try assertEquals(actual: results.aFoo, expected: 1)
|
||||
try assertEquals(actual: results.bFoo, expected: 2)
|
||||
}
|
||||
|
||||
// -------- Execution of the test --------
|
||||
|
||||
class TestTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("Kt42397", testKt42397)
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
enum E {
|
||||
A, B, C
|
||||
};
|
||||
|
||||
struct S {
|
||||
int i;
|
||||
float f;
|
||||
};
|
||||
|
||||
struct S globalS = { .i = 3, .f = 3.14f };
|
||||
|
||||
enum E createEnum() {
|
||||
return A;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import kt43517.*
|
||||
|
||||
fun produceEnum(): E =
|
||||
createEnum()
|
||||
|
||||
fun compareEnums(e1: E, e2: E): Boolean =
|
||||
e1 == e2
|
||||
|
||||
fun getFirstField(s: S): Int =
|
||||
s.i
|
||||
|
||||
fun getGlobalS(): S =
|
||||
globalS
|
||||
@@ -1,24 +0,0 @@
|
||||
import Foundation
|
||||
import Kt43517
|
||||
|
||||
func testKt43517() throws {
|
||||
try assertEquals(
|
||||
actual: Kt43517Kt.compareEnums(e1: Kt43517Kt.produceEnum(), e2: Kt43517Kt.produceEnum()),
|
||||
expected: true
|
||||
)
|
||||
try assertEquals(
|
||||
actual: Kt43517Kt.getFirstField(s: Kt43517Kt.getGlobalS()),
|
||||
expected: 3
|
||||
)
|
||||
}
|
||||
|
||||
class Kt43517Tests : TestProvider {
|
||||
var tests: [TestCase] = []
|
||||
|
||||
init() {
|
||||
providers.append(self)
|
||||
tests = [
|
||||
TestCase(name: "Kt43517", method: withAutorelease(testKt43517)),
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
enum class SimpleEnum {
|
||||
ONE,
|
||||
TWO
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
import Kt56233
|
||||
|
||||
func threadRoutine(pointer: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer? {
|
||||
autoreleasepool {
|
||||
let f = pointer.bindMemory(to: (() -> ()).self, capacity: 1).pointee
|
||||
f()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func launchThreads(
|
||||
_ f: @convention(c) () -> (),
|
||||
threadCount: Int = 4
|
||||
) throws {
|
||||
var threads: [pthread_t] = []
|
||||
for _ in 0..<threadCount {
|
||||
let fPtr = UnsafeMutablePointer<() -> ()>.allocate(capacity: 1)
|
||||
fPtr.initialize(to: f)
|
||||
var thread: pthread_t? = nil
|
||||
let result = pthread_create(&thread, nil, threadRoutine, fPtr)
|
||||
try assertEquals(actual: result, expected: 0)
|
||||
threads.append(thread!)
|
||||
}
|
||||
for thread in threads {
|
||||
pthread_join(thread, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func kt56233() {
|
||||
#if AGGRESSIVE_GC
|
||||
let count = 50_000
|
||||
#else
|
||||
let count = 50_000_000
|
||||
#endif
|
||||
// Stress testing for race conditions.
|
||||
for _ in 0..<count {
|
||||
_ = Kt56233.SimpleEnum.two.ordinal
|
||||
}
|
||||
}
|
||||
|
||||
// -------- Execution of the test --------
|
||||
|
||||
class TestTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("Kt56233", { try launchThreads(kt56233) })
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
interface Foo {
|
||||
fun bar(): String?
|
||||
}
|
||||
|
||||
internal class FooImplUnused : Foo {
|
||||
override fun bar(): String? = null
|
||||
}
|
||||
|
||||
fun foobar(foo: Foo): Boolean {
|
||||
val s = foo.bar()
|
||||
if (s == null)
|
||||
return false
|
||||
return s == "zzz"
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import Foundation
|
||||
import Kt57791
|
||||
|
||||
class FooImpl : Foo {
|
||||
func bar() -> String? { "zzz" }
|
||||
}
|
||||
|
||||
func testKt57791() throws {
|
||||
try assertTrue(KnlibraryKt.foobar(foo: FooImpl()))
|
||||
}
|
||||
|
||||
class TestTests : TestProvider {
|
||||
var tests: [TestCase] = []
|
||||
|
||||
init() {
|
||||
providers.append(self)
|
||||
tests = [
|
||||
TestCase(name: "Kt57791", method: withAutorelease(testKt57791)),
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,247 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
enum TestError : Error {
|
||||
case assertFailed(String)
|
||||
case failure
|
||||
case testsFailed([String])
|
||||
}
|
||||
|
||||
// ---------------- Assertions ----------------
|
||||
|
||||
private func throwAssertFailed(message: String, file: String, line: Int) throws -> Never {
|
||||
throw TestError.assertFailed("\(file):\(line): \(message)")
|
||||
}
|
||||
|
||||
func assertEquals<T: Equatable>(actual: T, expected: T,
|
||||
_ message: String = "Assertion failed:",
|
||||
file: String = #file, line: Int = #line) throws {
|
||||
if (actual != expected) {
|
||||
try throwAssertFailed(message: message + " Expected value: \(expected), but got: \(actual)",
|
||||
file: file, line: line)
|
||||
}
|
||||
}
|
||||
|
||||
func assertSame(actual: AnyObject?, expected: AnyObject?,
|
||||
_ message: String = "Assertion failed:",
|
||||
file: String = #file, line: Int = #line) throws {
|
||||
if (actual !== expected) {
|
||||
try throwAssertFailed(message: message + " Expected value: \(expected), but got: \(actual)",
|
||||
file: file, line: line)
|
||||
}
|
||||
}
|
||||
|
||||
func assertEquals<T: Equatable>(actual: [T], expected: [T],
|
||||
_ message: String = "Assertion failed: arrays not equal",
|
||||
file: String = #file, line: Int = #line) throws {
|
||||
try assertEquals(actual: actual.count, expected: expected.count, "Size differs", file: file, line: line)
|
||||
try assertTrue(actual.elementsEqual(expected), "Arrays elements are not equal", file: file, line: line)
|
||||
}
|
||||
|
||||
func assertTrue(_ value: Bool,
|
||||
_ message: String = "Assertion failed:",
|
||||
file: String = #file, line: Int = #line) throws {
|
||||
if (value != true) {
|
||||
try throwAssertFailed(message: message + " Expected value to be TRUE, but got: \(value)",
|
||||
file: file, line: line)
|
||||
}
|
||||
}
|
||||
|
||||
func assertFalse(_ value: Bool,
|
||||
_ message: String = "Assertion failed:",
|
||||
file: String = #file, line: Int = #line) throws {
|
||||
if (value != false) {
|
||||
try throwAssertFailed(message: message + " Expected value to be FALSE, but got: \(value)",
|
||||
file: file, line: line)
|
||||
}
|
||||
}
|
||||
|
||||
func assertNil(_ value: Any?,
|
||||
_ message: String = "Assertion failed:",
|
||||
file: String = #file, line: Int = #line) throws {
|
||||
if (value != nil) {
|
||||
try throwAssertFailed(message: message + " Expected value to be nil, but got: \(value!)",
|
||||
file: file, line: line)
|
||||
}
|
||||
}
|
||||
|
||||
func fail(_ message: String = "Should not reach here", file: String = #file, line: Int = #line) throws -> Never {
|
||||
try throwAssertFailed(message: message, file: file, line: line)
|
||||
}
|
||||
|
||||
func assertFailsWith<T : Error>(_ errorType: T.Type,
|
||||
_ message: String = "Assertion failed:",
|
||||
file: String = #file, line: Int = #line,
|
||||
block: () throws -> Void) throws {
|
||||
do {
|
||||
try block()
|
||||
} catch let error {
|
||||
if error is T { return }
|
||||
try throwAssertFailed(message: message + " Expected error \(errorType), got \(error)",
|
||||
file: file, line: line)
|
||||
}
|
||||
|
||||
try throwAssertFailed(message: message + " Expected error \(errorType), but finished successfully",
|
||||
file: file, line: line)
|
||||
}
|
||||
|
||||
func assertFailsWithKotlin<T>(_ exceptionType: T.Type,
|
||||
_ message: String = "Assertion failed:",
|
||||
file: String = #file, line: Int = #line,
|
||||
block: () throws -> Void) throws {
|
||||
do {
|
||||
try block()
|
||||
} catch let error {
|
||||
let kotlinException = error.kotlinException
|
||||
if kotlinException is T { return }
|
||||
let got = kotlinException ?? error
|
||||
try throwAssertFailed(message: message + " Expected Kotlin exception \(exceptionType), got \(got)",
|
||||
file: file, line: line)
|
||||
}
|
||||
|
||||
try throwAssertFailed(message: message + " Expected Kotlin exception \(exceptionType), but finished successfully",
|
||||
file: file, line: line)
|
||||
}
|
||||
|
||||
|
||||
// ---------------- Utils --------------------
|
||||
|
||||
func withAutorelease( _ method: @escaping () throws -> Void) -> () throws -> Void {
|
||||
return { () throws -> Void in
|
||||
try autoreleasepool { try method() }
|
||||
}
|
||||
}
|
||||
|
||||
extension Error {
|
||||
var kotlinException: Any? {
|
||||
get {
|
||||
return (self as NSError).userInfo["KotlinException"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------- Execution ----------------
|
||||
|
||||
private final class Statistics : CustomStringConvertible {
|
||||
var passed: [String] = []
|
||||
var failed: [String] = []
|
||||
|
||||
var description: String {
|
||||
return """
|
||||
---- RESULTS:
|
||||
PASSED: \(passed.count)
|
||||
FAILED: \(failed.count)
|
||||
"""
|
||||
}
|
||||
|
||||
static let instance = Statistics()
|
||||
|
||||
static func getInstance() -> Statistics {
|
||||
return instance
|
||||
}
|
||||
|
||||
func start(_ name: String) {
|
||||
print("---- Starting test: \(name)")
|
||||
}
|
||||
|
||||
func passed(_ name: String) {
|
||||
print("---- PASSED test: \(name)")
|
||||
passed.append(name)
|
||||
}
|
||||
|
||||
func failed(_ name: String, error: Error) {
|
||||
print("---- FAILED test: \(name) with error: \(error)")
|
||||
failed.append(name)
|
||||
}
|
||||
}
|
||||
/**
|
||||
* TestCase represents a single test
|
||||
*/
|
||||
struct TestCase {
|
||||
let name: String
|
||||
let method: () throws -> Void
|
||||
|
||||
init(name: String, method: @escaping () throws -> Void) {
|
||||
self.name = name
|
||||
self.method = method
|
||||
}
|
||||
|
||||
func run() {
|
||||
let stats = Statistics.getInstance()
|
||||
stats.start(name)
|
||||
do {
|
||||
try method()
|
||||
stats.passed(name)
|
||||
} catch {
|
||||
stats.failed(name, error: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protocol TestProvider {
|
||||
var tests: [TestCase] { get }
|
||||
}
|
||||
|
||||
class SimpleTestProvider : TestProvider {
|
||||
var tests: [TestCase] = []
|
||||
|
||||
init() {
|
||||
providers.append(self)
|
||||
}
|
||||
|
||||
func test(_ name: String, _ method: @escaping () throws -> Void) {
|
||||
tests.append(TestCase(name: name, method: withAutorelease(method)))
|
||||
}
|
||||
}
|
||||
|
||||
var providers: [TestProvider] = []
|
||||
|
||||
private func execute(tests: [TestCase]) {
|
||||
for test in tests {
|
||||
test.run()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point of the test
|
||||
*/
|
||||
private func main() {
|
||||
// Generated method that instantiates test providers.
|
||||
registerProviders()
|
||||
|
||||
let stats = Statistics.getInstance()
|
||||
for pr in providers {
|
||||
let name = String(describing: type(of: pr))
|
||||
print("-- \(name) started")
|
||||
execute(tests: pr.tests)
|
||||
print("-- \(name) finished")
|
||||
}
|
||||
print(stats)
|
||||
|
||||
let failed = stats.failed
|
||||
if !failed.isEmpty {
|
||||
print()
|
||||
print("Tests failed:")
|
||||
for testName in failed {
|
||||
print(":: \(testName)")
|
||||
}
|
||||
abort()
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
@file:Suppress("UNUSED")
|
||||
|
||||
package multiple
|
||||
|
||||
interface I1 {
|
||||
fun getFortyTwo(): Int
|
||||
}
|
||||
|
||||
class I1Impl : I1 {
|
||||
override fun getFortyTwo(): Int = 42
|
||||
}
|
||||
|
||||
fun getI1() = object : I1 {
|
||||
override fun getFortyTwo(): Int = 42
|
||||
}
|
||||
|
||||
class C
|
||||
|
||||
fun getUnit(): Unit? = Unit
|
||||
|
||||
/*
|
||||
// Disabled for now to avoid depending on platform libs.
|
||||
fun getAnonymousObject() = object : platform.darwin.NSObject() {}
|
||||
class NamedObject : platform.darwin.NSObject()
|
||||
fun getNamedObject() = NamedObject()
|
||||
*/
|
||||
@@ -1,10 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
@file:Suppress("UNUSED")
|
||||
|
||||
package multiple
|
||||
|
||||
val name = "first"
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
@file:Suppress("UNUSED")
|
||||
|
||||
package multiple
|
||||
|
||||
interface I2 {
|
||||
fun getFortyTwo(): Int
|
||||
}
|
||||
|
||||
fun getFortyTwoFrom(i2: I2): Int = i2.getFortyTwo()
|
||||
|
||||
fun getI2() = object : I2 {
|
||||
override fun getFortyTwo(): Int = 42
|
||||
}
|
||||
|
||||
class C
|
||||
|
||||
fun isUnit(obj: Any?): Boolean = (obj === Unit)
|
||||
|
||||
/*
|
||||
// Disabled for now to avoid depending on platform libs.
|
||||
fun getAnonymousObject() = object : platform.darwin.NSObject() {}
|
||||
class NamedObject : platform.darwin.NSObject()
|
||||
fun getNamedObject() = NamedObject()
|
||||
*/
|
||||
@@ -1,10 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
@file:Suppress("UNUSED")
|
||||
|
||||
package multiple
|
||||
|
||||
val name = "second"
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import First
|
||||
import Second
|
||||
|
||||
func testClashingNames() throws {
|
||||
try assertEquals(actual: "first", expected: First.TestKt.name)
|
||||
try assertEquals(actual: "second", expected: Second.TestKt.name)
|
||||
|
||||
let c1 = First.C()
|
||||
let c2 = Second.C()
|
||||
try assertTrue(type(of: c1) == First.C.self)
|
||||
try assertTrue(type(of: c2) == Second.C.self)
|
||||
try assertTrue(First.C.self != Second.C.self)
|
||||
try assertTrue(objc_getClass(class_getName(First.C.self)) as AnyObject === First.C.self)
|
||||
try assertTrue(objc_getClass(class_getName(Second.C.self)) as AnyObject === Second.C.self)
|
||||
}
|
||||
|
||||
extension I1Impl : I2 {}
|
||||
|
||||
func testInteraction() throws {
|
||||
try assertEquals(actual: SecondKt.getFortyTwoFrom(i2: I1Impl()), expected: 42)
|
||||
}
|
||||
|
||||
func testIsolation1() throws {
|
||||
try assertFalse(SecondKt.isUnit(obj: FirstKt.getUnit()))
|
||||
|
||||
// Ensure frameworks don't share the same runtime (state):
|
||||
try assertFalse(First.RuntimeState().consumeChange())
|
||||
try assertFalse(Second.RuntimeState().consumeChange())
|
||||
Second.RuntimeState().produceChange()
|
||||
try assertFalse(First.RuntimeState().consumeChange())
|
||||
try assertTrue(Second.RuntimeState().consumeChange())
|
||||
}
|
||||
|
||||
func testIsolation2() throws {
|
||||
try assertEquals(actual: FirstKt.getI1().getFortyTwo(), expected: 42)
|
||||
try assertEquals(actual: SecondKt.getI2().getFortyTwo(), expected: 42)
|
||||
}
|
||||
|
||||
func testIsolation3() throws {
|
||||
#if false // Disabled for now to avoid depending on platform libs.
|
||||
FirstKt.getAnonymousObject()
|
||||
SecondKt.getAnonymousObject()
|
||||
FirstKt.getNamedObject()
|
||||
SecondKt.getNamedObject()
|
||||
#endif
|
||||
}
|
||||
|
||||
// https://youtrack.jetbrains.com/issue/KT-34261
|
||||
// When First and Second are static frameworks with caches, this test fails due to bad cache isolation:
|
||||
// Caches included into both frameworks have 'ktypew' globals (with same name, hidden visibility and common linkage)
|
||||
// for writable part of this "unexposed stdlib class" TypeInfo.
|
||||
// ld ignores hidden visibility and merges common globals, so two independent frameworks happen to share
|
||||
// the same global instead of two different globals. Things go wrong at runtime then: this writable TypeInfo part
|
||||
// is used to store Obj-C class for this Kotlin class. So after the first object is obtained in Swift, both TypeInfos
|
||||
// have its class, and the second object is wrong then.
|
||||
func testIsolation4() throws {
|
||||
let obj1: Any = First.SharedKt.getUnexposedStdlibClassInstance()
|
||||
try assertTrue(obj1 is First.KotlinBase)
|
||||
try assertFalse(obj1 is Second.KotlinBase)
|
||||
|
||||
let obj2: Any = Second.SharedKt.getUnexposedStdlibClassInstance()
|
||||
try assertFalse(obj2 is First.KotlinBase)
|
||||
try assertTrue(obj2 is Second.KotlinBase)
|
||||
}
|
||||
|
||||
class MultipleTests : TestProvider {
|
||||
var tests: [TestCase] = []
|
||||
|
||||
init() {
|
||||
tests = [
|
||||
TestCase(name: "TestClashingNames", method: withAutorelease(testClashingNames)),
|
||||
TestCase(name: "TestInteraction", method: withAutorelease(testInteraction)),
|
||||
TestCase(name: "TestIsolation1", method: withAutorelease(testIsolation1)),
|
||||
TestCase(name: "TestIsolation2", method: withAutorelease(testIsolation2)),
|
||||
TestCase(name: "TestIsolation3", method: withAutorelease(testIsolation3)),
|
||||
TestCase(name: "TestIsolation4", method: withAutorelease(testIsolation4)),
|
||||
]
|
||||
providers.append(self)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
@file:OptIn(ObsoleteWorkersApi::class)
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
object RuntimeState {
|
||||
fun produceChange() {
|
||||
Worker.current.executeAfter {}
|
||||
}
|
||||
|
||||
fun consumeChange(): Boolean {
|
||||
return Worker.current.processQueue()
|
||||
}
|
||||
}
|
||||
|
||||
// Note: this assumes that IntRange class is not exposed by the enclosing framework.
|
||||
fun getUnexposedStdlibClassInstance(): Any = 0..2
|
||||
@@ -1,25 +0,0 @@
|
||||
@file:OptIn(kotlin.ExperimentalStdlibApi::class)
|
||||
|
||||
import kotlin.native.internal.GC
|
||||
import kotlin.native.internal.gc.GCInfo
|
||||
import kotlin.native.internal.isPermanent
|
||||
import kotlin.test.*
|
||||
|
||||
private var _counter = 0
|
||||
|
||||
object Permanent {
|
||||
var counter
|
||||
get() = _counter
|
||||
set(value) {
|
||||
_counter = value
|
||||
}
|
||||
}
|
||||
|
||||
fun assertIsPermanent() {
|
||||
assertTrue(Permanent.isPermanent())
|
||||
}
|
||||
|
||||
fun stableRefsCount(): Long {
|
||||
GC.collect()
|
||||
return GC.lastGCInfo!!.rootSet.stableReferences
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import PermanentObjects
|
||||
|
||||
func testPermanentObjects() throws {
|
||||
PermanentObjects.KnlibraryKt.assertIsPermanent()
|
||||
let stableRefsBefore = PermanentObjects.KnlibraryKt.stableRefsCount()
|
||||
autoreleasepool {
|
||||
for i in 0..<1000 {
|
||||
PermanentObjects.Permanent().counter += 1
|
||||
}
|
||||
}
|
||||
let stableRefsAfter = PermanentObjects.KnlibraryKt.stableRefsCount()
|
||||
try assertEquals(actual: PermanentObjects.Permanent().counter, expected: 1000)
|
||||
try assertEquals(actual: stableRefsAfter, expected: stableRefsBefore)
|
||||
}
|
||||
|
||||
// -------- Execution of the test --------
|
||||
|
||||
class TestTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("permanentObjects", testPermanentObjects)
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
fun inner1() : Nothing {
|
||||
throw Exception()
|
||||
}
|
||||
|
||||
fun getStackTrace() : List<String> {
|
||||
try {
|
||||
inner1()
|
||||
} catch (e: Exception) {
|
||||
return e.getStackTrace().toList()
|
||||
}
|
||||
return emptyList()
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
import Foundation
|
||||
import Stacktrace
|
||||
|
||||
func testStackTrace() throws {
|
||||
let trace = StacktraceKt.getStackTrace()
|
||||
print(trace)
|
||||
try assertTrue(trace[0].contains("Throwable.kt"))
|
||||
try assertTrue(trace[1].contains("Exceptions.kt"))
|
||||
try assertTrue(trace[2].contains("stacktrace.kt:8"))
|
||||
try assertTrue(trace[3].contains("stacktrace.kt:13"))
|
||||
try assertTrue(trace[4].contains("<compiler-generated>"))
|
||||
try assertTrue(trace[5].contains("stacktrace.swift:5"))
|
||||
try assertTrue(trace[6].contains("main.swift"))
|
||||
}
|
||||
|
||||
class StacktraceTests : TestProvider {
|
||||
var tests: [TestCase] = []
|
||||
|
||||
init() {
|
||||
providers.append(self)
|
||||
tests = [
|
||||
TestCase(name: "Stacktrace", method: withAutorelease(testStackTrace)),
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
fun thrower() : Nothing {
|
||||
throw Exception()
|
||||
}
|
||||
|
||||
fun getStackTrace() : List<String> {
|
||||
try {
|
||||
thrower()
|
||||
} catch (e: Exception) {
|
||||
return e.getStackTrace().toList()
|
||||
}
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
open class Foo {
|
||||
open fun foo(): List<String> { return emptyList() }
|
||||
}
|
||||
|
||||
private class Bar : Foo() {
|
||||
override fun foo(): List<String> = getStackTrace()
|
||||
}
|
||||
|
||||
object Object {
|
||||
var trace: List<String> = emptyList()
|
||||
|
||||
init {
|
||||
trace = getStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
class WithCompanion {
|
||||
companion object {
|
||||
var trace: List<String> = emptyList()
|
||||
|
||||
init {
|
||||
trace = getStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class E {
|
||||
A {
|
||||
init {
|
||||
trace = getStackTrace()
|
||||
}
|
||||
};
|
||||
|
||||
var trace: List<String> = emptyList()
|
||||
}
|
||||
|
||||
fun createBar(): Foo = Bar()
|
||||
|
||||
fun use(foo: Foo): List<String> {
|
||||
return foo.foo()
|
||||
}
|
||||
-54
@@ -1,54 +0,0 @@
|
||||
import Foundation
|
||||
import StacktraceBridges
|
||||
|
||||
class Bar : Foo {
|
||||
override func foo() -> Array<String> {
|
||||
return StacktraceBridgesKt.getStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
func testDirectObjc2Kotlin() throws {
|
||||
let trace = StacktraceBridgesKt.getStackTrace()
|
||||
try assertTrue(trace[4].contains("objc2kotlin_kfun:#getStackTrace(){}kotlin.collections.List<kotlin.String>"))
|
||||
}
|
||||
|
||||
func testVirtualObjc2Kotlin() throws {
|
||||
let trace = StacktraceBridgesKt.createBar().foo()
|
||||
try assertTrue(trace[6].contains("objc2kotlin_virtual_kfun:Foo#foo(){}kotlin.collections.List<kotlin.String>"))
|
||||
}
|
||||
|
||||
func testKotlin2Objc() throws {
|
||||
let trace = StacktraceBridgesKt.use(foo: Bar())
|
||||
try assertTrue(trace[8].contains("kotlin2objc_kfun:Foo#foo(){}kotlin.collections.List<kotlin.String>"))
|
||||
}
|
||||
|
||||
func testCompanionObject() throws {
|
||||
let trace = WithCompanion.companion.trace
|
||||
try assertTrue(trace[8].contains("objc2kotlin_kclass:WithCompanion#companion"))
|
||||
}
|
||||
|
||||
func testStandaloneObject() throws {
|
||||
let trace = Object.shared.trace
|
||||
try assertTrue(trace[8].contains("objc2kotlin_kclass:Object#shared"))
|
||||
}
|
||||
|
||||
func testEnumEntry() throws {
|
||||
let trace = E.a.trace
|
||||
try assertTrue(trace[8].contains("objc2kotlin_kclass:E.A"))
|
||||
}
|
||||
|
||||
class StacktraceBridgesTests : TestProvider {
|
||||
var tests: [TestCase] = []
|
||||
|
||||
init() {
|
||||
providers.append(self)
|
||||
tests = [
|
||||
TestCase(name: "Direct objc2kotlin", method: withAutorelease(testDirectObjc2Kotlin)),
|
||||
TestCase(name: "Virtual objc2kotlin", method: withAutorelease(testVirtualObjc2Kotlin)),
|
||||
TestCase(name: "kotlin2objc", method: withAutorelease(testKotlin2Objc)),
|
||||
TestCase(name: "Companion object", method: withAutorelease(testCompanionObject)),
|
||||
TestCase(name: "Standalone object", method: withAutorelease(testStandaloneObject)),
|
||||
TestCase(name: "Enum entry", method: withAutorelease(testEnumEntry)),
|
||||
]
|
||||
}
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
inline fun inner2() : Nothing {
|
||||
throw Exception()
|
||||
}
|
||||
|
||||
fun inner1() : Nothing {
|
||||
inner2()
|
||||
}
|
||||
|
||||
fun getStackTrace() : List<String> {
|
||||
try {
|
||||
inner1()
|
||||
} catch (e: Exception) {
|
||||
return e.getStackTrace().toList()
|
||||
}
|
||||
return emptyList()
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
import Foundation
|
||||
import StacktraceByLibbacktrace
|
||||
|
||||
func testStackTrace() throws {
|
||||
let trace = StacktraceByLibbacktraceKt.getStackTrace()
|
||||
try assertTrue(trace[0].contains("stacktraceByLibbacktrace.kt:8"))
|
||||
try assertTrue(trace[0].contains("[inlined]"))
|
||||
try assertTrue(trace[1].contains("stacktraceByLibbacktrace.kt:12"))
|
||||
try assertTrue(trace[2].contains("stacktraceByLibbacktrace.kt:17"))
|
||||
try assertTrue(trace[3].contains("<compiler-generated>"))
|
||||
try assertTrue(trace[4].contains("stacktraceByLibbacktrace.swift:5"))
|
||||
try assertTrue(trace[5].contains("main.swift:126"))
|
||||
}
|
||||
|
||||
class StacktraceByLibbacktraceTests : TestProvider {
|
||||
var tests: [TestCase] = []
|
||||
|
||||
init() {
|
||||
providers.append(self)
|
||||
tests = [
|
||||
TestCase(name: "Stacktrace", method: withAutorelease(testStackTrace)),
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
@file:Suppress("UNUSED")
|
||||
@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
|
||||
|
||||
package stdlib
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun <K, V> isEmpty(map: Map<K, V>) = map.isEmpty()
|
||||
|
||||
fun <K, V> getKeysAsSet(map: Map<K, V>) = map.keys
|
||||
fun <K, V> getKeysAsList(map: Map<K, V>) = map.keys.toList()
|
||||
|
||||
fun <K, V> toMutableMap(map: HashMap<K, V>) = map.toMutableMap()
|
||||
|
||||
fun <E> getFirstElement(collection: Collection<E>) = collection.first()
|
||||
|
||||
class GenericExtensionClass<K, out V, out T : Map<K, V>> (private val holder: T?) {
|
||||
fun getFirstKey(): K? = holder?.entries?.first()?.key
|
||||
|
||||
fun getFirstValue() : V? {
|
||||
holder?.entries?.forEach { e -> println("KEY: ${e.key} VALUE: ${e.value}") }
|
||||
return holder?.entries?.first()?.value
|
||||
}
|
||||
}
|
||||
|
||||
fun <K, V> createPair():
|
||||
Pair<LinkedHashMap<K, V>, GenericExtensionClass<K, V, Map<K, V>>> {
|
||||
val l = createLinkedMap<K, V>()
|
||||
val g = GenericExtensionClass(l)
|
||||
return Pair(l, g)
|
||||
}
|
||||
|
||||
fun <K, V> createLinkedMap() = linkedMapOf<K, V>()
|
||||
|
||||
fun createTypedMutableMap() = linkedMapOf<Int, String>()
|
||||
|
||||
fun addSomeElementsToMap(map: MutableMap<String, Int>) {
|
||||
map.put(key = "XYZ", value = 321)
|
||||
map.put(key = "TMP", value = 451)
|
||||
}
|
||||
|
||||
fun list(vararg elements: Any?): Any = listOf(*elements)
|
||||
fun set(vararg elements: Any?): Any = setOf(*elements)
|
||||
fun map(vararg keysAndValues: Any?): Any = mutableMapOf<Any?, Any?>().apply {
|
||||
(0 until keysAndValues.size step 2).forEach {index ->
|
||||
this[keysAndValues[index]] = keysAndValues[index + 1]
|
||||
}
|
||||
}
|
||||
|
||||
fun emptyMutableList(): Any = mutableListOf<Any?>()
|
||||
fun emptyMutableSet(): Any = mutableSetOf<Any?>()
|
||||
fun emptyMutableMap(): Any = mutableMapOf<Any?, Any?>()
|
||||
|
||||
data class TripleVals<T>(val first: T, val second: T, val third: T)
|
||||
|
||||
data class TripleVars<T>(var first: T, var second: T, var third: T) {
|
||||
override fun toString(): String {
|
||||
return "[$first, $second, $third]"
|
||||
}
|
||||
}
|
||||
|
||||
fun gc() = kotlin.native.runtime.GC.collect()
|
||||
|
||||
// Note: this method checks only some of the operations (namely the ones modified recently,
|
||||
// and thus required additional tests).
|
||||
// More tests are absolutely needed.
|
||||
@Throws(Throwable::class)
|
||||
@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
|
||||
fun testSet(set: Set<String>) {
|
||||
val setAny: Set<Any?> = set
|
||||
|
||||
assertTrue(set.contains("a"))
|
||||
assertTrue(set.contains("c"))
|
||||
assertFalse(set.contains("h"))
|
||||
assertFalse(setAny.contains(1))
|
||||
|
||||
val konanSet = set as kotlin.native.internal.KonanSet<String>
|
||||
assertEquals("a", konanSet.getElement("a"))
|
||||
assertNull(konanSet.getElement("aa"))
|
||||
assertNull((setAny as kotlin.native.internal.KonanSet<Any?>).getElement(1))
|
||||
}
|
||||
|
||||
// Note: this method checks only some of the operations (namely the ones modified recently,
|
||||
// and thus required additional tests).
|
||||
// More tests are absolutely needed.
|
||||
@Throws(Throwable::class)
|
||||
fun testMap(map: Map<String, Int>) {
|
||||
val mapAny: Map<String, Any?> = map
|
||||
val mapKeysAny: Set<Any?> = map.keys
|
||||
val mapEntriesAny: Set<Map.Entry<Any?, Any?>> = map.entries
|
||||
|
||||
assertTrue(map.containsKey("a"))
|
||||
assertTrue(map.keys.contains("b"))
|
||||
assertTrue(map.containsKey("g"))
|
||||
assertFalse(map.containsKey("0"))
|
||||
assertFalse(mapKeysAny.contains(1))
|
||||
|
||||
assertTrue(map.containsValue(1))
|
||||
assertTrue(map.values.contains(2))
|
||||
assertTrue(map.containsValue(7))
|
||||
assertFalse(map.containsValue(8))
|
||||
assertFalse(mapAny.containsValue("8"))
|
||||
|
||||
assertEquals(2, map.get("b"))
|
||||
assertEquals(4, map.get("d"))
|
||||
assertNull(map.get("h"))
|
||||
|
||||
val referenceMap = (0 until 7).map { ('a' + it).toString() to (it + 1) }.toMap()
|
||||
assertEquals(referenceMap.hashCode(), map.hashCode())
|
||||
assertEquals(referenceMap, map)
|
||||
assertEquals(map, referenceMap)
|
||||
|
||||
assertEquals(28, map.entries.sumBy { it.value })
|
||||
|
||||
assertTrue(map.entries.contains(createMapEntry("e", 5)))
|
||||
assertTrue(map.entries.contains(createMapEntry("g", 7)))
|
||||
assertFalse(map.entries.contains(createMapEntry("e", 7)))
|
||||
assertFalse(map.entries.contains(createMapEntry("e", 10)))
|
||||
assertFalse(map.entries.contains(createMapEntry("10", 5)))
|
||||
assertFalse(map.entries.contains(createMapEntry("10", 10)))
|
||||
assertFalse(mapEntriesAny.contains(createMapEntry(5, "e")))
|
||||
}
|
||||
|
||||
private fun <K, V> createMapEntry(key: K, value: V) = mapOf(key to value).entries.single()
|
||||
@@ -1,472 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
import Stdlib
|
||||
|
||||
extension NSEnumerator {
|
||||
func remainingObjects() -> [Any?] {
|
||||
var result = [Any?]()
|
||||
while (true) {
|
||||
if let next = self.nextObject() {
|
||||
result.append(next as AnyObject as Any?)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
class StdlibTests : TestProvider {
|
||||
var tests: [TestCase] = []
|
||||
|
||||
init() {
|
||||
tests = [
|
||||
TestCase(name: "TestEmptyDictionary", method: withAutorelease(testEmptyDictionary)),
|
||||
TestCase(name: "TestGenericMapUsage", method: withAutorelease(testGenericMapUsage)),
|
||||
TestCase(name: "TestOrderedMapStored", method: withAutorelease(testOrderedMapStored)),
|
||||
TestCase(name: "TestTypedMapUsage", method: withAutorelease(testTypedMapUsage)),
|
||||
TestCase(name: "TestFirstElement", method: withAutorelease(testFirstElement)),
|
||||
TestCase(name: "TestAddDictionary", method: withAutorelease(testAddDictionary)),
|
||||
TestCase(name: "TestList", method: withAutorelease(testList)),
|
||||
TestCase(name: "TestMutableList", method: withAutorelease(testMutableList)),
|
||||
TestCase(name: "TestSet", method: withAutorelease(testSet)),
|
||||
TestCase(name: "TestMutableSet", method: withAutorelease(testMutableSet)),
|
||||
TestCase(name: "TestMap", method: withAutorelease(testMap)),
|
||||
TestCase(name: "TestMutableMap", method: withAutorelease(testMutableMap)),
|
||||
TestCase(name: "TestKotlinMutableSetInit", method: withAutorelease(testKotlinMutableSetInit)),
|
||||
TestCase(name: "TestKotlinMutableDictionaryInit", method: withAutorelease(testKotlinMutableDictionaryInit)),
|
||||
TestCase(name: "TestSwiftSetInKotlin", method: withAutorelease(testSwiftSetInKotlin)),
|
||||
TestCase(name: "TestSwiftDictionaryInKotlin", method: withAutorelease(testSwiftDictionaryInKotlin)),
|
||||
]
|
||||
providers.append(self)
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass empty dictionary to Kotlin.
|
||||
*/
|
||||
func testEmptyDictionary() throws {
|
||||
let immutableEmptyDict = [String: Int]()
|
||||
try assertTrue(StdlibKt.isEmpty(map: immutableEmptyDict), "Empty dictionary")
|
||||
let keys = StdlibKt.getKeysAsSet(map: immutableEmptyDict)
|
||||
try assertTrue(keys.isEmpty, "Should have empty set")
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests usage of a map with generics.
|
||||
*/
|
||||
func testGenericMapUsage() throws {
|
||||
let map = StdlibKt.createLinkedMap()
|
||||
map[1] = "One"
|
||||
map[10] = "Ten"
|
||||
map[11] = "Eleven"
|
||||
map["10"] = "Ten as string"
|
||||
for (k, v) in map {
|
||||
print("MAP: \(k) - \(v)")
|
||||
}
|
||||
|
||||
try assertEquals(actual: map[11] as! String, expected: "Eleven", "An element of the map for key: 11")
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks order of the underlying LinkedHashMap.
|
||||
*/
|
||||
func testOrderedMapStored() throws {
|
||||
let pair = StdlibKt.createPair()
|
||||
let map = pair.first as? NSMutableDictionary
|
||||
|
||||
map?[1] = "One"
|
||||
map?[10] = "Ten"
|
||||
map?[11] = "Eleven"
|
||||
map?["10"] = "Ten as string"
|
||||
|
||||
let gen = pair.second as! GenericExtensionClass
|
||||
let value: String? = gen.getFirstValue() as? String
|
||||
try assertEquals(actual: value!, expected: "One", "First value of the map")
|
||||
|
||||
let key: Int? = gen.getFirstKey() as? Int
|
||||
try assertEquals(actual: key!, expected: 1, "First key of the map")
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests typed map created in Kotlin.
|
||||
*/
|
||||
func testTypedMapUsage() throws {
|
||||
let map = StdlibKt.createTypedMutableMap()
|
||||
map[1] = "One"
|
||||
map[1.0 as Float] = "Float"
|
||||
map[11] = "Eleven"
|
||||
map["10"] = "Ten as string"
|
||||
|
||||
try assertEquals(actual: map["10"] as! String, expected: "Ten as string", "String key")
|
||||
try assertEquals(actual: map[1.0 as Float] as! String, expected: "Float", "Float key")
|
||||
}
|
||||
|
||||
/**
|
||||
* Get first element of the collection.
|
||||
*/
|
||||
func testFirstElement() throws {
|
||||
let m = StdlibKt.createTypedMutableMap()
|
||||
m[10] = "Str"
|
||||
try assertEquals(actual: StdlibKt.getFirstElement(collection: m.allKeys) as! Int, expected: 10, "First key")
|
||||
|
||||
try assertEquals(actual: StdlibKt.getFirstElement(collection: StdlibKt.getKeysAsList(map: m as! Dictionary)) as! Int,
|
||||
expected: 10, "First key from a list")
|
||||
}
|
||||
|
||||
/**
|
||||
* Add element to dictionary in Kotlin
|
||||
*/
|
||||
func testAddDictionary() throws {
|
||||
let m = [ "ABC": 10, "CDE": 12, "FGH": 3 ]
|
||||
StdlibKt.addSomeElementsToMap(map: KotlinMutableDictionary(dictionary: m))
|
||||
for (k, v) in m {
|
||||
print("MAP: \(k) - \(v)")
|
||||
}
|
||||
|
||||
var smd = KotlinMutableDictionary<NSString, KotlinInt>()
|
||||
smd.setObject(333, forKey: "333" as NSString)
|
||||
try assertEquals(actual: smd.object(forKey: "333" as NSString) as! Int, expected: 333, "Add element to dict")
|
||||
|
||||
StdlibKt.addSomeElementsToMap(map: smd)
|
||||
for (k, v) in smd {
|
||||
print("MAP: \(k) - \(v)")
|
||||
}
|
||||
try assertEquals(actual: smd.object(forKey: "XYZ" as NSString) as! Int, expected: 321, "Get element from Kotlin")
|
||||
}
|
||||
|
||||
func zeroTo(_ n: Int32) -> KotlinArray<AnyObject> { return KotlinArray<AnyObject>(size: n) { $0 } }
|
||||
|
||||
func testList() throws {
|
||||
let elements = zeroTo(5)
|
||||
elements.set(index: 1, value: nil)
|
||||
let list = StdlibKt.list(elements: elements) as! NSArray
|
||||
try assertEquals(actual: list.object(at: 2) as! NSNumber, expected: NSNumber(value: 2))
|
||||
try assertEquals(actual: list.object(at: 1) as! NSNull, expected: NSNull())
|
||||
try assertEquals(actual: list.count, expected: 5)
|
||||
}
|
||||
|
||||
func testMutableList() throws {
|
||||
let kotlinList = StdlibKt.emptyMutableList() as! NSMutableArray
|
||||
let nsList = NSMutableArray()
|
||||
|
||||
func apply<T : Equatable>(op: (NSMutableArray)->T) throws {
|
||||
let actual = op(kotlinList)
|
||||
let expected = op(nsList)
|
||||
try assertEquals(actual: actual, expected: expected)
|
||||
try assertEquals(actual: kotlinList, expected: nsList)
|
||||
try assertEquals(actual: kotlinList.hash, expected: nsList.hash)
|
||||
}
|
||||
|
||||
func applyVoid(op: (NSMutableArray)->Void) throws {
|
||||
op(kotlinList)
|
||||
op(nsList)
|
||||
try assertEquals(actual: kotlinList, expected: nsList)
|
||||
try assertEquals(actual: kotlinList.hash, expected: nsList.hash)
|
||||
}
|
||||
|
||||
try apply { $0.count }
|
||||
try applyVoid { $0.insert(0, at: 0) }
|
||||
try applyVoid { $0.insert(1, at: 0) }
|
||||
try applyVoid { $0.insert(2, at: 1) }
|
||||
try applyVoid { $0.removeObject(at: 0) }
|
||||
try applyVoid { $0.add("foo") }
|
||||
try applyVoid { $0.removeLastObject() }
|
||||
try applyVoid { $0.replaceObject(at: 0, with: "bar") }
|
||||
let NULL: Any? = nil
|
||||
try applyVoid { $0.add(NULL as Any) }
|
||||
try applyVoid { $0.insert(NULL as Any, at: 2) }
|
||||
try applyVoid { $0.replaceObject(at: 1, with: NULL as Any) }
|
||||
try apply { $0.count }
|
||||
}
|
||||
|
||||
func testMutableSet() throws {
|
||||
let kotlinSet = StdlibKt.emptyMutableSet() as! NSMutableSet
|
||||
let nsSet = NSMutableSet()
|
||||
|
||||
func apply<T : Equatable>(op: (NSMutableSet)->T) throws {
|
||||
let actual = op(kotlinSet)
|
||||
let expected = op(nsSet)
|
||||
try assertEquals(actual: actual, expected: expected)
|
||||
try assertEquals(actual: kotlinSet, expected: nsSet)
|
||||
try assertEquals(actual: kotlinSet.hash, expected: nsSet.hash)
|
||||
}
|
||||
|
||||
func applyVoid(op: (NSMutableSet)->Void) throws {
|
||||
op(kotlinSet)
|
||||
op(nsSet)
|
||||
try assertEquals(actual: kotlinSet, expected: nsSet)
|
||||
try assertEquals(actual: kotlinSet.hash, expected: nsSet.hash)
|
||||
}
|
||||
|
||||
try apply { $0.count }
|
||||
try applyVoid { $0.add("foo") }
|
||||
try applyVoid { $0.add("bar") }
|
||||
try applyVoid { $0.remove("baz") }
|
||||
try applyVoid { $0.add("baz") }
|
||||
try applyVoid { $0.add(TripleVals<NSNumber>(first: 1, second: 2, third: 3)) }
|
||||
try apply { $0.member(TripleVals<NSNumber>(first: 1, second: 2, third: 3)) as! TripleVals<NSNumber> }
|
||||
try apply { $0.member(42) == nil }
|
||||
try applyVoid { $0.remove(TripleVals<NSNumber>(first: 1, second: 2, third: 3)) }
|
||||
|
||||
let NULL0: Any? = nil
|
||||
let NULL = NULL0 as Any
|
||||
|
||||
try applyVoid { $0.add(NULL) }
|
||||
try apply { $0.member(NULL) == nil }
|
||||
try apply { $0.member(NULL) as! NSObject }
|
||||
try applyVoid { $0.remove(NULL) }
|
||||
try apply { $0.member(NULL) == nil }
|
||||
|
||||
try apply { NSSet(array: $0.objectEnumerator().remainingObjects()) }
|
||||
|
||||
try apply { $0.count }
|
||||
}
|
||||
|
||||
func testMutableMap() throws {
|
||||
// TODO: test KotlinMutableSet/Dictionary constructors
|
||||
let kotlinMap = StdlibKt.emptyMutableMap() as! NSMutableDictionary
|
||||
let nsMap = NSMutableDictionary()
|
||||
|
||||
func apply<T : Equatable>(op: (NSMutableDictionary)->T) throws {
|
||||
let actual = op(kotlinMap)
|
||||
let expected = op(nsMap)
|
||||
try assertEquals(actual: actual, expected: expected)
|
||||
try assertEquals(actual: kotlinMap, expected: nsMap)
|
||||
try assertEquals(actual: kotlinMap.hash, expected: nsMap.hash)
|
||||
}
|
||||
|
||||
func applyVoid(op: (NSMutableDictionary) throws -> Void) throws {
|
||||
try op(kotlinMap)
|
||||
try op(nsMap)
|
||||
try assertEquals(actual: kotlinMap, expected: nsMap)
|
||||
try assertEquals(actual: kotlinMap.hash, expected: nsMap.hash)
|
||||
}
|
||||
|
||||
try apply { $0.count }
|
||||
try apply { $0.object(forKey: 42) == nil }
|
||||
try applyVoid { $0.setObject(42, forKey: 42 as NSNumber) }
|
||||
try applyVoid { $0.setObject(17, forKey: "foo" as NSString) }
|
||||
let triple = TripleVals<NSNumber>(first: 3, second: 2, third: 1)
|
||||
try applyVoid { $0.setObject("bar", forKey: triple) }
|
||||
try applyVoid { $0.removeObject(forKey: 42) }
|
||||
try apply { $0.count }
|
||||
try apply { $0.object(forKey: 42) == nil }
|
||||
try apply { $0.object(forKey: "foo") as! NSObject }
|
||||
try apply { $0.object(forKey: triple) as! NSObject }
|
||||
|
||||
try apply { NSSet(array: $0.keyEnumerator().remainingObjects()) }
|
||||
|
||||
let NULL0: Any? = nil
|
||||
let NULL = NULL0 as Any
|
||||
|
||||
try apply { $0.object(forKey: NULL) == nil }
|
||||
|
||||
|
||||
try applyVoid { $0.setObject(42, forKey: NULL as! NSCopying) }
|
||||
try applyVoid { $0.setObject(NULL, forKey: "baz" as NSString) }
|
||||
try apply { $0.object(forKey: NULL) as! NSObject }
|
||||
try apply { $0.object(forKey: "baz") as! NSObject }
|
||||
|
||||
try apply { NSSet(array: $0.keyEnumerator().remainingObjects()) }
|
||||
|
||||
try applyVoid { $0.removeObject(forKey: NULL) }
|
||||
try applyVoid { $0.removeObject(forKey: "baz") }
|
||||
|
||||
try applyVoid { $0.removeAllObjects() }
|
||||
|
||||
let myKey = MyKey()
|
||||
try applyVoid { $0.setObject(myKey, forKey: myKey) }
|
||||
try applyVoid {
|
||||
let key = $0.allKeys[0] as! MyKey
|
||||
let value = $0.allValues[0] as! MyKey
|
||||
try assertFalse(key === myKey)
|
||||
try assertTrue(value === myKey)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@objc class MyKey : NSObject, NSCopying {
|
||||
override var hash: Int {
|
||||
return 42
|
||||
}
|
||||
|
||||
override func isEqual(_ object: Any?) -> Bool {
|
||||
return object is MyKey
|
||||
}
|
||||
|
||||
func copy(with: NSZone? = nil) -> Any {
|
||||
return MyKey()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testSet() throws {
|
||||
let elements = KotlinArray<AnyObject>(size: 2) { index in nil }
|
||||
elements.set(index: 0, value: nil)
|
||||
elements.set(index: 1, value: 42 as NSNumber)
|
||||
let set = StdlibKt.set(elements: elements) as! NSSet
|
||||
try assertEquals(actual: set.count, expected: 2)
|
||||
try assertEquals(actual: set.member(NSNull()) as! NSNull, expected: NSNull())
|
||||
try assertEquals(actual: set.member(42) as! NSNumber, expected: NSNumber(value: 42 as Int32))
|
||||
try assertTrue(set.member(17) == nil)
|
||||
try assertFalse(set.member(42) as AnyObject === NSNumber(value: 42 as Int32))
|
||||
try assertTrue(set.contains(42))
|
||||
try assertTrue(set.contains(nil as Any?))
|
||||
try assertFalse(set.contains(17))
|
||||
|
||||
try assertEquals(actual: NSSet(array: set.objectEnumerator().remainingObjects()), expected: NSSet(array: [nil, 42] as [AnyObject]))
|
||||
}
|
||||
|
||||
func testMap() throws {
|
||||
let elements = KotlinArray<AnyObject>(size: 6) { index in nil }
|
||||
elements.set(index: 0, value: nil)
|
||||
elements.set(index: 1, value: 42 as NSNumber)
|
||||
elements.set(index: 2, value: "foo" as NSString)
|
||||
elements.set(index: 3, value: "bar" as NSString)
|
||||
elements.set(index: 4, value: 42 as NSNumber)
|
||||
elements.set(index: 5, value: nil)
|
||||
|
||||
let map = StdlibKt.map(keysAndValues: elements) as! NSDictionary
|
||||
try assertEquals(actual: map.count, expected: 3)
|
||||
|
||||
try assertEquals(actual: map.object(forKey: NSNull()) as! NSNumber, expected: NSNumber(value: 42))
|
||||
try assertEquals(actual: map.object(forKey: "foo") as! String, expected: "bar")
|
||||
try assertEquals(actual: map.object(forKey: 42) as! NSNull, expected: NSNull())
|
||||
try assertTrue(map.object(forKey: "bar") == nil)
|
||||
|
||||
try assertEquals(actual: NSSet(array: map.keyEnumerator().remainingObjects()), expected: NSSet(array: [nil, 42, "foo"] as [AnyObject]))
|
||||
}
|
||||
|
||||
func testKotlinMutableSetInit() throws {
|
||||
func test(
|
||||
_ set: KotlinMutableSet<NSString>,
|
||||
_ check: (KotlinMutableSet<NSString>) throws -> Void = { _ in }
|
||||
) throws {
|
||||
try assertEquals(actual: String(describing: type(of: set)), expected: "StdlibMutableSet")
|
||||
try check(set)
|
||||
try assertFalse(set.contains("1"))
|
||||
set.add("1")
|
||||
try assertTrue(set.contains("1"))
|
||||
}
|
||||
|
||||
try test(KotlinMutableSet())
|
||||
try test(KotlinMutableSet(capacity: 1))
|
||||
try test(KotlinMutableSet(object: "2")) {
|
||||
try assertTrue($0.contains("2"))
|
||||
}
|
||||
|
||||
var threeAndFour = ["3", "4"] as [AnyObject]
|
||||
try test(KotlinMutableSet(objects: &threeAndFour, count: 2)) {
|
||||
try assertTrue($0.contains("3"))
|
||||
try assertTrue($0.contains("4"))
|
||||
}
|
||||
|
||||
try test(KotlinMutableSet(array: ["5", "6"])) {
|
||||
try assertTrue($0.contains("5"))
|
||||
try assertTrue($0.contains("6"))
|
||||
}
|
||||
|
||||
try test(KotlinMutableSet(set: ["7", "8"])) {
|
||||
try assertTrue($0.contains("7"))
|
||||
try assertTrue($0.contains("8"))
|
||||
}
|
||||
|
||||
for flag in [false, true] {
|
||||
try test(KotlinMutableSet(set: ["9", "10"], copyItems: flag)) {
|
||||
try assertTrue($0.contains("9"))
|
||||
try assertTrue($0.contains("10"))
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: doesn't work, KotlinMutableSet seems to be serialized as NSMutableSet.
|
||||
if #available(macOS 10.13, *) {
|
||||
let data = try! NSKeyedArchiver.archivedData(
|
||||
withRootObject: KotlinMutableSet<NSString>(array: ["11", "12"]),
|
||||
requiringSecureCoding: false
|
||||
)
|
||||
|
||||
try test(try! NSKeyedUnarchiver.unarchivedObject(ofClass: KotlinMutableSet.self, from: data)!) {
|
||||
try assertTrue($0.contains("11"))
|
||||
try assertTrue($0.contains("12"))
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
StdlibKt.gc() // To reproduce https://github.com/JetBrains/kotlin-native/issues/3259
|
||||
}
|
||||
|
||||
func testKotlinMutableDictionaryInit() throws {
|
||||
func test(
|
||||
_ dict: KotlinMutableDictionary<NSString, NSString>,
|
||||
_ check: (KotlinMutableDictionary<NSString, NSString>) throws -> Void = { _ in }
|
||||
) throws {
|
||||
try assertEquals(actual: String(describing: type(of: dict)), expected: "StdlibMutableDictionary")
|
||||
try check(dict)
|
||||
try assertTrue(dict["1"] == nil)
|
||||
dict["1"] = "2"
|
||||
try assertTrue(dict["1"] as? NSString == "2")
|
||||
}
|
||||
|
||||
try test(KotlinMutableDictionary())
|
||||
try test(KotlinMutableDictionary(capacity: 4))
|
||||
|
||||
// TODO: test [initWithCoder:].
|
||||
|
||||
try test(KotlinMutableDictionary(objects: ["3", "4"], forKeys: ["4", "3"] as [NSString])) {
|
||||
try assertEquals(actual: $0["3"] as? String, expected: "4")
|
||||
try assertEquals(actual: $0["4"] as? String, expected: "3")
|
||||
}
|
||||
|
||||
var fiveAndSix = ["5", "6"] as [AnyObject]
|
||||
var sixAndFive = ["6", "5"] as [NSCopying]
|
||||
try test(KotlinMutableDictionary(objects: &fiveAndSix, forKeys: &sixAndFive, count: 2)) {
|
||||
try assertEquals(actual: $0["5"] as? String, expected: "6")
|
||||
try assertEquals(actual: $0["6"] as? String, expected: "5")
|
||||
}
|
||||
|
||||
try test(KotlinMutableDictionary(object: "7", forKey: "8" as NSString)) {
|
||||
try assertEquals(actual: $0["8"] as? String, expected: "7")
|
||||
}
|
||||
|
||||
try test(KotlinMutableDictionary(dictionary: ["10" : "9"])) {
|
||||
try assertEquals(actual: $0["10"] as? String, expected: "9")
|
||||
}
|
||||
|
||||
for flag in [false, true] {
|
||||
try test(KotlinMutableDictionary(dictionary: ["12" : "11"], copyItems: flag)) {
|
||||
try assertEquals(actual: $0["12"] as? String, expected: "11")
|
||||
}
|
||||
}
|
||||
|
||||
try test(KotlinMutableDictionary(dictionaryLiteral: ("14", "13"))) {
|
||||
try assertEquals(actual: $0["14"] as? String, expected: "13")
|
||||
}
|
||||
|
||||
StdlibKt.gc() // To reproduce https://github.com/JetBrains/kotlin-native/issues/3259
|
||||
}
|
||||
|
||||
func testSwiftSetInKotlin() throws {
|
||||
try StdlibKt.testSet(set: ["a", "b", "c", "d", "e", "f", "g"])
|
||||
}
|
||||
|
||||
func testSwiftDictionaryInKotlin() throws {
|
||||
try StdlibKt.testMap(map: ["a" : 1, "b" : 2, "c" : 3, "d" : 4, "e" : 5, "f" : 6, "g" : 7])
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package shared
|
||||
|
||||
fun shared() {}
|
||||
@@ -1,294 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
import ValuesGenerics
|
||||
|
||||
// -------- Tests --------
|
||||
|
||||
func testVararg() throws {
|
||||
let ktArray = KotlinArray<KotlinInt>(size: 3, init: { (_) -> KotlinInt in return KotlinInt(int:42) })
|
||||
let arr: [Int] = ValuesKt.varargToList(args: ktArray as! KotlinArray<AnyObject>) as! [Int]
|
||||
try assertEquals(actual: arr, expected: [42, 42, 42])
|
||||
}
|
||||
|
||||
func testDataClass() throws {
|
||||
let f = "1" as NSString
|
||||
let s = "2" as NSString
|
||||
let t = "3" as NSString
|
||||
|
||||
let tripleVal = TripleVals<NSString>(first: f, second: s, third: t)
|
||||
try assertEquals(actual: tripleVal.first, expected: f, "Data class' value")
|
||||
try assertEquals(actual: tripleVal.first, expected: "1", "Data class' value literal")
|
||||
print(tripleVal)
|
||||
try assertEquals(actual: String(describing: tripleVal), expected: "TripleVals(first=\(f), second=\(s), third=\(t))")
|
||||
|
||||
let tripleVar = TripleVars<NSString>(first: f, second: s, third: t)
|
||||
try assertEquals(actual: tripleVar.first, expected: f, "Data class' value")
|
||||
print(tripleVar)
|
||||
try assertEquals(actual: String(describing: tripleVar), expected: "[\(f), \(s), \(t)]")
|
||||
|
||||
tripleVar.first = t
|
||||
tripleVar.second = f
|
||||
tripleVar.third = s
|
||||
try assertEquals(actual: String(describing: tripleVar), expected: "[\(t), \(f), \(s)]")
|
||||
}
|
||||
|
||||
func testInlineClasses() throws {
|
||||
let ic1: Int32 = 42
|
||||
let ic1N = ValuesKt.box(ic1: 17)
|
||||
let ic2 = "foo"
|
||||
let ic2N = "bar"
|
||||
let ic3 = TripleVals<AnyObject>(first: KotlinInt(int:1), second: KotlinInt(int:2), third: KotlinInt(int:3))
|
||||
let ic3N = ValuesKt.box(ic3: nil)
|
||||
|
||||
try assertEquals(
|
||||
actual: ValuesKt.concatenateInlineClassValues(ic1: ic1, ic1N: ic1N, ic2: ic2, ic2N: ic2N, ic3: ic3, ic3N: ic3N),
|
||||
expected: "42 17 foo bar TripleVals(first=1, second=2, third=3) null"
|
||||
)
|
||||
|
||||
try assertEquals(
|
||||
actual: ValuesKt.concatenateInlineClassValues(ic1: ic1, ic1N: nil, ic2: ic2, ic2N: nil, ic3: nil, ic3N: nil),
|
||||
expected: "42 null foo null null null"
|
||||
)
|
||||
|
||||
try assertEquals(actual: ValuesKt.getValue1(ic1), expected: 42)
|
||||
try assertEquals(actual: ValuesKt.getValueOrNull1(ic1N) as! Int, expected: 17)
|
||||
|
||||
try assertEquals(actual: ValuesKt.getValue2(ic2), expected: "foo")
|
||||
try assertEquals(actual: ValuesKt.getValueOrNull2(ic2N), expected: "bar")
|
||||
|
||||
try assertEquals(actual: ValuesKt.getValue3(ic3), expected: ic3)
|
||||
try assertEquals(actual: ValuesKt.getValueOrNull3(ic3N), expected: nil)
|
||||
}
|
||||
|
||||
func testGeneric() throws {
|
||||
let a = SomeGeneric<SomeData>(t: SomeData(num: 52))
|
||||
let asd : SomeData = a.myVal()!
|
||||
try assertEquals(actual: asd.num, expected: 52)
|
||||
|
||||
let nulls = GenOpen<SomeData>(arg: SomeData(num: 62))
|
||||
let nullssd : SomeData = nulls.arg!
|
||||
try assertEquals(actual: nullssd.num, expected: 62)
|
||||
|
||||
let isnull = GenOpen<SomeData>(arg: nil)
|
||||
try assertEquals(actual: isnull.arg, expected: nil)
|
||||
|
||||
let nonnulls = GenNonNull<SomeData>(arg: SomeData(num: 72))
|
||||
let nonnullssd : SomeData = nonnulls.arg
|
||||
try assertEquals(actual: nonnullssd.num, expected: 72)
|
||||
try assertEquals(actual: (Values_genericsKt.starGeneric(arg: nonnulls as! GenNonNull<AnyObject>) as! SomeData).num, expected: 72)
|
||||
|
||||
let sd = SomeData(num: 33)
|
||||
let nullColl = GenCollectionsNull<SomeData>(arg: sd, coll: [sd])
|
||||
let nonNullColl = GenCollectionsNonNull<SomeData>(arg: sd, coll: [sd])
|
||||
|
||||
try assertEquals(actual: (nullColl.coll[0] as! SomeData).num, expected: 33)
|
||||
let nonNullCollSd : SomeData = nonNullColl.coll[0]
|
||||
try assertEquals(actual: nonNullCollSd.num, expected: 33)
|
||||
try assertEquals(actual: nonNullColl.arg, expected: nonNullCollSd)
|
||||
|
||||
let mixed = GenNullability<SomeData>(arg: sd, nArg: sd)
|
||||
try assertEquals(actual: mixed.asNullable()?.num, expected: 33)
|
||||
try assertEquals(actual: mixed.pAsNullable?.num, expected: 33)
|
||||
let mixedSd : SomeData? = mixed.pAsNullable
|
||||
try assertEquals(actual: mixedSd, expected: mixed.nArg)
|
||||
}
|
||||
|
||||
// Swift ignores the variance and lets you force-cast to whatever you need, for better or worse.
|
||||
// This would *not* work with direct Swift interop.
|
||||
func testGenericVariance() throws {
|
||||
let sd = SomeData(num: 22)
|
||||
|
||||
let variOut = GenVarOut<SomeData>(arg: sd)
|
||||
let variOutAny : GenVarOut<BaseData> = variOut as! GenVarOut<BaseData>
|
||||
let variOutOther : GenVarOut<SomeOtherData> = variOut as! GenVarOut<SomeOtherData>
|
||||
|
||||
let variOutCheck = "variOut: \(variOut.arg.asString()), variOutAny: \(variOutAny.arg.asString()), variOutOther: \(variOutOther.arg.asString())"
|
||||
try assertEquals(actual: variOutCheck, expected: "variOut: 22, variOutAny: 22, variOutOther: 22")
|
||||
|
||||
let variIn = GenVarIn<SomeData>(tArg: sd)
|
||||
let variInAny : GenVarIn<BaseData> = variIn as! GenVarIn<BaseData>
|
||||
let variInOther : GenVarIn<SomeOtherData> = variIn as! GenVarIn<SomeOtherData>
|
||||
|
||||
let varInCheck = "variIn: \(variIn.valString()), variInAny: \(variInAny.valString()), variInOther: \(variInOther.valString())"
|
||||
try assertEquals(actual: varInCheck, expected: "variIn: SomeData(num=22), variInAny: SomeData(num=22), variInOther: SomeData(num=22)")
|
||||
|
||||
let variCoType:GenVarOut<BaseData> = Values_genericsKt.variCoType()
|
||||
try assertEquals(actual: "890", expected: variCoType.arg.asString())
|
||||
|
||||
let variContraType:GenVarIn<SomeData> = Values_genericsKt.variContraType()
|
||||
try assertEquals(actual: "SomeData(num=1890)", expected: variContraType.valString())
|
||||
}
|
||||
|
||||
// Swift should completely ignore this, as should objc. Really verifying that the header generator
|
||||
// deals with this
|
||||
func testGenericUseSiteVariance() throws {
|
||||
let sd = SomeData(num: 22)
|
||||
|
||||
let varUse = GenVarUse<BaseData>(arg: sd)
|
||||
let varUseArg = GenVarUse<BaseData>(arg: sd)
|
||||
|
||||
varUse.varUse(a: varUseArg, b: GenVarUse<SomeData>(arg: sd) as! GenVarUse<BaseData>)
|
||||
}
|
||||
|
||||
func testGenericInterface() throws {
|
||||
let a: NoGeneric = SomeGeneric<SomeData>(t: SomeData(num: 52))
|
||||
try assertEquals(actual: (a.myVal() as! SomeData).num, expected: 52)
|
||||
}
|
||||
|
||||
func testGenericInheritance() throws {
|
||||
let ge = GenEx<SomeData, SomeOtherData>(myT:SomeOtherData(str:"Hello"), baseT:SomeData(num: 11))
|
||||
let geT : SomeData = ge.t
|
||||
try assertEquals(actual: geT.num, expected: 11)
|
||||
let gemyT : SomeOtherData = ge.myT
|
||||
try assertEquals(actual: gemyT.str, expected: "Hello")
|
||||
let geBase = ge as GenBase<SomeData>
|
||||
let geBaseT : SomeData = geBase.t
|
||||
try assertEquals(actual: geBaseT.num, expected: 11)
|
||||
|
||||
//Similar to above but param names don't match and will dupe property definitions on child class
|
||||
//Functional, but should be fixed
|
||||
let ge2 = GenEx2<SomeData, SomeOtherData>(myT:SomeOtherData(str:"Hello2"), baseT:SomeData(num: 22))
|
||||
let ge2Val : SomeData = ge2.t
|
||||
let ge2SODVal : SomeOtherData = ge2.myT
|
||||
let ge2base : GenBase<SomeData> = ge2 as GenBase<SomeData>
|
||||
let ge2BaseVal : SomeData = ge2base.t
|
||||
try assertEquals(actual: ge2Val, expected: ge2BaseVal)
|
||||
|
||||
let geAny = GenExAny<SomeData, SomeOtherData>(myT:SomeOtherData(str:"Hello"), baseT:SomeData(num: 131))
|
||||
try assertEquals(actual: (geAny.t as! SomeData).num, expected: 131)
|
||||
let geBaseAny = geAny as! GenBase<SomeData>
|
||||
let geBaseAnyT : SomeData = geBaseAny.t
|
||||
try assertEquals(actual: geBaseAnyT.num, expected: 131)
|
||||
}
|
||||
|
||||
func testGenericInnerClass() throws {
|
||||
|
||||
let nestedClass = GenOuterGenNested<SomeData>(b: SomeData(num: 543))
|
||||
let nestedClassB : SomeData = nestedClass.b
|
||||
try assertEquals(actual: nestedClassB.num, expected: 543)
|
||||
|
||||
let innerClass = GenOuterGenInner<SomeData, SomeOtherData>(GenOuter<SomeOtherData>(a: SomeOtherData(str: "ggg")), c: SomeData(num: 66), aInner: SomeOtherData(str: "ttt"))
|
||||
let innerClassC : SomeData = innerClass.c
|
||||
try assertEquals(actual: innerClassC.num, expected: 66)
|
||||
let outerFun : SomeOtherData = innerClass.outerFun()
|
||||
let outerVal : SomeOtherData = innerClass.outerVal
|
||||
try assertEquals(actual: outerFun, expected: outerVal)
|
||||
try assertEquals(actual: outerFun.str, expected: "ggg")
|
||||
|
||||
Values_genericsKt.genInnerFunc(obj: innerClass)
|
||||
Values_genericsKt.genInnerFuncAny(obj: innerClass as! GenOuterGenInner<AnyObject, AnyObject>)
|
||||
|
||||
let innerReturned : GenOuterGenInner<SomeOtherData, SomeData> = Values_genericsKt.genInnerCreate()
|
||||
let innerReturnedInner : SomeOtherData = innerReturned.c
|
||||
try assertEquals(actual: innerReturnedInner.str, expected: "ppp")
|
||||
|
||||
let nestedClassSame = GenOuterSameGenNestedSame<SomeData>(a: SomeData(num: 545))
|
||||
let nestedClassSameA : SomeData = nestedClassSame.a
|
||||
try assertEquals(actual: nestedClassSameA.num, expected: 545)
|
||||
|
||||
let nested = GenOuterSameNestedNoGeneric()
|
||||
|
||||
let innerClassSame = GenOuterSameGenInnerSame<SomeOtherData, SomeData>(GenOuterSame<SomeData>(a: SomeData(num: 44)), a: SomeOtherData(str: "rrr"))
|
||||
let innerClassSameA : SomeOtherData = innerClassSame.a
|
||||
try assertEquals(actual: innerClassSame.a.str, expected: "rrr")
|
||||
|
||||
let gob : GenOuterBlankGenInner<SomeOtherData> = GenOuterBlankGenInner<SomeOtherData>(GenOuterBlank(sd: SomeData(num: 321)), arg: SomeOtherData(str: "aaa"))
|
||||
let gob2 : GenOuterBlank2GenInner<SomeOtherData> = GenOuterBlank2GenInner<SomeOtherData>(GenOuterBlank2(oarg: SomeOtherData(str: "ooo")), arg: SomeOtherData(str: "bbb"))
|
||||
|
||||
let gobsod : SomeOtherData = gob.arg!
|
||||
try assertEquals(actual: gobsod.str, expected: "aaa")
|
||||
|
||||
let gob2arg : SomeOtherData = gob2.arg!
|
||||
let gob2out : SomeOtherData = gob2.fromOuter()!
|
||||
|
||||
try assertEquals(actual: gob2arg.str, expected: "bbb")
|
||||
try assertEquals(actual: gob2out.str, expected: "ooo")
|
||||
|
||||
let inarg = GenOuterDeepGenShallowInner<SomeOtherData>(GenOuterDeep<SomeOtherData>(oarg: SomeOtherData(str: "fff")))
|
||||
let godeep : GenOuterDeepGenShallowInnerGenDeepInner<SomeOtherData> = GenOuterDeepGenShallowInnerGenDeepInner<SomeOtherData>(inarg)
|
||||
let deepval : SomeOtherData = godeep.o()!
|
||||
try assertEquals(actual: deepval.str, expected: "fff")
|
||||
|
||||
let deep2 = GenOuterDeep2()
|
||||
let deep2Before = GenOuterDeep2.Before(deep2)
|
||||
let deep2After = GenOuterDeep2.After(deep2)
|
||||
let deep2soi = GenOuterDeep2.GenShallowOuterInner(deep2)
|
||||
let deep2si = GenOuterDeep2GenShallowOuterInnerGenShallowInner<SomeData>(deep2soi)
|
||||
let deep2i = GenOuterDeep2GenShallowOuterInnerGenShallowInnerGenDeepInner<SomeData>(deep2si)
|
||||
|
||||
let gbb : GenBothBlank.GenInner = GenBothBlank.GenInner(GenBothBlank(a: SomeData(num: 22)), b: SomeOtherData(str: "ttt"))
|
||||
try assertEquals(actual: gbb.b.str, expected: "ttt")
|
||||
}
|
||||
|
||||
func testGenericClashing() throws {
|
||||
let gcId = GenClashId<SomeData, SomeOtherData>(arg: SomeData(num: 22), arg2: SomeOtherData(str: "lll"))
|
||||
try assertEquals(actual: gcId.x() as! NSString, expected: "Foo")
|
||||
let gcIdArg : SomeData = gcId.arg
|
||||
try assertEquals(actual: gcIdArg.num, expected: 22)
|
||||
let gcIdArg2 : SomeOtherData = gcId.arg2
|
||||
try assertEquals(actual: gcIdArg2.str, expected: "lll")
|
||||
|
||||
let gcClass = GenClashClass<SomeData, SomeOtherData, NSString>(arg: SomeData(num: 432), arg2: SomeOtherData(str: "lll"), arg3: "Bar")
|
||||
try assertEquals(actual: gcClass.int(), expected: 55)
|
||||
try assertEquals(actual: gcClass.sd().num, expected: 88)
|
||||
try assertEquals(actual: gcClass.list()[1].num, expected: 22)
|
||||
try assertEquals(actual: gcClass.arg.num, expected: 432)
|
||||
try assertEquals(actual: gcClass.clash().str, expected: "aaa")
|
||||
try assertEquals(actual: gcClass.arg2.str, expected: "lll")
|
||||
try assertEquals(actual: gcClass.arg3, expected: "Bar")
|
||||
|
||||
//GenClashNames uses type parameter names that force the Objc class name itself to be mangled. Swift keeps names however
|
||||
let clashNames = GenClashNames<SomeData, SomeData, SomeData, SomeData>()
|
||||
try assertEquals(actual: clashNames.foo().str, expected: "nnn")
|
||||
try assertEquals(actual: clashNames.bar().str, expected: "qqq")
|
||||
try assertTrue(clashNames.baz(arg: ClashnameParam(str: "meh")), "ClashnameParam issue")
|
||||
|
||||
let clashNamesEx = GenClashEx<SomeData>()
|
||||
|
||||
let geClash = GenExClash<SomeOtherData>(myT:SomeOtherData(str:"Hello"))
|
||||
try assertEquals(actual: geClash.t.num, expected: 55)
|
||||
try assertEquals(actual: geClash.myT.str, expected: "Hello")
|
||||
}
|
||||
|
||||
func testGenericExtensions() throws {
|
||||
let gnn = GenNonNull<SomeData>(arg: SomeData(num: 432))
|
||||
try assertEquals(actual: (gnn.foo() as! SomeData).num, expected: 432)
|
||||
}
|
||||
|
||||
// -------- Execution of the test --------
|
||||
|
||||
class ValuesTests : TestProvider {
|
||||
var tests: [TestCase] = []
|
||||
|
||||
init() {
|
||||
providers.append(self)
|
||||
tests = [
|
||||
TestCase(name: "TestVararg", method: withAutorelease(testVararg)),
|
||||
TestCase(name: "TestDataClass", method: withAutorelease(testDataClass)),
|
||||
TestCase(name: "TestInlineClasses", method: withAutorelease(testInlineClasses)),
|
||||
TestCase(name: "TestGeneric", method: withAutorelease(testGeneric)),
|
||||
TestCase(name: "TestGenericVariance", method: withAutorelease(testGenericVariance)),
|
||||
TestCase(name: "TestGenericUseSiteVariance", method: withAutorelease(testGenericUseSiteVariance)),
|
||||
TestCase(name: "TestGenericInheritance", method: withAutorelease(testGenericInheritance)),
|
||||
TestCase(name: "TestGenericInterface", method: withAutorelease(testGenericInterface)),
|
||||
TestCase(name: "TestGenericInnerClass", method: withAutorelease(testGenericInnerClass)),
|
||||
TestCase(name: "TestGenericClashing", method: withAutorelease(testGenericClashing)),
|
||||
TestCase(name: "TestGenericExtensions", method: withAutorelease(testGenericExtensions)),
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,196 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
// All classes and methods should be used in tests
|
||||
@file:Suppress("UNUSED")
|
||||
|
||||
package conversions
|
||||
|
||||
import kotlin.native.concurrent.isFrozen
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
// Generics
|
||||
abstract class BaseData{
|
||||
abstract fun asString():String
|
||||
}
|
||||
|
||||
data class SomeData(val num:Int = 42):BaseData() {
|
||||
override fun asString(): String = num.toString()
|
||||
}
|
||||
|
||||
data class SomeOtherData(val str:String):BaseData() {
|
||||
fun anotherFun(){}
|
||||
override fun asString(): String = str
|
||||
}
|
||||
|
||||
interface NoGeneric<T> {
|
||||
fun myVal():T
|
||||
}
|
||||
|
||||
data class SomeGeneric<T>(val t:T):NoGeneric<T>{
|
||||
override fun myVal(): T = t
|
||||
}
|
||||
|
||||
class GenOpen<T:Any?>(val arg:T)
|
||||
class GenNonNull<T:Any>(val arg:T)
|
||||
|
||||
class GenCollectionsNull<T>(val arg: T, val coll: List<T>)
|
||||
class GenCollectionsNonNull<T:Any>(val arg: T, val coll: List<T>)
|
||||
|
||||
//Force @class declaration at top of file with Objc variance
|
||||
object ForceUse {
|
||||
val gvo = GenVarOut(SomeData())
|
||||
}
|
||||
|
||||
class GenVarOut<out T:Any>(val arg:T)
|
||||
|
||||
class GenVarIn<in T:Any>(tArg:T){
|
||||
private val t = tArg
|
||||
|
||||
fun valString():String = t.toString()
|
||||
|
||||
fun goIn(t:T){
|
||||
//Just taking a val
|
||||
}
|
||||
}
|
||||
|
||||
class GenVarUse<T:Any>(val arg:T){
|
||||
fun varUse(a:GenVarUse<out T>, b:GenVarUse<in T>){
|
||||
//Should complile but do nothing
|
||||
}
|
||||
}
|
||||
|
||||
fun variCoType():GenVarOut<BaseData>{
|
||||
val compileVarOutSD:GenVarOut<SomeData> = GenVarOut(SomeData(890))
|
||||
val compileVarOut:GenVarOut<BaseData> = compileVarOutSD
|
||||
return compileVarOut
|
||||
}
|
||||
|
||||
fun variContraType():GenVarIn<SomeData>{
|
||||
val compileVariIn:GenVarIn<BaseData> = GenVarIn(SomeData(1890))
|
||||
val compileVariInSD:GenVarIn<SomeData> = compileVariIn
|
||||
return compileVariInSD
|
||||
}
|
||||
|
||||
open class GenBase<T:Any>(val t:T)
|
||||
class GenEx<TT:Any, T:Any>(val myT:T, baseT:TT):GenBase<TT>(baseT)
|
||||
class GenEx2<T:Any, S:Any>(val myT:S, baseT:T):GenBase<T>(baseT)
|
||||
|
||||
class GenExAny<TT:Any, T:Any>(val myT:T, baseT:TT):GenBase<Any>(baseT)
|
||||
|
||||
class GenNullability<T:Any>(val arg: T, val nArg:T?){
|
||||
fun asNullable():T? = arg
|
||||
val pAsNullable:T?
|
||||
get() = arg
|
||||
}
|
||||
|
||||
fun starGeneric(arg: GenNonNull<*>):Any{
|
||||
return arg.arg
|
||||
}
|
||||
|
||||
class GenOuter<A:Any>(val a:A){
|
||||
class GenNested<B:Any>(val b:B)
|
||||
inner class GenInner<C:Any>(val c:C, val aInner:A) {
|
||||
fun outerFun(): A = a
|
||||
val outerVal: A = a
|
||||
}
|
||||
}
|
||||
|
||||
class GenOuterSame<A:Any>(val a:A){
|
||||
class GenNestedSame<A:Any>(val a:A)
|
||||
inner class GenInnerSame<A:Any>(val a:A)
|
||||
class NestedNoGeneric()
|
||||
}
|
||||
|
||||
fun genInnerFunc(obj: GenOuter<SomeOtherData>.GenInner<SomeData>) {}
|
||||
fun <A:Any, C:Any> genInnerFuncAny(obj: GenOuter<A>.GenInner<C>){}
|
||||
|
||||
fun genInnerCreate(): GenOuter<SomeData>.GenInner<SomeOtherData> =
|
||||
GenOuter(SomeData(33)).GenInner(SomeOtherData("ppp"), SomeData(77))
|
||||
|
||||
class GenOuterBlank(val sd: SomeData) {
|
||||
inner class GenInner<T>(val arg: T){
|
||||
fun fromOuter(): SomeData = sd
|
||||
}
|
||||
}
|
||||
|
||||
class GenOuterBlank2<T>(val oarg: T) {
|
||||
inner class GenInner(val arg: T){
|
||||
fun fromOuter(): T = oarg
|
||||
}
|
||||
}
|
||||
|
||||
class GenOuterDeep<T>(val oarg: T) {
|
||||
inner class GenShallowInner(){
|
||||
inner class GenDeepInner(){
|
||||
fun o(): T = oarg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class GenOuterDeep2() {
|
||||
inner class Before()
|
||||
inner class GenShallowOuterInner() {
|
||||
inner class GenShallowInner<T>() {
|
||||
inner class GenDeepInner()
|
||||
}
|
||||
}
|
||||
inner class After()
|
||||
}
|
||||
|
||||
class GenBothBlank(val a: SomeData) {
|
||||
inner class GenInner(val b: SomeOtherData)
|
||||
}
|
||||
|
||||
class GenClashId<id : Any, id_ : Any>(val arg: id, val arg2: id_){
|
||||
fun x(): Any = "Foo"
|
||||
}
|
||||
|
||||
class GenClashClass<ValuesGenericsClashingData : Any, NSArray : Any, int32_t : Any>(
|
||||
val arg: ValuesGenericsClashingData, val arg2: NSArray, val arg3: int32_t
|
||||
) {
|
||||
fun sd(): SomeData = SomeData(88)
|
||||
fun list(): List<SomeData> = listOf(SomeData(11), SomeData(22))
|
||||
fun int(): Int = 55
|
||||
fun clash(): ClashingData = ClashingData("aaa")
|
||||
}
|
||||
|
||||
data class ClashingData(val str: String)
|
||||
|
||||
class GenClashNames<ValuesGenericsClashnameClass, ValuesGenericsClashnameProtocol, ValuesGenericsClashnameParam, ValuesGenericsValues_genericsKt>() {
|
||||
fun foo() = ClashnameClass("nnn")
|
||||
|
||||
fun bar(): ClashnameProtocol = object : ClashnameProtocol{
|
||||
override val str = "qqq"
|
||||
}
|
||||
|
||||
fun baz(arg: ClashnameParam): Boolean {
|
||||
return arg.str == "meh"
|
||||
}
|
||||
}
|
||||
|
||||
class GenClashEx<ValuesGenericsClashnameClass>: ClashnameClass("ttt"){
|
||||
fun foo() = ClashnameClass("nnn")
|
||||
}
|
||||
|
||||
open class ClashnameClass(val str: String)
|
||||
interface ClashnameProtocol {
|
||||
val str: String
|
||||
}
|
||||
data class ClashnameParam(val str: String)
|
||||
|
||||
class GenExClash<ValuesGenericsSomeData:Any>(val myT:ValuesGenericsSomeData):GenBase<SomeData>(SomeData(55))
|
||||
|
||||
class SelfRef : GenBasic<SelfRef>()
|
||||
|
||||
open class GenBasic<T>()
|
||||
|
||||
//Extensions
|
||||
fun <T:Any> GenNonNull<T>.foo(): T = arg
|
||||
|
||||
class StarProjectionInfiniteRecursion<T : StarProjectionInfiniteRecursion<T>>
|
||||
|
||||
fun testStarProjectionInfiniteRecursion(x: StarProjectionInfiniteRecursion<*>) {}
|
||||
@@ -1,248 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
|
||||
|
||||
package coroutines
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.cancellation.CancellationException
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
import kotlin.native.concurrent.isFrozen
|
||||
import kotlin.native.internal.ObjCErrorException
|
||||
import kotlin.test.*
|
||||
import kotlin.reflect.*
|
||||
|
||||
class CoroutineException : Throwable()
|
||||
|
||||
suspend fun suspendFun() = 42
|
||||
suspend fun unitSuspendFun() = Unit
|
||||
|
||||
@Throws(CoroutineException::class, CancellationException::class)
|
||||
suspend fun suspendFun(result: Any?, doSuspend: Boolean, doThrow: Boolean): Any? {
|
||||
if (doSuspend) {
|
||||
suspendCoroutineUninterceptedOrReturn<Unit> {
|
||||
it.resume(Unit)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
}
|
||||
|
||||
if (doThrow) throw CoroutineException()
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@Throws(CoroutineException::class, CancellationException::class)
|
||||
suspend fun unitSuspendFun(doSuspend: Boolean, doThrow: Boolean) {
|
||||
if (doSuspend) {
|
||||
suspendCoroutineUninterceptedOrReturn<Unit> {
|
||||
it.resume(Unit)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
}
|
||||
|
||||
if (doThrow) throw CoroutineException()
|
||||
}
|
||||
|
||||
class ContinuationHolder<T> {
|
||||
internal var continuation: Continuation<T>? = null
|
||||
|
||||
fun resume(value: T) {
|
||||
continuation!!.resume(value)
|
||||
continuation = null
|
||||
}
|
||||
|
||||
fun resumeWithException(exception: Throwable) {
|
||||
continuation!!.resumeWithException(exception)
|
||||
continuation = null
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(CoroutineException::class, CancellationException::class)
|
||||
suspend fun suspendFunAsync(result: Any?, continuationHolder: ContinuationHolder<Any?>): Any? =
|
||||
suspendCoroutineUninterceptedOrReturn<Any?> {
|
||||
continuationHolder.continuation = it
|
||||
COROUTINE_SUSPENDED
|
||||
} ?: result
|
||||
|
||||
@Throws(CoroutineException::class, CancellationException::class)
|
||||
suspend fun unitSuspendFunAsync(continuationHolder: ContinuationHolder<Unit>): Unit =
|
||||
suspendCoroutineUninterceptedOrReturn<Unit> {
|
||||
continuationHolder.continuation = it
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
@Throws(CoroutineException::class, CancellationException::class)
|
||||
fun throwException(exception: Throwable) {
|
||||
throw exception
|
||||
}
|
||||
|
||||
interface SuspendFun {
|
||||
@Throws(CoroutineException::class, CancellationException::class)
|
||||
suspend fun suspendFun(doYield: Boolean, doThrow: Boolean): Int
|
||||
}
|
||||
|
||||
class ResultHolder<T> {
|
||||
var completed: Int = 0
|
||||
var result: T? = null
|
||||
var exception: Throwable? = null
|
||||
|
||||
internal fun complete(result: Result<T>) {
|
||||
this.result = result.getOrNull()
|
||||
this.exception = result.exceptionOrNull()
|
||||
this.completed += 1
|
||||
}
|
||||
}
|
||||
|
||||
private class ResultHolderCompletion<T>(val resultHolder: ResultHolder<T>) : Continuation<T> {
|
||||
override val context: CoroutineContext
|
||||
get() = EmptyCoroutineContext
|
||||
|
||||
override fun resumeWith(result: Result<T>) {
|
||||
resultHolder.complete(result)
|
||||
}
|
||||
}
|
||||
|
||||
fun callSuspendFun(suspendFun: SuspendFun, doYield: Boolean, doThrow: Boolean, resultHolder: ResultHolder<Int>) {
|
||||
suspend { suspendFun.suspendFun(doYield = doYield, doThrow = doThrow) }
|
||||
.startCoroutine(ResultHolderCompletion(resultHolder))
|
||||
}
|
||||
|
||||
@Throws(CoroutineException::class, CancellationException::class)
|
||||
suspend fun callSuspendFun2(suspendFun: SuspendFun, doYield: Boolean, doThrow: Boolean): Int {
|
||||
return suspendFun.suspendFun(doYield = doYield, doThrow = doThrow)
|
||||
}
|
||||
|
||||
interface SuspendBridge<T> {
|
||||
suspend fun int(value: T): Int
|
||||
suspend fun intAsAny(value: T): Any?
|
||||
|
||||
suspend fun unit(value: T): Unit
|
||||
suspend fun unitAsAny(value: T): Any?
|
||||
suspend fun nullableUnit(value: T): Unit?
|
||||
|
||||
@Throws(Throwable::class) suspend fun nothing(value: T): Nothing
|
||||
@Throws(Throwable::class) suspend fun nothingAsInt(value: T): Int
|
||||
@Throws(Throwable::class) suspend fun nothingAsAny(value: T): Any?
|
||||
@Throws(Throwable::class) suspend fun nothingAsUnit(value: T): Unit
|
||||
}
|
||||
|
||||
abstract class AbstractSuspendBridge : SuspendBridge<Int> {
|
||||
override suspend fun intAsAny(value: Int): Int = TODO()
|
||||
|
||||
override suspend fun unit(value: Int): Unit = TODO()
|
||||
override suspend fun unitAsAny(value: Int): Unit = TODO()
|
||||
override suspend fun nullableUnit(value: Int): Unit? = TODO()
|
||||
|
||||
override suspend fun nothingAsInt(value: Int): Nothing = TODO()
|
||||
override suspend fun nothingAsAny(value: Int): Nothing = TODO()
|
||||
override suspend fun nothingAsUnit(value: Int): Nothing = TODO()
|
||||
}
|
||||
|
||||
private suspend fun callSuspendBridgeImpl(bridge: SuspendBridge<Int>) {
|
||||
assertEquals(1, bridge.intAsAny(1))
|
||||
|
||||
assertSame(Unit, bridge.unit(2))
|
||||
assertSame(Unit, bridge.unitAsAny(3))
|
||||
assertSame(Unit, bridge.nullableUnit(4))
|
||||
|
||||
assertFailsWith<ObjCErrorException> { bridge.nothingAsInt(5) }
|
||||
assertFailsWith<ObjCErrorException> { bridge.nothingAsAny(6) }
|
||||
assertFailsWith<ObjCErrorException> { bridge.nothingAsUnit(7) }
|
||||
}
|
||||
|
||||
private suspend fun callAbstractSuspendBridgeImpl(bridge: AbstractSuspendBridge) {
|
||||
assertEquals(8, bridge.intAsAny(8))
|
||||
|
||||
assertSame(Unit, bridge.unit(9))
|
||||
assertSame(Unit, bridge.unitAsAny(10))
|
||||
assertSame(Unit, bridge.nullableUnit(11))
|
||||
|
||||
assertFailsWith<ObjCErrorException> { bridge.nothingAsInt(12) }
|
||||
assertFailsWith<ObjCErrorException> { bridge.nothingAsAny(13) }
|
||||
assertFailsWith<ObjCErrorException> { bridge.nothingAsUnit(14) }
|
||||
}
|
||||
|
||||
@Throws(Throwable::class)
|
||||
fun callSuspendBridge(bridge: AbstractSuspendBridge, resultHolder: ResultHolder<Unit>) {
|
||||
suspend {
|
||||
callSuspendBridgeImpl(bridge)
|
||||
callAbstractSuspendBridgeImpl(bridge)
|
||||
}.startCoroutine(ResultHolderCompletion(resultHolder))
|
||||
}
|
||||
|
||||
suspend fun throwCancellationException(): Unit {
|
||||
val exception = CancellationException("coroutine is cancelled")
|
||||
|
||||
// Note: frontend checker hardcodes fq names of CancellationException super classes (see NativeThrowsChecker).
|
||||
// This is our best effort to keep that list in sync with actual stdlib code:
|
||||
assertTrue(exception is kotlin.Throwable)
|
||||
assertTrue(exception is kotlin.Exception)
|
||||
assertTrue(exception is kotlin.RuntimeException)
|
||||
assertTrue(exception is kotlin.IllegalStateException)
|
||||
assertTrue(exception is kotlin.coroutines.cancellation.CancellationException)
|
||||
|
||||
throw exception
|
||||
}
|
||||
|
||||
abstract class ThrowCancellationException {
|
||||
internal abstract suspend fun throwCancellationException()
|
||||
}
|
||||
|
||||
class ThrowCancellationExceptionImpl : ThrowCancellationException() {
|
||||
public override suspend fun throwCancellationException() {
|
||||
throw CancellationException()
|
||||
}
|
||||
}
|
||||
|
||||
class suspendFunctionChild0: suspend () -> String {
|
||||
override suspend fun invoke(): String = "child 0"
|
||||
}
|
||||
|
||||
class suspendFunctionChild1: suspend (String) -> String {
|
||||
override suspend fun invoke(s: String): String = "$s 1"
|
||||
}
|
||||
|
||||
fun getSuspendLambda0(): suspend () -> String = { "lambda 0" }
|
||||
|
||||
private suspend fun suspendCallableReference0Target(): String = "callable reference 0"
|
||||
fun getSuspendCallableReference0(): suspend () -> String = ::suspendCallableReference0Target
|
||||
|
||||
fun getSuspendChild0() = suspendFunctionChild0()
|
||||
|
||||
fun getSuspendLambda1(): suspend (String) -> String = { "$it 1" }
|
||||
|
||||
private suspend fun suspendCallableReference1Target(str: String): String = "$str 1"
|
||||
fun getSuspendCallableReference1(): suspend (String) -> String = ::suspendCallableReference1Target
|
||||
fun getSuspendChild1() = suspendFunctionChild1()
|
||||
|
||||
|
||||
suspend fun invoke1(block: suspend (Any?) -> Any?, argument: Any?): Any? = block(argument)
|
||||
|
||||
fun getKSuspendCallableReference0(): KSuspendFunction0<String> = ::suspendCallableReference0Target
|
||||
fun getKSuspendCallableReference1(): KSuspendFunction1<String, String> = ::suspendCallableReference1Target
|
||||
|
||||
@Throws(Throwable::class)
|
||||
fun startCoroutineUninterceptedOrReturn(fn: suspend () -> Any?, resultHolder: ResultHolder<Any?>) =
|
||||
fn.startCoroutineUninterceptedOrReturn(ResultHolderCompletion(resultHolder))
|
||||
|
||||
@Throws(Throwable::class)
|
||||
fun startCoroutineUninterceptedOrReturn(fn: suspend Any?.() -> Any?, receiver: Any?, resultHolder: ResultHolder<Any?>) =
|
||||
fn.startCoroutineUninterceptedOrReturn(receiver, ResultHolderCompletion(resultHolder))
|
||||
|
||||
@Throws(Throwable::class)
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
fun startCoroutineUninterceptedOrReturn(fn: suspend Any?.(Any?) -> Any?, receiver: Any?, param: Any?, resultHolder: ResultHolder<Any?>) =
|
||||
fn.startCoroutineUninterceptedOrReturn(receiver, param, ResultHolderCompletion(resultHolder))
|
||||
|
||||
@Throws(Throwable::class)
|
||||
fun createCoroutineUninterceptedAndResume(fn: suspend () -> Any?, resultHolder: ResultHolder<Any?>) =
|
||||
fn.createCoroutine(ResultHolderCompletion(resultHolder)).resume(Unit)
|
||||
|
||||
@Throws(Throwable::class)
|
||||
fun createCoroutineUninterceptedAndResume(fn: suspend Any?.() -> Any?, receiver: Any?, resultHolder: ResultHolder<Any?>) =
|
||||
fn.createCoroutine(receiver, ResultHolderCompletion(resultHolder)).resume(Unit)
|
||||
|
||||
@OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
|
||||
fun gc() = kotlin.native.runtime.GC.collect()
|
||||
@@ -1,741 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
private func testCallSimple() throws {
|
||||
var result: KotlinInt? = nil
|
||||
var error: Error? = nil
|
||||
var completionCalled = 0
|
||||
|
||||
CoroutinesKt.suspendFun { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result
|
||||
error = _error
|
||||
}
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
try assertEquals(actual: result, expected: 42)
|
||||
try assertNil(error)
|
||||
}
|
||||
|
||||
private func testUnitCallSimple() throws {
|
||||
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
|
||||
var result: KotlinUnit? = nil
|
||||
#endif
|
||||
var error: Error? = nil
|
||||
var completionCalled = 0
|
||||
|
||||
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
|
||||
CoroutinesKt.unitSuspendFun { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result
|
||||
error = _error
|
||||
}
|
||||
#else
|
||||
CoroutinesKt.unitSuspendFun { _error in
|
||||
completionCalled += 1
|
||||
error = _error
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
|
||||
try assertSame(actual: result, expected: KotlinUnit.shared)
|
||||
#endif
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
try assertNil(error)
|
||||
}
|
||||
|
||||
private func testUnitCallNonMainDispatcher() throws {
|
||||
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
|
||||
var result: KotlinUnit? = nil
|
||||
#endif
|
||||
var error: Error? = nil
|
||||
var completionCalled = 0
|
||||
|
||||
let group = DispatchGroup()
|
||||
|
||||
#if ALLOW_SUSPEND_ANY_THREAD
|
||||
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
|
||||
DispatchQueue.global().async(group: group) {
|
||||
CoroutinesKt.unitSuspendFun { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result
|
||||
error = _error
|
||||
}
|
||||
}
|
||||
#else
|
||||
DispatchQueue.global().async(group: group) {
|
||||
CoroutinesKt.unitSuspendFun { _error in
|
||||
completionCalled += 1
|
||||
error = _error
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if ALLOW_SUSPEND_ANY_THREAD
|
||||
group.wait()
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
private func testCallSuspendFun(doSuspend: Bool, doThrow: Bool) throws {
|
||||
class C {}
|
||||
let expectedResult = C()
|
||||
|
||||
var completionCalled = 0
|
||||
var result: AnyObject? = nil
|
||||
var error: Error? = nil
|
||||
|
||||
CoroutinesKt.suspendFun(result: expectedResult, doSuspend: doSuspend, doThrow: doThrow) { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result as AnyObject?
|
||||
error = _error
|
||||
}
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
|
||||
if doThrow {
|
||||
try assertNil(result)
|
||||
try assertTrue(error?.kotlinException is CoroutineException)
|
||||
} else {
|
||||
try assertSame(actual: result, expected: expectedResult)
|
||||
try assertNil(error)
|
||||
}
|
||||
}
|
||||
|
||||
private func testCallUnitSuspendFun(doSuspend: Bool, doThrow: Bool) throws {
|
||||
var completionCalled = 0
|
||||
var result: AnyObject? = nil
|
||||
var error: Error? = nil
|
||||
|
||||
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
|
||||
CoroutinesKt.unitSuspendFun(doSuspend: doSuspend, doThrow: doThrow) { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result as AnyObject?
|
||||
error = _error
|
||||
}
|
||||
#else
|
||||
CoroutinesKt.unitSuspendFun(doSuspend: doSuspend, doThrow: doThrow) { _error in
|
||||
completionCalled += 1
|
||||
error = _error
|
||||
}
|
||||
#endif
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
|
||||
if doThrow {
|
||||
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
|
||||
try assertNil(result)
|
||||
#endif
|
||||
try assertTrue(error?.kotlinException is CoroutineException)
|
||||
} else {
|
||||
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
|
||||
try assertSame(actual: result, expected: KotlinUnit.shared)
|
||||
#endif
|
||||
try assertNil(error)
|
||||
}
|
||||
}
|
||||
|
||||
private class WeakRefHolder {
|
||||
weak var value: AnyObject? = nil
|
||||
}
|
||||
|
||||
#if NO_GENERICS
|
||||
typealias AnyContinuationHolder = ContinuationHolder
|
||||
#else
|
||||
typealias AnyContinuationHolder = ContinuationHolder<AnyObject>
|
||||
#endif
|
||||
|
||||
// This code is extracted to a function just to ensure that all local variables get released at the end.
|
||||
private func callSuspendFunAsync(
|
||||
weakRefToObjectCapturedByCompletion: WeakRefHolder,
|
||||
continuationHolder: AnyContinuationHolder,
|
||||
completionHandler: @escaping (Any?, Error?) -> Void
|
||||
) throws {
|
||||
class C {}
|
||||
let capturedByCompletion = C()
|
||||
weakRefToObjectCapturedByCompletion.value = capturedByCompletion
|
||||
|
||||
CoroutinesKt.suspendFunAsync(result: nil, continuationHolder: continuationHolder) { _result, _error in
|
||||
try! assertSame(actual: capturedByCompletion, expected: weakRefToObjectCapturedByCompletion.value)
|
||||
completionHandler(_result, _error)
|
||||
}
|
||||
}
|
||||
|
||||
private func testSuspendFuncAsync(doThrow: Bool) throws {
|
||||
var completionCalled = 0
|
||||
var result: AnyObject? = nil
|
||||
var error: Error? = nil
|
||||
|
||||
let continuationHolder = AnyContinuationHolder()
|
||||
|
||||
let weakRefToObjectCapturedByCompletion = WeakRefHolder()
|
||||
try assertTrue(weakRefToObjectCapturedByCompletion.value === nil)
|
||||
try autoreleasepool {
|
||||
try callSuspendFunAsync(
|
||||
weakRefToObjectCapturedByCompletion: weakRefToObjectCapturedByCompletion,
|
||||
continuationHolder: continuationHolder
|
||||
) { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result as AnyObject?
|
||||
error = _error
|
||||
}
|
||||
}
|
||||
CoroutinesKt.gc()
|
||||
// This assert checks that suspendFunAsync retains the completion handler:
|
||||
try assertFalse(weakRefToObjectCapturedByCompletion.value === nil)
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 0)
|
||||
|
||||
if doThrow {
|
||||
let exception = CoroutineException()
|
||||
continuationHolder.resumeWithException(exception: exception)
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
|
||||
try assertNil(result)
|
||||
try assertSame(actual: error?.kotlinException as AnyObject?, expected: exception)
|
||||
} else {
|
||||
class C {}
|
||||
let expectedResult = C()
|
||||
continuationHolder.resume(value: expectedResult)
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
|
||||
try assertSame(actual: result, expected: expectedResult)
|
||||
try assertNil(error)
|
||||
}
|
||||
|
||||
#if !NOOP_GC
|
||||
CoroutinesKt.gc()
|
||||
// This assert checks that the completion handler gets properly released after all:
|
||||
try assertTrue(weakRefToObjectCapturedByCompletion.value === nil)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if NO_GENERICS
|
||||
typealias UnitContinuationHolder = ContinuationHolder
|
||||
#else
|
||||
typealias UnitContinuationHolder = ContinuationHolder<KotlinUnit>
|
||||
#endif
|
||||
|
||||
// This code is extracted to a function just to ensure that all local variables get released at the end.
|
||||
private func callUnitSuspendFunAsync(
|
||||
weakRefToObjectCapturedByCompletion: WeakRefHolder,
|
||||
continuationHolder: UnitContinuationHolder,
|
||||
completionHandler: @escaping (Error?) -> Void
|
||||
) throws {
|
||||
class C {}
|
||||
let capturedByCompletion = C()
|
||||
weakRefToObjectCapturedByCompletion.value = capturedByCompletion
|
||||
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
|
||||
CoroutinesKt.unitSuspendFunAsync(continuationHolder: continuationHolder) { _result, _error in
|
||||
try! assertSame(actual: capturedByCompletion, expected: weakRefToObjectCapturedByCompletion.value)
|
||||
completionHandler(_error)
|
||||
}
|
||||
#else
|
||||
CoroutinesKt.unitSuspendFunAsync(continuationHolder: continuationHolder) { _error in
|
||||
try! assertSame(actual: capturedByCompletion, expected: weakRefToObjectCapturedByCompletion.value)
|
||||
completionHandler(_error)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private func testUnitSuspendFuncAsync(doThrow: Bool) throws {
|
||||
var completionCalled = 0
|
||||
var error: Error? = nil
|
||||
|
||||
let continuationHolder = UnitContinuationHolder()
|
||||
|
||||
let weakRefToObjectCapturedByCompletion = WeakRefHolder()
|
||||
try assertTrue(weakRefToObjectCapturedByCompletion.value === nil)
|
||||
try autoreleasepool {
|
||||
try callUnitSuspendFunAsync(
|
||||
weakRefToObjectCapturedByCompletion: weakRefToObjectCapturedByCompletion,
|
||||
continuationHolder: continuationHolder
|
||||
) { _error in
|
||||
completionCalled += 1
|
||||
error = _error
|
||||
}
|
||||
}
|
||||
CoroutinesKt.gc()
|
||||
// This assert checks that unitSuspendFunAsync retains the completion handler:
|
||||
try assertFalse(weakRefToObjectCapturedByCompletion.value === nil)
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 0)
|
||||
|
||||
if doThrow {
|
||||
let exception = CoroutineException()
|
||||
continuationHolder.resumeWithException(exception: exception)
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
|
||||
try assertSame(actual: error?.kotlinException as AnyObject?, expected: exception)
|
||||
} else {
|
||||
continuationHolder.resume(value: KotlinUnit.shared)
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
|
||||
try assertNil(error)
|
||||
}
|
||||
|
||||
#if !NOOP_GC
|
||||
CoroutinesKt.gc()
|
||||
// This assert checks that the completion handler gets properly released after all:
|
||||
try assertTrue(weakRefToObjectCapturedByCompletion.value === nil)
|
||||
#endif
|
||||
}
|
||||
|
||||
private func testCall() throws {
|
||||
try testCallSuspendFun(doSuspend: true, doThrow: false)
|
||||
try testCallSuspendFun(doSuspend: false, doThrow: false)
|
||||
try testCallSuspendFun(doSuspend: true, doThrow: true)
|
||||
try testCallSuspendFun(doSuspend: false, doThrow: true)
|
||||
|
||||
try testCallUnitSuspendFun(doSuspend: true, doThrow: false)
|
||||
try testCallUnitSuspendFun(doSuspend: false, doThrow: false)
|
||||
try testCallUnitSuspendFun(doSuspend: true, doThrow: true)
|
||||
try testCallUnitSuspendFun(doSuspend: false, doThrow: true)
|
||||
|
||||
try testSuspendFuncAsync(doThrow: false)
|
||||
try testSuspendFuncAsync(doThrow: true)
|
||||
|
||||
try testUnitSuspendFuncAsync(doThrow: false)
|
||||
try testUnitSuspendFuncAsync(doThrow: true)
|
||||
}
|
||||
|
||||
private func testCallSuspendFunChain(doSuspend: Bool, doThrow: Bool) throws {
|
||||
class C {}
|
||||
let expectedResult = C()
|
||||
|
||||
var completionCalled = 0
|
||||
var result: AnyObject? = nil
|
||||
var error: Error? = nil
|
||||
|
||||
CoroutinesKt.suspendFun(result: expectedResult, doSuspend: doSuspend, doThrow: doThrow) { _resultOuter, _errorOuter in
|
||||
CoroutinesKt.suspendFun(result: expectedResult, doSuspend: doSuspend, doThrow: doThrow) { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result as AnyObject?
|
||||
error = _error
|
||||
}
|
||||
}
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
|
||||
if doThrow {
|
||||
try assertNil(result)
|
||||
try assertTrue(error?.kotlinException is CoroutineException)
|
||||
} else {
|
||||
try assertSame(actual: result, expected: expectedResult)
|
||||
try assertNil(error)
|
||||
}
|
||||
}
|
||||
|
||||
private func testCallChain() throws {
|
||||
try testCallSuspendFunChain(doSuspend: true, doThrow: false)
|
||||
try testCallSuspendFunChain(doSuspend: false, doThrow: false)
|
||||
try testCallSuspendFunChain(doSuspend: true, doThrow: true)
|
||||
try testCallSuspendFunChain(doSuspend: false, doThrow: true)
|
||||
}
|
||||
|
||||
private class SuspendFunImpl : SuspendFun {
|
||||
class E : Error {}
|
||||
|
||||
var completion: (() -> Void)? = nil
|
||||
|
||||
func suspendFun(doYield: Bool, doThrow: Bool, completionHandler: @escaping (KotlinInt?, Error?) -> Void) {
|
||||
func callCompletion() {
|
||||
if doThrow {
|
||||
completionHandler(nil, E())
|
||||
} else {
|
||||
completionHandler(17, nil)
|
||||
}
|
||||
}
|
||||
|
||||
if doYield {
|
||||
self.completion = callCompletion
|
||||
} else {
|
||||
callCompletion()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func testSuspendFunImpl(doYield: Bool, doThrow: Bool) throws {
|
||||
#if NO_GENERICS
|
||||
let resultHolder = ResultHolder()
|
||||
#else
|
||||
let resultHolder = ResultHolder<KotlinInt>()
|
||||
#endif
|
||||
|
||||
let impl = SuspendFunImpl()
|
||||
|
||||
CoroutinesKt.callSuspendFun(
|
||||
suspendFun: impl,
|
||||
doYield: doYield,
|
||||
doThrow: doThrow,
|
||||
resultHolder: resultHolder
|
||||
)
|
||||
|
||||
if doYield {
|
||||
try assertEquals(actual: resultHolder.completed, expected: 0)
|
||||
guard let completion = impl.completion else { try fail() }
|
||||
completion()
|
||||
}
|
||||
|
||||
try assertEquals(actual: resultHolder.completed, expected: 1)
|
||||
|
||||
if doThrow {
|
||||
try assertNil(resultHolder.result)
|
||||
if let e = resultHolder.exception {
|
||||
try assertFailsWith(SuspendFunImpl.E.self) { try CoroutinesKt.throwException(exception: e) }
|
||||
} else {
|
||||
try fail()
|
||||
}
|
||||
} else {
|
||||
try assertEquals(actual: resultHolder.result as! Int, expected: 17)
|
||||
try assertNil(resultHolder.exception)
|
||||
}
|
||||
}
|
||||
|
||||
private func testSuspendFunImpl2(doYield: Bool, doThrow: Bool) throws {
|
||||
let impl = SuspendFunImpl()
|
||||
|
||||
var completionCalled = 0
|
||||
var result: KotlinInt? = nil
|
||||
var error: Error? = nil
|
||||
|
||||
CoroutinesKt.callSuspendFun2(suspendFun: impl, doYield: doYield, doThrow: doThrow) { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result
|
||||
error = _error
|
||||
}
|
||||
|
||||
if doYield {
|
||||
try assertEquals(actual: completionCalled, expected: 0)
|
||||
guard let completion = impl.completion else { try fail() }
|
||||
completion()
|
||||
}
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
|
||||
if doThrow {
|
||||
try assertNil(result)
|
||||
try assertTrue(error is SuspendFunImpl.E)
|
||||
} else {
|
||||
try assertEquals(actual: result, expected: 17)
|
||||
try assertNil(error)
|
||||
}
|
||||
}
|
||||
|
||||
private func testOverride() throws {
|
||||
try testSuspendFunImpl(doYield: false, doThrow: false)
|
||||
try testSuspendFunImpl(doYield: false, doThrow: true)
|
||||
try testSuspendFunImpl(doYield: true, doThrow: false)
|
||||
try testSuspendFunImpl(doYield: true, doThrow: true)
|
||||
|
||||
try testSuspendFunImpl2(doYield: false, doThrow: false)
|
||||
try testSuspendFunImpl2(doYield: false, doThrow: true)
|
||||
try testSuspendFunImpl2(doYield: true, doThrow: false)
|
||||
try testSuspendFunImpl2(doYield: true, doThrow: true)
|
||||
}
|
||||
|
||||
private class SwiftSuspendBridge : AbstractSuspendBridge {
|
||||
class E : Error {}
|
||||
|
||||
override func intAsAny(value: KotlinInt, completionHandler: @escaping (KotlinInt?, Error?) -> Void) {
|
||||
completionHandler(value, nil)
|
||||
}
|
||||
|
||||
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
|
||||
override func unit(value: KotlinInt, completionHandler: @escaping (KotlinUnit?, Error?) -> Void) {
|
||||
completionHandler(KotlinUnit(), nil)
|
||||
}
|
||||
#else
|
||||
override func unit(value: KotlinInt, completionHandler: @escaping (Error?) -> Void) {
|
||||
completionHandler(nil)
|
||||
}
|
||||
#endif
|
||||
|
||||
override func unitAsAny(value: KotlinInt, completionHandler: @escaping (KotlinUnit?, Error?) -> Void) {
|
||||
completionHandler(KotlinUnit(), nil)
|
||||
}
|
||||
|
||||
override func nullableUnit(value: KotlinInt, completionHandler: @escaping (KotlinUnit?, Error?) -> Void) {
|
||||
completionHandler(KotlinUnit(), nil)
|
||||
}
|
||||
|
||||
override func nothingAsInt(value: KotlinInt, completionHandler: @escaping (KotlinNothing?, Error?) -> Void) {
|
||||
completionHandler(nil, E())
|
||||
}
|
||||
|
||||
override func nothingAsAny(value: KotlinInt, completionHandler: @escaping (KotlinNothing?, Error?) -> Void) {
|
||||
completionHandler(nil, E())
|
||||
}
|
||||
|
||||
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
|
||||
override func nothingAsUnit(value: KotlinInt, completionHandler: @escaping (KotlinNothing?, Error?) -> Void) {
|
||||
completionHandler(nil, E())
|
||||
}
|
||||
#else
|
||||
override func nothingAsUnit(value: KotlinInt, completionHandler: @escaping (Error?) -> Void) {
|
||||
completionHandler(E())
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private func testBridges() throws {
|
||||
#if NO_GENERICS
|
||||
let resultHolder = ResultHolder()
|
||||
#else
|
||||
let resultHolder = ResultHolder<KotlinUnit>()
|
||||
#endif
|
||||
try CoroutinesKt.callSuspendBridge(bridge: SwiftSuspendBridge(), resultHolder: resultHolder)
|
||||
|
||||
try assertEquals(actual: resultHolder.completed, expected: 1)
|
||||
try assertNil(resultHolder.exception)
|
||||
try assertSame(actual: resultHolder.result as AnyObject, expected: KotlinUnit())
|
||||
}
|
||||
|
||||
private func testImplicitThrows1() throws {
|
||||
var error: Error? = nil
|
||||
var completionCalled = 0
|
||||
|
||||
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
|
||||
var result: KotlinUnit? = nil
|
||||
|
||||
CoroutinesKt.throwCancellationException { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result
|
||||
error = _error
|
||||
}
|
||||
|
||||
try assertNil(result)
|
||||
#else
|
||||
CoroutinesKt.throwCancellationException { _error in
|
||||
completionCalled += 1
|
||||
error = _error
|
||||
}
|
||||
#endif
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
try assertTrue(error?.kotlinException is KotlinCancellationException)
|
||||
}
|
||||
|
||||
private func testImplicitThrows2() throws {
|
||||
var error: Error? = nil
|
||||
var completionCalled = 0
|
||||
|
||||
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
|
||||
var result: KotlinUnit? = nil
|
||||
|
||||
ThrowCancellationExceptionImpl().throwCancellationException { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result
|
||||
error = _error
|
||||
}
|
||||
|
||||
try assertNil(result)
|
||||
#else
|
||||
ThrowCancellationExceptionImpl().throwCancellationException { _error in
|
||||
completionCalled += 1
|
||||
error = _error
|
||||
}
|
||||
#endif
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
try assertTrue(error?.kotlinException is KotlinCancellationException)
|
||||
}
|
||||
|
||||
private func testSuspendFunctionType0(f: KotlinSuspendFunction0, expectedResult: String) throws {
|
||||
try assertTrue((f as AnyObject) is KotlinSuspendFunction0)
|
||||
|
||||
var result: String? = nil
|
||||
var error: Error? = nil
|
||||
var completionCalled = 0
|
||||
|
||||
f.invoke { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result as? String
|
||||
error = _error
|
||||
}
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
try assertEquals(actual: result, expected: expectedResult)
|
||||
try assertNil(error)
|
||||
}
|
||||
|
||||
private func testSuspendFunctionType1(f: KotlinSuspendFunction1) throws {
|
||||
try assertTrue((f as AnyObject) is KotlinSuspendFunction1)
|
||||
|
||||
var result: String? = nil
|
||||
var error: Error? = nil
|
||||
var completionCalled = 0
|
||||
|
||||
f.invoke(p1: "suspend function type") { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result as? String
|
||||
error = _error
|
||||
}
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
try assertEquals(actual: result, expected: "suspend function type 1")
|
||||
try assertNil(error)
|
||||
}
|
||||
|
||||
private func testSuspendFunctionType() throws {
|
||||
try testSuspendFunctionType0(f: CoroutinesKt.getSuspendLambda0(), expectedResult: "lambda 0")
|
||||
try testSuspendFunctionType0(f: CoroutinesKt.getSuspendCallableReference0(), expectedResult: "callable reference 0")
|
||||
try testSuspendFunctionType0(f: CoroutinesKt.getSuspendChild0(), expectedResult: "child 0")
|
||||
try testSuspendFunctionType1(f: CoroutinesKt.getSuspendLambda1())
|
||||
try testSuspendFunctionType1(f: CoroutinesKt.getSuspendCallableReference1())
|
||||
try testSuspendFunctionType1(f: CoroutinesKt.getSuspendChild1())
|
||||
}
|
||||
|
||||
private func testKSuspendFunctionType0(f: KotlinKSuspendFunction0, expectedResult: String) throws {
|
||||
try assertTrue((f as AnyObject) is KotlinKSuspendFunction0)
|
||||
|
||||
var result: String? = nil
|
||||
var error: Error? = nil
|
||||
var completionCalled = 0
|
||||
|
||||
f.invoke { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result as? String
|
||||
error = _error
|
||||
}
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
try assertEquals(actual: result, expected: expectedResult)
|
||||
try assertNil(error)
|
||||
}
|
||||
|
||||
private func testKSuspendFunctionType1(f: KotlinKSuspendFunction1) throws {
|
||||
try assertTrue((f as AnyObject) is KotlinKSuspendFunction1)
|
||||
|
||||
var result: String? = nil
|
||||
var error: Error? = nil
|
||||
var completionCalled = 0
|
||||
|
||||
f.invoke(p1: "suspend function type") { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result as? String
|
||||
error = _error
|
||||
}
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
try assertEquals(actual: result, expected: "suspend function type 1")
|
||||
try assertNil(error)
|
||||
}
|
||||
|
||||
private func testKSuspendFunctionType() throws {
|
||||
try testKSuspendFunctionType0(f: CoroutinesKt.getKSuspendCallableReference0(), expectedResult: "callable reference 0")
|
||||
try testKSuspendFunctionType1(f: CoroutinesKt.getKSuspendCallableReference1())
|
||||
}
|
||||
|
||||
private func testSuspendFunctionSwiftImpl() throws {
|
||||
var result: String? = nil
|
||||
var error: Error? = nil
|
||||
var completionCalled = 0
|
||||
|
||||
CoroutinesKt.invoke1(block: SuspendFunction1SwiftImpl(), argument: "suspend function") { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result as? String
|
||||
error = _error
|
||||
}
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
try assertEquals(actual: result, expected: "suspend function Swift")
|
||||
try assertNil(error)
|
||||
}
|
||||
|
||||
#if NO_GENERICS
|
||||
typealias AnyResultHolder = ResultHolder
|
||||
#else
|
||||
typealias AnyResultHolder = ResultHolder<AnyObject>
|
||||
#endif
|
||||
|
||||
private extension AnyResultHolder {
|
||||
func getSuccessfulResult() throws -> Any? {
|
||||
try assertEquals(actual: completed, expected: 1)
|
||||
try assertNil(exception)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
// Reported in https://youtrack.jetbrains.com/issue/KT-51043
|
||||
private func testSuspendFunction0SwiftImplStartInKotlin() throws {
|
||||
let resultHolder = AnyResultHolder()
|
||||
try CoroutinesKt.startCoroutineUninterceptedOrReturn(fn: SuspendFunction0SwiftImpl(), resultHolder: resultHolder)
|
||||
try assertEquals(actual: resultHolder.getSuccessfulResult() as? String, expected: "Swift")
|
||||
}
|
||||
|
||||
private func testSuspendFunction1SwiftImplStartInKotlin() throws {
|
||||
let resultHolder = AnyResultHolder()
|
||||
try CoroutinesKt.startCoroutineUninterceptedOrReturn(fn: SuspendFunction1SwiftImpl(), receiver: "receiver", resultHolder: resultHolder)
|
||||
try assertEquals(actual: resultHolder.getSuccessfulResult() as? String, expected: "receiver Swift")
|
||||
}
|
||||
|
||||
private func testSuspendFunction2SwiftImplStartInKotlin() throws {
|
||||
let resultHolder = AnyResultHolder()
|
||||
try CoroutinesKt.startCoroutineUninterceptedOrReturn(fn: SuspendFunction2SwiftImpl(), receiver: "receiver", param: "param", resultHolder: resultHolder)
|
||||
try assertEquals(actual: resultHolder.getSuccessfulResult() as? String, expected: "receiver param Swift")
|
||||
}
|
||||
|
||||
private func testSuspendFunction0SwiftImplCreateInKotlin() throws {
|
||||
let resultHolder = AnyResultHolder()
|
||||
try CoroutinesKt.createCoroutineUninterceptedAndResume(fn: SuspendFunction0SwiftImpl(), resultHolder: resultHolder)
|
||||
try assertEquals(actual: resultHolder.getSuccessfulResult() as? String, expected: "Swift")
|
||||
}
|
||||
|
||||
private func testSuspendFunction1SwiftImplCreateInKotlin() throws {
|
||||
let resultHolder = AnyResultHolder()
|
||||
try CoroutinesKt.createCoroutineUninterceptedAndResume(fn: SuspendFunction1SwiftImpl(), receiver: "receiver", resultHolder: resultHolder)
|
||||
try assertEquals(actual: resultHolder.getSuccessfulResult() as? String, expected: "receiver Swift")
|
||||
}
|
||||
|
||||
private class SuspendFunction0SwiftImpl : KotlinSuspendFunction0 {
|
||||
func invoke(completionHandler: (Any?, Error?) -> Void) {
|
||||
completionHandler("Swift", nil)
|
||||
}
|
||||
}
|
||||
|
||||
private class SuspendFunction1SwiftImpl : KotlinSuspendFunction1 {
|
||||
func invoke(p1: Any?, completionHandler: (Any?, Error?) -> Void) {
|
||||
completionHandler("\(p1 ?? "nil") Swift", nil)
|
||||
}
|
||||
}
|
||||
|
||||
private class SuspendFunction2SwiftImpl : KotlinSuspendFunction2 {
|
||||
func invoke(p1: Any?, p2: Any?, completionHandler: (Any?, Error?) -> Void) {
|
||||
completionHandler("\(p1 ?? "nil") \(p2 ?? "nil") Swift", nil)
|
||||
}
|
||||
}
|
||||
|
||||
class CoroutinesTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("TestCallSimple", testCallSimple)
|
||||
test("TestCallUnitSimple", testUnitCallSimple)
|
||||
test("TestCallFromNonMainDispatcher", testUnitCallNonMainDispatcher)
|
||||
test("TestCall", testCall)
|
||||
test("TestCallChain", testCallChain)
|
||||
test("TestOverride", testOverride)
|
||||
test("TestBridges", testBridges)
|
||||
test("TestImplicitThrows1", testImplicitThrows1)
|
||||
test("TestImplicitThrows2", testImplicitThrows2)
|
||||
test("TestSuspendFunctionType", testSuspendFunctionType)
|
||||
test("TestKSuspendFunctionType", testSuspendFunctionType)
|
||||
test("TestSuspendFunctionSwiftImpl", testSuspendFunctionSwiftImpl)
|
||||
test("TestSuspendFunction0SwiftImplStartInKotlin", testSuspendFunction0SwiftImplStartInKotlin)
|
||||
test("TestSuspendFunction1SwiftImplStartInKotlin", testSuspendFunction1SwiftImplStartInKotlin)
|
||||
test("TestSuspendFunction2SwiftImplStartInKotlin", testSuspendFunction2SwiftImplStartInKotlin)
|
||||
test("TestSuspendFunction0SwiftImplCreateInKotlin", testSuspendFunction0SwiftImplCreateInKotlin)
|
||||
test("TestSuspendFunction1SwiftImplCreateInKotlin", testSuspendFunction1SwiftImplCreateInKotlin)
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package dataClassComponentMethods
|
||||
|
||||
data class DataClassWithExplicitComponentMethod(val x: Int, val y: Int) {
|
||||
fun component1(arg: Int): Int {
|
||||
return arg + x
|
||||
}
|
||||
}
|
||||
|
||||
interface ComponentInterface {
|
||||
fun component1(): Int
|
||||
}
|
||||
|
||||
data class DataClassWithInheritedComponentMethod(val x: Int) : ComponentInterface
|
||||
|
||||
class RegularClassWithComponentMethods {
|
||||
fun component1() = 3
|
||||
fun component3() = 4
|
||||
}
|
||||
|
||||
fun component1() = 5
|
||||
fun component4() = 6
|
||||
|
||||
data class DataClassWithStrangeNames(val component124: Int, val componentABC: Int) {
|
||||
operator fun component15() = component124
|
||||
fun component16() = component124
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
private func testCustomComponentMethodsAreAccessible() throws {
|
||||
let d = DataClassWithExplicitComponentMethod(x: 1, y: 2)
|
||||
try assertEquals(actual: d.component1(arg: 3), expected: 4)
|
||||
}
|
||||
|
||||
private func testDataClassWithInheritedComponentAreAccessible() throws {
|
||||
let d = DataClassWithInheritedComponentMethod(x: 1)
|
||||
try assertEquals(actual: d.component1(), expected: 1)
|
||||
}
|
||||
|
||||
// Absence of deprecation attributes is checked by comparing "lazy header".
|
||||
private func testRegularComponentMethodsAreAccessible() throws {
|
||||
let r = RegularClassWithComponentMethods()
|
||||
try assertEquals(actual: r.component1(), expected: 3)
|
||||
try assertEquals(actual: r.component3(), expected: 4)
|
||||
}
|
||||
|
||||
private func testTopLevelComponentMethodsAreAccessible() throws {
|
||||
try assertEquals(actual: DataClassComponentMethodsKt.component1(), expected: 5)
|
||||
try assertEquals(actual: DataClassComponentMethodsKt.component4(), expected: 6)
|
||||
}
|
||||
|
||||
private func testComponentExportedOrNot() throws {
|
||||
try assertFalse(class_respondsToSelector(object_getClass(DataClassWithStrangeNames.self), NSSelectorFromString("component1")));
|
||||
try assertFalse(class_respondsToSelector(object_getClass(DataClassWithStrangeNames.self), NSSelectorFromString("component2")));
|
||||
try assertFalse(class_respondsToSelector(object_getClass(DataClassWithStrangeNames.self), NSSelectorFromString("component15")));
|
||||
let r = DataClassWithStrangeNames(component124: 1, componentABC:2)
|
||||
try assertEquals(actual: r.component124, expected: 1)
|
||||
try assertEquals(actual: r.componentABC, expected: 2)
|
||||
try assertEquals(actual: r.component16(), expected: 1)
|
||||
}
|
||||
|
||||
class DataClassComponentMethodsTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
test("testDataClassWithInheritedComponentAreAccessible", testDataClassWithInheritedComponentAreAccessible)
|
||||
test("testCustomComponentMethodsAreAccessible", testCustomComponentMethodsAreAccessible)
|
||||
test("testRegularComponentMethodsAreAccessible", testRegularComponentMethodsAreAccessible)
|
||||
test("testTopLevelComponentMethodsAreAccessible", testTopLevelComponentMethodsAreAccessible)
|
||||
test("testComponentExportedOrNot", testComponentExportedOrNot)
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
package deallocretain
|
||||
|
||||
open class DeallocRetainBase
|
||||
|
||||
@OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
|
||||
fun garbageCollect() = kotlin.native.runtime.GC.collect()
|
||||
|
||||
fun createWeakReference(value: Any) = kotlin.native.ref.WeakReference(value)
|
||||
|
||||
fun assertNull(value: Any?) {
|
||||
kotlin.test.assertNull(value)
|
||||
}
|
||||
|
||||
@OptIn(kotlin.ExperimentalStdlibApi::class)
|
||||
fun isExperimentalMM() = kotlin.native.isExperimentalMM()
|
||||
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
// Note: these tests rely on GC assertions: without the fix and the assertions it won't actually crash.
|
||||
// GC should fire an assertion if it obtains a reference to Kotlin object that is being (or has been) deallocated.
|
||||
|
||||
private func test1() throws {
|
||||
// Attempt to make the state predictable:
|
||||
DeallocRetainKt.garbageCollect()
|
||||
|
||||
DeallocRetain.deallocated = false
|
||||
try assertFalse(DeallocRetain.deallocated)
|
||||
|
||||
try autoreleasepool {
|
||||
let obj = DeallocRetain()
|
||||
try obj.checkWeak()
|
||||
}
|
||||
|
||||
// Runs DeallocRetain.deinit:
|
||||
DeallocRetainKt.garbageCollect()
|
||||
|
||||
try assertTrue(DeallocRetain.deallocated)
|
||||
|
||||
// Might crash due to double-dispose if the dealloc applied addRef/releaseRef to reclaimed Kotlin object:
|
||||
DeallocRetainKt.garbageCollect()
|
||||
}
|
||||
|
||||
private class DeallocRetain : DeallocRetainBase {
|
||||
static var deallocated = false
|
||||
static var retainObject: DeallocRetain? = nil
|
||||
static weak var weakObject: DeallocRetain? = nil
|
||||
#if NO_GENERICS
|
||||
static var kotlinWeakRef: KotlinWeakReference? = nil
|
||||
#else
|
||||
static var kotlinWeakRef: KotlinWeakReference<AnyObject>? = nil
|
||||
#endif
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
DeallocRetain.weakObject = self
|
||||
DeallocRetain.kotlinWeakRef = DeallocRetainKt.createWeakReference(value: self)
|
||||
}
|
||||
|
||||
func checkWeak() throws {
|
||||
try assertSame(actual: DeallocRetain.weakObject, expected: self)
|
||||
try assertSame(actual: DeallocRetain.kotlinWeakRef!.value as AnyObject, expected: self)
|
||||
}
|
||||
|
||||
deinit {
|
||||
DeallocRetain.retainObject = self
|
||||
DeallocRetain.retainObject = nil
|
||||
|
||||
try! assertNil(DeallocRetain.weakObject)
|
||||
try! assertNil(DeallocRetain.kotlinWeakRef!.value)
|
||||
|
||||
try! assertFalse(DeallocRetain.deallocated)
|
||||
DeallocRetain.deallocated = true
|
||||
}
|
||||
}
|
||||
|
||||
private class DeallocRetainAndAccess : DeallocRetainBase {
|
||||
static var deallocated = false
|
||||
static var retainObject: DeallocRetainAndAccess? = nil
|
||||
|
||||
deinit {
|
||||
DeallocRetainAndAccess.retainObject = self
|
||||
DeallocRetainKt.assertNull(value: DeallocRetainAndAccess.retainObject)
|
||||
DeallocRetainAndAccess.retainObject = nil
|
||||
|
||||
try! assertFalse(DeallocRetainAndAccess.deallocated)
|
||||
DeallocRetainAndAccess.deallocated = true
|
||||
}
|
||||
}
|
||||
|
||||
private func test2() throws {
|
||||
// Attempt to make the state predictable:
|
||||
DeallocRetainKt.garbageCollect()
|
||||
|
||||
DeallocRetainAndAccess.deallocated = false
|
||||
|
||||
autoreleasepool {
|
||||
DeallocRetainAndAccess()
|
||||
}
|
||||
|
||||
// Runs DeallocRetainAndAccess.deinit:
|
||||
DeallocRetainKt.garbageCollect()
|
||||
|
||||
try assertTrue(DeallocRetain.deallocated)
|
||||
|
||||
// Might crash due to double-dispose if the dealloc applied addRef/releaseRef to reclaimed Kotlin object:
|
||||
DeallocRetainKt.garbageCollect()
|
||||
}
|
||||
|
||||
class DeallocRetainTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
#if !NOOP_GC
|
||||
test("Test1", test1)
|
||||
if (DeallocRetainKt.isExperimentalMM()) {
|
||||
test("Test2", test2)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package enumValues
|
||||
|
||||
import noEnumEntries.*
|
||||
|
||||
enum class EnumLeftRightUpDown {
|
||||
LEFT, RIGHT, UP, DOWN
|
||||
}
|
||||
|
||||
enum class EnumOneTwoThreeValues {
|
||||
ONE, TWO, THREE, VALUES, ENTRIES
|
||||
}
|
||||
|
||||
enum class EnumValuesValues_ {
|
||||
VALUES, VALUES_, ENTRIES, ENTRIES_
|
||||
}
|
||||
|
||||
enum class EmptyEnum {
|
||||
}
|
||||
|
||||
|
||||
fun dceAvoidance() : NoEnumEntriesEnum {
|
||||
return NoEnumEntriesEnum.ONE
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
import Kt
|
||||
|
||||
private func testEnumValues() throws {
|
||||
let values = EnumLeftRightUpDown.values()
|
||||
|
||||
try assertEquals(actual: values.size, expected: 4)
|
||||
|
||||
try assertSame(actual: values.get(index: 0) as AnyObject, expected: EnumLeftRightUpDown.left)
|
||||
try assertSame(actual: values.get(index: 1) as AnyObject, expected: EnumLeftRightUpDown.right)
|
||||
try assertSame(actual: values.get(index: 2) as AnyObject, expected: EnumLeftRightUpDown.up)
|
||||
try assertSame(actual: values.get(index: 3) as AnyObject, expected: EnumLeftRightUpDown.down)
|
||||
}
|
||||
|
||||
private func testEnumValuesMangled() throws {
|
||||
let values = EnumOneTwoThreeValues.values_()
|
||||
|
||||
try assertEquals(actual: values.size, expected: 5)
|
||||
|
||||
try assertSame(actual: values.get(index: 0) as AnyObject, expected: EnumOneTwoThreeValues.one)
|
||||
try assertSame(actual: values.get(index: 1) as AnyObject, expected: EnumOneTwoThreeValues.two)
|
||||
try assertSame(actual: values.get(index: 2) as AnyObject, expected: EnumOneTwoThreeValues.three)
|
||||
try assertSame(actual: values.get(index: 3) as AnyObject, expected: EnumOneTwoThreeValues.values)
|
||||
try assertSame(actual: values.get(index: 4) as AnyObject, expected: EnumOneTwoThreeValues.entries)
|
||||
}
|
||||
|
||||
private func testEnumValuesMangledTwice() throws {
|
||||
let values = EnumValuesValues_.values__()
|
||||
|
||||
try assertEquals(actual: values.size, expected: 4)
|
||||
|
||||
try assertSame(actual: values.get(index: 0) as AnyObject, expected: EnumValuesValues_.values)
|
||||
try assertSame(actual: values.get(index: 1) as AnyObject, expected: EnumValuesValues_.values_)
|
||||
try assertSame(actual: values.get(index: 2) as AnyObject, expected: EnumValuesValues_.entries)
|
||||
try assertSame(actual: values.get(index: 3) as AnyObject, expected: EnumValuesValues_.entries_)
|
||||
}
|
||||
|
||||
private func testEnumValuesEmpty() throws {
|
||||
try assertEquals(actual: EmptyEnum.values().size, expected: 0)
|
||||
}
|
||||
|
||||
extension NSObject {
|
||||
|
||||
// convert to dictionary
|
||||
static func toDictionary(from classType: AnyClass) -> [String: Any] {
|
||||
|
||||
var propertiesCount : CUnsignedInt = 0
|
||||
let propertiesInAClass = class_copyMethodList(classType, &propertiesCount)
|
||||
var propertiesDictionary = [String:Any]()
|
||||
|
||||
for i in 0 ..< Int(propertiesCount) {
|
||||
if let property = propertiesInAClass?[i],
|
||||
let strKey = NSString(utf8String: sel_getName(method_getName(property))) as String? {
|
||||
propertiesDictionary[strKey] = value(forKey: strKey)
|
||||
}
|
||||
}
|
||||
return propertiesDictionary
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func testNoEnumEntries() throws {
|
||||
try assertTrue(class_respondsToSelector(object_getClass(EnumLeftRightUpDown.self), NSSelectorFromString("entries")));
|
||||
try assertFalse(class_respondsToSelector(object_getClass(NoEnumEntriesEnum.self), NSSelectorFromString("entries")));
|
||||
}
|
||||
|
||||
private func testEnumEntries() throws {
|
||||
let entries = EnumLeftRightUpDown.entries
|
||||
|
||||
try assertEquals(actual: entries.count, expected: 4)
|
||||
|
||||
try assertSame(actual: entries[0] as AnyObject, expected: EnumLeftRightUpDown.left)
|
||||
try assertSame(actual: entries[1] as AnyObject, expected: EnumLeftRightUpDown.right)
|
||||
try assertSame(actual: entries[2] as AnyObject, expected: EnumLeftRightUpDown.up)
|
||||
try assertSame(actual: entries[3] as AnyObject, expected: EnumLeftRightUpDown.down)
|
||||
}
|
||||
|
||||
private func testEnumEntriesMangled() throws {
|
||||
let entries = EnumOneTwoThreeValues.entries_
|
||||
|
||||
try assertEquals(actual: entries.count, expected: 5)
|
||||
|
||||
try assertSame(actual: entries[0] as AnyObject, expected: EnumOneTwoThreeValues.one)
|
||||
try assertSame(actual: entries[1] as AnyObject, expected: EnumOneTwoThreeValues.two)
|
||||
try assertSame(actual: entries[2] as AnyObject, expected: EnumOneTwoThreeValues.three)
|
||||
try assertSame(actual: entries[3] as AnyObject, expected: EnumOneTwoThreeValues.values)
|
||||
try assertSame(actual: entries[4] as AnyObject, expected: EnumOneTwoThreeValues.entries)
|
||||
}
|
||||
|
||||
private func testEnumEntriesMangledTwice() throws {
|
||||
let entries = EnumValuesValues_.entries__
|
||||
|
||||
try assertEquals(actual: entries.count, expected: 4)
|
||||
|
||||
try assertSame(actual: entries[0] as AnyObject, expected: EnumValuesValues_.values)
|
||||
try assertSame(actual: entries[1] as AnyObject, expected: EnumValuesValues_.values_)
|
||||
try assertSame(actual: entries[2] as AnyObject, expected: EnumValuesValues_.entries)
|
||||
try assertSame(actual: entries[3] as AnyObject, expected: EnumValuesValues_.entries_)
|
||||
}
|
||||
|
||||
private func testEnumEntriesEmpty() throws {
|
||||
try assertEquals(actual: EmptyEnum.entries.count, expected: 0)
|
||||
}
|
||||
|
||||
class EnumValuesTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("TestEnumValues", testEnumValues)
|
||||
test("TestEnumValuesMangled", testEnumValuesMangled)
|
||||
test("TestEnumValuesMangledTwice", testEnumValuesMangledTwice)
|
||||
test("TestEnumValuesEmpty", testEnumValuesEmpty)
|
||||
test("TestNoEnumEntries", testNoEnumEntries)
|
||||
test("TestEnumEntries", testEnumEntries)
|
||||
test("TestEnumEntriesMangled", testEnumEntriesMangled)
|
||||
test("TestEnumEntriesMangledTwice", testEnumEntriesMangledTwice)
|
||||
test("TestEnumEntriesEmpty", testEnumEntriesEmpty)
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,15 +0,0 @@
|
||||
package funinterfaces
|
||||
|
||||
fun interface FunInterface {
|
||||
fun run(): Int
|
||||
}
|
||||
|
||||
fun getObject(): FunInterface {
|
||||
return object : FunInterface {
|
||||
override fun run() = 1
|
||||
}
|
||||
}
|
||||
|
||||
fun getLambda(): FunInterface {
|
||||
return FunInterface { 2 }
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import Kt
|
||||
|
||||
// Based on https://youtrack.jetbrains.com/issue/KT-44799.
|
||||
private func testSAMConversion() throws {
|
||||
try assertEquals(actual: FunInterfacesKt.getObject().run(), expected: 1)
|
||||
try assertEquals(actual: FunInterfacesKt.getLambda().run(), expected: 2)
|
||||
}
|
||||
|
||||
class FunInterfacesTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("TestSAMConversion", testSAMConversion)
|
||||
}
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
package functionalTypes
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
typealias AN = Any?
|
||||
|
||||
typealias F2 = (AN, AN) -> AN
|
||||
typealias F5 = (AN, AN, AN, AN, AN) -> AN
|
||||
typealias F6 = (AN, AN, AN, AN, AN, AN,) -> AN
|
||||
typealias F32 = (AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN,
|
||||
AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN,
|
||||
AN, AN, AN, AN, AN, AN, AN, AN) -> AN
|
||||
typealias F33 = (AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN,
|
||||
AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN,
|
||||
AN, AN, AN, AN, AN, AN, AN, AN, AN) -> AN
|
||||
|
||||
fun callDynType2(list: List<F2>, param: AN) {
|
||||
val fct = list.first()
|
||||
val ret = fct(param, null)
|
||||
assertEquals(param, ret)
|
||||
}
|
||||
|
||||
fun callStaticType2(fct: F2, param: AN) {
|
||||
val ret = fct(param, null)
|
||||
assertEquals(param, ret)
|
||||
}
|
||||
|
||||
fun callDynType32(list: List<F32>, param: AN) {
|
||||
val fct = list.first()
|
||||
val ret = fct(param
|
||||
, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null
|
||||
)
|
||||
assertEquals(param, ret)
|
||||
}
|
||||
|
||||
fun callStaticType32(fct: F32, param: AN) {
|
||||
val ret = fct(param
|
||||
, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null
|
||||
)
|
||||
assertEquals(param, ret)
|
||||
}
|
||||
|
||||
fun callDynType33(list: List<F33>, param: AN) {
|
||||
val fct = list.first()
|
||||
val ret = fct(param
|
||||
, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null, null
|
||||
)
|
||||
assertEquals(param, ret)
|
||||
}
|
||||
|
||||
fun callStaticType33(fct: F33, param: AN) {
|
||||
val ret = fct(param
|
||||
, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null, null
|
||||
)
|
||||
assertEquals(param, ret)
|
||||
}
|
||||
|
||||
abstract class FHolder {
|
||||
abstract val value: Any?
|
||||
}
|
||||
|
||||
// Note: can't provoke dynamic function type conversion using list (as above) or generics
|
||||
// due to Swift <-> Obj-C interop bugs/limitations.
|
||||
// Use covariant return type instead:
|
||||
class F2Holder(override val value: F2) : FHolder()
|
||||
|
||||
fun getDynTypeLambda2(): F2Holder = F2Holder({ p1, _ -> p1 })
|
||||
fun getStaticLambda2(): F2 = { p1, _ -> p1 }
|
||||
|
||||
private fun f2(p1: AN, p2: AN): AN = p1
|
||||
|
||||
fun getDynTypeRef2(): F2Holder = F2Holder(::f2)
|
||||
fun getStaticRef2(): F2 = ::f2
|
||||
|
||||
private fun f32(
|
||||
p1: AN, p2: AN, p3: AN, p4: AN, p5: AN, p6: AN, p7: AN, p8: AN,
|
||||
p9: AN, p10: AN, p11: AN, p12: AN, p13: AN, p14: AN, p15: AN, p16: AN,
|
||||
p17: AN, p18: AN, p19: AN, p20: AN, p21: AN, p22: AN, p23: AN, p24: AN,
|
||||
p25: AN, p26: AN, p27: AN, p28: AN, p29: AN, p30: AN, p31: AN, p32: AN
|
||||
): AN = p1
|
||||
|
||||
private fun f33(
|
||||
p1: AN, p2: AN, p3: AN, p4: AN, p5: AN, p6: AN, p7: AN, p8: AN,
|
||||
p9: AN, p10: AN, p11: AN, p12: AN, p13: AN, p14: AN, p15: AN, p16: AN,
|
||||
p17: AN, p18: AN, p19: AN, p20: AN, p21: AN, p22: AN, p23: AN, p24: AN,
|
||||
p25: AN, p26: AN, p27: AN, p28: AN, p29: AN, p30: AN, p31: AN, p32: AN,
|
||||
p33: AN
|
||||
): AN = p1
|
||||
|
||||
class F32Holder(override val value: F32) : FHolder()
|
||||
|
||||
fun getDynType32(): F32Holder = F32Holder(::f32)
|
||||
fun getStaticType32(): F32 = ::f32
|
||||
|
||||
class F33Holder(override val value: F33) : FHolder()
|
||||
|
||||
fun getDynTypeRef33(): F33Holder = F33Holder(::f33)
|
||||
fun getStaticTypeRef33(): F33 = ::f33
|
||||
|
||||
fun getDynTypeLambda33(): F33Holder = F33Holder(getStaticTypeLambda33())
|
||||
fun getStaticTypeLambda33(): F33 = {
|
||||
p,
|
||||
_, _, _, _, _, _, _, _,
|
||||
_, _, _, _, _, _, _, _,
|
||||
_, _, _, _, _, _, _, _,
|
||||
_, _, _, _, _, _, _, _
|
||||
->
|
||||
p
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
private func test1() {
|
||||
FunctionalTypesKt.callStaticType2(fct: foo2, param: "from swift")
|
||||
FunctionalTypesKt.callDynType2(list: [ foo2 ], param: "from swift")
|
||||
|
||||
FunctionalTypesKt.callStaticType2(fct : {a1, _ in return a1 }, param: "from swift block")
|
||||
FunctionalTypesKt.callDynType2(list: [ {a1, _ in return a1 } ], param: "from swift block")
|
||||
|
||||
// 32 params is mapped as regular; block is OK
|
||||
FunctionalTypesKt.callStaticType32(fct : {
|
||||
a1, _, _, _, _, _, _, _,
|
||||
_, _, _, _, _, _, _, _,
|
||||
_, _, _, _, _, _, _, _,
|
||||
_, _, _, _, _, _, _, _
|
||||
in return a1 }, param: "from swift block")
|
||||
|
||||
FunctionalTypesKt.callDynType32(list : [{
|
||||
a1, _, _, _, _, _, _, _,
|
||||
_, _, _, _, _, _, _, _,
|
||||
_, _, _, _, _, _, _, _,
|
||||
_, _, _, _, _, _, _, _
|
||||
in return a1 }], param: "from swift block")
|
||||
|
||||
// 33 params requires explicit implementation of KotlinFunction33
|
||||
FunctionalTypesKt.callStaticType33(fct: foo33, param: "from swift")
|
||||
FunctionalTypesKt.callDynType33(list: [ Foo33() ], param: "from swift")
|
||||
}
|
||||
|
||||
private func test2() throws {
|
||||
try assertEquals(actual: FunctionalTypesKt.getDynTypeLambda2().value("one", nil) as? String, expected: "one")
|
||||
try assertEquals(actual: FunctionalTypesKt.getStaticLambda2()("two", nil) as? String, expected: "two")
|
||||
|
||||
try assertEquals(actual: FunctionalTypesKt.getDynTypeRef2().value("three", nil) as? String, expected: "three")
|
||||
try assertEquals(actual: FunctionalTypesKt.getStaticRef2()("four", nil) as? String, expected: "four")
|
||||
|
||||
// 32 params is mapped as regular; calling result as block is OK
|
||||
try assertEquals(
|
||||
actual: FunctionalTypesKt.getDynType32().value(
|
||||
"five",
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil
|
||||
) as? String,
|
||||
expected: "five"
|
||||
)
|
||||
|
||||
try assertEquals(
|
||||
actual: FunctionalTypesKt.getStaticType32()(
|
||||
"six",
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil
|
||||
) as? String,
|
||||
expected: "six"
|
||||
)
|
||||
|
||||
// 33 params requires explicit invocation of KotlinFunction33.invoke
|
||||
try assertEquals(
|
||||
actual: FunctionalTypesKt.getDynTypeRef33().value.invoke(
|
||||
p1: "seven",
|
||||
p2: nil, p3: nil, p4: nil, p5: nil, p6: nil, p7: nil, p8: nil, p9: nil,
|
||||
p10: nil, p11: nil, p12: nil, p13: nil, p14: nil, p15: nil, p16: nil, p17: nil,
|
||||
p18: nil, p19: nil, p20: nil, p21: nil, p22: nil, p23: nil, p24: nil, p25: nil,
|
||||
p26: nil, p27: nil, p28: nil, p29: nil, p30: nil, p31: nil, p32: nil, p33: nil
|
||||
) as? String,
|
||||
expected: "seven"
|
||||
)
|
||||
|
||||
// static conversion is ok though.
|
||||
try assertEquals(
|
||||
actual: FunctionalTypesKt.getStaticTypeRef33()(
|
||||
"eight",
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil
|
||||
) as? String,
|
||||
expected: "eight"
|
||||
)
|
||||
|
||||
try assertEquals(
|
||||
actual: FunctionalTypesKt.getDynTypeLambda33().value.invoke(
|
||||
p1: "nine",
|
||||
p2: nil, p3: nil, p4: nil, p5: nil, p6: nil, p7: nil, p8: nil, p9: nil,
|
||||
p10: nil, p11: nil, p12: nil, p13: nil, p14: nil, p15: nil, p16: nil, p17: nil,
|
||||
p18: nil, p19: nil, p20: nil, p21: nil, p22: nil, p23: nil, p24: nil, p25: nil,
|
||||
p26: nil, p27: nil, p28: nil, p29: nil, p30: nil, p31: nil, p32: nil, p33: nil
|
||||
) as? String,
|
||||
expected: "nine"
|
||||
)
|
||||
|
||||
try assertEquals(
|
||||
actual: FunctionalTypesKt.getStaticTypeLambda33()(
|
||||
"ten",
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil
|
||||
) as? String,
|
||||
expected: "ten"
|
||||
)
|
||||
}
|
||||
|
||||
class FunctionalTypesTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("Test1", test1)
|
||||
test("Test2", test2)
|
||||
}
|
||||
}
|
||||
|
||||
private func foo2(a1: Any?, _: Any?) -> Any? {
|
||||
return a1
|
||||
}
|
||||
|
||||
private func foo33(a1: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?,
|
||||
_: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?,
|
||||
_: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?,
|
||||
_: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?
|
||||
) -> Any? {
|
||||
return a1
|
||||
}
|
||||
|
||||
private class Foo33 : KotlinFunction33 {
|
||||
func invoke(p1: Any?, p2: Any?, p3: Any?, p4: Any?, p5: Any?, p6: Any?, p7: Any?, p8: Any?, p9: Any?,
|
||||
p10: Any?, p11: Any?, p12: Any?, p13: Any?, p14: Any?, p15: Any?, p16: Any?, p17: Any?, p18: Any?, p19: Any?,
|
||||
p20: Any?, p21: Any?, p22: Any?, p23: Any?, p24: Any?, p25: Any?, p26: Any?, p27: Any?, p28: Any?, p29: Any?,
|
||||
p30: Any?, p31: Any?, p32: Any?, p33: Any?
|
||||
) -> Any? {
|
||||
return foo33(a1: p1
|
||||
, nil, nil, nil, nil, nil, nil, nil, nil
|
||||
, nil, nil, nil, nil, nil, nil, nil, nil
|
||||
, nil, nil, nil, nil, nil, nil, nil, nil
|
||||
, nil, nil, nil, nil, nil, nil, nil, nil)
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package gh4002
|
||||
|
||||
open class GH4002ArgumentBase
|
||||
class GH4002Argument : GH4002ArgumentBase()
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
// See https://github.com/JetBrains/kotlin-native/issues/4002
|
||||
|
||||
class GH4002Base0 : NSObject, NSCoding {
|
||||
required init(coder: NSCoder) { fatalError() }
|
||||
|
||||
func encode(with coder: NSCoder) { fatalError() }
|
||||
}
|
||||
|
||||
class GH4002Base1<T : GH4002ArgumentBase> : GH4002Base0 {}
|
||||
|
||||
@objc(ObjCGH4002)
|
||||
class GH4002 : GH4002Base1<GH4002Argument> {}
|
||||
|
||||
private func test1() throws {
|
||||
try assertEquals(actual: String(cString: class_getName(GH4002.self)), expected: "ObjCGH4002")
|
||||
}
|
||||
|
||||
class Gh4002Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("Test1", test1)
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package headerWarnings
|
||||
|
||||
// Note: the test parses the generated header with -Werror to detect warnings.
|
||||
|
||||
class TestIncompatiblePropertyTypeWarning {
|
||||
class Generic<T>(val value: T)
|
||||
|
||||
interface InterfaceWithGenericProperty<T> {
|
||||
val p: Generic<T>
|
||||
}
|
||||
|
||||
class ClassOverridingInterfaceWithGenericProperty(override val p: Generic<String>) : InterfaceWithGenericProperty<String>
|
||||
}
|
||||
|
||||
// https://github.com/JetBrains/kotlin-native/issues/3992
|
||||
class TestGH3992 {
|
||||
abstract class C(open val a: A)
|
||||
|
||||
class D(override val a: B) : C(a)
|
||||
|
||||
abstract class A
|
||||
|
||||
class B : A()
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
// Note: the test parses the generated header with -Werror to detect warnings.
|
||||
// It is enough to have just Kotlin declarations at the moment.
|
||||
// Adding usages for all declarations to avoid any kind of DCE that may appear later.
|
||||
|
||||
#if !NO_GENERICS
|
||||
private func testIncompatiblePropertyType() throws {
|
||||
let c = TestIncompatiblePropertyTypeWarning.ClassOverridingInterfaceWithGenericProperty(
|
||||
p: TestIncompatiblePropertyTypeWarningGeneric<NSString>(value: "cba")
|
||||
)
|
||||
|
||||
let pc: TestIncompatiblePropertyTypeWarningGeneric<NSString> = c.p
|
||||
try assertEquals(actual: pc.value, expected: "cba")
|
||||
|
||||
let i: TestIncompatiblePropertyTypeWarningInterfaceWithGenericProperty = c
|
||||
let pi: TestIncompatiblePropertyTypeWarningGeneric<AnyObject> = i.p
|
||||
try assertEquals(actual: pi.value as! String, expected: "cba")
|
||||
}
|
||||
#endif
|
||||
|
||||
private func testGH3992() throws {
|
||||
let d = TestGH3992.D(a: TestGH3992.B())
|
||||
let c: TestGH3992.C = d
|
||||
|
||||
let b: TestGH3992.B = d.a
|
||||
let a: TestGH3992.A = b
|
||||
|
||||
try assertTrue(a is TestGH3992.B)
|
||||
}
|
||||
|
||||
class HeaderWarningsTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
#if !NO_GENERICS
|
||||
test("TestIncompatiblePropertyType", testIncompatiblePropertyType)
|
||||
#endif
|
||||
test("TestGH3992", testGH3992)
|
||||
}
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package hiddenfromobjc
|
||||
|
||||
import kotlin.experimental.ExperimentalObjCRefinement
|
||||
|
||||
@OptIn(ExperimentalObjCRefinement::class)
|
||||
@HiddenFromObjC
|
||||
data class ClassNotAvailableInSwift(val param: String)
|
||||
|
||||
// KT-58839
|
||||
fun ClassNotAvailableInSwift.doSomethingMeaningless(another: ClassNotAvailableInSwift): ClassNotAvailableInSwift {
|
||||
return ClassNotAvailableInSwift(this.param + another.param)
|
||||
}
|
||||
|
||||
fun String.doSomethingMeaningless(another: ClassNotAvailableInSwift): ClassNotAvailableInSwift {
|
||||
return ClassNotAvailableInSwift(this + another.param)
|
||||
}
|
||||
|
||||
// Check that inner and nested classes are hidden if enclosing class is hidden
|
||||
@OptIn(ExperimentalObjCRefinement::class)
|
||||
@HiddenFromObjC
|
||||
class ParentClass {
|
||||
class NestedClass {
|
||||
class DeeplyNestedClass
|
||||
}
|
||||
|
||||
inner class InnerClass
|
||||
}
|
||||
|
||||
fun useOfUnavailableClass(param: ClassNotAvailableInSwift): ClassNotAvailableInSwift {
|
||||
return ClassNotAvailableInSwift("hi")
|
||||
}
|
||||
|
||||
fun useOfNullableUnavailableClass(param: ClassNotAvailableInSwift?): ClassNotAvailableInSwift? {
|
||||
return null
|
||||
}
|
||||
|
||||
fun produceUnavailable(): ClassNotAvailableInSwift {
|
||||
return ClassNotAvailableInSwift("hi")
|
||||
}
|
||||
|
||||
fun consumeUnavailable(param: ClassNotAvailableInSwift): String {
|
||||
return param.param
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalObjCRefinement::class)
|
||||
@HiddenFromObjC
|
||||
interface InterfaceNotAvailableInSwift {
|
||||
fun f(): String
|
||||
}
|
||||
|
||||
fun createUnavailableInterface(): InterfaceNotAvailableInSwift {
|
||||
return object : InterfaceNotAvailableInSwift {
|
||||
override fun f(): String = "I'm actually unavailable, call me later."
|
||||
}
|
||||
}
|
||||
|
||||
fun useOfNullableUnavailableInterface(param: InterfaceNotAvailableInSwift?): String? {
|
||||
return param?.f() ?: "null"
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalObjCRefinement::class)
|
||||
@HiddenFromObjC
|
||||
enum class UnavailableEnum {
|
||||
A, B, C;
|
||||
}
|
||||
|
||||
fun createUnavailableEnum(): UnavailableEnum {
|
||||
return UnavailableEnum.A
|
||||
}
|
||||
|
||||
fun useOfUnavailableEnum(param: UnavailableEnum): String {
|
||||
return param.toString()
|
||||
}
|
||||
|
||||
fun useOfNullableUnavailableEnum(param: UnavailableEnum?): String {
|
||||
return param?.toString() ?: "null"
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalObjCRefinement::class)
|
||||
@HiddenFromObjC
|
||||
object UnavailableObject {
|
||||
val field: String = "objectField"
|
||||
}
|
||||
|
||||
fun getUnavailableObject(): UnavailableObject {
|
||||
return UnavailableObject
|
||||
}
|
||||
|
||||
fun useOfUnavailableObject(param:UnavailableObject):String {
|
||||
return param.field
|
||||
}
|
||||
|
||||
fun useOfNullableUnavailableObject(param:UnavailableObject?):String? {
|
||||
return param?.field ?: "null"
|
||||
}
|
||||
|
||||
|
||||
sealed class SealedClass {
|
||||
|
||||
@OptIn(ExperimentalObjCRefinement::class)
|
||||
@HiddenFromObjC
|
||||
class A : SealedClass()
|
||||
|
||||
class B : SealedClass()
|
||||
|
||||
@OptIn(ExperimentalObjCRefinement::class)
|
||||
@HiddenFromObjC
|
||||
object C : SealedClass()
|
||||
}
|
||||
|
||||
fun createSealedClass(): SealedClass {
|
||||
return SealedClass.A()
|
||||
}
|
||||
|
||||
fun useSealedClass(param: SealedClass): String {
|
||||
return when (param) {
|
||||
is SealedClass.A -> "A"
|
||||
is SealedClass.B -> "B"
|
||||
SealedClass.C -> "C"
|
||||
}
|
||||
}
|
||||
|
||||
fun <T : InterfaceNotAvailableInSwift> useUnavailable(a : T): String {
|
||||
return a.f()
|
||||
}
|
||||
|
||||
class WrapperOverUnavailable<T: InterfaceNotAvailableInSwift>(val arg: T)
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
private func testUnavailableEnum() throws {
|
||||
try assertEquals(actual: HiddenfromobjcKt.useOfUnavailableEnum(param: HiddenfromobjcKt.createUnavailableEnum()), expected: "A")
|
||||
try assertEquals(actual: HiddenfromobjcKt.useOfNullableUnavailableEnum(param: nil), expected: "null")
|
||||
try assertEquals(actual: HiddenfromobjcKt.useOfNullableUnavailableEnum(param: HiddenfromobjcKt.createUnavailableEnum()), expected: "A")
|
||||
}
|
||||
|
||||
private func testUnavailableObject() throws {
|
||||
try assertEquals(actual: HiddenfromobjcKt.useOfUnavailableObject(param: HiddenfromobjcKt.getUnavailableObject()), expected: "objectField")
|
||||
try assertEquals(actual: HiddenfromobjcKt.useOfNullableUnavailableObject(param: HiddenfromobjcKt.getUnavailableObject()), expected: "objectField")
|
||||
try assertEquals(actual: HiddenfromobjcKt.useOfNullableUnavailableObject(param: nil), expected: "null")
|
||||
}
|
||||
|
||||
private func testUnavailableInterface() throws {
|
||||
try assertEquals(actual: HiddenfromobjcKt.useOfNullableUnavailableInterface(
|
||||
param: HiddenfromobjcKt.createUnavailableInterface()),
|
||||
expected: "I'm actually unavailable, call me later."
|
||||
)
|
||||
try assertEquals(actual: HiddenfromobjcKt.useOfNullableUnavailableInterface(param: nil), expected: "null")
|
||||
}
|
||||
|
||||
private func testSealedClass() throws {
|
||||
try assertEquals(actual: HiddenfromobjcKt.useSealedClass(param: HiddenfromobjcKt.createSealedClass()), expected: "A")
|
||||
try assertEquals(actual: HiddenfromobjcKt.useSealedClass(param: SealedClass.B()), expected: "B")
|
||||
}
|
||||
|
||||
private func testUnavailableGenerics() throws {
|
||||
try assertEquals(
|
||||
actual: HiddenfromobjcKt.useUnavailable(a: HiddenfromobjcKt.createUnavailableInterface()),
|
||||
expected: "I'm actually unavailable, call me later."
|
||||
)
|
||||
|
||||
let wrapper = WrapperOverUnavailable(arg: HiddenfromobjcKt.createUnavailableInterface() as AnyObject)
|
||||
try assertEquals(
|
||||
actual: HiddenfromobjcKt.useUnavailable(a: wrapper.arg),
|
||||
expected: "I'm actually unavailable, call me later."
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
class HiddenfromobjcTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
// Here we check that even if type is erased from Objective-C declarations, we still able to use them properly with proper objects.
|
||||
test("testUnavailableEnum", testUnavailableEnum)
|
||||
test("testUnavailableObject", testUnavailableObject)
|
||||
test("testUnavailableInterface", testUnavailableInterface)
|
||||
test("testSealedClass", testSealedClass)
|
||||
test("testUnavailableGenerics", testUnavailableGenerics)
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
@file:OptIn(kotlin.experimental.ExperimentalObjCName::class)
|
||||
|
||||
package objcNameMangling
|
||||
|
||||
interface InterfaceNameManglingI1 {
|
||||
val clashingProperty: Int
|
||||
|
||||
fun clashingMethod(): Int
|
||||
|
||||
@ObjCName(name = "interfaceClashingMethodWithObjCNameInI1")
|
||||
fun clashingMethodWithObjCNameInI1(): Int
|
||||
|
||||
fun interfaceClashingMethodWithObjCNameInI2(): Int
|
||||
|
||||
@ObjCName(name = "interfaceClashingMethodWithObjCNameInBoth")
|
||||
fun clashingMethodWithObjCNameInBoth(): Int
|
||||
}
|
||||
|
||||
fun i1() = object : InterfaceNameManglingI1 {
|
||||
override val clashingProperty: Int
|
||||
get() = 1
|
||||
|
||||
override fun clashingMethod(): Int = 2
|
||||
|
||||
override fun clashingMethodWithObjCNameInI1(): Int = 3
|
||||
|
||||
override fun interfaceClashingMethodWithObjCNameInI2(): Int = 4
|
||||
|
||||
override fun clashingMethodWithObjCNameInBoth(): Int = 5
|
||||
}
|
||||
|
||||
interface InterfaceNameManglingI2 {
|
||||
val clashingProperty: Any
|
||||
|
||||
fun clashingMethod(): Any
|
||||
|
||||
fun interfaceClashingMethodWithObjCNameInI1(): Any
|
||||
|
||||
@ObjCName(name = "interfaceClashingMethodWithObjCNameInI2")
|
||||
fun clashingMethodWithObjCNameInI2(): Any
|
||||
|
||||
@ObjCName(name = "interfaceClashingMethodWithObjCNameInBoth")
|
||||
fun clashingMethodWithObjCNameInBoth(): Any
|
||||
}
|
||||
|
||||
fun i2() = object : InterfaceNameManglingI2 {
|
||||
override val clashingProperty: Any
|
||||
get() = "one"
|
||||
|
||||
override fun clashingMethod(): Any = "two"
|
||||
|
||||
override fun interfaceClashingMethodWithObjCNameInI1(): Any = "three"
|
||||
|
||||
override fun clashingMethodWithObjCNameInI2(): Any = "four"
|
||||
|
||||
override fun clashingMethodWithObjCNameInBoth(): Any = "five"
|
||||
}
|
||||
|
||||
class InterfaceNameManglingC1 {
|
||||
val clashingProperty: String = "one"
|
||||
|
||||
fun clashingMethod(): String = "two"
|
||||
}
|
||||
|
||||
final class InterfaceNameManglingC2 {
|
||||
val clashingProperty: Int = 1
|
||||
|
||||
fun clashingMethod(): Int = 2
|
||||
}
|
||||
|
||||
fun o1() = InterfaceNameManglingC1()
|
||||
|
||||
fun o2() = InterfaceNameManglingC2()
|
||||
@@ -1,35 +0,0 @@
|
||||
import Kt
|
||||
|
||||
private func test1() throws {
|
||||
let i1 = InterfaceMethodNameManglingKt.i1()
|
||||
let i2 = InterfaceMethodNameManglingKt.i2()
|
||||
let o1 = InterfaceMethodNameManglingKt.o1()
|
||||
let o2 = InterfaceMethodNameManglingKt.o2()
|
||||
|
||||
#if DISABLE_MEMBER_NAME_MANGLING || DISABLE_INTERFACE_METHOD_NAME_MANGLING
|
||||
try assertEquals(actual: i1.clashingProperty, expected: 1)
|
||||
try assertEquals(actual: i1.clashingMethod(), expected: 2)
|
||||
try assertEquals(actual: i1.interfaceClashingMethodWithObjCNameInI1(), expected: 3)
|
||||
try assertEquals(actual: i1.interfaceClashingMethodWithObjCNameInI2(), expected: 4)
|
||||
try assertEquals(actual: i1.interfaceClashingMethodWithObjCNameInBoth(), expected: 5)
|
||||
|
||||
try assertEquals(actual: i2.clashingProperty as! String, expected: "one")
|
||||
try assertEquals(actual: i2.clashingMethod() as! String, expected: "two")
|
||||
try assertEquals(actual: i2.interfaceClashingMethodWithObjCNameInI1() as! String, expected: "three")
|
||||
try assertEquals(actual: i2.interfaceClashingMethodWithObjCNameInI2() as! String, expected: "four")
|
||||
try assertEquals(actual: i2.interfaceClashingMethodWithObjCNameInBoth() as! String, expected: "five")
|
||||
|
||||
try assertEquals(actual: o1.clashingProperty, expected: "one")
|
||||
try assertEquals(actual: o1.clashingMethod(), expected: "two")
|
||||
#endif
|
||||
try assertEquals(actual: o2.clashingProperty, expected: 1)
|
||||
try assertEquals(actual: o2.clashingMethod(), expected: 2)
|
||||
}
|
||||
|
||||
class InterfaceMethodNameManglingTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("Test1", test1)
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
package kdocExport
|
||||
|
||||
/**
|
||||
* Summary class [KDocExport].
|
||||
*
|
||||
* @property xyzzy Doc for property xyzzy
|
||||
* @property zzz See below.
|
||||
*/
|
||||
|
||||
// Expected: this comment shall not affect KDoc (i.e. kdoc above is still OK)
|
||||
class KDocExport() {
|
||||
/**
|
||||
* @param xyzzy is documented.
|
||||
*
|
||||
* This is multi-line KDoc. See a blank line above.
|
||||
*/
|
||||
val xyzzy: String = "String example"
|
||||
|
||||
/** Non-primary ctor KDoc: */
|
||||
constructor(name: String) : this() {
|
||||
println(name)
|
||||
}
|
||||
|
||||
/** @property xyzzy KDoc for foo? */
|
||||
val foo = "foo"
|
||||
/** @property foo KDoc for yxxyz? */
|
||||
var yxxyz = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Useless function [whatever]
|
||||
*
|
||||
* This kdoc has some additional formatting.
|
||||
* @param a keep intact and return
|
||||
* @return value of [a]
|
||||
* Check for additional comment (note) below
|
||||
*/
|
||||
@Throws(IllegalArgumentException::class)
|
||||
fun whatever(a:String) = a
|
||||
|
||||
public abstract class SomeClassWithProperty
|
||||
{
|
||||
/**
|
||||
* Returns dispatcher that executes coroutines immediately when it is already in the right context
|
||||
* (e.g. current looper is the same as this handler's looper) without an additional [re-dispatch][CoroutineDispatcher.dispatch].
|
||||
*
|
||||
* Immediate dispatcher is safe from stack overflows and in case of nested invocations forms event-loop similar to [Dispatchers.Unconfined].
|
||||
* The event loop is an advanced topic and its implications can be found in [Dispatchers.Unconfined] documentation.
|
||||
* The formed event-loop is shared with [Unconfined] and other immediate dispatchers, potentially overlapping tasks between them.
|
||||
*
|
||||
* Example of usage:
|
||||
* ```
|
||||
* suspend fun updateUiElement(val text: String) {
|
||||
* /*
|
||||
* * If it is known that updateUiElement can be invoked both from the Main thread and from other threads,
|
||||
* * `immediate` dispatcher is used as a performance optimization to avoid unnecessary dispatch.
|
||||
* *
|
||||
* * In that case, when `updateUiElement` is invoked from the Main thread, `uiElement.text` will be
|
||||
* * invoked immediately without any dispatching, otherwise, the `Dispatchers.Main` dispatch cycle will be triggered.
|
||||
* */
|
||||
* withContext(Dispatchers.Main.immediate) {
|
||||
* uiElement.text = text
|
||||
* }
|
||||
* // Do context-independent logic such as logging
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* Method may throw [UnsupportedOperationException] if immediate dispatching is not supported by current dispatcher,
|
||||
* please refer to specific dispatcher documentation.
|
||||
*
|
||||
* [Dispatchers.Main] supports immediate execution for Android, JavaFx and Swing platforms.
|
||||
*/
|
||||
public abstract val heavyFormattedKDocFoo: SomeClassWithProperty
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package kotlinPrivateOverride
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// The intention is to test "virtual adapters" machinery of ObjCExport.
|
||||
// This machinery handles the case when exported Kotlin type is subclassed
|
||||
// by a non-exported (e.g. private) Kotlin type, and the instance of the latter is passed to Obj-C.
|
||||
|
||||
interface KotlinPrivateOverrideI1 {
|
||||
fun i123AbstractMethod(): Int
|
||||
fun i1OpenMethod(): Int = -1
|
||||
}
|
||||
|
||||
interface KotlinPrivateOverrideI2 {
|
||||
fun i123AbstractMethod(): Int
|
||||
fun i234AbstractMethod(): Int
|
||||
fun i2AbstractMethod(): Int
|
||||
}
|
||||
|
||||
private interface KotlinPrivateOverridePI1 {
|
||||
fun pi1AbstractMethod(): Int
|
||||
}
|
||||
|
||||
abstract class KotlinPrivateOverrideA1 : KotlinPrivateOverrideI1, KotlinPrivateOverrideI2, KotlinPrivateOverridePI1 {
|
||||
abstract fun a1AbstractMethod(): Int
|
||||
open fun a1OpenMethod(): Int = -2
|
||||
}
|
||||
|
||||
interface KotlinPrivateOverrideI3 {
|
||||
fun i123AbstractMethod(): Int
|
||||
fun i234AbstractMethod(): Int
|
||||
fun i3AbstractMethod(): Int
|
||||
}
|
||||
|
||||
private interface KotlinPrivateOverridePI2 {
|
||||
fun pi2AbstractMethod(): Int
|
||||
}
|
||||
|
||||
private open class KotlinPrivateOverrideP1 : KotlinPrivateOverrideA1(), KotlinPrivateOverrideI3, KotlinPrivateOverridePI2 {
|
||||
override fun i123AbstractMethod(): Int = 1
|
||||
override fun i1OpenMethod(): Int = 2
|
||||
override fun i234AbstractMethod(): Int = 3
|
||||
override fun i2AbstractMethod(): Int = 4
|
||||
override fun pi1AbstractMethod(): Int = 5
|
||||
override fun a1AbstractMethod(): Int = 6
|
||||
override fun a1OpenMethod(): Int = 7
|
||||
override fun i3AbstractMethod(): Int = 8
|
||||
override fun pi2AbstractMethod(): Int = 9
|
||||
}
|
||||
|
||||
fun createP1(): Any = KotlinPrivateOverrideP1()
|
||||
|
||||
interface KotlinPrivateOverrideI4 {
|
||||
fun i234AbstractMethod(): Int
|
||||
fun i4AbstractMethod(): Int
|
||||
}
|
||||
|
||||
private interface KotlinPrivateOverridePI3 {
|
||||
fun pi3AbstractMethod(): Int
|
||||
}
|
||||
|
||||
private class KotlinPrivateOverrideP12 : KotlinPrivateOverrideP1(), KotlinPrivateOverrideI4, KotlinPrivateOverridePI3 {
|
||||
override fun i123AbstractMethod(): Int = 11
|
||||
override fun i1OpenMethod(): Int = 12
|
||||
override fun i234AbstractMethod(): Int = 13
|
||||
override fun i2AbstractMethod(): Int = 14
|
||||
override fun pi1AbstractMethod(): Int = 15
|
||||
override fun a1AbstractMethod(): Int = 16
|
||||
override fun a1OpenMethod(): Int = 17
|
||||
override fun i3AbstractMethod(): Int = 18
|
||||
override fun pi2AbstractMethod(): Int = 19
|
||||
override fun i4AbstractMethod(): Int = 20
|
||||
override fun pi3AbstractMethod(): Int = 21
|
||||
}
|
||||
|
||||
fun createP12(): Any = KotlinPrivateOverrideP12()
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
private func testI1Methods(p: Any, base: Int32) throws {
|
||||
guard let i1 = p as? KotlinPrivateOverrideI1 else { try fail() }
|
||||
try assertEquals(actual: i1.i123AbstractMethod(), expected: base + 1)
|
||||
try assertEquals(actual: i1.i1OpenMethod(), expected: base + 2)
|
||||
}
|
||||
|
||||
private func testI2Methods(p: Any, base: Int32) throws {
|
||||
guard let i2 = p as? KotlinPrivateOverrideI2 else { try fail() }
|
||||
try assertEquals(actual: i2.i123AbstractMethod(), expected: base + 1)
|
||||
try assertEquals(actual: i2.i234AbstractMethod(), expected: base + 3)
|
||||
try assertEquals(actual: i2.i2AbstractMethod(), expected: base + 4)
|
||||
}
|
||||
|
||||
private func testA1Methods(p: Any, base: Int32) throws {
|
||||
guard let a1 = p as? KotlinPrivateOverrideA1 else { try fail() }
|
||||
try assertEquals(actual: a1.i123AbstractMethod(), expected: base + 1)
|
||||
try assertEquals(actual: a1.i1OpenMethod(), expected: base + 2)
|
||||
try assertEquals(actual: a1.i234AbstractMethod(), expected: base + 3)
|
||||
try assertEquals(actual: a1.i2AbstractMethod(), expected: base + 4)
|
||||
try assertEquals(actual: a1.a1AbstractMethod(), expected: base + 6)
|
||||
try assertEquals(actual: a1.a1OpenMethod(), expected: base + 7)
|
||||
}
|
||||
|
||||
private func testI3Methods(p: Any, base: Int32) throws {
|
||||
guard let i3 = p as? KotlinPrivateOverrideI3 else { try fail() }
|
||||
try assertEquals(actual: i3.i123AbstractMethod(), expected: base + 1)
|
||||
try assertEquals(actual: i3.i234AbstractMethod(), expected: base + 3)
|
||||
try assertEquals(actual: i3.i3AbstractMethod(), expected: base + 8)
|
||||
}
|
||||
|
||||
private func testI4Methods(p: Any, base: Int32) throws {
|
||||
guard let i4 = p as? KotlinPrivateOverrideI4 else { try fail() }
|
||||
try assertEquals(actual: i4.i234AbstractMethod(), expected: base + 3)
|
||||
try assertEquals(actual: i4.i4AbstractMethod(), expected: base + 10)
|
||||
}
|
||||
|
||||
private func test(p: Any, base: Int32, isI4: Bool) throws {
|
||||
try testI1Methods(p: p, base: base)
|
||||
try testI2Methods(p: p, base: base)
|
||||
try testA1Methods(p: p, base: base)
|
||||
try testI3Methods(p: p, base: base)
|
||||
if isI4 {
|
||||
try testI4Methods(p: p, base: base)
|
||||
}
|
||||
}
|
||||
|
||||
private func test1() throws {
|
||||
try test(p: KotlinPrivateOverrideKt.createP1(), base: 0, isI4: false)
|
||||
try test(p: KotlinPrivateOverrideKt.createP12(), base: 10, isI4: true)
|
||||
}
|
||||
|
||||
|
||||
class KotlinPrivateOverrideTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("Test1", test1)
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package kt35940
|
||||
|
||||
import kotlin.reflect.*
|
||||
|
||||
@OptIn(ExperimentalAssociatedObjects::class)
|
||||
@AssociatedObjectKey
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
annotation class Associated(val kClass: KClass<*>)
|
||||
|
||||
private interface I1 {
|
||||
val s: String
|
||||
}
|
||||
|
||||
private class I1Impl : I1 {
|
||||
override val s = "zzz"
|
||||
}
|
||||
|
||||
private class C(var i1: I1?)
|
||||
|
||||
private interface I2 {
|
||||
fun bar(c: C)
|
||||
}
|
||||
|
||||
private object I2Impl : I2 {
|
||||
override fun bar(c: C) {
|
||||
c.i1 = I1Impl()
|
||||
}
|
||||
}
|
||||
|
||||
@Associated(I2Impl::class)
|
||||
private class I2ImplHolder
|
||||
|
||||
@OptIn(ExperimentalAssociatedObjects::class)
|
||||
fun testKt35940(): String {
|
||||
val i2 = I2ImplHolder::class.findAssociatedObject<Associated>()!! as I2
|
||||
val c = C(null)
|
||||
i2.bar(c)
|
||||
return c.i1!!.s
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
private func test1() throws {
|
||||
try assertEquals(actual: Kt35940Kt.testKt35940(), expected: "zzz")
|
||||
}
|
||||
|
||||
class Kt35940Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("Test1", test1)
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package kt38641
|
||||
|
||||
// See https://youtrack.jetbrains.com/issue/KT-38641.
|
||||
class KT38641 {
|
||||
class IntType {
|
||||
var description = 42
|
||||
}
|
||||
|
||||
class Val {
|
||||
val description = "val"
|
||||
}
|
||||
|
||||
class Var {
|
||||
var description = "var"
|
||||
}
|
||||
|
||||
class TwoProperties {
|
||||
val description = "description"
|
||||
val description_ = "description_"
|
||||
}
|
||||
|
||||
abstract class OverrideVal {
|
||||
abstract val description: String
|
||||
}
|
||||
|
||||
interface OverrideVar {
|
||||
var description: String
|
||||
}
|
||||
}
|
||||
|
||||
fun getOverrideValDescription(impl: KT38641.OverrideVal) = impl.description
|
||||
|
||||
fun getOverrideVarDescription(impl: KT38641.OverrideVar) = impl.description
|
||||
fun setOverrideVarDescription(impl: KT38641.OverrideVar, newValue: String) {
|
||||
impl.description = newValue
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
private func testIntType() throws {
|
||||
let i = KT38641.IntType()
|
||||
|
||||
try assertEquals(actual: i.description_, expected: 42)
|
||||
|
||||
i.description_ = 17
|
||||
try assertEquals(actual: i.description_, expected: 17)
|
||||
}
|
||||
|
||||
private func testVal() throws {
|
||||
try assertEquals(actual: KT38641.Val().description_, expected: "val")
|
||||
}
|
||||
|
||||
private func testVar() throws {
|
||||
let v = KT38641.Var()
|
||||
|
||||
try assertEquals(actual: v.description_, expected: "var")
|
||||
|
||||
v.description_ = "newValue"
|
||||
try assertEquals(actual: v.description_, expected: "newValue")
|
||||
}
|
||||
|
||||
private func testTwoProperties() throws {
|
||||
let t = KT38641.TwoProperties()
|
||||
#if !DISABLE_MEMBER_NAME_MANGLING
|
||||
try assertEquals(actual: t.description_, expected: "description")
|
||||
try assertEquals(actual: t.description__, expected: "description_")
|
||||
#endif
|
||||
}
|
||||
|
||||
private func testOverrideVal() throws {
|
||||
try assertEquals(actual: Kt38641Kt.getOverrideValDescription(impl: KT38641OverrideValImpl()), expected: "description_")
|
||||
}
|
||||
|
||||
class KT38641OverrideValImpl : KT38641.OverrideVal {
|
||||
override var description_: String {
|
||||
get {
|
||||
return "description_"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func testOverrideVar() throws {
|
||||
let impl = KT38641OverrideVarImpl()
|
||||
|
||||
try assertEquals(actual: Kt38641Kt.getOverrideVarDescription(impl: impl), expected: "description_")
|
||||
|
||||
Kt38641Kt.setOverrideVarDescription(impl: impl, newValue: "d")
|
||||
try assertEquals(actual: Kt38641Kt.getOverrideVarDescription(impl: impl), expected: "d")
|
||||
}
|
||||
|
||||
class KT38641OverrideVarImpl : KT38641OverrideVar {
|
||||
var description_: String = "description_"
|
||||
}
|
||||
|
||||
class Kt38641Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("TestIntType", testIntType)
|
||||
test("TestVal", testVal)
|
||||
test("TestVar", testVar)
|
||||
test("TestTwoProperties", testTwoProperties)
|
||||
test("TestOverrideVal", testOverrideVal)
|
||||
test("TestOverrideVar", testOverrideVar)
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
// See https://youtrack.jetbrains.com/issue/KT-39206.
|
||||
@Deprecated("Don't call this\nPlease")
|
||||
fun myFunc() = 17
|
||||
|
||||
// See https://youtrack.jetbrains.com/issue/KT-41193.
|
||||
@Deprecated(
|
||||
level = DeprecationLevel.ERROR,
|
||||
message = "This class is deprecated for removal during serialization 1.0 API stabilization.\n" +
|
||||
"For configuring Json instances, the corresponding builder function can be used instead, e.g. instead of" +
|
||||
"'Json(JsonConfiguration.Stable.copy(isLenient = true))' 'Json { isLenient = true }' should be used.\n" +
|
||||
"Instead of storing JsonConfiguration instances of the code, Json instances can be used directly:" +
|
||||
"'Json(MyJsonConfiguration.copy(prettyPrint = true))' can be replaced with 'Json(from = MyApplicationJson) { prettyPrint = true }'"
|
||||
)
|
||||
public open class JsonConfiguration
|
||||
|
||||
@Deprecated("'\"\\@\$(){}\r\n")
|
||||
class MoreTrickyChars
|
||||
@@ -1,18 +0,0 @@
|
||||
import Kt
|
||||
|
||||
private func test1() throws {
|
||||
try assertEquals(actual: Kt39206Kt.myFunc(), expected: 17)
|
||||
}
|
||||
|
||||
private func test2() throws {
|
||||
try assertTrue(MoreTrickyChars() as AnyObject is MoreTrickyChars)
|
||||
}
|
||||
|
||||
class Kt39206Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("Test1", test1)
|
||||
test("Test2", test2)
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package kt41907
|
||||
|
||||
class Ckt41907
|
||||
|
||||
interface Ikt41907 {
|
||||
fun foo(c: Ckt41907)
|
||||
}
|
||||
|
||||
private class Bkt41907 {
|
||||
var c: Ckt41907? = null
|
||||
}
|
||||
|
||||
private val b = Bkt41907()
|
||||
|
||||
fun escapeC(c: Ckt41907) {
|
||||
b.c = c
|
||||
}
|
||||
|
||||
fun testKt41907(o: Ikt41907) {
|
||||
val c = Ckt41907()
|
||||
o.foo(c)
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
class Ikt41907Impl : Ikt41907 {
|
||||
func foo(c: Ckt41907) {
|
||||
Kt41907Kt.escapeC(c: c)
|
||||
}
|
||||
}
|
||||
|
||||
private func test1() {
|
||||
Kt41907Kt.testKt41907(o: Ikt41907Impl())
|
||||
}
|
||||
|
||||
class Kt41907Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("Test1", test1)
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package kt43599
|
||||
|
||||
// Note: this test relies on two-stage compilation.
|
||||
|
||||
class KT43599 {
|
||||
var memberProperty = "memberProperty"
|
||||
private set
|
||||
}
|
||||
|
||||
var KT43599.extensionProperty
|
||||
get() = "extensionProperty"
|
||||
private set(value) { TODO() }
|
||||
|
||||
var topLevelProperty
|
||||
get() = "topLevelProperty"
|
||||
private set(value) { TODO() }
|
||||
|
||||
lateinit var topLevelLateinitProperty: String
|
||||
private set
|
||||
|
||||
fun setTopLevelLateinitProperty(value: String) {
|
||||
topLevelLateinitProperty = value
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
private func testPropertyWithPrivateSetter() throws {
|
||||
try assertEquals(actual: KT43599().memberProperty, expected: "memberProperty")
|
||||
try assertEquals(actual: KT43599().extensionProperty, expected: "extensionProperty")
|
||||
try assertEquals(actual: Kt43599Kt.topLevelProperty, expected: "topLevelProperty")
|
||||
|
||||
// Checking the reported case too:
|
||||
Kt43599Kt.setTopLevelLateinitProperty(value: "topLevelLateinitProperty")
|
||||
try assertEquals(actual: Kt43599Kt.topLevelLateinitProperty, expected: "topLevelLateinitProperty")
|
||||
}
|
||||
|
||||
class Kt43599Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("TestPropertyWithPrivateSetter", testPropertyWithPrivateSetter)
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
object KT43780TestObject {
|
||||
val x = 5
|
||||
val y = 6
|
||||
val shared = "shared"
|
||||
val Shared = "Shared"
|
||||
}
|
||||
|
||||
class KT43780TestClassWithCompanion {
|
||||
companion object {
|
||||
val z = 7
|
||||
}
|
||||
}
|
||||
|
||||
object Shared {
|
||||
val x = 8
|
||||
}
|
||||
|
||||
class Companion {
|
||||
val t = 10
|
||||
companion object {
|
||||
val x = 9
|
||||
}
|
||||
}
|
||||
|
||||
enum class KT43780Enum {
|
||||
OTHER_ENTRY,
|
||||
COMPANION;
|
||||
|
||||
companion object {
|
||||
val x = 11
|
||||
}
|
||||
}
|
||||
|
||||
class ClassWithInternalCompanion {
|
||||
internal companion object {
|
||||
val x = 12
|
||||
}
|
||||
|
||||
val y = 13
|
||||
}
|
||||
|
||||
class ClassWithPrivateCompanion {
|
||||
private companion object {
|
||||
val x = 14
|
||||
}
|
||||
|
||||
val y = 15
|
||||
}
|
||||
|
||||
// Shouldn't be exported at all:
|
||||
internal class InternalClassWithCompanion {
|
||||
companion object
|
||||
}
|
||||
|
||||
private class PrivateClassWithCompanion {
|
||||
companion object
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
import Kt
|
||||
|
||||
private func testObject() throws {
|
||||
let object = KT43780TestObject.shared
|
||||
try assertEquals(actual: object.x, expected: 5)
|
||||
try assertEquals(actual: object.y, expected: 6)
|
||||
try assertEquals(actual: object.shared, expected: "shared")
|
||||
try assertEquals(actual: object.Shared, expected: "Shared")
|
||||
try assertTrue(object === KT43780TestObject())
|
||||
}
|
||||
|
||||
private func testCompanionObject() throws {
|
||||
let object = KT43780TestClassWithCompanion.companion
|
||||
try assertEquals(actual: object.z, expected: 7)
|
||||
try assertTrue(object === KT43780TestClassWithCompanion.Companion())
|
||||
try assertTrue(object === KT43780TestClassWithCompanion.Companion.shared)
|
||||
}
|
||||
|
||||
private func testNameClash() throws {
|
||||
let object = Shared.shared
|
||||
try assertEquals(actual: object.x, expected: 8)
|
||||
try assertTrue(object === Shared())
|
||||
let object2 = Companion.companion
|
||||
try assertEquals(actual: object2.x, expected: 9)
|
||||
try assertTrue(object2 === Companion.Companion())
|
||||
let object3 = Companion()
|
||||
try assertEquals(actual: object3.t, expected: 10)
|
||||
let object4 = Companion()
|
||||
try assertEquals(actual: object4.t, expected: 10)
|
||||
try assertTrue(object3 !== object4)
|
||||
|
||||
let object5 = KT43780Enum.Companion()
|
||||
try assertEquals(actual: object5.x, expected: 11)
|
||||
try assertTrue(object5 === KT43780Enum.Companion())
|
||||
let enumEntry : KT43780Enum = KT43780Enum.companion
|
||||
try assertEquals(actual: enumEntry.name, expected: "COMPANION")
|
||||
try assertEquals(actual: KT43780Enum.otherEntry.name, expected: "OTHER_ENTRY")
|
||||
}
|
||||
|
||||
// Reported as https://youtrack.jetbrains.com/issue/KT-47462
|
||||
private func testUnexposedCompanion() throws {
|
||||
// Just trying to ensure that the classes are accessible:
|
||||
try assertEquals(actual: 13, expected: ClassWithInternalCompanion().y)
|
||||
try assertEquals(actual: 15, expected: ClassWithPrivateCompanion().y)
|
||||
// and this doesn't make the companions accessible as well.
|
||||
}
|
||||
|
||||
|
||||
class Kt43780Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("testObject", testObject)
|
||||
test("testCompanionObject", testCompanionObject)
|
||||
test("testNameClash", testNameClash)
|
||||
test("testUnexposedCompanion", testUnexposedCompanion)
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package kt43599
|
||||
|
||||
// Based on https://youtrack.jetbrains.com/issue/KT-46431
|
||||
|
||||
interface Host {
|
||||
val test: String
|
||||
}
|
||||
abstract class AbstractHost : Host
|
||||
|
||||
fun createAbstractHost(): Host {
|
||||
return object : AbstractHost() {
|
||||
override val test: String
|
||||
get() = "1234"
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
// Based on https://youtrack.jetbrains.com/issue/KT-46431.
|
||||
|
||||
private func test1() throws {
|
||||
try assertEquals(actual: Kt46431Kt.createAbstractHost().test, expected: "1234")
|
||||
}
|
||||
|
||||
class Kt46431Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("Test1", test1)
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package kt49937
|
||||
|
||||
// Based on https://youtrack.jetbrains.com/issue/KT-49937
|
||||
|
||||
final class KT49937 {
|
||||
override fun toString(): String {
|
||||
return "KT49937"
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
// Based on https://youtrack.jetbrains.com/issue/KT-49937.
|
||||
|
||||
public extension KT49937 {
|
||||
override var description: String { "KT49937Swift" }
|
||||
}
|
||||
|
||||
private func test1() throws {
|
||||
try assertEquals(actual: KT49937().description, expected: "KT49937Swift")
|
||||
|
||||
let nsObject: NSObject = KT49937()
|
||||
try assertEquals(actual: nsObject.description, expected: "KT49937Swift")
|
||||
}
|
||||
|
||||
class Kt49937Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("Test1", test1)
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.
|
||||
*/
|
||||
@file:MyCustomFileAspect(type = "kt")
|
||||
|
||||
@Target(AnnotationTarget.FILE)
|
||||
annotation class MyCustomFileAspect(val type: String = "kt")
|
||||
|
||||
annotation class NoDoc
|
||||
@MustBeDocumented
|
||||
annotation class Foo
|
||||
@MustBeDocumented
|
||||
annotation class BugReport(
|
||||
val assignedTo: String = "[none]",
|
||||
val status: String = "open"
|
||||
)
|
||||
|
||||
@NoDoc
|
||||
@Foo
|
||||
@BugReport(assignedTo = "me", status = "open")
|
||||
interface MyInterface {
|
||||
}
|
||||
|
||||
@NoDoc
|
||||
@Foo
|
||||
@BugReport(assignedTo = "me", status = "open")
|
||||
class Bar {
|
||||
@NoDoc
|
||||
@Foo
|
||||
@Deprecated("warning", level = DeprecationLevel.WARNING)
|
||||
/**
|
||||
* My method
|
||||
* @param nodocParam is one arg
|
||||
* @param fooParam is second arg
|
||||
* @return their sum
|
||||
*/
|
||||
protected suspend fun baz (@NoDoc nodocParam:Int, @Foo @BugReport(assignedTo = "me", status = "fixed") fooParam:Int): Int { return nodocParam + fooParam }
|
||||
|
||||
/** My property
|
||||
***
|
||||
*
|
||||
*/
|
||||
@Foo
|
||||
@BugReport(assignedTo = "me", status = "open")
|
||||
val greeting: String
|
||||
get() {
|
||||
return "Hello World!"
|
||||
}
|
||||
|
||||
// Not a kDoc-formatted comment
|
||||
protected val farewell: String
|
||||
get() { return "Bye bye!" }
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.
|
||||
*/
|
||||
|
||||
package kt54119
|
||||
|
||||
class KT54119KotlinKey
|
||||
|
||||
private typealias Foo = KT54119KotlinKey
|
||||
|
||||
fun callContains(set: Set<*>) = set.contains(Foo())
|
||||
|
||||
@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
|
||||
fun callGetElement(set: Set<*>) = (set as kotlin.native.internal.KonanSet<Any?>).getElement(Foo())
|
||||
|
||||
fun callContainsKey(map: Map<*, *>) = map.containsKey(Foo())
|
||||
|
||||
fun callContainsValue(map: Map<*, *>) = map.containsValue(Foo())
|
||||
|
||||
fun callGet(map: Map<*, *>) = map.get(Foo())
|
||||
|
||||
fun callGetOrThrowConcurrentModification(map: Map<*, *>) = map.hashCode() // calls getOrThrowConcurrentModification under the hood.
|
||||
fun callContainsEntry(map: Map<*, *>) = map.entries.contains(map.entries.first())
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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 Foundation
|
||||
import Kt
|
||||
|
||||
// See https://youtrack.jetbrains.com/issue/KT-54119/Native-runtime-assertion-failed-due-to-missing-thread-state-switch
|
||||
|
||||
private func testSetContains() throws {
|
||||
try assertFalse(Kt54119Kt.callContains(set: ["111"]))
|
||||
}
|
||||
|
||||
private func testSetGetElement() throws {
|
||||
try assertNil(Kt54119Kt.callGetElement(set: [222]))
|
||||
}
|
||||
|
||||
private func testMapContainsKey() throws {
|
||||
try assertFalse(Kt54119Kt.callContainsKey(map: ["abc" : "def"]))
|
||||
}
|
||||
|
||||
private func testMapContainsValue() throws {
|
||||
try assertFalse(Kt54119Kt.callContainsValue(map: [KT54119KotlinKey() : 1]))
|
||||
}
|
||||
|
||||
private func testMapGet() throws {
|
||||
try assertNil(Kt54119Kt.callGet(map: [0 : 0]))
|
||||
}
|
||||
|
||||
private func testMapGetOrThrowConcurrentModification() throws {
|
||||
Kt54119Kt.callGetOrThrowConcurrentModification(map: [KT54119KotlinKey() : 2])
|
||||
}
|
||||
|
||||
private func testMapContainsEntry() throws {
|
||||
try assertTrue(Kt54119Kt.callContainsEntry(map: [KT54119KotlinKey() : 3]))
|
||||
}
|
||||
|
||||
class Kt54119Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("testSetContains", testSetContains)
|
||||
test("testSetGetElement", testSetGetElement)
|
||||
test("testMapContainsKey", testMapContainsKey)
|
||||
test("testMapContainsValue", testMapContainsValue)
|
||||
test("testMapGet", testMapGet)
|
||||
test("testMapGetOrThrowConcurrentModification", testMapGetOrThrowConcurrentModification)
|
||||
test("testMapContainsEntry", testMapContainsEntry)
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* 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 kotlin.sequences.*
|
||||
|
||||
suspend fun SequenceScope<Int>.fill() {
|
||||
yield(1)
|
||||
yield(2)
|
||||
}
|
||||
|
||||
fun getFillFunction() = SequenceScope<Int>::fill
|
||||
|
||||
fun callback(block: suspend SequenceScope<Int>.() -> Unit) : List<Int> {
|
||||
return sequence {
|
||||
block()
|
||||
}.toList()
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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 Foundation
|
||||
import Kt
|
||||
|
||||
private func testFill() throws {
|
||||
let result = Kt55736Kt.callback(block: Kt55736Kt.getFillFunction())
|
||||
try assertEquals(actual: result.count, expected: 2)
|
||||
try assertEquals(actual: result[0], expected: 1)
|
||||
try assertEquals(actual: result[1], expected: 2)
|
||||
}
|
||||
|
||||
class Kt55736Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("testFill", testFill)
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
var initialized = 0
|
||||
|
||||
object Kt56521 {
|
||||
init {
|
||||
initialized = 1
|
||||
}
|
||||
}
|
||||
|
||||
fun getKt56521(): Kt56521 {
|
||||
Kt56521
|
||||
return Kt56521
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* 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 Kt
|
||||
|
||||
func testKt56521() throws {
|
||||
let object = Kt56521()
|
||||
try assertTrue(object is Kt56521)
|
||||
try assertEquals(actual: Kt56521Kt.initialized, expected: 1)
|
||||
}
|
||||
|
||||
class Kt56521Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("testKt56521", testKt56521)
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
interface IKt57373 {
|
||||
val bar: Int
|
||||
}
|
||||
|
||||
class DKt57373(foo: IKt57373) : IKt57373 by foo
|
||||
|
||||
class CKt57373 : IKt57373 {
|
||||
override val bar: Int = 42
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* 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 Kt
|
||||
|
||||
func testKt57373() throws {
|
||||
let impl = CKt57373()
|
||||
let x = DKt57373(foo: impl)
|
||||
try assertEquals(actual: x.bar, expected: 42)
|
||||
}
|
||||
|
||||
class Kt57373Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("testKt57373", testKt57373)
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package kt57791
|
||||
|
||||
abstract class Ckt57791 {
|
||||
abstract fun baz(): Int
|
||||
}
|
||||
|
||||
object Okt57791 : Ckt57791() {
|
||||
override fun baz() = 117
|
||||
}
|
||||
|
||||
class Ckt57791Final : Ckt57791() {
|
||||
override fun baz() = 42
|
||||
}
|
||||
|
||||
interface Foo {
|
||||
fun getCkt57791(): Ckt57791Final
|
||||
}
|
||||
|
||||
fun foobar(f: Boolean, foo: Foo): Boolean {
|
||||
val z = if (f) Okt57791 else foo.getCkt57791()
|
||||
return z.baz() == 42
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
* 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 Kt
|
||||
|
||||
class FooImpl : Foo {
|
||||
func getCkt57791() -> Ckt57791Final { return Ckt57791Final() }
|
||||
}
|
||||
|
||||
func testKt57791() throws {
|
||||
try assertTrue(Kt57791Kt.foobar(f: false, foo: FooImpl()))
|
||||
}
|
||||
|
||||
class Kt57791Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("testKt57791", testKt57791)
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package library
|
||||
|
||||
fun readDataFromLibraryClass(input: A): String {
|
||||
return input.data
|
||||
}
|
||||
|
||||
fun readDataFromLibraryInterface(input: I): String {
|
||||
return input.data
|
||||
}
|
||||
|
||||
fun readDataFromLibraryEnum(input: E): String {
|
||||
return input.data
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
func testAccessClassFromLibraryWithShortName() throws {
|
||||
|
||||
let object: MyLibraryA = MyLibraryA(data: "Data from Class")
|
||||
let interface: MyLibraryI = MyLibraryA(data: "Data from Interface")
|
||||
let enumObject: MyLibraryE = MyLibraryE.b
|
||||
|
||||
|
||||
let dataFromClass = LibraryKt.readDataFromLibraryClass(input: object)
|
||||
let dataFromInterface = LibraryKt.readDataFromLibraryInterface(input: interface)
|
||||
let dataFromEnum = LibraryKt.readDataFromLibraryEnum(input: enumObject)
|
||||
|
||||
try assertEquals(actual: dataFromClass, expected: "Data from Class")
|
||||
try assertEquals(actual: dataFromInterface, expected: "Data from Interface")
|
||||
try assertEquals(actual: dataFromEnum, expected: "Enum entry B")
|
||||
}
|
||||
|
||||
class LibraryTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("testAccessClassFromLibraryWithShortName", testAccessClassFromLibraryWithShortName)
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package library
|
||||
|
||||
interface I {
|
||||
val data: String
|
||||
}
|
||||
|
||||
class A(override val data: String): I
|
||||
|
||||
enum class E(val data: String) {
|
||||
A("Enum entry A"),
|
||||
B("Enum entry B"),
|
||||
C("Enum entry C")
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
// All classes and methods should be used in tests
|
||||
@file:Suppress("UNUSED")
|
||||
|
||||
package localEA
|
||||
|
||||
class ArraysConstructor {
|
||||
private val memberArray: IntArray
|
||||
constructor(int1: Int, int2: Int) {
|
||||
memberArray = IntArray(2)
|
||||
set(int1, int2)
|
||||
}
|
||||
fun set(int1: Int, int2: Int) {
|
||||
memberArray[0] = int1
|
||||
memberArray[1] = int2
|
||||
}
|
||||
fun log() = "size: ${memberArray.size}, contents: ${memberArray.contentToString()}"
|
||||
}
|
||||
class ArraysDefault {
|
||||
private val memberArray = IntArray(2)
|
||||
constructor(int1: Int, int2: Int) {
|
||||
set(int1, int2)
|
||||
}
|
||||
fun set(int1: Int, int2: Int) {
|
||||
memberArray[0] = int1
|
||||
memberArray[1] = int2
|
||||
}
|
||||
fun log() = "size: ${memberArray.size}, contents: ${memberArray.contentToString()}"
|
||||
}
|
||||
class ArraysInitBlock {
|
||||
private val memberArray : IntArray
|
||||
init {
|
||||
memberArray = IntArray(2)
|
||||
}
|
||||
constructor(int1: Int, int2: Int) {
|
||||
set(int1, int2)
|
||||
}
|
||||
fun set(int1: Int, int2: Int) {
|
||||
memberArray[0] = int1
|
||||
memberArray[1] = int2
|
||||
}
|
||||
fun log() = "size: ${memberArray.size}, contents: ${memberArray.contentToString()}"
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
// -------- Tests --------
|
||||
|
||||
func testArraysEscapeAsParameter() throws {
|
||||
let array1 = ArraysConstructor(int1: 1, int2: 2)
|
||||
try assertEquals(actual: array1.log(), expected: "size: 2, contents: [1, 2]", "Wrong array values in class ArraysConstructor.")
|
||||
array1.set(int1: 3, int2: 4)
|
||||
try assertEquals(actual: array1.log(), expected: "size: 2, contents: [3, 4]", "Wrong array values in class ArraysConstructor.")
|
||||
|
||||
let array2 = ArraysDefault(int1: 1, int2: 2)
|
||||
try assertEquals(actual: array2.log(), expected: "size: 2, contents: [1, 2]", "Wrong array values in class ArraysDefault.")
|
||||
array2.set(int1: 3, int2: 4)
|
||||
try assertEquals(actual: array2.log(), expected: "size: 2, contents: [3, 4]", "Wrong array values in class ArraysDefault.")
|
||||
|
||||
let array3 = ArraysInitBlock(int1: 1, int2: 2)
|
||||
try assertEquals(actual: array3.log(), expected: "size: 2, contents: [1, 2]", "Wrong array values in class ArraysInitBlock.")
|
||||
array3.set(int1: 3, int2: 4)
|
||||
try assertEquals(actual: array3.log(), expected: "size: 2, contents: [3, 4]", "Wrong array values in class ArraysInitBlock.")
|
||||
}
|
||||
|
||||
// -------- Execution of the test --------
|
||||
|
||||
class LocalEATests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("TestArraysEscapeAsParameter", testArraysEscapeAsParameter)
|
||||
}
|
||||
}
|
||||
@@ -1,205 +0,0 @@
|
||||
package noAutorelease
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
import kotlin.native.internal.NativePtr
|
||||
import kotlin.native.ref.WeakReference
|
||||
import kotlin.test.*
|
||||
|
||||
@OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
class KotlinLivenessTracker {
|
||||
val weakRefs = mutableListOf<WeakReference<Any>>()
|
||||
|
||||
fun add(obj: Any?) {
|
||||
assertNotNull(obj)
|
||||
weakRefs += WeakReference(obj)
|
||||
assertFalse(objectsAreDead())
|
||||
}
|
||||
|
||||
fun isEmpty() = weakRefs.isEmpty()
|
||||
fun objectsAreDead() = weakRefs.all { it.value === null }
|
||||
}
|
||||
|
||||
@OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
|
||||
fun gc() = kotlin.native.runtime.GC.collect()
|
||||
|
||||
class KotlinObject
|
||||
|
||||
interface NoAutoreleaseSendHelper {
|
||||
fun sendKotlinObject(kotlinObject: KotlinObject)
|
||||
fun blockReceivingKotlinObject(): (KotlinObject) -> Unit
|
||||
fun sendSwiftObject(swiftObject: Any)
|
||||
fun sendList(list: List<*>)
|
||||
fun sendString(string: String)
|
||||
fun sendNumber(number: Any)
|
||||
fun sendBlock(block: () -> KotlinObject)
|
||||
suspend fun sendCompletion(): Any?
|
||||
}
|
||||
|
||||
interface NoAutoreleaseReceiveHelper {
|
||||
fun receiveKotlinObject(): KotlinObject
|
||||
fun receiveSwiftObject(): Any
|
||||
fun receiveList(): List<*>
|
||||
fun receiveString(): String
|
||||
fun receiveNumber(): Any
|
||||
fun receiveBlock(): () -> KotlinObject
|
||||
}
|
||||
|
||||
class NoAutoreleaseKotlinSendHelper(val kotlinLivenessTracker: KotlinLivenessTracker) : NoAutoreleaseSendHelper {
|
||||
override fun sendKotlinObject(kotlinObject: KotlinObject) = kotlinLivenessTracker.add(kotlinObject)
|
||||
override fun blockReceivingKotlinObject(): (KotlinObject) -> Unit = { kotlinLivenessTracker.add(it) }
|
||||
override fun sendSwiftObject(swiftObject: Any) = kotlinLivenessTracker.add(swiftObject)
|
||||
override fun sendList(list: List<*>) = kotlinLivenessTracker.add(list)
|
||||
override fun sendString(string: String) = kotlinLivenessTracker.add(string)
|
||||
override fun sendNumber(number: Any) = kotlinLivenessTracker.add(number)
|
||||
override fun sendBlock(block: () -> KotlinObject) = kotlinLivenessTracker.add(block)
|
||||
override suspend fun sendCompletion() = suspendCoroutineUninterceptedOrReturn<Any?> { continuation ->
|
||||
kotlinLivenessTracker.add(continuation)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
class NoAutoreleaseKotlinReceiveHelper(val kotlinLivenessTracker: KotlinLivenessTracker) : NoAutoreleaseReceiveHelper {
|
||||
private val kotlinObject = KotlinObject()
|
||||
lateinit var swiftObject: Any
|
||||
private val list = listOf(Any())
|
||||
private val string = Any().toString()
|
||||
private val number = createKotlinNumber()
|
||||
private val block = createLambda(kotlinLivenessTracker)
|
||||
|
||||
override fun receiveKotlinObject(): KotlinObject = kotlinObject.also { kotlinLivenessTracker.add(it) }
|
||||
override fun receiveSwiftObject(): Any = swiftObject.also { kotlinLivenessTracker.add(it) }
|
||||
override fun receiveList(): List<*> = list.also { kotlinLivenessTracker.add(it) }
|
||||
override fun receiveString(): String = string.also { kotlinLivenessTracker.add(it) }
|
||||
override fun receiveNumber(): Any = number.also { kotlinLivenessTracker.add(it) }
|
||||
override fun receiveBlock(): () -> KotlinObject = block.also { kotlinLivenessTracker.add(it) }
|
||||
}
|
||||
|
||||
object NoAutoreleaseSingleton {
|
||||
val x = 1
|
||||
}
|
||||
enum class NoAutoreleaseEnum {
|
||||
ENTRY;
|
||||
|
||||
val x = 2
|
||||
}
|
||||
|
||||
fun callSendKotlinObject(helper: NoAutoreleaseSendHelper, tracker: KotlinLivenessTracker) {
|
||||
val kotlinObject = KotlinObject()
|
||||
|
||||
// Repeating twice to cover possible fast paths after caching something for an object.
|
||||
helper.sendKotlinObject(kotlinObject)
|
||||
helper.sendKotlinObject(kotlinObject)
|
||||
tracker.add(kotlinObject)
|
||||
}
|
||||
|
||||
fun sendKotlinObjectToBlock(helper: NoAutoreleaseSendHelper, tracker: KotlinLivenessTracker) {
|
||||
val kotlinObject = KotlinObject()
|
||||
|
||||
helper.blockReceivingKotlinObject()(kotlinObject)
|
||||
helper.blockReceivingKotlinObject()(kotlinObject)
|
||||
tracker.add(kotlinObject)
|
||||
}
|
||||
|
||||
fun callSendSwiftObject(helper: NoAutoreleaseSendHelper, tracker: KotlinLivenessTracker, swiftObject: Any) {
|
||||
helper.sendSwiftObject(swiftObject)
|
||||
helper.sendSwiftObject(swiftObject)
|
||||
tracker.add(swiftObject)
|
||||
}
|
||||
|
||||
fun callSendList(helper: NoAutoreleaseSendHelper, tracker: KotlinLivenessTracker) {
|
||||
val list = listOf(Any())
|
||||
|
||||
helper.sendList(list)
|
||||
helper.sendList(list)
|
||||
tracker.add(list)
|
||||
}
|
||||
|
||||
fun callSendString(helper: NoAutoreleaseSendHelper, tracker: KotlinLivenessTracker) {
|
||||
val string = Any().toString()
|
||||
|
||||
helper.sendString(string)
|
||||
helper.sendString(string)
|
||||
tracker.add(string)
|
||||
}
|
||||
|
||||
fun callSendNumber(helper: NoAutoreleaseSendHelper, tracker: KotlinLivenessTracker) {
|
||||
val number = createKotlinNumber()
|
||||
|
||||
helper.sendNumber(number)
|
||||
helper.sendNumber(number)
|
||||
tracker.add(number)
|
||||
}
|
||||
|
||||
fun callSendBlock(helper: NoAutoreleaseSendHelper, tracker: KotlinLivenessTracker) {
|
||||
val block = createLambda()
|
||||
|
||||
helper.sendBlock(block)
|
||||
helper.sendBlock(block)
|
||||
tracker.add(block)
|
||||
}
|
||||
|
||||
private class EmptyContinuation : Continuation<Any?> {
|
||||
override val context: CoroutineContext = EmptyCoroutineContext
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
fun callSendCompletion(helper: NoAutoreleaseSendHelper, tracker: KotlinLivenessTracker) {
|
||||
val completion = EmptyContinuation()
|
||||
|
||||
suspend {
|
||||
helper.sendCompletion()
|
||||
helper.sendCompletion()
|
||||
}.startCoroutine(completion)
|
||||
|
||||
tracker.add(completion)
|
||||
}
|
||||
|
||||
fun callReceiveKotlinObject(helper: NoAutoreleaseReceiveHelper, tracker: KotlinLivenessTracker) = repeat(2) {
|
||||
tracker.add(helper.receiveKotlinObject())
|
||||
}
|
||||
|
||||
fun callReceiveSwiftObject(helper: NoAutoreleaseReceiveHelper, tracker: KotlinLivenessTracker) = repeat(2) {
|
||||
tracker.add(helper.receiveSwiftObject())
|
||||
}
|
||||
|
||||
fun callReceiveList(helper: NoAutoreleaseReceiveHelper, tracker: KotlinLivenessTracker) = repeat(2) {
|
||||
tracker.add(helper.receiveList())
|
||||
}
|
||||
|
||||
fun callReceiveString(helper: NoAutoreleaseReceiveHelper, tracker: KotlinLivenessTracker) = repeat(2) {
|
||||
tracker.add(helper.receiveString())
|
||||
}
|
||||
|
||||
fun callReceiveNumber(helper: NoAutoreleaseReceiveHelper, tracker: KotlinLivenessTracker) = repeat(2) {
|
||||
tracker.add(helper.receiveNumber())
|
||||
}
|
||||
|
||||
fun callReceiveBlock(helper: NoAutoreleaseReceiveHelper, tracker: KotlinLivenessTracker) = repeat(2) {
|
||||
tracker.add(helper.receiveBlock())
|
||||
}
|
||||
|
||||
fun callReceiveBlockAndCall(helper: NoAutoreleaseReceiveHelper, tracker: KotlinLivenessTracker) = repeat(2) {
|
||||
tracker.add(helper.receiveBlock()())
|
||||
}
|
||||
|
||||
fun objc_autoreleasePoolPush() = kotlinx.cinterop.objc_autoreleasePoolPush()
|
||||
fun objc_autoreleasePoolPop(handle: NativePtr) = kotlinx.cinterop.objc_autoreleasePoolPop(handle)
|
||||
|
||||
fun useIntArray(array: IntArray) {} // Just to make IntArray available from Swift.
|
||||
|
||||
private fun createLambda(): () -> KotlinObject {
|
||||
val lambdaResult = KotlinObject()
|
||||
return { lambdaResult } // make it capturing thus dynamic.
|
||||
}
|
||||
|
||||
private fun createLambda(kotlinLivenessTracker: KotlinLivenessTracker): () -> KotlinObject {
|
||||
val lambdaResult = KotlinObject()
|
||||
return {
|
||||
val result = lambdaResult // make it capturing thus dynamic.
|
||||
kotlinLivenessTracker.add(result)
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
private fun createKotlinNumber(): Any = (0.5 + Any().hashCode().toDouble()) // to make it dynamic.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user