[jboss-svn-commits] JBL Code SVN: r25933 - in labs/jbosstm/workspace/adinn/orchestration: src/org/jboss/jbossts/orchestration/rule/expression and 6 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Apr 3 06:37:08 EDT 2009
Author: adinn
Date: 2009-04-03 06:37:03 -0400 (Fri, 03 Apr 2009)
New Revision: 25933
Added:
labs/jbosstm/workspace/adinn/orchestration/tests/dd/scripts/javaops/
labs/jbosstm/workspace/adinn/orchestration/tests/dd/scripts/javaops/TestArithmetic.txt
labs/jbosstm/workspace/adinn/orchestration/tests/src/org/jboss/jbossts/orchestration/tests/javaops/
labs/jbosstm/workspace/adinn/orchestration/tests/src/org/jboss/jbossts/orchestration/tests/javaops/TestArithmetic.java
Modified:
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Rule.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ArithmeticExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/MinusExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/PlusExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ReturnExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/type/Type.java
labs/jbosstm/workspace/adinn/orchestration/tests/build.xml
labs/jbosstm/workspace/adinn/orchestration/tests/src/org/jboss/jbossts/orchestration/tests/Test.java
Log:
added tests of java arithmetic operations to tests dir and fixed bugs found by them
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Rule.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Rule.java 2009-04-03 10:28:37 UTC (rev 25932)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Rule.java 2009-04-03 10:37:03 UTC (rev 25933)
@@ -140,6 +140,12 @@
*/
private boolean checkFailed;
+ /**
+ * return type of the rule's trigger method
+ */
+
+ private Type returnType;
+
private Rule(String name, String targetClass, String targetMethod,Class<?> helperClass, Location targetLocation, String ruleSpec, ClassLoader loader)
throws ParseException, TypeException, CompileException
{
@@ -175,6 +181,7 @@
triggerMethod = null;
triggerDescriptor = null;
triggerAccess = 0;
+ returnType = null;
}
public TypeGroup getTypeGroup()
@@ -220,6 +227,11 @@
return triggerClass;
}
+ public Type getReturnType()
+ {
+ return returnType;
+ }
+
public static Rule create(String name, String targetClass, String targetMethod, Class<?> helperClass, Location targetLocation, String ruleSpec, ClassLoader loader)
throws ParseException, TypeException, CompileException
{
@@ -372,6 +384,10 @@
binding.setType(paramType);
}
}
+
+ String returnTypeName = Type.parseMethodReturnType(triggerDescriptor);
+
+ returnType = typeGroup.create(returnTypeName);
}
/**
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ArithmeticExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ArithmeticExpression.java 2009-04-03 10:28:37 UTC (rev 25932)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ArithmeticExpression.java 2009-04-03 10:37:03 UTC (rev 25933)
@@ -60,8 +60,20 @@
{
try {
// n.b. be careful with characters here
- Number value1 = (Number)getOperand(0).interpret(helper);
- Number value2 = (Number)getOperand(1).interpret(helper);
+ Object objValue1 = getOperand(0).interpret(helper);
+ Object objValue2 = getOperand(1).interpret(helper);
+ Number value1;
+ Number value2;
+ if (objValue1 instanceof Character) {
+ value1 = new Integer((Character)objValue1);
+ } else {
+ value1 = (Number)objValue1;
+ }
+ if (objValue2 instanceof Character) {
+ value2 = new Integer((Character)objValue2);
+ } else {
+ value2 = (Number)objValue2;
+ }
// type is the result of promoting one or other or both of the operands
// and they should be converted to this type before doing the arithmetic operation
if (type == type.B) {
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/MinusExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/MinusExpression.java 2009-04-03 10:28:37 UTC (rev 25932)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/MinusExpression.java 2009-04-03 10:37:03 UTC (rev 25933)
@@ -54,7 +54,13 @@
public Object interpret(HelperAdapter helper) throws ExecuteException {
try {
- Number value = (Number)getOperand(0).interpret(helper);
+ Object objValue = (Object)getOperand(0).interpret(helper);
+ Number value;
+ if (objValue instanceof Character) {
+ value = new Integer((Character)objValue);
+ } else {
+ value = (Number)objValue;
+ }
if (type == Type.B) {
return (byte)-value.intValue();
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/PlusExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/PlusExpression.java 2009-04-03 10:28:37 UTC (rev 25932)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/PlusExpression.java 2009-04-03 10:37:03 UTC (rev 25933)
@@ -74,6 +74,12 @@
String s2 = (String)value2;
return s1 + s2;
} else {
+ if (value1 instanceof Character) {
+ value1 = new Integer((Character)value1);
+ }
+ if (value2 instanceof Character) {
+ value2 = new Integer((Character)value2);
+ }
Number n1 = (Number)value1;
Number n2 = (Number)value2;
if (type == Type.B) {
@@ -105,7 +111,7 @@
char c1 = (char)n1.intValue();
char c2 = (char)n2.intValue();
char result = (char)(c1 + c2);
- return new Integer(result);
+ return new Character(result);
}
}
}
@@ -131,37 +137,45 @@
// add two strings leaving one string
expected = 1;
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "concat", "(Ljava/lang/String;)Ljava/lang/String;");
+ currentStackHeights.addStackCount(-1);
} else if (type == Type.B) {
// add two bytes leaving one byte
expected = 1;
mv.visitInsn(Opcodes.IADD);
mv.visitInsn(Opcodes.I2B);
+ currentStackHeights.addStackCount(-1);
} else if (type == Type.S ) {
// add two shorts leaving one short
expected = 1;
mv.visitInsn(Opcodes.IADD);
mv.visitInsn(Opcodes.I2S);
+ currentStackHeights.addStackCount(-1);
} else if (type == Type.C) {
// add two chars leaving one char
expected = 1;
mv.visitInsn(Opcodes.IADD);
mv.visitInsn(Opcodes.I2C);
+ currentStackHeights.addStackCount(-1);
} else if (type == Type.I) {
// add two ints leaving one int
expected = 1;
mv.visitInsn(Opcodes.IADD);
+ currentStackHeights.addStackCount(-1);
} else if (type == Type.J) {
// add two longs leaving one long
expected = 1;
mv.visitInsn(Opcodes.LADD);
+ currentStackHeights.addStackCount(-2);
} else if (type == Type.F) {
// add two floats leaving one float
expected = 1;
mv.visitInsn(Opcodes.FADD);
+ currentStackHeights.addStackCount(-1);
} else if (type == Type.D) {
// add two doubles leaving one double
expected = 1;
mv.visitInsn(Opcodes.FADD);
+ currentStackHeights.addStackCount(-2);
}
if (currentStackHeights.stackCount != currentStack + expected) {
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ReturnExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ReturnExpression.java 2009-04-03 10:28:37 UTC (rev 25932)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ReturnExpression.java 2009-04-03 10:37:03 UTC (rev 25933)
@@ -24,6 +24,7 @@
package org.jboss.jbossts.orchestration.rule.expression;
import org.jboss.jbossts.orchestration.rule.binding.Binding;
+import org.jboss.jbossts.orchestration.rule.binding.Bindings;
import org.jboss.jbossts.orchestration.rule.type.Type;
import org.jboss.jbossts.orchestration.rule.exception.TypeException;
import org.jboss.jbossts.orchestration.rule.exception.ExecuteException;
@@ -69,6 +70,7 @@
// ensure the return value expression has all its bindings
return returnValue.bind();
}
+
return true;
}
@@ -85,15 +87,14 @@
*/
public Type typeCheck(Type expected) throws TypeException {
// we need to check the returnValue expression against the type of the trigger method
- Binding returnBinding = getBindings().lookup("$!");
- Type returnBindingType = (returnBinding != null ? returnBinding.getType() : Type.VOID);
- if (returnValue == null && !returnBindingType.isVoid()) {
- throw new TypeException("ReturnExpression.typeCheck : return expression must supply argument when triggered from method with return type " + returnBindingType.getName() + getPos());
+ type = rule.getReturnType();
+ if (returnValue == null && !type.isVoid()) {
+ throw new TypeException("ReturnExpression.typeCheck : return expression must supply argument when triggered from method with return type " + type.getName() + getPos());
} else if (returnValue != null) {
- if (returnBindingType.isVoid()) {
+ if (type.isVoid()) {
throw new TypeException("ReturnExpression.typeCheck : return expression must not supply argument when triggered from void method" + getPos());
}
- returnValue.typeCheck(returnBindingType);
+ returnValue.typeCheck(type);
}
return type;
}
@@ -116,6 +117,51 @@
// catch this and return as appropriate
if (returnValue != null) {
Object value = returnValue.interpret(helper);
+ Type subtype = returnValue.type;
+ if (type.isNumeric()) {
+ // make sure we produce the expected type of numeric
+ if (type == Type.C && subtype != Type.C) {
+ // ok, transform Number to a Character
+ int number = ((Number)value).intValue();
+ value = new Character((char)number);
+ } else if (subtype == Type.C) {
+ // ok, transform Character to a boxed Numeric if necessary
+ char c = ((Character)value).charValue();
+ if (type == Type.B) {
+ value = new Byte((byte)c);
+ } else if (type == Type.S) {
+ value = new Short((short)c);
+ } else if (type == Type.I) {
+ value = new Integer((int)c);
+ } else if (type == Type.J) {
+ value = new Long((int)c);
+ } else if (type == Type.F) {
+ value = new Float((int)c);
+ } else if (type == Type.D) {
+ value = new Double((int)c);
+ }
+ } else {
+ if (type == Type.B && subtype != Type.B) {
+ Number number = (Number)value;
+ value = new Byte(number.byteValue());
+ } else if (type == Type.S && subtype != Type.S) {
+ Number number = (Number)value;
+ value = new Short(number.shortValue());
+ } else if (type == Type.I && subtype != Type.I) {
+ Number number = (Number)value;
+ value = new Integer(number.intValue());
+ } else if (type == Type.J && subtype != Type.J) {
+ Number number = (Number)value;
+ value = new Long(number.longValue());
+ } else if (type == Type.F && subtype != Type.F) {
+ Number number = (Number)value;
+ value = new Float(number.floatValue());
+ } else if (type == Type.D && subtype != Type.D) {
+ Number number = (Number)value;
+ value = new Double(number.doubleValue());
+ }
+ }
+ }
throw new EarlyReturnException("return from " + helper.getName(), value);
} else {
throw new EarlyReturnException("return from " + helper.getName());
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/type/Type.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/type/Type.java 2009-04-03 10:28:37 UTC (rev 25932)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/type/Type.java 2009-04-03 10:37:03 UTC (rev 25933)
@@ -799,6 +799,85 @@
return null;
}
+ public static String parseMethodReturnType(String descriptor)
+ {
+ int length = descriptor.length();
+ int idx = descriptor.indexOf(")");
+ int arrayDepth = 0;
+
+ if (idx < 0) {
+ return "void";
+ }
+ idx = idx + 1;
+ while (idx < length) {
+ char c = descriptor.charAt(idx);
+ switch(c)
+ {
+ case 'Z':
+ {
+ String baseType = "boolean";
+ return fixArrayType(baseType, arrayDepth);
+ }
+ case 'B':
+ {
+ String baseType = "byte";
+ return fixArrayType(baseType, arrayDepth);
+ }
+ case 'S':
+ {
+ String baseType = "short";
+ return fixArrayType(baseType, arrayDepth);
+ }
+ case 'C':
+ {
+ String baseType = "char";
+ return fixArrayType(baseType, arrayDepth);
+ }
+ case 'I':
+ {
+ String baseType = "int";
+ return fixArrayType(baseType, arrayDepth);
+ }
+ case 'J':
+ {
+ String baseType = "long";
+ return fixArrayType(baseType, arrayDepth);
+ }
+ case 'F':
+ {
+ String baseType = "float";
+ return fixArrayType(baseType, arrayDepth);
+ }
+ case 'D':
+ {
+ String baseType = "double";
+ return fixArrayType(baseType, arrayDepth);
+ }
+ case 'V':
+ {
+ return "void";
+ }
+ case 'L':
+ {
+ int endIdx = descriptor.indexOf(';', idx);
+ if (endIdx < 0) {
+ return "void";
+ }
+ String baseType = descriptor.substring(idx+1, endIdx).replaceAll("/", ".");
+ return fixArrayType(baseType, arrayDepth);
+ }
+ case '[':
+ {
+ arrayDepth++;
+ idx++;
+ }
+ default:
+ return "void";
+ }
+ }
+ return "void";
+ }
+
public static String fixArrayType(String baseType, int dimension)
{
String result = baseType;
@@ -970,4 +1049,8 @@
internalNames.put("double", "D");
internalNames.put("void", "V");
}
+ public String toString()
+ {
+ return getName();
+ }
}
Modified: labs/jbosstm/workspace/adinn/orchestration/tests/build.xml
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/tests/build.xml 2009-04-03 10:28:37 UTC (rev 25932)
+++ labs/jbosstm/workspace/adinn/orchestration/tests/build.xml 2009-04-03 10:37:03 UTC (rev 25933)
@@ -71,8 +71,11 @@
<delete dir="${build.dir}"/>
</target>
+ <!--
<target name="tests" depends="jar, tests.location, tests.location.compiled"/>
-
+ -->
+ <target name="tests" depends="jar, tests.location, tests.location.compiled, tests.javaops, tests.javaops.compiled"/>
+
<target name="tests.location">
<junit fork="true" showoutput="true">
<classpath>
@@ -211,4 +214,53 @@
</junit>
</target>
+ <target name="tests.javaops">
+ <junit fork="true" showoutput="true">
+ <classpath>
+ <pathelement location="${build.lib.dir}/orchestration-tests.jar"/>
+ <pathelement location="${junit.home}/${junit.jar}"/>
+ </classpath>
+ <jvmarg value="-javaagent:${toast.home}/${toast.jar}=script:${scripts.dir}/javaops/TestArithmetic.txt"/>
+ <!-- uncomment for verbose toast output
+ <jvmarg value="-Dorg.jboss.jbossts.orchestration.verbose"/>
+ -->
+ <!-- uncomment to dump generated code
+ <jvmarg value="-Dorg.jboss.jbossts.orchestration.dump.generated.classes"/>
+ <jvmarg value="-Dorg.jboss.jbossts.orchestration.dump.generated.classes.directory=dump"/>
+ -->
+ <!-- uncomment to enable debug
+ <jvmarg value="-Xdebug"/>
+ <jvmarg value="-Xnoagent"/>
+ <jvmarg value="-Djava.compiler=NONE"/>
+ <jvmarg value="-Xrunjdwp:transport=dt_socket,server=n,suspend=y,address=5005"/>
+ -->
+ <test name="org.jboss.jbossts.orchestration.tests.javaops.TestArithmetic"/>
+ </junit>
+ </target>
+
+ <target name="tests.javaops.compiled">
+ <junit fork="true" showoutput="true">
+ <classpath>
+ <pathelement location="${build.lib.dir}/orchestration-tests.jar"/>
+ <pathelement location="${junit.home}/${junit.jar}"/>
+ </classpath>
+ <jvmarg value="-javaagent:${toast.home}/${toast.jar}=script:${scripts.dir}/javaops/TestArithmetic.txt"/>
+ <!-- uncomment for verbose toast output
+ <jvmarg value="-Dorg.jboss.jbossts.orchestration.verbose"/>
+ -->
+ <!-- uncomment to dump generated code
+ <jvmarg value="-Dorg.jboss.jbossts.orchestration.dump.generated.classes"/>
+ <jvmarg value="-Dorg.jboss.jbossts.orchestration.dump.generated.classes.directory=dump"/>
+ -->
+ <!-- uncomment to enable debug
+ <jvmarg value="-Xdebug"/>
+ <jvmarg value="-Xnoagent"/>
+ <jvmarg value="-Djava.compiler=NONE"/>
+ <jvmarg value="-Xrunjdwp:transport=dt_socket,server=n,suspend=y,address=5005"/>
+ <jvmarg value="-Dorg.jboss.jbossts.orchestration.compileToBytecode"/>
+ -->
+ <test name="org.jboss.jbossts.orchestration.tests.javaops.TestArithmetic"/>
+ </junit>
+ </target>
+
</project>
Copied: labs/jbosstm/workspace/adinn/orchestration/tests/dd/scripts/javaops/TestArithmetic.txt (from rev 25916, labs/jbosstm/workspace/adinn/orchestration/tests/dd/scripts/location/TestCall.txt)
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/tests/dd/scripts/javaops/TestArithmetic.txt (rev 0)
+++ labs/jbosstm/workspace/adinn/orchestration/tests/dd/scripts/javaops/TestArithmetic.txt 2009-04-03 10:37:03 UTC (rev 25933)
@@ -0,0 +1,87 @@
+RULE test arithmetic plus
+CLASS TestArithmetic
+METHOD triggerMethod1(int,char,short,byte)
+AFTER CALL log
+HELPER org.jboss.jbossts.orchestration.tests.helpers.Default
+BIND test : Test = $0,
+ i : int = $1,
+ c : char = $2,
+ s : short = $3,
+ b : byte = $4
+IF TRUE
+DO test.log("triggerMethod1 : i == " + i),
+ test.log("triggerMethod1 : c == '" + c + "'"),
+ test.log("triggerMethod1 : s == " + s),
+ test.log("triggerMethod1 : b == " + b),
+ test.log("triggerMethod1 : i + 255 == " + (i + 255)),
+ test.log("triggerMethod1 : c + 255 == " + (c + 255)),
+ test.log("triggerMethod1 : s + 255 == " + (s + 255)),
+ test.log("triggerMethod1 : b + 255 == " + (b + 255)),
+ return (s + c)
+ENDRULE
+
+RULE test arithmetic minus
+CLASS TestArithmetic
+METHOD triggerMethod2(int,char,short,byte)
+AFTER CALL log
+HELPER org.jboss.jbossts.orchestration.tests.helpers.Default
+BIND test : Test = $0,
+ i : int = $1,
+ c : char = $2,
+ s : short = $3,
+ b : byte = $4
+IF TRUE
+DO test.log("triggerMethod2 : i == " + i),
+ test.log("triggerMethod2 : c == '" + c + "'"),
+ test.log("triggerMethod2 : s == " + s),
+ test.log("triggerMethod2 : b == " + b),
+ test.log("triggerMethod2 : i - 255 == " + (i - 255)),
+ test.log("triggerMethod2 : c - 255 == " + (c - 255)),
+ test.log("triggerMethod2 : s - 255 == " + (s - 255)),
+ test.log("triggerMethod2 : b - 255 == " + (b - 255)),
+ return (c + c)
+ENDRULE
+
+RULE test arithmetic mod, times and div
+CLASS TestArithmetic
+METHOD triggerMethod3(int,char,short,byte)
+AFTER CALL log
+HELPER org.jboss.jbossts.orchestration.tests.helpers.Default
+BIND test : Test = $0,
+ i : int = $1,
+ c : char = $2,
+ s : short = $3,
+ b : byte = $4
+IF TRUE
+DO test.log("triggerMethod3 : i == " + i),
+ test.log("triggerMethod3 : c == '" + c + "'"),
+ test.log("triggerMethod3 : s == " + s),
+ test.log("triggerMethod3 : b == " + b),
+ test.log("triggerMethod3 : 255 % b == " + (255 % b)),
+ test.log("triggerMethod3 : c / 2 == " + (c / 2)),
+ test.log("triggerMethod3 : s * 1.5 == " + (s * 1.5)),
+ test.log("triggerMethod3 : b * b == " + (b * b)),
+ return (s * b)
+ENDRULE
+
+RULE test arithmetic mod, times and div again
+CLASS TestArithmetic
+METHOD triggerMethod4(int,char,short,byte)
+AFTER CALL log
+HELPER org.jboss.jbossts.orchestration.tests.helpers.Default
+BIND test : Test = $0,
+ i : int = $1,
+ c : char = $2,
+ s : short = $3,
+ b : byte = $4
+IF TRUE
+DO test.log("triggerMethod4 : i == " + i),
+ test.log("triggerMethod4 : c == '" + c + "'"),
+ test.log("triggerMethod4 : s == " + s),
+ test.log("triggerMethod4 : b == " + b),
+ test.log("triggerMethod4 : 255 * b == " + (255 * b)),
+ test.log("triggerMethod4 : c / 0.5 == " + (c / 0.5)),
+ test.log("triggerMethod4 : s * c == " + (s * c)),
+ test.log("triggerMethod4 : b % 0.5 == " + (b % 0.5)),
+ return (c * (b + s))
+ENDRULE
Modified: labs/jbosstm/workspace/adinn/orchestration/tests/src/org/jboss/jbossts/orchestration/tests/Test.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/tests/src/org/jboss/jbossts/orchestration/tests/Test.java 2009-04-03 10:28:37 UTC (rev 25932)
+++ labs/jbosstm/workspace/adinn/orchestration/tests/src/org/jboss/jbossts/orchestration/tests/Test.java 2009-04-03 10:37:03 UTC (rev 25933)
@@ -56,7 +56,9 @@
String output = getOutput();
String expected = getExpected();
if (!output.equals(expected)) {
- fail("\n\nexpecting\n" + expected + "\n\ngot\n" + output);
+ fail("Test " + name + "fail" + "\n\n<expected>\n" + expected + "</expected>\n\n<log>\n" + output +"</log>\n");
+ } else {
+ System.out.println("Test " + name + "success" + "\n\n<log>\n" + output + "</log>\n");
}
if (reset) {
Copied: labs/jbosstm/workspace/adinn/orchestration/tests/src/org/jboss/jbossts/orchestration/tests/javaops/TestArithmetic.java (from rev 25916, labs/jbosstm/workspace/adinn/orchestration/tests/src/org/jboss/jbossts/orchestration/tests/location/TestCall.java)
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/tests/src/org/jboss/jbossts/orchestration/tests/javaops/TestArithmetic.java (rev 0)
+++ labs/jbosstm/workspace/adinn/orchestration/tests/src/org/jboss/jbossts/orchestration/tests/javaops/TestArithmetic.java 2009-04-03 10:37:03 UTC (rev 25933)
@@ -0,0 +1,172 @@
+package org.jboss.jbossts.orchestration.tests.javaops;
+
+import org.jboss.jbossts.orchestration.tests.Test;
+
+/**
+ * Test to ensure at entry trigger points are correctly identified
+ */
+public class TestArithmetic extends Test
+{
+ public TestArithmetic()
+ {
+ super(TestArithmetic.class.getCanonicalName());
+ }
+
+ static int runNumber = 0;
+
+ public void test()
+ {
+ int ires;
+ char cres;
+ short sres;
+ byte bres;
+
+ runNumber = 1;
+ try {
+ log("calling TestArithmetic.triggerMethod1");
+ ires = triggerMethod1(0, '0', (short)99, (byte)0xf);
+ log("called TestArithmetic.triggerMethod1 : result == " + ires);
+ } catch (Exception e) {
+ log(e);
+ }
+
+ checkOutput(true);
+
+ runNumber = 2;
+ try {
+ log("calling TestArithmetic.triggerMethod2");
+ cres = triggerMethod2(0, '0', (short)99, (byte)0xf);
+ log("called TestArithmetic.triggerMethod2 : result == " + cres);
+ } catch (Exception e) {
+ log(e);
+ }
+
+ checkOutput(true);
+
+ runNumber = 3;
+ try {
+ log("calling TestArithmetic.triggerMethod3");
+ sres = triggerMethod3(0, '0', (short)99, (byte)0xf);
+ log("called TestArithmetic.triggerMethod3 : result == " + sres);
+ } catch (Exception e) {
+ log(e);
+ }
+
+ checkOutput(true);
+
+ runNumber = 4;
+ try {
+ log("calling TestArithmetic.triggerMethod4");
+ bres = triggerMethod4(0, '0', (short)99, (byte)0xf);
+ log("called TestArithmetic.triggerMethod4 : result == " + bres);
+ } catch (Exception e) {
+ log(e);
+ }
+
+ checkOutput(true);
+ }
+
+ public int triggerMethod1(int i, char c, short s, byte b)
+ {
+ log("inside TestArithmetic.triggerMethod1");
+ return 0;
+ }
+
+ public char triggerMethod2(int i, char c, short s, byte b)
+ {
+ log("inside TestArithmetic.triggerMethod2");
+ return '0';
+ }
+
+ public short triggerMethod3(int i, char c, short s, byte b)
+ {
+ log("inside TestArithmetic.triggerMethod3");
+ return (short)0;
+ }
+
+ public byte triggerMethod4(int i, char c, short s, byte b)
+ {
+ log("inside TestArithmetic.triggerMethod4");
+ return (byte)0;
+ }
+
+ public float triggerMethod5(int i, char c, short s, byte b, float f, double d)
+ {
+ log("inside TestArithmetic.triggerMethod5");
+ return (byte)0;
+ }
+
+ public double triggerMethod6(int i, char c, short s, byte b, float f, double d)
+ {
+ log("inside TestArithmetic.triggerMethod6");
+ return (byte)0;
+ }
+
+ @Override
+ public String getExpected() {
+ switch (runNumber) {
+ case 1:
+ {
+ logExpected("calling TestArithmetic.triggerMethod1");
+ logExpected("inside TestArithmetic.triggerMethod1");
+ logExpected("triggerMethod1 : i == 0");
+ logExpected("triggerMethod1 : c == '0'");
+ logExpected("triggerMethod1 : s == 99");
+ logExpected("triggerMethod1 : b == 15");
+ logExpected("triggerMethod1 : i + 255 == " + (0 + 255));
+ logExpected("triggerMethod1 : c + 255 == " + ('0' + 255));
+ logExpected("triggerMethod1 : s + 255 == " + ((short)99 + 255));
+ logExpected("triggerMethod1 : b + 255 == " + ((byte)0xf + 255));
+ logExpected("called TestArithmetic.triggerMethod1 : result == " + ((short)99 + '0'));
+ }
+ break;
+ case 2:
+ {
+ logExpected("calling TestArithmetic.triggerMethod2");
+ logExpected("inside TestArithmetic.triggerMethod2");
+ logExpected("triggerMethod2 : i == 0");
+ logExpected("triggerMethod2 : c == '0'");
+ logExpected("triggerMethod2 : s == 99");
+ logExpected("triggerMethod2 : b == 15");
+ logExpected("triggerMethod2 : i - 255 == " + (0 - 255));
+ logExpected("triggerMethod2 : c - 255 == " + ('0' - 255));
+ logExpected("triggerMethod2 : s - 255 == " + ((short)99 - 255));
+ logExpected("triggerMethod2 : b - 255 == " + ((byte)0xf - 255));
+ logExpected("called TestArithmetic.triggerMethod2 : result == " + (char)('0' + '0'));
+ }
+ break;
+ case 3:
+ {
+ logExpected("calling TestArithmetic.triggerMethod3");
+ logExpected("inside TestArithmetic.triggerMethod3");
+ logExpected("triggerMethod3 : i == 0");
+ logExpected("triggerMethod3 : c == '0'");
+ logExpected("triggerMethod3 : s == 99");
+ logExpected("triggerMethod3 : b == 15");
+ logExpected("triggerMethod3 : 255 % b == " + (255 % (byte)0xf));
+ logExpected("triggerMethod3 : c / 2 == " + ('0' / 2));
+ logExpected("triggerMethod3 : s * 1.5 == " + ((short)99 * 1.5));
+ logExpected("triggerMethod3 : b * b == " + ((byte)(0xf * 0xf)));
+ logExpected("called TestArithmetic.triggerMethod3 : result == " + (short)(99 * 0xf));
+ }
+ break;
+ case 4:
+ {
+ logExpected("calling TestArithmetic.triggerMethod4");
+ logExpected("inside TestArithmetic.triggerMethod4");
+ logExpected("triggerMethod4 : i == 0");
+ logExpected("triggerMethod4 : c == '0'");
+ logExpected("triggerMethod4 : s == 99");
+ logExpected("triggerMethod4 : b == 15");
+ logExpected("triggerMethod4 : 255 * b == " + (255 * (byte)0xf));
+ logExpected("triggerMethod4 : c / 0.5 == " + ('0' / 0.5));
+ logExpected("triggerMethod4 : s * c == " + ((short)99 * '0'));
+ logExpected("triggerMethod4 : b % 0.5 == " + (0xf % 0.5));
+ logExpected("called TestArithmetic.triggerMethod4 : result == " + (byte)('0' * (99 + 0xf)));
+ }
+ break;
+ }
+
+ return super.getExpected();
+ }
+}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list