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

Merge branch '17-missing-default-mapping-for-boolean' into 'dev'

Resolve "Missing default mapping for boolean"

See merge request !2
parents 9b7b02b4 efcbb658
Pipeline #8883 passed with stages
in 9 minutes and 4 seconds
......@@ -62,6 +62,8 @@ aspect Analysis {
}
syn String JavaTypeUse.primitivePrettyPrint() {
switch(getName()) {
case "boolean":
case "Boolean": return "boolean";
case "int":
case "Integer": return "int";
case "short":
......
......@@ -20,6 +20,8 @@ aspect DefaultMappings {
return result;
}
syn nta DefaultMappingDefinition RagConnect.defaultBytesToBooleanMapping() = baseDefaultMappingDefinition(
"byte[]", "boolean", "return input[0] == (byte) 1;");
syn nta DefaultMappingDefinition RagConnect.defaultBytesToIntMapping() = baseDefaultMappingDefinition(
"byte[]", "int", "return java.nio.ByteBuffer.wrap(input).getInt();");
syn nta DefaultMappingDefinition RagConnect.defaultBytesToShortMapping() = baseDefaultMappingDefinition(
......@@ -35,6 +37,8 @@ aspect DefaultMappings {
syn nta DefaultMappingDefinition RagConnect.defaultBytesToStringMapping() = baseDefaultMappingDefinition(
"byte[]", "String", "return new String(input);");
syn nta DefaultMappingDefinition RagConnect.defaultBooleanToBytesMapping() = baseDefaultMappingDefinition(
"boolean", "byte[]", "return java.nio.ByteBuffer.allocate(1).put((byte) (input ? 1 : 0)).array();");
syn nta DefaultMappingDefinition RagConnect.defaultIntToBytesMapping() = baseDefaultMappingDefinition(
"int", "byte[]", "return java.nio.ByteBuffer.allocate(Integer.BYTES).putInt(input).array();");
syn nta DefaultMappingDefinition RagConnect.defaultShortToBytesMapping() = baseDefaultMappingDefinition(
......@@ -50,6 +54,8 @@ aspect DefaultMappings {
syn nta DefaultMappingDefinition RagConnect.defaultStringToBytesMapping() = baseDefaultMappingDefinition(
"String", "byte[]", "return input.getBytes();");
syn nta DefaultMappingDefinition RagConnect.defaultStringToBooleanMapping() = baseDefaultMappingDefinition(
"String", "boolean", "return Boolean.parseBoolean(input);");
syn nta DefaultMappingDefinition RagConnect.defaultStringToIntMapping() = baseDefaultMappingDefinition(
"String", "int", "return Integer.parseInt(input);");
syn nta DefaultMappingDefinition RagConnect.defaultStringToShortMapping() = baseDefaultMappingDefinition(
......@@ -63,6 +69,8 @@ aspect DefaultMappings {
syn nta DefaultMappingDefinition RagConnect.defaultStringToCharMapping() = baseDefaultMappingDefinition(
"String", "char", "return input.charAt(0);");
syn nta DefaultMappingDefinition RagConnect.defaultBooleanToStringMapping() = baseDefaultMappingDefinition(
"boolean", "String", "return String.valueOf(input);");
syn nta DefaultMappingDefinition RagConnect.defaultIntToStringMapping() = baseDefaultMappingDefinition(
"int", "String", "return String.valueOf(input);");
syn nta DefaultMappingDefinition RagConnect.defaultShortToStringMapping() = baseDefaultMappingDefinition(
......@@ -111,6 +119,7 @@ aspect Mappings {
syn boolean JavaTypeUse.isPrimitiveType() = false;
eq SimpleJavaTypeUse.isPrimitiveType() {
switch(getName()) {
case "boolean":
case "int":
case "short":
case "long":
......@@ -131,6 +140,8 @@ aspect Mappings {
// --- suitableReceiveDefaultMapping ---
syn DefaultMappingDefinition EndpointDefinition.suitableReceiveDefaultMapping() {
switch (targetTypeName()) {
case "boolean":
case "Boolean": return ragconnect().defaultBytesToBooleanMapping();
case "int":
case "Integer": return ragconnect().defaultBytesToIntMapping();
case "short":
......@@ -150,6 +161,8 @@ aspect Mappings {
// --- suitableSendDefaultMapping ---
syn DefaultMappingDefinition EndpointDefinition.suitableSendDefaultMapping() {
switch (targetTypeName()) {
case "boolean":
case "Boolean": return ragconnect().defaultBooleanToBytesMapping();
case "int":
case "Integer": return ragconnect().defaultIntToBytesMapping();
case "short":
......@@ -240,6 +253,7 @@ aspect Mappings {
java.util.List<MappingDefinition> result = new java.util.ArrayList<>();
getMappingDefinitionList().iterator().forEachRemaining(result::add);
// byte[] conversion
result.add(defaultBytesToBooleanMapping());
result.add(defaultBytesToIntMapping());
result.add(defaultBytesToShortMapping());
result.add(defaultBytesToLongMapping());
......@@ -247,6 +261,7 @@ aspect Mappings {
result.add(defaultBytesToDoubleMapping());
result.add(defaultBytesToCharMapping());
result.add(defaultBytesToStringMapping());
result.add(defaultBooleanToBytesMapping());
result.add(defaultIntToBytesMapping());
result.add(defaultShortToBytesMapping());
result.add(defaultLongToBytesMapping());
......@@ -255,12 +270,14 @@ aspect Mappings {
result.add(defaultCharToBytesMapping());
result.add(defaultStringToBytesMapping());
// // string conversion
// result.add(defaultStringToBooleanMapping());
// result.add(defaultStringToIntMapping());
// result.add(defaultStringToShortMapping());
// result.add(defaultStringToLongMapping());
// result.add(defaultStringToFloatMapping());
// result.add(defaultStringToDoubleMapping());
// result.add(defaultStringToCharMapping());
// result.add(defaultBooleanToStringMapping());
// result.add(defaultIntToStringMapping());
// result.add(defaultShortToStringMapping());
// result.add(defaultLongToStringMapping());
......
......@@ -206,7 +206,7 @@ public class Compiler extends AbstractCompiler {
atLeastOneRagConnect = true;
break;
default:
throw new CompilerException("Unknown file extension in " + filename);
throw new CompilerException("Unknown file extension " + extension + " in " + filename);
}
}
if (!atLeastOneGrammar) {
......@@ -218,14 +218,19 @@ public class Compiler extends AbstractCompiler {
if (!atLeastOneGrammar && !atLeastOneRagConnect) {
System.exit(1);
}
// here, the program subtree is also flushed and resolved
ragConnect.flushTreeCache();
ragConnect.treeResolveAll();
ragConnect.additionalRelations().forEach(ragConnectGrammarPart::addDeclaration);
ASTNode.loggingEnabledForReads = optionLogReads.value();
ASTNode.loggingEnabledForWrites = optionLogWrites.value();
// reuse "--incremental" option of JastAdd
ASTNode.incrementalOptionActive = getConfiguration().incremental() && getConfiguration().traceFlush();
printMessage("ASTNode.incrementalOptionActive = " + ASTNode.incrementalOptionActive);
ASTNode.usesMqtt = optionProtocols.hasValue(OPTION_PROTOCOL_MQTT);
ASTNode.usesRest = optionProtocols.hasValue(OPTION_PROTOCOL_REST);
return ragConnect;
......@@ -240,7 +245,6 @@ public class Compiler extends AbstractCompiler {
grammarFile.dumpTree(System.out);
}
program.addGrammarFile(grammarFile);
grammarFile.treeResolveAll();
grammarFile.setFileName(toBaseName(filename));
} catch (IOException | Parser.Exception e) {
throw new CompilerException("Could not parse grammar file " + filename, e);
......
......@@ -84,7 +84,7 @@ task specificTest(type: Test, dependsOn: testClasses) {
group = 'verification'
useJUnitPlatform {
includeTags 'NewTest'
includeTags 'SpecificTest'
}
}
......
// --- update definitions ---
receive NativeTypes.BooleanValue;
receive NativeTypes.IntValue;
receive NativeTypes.ShortValue;
receive NativeTypes.LongValue;
......@@ -7,6 +8,7 @@ receive NativeTypes.DoubleValue;
receive NativeTypes.CharValue;
receive NativeTypes.StringValue;
receive NativeTypes.BooleanValueTransformed using BooleanTransformation;
receive NativeTypes.IntValueTransformed using IntTransformation;
receive NativeTypes.ShortValueTransformed using ShortTransformation;
receive NativeTypes.LongValueTransformed using LongTransformation;
......@@ -15,6 +17,7 @@ receive NativeTypes.DoubleValueTransformed using DoubleTransformation;
receive NativeTypes.CharValueTransformed using CharTransformation;
receive NativeTypes.StringValueTransformed using StringTransformation;
receive BoxedTypes.BooleanValue;
receive BoxedTypes.IntValue;
receive BoxedTypes.ShortValue;
receive BoxedTypes.LongValue;
......@@ -22,6 +25,7 @@ receive BoxedTypes.FloatValue;
receive BoxedTypes.DoubleValue;
receive BoxedTypes.CharValue;
receive BoxedTypes.BooleanValueTransformed using BooleanTransformation;
receive BoxedTypes.IntValueTransformed using IntTransformation;
receive BoxedTypes.ShortValueTransformed using ShortTransformation;
receive BoxedTypes.LongValueTransformed using LongTransformation;
......@@ -29,6 +33,9 @@ receive BoxedTypes.FloatValueTransformed using FloatTransformation;
receive BoxedTypes.DoubleValueTransformed using DoubleTransformation;
receive BoxedTypes.CharValueTransformed using CharTransformation;
BooleanTransformation maps boolean b to boolean {:
return b;
:}
IntTransformation maps int i to int {:
return i;
:}
......
A ::= NativeTypes* BoxedTypes* ;
NativeTypes ::= <IntValue:int> <ShortValue:short> <LongValue:long> <FloatValue:float> <DoubleValue:double> <CharValue:char> <StringValue:String> <IntValueTransformed:int> <ShortValueTransformed:short> <LongValueTransformed:long> <FloatValueTransformed:float> <DoubleValueTransformed:double> <CharValueTransformed:char> <StringValueTransformed:String> ;
BoxedTypes ::= <IntValue:Integer> <ShortValue:Short> <LongValue:Long> <FloatValue:Float> <DoubleValue:Double> <CharValue:Character> <IntValueTransformed:Integer> <ShortValueTransformed:Short> <LongValueTransformed:Long> <FloatValueTransformed:Float> <DoubleValueTransformed:Double> <CharValueTransformed:Character> ;
NativeTypes ::= <BooleanValue:boolean> <IntValue:int> <ShortValue:short> <LongValue:long> <FloatValue:float> <DoubleValue:double> <CharValue:char> <StringValue:String> <BooleanValueTransformed:boolean> <IntValueTransformed:int> <ShortValueTransformed:short> <LongValueTransformed:long> <FloatValueTransformed:float> <DoubleValueTransformed:double> <CharValueTransformed:char> <StringValueTransformed:String> ;
BoxedTypes ::= <BooleanValue:Boolean> <IntValue:Integer> <ShortValue:Short> <LongValue:Long> <FloatValue:Float> <DoubleValue:Double> <CharValue:Character> <BooleanValueTransformed:Boolean> <IntValueTransformed:Integer> <ShortValueTransformed:Short> <LongValueTransformed:Long> <FloatValueTransformed:Float> <DoubleValueTransformed:Double> <CharValueTransformed:Character> ;
// --- update definitions ---
// native types, synthesized
send NativeTypesSyn.BooleanValue;
send NativeTypesSyn.IntValue;
send NativeTypesSyn.ShortValue;
send NativeTypesSyn.LongValue;
......@@ -9,6 +10,7 @@ send NativeTypesSyn.CharValue;
send NativeTypesSyn.StringValue;
// native types, synthesized, transformed
send NativeTypesSyn.BooleanValueTransformed using BooleanTransformation;
send NativeTypesSyn.IntValueTransformed using IntTransformation;
send NativeTypesSyn.ShortValueTransformed using ShortTransformation;
send NativeTypesSyn.LongValueTransformed using LongTransformation;
......@@ -18,6 +20,7 @@ send NativeTypesSyn.CharValueTransformed using CharTransformation;
send NativeTypesSyn.StringValueTransformed using StringTransformation;
// boxed types, synthesized
send BoxedTypesSyn.BooleanValue;
send BoxedTypesSyn.IntValue;
send BoxedTypesSyn.ShortValue;
send BoxedTypesSyn.LongValue;
......@@ -26,6 +29,7 @@ send BoxedTypesSyn.DoubleValue;
send BoxedTypesSyn.CharValue;
// boxed types, synthesized, transformed
send BoxedTypesSyn.BooleanValueTransformed using BooleanTransformation;
send BoxedTypesSyn.IntValueTransformed using IntTransformation;
send BoxedTypesSyn.ShortValueTransformed using ShortTransformation;
send BoxedTypesSyn.LongValueTransformed using LongTransformation;
......@@ -34,6 +38,7 @@ send BoxedTypesSyn.DoubleValueTransformed using DoubleTransformation;
send BoxedTypesSyn.CharValueTransformed using CharTransformation;
// --- dependency definitions ---
NativeTypesSyn.BooleanValue canDependOn NativeTypesSyn.DriverSyn as nativeBooleanDependency;
NativeTypesSyn.IntValue canDependOn NativeTypesSyn.DriverSyn as nativeIntDependency;
NativeTypesSyn.ShortValue canDependOn NativeTypesSyn.DriverSyn as nativeShortDependency;
NativeTypesSyn.LongValue canDependOn NativeTypesSyn.DriverSyn as nativeLongDependency;
......@@ -41,6 +46,8 @@ NativeTypesSyn.FloatValue canDependOn NativeTypesSyn.DriverSyn as nativeFloatDep
NativeTypesSyn.DoubleValue canDependOn NativeTypesSyn.DriverSyn as nativeDoubleDependency;
NativeTypesSyn.CharValue canDependOn NativeTypesSyn.DriverSyn as nativeCharDependency;
NativeTypesSyn.StringValue canDependOn NativeTypesSyn.DriverSyn as nativeStringDependency;
BoxedTypesSyn.BooleanValue canDependOn BoxedTypesSyn.DriverSyn as boxedBooleanDependency;
BoxedTypesSyn.IntValue canDependOn BoxedTypesSyn.DriverSyn as boxedIntDependency;
BoxedTypesSyn.ShortValue canDependOn BoxedTypesSyn.DriverSyn as boxedShortDependency;
BoxedTypesSyn.LongValue canDependOn BoxedTypesSyn.DriverSyn as boxedLongDependency;
......@@ -48,6 +55,7 @@ BoxedTypesSyn.FloatValue canDependOn BoxedTypesSyn.DriverSyn as boxedFloatDepend
BoxedTypesSyn.DoubleValue canDependOn BoxedTypesSyn.DriverSyn as boxedDoubleDependency;
BoxedTypesSyn.CharValue canDependOn BoxedTypesSyn.DriverSyn as boxedCharDependency;
NativeTypesSyn.BooleanValueTransformed canDependOn NativeTypesSyn.DriverSyn as nativeBooleanTransformedDependency;
NativeTypesSyn.IntValueTransformed canDependOn NativeTypesSyn.DriverSyn as nativeIntTransformedDependency;
NativeTypesSyn.ShortValueTransformed canDependOn NativeTypesSyn.DriverSyn as nativeShortTransformedDependency;
NativeTypesSyn.LongValueTransformed canDependOn NativeTypesSyn.DriverSyn as nativeLongTransformedDependency;
......@@ -56,6 +64,7 @@ NativeTypesSyn.DoubleValueTransformed canDependOn NativeTypesSyn.DriverSyn as na
NativeTypesSyn.CharValueTransformed canDependOn NativeTypesSyn.DriverSyn as nativeCharTransformedDependency;
NativeTypesSyn.StringValueTransformed canDependOn NativeTypesSyn.DriverSyn as nativeStringTransformedDependency;
BoxedTypesSyn.BooleanValueTransformed canDependOn BoxedTypesSyn.DriverSyn as boxedBooleanTransformedDependency;
BoxedTypesSyn.IntValueTransformed canDependOn BoxedTypesSyn.DriverSyn as boxedIntTransformedDependency;
BoxedTypesSyn.ShortValueTransformed canDependOn BoxedTypesSyn.DriverSyn as boxedShortTransformedDependency;
BoxedTypesSyn.LongValueTransformed canDependOn BoxedTypesSyn.DriverSyn as boxedLongTransformedDependency;
......@@ -82,6 +91,9 @@ BoxedTypesSyn.CharValueTransformed canDependOn BoxedTypesSyn.DriverSyn as boxedC
//send BoxedTypesInh.DoubleValue;
//send BoxedTypesInh.CharValue;
BooleanTransformation maps boolean b to boolean {:
return b;
:}
IntTransformation maps int i to int {:
return i;
:}
......
aspect Computation {
// native types, synthesized
syn boolean NativeTypesSyn.getBooleanValue() = Integer.parseInt(getDriverSyn()) > 1;
syn int NativeTypesSyn.getIntValue() = Integer.parseInt(getDriverSyn());
syn short NativeTypesSyn.getShortValue() = Short.parseShort(getDriverSyn());
syn long NativeTypesSyn.getLongValue() = Long.parseLong(getDriverSyn());
......@@ -7,6 +8,8 @@ aspect Computation {
syn double NativeTypesSyn.getDoubleValue() = Double.parseDouble(getDriverSyn());
syn char NativeTypesSyn.getCharValue() = getDriverSyn().charAt(0);
syn String NativeTypesSyn.getStringValue() = new String(getDriverSyn());
syn boolean NativeTypesSyn.getBooleanValueTransformed() = Integer.parseInt(getDriverSyn()) > 1;
syn int NativeTypesSyn.getIntValueTransformed() = Integer.parseInt(getDriverSyn());
syn short NativeTypesSyn.getShortValueTransformed() = Short.parseShort(getDriverSyn());
syn long NativeTypesSyn.getLongValueTransformed() = Long.parseLong(getDriverSyn());
......@@ -16,12 +19,15 @@ aspect Computation {
syn String NativeTypesSyn.getStringValueTransformed() = new String(getDriverSyn());
// boxed types, synthesized
syn Boolean BoxedTypesSyn.getBooleanValue() = Integer.parseInt(getDriverSyn()) > 1;
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);
syn Boolean BoxedTypesSyn.getBooleanValueTransformed() = Integer.parseInt(getDriverSyn()) > 1;
syn Integer BoxedTypesSyn.getIntValueTransformed() = Integer.valueOf(getDriverSyn());
syn Short BoxedTypesSyn.getShortValueTransformed() = Short.valueOf(getDriverSyn());
syn Long BoxedTypesSyn.getLongValueTransformed() = Long.valueOf(getDriverSyn());
......
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>/ /<IntValueTransformed:int>/ /<ShortValueTransformed:short>/ /<LongValueTransformed:long>/ /<FloatValueTransformed:float>/ /<DoubleValueTransformed:double>/ /<CharValueTransformed:char>/ /<StringValueTransformed:String>/ ;
NativeTypesSyn ::= <DriverSyn:String> /<BooleanValue:boolean>/ /<IntValue:int>/ /<ShortValue:short>/ /<LongValue:long>/ /<FloatValue:float>/ /<DoubleValue:double>/ /<CharValue:char>/ /<StringValue:String>/ /<BooleanValueTransformed:boolean>/ /<IntValueTransformed:int>/ /<ShortValueTransformed:short>/ /<LongValueTransformed:long>/ /<FloatValueTransformed:float>/ /<DoubleValueTransformed:double>/ /<CharValueTransformed:char>/ /<StringValueTransformed:String>/ ;
// boxed types, synthesized
BoxedTypesSyn ::= <DriverSyn:String> /<IntValue:Integer>/ /<ShortValue:Short>/ /<LongValue:Long>/ /<FloatValue:Float>/ /<DoubleValue:Double>/ /<CharValue:Character>/ /<IntValueTransformed:Integer>/ /<ShortValueTransformed:Short>/ /<LongValueTransformed:Long>/ /<FloatValueTransformed:Float>/ /<DoubleValueTransformed:Double>/ /<CharValueTransformed:Character>/ ;
BoxedTypesSyn ::= <DriverSyn:String> /<BooleanValue:Boolean>/ /<IntValue:Integer>/ /<ShortValue:Short>/ /<LongValue:Long>/ /<FloatValue:Float>/ /<DoubleValue:Double>/ /<CharValue:Character>/ /<BooleanValueTransformed:Boolean>/ /<IntValueTransformed:Integer>/ /<ShortValueTransformed:Short>/ /<LongValueTransformed:Long>/ /<FloatValueTransformed:Float>/ /<DoubleValueTransformed:Double>/ /<CharValueTransformed:Character>/ ;
// --- inherited attributes not supported ---
//// native types, inherited
......
......@@ -4,6 +4,7 @@ receive NativeTypes.LongValue using String2Int, Int2Short, Short2Long ;
receive NativeTypes.FloatValue using String2Int, Int2Short, Short2Long, Long2Float ;
receive NativeTypes.DoubleValue using String2Int, Int2Short, Short2Long, Long2Float, Float2Double ;
receive NativeTypes.CharValue using String2Int, Int2Short, Short2Long, Long2Float, Float2Double, Double2Char ;
receive NativeTypes.BooleanValue using String2Int, Int2Short, Short2Long, Long2Float, Float2Double, Double2Char, Char2Boolean ;
send NativeTypes.WriteIntValue using String2Int ;
send NativeTypes.WriteShortValue using String2Int, Int2Short ;
......@@ -11,6 +12,7 @@ send NativeTypes.WriteLongValue using String2Int, Int2Short, Short2Long ;
send NativeTypes.WriteFloatValue using String2Int, Int2Short, Short2Long, Long2Float ;
send NativeTypes.WriteDoubleValue using String2Int, Int2Short, Short2Long, Long2Float, Float2Double ;
send NativeTypes.WriteCharValue using String2Int, Int2Short, Short2Long, Long2Float, Float2Double, Double2Char ;
send NativeTypes.WriteBooleanValue using String2Int, Int2Short, Short2Long, Long2Float, Float2Double, Double2Char, Char2Boolean ;
receive BoxedTypes.IntValue using String2Int ;
receive BoxedTypes.ShortValue using String2Int, Int2Short ;
......@@ -18,6 +20,7 @@ receive BoxedTypes.LongValue using String2Int, Int2Short, Short2Long ;
receive BoxedTypes.FloatValue using String2Int, Int2Short, Short2Long, Long2Float ;
receive BoxedTypes.DoubleValue using String2Int, Int2Short, Short2Long, Long2Float, Float2Double ;
receive BoxedTypes.CharValue using String2Int, Int2Short, Short2Long, Long2Float, Float2Double, Double2Char ;
receive BoxedTypes.BooleanValue using String2Int, Int2Short, Short2Long, Long2Float, Float2Double, Double2Char, Char2Boolean ;
String2Int maps String s to int {:
return Integer.parseInt(s);
......@@ -37,6 +40,9 @@ Float2Double maps float f to double {:
Double2Char maps double d to char {:
return (char) ((int) d);
:}
Char2Boolean maps char c to boolean {:
return c > 21;
:}
NativeTypes.WriteIntValue canDependOn NativeTypes.Driver as nativeIntDependency;
NativeTypes.WriteShortValue canDependOn NativeTypes.Driver as nativeShortDependency;
......@@ -44,3 +50,4 @@ NativeTypes.WriteLongValue canDependOn NativeTypes.Driver as nativeLongDependenc
NativeTypes.WriteFloatValue canDependOn NativeTypes.Driver as nativeFloatDependency;
NativeTypes.WriteDoubleValue canDependOn NativeTypes.Driver as nativeDoubleDependency;
NativeTypes.WriteCharValue canDependOn NativeTypes.Driver as nativeCharDependency;
NativeTypes.WriteBooleanValue canDependOn NativeTypes.Driver as nativeBooleanDependency;
......@@ -6,4 +6,5 @@ aspect Computation {
syn String NativeTypes.getWriteFloatValue() = getDriver();
syn String NativeTypes.getWriteDoubleValue() = getDriver();
syn String NativeTypes.getWriteCharValue() = getDriver();
syn String NativeTypes.getWriteBooleanValue() = getDriver();
}
A ::= NativeTypes BoxedTypes ;
NativeTypes ::= <IntValue:int> <ShortValue:short> <LongValue:long> <FloatValue:float> <DoubleValue:double> <CharValue:char> <Driver:String> /<WriteIntValue:String>/ /<WriteShortValue:String>/ /<WriteLongValue:String>/ /<WriteFloatValue:String>/ /<WriteDoubleValue:String>/ /<WriteCharValue:String>/;
BoxedTypes ::= <IntValue:Integer> <ShortValue:Short> <LongValue:Long> <FloatValue:Float> <DoubleValue:Double> <CharValue:Character> ;
NativeTypes ::= <IntValue:int> <ShortValue:short> <LongValue:long> <FloatValue:float> <DoubleValue:double> <CharValue:char> <BooleanValue:boolean> <Driver:String> /<WriteIntValue:String>/ /<WriteShortValue:String>/ /<WriteLongValue:String>/ /<WriteFloatValue:String>/ /<WriteDoubleValue:String>/ /<WriteCharValue:String>/ /<WriteBooleanValue:String>/;
BoxedTypes ::= <IntValue:Integer> <ShortValue:Short> <LongValue:Long> <FloatValue:Float> <DoubleValue:Double> <CharValue:Character> <BooleanValue:Boolean> ;
......@@ -6,7 +6,6 @@ import defaultOnlyRead.ast.MqttHandler;
import defaultOnlyRead.ast.NativeTypes;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.concurrent.TimeUnit;
import static org.jastadd.ragconnect.tests.TestUtils.mqttUri;
......@@ -20,7 +19,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
*/
public class DefaultOnlyReadTest extends AbstractMqttTest {
private static final String TOPIC_NATIVE_INT = "native/int";
private static final String TOPIC_NATIVE_INT = "native/boolean";
private static final String TOPIC_NATIVE_BOOLEAN = "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";
......@@ -28,6 +28,7 @@ public class DefaultOnlyReadTest extends AbstractMqttTest {
private static final String TOPIC_NATIVE_CHAR = "native/char";
private static final String TOPIC_NATIVE_STRING = "native/string";
private static final String TOPIC_BOXED_BOOLEAN = "boxed/boolean";
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";
......@@ -59,6 +60,7 @@ public class DefaultOnlyReadTest extends AbstractMqttTest {
protected void setupReceiverAndConnect(boolean writeCurrentValue) throws IOException {
model.ragconnectSetupMqttWaitUntilReady(2, TimeUnit.SECONDS);
integers.connectBooleanValue(mqttUri(TOPIC_NATIVE_BOOLEAN));
integers.connectIntValue(mqttUri(TOPIC_NATIVE_INT));
integers.connectShortValue(mqttUri(TOPIC_NATIVE_SHORT));
integers.connectLongValue(mqttUri(TOPIC_NATIVE_LONG));
......@@ -67,6 +69,7 @@ public class DefaultOnlyReadTest extends AbstractMqttTest {
chars.connectCharValue(mqttUri(TOPIC_NATIVE_CHAR));
chars.connectStringValue(mqttUri(TOPIC_NATIVE_STRING));
integers.connectBooleanValueTransformed(mqttUri(TOPIC_NATIVE_BOOLEAN));
integers.connectIntValueTransformed(mqttUri(TOPIC_NATIVE_INT));
integers.connectShortValueTransformed(mqttUri(TOPIC_NATIVE_SHORT));
integers.connectLongValueTransformed(mqttUri(TOPIC_NATIVE_LONG));
......@@ -75,6 +78,7 @@ public class DefaultOnlyReadTest extends AbstractMqttTest {
chars.connectCharValueTransformed(mqttUri(TOPIC_NATIVE_CHAR));
chars.connectStringValueTransformed(mqttUri(TOPIC_NATIVE_STRING));
allBoxed.connectBooleanValue(mqttUri(TOPIC_BOXED_BOOLEAN));
allBoxed.connectIntValue(mqttUri(TOPIC_BOXED_INTEGER));
allBoxed.connectShortValue(mqttUri(TOPIC_BOXED_SHORT));
allBoxed.connectLongValue(mqttUri(TOPIC_BOXED_LONG));
......@@ -82,6 +86,7 @@ public class DefaultOnlyReadTest extends AbstractMqttTest {
allBoxed.connectDoubleValue(mqttUri(TOPIC_BOXED_DOUBLE));
allBoxed.connectCharValue(mqttUri(TOPIC_BOXED_CHARACTER));
allBoxed.connectBooleanValueTransformed(mqttUri(TOPIC_BOXED_BOOLEAN));
allBoxed.connectIntValueTransformed(mqttUri(TOPIC_BOXED_INTEGER));
allBoxed.connectShortValueTransformed(mqttUri(TOPIC_BOXED_SHORT));
allBoxed.connectLongValueTransformed(mqttUri(TOPIC_BOXED_LONG));
......@@ -100,6 +105,7 @@ public class DefaultOnlyReadTest extends AbstractMqttTest {
@Override
protected void communicateOnlyUpdatedValue() throws InterruptedException {
final boolean expectedBooleanValue = true;
final int expectedIntValue = 1;
final short expectedShortValue = 2;
final long expectedLongValue = 3L;
......@@ -108,23 +114,26 @@ public class DefaultOnlyReadTest extends AbstractMqttTest {
final char expectedCharValue = 'c';
final String expectedStringValue = "6.3";
sender.publish(TOPIC_NATIVE_INT, ByteBuffer.allocate(4).putInt(expectedIntValue).array());
sender.publish(TOPIC_NATIVE_SHORT, ByteBuffer.allocate(2).putShort(expectedShortValue).array());
sender.publish(TOPIC_NATIVE_LONG, ByteBuffer.allocate(8).putLong(expectedLongValue).array());
sender.publish(TOPIC_NATIVE_FLOAT, ByteBuffer.allocate(4).putFloat(expectedFloatValue).array());
sender.publish(TOPIC_NATIVE_DOUBLE, ByteBuffer.allocate(8).putDouble(expectedDoubleValue).array());
sender.publish(TOPIC_NATIVE_CHAR, ByteBuffer.allocate(2).putChar(expectedCharValue).array());
sender.publish(TOPIC_NATIVE_STRING, expectedStringValue.getBytes());
sender.publish(TOPIC_BOXED_INTEGER, ByteBuffer.allocate(4).putInt(expectedIntValue).array());
sender.publish(TOPIC_BOXED_SHORT, ByteBuffer.allocate(2).putShort(expectedShortValue).array());
sender.publish(TOPIC_BOXED_LONG, ByteBuffer.allocate(8).putLong(expectedLongValue).array());
sender.publish(TOPIC_BOXED_FLOAT, ByteBuffer.allocate(4).putFloat(expectedFloatValue).array());
sender.publish(TOPIC_BOXED_DOUBLE, ByteBuffer.allocate(8).putDouble(expectedDoubleValue).array());
sender.publish(TOPIC_BOXED_CHARACTER, ByteBuffer.allocate(2).putChar(expectedCharValue).array());
sender.publish(TOPIC_NATIVE_BOOLEAN, TestUtils.DefaultMappings.BoolToBytes(expectedBooleanValue));
sender.publish(TOPIC_NATIVE_INT, TestUtils.DefaultMappings.IntToBytes(expectedIntValue));
sender.publish(TOPIC_NATIVE_SHORT, TestUtils.DefaultMappings.ShortToBytes(expectedShortValue));
sender.publish(TOPIC_NATIVE_LONG, TestUtils.DefaultMappings.LongToBytes(expectedLongValue));
sender.publish(TOPIC_NATIVE_FLOAT, TestUtils.DefaultMappings.FloatToBytes(expectedFloatValue));
sender.publish(TOPIC_NATIVE_DOUBLE, TestUtils.DefaultMappings.DoubleToBytes(expectedDoubleValue));
sender.publish(TOPIC_NATIVE_CHAR, TestUtils.DefaultMappings.CharToBytes(expectedCharValue));
sender.publish(TOPIC_NATIVE_STRING, TestUtils.DefaultMappings.StringToBytes(expectedStringValue));
sender.publish(TOPIC_BOXED_BOOLEAN, TestUtils.DefaultMappings.BoolToBytes(expectedBooleanValue));
sender.publish(TOPIC_BOXED_INTEGER, TestUtils.DefaultMappings.IntToBytes(expectedIntValue));
sender.publish(TOPIC_BOXED_SHORT, TestUtils.DefaultMappings.ShortToBytes(expectedShortValue));
sender.publish(TOPIC_BOXED_LONG, TestUtils.DefaultMappings.LongToBytes(expectedLongValue));
sender.publish(TOPIC_BOXED_FLOAT, TestUtils.DefaultMappings.FloatToBytes(expectedFloatValue));
sender.publish(TOPIC_BOXED_DOUBLE, TestUtils.DefaultMappings.DoubleToBytes(expectedDoubleValue));
sender.publish(TOPIC_BOXED_CHARACTER, TestUtils.DefaultMappings.CharToBytes(expectedCharValue));
TestUtils.waitForMqtt();
assertEquals(expectedBooleanValue, integers.getBooleanValue());
assertEquals(expectedIntValue, integers.getIntValue());
assertEquals(expectedShortValue, integers.getShortValue());
assertEquals(expectedLongValue, integers.getLongValue());
......@@ -133,6 +142,7 @@ public class DefaultOnlyReadTest extends AbstractMqttTest {
assertEquals(expectedCharValue, chars.getCharValue());
assertEquals(expectedStringValue, chars.getStringValue());
assertEquals(expectedBooleanValue, integers.getBooleanValueTransformed());
assertEquals(expectedIntValue, integers.getIntValueTransformed());
assertEquals(expectedShortValue, integers.getShortValueTransformed());
assertEquals(expectedLongValue, integers.getLongValueTransformed());
......@@ -141,6 +151,7 @@ public class DefaultOnlyReadTest extends AbstractMqttTest {
assertEquals(expectedCharValue, chars.getCharValueTransformed());
assertEquals(expectedStringValue, chars.getStringValueTransformed());
assertEquals(expectedBooleanValue, allBoxed.getBooleanValue());
assertEquals(expectedIntValue, allBoxed.getIntValue().intValue());
assertEquals(expectedShortValue, allBoxed.getShortValue().shortValue());
assertEquals(expectedLongValue, allBoxed.getLongValue().longValue());
......@@ -148,6 +159,7 @@ public class DefaultOnlyReadTest extends AbstractMqttTest {
assertEquals(expectedDoubleValue, allBoxed.getDoubleValue(), TestUtils.DELTA);
assertEquals(expectedCharValue, allBoxed.getCharValue().charValue());
assertEquals(expectedBooleanValue, allBoxed.getBooleanValueTransformed());
assertEquals(expectedIntValue, allBoxed.getIntValueTransformed().intValue());
assertEquals(expectedShortValue, allBoxed.getShortValueTransformed().shortValue());
assertEquals(expectedLongValue, allBoxed.getLongValueTransformed().longValue());
......
......@@ -18,6 +18,7 @@ import static org.junit.jupiter.api.Assertions.*;
*/
public class DefaultOnlyWriteTest extends AbstractMqttTest {
private static final String TOPIC_NATIVE_BOOLEAN = "native/boolean";
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";
......@@ -26,6 +27,7 @@ public class DefaultOnlyWriteTest extends AbstractMqttTest {
private static final String TOPIC_NATIVE_CHAR = "native/char";
private static final String TOPIC_NATIVE_STRING = "native/string";
private static final String TOPIC_NATIVE_BOOLEAN_TRANSFORMED = "native/boolean/t";
private static final String TOPIC_NATIVE_INT_TRANSFORMED = "native/int/t";
private static final String TOPIC_NATIVE_SHORT_TRANSFORMED = "native/short/t";
private static final String TOPIC_NATIVE_LONG_TRANSFORMED = "native/long/t";
......@@ -34,6 +36,7 @@ public class DefaultOnlyWriteTest extends AbstractMqttTest {
private static final String TOPIC_NATIVE_CHAR_TRANSFORMED = "native/char/t";
private static final String TOPIC_NATIVE_STRING_TRANSFORMED = "native/string/t";
private static final String TOPIC_BOXED_BOOLEAN = "boxed/Boolean";
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";
......@@ -41,6 +44,7 @@ public class DefaultOnlyWriteTest extends AbstractMqttTest {
private static final String TOPIC_BOXED_DOUBLE = "boxed/Double";
private static final String TOPIC_BOXED_CHARACTER = "boxed/Character";
private static final String TOPIC_BOXED_BOOLEAN_TRANSFORMED = "boxed/Boolean/t";
private static final String TOPIC_BOXED_INTEGER_TRANSFORMED = "boxed/Integer/t";
private static final String TOPIC_BOXED_SHORT_TRANSFORMED = "boxed/Short/t";
private static final String TOPIC_BOXED_LONG_TRANSFORMED = "boxed/Long/t";
......@@ -87,6 +91,7 @@ public class DefaultOnlyWriteTest extends AbstractMqttTest {
receiver = new MqttHandler().dontSendWelcomeMessage().setHost(TestUtils.getMqttHost());
assertTrue(receiver.waitUntilReady(2, TimeUnit.SECONDS));
nativeIntegers.addNativeBooleanDependency(nativeIntegers);
nativeIntegers.addNativeIntDependency(nativeIntegers);
nativeIntegers.addNativeShortDependency(nativeIntegers);
nativeIntegers.addNativeLongDependency(nativeIntegers);
......@@ -95,6 +100,7 @@ public class DefaultOnlyWriteTest extends AbstractMqttTest {
nativeChars.addNativeCharDependency(nativeChars);
nativeChars.addNativeStringDependency(nativeChars);
nativeIntegers.addNativeBooleanTransformedDependency(nativeIntegers);
nativeIntegers.addNativeIntTransformedDependency(nativeIntegers);
nativeIntegers.addNativeShortTransformedDependency(nativeIntegers);
nativeIntegers.addNativeLongTransformedDependency(nativeIntegers);
......@@ -103,6 +109,7 @@ public class DefaultOnlyWriteTest extends AbstractMqttTest {
nativeChars.addNativeCharTransformedDependency(nativeChars);
nativeChars.addNativeStringTransformedDependency(nativeChars);
boxedIntegers.addBoxedBooleanDependency(boxedIntegers);
boxedIntegers.addBoxedIntDependency(boxedIntegers);
boxedIntegers.addBoxedShortDependency(boxedIntegers);
boxedIntegers.addBoxedLongDependency(boxedIntegers);
......@@ -110,6 +117,7 @@ public class DefaultOnlyWriteTest extends AbstractMqttTest {
boxedFloats.addBoxedDoubleDependency(boxedFloats);
boxedChars.addBoxedCharDependency(boxedChars);
boxedIntegers.addBoxedBooleanTransformedDependency(boxedIntegers);
boxedIntegers.addBoxedIntTransformedDependency(boxedIntegers);
boxedIntegers.addBoxedShortTransformedDependency(boxedIntegers);
boxedIntegers.addBoxedLongTransformedDependency(boxedIntegers);
......@@ -120,6 +128,7 @@ public class DefaultOnlyWriteTest extends AbstractMqttTest {
dataNormal = createReceiver(false);
dataTransformed = createReceiver(true);
nativeIntegers.connectBooleanValue(mqttUri(TOPIC_NATIVE_BOOLEAN), writeCurrentValue);
nativeIntegers.connectIntValue(mqttUri(TOPIC_NATIVE_INT), writeCurrentValue);
nativeIntegers.connectShortValue(mqttUri(TOPIC_NATIVE_SHORT), writeCurrentValue);
nativeIntegers.connectLongValue(mqttUri(TOPIC_NATIVE_LONG), writeCurrentValue);
......@@ -128,6 +137,7 @@ public class DefaultOnlyWriteTest extends AbstractMqttTest {
nativeChars.connectCharValue(mqttUri(TOPIC_NATIVE_CHAR), writeCurrentValue);
nativeChars.connectStringValue(mqttUri(TOPIC_NATIVE_STRING), writeCurrentValue);
nativeIntegers.connectBooleanValueTransformed(mqttUri(TOPIC_NATIVE_BOOLEAN_TRANSFORMED), writeCurrentValue);
nativeIntegers.connectIntValueTransformed(mqttUri(TOPIC_NATIVE_INT_TRANSFORMED), writeCurrentValue);
nativeIntegers.connectShortValueTransformed(mqttUri(TOPIC_NATIVE_SHORT_TRANSFORMED), writeCurrentValue);
nativeIntegers.connectLongValueTransformed(mqttUri(TOPIC_NATIVE_LONG_TRANSFORMED), writeCurrentValue);
......@@ -136,6 +146,7 @@ public class DefaultOnlyWriteTest extends AbstractMqttTest {
nativeChars.connectCharValueTransformed(mqttUri(TOPIC_NATIVE_CHAR_TRANSFORMED), writeCurrentValue);
nativeChars.connectStringValueTransformed(mqttUri(TOPIC_NATIVE_STRING_TRANSFORMED), writeCurrentValue);
boxedIntegers.connectBooleanValue(mqttUri(TOPIC_BOXED_BOOLEAN), writeCurrentValue);
boxedIntegers.connectIntValue(mqttUri(TOPIC_BOXED_INTEGER), writeCurrentValue);
boxedIntegers.connectShortValue(mqttUri(TOPIC_BOXED_SHORT), writeCurrentValue);
boxedIntegers.connectLongValue(mqttUri(TOPIC_BOXED_LONG), writeCurrentValue);
......@@ -143,6 +154,7 @@ public class DefaultOnlyWriteTest extends AbstractMqttTest {
boxedFloats.connectDoubleValue(mqttUri(TOPIC_BOXED_DOUBLE), writeCurrentValue);
boxedChars.connectCharValue(mqttUri(TOPIC_BOXED_CHARACTER), writeCurrentValue);
boxedIntegers.connectBooleanValueTransformed(mqttUri(TOPIC_BOXED_BOOLEAN_TRANSFORMED), writeCurrentValue);
boxedIntegers.connectIntValueTransformed(mqttUri(TOPIC_BOXED_INTEGER_TRANSFORMED), writeCurrentValue);
boxedIntegers.connectShortValueTransformed(mqttUri(TOPIC_BOXED_SHORT_TRANSFORMED), writeCurrentValue);
boxedIntegers.connectLongValueTransformed(mqttUri(TOPIC_BOXED_LONG_TRANSFORMED), writeCurrentValue);
......@@ -154,57 +166,65 @@ public class DefaultOnlyWriteTest extends AbstractMqttTest {
private ReceiverData createReceiver(boolean transformed) {
ReceiverData result = new ReceiverData();
receiver.newConnection(transformed ? TOPIC_NATIVE_BOOLEAN_TRANSFORMED : TOPIC_NATIVE_BOOLEAN, bytes -> {
result.numberOfNativeBoolValues += 1;
result.lastNativeBoolValue = TestUtils.DefaultMappings.BytesToBool(bytes);
});
receiver.newConnection(transformed ? TOPIC_NATIVE_INT_TRANSFORMED : TOPIC_NATIVE_INT, bytes -> {
result.numberOfNativeIntValues += 1;
result.lastNativeIntValue = java.nio.ByteBuffer.wrap(bytes).getInt();
result.lastNativeIntValue = TestUtils.DefaultMappings.BytesToInt(bytes);