Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2013-11-14 11:26:35 +0000
committerHenrik Rentz-Reichert2013-11-15 09:47:35 +0000
commitaf42471511f758e47a5962345e91d5a1f5fe266c (patch)
treed55f732b54c06b81ce3d9ee051268693615906e8 /tests/org.eclipse.etrice.core.room.tests
parent88ef1ceb04743522dca1198378771480754d3657 (diff)
downloadorg.eclipse.etrice-af42471511f758e47a5962345e91d5a1f5fe266c.tar.gz
org.eclipse.etrice-af42471511f758e47a5962345e91d5a1f5fe266c.tar.xz
org.eclipse.etrice-af42471511f758e47a5962345e91d5a1f5fe266c.zip
Bug 392072: enums as Primitive Types that can be used as Attributes for Operations and Messages
https://bugs.eclipse.org/392072 Change-Id: I6e16a691df0d720956652529f912eaed1d58097b
Diffstat (limited to 'tests/org.eclipse.etrice.core.room.tests')
-rw-r--r--tests/org.eclipse.etrice.core.room.tests/models/EnumExample.room45
-rw-r--r--tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/TestEnumerations.java136
2 files changed, 181 insertions, 0 deletions
diff --git a/tests/org.eclipse.etrice.core.room.tests/models/EnumExample.room b/tests/org.eclipse.etrice.core.room.tests/models/EnumExample.room
new file mode 100644
index 000000000..fa1818927
--- /dev/null
+++ b/tests/org.eclipse.etrice.core.room.tests/models/EnumExample.room
@@ -0,0 +1,45 @@
+RoomModel EnumExample {
+ PrimitiveType int16: ptInteger -> short(Short) default "0"
+ PrimitiveType char: ptCharacter -> char(Char) default ""
+
+ Enumeration FirstEnum {
+ zero, // 0
+ one, // 1
+ two, // 2
+ three // 3
+ }
+
+ Enumeration SecondEnum {
+ one = 1, // 1
+ two, // 2
+ three // 3
+ }
+
+ Enumeration ThirdEnum {
+ one = 1, // 1
+ two, // 2
+ five = 5 // 5
+ }
+
+ Enumeration FourthEnum {
+ one = 1, // 1
+ three = 3, // 3
+ sixtyfive = 0x41 // 0x41 or 65
+ }
+
+ Enumeration FifthEnum of int16 {
+ f1 = 0x1, // 0x1 or 1
+ f2 = 0x2, // 0x2 or 2
+ f3 = 0x4, // 0x4 or 4
+ f4 = 0x8 // 0x8 or 8
+ }
+
+ Enumeration WrongType of char /* <- ERROR: no integer primitive type */ {
+ c
+ }
+
+ Enumeration EmptyEnum {
+ // ERROR: no literals defined
+ }
+
+} \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/TestEnumerations.java b/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/TestEnumerations.java
new file mode 100644
index 000000000..adc68f457
--- /dev/null
+++ b/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/TestEnumerations.java
@@ -0,0 +1,136 @@
+/*******************************************************************************
+ * Copyright (c) 2013 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.core;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.etrice.core.room.EnumLiteral;
+import org.eclipse.etrice.core.room.EnumerationType;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class TestEnumerations extends TestBase {
+ private Resource res = null;
+
+ @Before
+ public void SetUp() {
+ prepare();
+ res = getResource("EnumExample.room");
+ }
+
+ @Test
+ public void testImplicitEnumValues() {
+ EObject obj = res.getEObject("EnumerationType:FirstEnum");
+ EnumerationType et = (EnumerationType) obj;
+ Diagnostic diag = getDiag(et);
+ assertTrue(diag.getChildren().isEmpty());
+
+ int i = 0;
+ for (EnumLiteral lit : et.getLiterals()) {
+ assertEquals("literal value", i++, lit.getLiteralValue());
+ }
+ }
+
+ @Test
+ public void testImplicitEnumValuesWithStart() {
+ EObject obj = res.getEObject("EnumerationType:SecondEnum");
+ EnumerationType et = (EnumerationType) obj;
+ Diagnostic diag = getDiag(et);
+ assertTrue(diag.getChildren().isEmpty());
+
+ int i = 1;
+ for (EnumLiteral lit : et.getLiterals()) {
+ assertEquals("literal value", i++, lit.getLiteralValue());
+ }
+ }
+
+ @Test
+ public void testPartialExplicitValues() {
+ EObject obj = res.getEObject("EnumerationType:ThirdEnum");
+ EnumerationType et = (EnumerationType) obj;
+ Diagnostic diag = getDiag(et);
+ assertTrue(diag.getChildren().isEmpty());
+
+ for (EnumLiteral lit : et.getLiterals()) {
+ if (lit.getName().equals("one"))
+ assertEquals("literal value", 1, lit.getLiteralValue());
+ else if (lit.getName().equals("two"))
+ assertEquals("literal value", 2, lit.getLiteralValue());
+ else if (lit.getName().equals("five"))
+ assertEquals("literal value", 5, lit.getLiteralValue());
+ }
+ }
+
+ @Test
+ public void testExplicitValuesWithHex() {
+ EObject obj = res.getEObject("EnumerationType:FourthEnum");
+ EnumerationType et = (EnumerationType) obj;
+ Diagnostic diag = getDiag(et);
+ assertTrue(diag.getChildren().isEmpty());
+
+ for (EnumLiteral lit : et.getLiterals()) {
+ if (lit.getName().equals("one"))
+ assertEquals("literal value", 1, lit.getLiteralValue());
+ else if (lit.getName().equals("three"))
+ assertEquals("literal value", 3, lit.getLiteralValue());
+ else if (lit.getName().equals("sixtyfive"))
+ assertEquals("literal value", 0x41, lit.getLiteralValue());
+ }
+ }
+
+ @Test
+ public void testExplicitValuesWithHexOnly() {
+ EObject obj = res.getEObject("EnumerationType:FourthEnum");
+ EnumerationType et = (EnumerationType) obj;
+ Diagnostic diag = getDiag(et);
+ assertTrue(diag.getChildren().isEmpty());
+
+ for (EnumLiteral lit : et.getLiterals()) {
+ if (lit.getName().equals("f1"))
+ assertEquals("literal value", 0x1, lit.getLiteralValue());
+ else if (lit.getName().equals("f2"))
+ assertEquals("literal value", 0x2, lit.getLiteralValue());
+ else if (lit.getName().equals("f3"))
+ assertEquals("literal value", 0x4, lit.getLiteralValue());
+ else if (lit.getName().equals("f4"))
+ assertEquals("literal value", 0x8, lit.getLiteralValue());
+ }
+ }
+
+ @Test
+ public void testWrongEnumType() {
+ EObject obj = res.getEObject("EnumerationType:WrongType");
+ EnumerationType et = (EnumerationType) obj;
+ Diagnostic diag = getDiag(et);
+ assertTrue(diag.getChildren().size() == 1);
+ assertTrue(diag.getChildren().get(0).getMessage().contains("enumerations must be of integer type"));
+ }
+
+ @Test
+ public void testEmptyEnum() {
+ EObject obj = res.getEObject("EnumerationType:EmptyEnum");
+ EnumerationType et = (EnumerationType) obj;
+ Diagnostic diag = getDiag(et);
+ assertTrue(diag.getChildren().size() == 1);
+ assertTrue(diag.getChildren().get(0).getMessage().contains("at least one literal has to be specified"));
+ }
+
+}

Back to the top