From 59615f3165b336bdc5c6b5a8747603cf9d5f5e23 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Tue, 3 Dec 2013 22:38:22 +0400 Subject: [PATCH] Makes tests to be runnable both on JVM and TeaVM --- .../{TClassTests.java => ClassTests.java} | 2 +- .../{TObjectTests.java => ObjectTests.java} | 2 +- ...lderTests.java => StringBuilderTests.java} | 10 +++++----- .../{TStringTests.java => StringTests.java} | 2 +- .../{TSystemTests.java => SystemTests.java} | 20 +++++++++---------- .../classlibgen/ClasslibTestGenerator.java | 3 +++ 6 files changed, 21 insertions(+), 18 deletions(-) rename teavm-classlib/src/main/java/org/teavm/classlib/java/lang/{TClassTests.java => ClassTests.java} (97%) rename teavm-classlib/src/main/java/org/teavm/classlib/java/lang/{TObjectTests.java => ObjectTests.java} (97%) rename teavm-classlib/src/main/java/org/teavm/classlib/java/lang/{TStringBuilderTests.java => StringBuilderTests.java} (73%) rename teavm-classlib/src/main/java/org/teavm/classlib/java/lang/{TStringTests.java => StringTests.java} (94%) rename teavm-classlib/src/main/java/org/teavm/classlib/java/lang/{TSystemTests.java => SystemTests.java} (55%) diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TClassTests.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ClassTests.java similarity index 97% rename from teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TClassTests.java rename to teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ClassTests.java index 6a8a88e06..75b79c960 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TClassTests.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ClassTests.java @@ -7,7 +7,7 @@ import org.junit.Test; * * @author Alexey Andreev */ -class TClassTests { +public class ClassTests { @Test public void classNameEvaluated() { assertEquals("java.lang.Object", Object.class.getName()); diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TObjectTests.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ObjectTests.java similarity index 97% rename from teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TObjectTests.java rename to teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ObjectTests.java index 12d0bd07f..b099399f3 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TObjectTests.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ObjectTests.java @@ -7,7 +7,7 @@ import org.junit.Test; * * @author Alexey Andreev */ -class TObjectTests { +public class ObjectTests { @Test public void objectCreated() { Object a = new Object(); diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStringBuilderTests.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/StringBuilderTests.java similarity index 73% rename from teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStringBuilderTests.java rename to teavm-classlib/src/main/java/org/teavm/classlib/java/lang/StringBuilderTests.java index c4b0a54c1..ea6e07815 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStringBuilderTests.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/StringBuilderTests.java @@ -7,30 +7,30 @@ import org.junit.Test; * * @author Alexey Andreev */ -class TStringBuilderTests { +public class StringBuilderTests { public void integerAppended() { - TStringBuilder sb = new TStringBuilder(); + StringBuilder sb = new StringBuilder(); sb.append(23); assertEquals("23", sb.toString()); } @Test public void largeIntegerAppended() { - TStringBuilder sb = new TStringBuilder(); + StringBuilder sb = new StringBuilder(); sb.append(123456); assertEquals("123456", sb.toString()); } @Test public void negativeIntegerAppended() { - TStringBuilder sb = new TStringBuilder(); + StringBuilder sb = new StringBuilder(); sb.append(-23); assertEquals("-23", sb.toString()); } @Test public void maxIntegerAppended() { - TStringBuilder sb = new TStringBuilder(); + StringBuilder sb = new StringBuilder(); sb.append(2147483647); assertEquals("2147483647", sb.toString()); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStringTests.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/StringTests.java similarity index 94% rename from teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStringTests.java rename to teavm-classlib/src/main/java/org/teavm/classlib/java/lang/StringTests.java index bc7a58873..ae2b0a0ea 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStringTests.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/StringTests.java @@ -7,7 +7,7 @@ import org.junit.Test; * * @author Alexey Andreev */ -class TStringTests { +public class StringTests { @Test public void charsExtracted() { String str = "123"; diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TSystemTests.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/SystemTests.java similarity index 55% rename from teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TSystemTests.java rename to teavm-classlib/src/main/java/org/teavm/classlib/java/lang/SystemTests.java index a5e3e484b..136c8f934 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TSystemTests.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/SystemTests.java @@ -7,14 +7,14 @@ import org.junit.Test; * * @author Alexey Andreev */ -class TSystemTests { +public class SystemTests { @Test public void copiesArray() { - TObject a = new TObject(); - TObject b = new TObject(); - TObject[] src = { a, b, a }; - TObject[] dest = new TObject[3]; - TSystem.arraycopy(TObject.wrap(src), 0, TObject.wrap(dest), 0, 3); + Object a = new Object(); + Object b = new Object(); + Object[] src = { a, b, a }; + Object[] dest = new Object[3]; + System.arraycopy(src, 0, dest, 0, 3); assertSame(a, dest[0]); assertSame(b, dest[1]); assertSame(a, dest[2]); @@ -22,21 +22,21 @@ class TSystemTests { @Test(expected = IndexOutOfBoundsException.class) public void failsToCopyArraysWithInvalidIndexes() { - TSystem.arraycopy(TObject.wrap(new TObject[0]), 0, TObject.wrap(new TObject[0]), 0, 1); + System.arraycopy(new Object[0], 0, new TObject[0], 0, 1); } @Test(expected = ArrayStoreException.class) public void failsToCopyArraysWithIncompatibleElements() { - TSystem.arraycopy(TObject.wrap(new TObject[1]), 0, TObject.wrap(new int[1]), 0, 1); + System.arraycopy(new Object[1], 0, new int[1], 0, 1); } @Test(expected = NullPointerException.class) public void failsToCopyFromNullSource() { - TSystem.arraycopy(null, 0, TObject.wrap(new int[1]), 0, 1); + System.arraycopy(null, 0, new int[1], 0, 1); } @Test(expected = NullPointerException.class) public void failsToCopyToNullTarget() { - TSystem.arraycopy(TObject.wrap(new TObject[1]), 0, null, 0, 1); + System.arraycopy(new TObject[1], 0, null, 0, 1); } } diff --git a/teavm-classlib/src/main/java/org/teavm/classlibgen/ClasslibTestGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlibgen/ClasslibTestGenerator.java index 39df36501..abb20ff19 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlibgen/ClasslibTestGenerator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlibgen/ClasslibTestGenerator.java @@ -46,6 +46,9 @@ public class ClasslibTestGenerator { writer = new SourceWriter(naming); renderer = new Renderer(writer, classSource); DependencyChecker dependencyChecker = new DependencyChecker(classSource); + for (int i = 0; i < testClasses.length; ++i) { + testClasses[i] = "org.teavm.classlib." + testClasses[i]; + } for (String testClass : testClasses) { ClassHolder classHolder = classSource.getClassHolder(testClass); findTests(classHolder);