Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion test-app/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ import java.security.MessageDigest

apply plugin: "com.android.application"

def useKotlin = project.hasProperty("useKotlin") && project.ext.useKotlin=="true"
if (useKotlin) {
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
}

def onlyX86 = project.hasProperty("onlyX86")
if (onlyX86) {
println "OnlyX86 build triggered."
Expand Down Expand Up @@ -64,6 +70,7 @@ def METADATA_OUT_PATH = "$projectDir/src/main/assets/metadata"
def pluginsJarLibraries = new LinkedList<String>()
def allJarLibraries = new LinkedList<String>()

def computeKotlinVersion = { -> project.hasProperty("kotlinVersion") ? kotlinVersion : "1.3.41" }
def computeCompileSdkVersion = { -> project.hasProperty("compileSdk") ? compileSdk : 29 }
def computeTargetSdkVersion = { -> project.hasProperty("targetSdk") ? targetSdk : 29 }
def computeBuildToolsVersion = { ->
Expand Down Expand Up @@ -220,6 +227,13 @@ def setAppIdentifier = { ->
}

android {

if (useKotlin) {
kotlinOptions {
jvmTarget = '1.8'
}
}

compileSdkVersion computeCompileSdkVersion()
buildToolsVersion computeBuildToolsVersion()

Expand Down Expand Up @@ -305,6 +319,7 @@ repositories {
dirs pluginDependencies
}
}
mavenCentral()
}

dependencies {
Expand All @@ -325,7 +340,7 @@ dependencies {

println "\t + using android X library androidx.legacy:legacy-support-v4:$androidXLegacyVersion"

implementation "androidx.multidex:multidex:2.0.0"
implementation "androidx.multidex:multidex:2.0.1"
implementation "androidx.legacy:legacy-support-v4:$androidXLegacyVersion"
implementation "androidx.appcompat:appcompat:$androidXAppCompatVersion"
implementation "com.google.android.material:material:$androidXMaterialVersion"
Expand Down Expand Up @@ -364,6 +379,11 @@ dependencies {
implementation project(':runtime')
}

def kotlinVersion = computeKotlinVersion()
if (useKotlin) {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
}

}

////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -686,6 +706,11 @@ task buildMetadata(type: JavaExec) {
def classesDir = "$buildDir/intermediates/javac"
inputs.dir(classesDir)

def kotlinClassesDir = "$buildDir/tmp/kotlin-classes"
if (file(kotlinClassesDir).exists()) {
inputs.dir(kotlinClassesDir)
}

outputs.files("$METADATA_OUT_PATH/treeNodeStream.dat", "$METADATA_OUT_PATH/treeStringsStream.dat", "$METADATA_OUT_PATH/treeValueStream.dat")

doFirst {
Expand All @@ -703,6 +728,15 @@ task buildMetadata(type: JavaExec) {
}
}

if (file(kotlinClassesDir).exists()) {
def kotlinClassesSubDirs = new File(kotlinClassesDir).listFiles()
for (File subDir : kotlinClassesSubDirs) {
if (subDir.getName() == selectedBuildType) {
generatedClasses.add(subDir.getAbsolutePath())
}
}
}

new File("$BUILD_TOOLS_PATH/$MDG_OUTPUT_DIR").withWriter { out ->
out.println "$METADATA_OUT_PATH"
}
Expand Down
7 changes: 6 additions & 1 deletion test-app/app/src/main/assets/app/mainpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ require("./tests/dex-interface-implementation");
require("./tests/testInterfaceImplementation");
require("./tests/testRuntimeImplementedAPIs");
require("./tests/testsInstanceOfOperator");
require("./tests/testReleaseNativeCounterpart");
require("./tests/testReleaseNativeCounterpart");
require("./tests/kotlin/companions/testCompanionObjectsSupport");
require("./tests/kotlin/properties/testPropertiesSupport");
require("./tests/kotlin/delegation/testDelegationSupport");
require("./tests/kotlin/objects/testObjectsSupport");
require("./tests/kotlin/functions/testTopLevelFunctionsSupport");
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
describe("Tests Kotlin companion objects support", function () {
it("Test Kotlin companion object without a name should be supported", function () {
var stringFromCompanion = com.tns.tests.kotlin.companions.KotlinClassWithCompanion.Companion.getStringFromCompanion();
expect(stringFromCompanion).toBe("testCompanion");

var providedStringFromCompanion = com.tns.tests.kotlin.companions.KotlinClassWithCompanion.Companion.getProvidedStringFromCompanion("providedString");
expect(providedStringFromCompanion).toBe("providedString");

var simpleObjectFromCompanion = com.tns.tests.kotlin.companions.KotlinClassWithCompanion.Companion.getSimpleObjectFromCompanion();
expect(simpleObjectFromCompanion.getSomeString()).toBe("test");

var simpleKotlinObject = new com.tns.tests.kotlin.SimpleKotlinObject();
var providedSimpleObjectFromCompanion = com.tns.tests.kotlin.companions.KotlinClassWithCompanion.Companion.getProvidedSimpleObjectFromCompanion(simpleKotlinObject);
expect(simpleKotlinObject.equals(providedSimpleObjectFromCompanion)).toBe(true);

var stringJvmStaticFromCompanion = com.tns.tests.kotlin.companions.KotlinClassWithCompanion.getStringJvmStaticFromCompanion();
expect(stringJvmStaticFromCompanion).toBe("testCompanion");

var providedStringJvmStaticFromCompanion = com.tns.tests.kotlin.companions.KotlinClassWithCompanion.getProvidedStringJvmStaticFromCompanion("providedString");
expect(providedStringJvmStaticFromCompanion).toBe("providedString");
});

it("Test Kotlin named companion object without a name should be supported", function () {
var stringFromCompanion = com.tns.tests.kotlin.companions.KotlinClassWithNamedCompanion.NamedCompanion.getStringFromNamedCompanion();
expect(stringFromCompanion).toBe("testCompanion");

var providedStringFromCompanion = com.tns.tests.kotlin.companions.KotlinClassWithNamedCompanion.NamedCompanion.getProvidedStringFromNamedCompanion("providedString");
expect(providedStringFromCompanion).toBe("providedString");

var simpleObjectFromCompanion = com.tns.tests.kotlin.companions.KotlinClassWithNamedCompanion.NamedCompanion.getSimpleObjectFromNamedCompanion();
expect(simpleObjectFromCompanion.getSomeString()).toBe("test");

var simpleKotlinObject = new com.tns.tests.kotlin.SimpleKotlinObject();
var providedSimpleObjectFromCompanion = com.tns.tests.kotlin.companions.KotlinClassWithNamedCompanion.NamedCompanion.getProvidedSimpleObjectFromNamedCompanion(simpleKotlinObject);
expect(simpleKotlinObject.equals(providedSimpleObjectFromCompanion)).toBe(true);

var stringJvmStaticFromCompanion = com.tns.tests.kotlin.companions.KotlinClassWithNamedCompanion.getStringJvmStaticFromNamedCompanion();
expect(stringJvmStaticFromCompanion).toBe("testCompanion");

var providedStringJvmStaticFromCompanion = com.tns.tests.kotlin.companions.KotlinClassWithNamedCompanion.getProvidedStringJvmStaticFromNamedCompanion("providedString");
expect(providedStringJvmStaticFromCompanion).toBe("providedString");
});


it("Test Kotlin interface companion object without a name should be supported", function () {
var stringFromCompanion = com.tns.tests.kotlin.companions.KotlinInterfaceWithCompanion.Companion.getStringFromCompanion();
expect(stringFromCompanion).toBe("testCompanion");

var providedStringFromCompanion = com.tns.tests.kotlin.companions.KotlinInterfaceWithCompanion.Companion.getProvidedStringFromCompanion("providedString");
expect(providedStringFromCompanion).toBe("providedString");

var simpleObjectFromCompanion = com.tns.tests.kotlin.companions.KotlinInterfaceWithCompanion.Companion.getSimpleObjectFromCompanion();
expect(simpleObjectFromCompanion.getSomeString()).toBe("test");

var simpleKotlinObject = new com.tns.tests.kotlin.SimpleKotlinObject();
var providedSimpleObjectFromCompanion = com.tns.tests.kotlin.companions.KotlinInterfaceWithCompanion.Companion.getProvidedSimpleObjectFromCompanion(simpleKotlinObject);
expect(simpleKotlinObject.equals(providedSimpleObjectFromCompanion)).toBe(true);

var stringJvmStaticFromCompanion = com.tns.tests.kotlin.companions.KotlinInterfaceWithCompanion.getStringJvmStaticFromCompanion();
expect(stringJvmStaticFromCompanion).toBe("testCompanion");

var providedStringJvmStaticFromCompanion = com.tns.tests.kotlin.companions.KotlinInterfaceWithCompanion.getProvidedStringJvmStaticFromCompanion("providedString");
expect(providedStringJvmStaticFromCompanion).toBe("providedString");
});

it("Test Kotlin interface named companion object without a name should be supported", function () {
var stringFromCompanion = com.tns.tests.kotlin.companions.KotlinInterfaceWithNamedCompanion.NamedCompanion.getStringFromNamedCompanion();
expect(stringFromCompanion).toBe("testCompanion");

var providedStringFromCompanion = com.tns.tests.kotlin.companions.KotlinInterfaceWithNamedCompanion.NamedCompanion.getProvidedStringFromNamedCompanion("providedString");
expect(providedStringFromCompanion).toBe("providedString");

var simpleObjectFromCompanion = com.tns.tests.kotlin.companions.KotlinInterfaceWithNamedCompanion.NamedCompanion.getSimpleObjectFromNamedCompanion();
expect(simpleObjectFromCompanion.getSomeString()).toBe("test");

var simpleKotlinObject = new com.tns.tests.kotlin.SimpleKotlinObject();
var providedSimpleObjectFromCompanion = com.tns.tests.kotlin.companions.KotlinInterfaceWithNamedCompanion.NamedCompanion.getProvidedSimpleObjectFromNamedCompanion(simpleKotlinObject);
expect(simpleKotlinObject.equals(providedSimpleObjectFromCompanion)).toBe(true);

var stringJvmStaticFromCompanion = com.tns.tests.kotlin.companions.KotlinInterfaceWithNamedCompanion.getStringJvmStaticFromNamedCompanion();
expect(stringJvmStaticFromCompanion).toBe("testCompanion");

var providedStringJvmStaticFromCompanion = com.tns.tests.kotlin.companions.KotlinInterfaceWithNamedCompanion.getProvidedStringJvmStaticFromNamedCompanion("providedString");
expect(providedStringJvmStaticFromCompanion).toBe("providedString");
});

it("Test Kotlin class whose parent class contains a companion should work", function () {
var child = new com.tns.tests.kotlin.companions.ChildKotlinClass();
var str = child.getStringFromCompanion();
expect(str).toBe("someString");
});

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
describe("Tests Kotlin delegation support", function () {
it("Test Kotlin class implementation delegation should work", function () {
var delegationObject = new com.tns.tests.kotlin.delegation.DelegationClass();
expect(delegationObject.getString()).toBe("some string");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
describe("Tests Kotlin top level functions support", function () {
it("Test Kotlin top level functions in an unnamed class should work", function () {
var res = com.tns.tests.kotlin.functions.TopLevelFunctionsKt.getRandomNumber();
expect(res).toBe(42);
});

it("Test Kotlin top level functions in a named class should work", function () {
var res = com.tns.tests.kotlin.functions.DemoUtils.getRandomString();
expect(res).toBe("42");
});

it("Test Kotlin top level functions in a named multifile class should work", function () {
var res1 = com.tns.tests.kotlin.multifiles.Utils.getNewString();
expect(res1).toBe("new string");

var res2 = com.tns.tests.kotlin.multifiles.Utils.getOldString();
expect(res2).toBe("old string");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe("Tests Kotlin objects support", function () {
it("Test Kotlin object instances should be the same reference", function () {
var kotlinClass = com.tns.tests.kotlin.objects.KotlinSingleton.INSTANCE;
var kotlinClass2 = com.tns.tests.kotlin.objects.KotlinSingleton.INSTANCE;
expect(com.tns.EqualityComparator.areReferencesEqual(kotlinClass, kotlinClass2)).toBe(true);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
describe("Tests Kotlin properties support", function () {
it("Test Kotlin public properties should work", function () {
var kotlinClass = new com.tns.tests.kotlin.properties.KotlinClassWithProperties();

expect(kotlinClass.immutableProperty).toBe("someImmutableProperty");
try{
kotlinClass.immutableProperty = "SHOULD NOT WORK";
fail();
} catch{}

expect(kotlinClass.mutableProperty).toBe("someMutableProperty");
kotlinClass.mutableProperty = "someOtherMutableProperty";
expect(kotlinClass.mutableProperty).toBe("someOtherMutableProperty");
});

it("Test Kotlin private properties should not work", function () {
var kotlinClass = new com.tns.tests.kotlin.properties.KotlinClassWithProperties();

expect(kotlinClass.privateMutableProperty).toBe(undefined);
expect(kotlinClass.privateImmutableProperty).toBe(undefined);
});

it("Test Kotlin internal properties should not work", function () {
var kotlinClass = new com.tns.tests.kotlin.properties.KotlinClassWithProperties();

expect(kotlinClass.internalMutableProperty).toBe(undefined);
expect(kotlinClass.internalImmutableProperty).toBe(undefined);
});

it("Test Kotlin protected properties should work", function () {
var kotlinClass = new (com.tns.tests.kotlin.properties.KotlinClassWithProperties.extend({
getProtectedMutableProperty: function(){
expect(this.super.protectedMutableProperty).toBe("someProtectedMutableProperty");
this.super.protectedMutableProperty = "someOtherProtectedMutableProperty";
expect(this.super.protectedMutableProperty).toBe("someOtherProtectedMutableProperty");
},
getProtectedImmutableProperty: function(){
expect(this.super.protectedImmutableProperty).toBe("someProtectedImmutableProperty");
try{
this.super.protectedImmutableProperty = "SHOULD NOT WORK";
fail();
} catch {}
}
}))();

kotlinClass.getProtectedMutableProperty();
kotlinClass.getProtectedImmutableProperty();
});


it("Test Kotlin property private should not work", function () {
var kotlinClass = new com.tns.tests.kotlin.properties.KotlinClassWithProperties();
try{
kotlinClass.privateSetterProperty = "SHOULD NOT WORK";
fail();
} catch {}
});

it("Test Kotlin boolean property should work", function () {
var kotlinClass = new com.tns.tests.kotlin.properties.KotlinClassWithProperties();

expect(kotlinClass.isMutableBooleanProperty()).toBe(true);
kotlinClass.setMutableBooleanProperty(false);
expect(kotlinClass.isMutableBooleanProperty()).toBe(false);
});

it("Test Kotlin property with complext type should work", function () {
var kotlinClass = new com.tns.tests.kotlin.properties.KotlinClassWithProperties();

expect(kotlinClass.mutablePropertyWithComplexType.someString).toBe("test");

var simpleObject = new com.tns.tests.kotlin.SimpleKotlinObject();
kotlinClass.mutablePropertyWithComplexType = simpleObject;
expect(kotlinClass.mutablePropertyWithComplexType.equals(simpleObject)).toBe(true);
});
});
7 changes: 7 additions & 0 deletions test-app/app/src/main/java/com/tns/EqualityComparator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.tns;

public final class EqualityComparator {
public static boolean areReferencesEqual(Object a, Object b) {
return a == b;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.tns.tests.kotlin

class SimpleKotlinObject {
var someString: String = "test"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.tns.tests.kotlin.companions

abstract class BaseKotlinClassWithCompanion {
companion object {
public fun getString() = "someString"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.tns.tests.kotlin.companions

class ChildKotlinClass : BaseKotlinClassWithCompanion() {
fun getStringFromCompanion() = BaseKotlinClassWithCompanion.getString()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.tns.tests.kotlin.companions

import com.tns.tests.kotlin.SimpleKotlinObject

class KotlinClassWithCompanion {
companion object {
fun getStringFromCompanion(): String = "testCompanion"
fun getProvidedStringFromCompanion(providedString: String) = providedString

fun getSimpleObjectFromCompanion(): SimpleKotlinObject = SimpleKotlinObject()
fun getProvidedSimpleObjectFromCompanion(providedSimpleObject: SimpleKotlinObject) = providedSimpleObject

@JvmStatic fun getStringJvmStaticFromCompanion(): String = "testCompanion"
@JvmStatic fun getProvidedStringJvmStaticFromCompanion(providedString: String) = providedString
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.tns.tests.kotlin.companions

import com.tns.tests.kotlin.SimpleKotlinObject

class KotlinClassWithNamedCompanion {
companion object NamedCompanion {
fun getStringFromNamedCompanion(): String = "testCompanion"
fun getProvidedStringFromNamedCompanion(providedString: String) = providedString

fun getSimpleObjectFromNamedCompanion(): SimpleKotlinObject = SimpleKotlinObject()
fun getProvidedSimpleObjectFromNamedCompanion(providedSimpleObject: SimpleKotlinObject) = providedSimpleObject

@JvmStatic fun getStringJvmStaticFromNamedCompanion(): String = "testCompanion"
@JvmStatic fun getProvidedStringJvmStaticFromNamedCompanion(providedString: String) = providedString
}
}
Loading