Commit bd6c3376 authored by René Schöne's avatar René Schöne
Browse files

Testing default only write.

- base: fixed bug when multiple dependency definitions have same source (used to generate multiple getter/setter)
- added test case for writing all supported types for default mapping definitions
- inherited attributes for token-attributes are not supported (because no "$token_reset()" is generated by JastAdd)
- added short test descriptions
parent 5a7f81e3
Pipeline #6834 passed with stage
in 2 minutes and 11 seconds
......@@ -15,6 +15,10 @@ aspect Navigation {
syn boolean Component.isTypeComponent() = false;
eq TypeComponent.isTypeComponent() = true;
// --- asTypeComponent (should be in preprocessor) ---
syn TypeComponent Component.asTypeComponent() = null;
eq TypeComponent.asTypeComponent() = this;
// --- isWriteToMqttDefinition ---
syn boolean UpdateDefinition.isWriteToMqttDefinition() = false;
eq WriteToMqttDefinition.isWriteToMqttDefinition() = true;
......@@ -38,4 +42,10 @@ aspect Navigation {
// --- isDefaultMappingDefinition ---
syn boolean MappingDefinition.isDefaultMappingDefinition() = false;
eq DefaultMappingDefinition.isDefaultMappingDefinition() = true;
// --- allTokenComponents ---
coll java.util.Set<TokenComponent> Program.allTokenComponents() [new java.util.HashSet<>()] root Program;
TokenComponent contributes this
to Program.allTokenComponents()
for program();
}
......@@ -101,6 +101,9 @@ aspect AspectGeneration {
for (DependencyDefinition def : getDependencyDefinitionList()) {
def.generateAspect(sb);
}
for (TokenComponent token : getProgram().allTokenComponents()) {
token.generateAspect(sb);
}
sb.append("}\n");
}
......@@ -235,27 +238,40 @@ aspect AspectGeneration {
.append(dependencyMethod()).append("(").append(sourceParentTypeName).append(" source) {\n");
sb.append(ind(2)).append("add").append(internalRelationPrefix()).append("Source(source);\n");
sb.append(ind(1)).append("}\n\n");
}
void TokenComponent.generateAspect(StringBuilder sb) {
if (getDependencySourceDefinitionList().isEmpty()) { return; }
String parentTypeName = containingTypeDecl().getName();
// virtual setter
sb.append(ind(1)).append("public ").append(sourceParentTypeName).append(" ")
.append(sourceParentTypeName).append(".set").append(getSource().getName()).append("(");
getSource().getJavaTypeUse().generateAbstractGrammar(sb);
sb.append(ind(1)).append("public ").append(parentTypeName).append(" ")
.append(parentTypeName).append(".set").append(getName()).append("(");
getJavaTypeUse().generateAbstractGrammar(sb);
sb.append(" value) {\n");
sb.append(ind(2)).append("set").append(internalTokenName()).append("(value);\n");
sb.append(ind(2)).append("for (").append(targetParentTypeName).append(" target : get")
.append(internalRelationPrefix()).append("TargetList()) {\n");
sb.append(ind(3)).append("if (target.").append(targetUpdateDefinition().updateMethod()).append("()) {\n");
sb.append(ind(4)).append("target.").append(targetUpdateDefinition().writeMethod()).append("();\n");
sb.append(ind(3)).append("}\n");
sb.append(ind(2)).append("}\n");
sb.append(ind(2)).append("set").append(internalName()).append("(value);\n");
for (DependencyDefinition dependencyDefinition : getDependencySourceDefinitionList()) {
String targetParentTypeName = dependencyDefinition.getTarget().containingTypeDecl().getName();
sb.append(ind(2)).append("for (").append(targetParentTypeName).append(" target : get")
.append(dependencyDefinition.internalRelationPrefix()).append("TargetList()) {\n");
sb.append(ind(3)).append("if (target.")
.append(dependencyDefinition.targetUpdateDefinition().updateMethod())
.append("()) {\n");
sb.append(ind(4)).append("target.")
.append(dependencyDefinition.targetUpdateDefinition().writeMethod())
.append("();\n");
sb.append(ind(3)).append("}\n");
sb.append(ind(2)).append("}\n");
}
sb.append(ind(2)).append("return this;\n");
sb.append(ind(1)).append("}\n\n");
// virtual getter
sb.append(ind(1)).append("public ");
getSource().getJavaTypeUse().generateAbstractGrammar(sb);
sb.append(" ").append(sourceParentTypeName).append(".get").append(getSource().getName()).append("() {\n");
sb.append(ind(2)).append("return get").append(internalTokenName()).append("();\n");
getJavaTypeUse().generateAbstractGrammar(sb);
sb.append(" ").append(parentTypeName).append(".get").append(getName()).append("() {\n");
sb.append(ind(2)).append("return get").append(internalName()).append("();\n");
sb.append(ind(1)).append("}\n\n");
}
}
......
......@@ -73,7 +73,6 @@ task preprocessExampleTest(type: JavaExec, group: 'verification') {
}
task compileExampleTest(type: RelastTest) {
verbose = true
useJastAddNames = true
jastAddList = 'JastAddList'
relastFiles 'src/test/02-after-ros2rag/example/Grammar.relast'
......@@ -106,7 +105,6 @@ task preprocessDefaultOnlyReadTest(type: JavaExec, group: 'verification') {
}
task compileDefaultOnlyReadTest(type: RelastTest) {
verbose = true
useJastAddNames = true
jastAddList = 'JastAddList'
relastFiles 'src/test/02-after-ros2rag/defaultOnlyRead/Grammar.relast'
......@@ -119,6 +117,38 @@ task compileDefaultOnlyReadTest(type: RelastTest) {
test.dependsOn compileDefaultOnlyReadTest
compileDefaultOnlyReadTest.dependsOn preprocessDefaultOnlyReadTest
// --- Test: default-only-write ---
task preprocessDefaultOnlyWriteTest(type: JavaExec, group: 'verification') {
doFirst {
delete 'src/test/02-after-ros2rag/defaultOnlyWrite/Grammar.relast',
'src/test/02-after-ros2rag/defaultOnlyWrite/MqttUpdater.java',
'src/test/02-after-ros2rag/defaultOnlyWrite/ROS2RAG.jadd'
}
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.ros2rag.compiler.Compiler'
//noinspection GroovyAssignabilityCheck
args '--outputDir=src/test/02-after-ros2rag/defaultOnlyWrite',
'--inputGrammar=src/test/01-input/defaultOnlyWrite/Example.relast',
'--inputRos2Rag=src/test/01-input/defaultOnlyWrite/Example.ros2rag',
'--rootNode=A',
'--verbose'
}
task compileDefaultOnlyWriteTest(type: RelastTest) {
useJastAddNames = true
jastAddList = 'JastAddList'
relastFiles 'src/test/02-after-ros2rag/defaultOnlyWrite/Grammar.relast'
grammarName = 'src/test/03-after-relast/defaultOnlyWrite/defaultOnlyWrite'
packageName = 'defaultOnlyWrite.ast'
moreInputFiles 'src/test/01-input/defaultOnlyWrite/Example.jadd',
'src/test/02-after-ros2rag/defaultOnlyWrite/MqttUpdater.jadd',
'src/test/02-after-ros2rag/defaultOnlyWrite/ROS2RAG.jadd'
}
test.dependsOn compileDefaultOnlyWriteTest
compileDefaultOnlyWriteTest.dependsOn preprocessDefaultOnlyWriteTest
clean {
delete 'src/test/02-after-ros2rag/*/', 'src/test/03-after-relast/*/'
}
# Default Only Read
Idea: Use only `ReadFromMqttDefinition`, test all default mapping definitions from `byte[]` to primitive (and boxed) types
aspect Computation {
// native types, synthesized
syn int NativeTypesSyn.getIntValue() = Integer.parseInt(getDriverSyn());
syn short NativeTypesSyn.getShortValue() = Short.parseShort(getDriverSyn());
syn long NativeTypesSyn.getLongValue() = Long.parseLong(getDriverSyn());
syn float NativeTypesSyn.getFloatValue() = Float.parseFloat(getDriverSyn());
syn double NativeTypesSyn.getDoubleValue() = Double.parseDouble(getDriverSyn());
syn char NativeTypesSyn.getCharValue() = getDriverSyn().charAt(0);
syn String NativeTypesSyn.getStringValue() = new String(getDriverSyn());
// boxed types, synthesized
syn Integer BoxedTypesSyn.getIntValue() = Integer.valueOf(getDriverSyn());
syn Short BoxedTypesSyn.getShortValue() = Short.valueOf(getDriverSyn());
syn Long BoxedTypesSyn.getLongValue() = Long.valueOf(getDriverSyn());
syn Float BoxedTypesSyn.getFloatValue() = Float.valueOf(getDriverSyn());
syn Double BoxedTypesSyn.getDoubleValue() = Double.valueOf(getDriverSyn());
syn Character BoxedTypesSyn.getCharValue() = getDriverSyn().charAt(0);
// --- inherited attributes not supported ---
// // native types, inherited
// inh int NativeTypesInh.getIntValue();
// eq A.getNativeTypesInh().getIntValue() = Integer.parseInt(getDriverInh());
// inh short NativeTypesInh.getShortValue();
// eq A.getNativeTypesInh().getShortValue() = Short.parseShort(getDriverInh());
// inh long NativeTypesInh.getLongValue();
// eq A.getNativeTypesInh().getLongValue() = Long.parseLong(getDriverInh());
// inh float NativeTypesInh.getFloatValue();
// eq A.getNativeTypesInh().getFloatValue() = Float.parseFloat(getDriverInh());
// inh double NativeTypesInh.getDoubleValue();
// eq A.getNativeTypesInh().getDoubleValue() = Double.parseDouble(getDriverInh());
// inh char NativeTypesInh.getCharValue();
// eq A.getNativeTypesInh().getCharValue() = getDriverInh().charAt(0);
// inh String NativeTypesInh.getStringValue();
// eq A.getNativeTypesInh().getStringValue() = new String(getDriverInh());
//
// // boxed types, inherited
// inh Integer BoxedTypesInh.getIntValue();
// eq A.getBoxedTypesInh().getIntValue() = Integer.valueOf(getDriverInh());
// inh Short BoxedTypesInh.getShortValue();
// eq A.getBoxedTypesInh().getShortValue() = Short.valueOf(getDriverInh());
// inh Long BoxedTypesInh.getLongValue();
// eq A.getBoxedTypesInh().getLongValue() = Long.valueOf(getDriverInh());
// inh Float BoxedTypesInh.getFloatValue();
// eq A.getBoxedTypesInh().getFloatValue() = Float.valueOf(getDriverInh());
// inh Double BoxedTypesInh.getDoubleValue();
// eq A.getBoxedTypesInh().getDoubleValue() = Double.valueOf(getDriverInh());
// inh Character BoxedTypesInh.getCharValue();
// eq A.getBoxedTypesInh().getCharValue() = getDriverInh().charAt(0);
}
A ::= NativeTypesSyn* BoxedTypesSyn* <DriverInh:String>;
// native types, synthesized
NativeTypesSyn ::= <DriverSyn:String> /<IntValue:int>/ /<ShortValue:short>/ /<LongValue:long>/ /<FloatValue:float>/ /<DoubleValue:double>/ /<CharValue:char>/ /<StringValue:String>/ ;
// boxed types, synthesized
BoxedTypesSyn ::= <DriverSyn:String> /<IntValue:Integer>/ /<ShortValue:Short>/ /<LongValue:Long>/ /<FloatValue:Float>/ /<DoubleValue:Double>/ /<CharValue:Character>/ ;
// --- inherited attributes not supported ---
//// native types, inherited
//NativeTypesInh ::= /<IntValue:int>/ /<ShortValue:short>/ /<LongValue:long>/ /<FloatValue:float>/ /<DoubleValue:double>/ /<CharValue:char>/ /<StringValue:String>/ ;
//// boxed types, inherited
//BoxedTypesInh ::= /<IntValue:Integer>/ /<ShortValue:Short>/ /<LongValue:Long>/ /<FloatValue:Float>/ /<DoubleValue:Double>/ /<CharValue:Character>/ ;
// --- update definitions ---
// native types, synthesized
write NativeTypesSyn.IntValue;
write NativeTypesSyn.ShortValue;
write NativeTypesSyn.LongValue;
write NativeTypesSyn.FloatValue;
write NativeTypesSyn.DoubleValue;
write NativeTypesSyn.CharValue;
write NativeTypesSyn.StringValue;
// boxed types, synthesized
write BoxedTypesSyn.IntValue;
write BoxedTypesSyn.ShortValue;
write BoxedTypesSyn.LongValue;
write BoxedTypesSyn.FloatValue;
write BoxedTypesSyn.DoubleValue;
write BoxedTypesSyn.CharValue;
// --- dependency definitions ---
NativeTypesSyn.IntValue canDependOn NativeTypesSyn.DriverSyn as nativeIntDependency;
NativeTypesSyn.ShortValue canDependOn NativeTypesSyn.DriverSyn as nativeShortDependency;
NativeTypesSyn.LongValue canDependOn NativeTypesSyn.DriverSyn as nativeLongDependency;
NativeTypesSyn.FloatValue canDependOn NativeTypesSyn.DriverSyn as nativeFloatDependency;
NativeTypesSyn.DoubleValue canDependOn NativeTypesSyn.DriverSyn as nativeDoubleDependency;
NativeTypesSyn.CharValue canDependOn NativeTypesSyn.DriverSyn as nativeCharDependency;
NativeTypesSyn.StringValue canDependOn NativeTypesSyn.DriverSyn as nativeStringDependency;
BoxedTypesSyn.IntValue canDependOn BoxedTypesSyn.DriverSyn as boxedIntDependency;
BoxedTypesSyn.ShortValue canDependOn BoxedTypesSyn.DriverSyn as boxedShortDependency;
BoxedTypesSyn.LongValue canDependOn BoxedTypesSyn.DriverSyn as boxedLongDependency;
BoxedTypesSyn.FloatValue canDependOn BoxedTypesSyn.DriverSyn as boxedFloatDependency;
BoxedTypesSyn.DoubleValue canDependOn BoxedTypesSyn.DriverSyn as boxedDoubleDependency;
BoxedTypesSyn.CharValue canDependOn BoxedTypesSyn.DriverSyn as boxedCharDependency;
// --- inherited attributes not supported ---
//// native types, inherited
//write NativeTypesInh.IntValue;
//write NativeTypesInh.ShortValue;
//write NativeTypesInh.LongValue;
//write NativeTypesInh.FloatValue;
//write NativeTypesInh.DoubleValue;
//write NativeTypesInh.CharValue;
//write NativeTypesInh.StringValue;
//
//// boxed types, inherited
//write BoxedTypesInh.IntValue;
//write BoxedTypesInh.ShortValue;
//write BoxedTypesInh.LongValue;
//write BoxedTypesInh.FloatValue;
//write BoxedTypesInh.DoubleValue;
//write BoxedTypesInh.CharValue;
# Default Only Write
Idea: Use only `WriteToMqttDefintion`, test all default mapping definitions from primitive (and boxed) types to `byte[]`.
# Example
Idea: Use the motivating example from our paper as a test case, including one read, one write update definition
package org.jastadd.ros2rag.tests;
import defaultOnlyWrite.ast.A;
import defaultOnlyWrite.ast.BoxedTypesSyn;
import defaultOnlyWrite.ast.MqttUpdater;
import defaultOnlyWrite.ast.NativeTypesSyn;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*;
/**
* Test case "defaultOnlyRead".
*
* @author rschoene - Initial contribution
*/
public class DefaultOnlyWriteTest {
private static final String TOPIC_NATIVE_INT = "native/int";
private static final String TOPIC_NATIVE_SHORT = "native/short";
private static final String TOPIC_NATIVE_LONG = "native/long";
private static final String TOPIC_NATIVE_FLOAT = "native/float";
private static final String TOPIC_NATIVE_DOUBLE = "native/double";
private static final String TOPIC_NATIVE_CHAR = "native/char";
private static final String TOPIC_NATIVE_STRING = "native/string";
private static final String TOPIC_BOXED_INTEGER = "boxed/Integer";
private static final String TOPIC_BOXED_SHORT = "boxed/Short";
private static final String TOPIC_BOXED_LONG = "boxed/Long";
private static final String TOPIC_BOXED_FLOAT = "boxed/Float";
private static final String TOPIC_BOXED_DOUBLE = "boxed/Double";
private static final String TOPIC_BOXED_CHARACTER = "boxed/Character";
private A model;
private NativeTypesSyn nativeIntegers;
private NativeTypesSyn nativeFloats;
private NativeTypesSyn nativeChars;
private BoxedTypesSyn boxedIntegers;
private BoxedTypesSyn boxedFloats;
private BoxedTypesSyn boxedChars;
private MqttUpdater receiver;
private ReceiverData data;
@AfterEach
public void closeConnections() {
if (receiver != null) {
receiver.close();
}
if (model != null) {
model.MqttCloseConnections();
}
}
@Test
public void buildModel() {
createModel();
}
@Test
public void communicateSendInitialValue() throws IOException, InterruptedException {
createModel();
setData("1", "1.1", "ab");
setupReceiverAndConnect(true);
// check initial value
TimeUnit.SECONDS.sleep(2);
checkData(1, 1, 1.1, 'a', "ab");
// set new value
setData("2", "2.2", "cd");
// check new value
TimeUnit.SECONDS.sleep(2);
checkData(2, 2, 2.2, 'c', "cd");
// set new value
setData("3", "3.2", "ee");
// check new value
TimeUnit.SECONDS.sleep(2);
checkData(3, 3, 3.2, 'e', "ee");
}
@Test
public void communicateOnlyUpdatedValue() throws IOException, InterruptedException {
createModel();
setData("1", "1.1", "ab");
setupReceiverAndConnect(false);
// check initial value (will be default values)
TimeUnit.SECONDS.sleep(2);
checkData(0, null, null, null, null);
// set new value
setData("2", "2.2", "cd");
// check new value
TimeUnit.SECONDS.sleep(2);
checkData(1, 2, 2.2, 'c', "cd");
// set new value
setData("3", "3.2", "ee");
// check new value
TimeUnit.SECONDS.sleep(2);
checkData(2, 3, 3.2, 'e', "ee");
}
private void createModel() {
model = new A();
nativeIntegers = new NativeTypesSyn();
nativeFloats = new NativeTypesSyn();
nativeChars = new NativeTypesSyn();
model.addNativeTypesSyn(nativeIntegers);
model.addNativeTypesSyn(nativeFloats);
model.addNativeTypesSyn(nativeChars);
boxedIntegers = new BoxedTypesSyn();
boxedFloats = new BoxedTypesSyn();
boxedChars = new BoxedTypesSyn();
model.addBoxedTypesSyn(boxedIntegers);
model.addBoxedTypesSyn(boxedFloats);
model.addBoxedTypesSyn(boxedChars);
}
private void setupReceiverAndConnect(boolean writeCurrentValue) throws IOException {
model.MqttSetHost(TestUtils.getMqttHost());
assertTrue(model.MqttWaitUntilReady(2, TimeUnit.SECONDS));
receiver = new MqttUpdater().dontSendWelcomeMessage().setHost(TestUtils.getMqttHost());
assertTrue(receiver.waitUntilReady(2, TimeUnit.SECONDS));
nativeIntegers.addNativeIntDependency(nativeIntegers);
nativeIntegers.addNativeShortDependency(nativeIntegers);
nativeIntegers.addNativeLongDependency(nativeIntegers);
nativeFloats.addNativeFloatDependency(nativeFloats);
nativeFloats.addNativeDoubleDependency(nativeFloats);
nativeChars.addNativeCharDependency(nativeChars);
nativeChars.addNativeStringDependency(nativeChars);
boxedIntegers.addBoxedIntDependency(boxedIntegers);
boxedIntegers.addBoxedShortDependency(boxedIntegers);
boxedIntegers.addBoxedLongDependency(boxedIntegers);
boxedFloats.addBoxedFloatDependency(boxedFloats);
boxedFloats.addBoxedDoubleDependency(boxedFloats);
boxedChars.addBoxedCharDependency(boxedChars);
data = new ReceiverData();
receiver.newConnection(TOPIC_NATIVE_INT, bytes -> {
data.numberOfNativeIntValues += 1;
data.lastNativeIntValue = java.nio.ByteBuffer.wrap(bytes).getInt();
});
receiver.newConnection(TOPIC_NATIVE_SHORT, bytes -> {
data.numberOfNativeShortValues += 1;
data.lastNativeShortValue = java.nio.ByteBuffer.wrap(bytes).getShort();
});
receiver.newConnection(TOPIC_NATIVE_LONG, bytes -> {
data.numberOfNativeLongValues += 1;
data.lastNativeLongValue = java.nio.ByteBuffer.wrap(bytes).getLong();
});
receiver.newConnection(TOPIC_NATIVE_FLOAT, bytes -> {
data.numberOfNativeFloatValues += 1;
data.lastNativeFloatValue = java.nio.ByteBuffer.wrap(bytes).getFloat();
});
receiver.newConnection(TOPIC_NATIVE_DOUBLE, bytes -> {
data.numberOfNativeDoubleValues += 1;
data.lastNativeDoubleValue = java.nio.ByteBuffer.wrap(bytes).getDouble();
});
receiver.newConnection(TOPIC_NATIVE_CHAR, bytes -> {
data.numberOfNativeCharValues += 1;
data.lastNativeCharValue = java.nio.ByteBuffer.wrap(bytes).getChar();
});
receiver.newConnection(TOPIC_NATIVE_STRING, bytes -> {
data.numberOfNativeStringValues += 1;
data.lastNativeStringValue = new String(bytes);
});
receiver.newConnection(TOPIC_BOXED_INTEGER, bytes -> {
data.numberOfBoxedIntValues += 1;
data.lastBoxedIntValue = java.nio.ByteBuffer.wrap(bytes).getInt();
});
receiver.newConnection(TOPIC_BOXED_SHORT, bytes -> {
data.numberOfBoxedShortValues += 1;
data.lastBoxedShortValue = java.nio.ByteBuffer.wrap(bytes).getShort();
});
receiver.newConnection(TOPIC_BOXED_LONG, bytes -> {
data.numberOfBoxedLongValues += 1;
data.lastBoxedLongValue = java.nio.ByteBuffer.wrap(bytes).getLong();
});
receiver.newConnection(TOPIC_BOXED_FLOAT, bytes -> {
data.numberOfBoxedFloatValues += 1;
data.lastBoxedFloatValue = java.nio.ByteBuffer.wrap(bytes).getFloat();
});
receiver.newConnection(TOPIC_BOXED_DOUBLE, bytes -> {
data.numberOfBoxedDoubleValues += 1;
data.lastBoxedDoubleValue = java.nio.ByteBuffer.wrap(bytes).getDouble();
});
receiver.newConnection(TOPIC_BOXED_CHARACTER, bytes -> {
data.numberOfBoxedCharValues += 1;
data.lastBoxedCharValue = java.nio.ByteBuffer.wrap(bytes).getChar();
});
nativeIntegers.connectIntValue(TOPIC_NATIVE_INT, writeCurrentValue);
nativeIntegers.connectShortValue(TOPIC_NATIVE_SHORT, writeCurrentValue);
nativeIntegers.connectLongValue(TOPIC_NATIVE_LONG, writeCurrentValue);
nativeFloats.connectFloatValue(TOPIC_NATIVE_FLOAT, writeCurrentValue);
nativeFloats.connectDoubleValue(TOPIC_NATIVE_DOUBLE, writeCurrentValue);
nativeChars.connectCharValue(TOPIC_NATIVE_CHAR, writeCurrentValue);
nativeChars.connectStringValue(TOPIC_NATIVE_STRING, writeCurrentValue);
boxedIntegers.connectIntValue(TOPIC_BOXED_INTEGER, writeCurrentValue);
boxedIntegers.connectShortValue(TOPIC_BOXED_SHORT, writeCurrentValue);
boxedIntegers.connectLongValue(TOPIC_BOXED_LONG, writeCurrentValue);
boxedFloats.connectFloatValue(TOPIC_BOXED_FLOAT, writeCurrentValue);
boxedFloats.connectDoubleValue(TOPIC_BOXED_DOUBLE, writeCurrentValue);
boxedChars.connectCharValue(TOPIC_BOXED_CHARACTER, writeCurrentValue);
}
private void setData(String integerDriver, String floatDriver, String stringDriver) {
nativeIntegers.setDriverSyn(integerDriver);
nativeFloats.setDriverSyn(floatDriver);
nativeChars.setDriverSyn(stringDriver);
boxedIntegers.setDriverSyn(integerDriver);
boxedFloats.setDriverSyn(floatDriver);
boxedChars.setDriverSyn(stringDriver);
}
private void checkData(int expectedNumberOfValues,
Integer expectedInt, Double expectedDouble,
Character expectedChar, String expectedString) {
assertEquals(expectedNumberOfValues, data.numberOfNativeIntValues);
assertEquals(expectedNumberOfValues, data.numberOfNativeShortValues);
assertEquals(expectedNumberOfValues, data.numberOfNativeLongValues);
assertEquals(expectedNumberOfValues, data.numberOfNativeFloatValues);
assertEquals(expectedNumberOfValues, data.numberOfNativeDoubleValues);
assertEquals(expectedNumberOfValues, data.numberOfNativeCharValues);
assertEquals(expectedNumberOfValues, data.numberOfNativeStringValues);
assertEquals(expectedNumberOfValues, data.numberOfBoxedIntValues);
assertEquals(expectedNumberOfValues, data.numberOfBoxedShortValues);
assertEquals(expectedNumberOfValues, data.numberOfBoxedLongValues);
assertEquals(expectedNumberOfValues, data.numberOfBoxedFloatValues);
assertEquals(expectedNumberOfValues, data.numberOfBoxedDoubleValues);
assertEquals(expectedNumberOfValues, data.numberOfBoxedCharValues);
if (expectedInt != null) {
assertEquals(expectedInt.intValue(), data.lastNativeIntValue);
assertEquals(expectedInt.shortValue(), data.lastNativeShortValue);
assertEquals(expectedInt.longValue(), data.lastNativeLongValue);
assertEquals(expectedInt.intValue(), data.lastBoxedIntValue.intValue());
assertEquals(expectedInt.shortValue(), data.lastBoxedShortValue.shortValue());
assertEquals(expectedInt.longValue(), data.lastBoxedLongValue.longValue());
} else {
assertEquals(0, data.lastNativeIntValue);
assertEquals(0, data.lastNativeShortValue);
assertEquals(0, data.lastNativeLongValue);
assertNull(data.lastBoxedIntValue);
assertNull(data.lastBoxedShortValue);
assertNull(data.lastBoxedLongValue);
}
if (expectedDouble != null) {
assertEquals(expectedDouble.floatValue(), data.lastNativeFloatValue, TestUtils.DELTA);
assertEquals(expectedDouble, data.lastNativeDoubleValue, TestUtils.DELTA);
assertEquals(expectedDouble.floatValue(), data.lastBoxedFloatValue, TestUtils.DELTA);
assertEquals(expectedDouble, data.lastBoxedDoubleValue, TestUtils.DELTA);
} else {
assertEquals(0f, data.lastNativeFloatValue, TestUtils.DELTA);
assertEquals(0d, data.lastNativeDoubleValue, TestUtils.DELTA);
assertNull(data.lastBoxedFloatValue);
assertNull(data.lastBoxedDoubleValue);
}
if (expectedChar != null) {
assertEquals(expectedChar.charValue(), data.lastNativeCharValue);
assertEquals(expectedChar, data.lastBoxedCharValue);
} else {
assertEquals('\0', data.lastNativeCharValue);
assertNull(data.lastBoxedCharValue);
}
assertEquals(expectedString, data.lastNativeStringValue);
}
private static class ReceiverData {
int lastNativeIntValue;
int numberOfNativeIntValues = 0;
short lastNativeShortValue;
int numberOfNativeShortValues = 0;
long lastNativeLongValue;
int numberOfNativeLongValues = 0;
float lastNativeFloatValue;
int numberOfNativeFloatValues = 0;
double lastNativeDoubleValue;
int numberOfNativeDoubleValues = 0;
char lastNativeCharValue;
int numberOfNativeCharValues = 0;
String lastNativeStringValue;
int numberOfNativeStringValues = 0;
Integer lastBoxedIntValue;
int numberOfBoxedIntValues = 0;
Short lastBoxedShortValue;
int numberOfBoxedShortValues = 0;
Long lastBoxedLongValue;
int numberOfBoxedLongValues = 0;
Float lastBoxedFloatValue;
int numberOfBoxedFloatValues = 0;
Double lastBoxedDoubleValue;
int numberOfBoxedDoubleValues = 0;
Character lastBoxedCharValue;
int numberOfBoxedCharValues = 0;