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
1 change: 1 addition & 0 deletions test-app/app/src/main/assets/app/mainpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ require("./tests/testInterfaceImplementation");
require("./tests/testRuntimeImplementedAPIs");
require("./tests/testsInstanceOfOperator");
require("./tests/testReleaseNativeCounterpart");
require("./tests/testJSONObjects");
require("./tests/kotlin/companions/testCompanionObjectsSupport");
require("./tests/kotlin/properties/testPropertiesSupport");
require("./tests/kotlin/delegation/testDelegationSupport");
Expand Down
114 changes: 58 additions & 56 deletions test-app/app/src/main/assets/app/tests/testGC.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
describe("Tests garbage collection", function () {

// Run GC tests only in Full marking mode
let describeFunc = __markingMode == 0 ? describe : xdescribe;

describeFunc("Tests garbage collection", function () {
var myCustomEquality = function(first, second) {
return first == second;
};

beforeEach(function() {
jasmine.addCustomEqualityTester(myCustomEquality);
});

xit("TestGarbageCollection", function (done) {
var normalTest = function () {
var normalTest = function () {

__log("TEST: TestGarbageCollection");

var obj = new com.tns.tests.ClassX();

obj.dummy();

obj = null;

gc();
java.lang.System.gc();
gc();
java.lang.System.gc();
gc();
java.lang.System.gc();

new java.lang.Thread(new java.lang.Runnable("ThreadFunc", {
run: function() {
var isCollected = com.tns.tests.ClassX.IsCollected;
Expand All @@ -37,62 +39,62 @@ describe("Tests garbage collection", function () {
};
normalTest();
});

// this test has implicit assert in com.tns.Runtime.getJavaObjectByID method
it("test1", function () {

function createObjects(name) {
var c1 = new com.tns.tests.Class1();

var cb1 = new com.tns.tests.Class1.Callback1(name, {
getMessage: function() {
var msg = c1.getMessage();
return msg;
}
});

return com.tns.tests.Class1.Class2.printMessageWithDelay(cb1, 5 * 1000);
}

expect(createObjects("Callback5")).toBe(true);
expect(createObjects("Callback26")).toBe(true);

gc();
java.lang.System.gc();
});

// this test has implicit assert in com.tns.Runtime.getJavaObjectByID method
it("test2", function () {

function indref1() {
this.class1 = new com.tns.tests.Class1();
}
indref1.prototype.getMessage = function() {
return "~~~" + this.class1.getMessage();
}

function createObjects(name) {
var c1 = new indref1();

var cb1 = new com.tns.tests.Class1.Callback1(name, {
getMessage: function() {
var msg = c1.getMessage();
return msg;
}
});

return com.tns.tests.Class1.Class2.printMessageWithDelay(cb1, 5 * 1000);
}

expect(createObjects("Callback55")).toBe(true);
expect(createObjects("Callback56")).toBe(true);
gc();
java.lang.System.gc();
});

// this test has implicit assert in com.tns.Runtime.getJavaObjectByID method
it("test3", function () {

function indref2() {
this.helper = new indref2helper();
}
Expand All @@ -105,29 +107,29 @@ describe("Tests garbage collection", function () {
indref2helper.prototype.getMessage = function() {
return "***" + this.class1.getMessage();
}

function createObjects(name) {
var c1 = new indref2();

var cb1 = new com.tns.tests.Class1.Callback1(name, {
getMessage: function() {
var msg = c1.getMessage();
return msg;
}
});

return com.tns.tests.Class1.Class2.printMessageWithDelay(cb1, 5 * 1000);
}

expect(createObjects("Callback91")).toBe(true);
expect(createObjects("Callback92")).toBe(true);
gc();
java.lang.System.gc();
});

// this test has implicit assert in com.tns.Runtime.getJavaObjectByID method
it("test4", function () {

function indref3() {
this.helper = new indref3helper();
}
Expand All @@ -136,97 +138,97 @@ describe("Tests garbage collection", function () {
}
function indref3helper() {
this._class1 = new com.tns.tests.Class1();

Object.defineProperty(this, "class1", {
get: function() {
return this._class1
}
return this._class1
}
});
}
indref3helper.prototype.getMessage = function() {
return "^^^" + this.class1.getMessage();
}
}

function createObjects(name) {
var c1 = new indref3();

var cb1 = new com.tns.tests.Class1.Callback1(name, {
getMessage: function() {
var msg = c1.getMessage();
return msg;
}
});

return com.tns.tests.Class1.Class2.printMessageWithDelay(cb1, 5 * 1000);
}

expect(createObjects("Callback1133")).toBe(true);
expect(createObjects("Callback1134")).toBe(true);
gc();
java.lang.System.gc();
});

// this test has implicit assert in com.tns.Runtime.getJavaObjectByID method
//originally test was commented out
xit("test5", function () {

function indref4() {
this.helper = new indref4helper();
}
indref4.prototype.getMessage = function() {
return "&&&" + this.helper.getMessageZZZ();
}
function indref4helper() {
function indref4helper() {
var _class1 = new com.tns.tests.Class1();

__log("indref4helper _class1=" + _class1);

Object.defineProperty(this, "class1", {
get: function() {
return _class1
return _class1
}
,enumerable: false
});
}
indref4helper.prototype.getMessageZZZ = function() {
return "```" + this.class1.getMessage();
}

function createObjects(name) {
var c1 = new indref4();

var cb1 = new com.tns.tests.Class1.Callback1(name, {
getMessage: function() {
var msg = c1.getMessage();
return msg;
}
});

return com.tns.tests.Class1.Class2.printMessageWithDelay(cb1, 5 * 1000);
}

expect(createObjects("Callback1178")).toBe(true);
expect(createObjects("Callback1179")).toBe(true);
gc();
java.lang.System.gc();
});

it("testAccessingStringFieldWontLeak", function () {

__log("TEST: testAccessingStringFieldWontLeak");

var dummy = new com.tns.tests.DummyClass();

for (var i=0; i<10000; i++)
{
var name = dummy.nameField;

expect(name).toBe("dummy");
}
});

xit("should persist JavaScript object when it reappears after GC", function () {

function getObject() {
var o = new java.lang.Object();
o.x = 123;
Expand Down Expand Up @@ -287,7 +289,7 @@ describe("Tests garbage collection", function () {
gc();
java.lang.System.gc();
})

it("should properly reintroduce Java object back in a callback", function () {
function getTestObject() {
return new com.tns.tests.BadEqualsTest(
Expand All @@ -300,19 +302,19 @@ describe("Tests garbage collection", function () {
}

var test = getTestObject();

// flush LRU cache
for (var i=0; i<65536; i++) {
new java.lang.Object().hashCode();
}

gc();
java.lang.Runtime.getRuntime().gc();
gc();
java.lang.Runtime.getRuntime().gc();
gc();
java.lang.Runtime.getRuntime().gc();

test.postCallback();
});
});
62 changes: 62 additions & 0 deletions test-app/app/src/main/assets/app/tests/testJSONObjects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
describe("Test JSONObject conversions", () => {
it("org.json.JSONObject.from method is defined", () => {
expect(typeof org.json.JSONObject.from).toBe("function");
});

it("JSONObject.from takes at least one argument", () => {
expect(() => org.json.JSONObject.from()).toThrowError();
});

it("JSONObject.from with boolean", () => {
let param = true;
let actual = org.json.JSONObject.from(param);
expect(actual).toBe(param);
});

it("JSONObject.from with string", () => {
let param = "some param";
let actual = org.json.JSONObject.from(param);
expect(actual).toBe(param);
});

it("JSONObject.from with number", () => {
let param = 123;
let actual = org.json.JSONObject.from(param);
expect(actual).toBe(param);
});

it("JSONObject.from with date must serialize it to JSON using ISO8601", () => {
let timestamp = 1570696661136;
let param = new Date(timestamp);
let actual = org.json.JSONObject.from(param);
expect(actual).toBe("2019-10-10T08:37:41.136Z");
});

it("JSONObject.from with object", () => {
let param = {
prop1: "prop1 value",
prop2: 123,
prop3: {
prop4: "prop 4 value"
}
};
let actual = org.json.JSONObject.from(param);
expect(actual instanceof org.json.JSONObject).toBe(true);
let actualStr = com.tns.tests.JSONObjectMethods.testWithObject(actual);
expect(actualStr).toBe(`{"prop1":"prop1 value","prop2":123,"prop3":{"prop4":"prop 4 value"}}`);
});

it("JSONObject.from with array", () => {
let param = [{
prop1: "item 1, prop1 value",
prop2: 123
}, {
prop1: "item 2, prop1 value",
prop2: 456
}];
let actual = org.json.JSONObject.from(param);
expect(actual instanceof org.json.JSONArray).toBe(true);
let actualStr = com.tns.tests.JSONObjectMethods.testWithArray(actual);
expect(actualStr).toBe(`[{"prop1":"item 1, prop1 value","prop2":123},{"prop1":"item 2, prop1 value","prop2":456}]`);
});
});
14 changes: 14 additions & 0 deletions test-app/app/src/main/java/com/tns/tests/JSONObjectMethods.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.tns.tests;

import org.json.JSONArray;
import org.json.JSONObject;

public class JSONObjectMethods {
public static String testWithObject(JSONObject obj) {
return obj.toString();
}

public static String testWithArray(JSONArray obj) {
return obj.toString();
}
}
Loading