Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2017-11-06 10:37:41 +0000
committerHenrik Rentz-Reichert2017-11-07 06:58:06 +0000
commit48d51b2b32f759e255f0cca154d2757c95d15e19 (patch)
treef1455e17e092e88c01feac4b6cf7f5ec2d2896ff /tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice
parentb09856b29bfcaea08e9e57b14da3744c0a201867 (diff)
downloadorg.eclipse.etrice-48d51b2b32f759e255f0cca154d2757c95d15e19.tar.gz
org.eclipse.etrice-48d51b2b32f759e255f0cca154d2757c95d15e19.tar.xz
org.eclipse.etrice-48d51b2b32f759e255f0cca154d2757c95d15e19.zip
Bug 511330 - [core.genmodel.fsm] introduce simplified generator model
for state machines * manually merged newfsmgen to newfsmgen_finalize because no rebase was possible due to structural changes * rebased on master * switch to Oxygen and Xtend 2.12 Change-Id: If9a8c7421f07fb8e8fa824b7bc6761b9142b7eaf
Diffstat (limited to 'tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice')
-rw-r--r--tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestFSMGenModel.xtend121
1 files changed, 121 insertions, 0 deletions
diff --git a/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestFSMGenModel.xtend b/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestFSMGenModel.xtend
new file mode 100644
index 000000000..455c952e4
--- /dev/null
+++ b/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestFSMGenModel.xtend
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Juergen Haug (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.commands
+
+import com.google.common.collect.Sets
+import java.util.List
+import org.eclipse.emf.common.util.URI
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
+import org.eclipse.emf.ecore.util.EcoreUtil
+import org.eclipse.etrice.core.RoomStandaloneSetup
+import org.eclipse.etrice.core.TestBase
+import org.eclipse.etrice.core.fsm.fSM.StateGraphItem
+import org.eclipse.etrice.core.genmodel.fsm.ExtendedFsmGenBuilder
+import org.eclipse.etrice.core.genmodel.fsm.FsmGenChecker
+import org.eclipse.etrice.core.genmodel.fsm.IDiagnostician
+import org.eclipse.etrice.core.genmodel.fsm.NullDiagnostician
+import org.eclipse.etrice.core.genmodel.fsm.NullLogger
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.GraphContainer
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Link
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Node
+import org.eclipse.etrice.core.room.ActorClass
+import org.eclipse.etrice.core.room.RoomModel
+import org.eclipse.etrice.ui.behavior.BehaviorTestActivator
+import org.junit.Test
+
+import static org.junit.Assert.assertEquals
+import static org.junit.Assert.assertFalse
+import static org.junit.Assert.assertNotNull
+import static org.junit.Assert.assertTrue
+
+class TestFSMGenModel extends TestBase {
+
+ val injector = new RoomStandaloneSetup().createInjectorAndDoEMFRegistration()
+ protected IDiagnostician diagnostician = new NullDiagnostician
+ protected extension ExtendedFsmGenBuilder builder = new ExtendedFsmGenBuilder(injector, diagnostician)
+
+ protected def createResourceSetWithGc(String roomFile, String actorName) {
+ prepare(BehaviorTestActivator.^default.getBundle())
+ val res = getResource(roomFile)
+ val actor = (res.contents.get(0) as RoomModel).actorClasses.findFirst[name.equals(actorName)]
+
+ val gc = builder.createTransformedModel(actor) => [gc |
+ assertNotNull("graph context was created", gc)
+
+ val logger = new NullLogger
+ FsmGenChecker.check(gc, logger)
+ assertFalse("logger has no errors", logger.hasErrors)
+ save(gc, actor.name)
+ ]
+
+ res.resourceSet.createResource(URI.createURI('dummy://' + actorName + '.fsmgen')) => [
+ contents += gc
+ ]
+
+ return res.resourceSet
+ }
+
+ protected def save(GraphContainer gc, String fileName) {
+ val rs = new ResourceSetImpl
+ val uri = URI.createFileURI("./output/" + fileName + ".fsmgen")
+ val res = rs.createResource(uri)
+ res.contents.add(gc)
+ res.save(newHashMap)
+ }
+
+ @Test
+ def void testBaseClass() {
+ val rs = createResourceSetWithGc("InheritedStateMachine.room", "Base")
+ val actorClasses = EcoreUtil.getAllContents(rs, true).filter(ActorClass).filter[name == 'Base'].toList
+ val gc = rs.resources.map[contents].flatten.filter(GraphContainer).head
+
+ checkAgainstRoom(gc, actorClasses)
+ }
+
+ @Test
+ def void testDerivedClass() {
+ val rs = createResourceSetWithGc("InheritedStateMachine.room", "Derived")
+ val actorClasses = EcoreUtil.getAllContents(rs, true).filter(ActorClass).filter[name == 'Base' || name == 'Derived'].toList
+ val gc = rs.resources.map[contents].flatten.filter(GraphContainer).head
+
+ checkAgainstRoom(gc, actorClasses)
+ }
+
+ @Test
+ def void testDoubleDerivedClass() {
+ val rs = createResourceSetWithGc("InheritedStateMachine.room", "DoubleDerived")
+ val actorClasses = EcoreUtil.getAllContents(rs, true).filter(ActorClass).filter[name == 'Base' || name == 'Derived' || name == 'DoubleDerived'].toList
+ val gc = rs.resources.map[contents].flatten.filter(GraphContainer).head
+
+ checkAgainstRoom(gc, actorClasses)
+ }
+
+ def void checkAgainstRoom(GraphContainer gc, List<ActorClass> actorClasses) {
+ // genmodel should refer to latest fsm (check in-memory ref)
+ val genModelRefs = (EcoreUtil.getAllContents(gc, true).filter(Node).map[stateGraphNode] + EcoreUtil.getAllContents(gc, true).filter(Link).map[transition]).toSet
+ EcoreUtil.getAllContents(actorClasses.last, false).filter(StateGraphItem).forEach[
+ assertTrue('missing ' + EcoreUtil.getURI(it), genModelRefs.contains(it))
+ ]
+
+ // all fsm items should be in genmodel (check name)
+ // node, there are duplicate names in subgraphs => not complete
+ val stateGraphItemsNames = EcoreUtil.getAllContents(actorClasses, true).filter(StateGraphItem).map[name].toIterable.toSortedSet
+ val namesFromGenModel = genModelRefs.map[name].toSortedSet
+ assertEquals(stateGraphItemsNames, namesFromGenModel)
+ }
+
+ private def <T extends Comparable> toSortedSet(Iterable<T> iterable) {
+ Sets.<T>newTreeSet(iterable)
+ }
+
+} \ No newline at end of file

Back to the top