diff options
author | Henrik Rentz-Reichert | 2013-07-26 09:29:08 +0000 |
---|---|---|
committer | Henrik Rentz-Reichert | 2013-07-26 09:39:04 +0000 |
commit | 4f6f960093a1314b923d1132d15089d12a70a7d7 (patch) | |
tree | cfd99bc9789186c99297e0d1ced37d62851704ca /tests/org.eclipse.etrice.core.room.tests | |
parent | 27dddfbd1b567c8fa5bc813d36bc4e957e377c50 (diff) | |
download | org.eclipse.etrice-4f6f960093a1314b923d1132d15089d12a70a7d7.tar.gz org.eclipse.etrice-4f6f960093a1314b923d1132d15089d12a70a7d7.tar.xz org.eclipse.etrice-4f6f960093a1314b923d1132d15089d12a70a7d7.zip |
[*] manually merged DynamicActors, new ui.structure and physical model aware Java generator
Diffstat (limited to 'tests/org.eclipse.etrice.core.room.tests')
7 files changed, 279 insertions, 58 deletions
diff --git a/tests/org.eclipse.etrice.core.room.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.etrice.core.room.tests/META-INF/MANIFEST.MF index e96122293..ce6a8f7c4 100644 --- a/tests/org.eclipse.etrice.core.room.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.etrice.core.room.tests/META-INF/MANIFEST.MF @@ -5,8 +5,8 @@ Bundle-SymbolicName: org.eclipse.etrice.core.room.tests Bundle-Version: 0.4.0.qualifier Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-Vendor: Eclipse eTrice (Incubation) -Require-Bundle: org.eclipse.etrice.core.room;bundle-version="0.1.0", - org.eclipse.etrice.core.room.ui;bundle-version="0.1.0", +Require-Bundle: org.eclipse.etrice.core.room;bundle-version="0.4.0", + org.eclipse.etrice.core.room.ui;bundle-version="0.4.0", org.junit;bundle-version="4.8.1", org.eclipse.osgi;bundle-version="3.6.0", org.eclipse.xtext;bundle-version="2.1.1", diff --git a/tests/org.eclipse.etrice.core.room.tests/models/TestBindings.room b/tests/org.eclipse.etrice.core.room.tests/models/TestBindings.room index 19f9ebd91..f37c15084 100644 --- a/tests/org.eclipse.etrice.core.room.tests/models/TestBindings.room +++ b/tests/org.eclipse.etrice.core.room.tests/models/TestBindings.room @@ -1,64 +1,146 @@ RoomModel TestBindings { - LogicalSystem Sys { - SubSystemRef main: Application + + ActorClass Example1 { + Structure { + ActorRef ref1: AC1 + ActorRef ref2: AC2 + + // no self connection allowed, ports are identical + Binding ref1.reg and ref1.reg + } } - SubSystemClass Application { - ActorRef ref1: AC1 - ActorRef ref2: AC2 - - // no self connection allowed, ports are indentical - Binding ref1.reg and ref1.reg - - // port with multiplicity 1 is already connected - Binding ref1.reg and ref2.conj - Binding ref1.reg and ref2.conj - - // protocols don't match - Binding ref1.reg and ref2.other - - // protocol extends incoming - Binding ref1.base and ref2.extin - - // ok - Binding ref1.base2 and ref2.extout - - // protocol extends outgoing - Binding ref1.base3 and ref2.extout2 - - // derived protocols not connectable (both directions extended) - Binding ref1.base4 and ref2.extinout - - LogicalThread dflt_thread + ActorClass Example1a { + Structure { + ActorRef ref1: AC1 + ActorRef ref2: AC2 + + // ports are already bound + Binding ref1.reg and ref2.conj + Binding ref1.reg and ref2.conj + } + } + + ActorClass Example2 { + Structure { + ActorRef ref1: AC1 + ActorRef ref2: AC2 + ActorRef ref3: AC2 + + // port with multiplicity 1 is already connected + Binding ref1.reg and ref2.conj + Binding ref1.reg and ref3.conj + } + } + + ActorClass Example3 { + Structure { + ActorRef ref1: AC1 + ActorRef ref2: AC2 + + // protocols don't match + Binding ref1.reg and ref2.other + } + } + + ActorClass Example4 { + Structure { + ActorRef ref1: AC3 + ActorRef ref2: AC4 + + // protocol extends incoming + Binding ref1.base and ref2.extin + } + } + + ActorClass Example5 { + Structure { + ActorRef ref1: AC3 + ActorRef ref2: AC4 + + // ok + Binding ref1.base2 and ref2.extout + } + } + + ActorClass Example6 { + Structure { + ActorRef ref1: AC3 + ActorRef ref2: AC4 + + // protocol extends outgoing + Binding ref1.base3 and ref2.extout2 + } + } + + ActorClass Example7 { + Structure { + ActorRef ref1: AC3 + ActorRef ref2: AC4 + + // derived protocols not connectable (both directions extended) + Binding ref1.base4 and ref2.extinout + } } + ActorClass Example8 { + Structure { + ActorRef ref1: AC5 + ActorRef ref2: AC6 + ActorRef ref3: AC5 + ActorRef ref4: AC6 + + // a replicated port must have at most one replicated peer + Binding ref1.p and ref2.pc + Binding ref2.pc and ref3.p + Binding ref3.p and ref4.pc + } + } + + + // helper actor classes + ActorClass AC1 { Interface { Port reg: PC1 + } + } + + ActorClass AC2 { + Interface { + conjugated Port conj: PC1 + conjugated Port other: PC2 + } + } + + ActorClass AC3 { + Interface { Port base: PCBase Port base2: PCBase conjugated Port base3: PCBase conjugated Port base4: PCBase } - Structure { - external Port reg - } - Behavior { } } - ActorClass AC2 { + ActorClass AC4 { Interface { - conjugated Port conj: PC1 - conjugated Port other: PC2 conjugated Port extout: PCExtendOut conjugated Port extin: PCExtendIn Port extout2: PCExtendOut Port extinout: PCExtendInOut } - Structure { - external Port conj + } + + ActorClass AC5 { + Interface { + Port p[2]: PC1 + } + } + + ActorClass AC6 { + Interface { + conjugated Port pc[2]: PC1 } - Behavior { } } ProtocolClass PC1 { diff --git a/tests/org.eclipse.etrice.core.room.tests/models/TestDynamicActors.room b/tests/org.eclipse.etrice.core.room.tests/models/TestDynamicActors.room new file mode 100644 index 000000000..b4dc94564 --- /dev/null +++ b/tests/org.eclipse.etrice.core.room.tests/models/TestDynamicActors.room @@ -0,0 +1,24 @@ +RoomModel test { + + ActorClass Test { + Structure { + ActorRef dflt: Ref + fixed ActorRef fix: Ref + optional ActorRef opt: Ref + + // arrays + ActorRef dfltArrayFixed[3]: Ref + fixed ActorRef fixArrayFixed[3]: Ref + optional ActorRef optArrayAny[*]: Ref + ActorRef dfltArrayAny[*]: Ref + fixed ActorRef fixArrayAny[*]: Ref + optional ActorRef optArrayFixed[3]: Ref + } + Behavior { } + } + + ActorClass Ref { + Structure { } + Behavior { } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/TestBase.java b/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/TestBase.java index fd7d3f934..8922ce74d 100644 --- a/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/TestBase.java +++ b/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/TestBase.java @@ -61,7 +61,7 @@ public class TestBase { public Diagnostic getDiag(EObject ele) { Map<Object, Object> options = Maps.newHashMap(); - options.put(CheckMode.KEY, CheckMode.ALL); + options.put(CheckMode.KEY, CheckMode.FAST_ONLY); options.put(CancelableDiagnostician.CANCEL_INDICATOR, CancelIndicator.NullImpl); // disable concrete syntax validation, since a semantic model that has been parsed // from the concrete syntax always complies with it - otherwise there are parse errors. diff --git a/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/TestBindings.java b/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/TestBindings.java index 1c8fb8703..2ed4994e4 100644 --- a/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/TestBindings.java +++ b/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/TestBindings.java @@ -16,10 +16,11 @@ import static org.junit.Assert.*; import org.eclipse.emf.common.util.Diagnostic; import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.etrice.core.room.ActorClass; import org.eclipse.etrice.core.room.Binding; import org.eclipse.etrice.core.room.GeneralProtocolClass; import org.eclipse.etrice.core.room.RoomModel; -import org.eclipse.etrice.core.room.SubSystemClass; +import org.eclipse.etrice.core.validation.RoomJavaValidator; import org.junit.Before; import org.junit.Test; @@ -39,35 +40,55 @@ public class TestBindings extends TestBase { @Test public void testBindingValidation() { - RoomModel mdl = (RoomModel) resource.getContents().get(0); - SubSystemClass ssc = mdl.getSubSystemClasses().get(0); - Binding bind = ssc.getBindings().get(0); + Binding bind = getBinding("Example1", 0); Diagnostic diag = getDiag(bind).getChildren().get(0); - assertEquals("expect error message", "no self connection allowed, ports are indentical", diag.getMessage()); + assertEquals("expect error message", "no self connection allowed, ports are identical", diag.getMessage()); + + bind = getBinding("Example1a", 0); + diag = getDiag(bind).getChildren().get(0); + assertEquals("expect error message", "ports are already bound", diag.getMessage()); + + bind = getBinding("Example1a", 1); + diag = getDiag(bind).getChildren().get(0); + assertEquals("expect error message", "ports are already bound", diag.getMessage()); - bind = ssc.getBindings().get(1); + bind = getBinding("Example2", 0); diag = getDiag(bind).getChildren().get(0); assertEquals("expect error message", "port with multiplicity 1 is already connected", diag.getMessage()); - bind = ssc.getBindings().get(2); + bind = getBinding("Example2", 0); diag = getDiag(bind).getChildren().get(0); assertEquals("expect error message", "port with multiplicity 1 is already connected", diag.getMessage()); - bind = ssc.getBindings().get(3); + bind = getBinding("Example3", 0); diag = getDiag(bind).getChildren().get(0); assertEquals("protocols don't match", diag.getMessage()); - bind = ssc.getBindings().get(4); + bind = getBinding("Example4", 0); diag = getDiag(bind).getChildren().get(0); assertEquals("protocol extends incoming", diag.getMessage()); - bind = ssc.getBindings().get(6); + bind = getBinding("Example5", 0); + diag = getDiag(bind); + assertTrue("binding is ok", diag.getChildren().isEmpty()); + + bind = getBinding("Example6", 0); diag = getDiag(bind).getChildren().get(0); assertEquals("protocol extends outgoing", diag.getMessage()); - bind = ssc.getBindings().get(7); + bind = getBinding("Example7", 0); diag = getDiag(bind).getChildren().get(0); assertEquals("derived protocols not connectable (both directions extended)", diag.getMessage()); + + diag = getDiag(resource.getEObject("ActorClass:Example8")); + Diagnostic childDiag = diag.getChildren().get(0); + assertEquals(RoomJavaValidator.A_REPLICATED_PORT_MUST_HAVE_AT_MOST_ONE_REPLICATED_PEER, childDiag.getMessage()); + childDiag = diag.getChildren().get(1); + assertEquals(RoomJavaValidator.A_REPLICATED_PORT_MUST_HAVE_AT_MOST_ONE_REPLICATED_PEER, childDiag.getMessage()); + childDiag = diag.getChildren().get(2); + assertEquals(RoomJavaValidator.A_REPLICATED_PORT_MUST_HAVE_AT_MOST_ONE_REPLICATED_PEER, childDiag.getMessage()); + childDiag = diag.getChildren().get(3); + assertEquals(RoomJavaValidator.A_REPLICATED_PORT_MUST_HAVE_AT_MOST_ONE_REPLICATED_PEER, childDiag.getMessage()); } @Test @@ -80,4 +101,9 @@ public class TestBindings extends TestBase { } } } + + private Binding getBinding(String acname, int idx) { + ActorClass ac = (ActorClass) resource.getEObject("ActorClass:"+acname); + return ac.getBindings().get(idx); + } } diff --git a/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/TestCases.java b/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/TestCases.java index 56815e6b3..8030130c0 100644 --- a/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/TestCases.java +++ b/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/TestCases.java @@ -15,6 +15,7 @@ import java.util.HashMap; import org.eclipse.emf.common.util.Diagnostic; import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.etrice.core.validation.ValidationUtil; import org.junit.Before; import org.junit.Test; @@ -26,10 +27,6 @@ import org.junit.Test; */ public class TestCases extends TestBase { - /** - * - */ - private static final String MSG1 = "connected sub component ports must be conjugated to each other"; private Resource resource; @Before @@ -44,7 +41,8 @@ public class TestCases extends TestBase { Diagnostic diag = getDiag(resource.getContents().get(0)); HashMap<String, Diagnostic> msg2diag = getMappedDiagnostics(diag); assertEquals("number of problems", 1, msg2diag.size()); - assertNotNull(MSG1, msg2diag.get(MSG1)); + assertNotNull(ValidationUtil.CONNECTED_SUB_COMPONENT_PORTS_MUST_BE_CONJUGATED_TO_EACH_OTHER, + msg2diag.get(ValidationUtil.CONNECTED_SUB_COMPONENT_PORTS_MUST_BE_CONJUGATED_TO_EACH_OTHER)); } /** diff --git a/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/TestDynamicActors.java b/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/TestDynamicActors.java new file mode 100644 index 000000000..163223420 --- /dev/null +++ b/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/TestDynamicActors.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * 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.*; + +import java.util.List; + +import org.eclipse.emf.common.util.Diagnostic; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.etrice.core.room.ActorClass; +import org.eclipse.etrice.core.room.ActorRef; +import org.eclipse.etrice.core.room.ReferenceType; +import org.eclipse.etrice.core.validation.RoomJavaValidator; +import org.junit.Before; +import org.junit.Test; + +/** + * @author Henrik Rentz-Reichert + * + */ +public class TestDynamicActors extends TestBase { + private Resource resource; + + @Before + public void setUp() { + prepare(); + + resource = getResource("TestDynamicActors.room"); + } + + @Test + public void testDynamicActors() { + ActorClass ac = (ActorClass) resource.getEObject("ActorClass:Test"); + assertNotNull("actor class test found", ac); + ActorRef ar; + + // scalar refs + ar = (ActorRef) resource.getEObject("ActorRef:Test$dflt"); + assertTrue("ActorRef dflt is of ref type fixed", ar.getRefType()==ReferenceType.FIXED); + ar = (ActorRef) resource.getEObject("ActorRef:Test$fix"); + assertTrue("ActorRef fix is of ref type fixed", ar.getRefType()==ReferenceType.FIXED); + ar = (ActorRef) resource.getEObject("ActorRef:Test$opt"); + assertTrue("ActorRef opt is of ref type fixed", ar.getRefType()==ReferenceType.OPTIONAL); + } + + @Test + public void testDynamicActorValidation() { + ActorRef ar; + List<Diagnostic> errors; + + // arrays + ar = (ActorRef) resource.getEObject("ActorRef:Test$dfltArrayFixed"); + errors = getDiag(ar).getChildren(); + assertTrue("ActorRef dfltArrayFixed has no errors", errors.isEmpty()); + ar = (ActorRef) resource.getEObject("ActorRef:Test$fixArrayFixed"); + errors = getDiag(ar).getChildren(); + assertTrue("ActorRef fixArrayFixed has no errors", errors.isEmpty()); + ar = (ActorRef) resource.getEObject("ActorRef:Test$optArrayAny"); + errors = getDiag(ar).getChildren(); + assertTrue("ActorRef optArrayAny has no errors", errors.isEmpty()); + ar = (ActorRef) resource.getEObject("ActorRef:Test$dfltArrayAny"); + errors = getDiag(ar).getChildren(); + assertEquals("ActorRef dfltArrayAny has one error", 1, errors.size()); + assertEquals("ActorRef dfltArrayAny has error: "+RoomJavaValidator.MULTIPLICITY_ANY_REQUIRES_OPTIONAL, + RoomJavaValidator.MULTIPLICITY_ANY_REQUIRES_OPTIONAL, + errors.get(0).getMessage()); + ar = (ActorRef) resource.getEObject("ActorRef:Test$fixArrayAny"); + errors = getDiag(ar).getChildren(); + assertEquals("ActorRef fixArrayAny has one error", 1, errors.size()); + assertEquals("ActorRef fixArrayAny has error: "+RoomJavaValidator.MULTIPLICITY_ANY_REQUIRES_OPTIONAL, + RoomJavaValidator.MULTIPLICITY_ANY_REQUIRES_OPTIONAL, + errors.get(0).getMessage()); + ar = (ActorRef) resource.getEObject("ActorRef:Test$optArrayFixed"); + errors = getDiag(ar).getChildren(); + assertEquals("ActorRef optArrayFixed has one error", 1, errors.size()); + assertEquals("ActorRef optArrayFixed has error: "+RoomJavaValidator.OPTIONAL_REFS_HAVE_TO_HAVE_MULTIPLICITY_ANY, + RoomJavaValidator.OPTIONAL_REFS_HAVE_TO_HAVE_MULTIPLICITY_ANY, + errors.get(0).getMessage()); + } +} |