Skip to content

Commit 531415b

Browse files
committed
Merge pull request #318 from NativeScript/plamen5kov/add_common_tests
Plamen5kov/add common tests
2 parents 5422f57 + 87e2d28 commit 531415b

32 files changed

+151
-345
lines changed

.gitmodules

+6
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@
22
path = android-metadata-generator
33
url = https://github.com/NativeScript/android-metadata-generator.git
44
branch = master
5+
[submodule "test-app/assets/app/shared"]
6+
path = test-app/assets/app/shared
7+
url = [email protected]:NativeScript/common-runtime-tests-app.git
8+
[submodule "test-app/assets/app/tns_modules/shared"]
9+
path = test-app/assets/app/tns_modules/shared
10+
url = [email protected]:NativeScript/common-runtime-tests-modules.git

test-app/assets/app/mainpage.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
__disableVerboseLogging();
22
__log("starting tests");
33

4+
// methods that common tests need to run
5+
var testContent = "";
6+
__collect = gc;
7+
TNSClearOutput = function () {
8+
testContent = "";
9+
}
10+
TNSLog = function (text) {
11+
testContent += text;
12+
}
13+
TNSGetOutput = function () {
14+
return testContent;
15+
}
16+
__approot = __dirname.substr(0, __dirname.length - 4);
17+
18+
require("./shared");
19+
420
require("./tests/testMetadata");
521
require("./tests/testAsserts");
622
require("./tests/testWeakRef");
@@ -21,7 +37,6 @@ require("./tests/testFieldGetSet");
2137
require("./tests/extendedClassesTests");
2238
require("./tests/extendClassNameTests");
2339
require("./tests/testJniReferenceLeak");
24-
require("./tests/testRequireJSON");
2540
require("./tests/testNativeModules");
2641
require("./tests/requireExceptionTests");
2742

test-app/assets/app/module2/file2.js

-1
This file was deleted.

test-app/assets/app/module2/index.js

-1
This file was deleted.

test-app/assets/app/module2/package.json

-4
This file was deleted.

test-app/assets/app/modules/module.js

-21
This file was deleted.

test-app/assets/app/modules/module1.js

-2
This file was deleted.

test-app/assets/app/modules/module2.js

-1
This file was deleted.

test-app/assets/app/modules/module3.js

-1
This file was deleted.
-29 Bytes
Binary file not shown.

test-app/assets/app/modules/mymodule.js

-3
This file was deleted.

test-app/assets/app/modules/package.json

-4
This file was deleted.

test-app/assets/app/modules3/index.js

-1
This file was deleted.

test-app/assets/app/modules3/package.json

-3
This file was deleted.

test-app/assets/app/shared

Submodule shared added at f92acfd

test-app/assets/app/tests/data/badJSON1.json

-1
This file was deleted.

test-app/assets/app/tests/data/badJSON2.json

-1
This file was deleted.

test-app/assets/app/tests/data/data1.json

-1
This file was deleted.

test-app/assets/app/tests/requireExceptionTests.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,20 @@ describe("Tests require exceptions ", function () {
147147
expect(partialMessage).toBe(thrownException);
148148
});
149149

150-
it("when requiring a module with package.json, but with NO 'main' property in it the runtime should look for index.js", function () {
151-
var fromIndexJs = require("~/modules3");
150+
it("TestRequire", function () {
152151

153-
expect(fromIndexJs.value123.toString()).toBe("123");
152+
__log("TEST: TestRequire");
153+
154+
var exceptionCaught = false;
155+
try{
156+
var myModule = require("../simplemodule");
157+
}
158+
catch(e) {
159+
exceptionCaught = true;
160+
}
161+
162+
myModule.myLog("Hello world from NativeScript!");
163+
164+
expect(exceptionCaught).toBe(false);
154165
});
155166
});

test-app/assets/app/tests/testArrays.js

+83-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,32 @@ describe("Tests array operations", function () {
77
beforeEach(function() {
88
jasmine.addCustomEqualityTester(myCustomEquality);
99
});
10-
10+
11+
it("TestWorkingWithJavaArrayDoesNotMakeMemoryLeak", function () {
12+
13+
__log("TEST: TestWorkingWithJavaArrayDoesNotMakeMemoryLeak");
14+
15+
var size = 10 * 1024 * 1024;
16+
17+
for (var i = 0; i < 100; i++) {
18+
19+
var arr = java.lang.reflect.Array.newInstance(java.lang.Byte.class.getField("TYPE").get(null), size);
20+
21+
var length = arr.length;
22+
23+
expect(length).toEqual(size);
24+
25+
arr[0] = 123;
26+
27+
var el = arr[0];
28+
29+
expect(el).toEqual(123);
30+
31+
gc();
32+
java.lang.System.gc();
33+
}
34+
});
35+
1136
it("TestArraySize", function () {
1237

1338
var size = 12345;
@@ -36,4 +61,61 @@ describe("Tests array operations", function () {
3661
}
3762
});
3863

64+
it("TestArrays", function () {
65+
66+
__log("TEST: TestArrays");
67+
68+
var MyButton = com.tns.tests.Button1.extend("MyButton639", {
69+
toString : function() {
70+
return "button1";
71+
}
72+
});
73+
var tester = new MyButton();
74+
var instances = tester.getDummyInstances();
75+
76+
var instanceFound = false;
77+
78+
for (var i = 0; i < instances.length; i++)
79+
{
80+
if (instances[i].getName() == "second");
81+
{
82+
instanceFound = true;
83+
}
84+
}
85+
86+
expect(instanceFound).toEqual(true);
87+
88+
instances[0] = instances[1];
89+
90+
var instances0name = instances[0].getName();
91+
var instances1name = instances[1].getName();
92+
93+
expect(instances0name).toEqual(instances1name);
94+
});
95+
96+
it("TestArrayLengthPropertyIsNumber", function () {
97+
98+
__log("TEST: TestArrayLengthPropertyIsNumber");
99+
100+
var expectedLength = 10;
101+
102+
function getLength(x)
103+
{
104+
var arr = x.getIntArray1(expectedLength);
105+
106+
return arr ? arr.length : 123456;
107+
}
108+
109+
var MyButton = com.tns.tests.Button1.extend("MyButton680", {
110+
toString : function() {
111+
return "button1";
112+
}
113+
});
114+
115+
var count = getLength(new MyButton());
116+
117+
expect(count).toBe(expectedLength);
118+
119+
});
120+
39121
});

test-app/assets/app/tests/testGC.js

+30
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,36 @@ describe("Tests garbage collection", function () {
77
beforeEach(function() {
88
jasmine.addCustomEqualityTester(myCustomEquality);
99
});
10+
11+
it("TestGarbageCollection", function (done) {
12+
var normalTest = function () {
13+
14+
__log("TEST: TestGarbageCollection");
15+
16+
var obj = new com.tns.tests.ClassX();
17+
18+
obj.dummy();
19+
20+
obj = null;
21+
22+
gc();
23+
java.lang.System.gc();
24+
gc();
25+
java.lang.System.gc();
26+
gc();
27+
java.lang.System.gc();
28+
29+
new java.lang.Thread(new java.lang.Runnable("ThreadFunc", {
30+
run: function() {
31+
var isCollected = com.tns.tests.ClassX.IsCollected;
32+
__log('----------> isCollected: ' + isCollected);
33+
expect(isCollected).toBe(true);
34+
done();
35+
}
36+
})).start();
37+
};
38+
normalTest();
39+
});
1040

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

test-app/assets/app/tests/testModules/someDirModule/index.js

-4
This file was deleted.

test-app/assets/app/tests/testModules/testmodule.js

-4
This file was deleted.

test-app/assets/app/tests/testRequireJSON.js

-37
This file was deleted.

0 commit comments

Comments
 (0)