You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by hu...@apache.org on 2021/03/18 10:33:31 UTC
[plc4x] branch feature/string_enum_mspec updated: Add additional
tests to the test.mspec
This is an automated email from the ASF dual-hosted git repository.
hutcheb pushed a commit to branch feature/string_enum_mspec
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/feature/string_enum_mspec by this push:
new a83a6f0 Add additional tests to the test.mspec
a83a6f0 is described below
commit a83a6f005b4316741fe97e5c18f2f0d74c411e65
Author: hutcheb <be...@gmail.com>
AuthorDate: Thu Mar 18 06:19:36 2021 -0400
Add additional tests to the test.mspec
---
.../resources/templates/c/enum-template-h.ftlh | 3 +-
.../resources/templates/java/enum-template.ftlh | 2 +-
.../src/main/resources/protocols/test/test.mspec | 117 +++++++++++++++++++--
3 files changed, 113 insertions(+), 9 deletions(-)
diff --git a/build-utils/language-c/src/main/resources/templates/c/enum-template-h.ftlh b/build-utils/language-c/src/main/resources/templates/c/enum-template-h.ftlh
index 497195d..b606737 100644
--- a/build-utils/language-c/src/main/resources/templates/c/enum-template-h.ftlh
+++ b/build-utils/language-c/src/main/resources/templates/c/enum-template-h.ftlh
@@ -50,6 +50,7 @@ ${helper.getIncludesDirectory()?replace(".", "/")}/${helper.camelCaseToSnakeCase
</#list>
</#if>
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -59,7 +60,7 @@ extern "C" {
-->
enum ${helper.getCTypeName(type.name)} {
<#list type.enumValues as enumValue>
- ${helper.getCTypeName(type.name)}_${enumValue.name} = <#if helper.isStringTypeReference(type.type)>${enumValue?index}<#else>${enumValue.value}</#if><#sep>,
+ ${helper.getCTypeName(type.name)}_${enumValue.name} = <#if helper.isStringTypeReference(type.type)>${enumValue?index}<#elseif helper.isComplexTypeReference(type.type)><#if helper.isEnumTypeReference(type.type)>${helper.getLanguageTypeNameForTypeReference(type.type)}_${enumValue.value}<#else>${enumValue.value}</#if><#else>${enumValue.value}</#if><#sep>,
</#sep></#list>
};
diff --git a/build-utils/language-java/src/main/resources/templates/java/enum-template.ftlh b/build-utils/language-java/src/main/resources/templates/java/enum-template.ftlh
index f3cac8b..e43f628 100644
--- a/build-utils/language-java/src/main/resources/templates/java/enum-template.ftlh
+++ b/build-utils/language-java/src/main/resources/templates/java/enum-template.ftlh
@@ -59,7 +59,7 @@ import java.util.Map;
public enum ${type.name} {
<#list type.enumValues as enumValue>
- ${enumValue.name}(<#if type.type?has_content>(${helper.getLanguageTypeNameForTypeReference(type.type, true)}) <#if helper.isStringTypeReference(type.type)>"${enumValue.value}"<#else>${enumValue.value}</#if></#if><#if type.constantNames?has_content><#if type.type?has_content>, </#if><#list type.constantNames as constantName><#if helper.isComplexTypeReference(type.getConstantType(constantName))><#if helper.escapeValue(type.getConstantType(constantName), enumValue.getConstant(constantNa [...]
+ ${enumValue.name}(<#if type.type?has_content>(${helper.getLanguageTypeNameForTypeReference(type.type, true)}) <#if helper.isStringTypeReference(type.type)>"${enumValue.value}"<#elseif helper.isComplexTypeReference(type.type)><#if helper.isEnumTypeReference(type.type)>${helper.getLanguageTypeNameForTypeReference(type.type, true)}.${enumValue.value}<#else>${enumValue.value}</#if><#else>${enumValue.value}</#if></#if><#if type.constantNames?has_content><#if type.type?has_content>, </#if> [...]
</#sep></#list>;
<#if type.type?has_content>
diff --git a/build-utils/protocol-test/src/main/resources/protocols/test/test.mspec b/build-utils/protocol-test/src/main/resources/protocols/test/test.mspec
index 8b78d0a..41a7666 100644
--- a/build-utils/protocol-test/src/main/resources/protocols/test/test.mspec
+++ b/build-utils/protocol-test/src/main/resources/protocols/test/test.mspec
@@ -165,7 +165,7 @@
]
////////////////////////////////////////////////////////////////
-// Discriminated Type
+// Discriminated Type Tests
////////////////////////////////////////////////////////////////
[discriminatedType 'EnumDiscriminatedType'
@@ -183,6 +183,53 @@
]
]
+// Multiple Enumerated discriminators
+[discriminatedType 'EnumDiscriminatedTypeMultiple'
+ [discriminator EnumType 'discr1']
+ [discriminator EnumTypeInt 'discr2']
+ [typeSwitch 'discr1','discr2'
+ ['BOOL','BOOLINT' EnumDiscriminatedTypeMultipleA
+ [simple uint 8 'simpA']
+ ]
+ ['UINT','UINTINT' EnumDiscriminatedTypeMultipleB
+ [simple uint 8 'simpB']
+ ]
+ ['INT','INTINT' EnumDiscriminatedTypeMultipleC
+ [simple uint 8 'simpC']
+ ]
+ ]
+]
+
+// Enumerated Parameter
+[discriminatedType 'EnumDiscriminatedTypeParameter' [EnumType 'discr']
+ [typeSwitch 'discr'
+ ['BOOL' EnumDiscriminatedTypeAParameter
+ [simple uint 8 'simpA']
+ ]
+ ['UINT' EnumDiscriminatedTypeBParameter
+ [simple uint 8 'simpB']
+ ]
+ ['INT' EnumDiscriminatedTypeCParameter
+ [simple uint 8 'simpC']
+ ]
+ ]
+]
+
+// Multiple Enumerated Parameters
+[discriminatedType 'EnumDiscriminatedTypeParameterMultiple' [EnumType 'discr1', EnumTypeInt 'discr2']
+ [typeSwitch 'discr1','discr2'
+ ['BOOL','BOOLINT' EnumDiscriminatedTypeAParameterMultiple
+ [simple uint 8 'simpA']
+ ]
+ ['UINT','UINTINT' EnumDiscriminatedTypeBParameterMultiple
+ [simple uint 8 'simpB']
+ ]
+ ['INT','INTINT' EnumDiscriminatedTypeCParameterMultiple
+ [simple uint 8 'simpC']
+ ]
+ ]
+]
+
[discriminatedType 'SimpleDiscriminatedType'
[discriminator uint 8 'discr']
[typeSwitch 'discr'
@@ -198,17 +245,26 @@
]
]
-
-
////////////////////////////////////////////////////////////////
-// Arguments Type
+// Enumerated Type Tests
////////////////////////////////////////////////////////////////
+//Not really useful, but this uses the pojo templates instead of the enum templates
+[enum int 8 'EnumEmpty'
-////////////////////////////////////////////////////////////////
-// Discriminated Type with multiple conditions
-////////////////////////////////////////////////////////////////
+]
+// Go doesn't support Enumerated Bits
+//[enum bit 'EnumTypeBit'
+// ['true' TRUE]
+// ['false' FALSE]
+//]
+
+[enum int 8 'EnumTypeInt'
+ ['0x01' BOOLINT]
+ ['0x02' UINTINT]
+ ['0x03' INTINT]
+]
[enum uint 8 'EnumType'
['0x01' BOOL]
@@ -216,6 +272,53 @@
['0x03' INT]
]
+// C doesn't support non integer switch fields
+//[enum float 8.23 'EnumTypeFloat'
+// ['100.0' LOW]
+// ['101.0' MID]
+// ['102.0' BIG]
+//]
+
+// C doesn't support non integer switch fields
+//[enum float 11.52 'EnumTypeDouble'
+// ['100.0' LOW]
+// ['101.0' MID]
+// ['102.0' BIG]
+//]
+
+//String based enum's needs some work in C, compiles but assigns 0 as values.
+[enum string '-1' 'EnumTypeString'
+ ['Toddy1' TODDY]
+]
+
+// Fails to import the base Enum in C, need to find it in getComplexTypeReferences
+//[enum EnumType 'EnumTypeEnum'
+// ['BOOL' BOOL]
+// ['UINT' UINT]
+// ['INT' INT]
+//]
+
+// Float parameters aren't implemented for constants in enums in C
+//[enum int 8 'EnumTypeAllTest' [bit 'bitType', int 8 'intType', uint 8 'uintType', float 8.23 'floatType', float 11.52 'doubleType', string '-1' 'stringType', EnumType 'enumType']
+// ['0x01' BOOL ['false' , '1' , '1' , '100.0' , '100.0' , 'IEC61131_BOOL' , 'BOOL']]
+// ['0x02' BYTE ['true' , '2' , '2' , '101.1' , '101.1' , 'IEC61131_BYTE' , 'UINT']]
+//]
+
+// Keyword named parameters aren't allowed
+//[enum int 8 'EnumTypeIntTest' [int 8 'int']
+// ['0x01' BOOL ['1']]
+// ['0x02' BYTE ['2']]
+//]
+
+//Showing allowed parameter types for enums
+[enum int 8 'EnumTypeParameters' [bit 'bitType', int 8 'intType', uint 8 'uintType', string '-1' 'stringType', EnumType 'enumType']
+ ['0x01' BOOL ['false' , '1' , '1' , 'IEC61131_BOOL' , 'BOOL']]
+ ['0x02' BYTE ['true' , '2' , '2' , 'IEC61131_BYTE' , 'UINT']]
+]
+
+////////////////////////////////////////////////////////////////
+// Data IO Tests
+////////////////////////////////////////////////////////////////
[dataIo 'DataIOTypeEmpty'