diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ObjectNativeGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ObjectNativeGenerator.java index 2aa1324db..bea3584b3 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ObjectNativeGenerator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ObjectNativeGenerator.java @@ -104,7 +104,7 @@ public class ObjectNativeGenerator implements Generator, DependencyPlugin { } private void generateWrap(GeneratorContext context, SourceWriter writer) { - writer.append("return ").append(context.getParameterName(1)); + writer.append("return ").append(context.getParameterName(1)).append(";").newLine(); } private void achieveWrap(DependencyChecker checker, MethodReference method) { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java index a45610a78..a34435d0e 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java @@ -47,7 +47,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable { } else { int pos = 10; int sz = 1; - while (pos <= 1000000000 && pos <= value) { + while (pos < 1000000000 && pos * 10 <= value) { pos *= 10; ++sz; } @@ -58,7 +58,6 @@ class TAbstractStringBuilder extends TObject implements TSerializable { if (!positive) { buffer[length++] = '-'; } - pos /= 10; while (pos > 0) { buffer[length++] = (char)('0' + value / pos); value %= pos; 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/TObjectTests.java index 141fb8809..12d0bd07f 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/TObjectTests.java @@ -45,9 +45,4 @@ class TObjectTests { public void properInstanceDetected() { assertTrue(Object.class.isInstance(new Object())); } - - @Test - public void alwaysFails() { - fail(); - } } 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/TStringBuilderTests.java index c84b43059..c4b0a54c1 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/TStringBuilderTests.java @@ -8,10 +8,30 @@ import org.junit.Test; * @author Alexey Andreev */ class TStringBuilderTests { - @Test public void integerAppended() { TStringBuilder sb = new TStringBuilder(); sb.append(23); assertEquals("23", sb.toString()); } + + @Test + public void largeIntegerAppended() { + TStringBuilder sb = new TStringBuilder(); + sb.append(123456); + assertEquals("123456", sb.toString()); + } + + @Test + public void negativeIntegerAppended() { + TStringBuilder sb = new TStringBuilder(); + sb.append(-23); + assertEquals("-23", sb.toString()); + } + + @Test + public void maxIntegerAppended() { + TStringBuilder sb = new TStringBuilder(); + sb.append(2147483647); + assertEquals("2147483647", sb.toString()); + } } 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/TSystemTests.java index 83083a36a..4598b8029 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/TSystemTests.java @@ -20,12 +20,12 @@ class TSystemTests { assertSame(a, dest[2]); } - @Test + @Test(expected = IndexOutOfBoundsException.class) public void failsToCopyArraysWithInvalidIndexes() { TSystem.arraycopy(TObject.wrap(new TObject[0]), 0, TObject.wrap(new TObject[0]), 0, 1); } - @Test + @Test(expected = ArrayStoreException.class) public void failsToCopyArraysWithIncompatibleElements() { TSystem.arraycopy(TObject.wrap(new TObject[1]), 0, TObject.wrap(new int[1]), 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 53833f742..9be96d44e 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlibgen/ClasslibTestGenerator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlibgen/ClasslibTestGenerator.java @@ -119,7 +119,16 @@ public class ClasslibTestGenerator { for (MethodReference method : methods) { writer.append("runTestCase(").appendClass(cls.getName()).append(".").appendMethod(cons) .append("(), \"" + method.getDescriptor().getName() + "\", \"").appendMethod(method) - .append("\");").newLine(); + .append("\", ["); + MethodHolder methodHolder = classSource.getClassHolder(method.getClassName()).getMethod( + method.getDescriptor()); + AnnotationHolder annot = methodHolder.getAnnotations().get("org.junit.Test"); + AnnotationValue expectedAnnot = annot.getValues().get("expected"); + if (expectedAnnot != null) { + String className = ((ValueType.Object)expectedAnnot.getJavaClass()).getClassName(); + writer.appendClass(className); + } + writer.append("]);").newLine(); } writer.outdent().append("})").newLine(); } diff --git a/teavm-classlib/src/main/resources/org/teavm/classlib/junit-support.js b/teavm-classlib/src/main/resources/org/teavm/classlib/junit-support.js index 62981a432..873dc434d 100644 --- a/teavm-classlib/src/main/resources/org/teavm/classlib/junit-support.js +++ b/teavm-classlib/src/main/resources/org/teavm/classlib/junit-support.js @@ -1,6 +1,6 @@ currentTestReportBody = null; -runTestCase = function(instance, methodName, realMethodName) { +runTestCase = function(instance, methodName, realMethodName, expectedExceptions) { var row = document.createElement("tr"); currentTestReportBody.appendChild(row); var nameCell = document.createElement("td"); @@ -12,15 +12,34 @@ runTestCase = function(instance, methodName, realMethodName) { row.appendChild(exceptionCell); try { instance[realMethodName](); - statusCell.appendChild(document.createTextNode("ok")); + if (expectedExceptions.length > 0) { + statusCell.appendChild(document.createTextNode("expected exception not thrown")); + } else { + statusCell.appendChild(document.createTextNode("ok")); + } } catch (e) { - statusCell.appendChild(document.createTextNode("unexpected exception")); - var exceptionText = document.createElement("pre"); - exceptionText.appendChild(document.createTextNode(e.stack)); - exceptionCell.appendChild(exceptionText); + if (isExpectedException(e, expectedExceptions)) { + statusCell.appendChild(document.createTextNode("ok")); + } else { + statusCell.appendChild(document.createTextNode("unexpected exception")); + var exceptionText = document.createElement("pre"); + exceptionText.appendChild(document.createTextNode(e.stack)); + exceptionCell.appendChild(exceptionText); + } } } +isExpectedException = function(e, expectedExceptions) { + if (e.$javaException !== undefined) { + for (var i = 0; i < expectedExceptions.length; ++i) { + if (expectedExceptions[i] === e.$javaException.$class) { + return true; + } + } + } + return false; +} + testClass = function(className, classTests) { var table = document.createElement("table"); document.body.appendChild(table); diff --git a/teavm-core/src/main/java/org/teavm/parsing/ProgramParser.java b/teavm-core/src/main/java/org/teavm/parsing/ProgramParser.java index 6b3607c64..74b5e3228 100644 --- a/teavm-core/src/main/java/org/teavm/parsing/ProgramParser.java +++ b/teavm-core/src/main/java/org/teavm/parsing/ProgramParser.java @@ -496,6 +496,7 @@ public class ProgramParser { NegateInstruction insn = new NegateInstruction(operandType); insn.setOperand(getVariable(operand)); insn.setReceiver(getVariable(receiver)); + builder.add(insn); } private void emitCast(ValueType targetType, int value, int result) {