More tests added

This commit is contained in:
Alexey Andreev 2013-12-02 17:28:48 +04:00
parent ac0df0ca6b
commit c8528ef91a
8 changed files with 61 additions and 18 deletions

View File

@ -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) {

View File

@ -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;

View File

@ -45,9 +45,4 @@ class TObjectTests {
public void properInstanceDetected() {
assertTrue(Object.class.isInstance(new Object()));
}
@Test
public void alwaysFails() {
fail();
}
}

View File

@ -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());
}
}

View File

@ -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);
}

View File

@ -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();
}

View File

@ -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);

View File

@ -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) {