Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2012-07-20 08:31:52 +0000
committerHenrik Rentz-Reichert2012-07-20 08:31:52 +0000
commit886d26c5aaa2c8a04057713fc3778199773cbed6 (patch)
tree7a85b6300b12a85abab7d118080dd6448f3f132e /tests/org.eclipse.etrice.generator.tests
parentcbda5a83576974bc145bbeadd2192dba0fb0b7f5 (diff)
downloadorg.eclipse.etrice-886d26c5aaa2c8a04057713fc3778199773cbed6.tar.gz
org.eclipse.etrice-886d26c5aaa2c8a04057713fc3778199773cbed6.tar.xz
org.eclipse.etrice-886d26c5aaa2c8a04057713fc3778199773cbed6.zip
[generator, generator.c] improved translation provider for attributes
distinguish get and set and support for arrays
Diffstat (limited to 'tests/org.eclipse.etrice.generator.tests')
-rw-r--r--tests/org.eclipse.etrice.generator.tests/src/org/eclipse/etrice/generator/base/TestDetailCodeTranslator.java67
1 files changed, 62 insertions, 5 deletions
diff --git a/tests/org.eclipse.etrice.generator.tests/src/org/eclipse/etrice/generator/base/TestDetailCodeTranslator.java b/tests/org.eclipse.etrice.generator.tests/src/org/eclipse/etrice/generator/base/TestDetailCodeTranslator.java
index e82fe49d7..6a6555de3 100644
--- a/tests/org.eclipse.etrice.generator.tests/src/org/eclipse/etrice/generator/base/TestDetailCodeTranslator.java
+++ b/tests/org.eclipse.etrice.generator.tests/src/org/eclipse/etrice/generator/base/TestDetailCodeTranslator.java
@@ -62,8 +62,19 @@ public class TestDetailCodeTranslator {
}
@Override
- public String getAttributeText(Attribute att, String orig) {
- return ">"+att.getName()+"<";
+ public String getAttributeGetter(Attribute att, String index, String orig) {
+ if (index==null)
+ return ">"+att.getName()+"<";
+ else
+ return ">"+att.getName()+"["+index+"]<";
+ }
+
+ @Override
+ public String getAttributeSetter(Attribute att, String index, String value, String orig) {
+ if (index==null)
+ return ">"+att.getName()+" = "+value+"<";
+ else
+ return ">"+att.getName()+"["+index+"] = "+value+"<";
}
@Override
@@ -153,6 +164,12 @@ public class TestDetailCodeTranslator {
attr.setName("value");
attr.setRefType(EcoreUtil.copy(refType));
ac.getAttributes().add(attr);
+
+ attr = RoomFactory.eINSTANCE.createAttribute();
+ attr.setName("array");
+ attr.setRefType(EcoreUtil.copy(refType));
+ attr.setSize(8);
+ ac.getAttributes().add(attr);
StandardOperation op0 = RoomFactory.eINSTANCE.createStandardOperation();
op0.setName("bar0");
@@ -342,13 +359,53 @@ public class TestDetailCodeTranslator {
}
@Test
- public void testAttribute() {
+ public void testAttributeGetter() {
+ DetailCode dc = RoomFactory.eINSTANCE.createDetailCode();
+ dc.getCommands().add("int x = value*2;");
+
+ String result = translator.translateDetailCode(dc);
+
+ assertEquals("read attribute", "int x = >value<*2;", result);
+ }
+
+ @Test
+ public void testAttributeIndexedGetter() {
+ DetailCode dc = RoomFactory.eINSTANCE.createDetailCode();
+ dc.getCommands().add("int x = array[2]*2;");
+
+ String result = translator.translateDetailCode(dc);
+
+ assertEquals("read indexed attribute", "int x = >array[2]<*2;", result);
+ }
+
+ @Test
+ public void testAttributeSetter() {
+ DetailCode dc = RoomFactory.eINSTANCE.createDetailCode();
+ dc.getCommands().add("value.set(2);");
+
+ String result = translator.translateDetailCode(dc);
+
+ assertEquals("write attribute", ">value = 2<;", result);
+ }
+
+ @Test
+ public void testAttributeIndexedSetter() {
+ DetailCode dc = RoomFactory.eINSTANCE.createDetailCode();
+ dc.getCommands().add("array[3].set(2);");
+
+ String result = translator.translateDetailCode(dc);
+
+ assertEquals("write indexed attribute", ">array[3] = 2<;", result);
+ }
+
+ @Test
+ public void testAttributeIndexedSetterRecursive() {
DetailCode dc = RoomFactory.eINSTANCE.createDetailCode();
- dc.getCommands().add("value = 1;");
+ dc.getCommands().add("array[value].set(value);");
String result = translator.translateDetailCode(dc);
- assertEquals("attribute replacement", ">value< = 1;", result);
+ assertEquals("write indexed attribute", ">array[>value<] = >value<<;", result);
}
@Test

Back to the top