Преглед на файлове

Fixed statemachine reference not created if events are used in interfaces.

markus.muehlbrandt@itemis.de преди 13 години
родител
ревизия
cb83cfb793
променени са 9 файла, в които са добавени 190 реда и са изтрити 34 реда
  1. 0 2
      examples/org.yakindu.sct.generator.java.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/TrafficLightWaitingCycleBasedStatemachine.java
  2. 1 1
      plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/CustomInterfaceImpl.xpt
  3. 3 0
      plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/ExecutionModelExtensions.ext
  4. 0 11
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_hierarchy/Test_HierarchyCycleBasedStatemachine.java
  5. 0 12
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_parallelregions/Test_ParallelRegionsCycleBasedStatemachine.java
  6. 2 1
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src/org/yakindu/sct/generator/java/runtime/test/AllEventBasedStatemachineTests.java
  7. 23 0
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src/org/yakindu/sct/generator/java/runtime/test/AllStatemachineTests.java
  8. 12 7
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src/org/yakindu/sct/generator/java/runtime/test/TestParallelRegionsCycleBasedStatemachine.java
  9. 149 0
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src/org/yakindu/sct/generator/java/runtime/test/TestParallelRegionsEventBasedStatemachine.java

+ 0 - 2
examples/org.yakindu.sct.generator.java.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/TrafficLightWaitingCycleBasedStatemachine.java

@@ -366,7 +366,6 @@ public class TrafficLightWaitingCycleBasedStatemachine
 					default :
 						break;
 				}
-
 				getTimerService().resetTimer(PedWaiting_time_event_0);
 				interfacePedestrian.setVarRequest(false);
 
@@ -502,7 +501,6 @@ public class TrafficLightWaitingCycleBasedStatemachine
 					default :
 						break;
 				}
-
 				getTimerService().resetTimer(PedWaiting_time_event_0);
 				interfacePedestrian.setVarRequest(false);
 

+ 1 - 1
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/CustomInterfaceImpl.xpt

@@ -21,7 +21,7 @@ Contributors:
 «getLicenseHeader(entry)»
 package «getImplementationPackageName(entry)»;
 
-«IF hasEvents()-»
+«IF hasUnvaluedEvents()-»
 import «entry.getBasePackageName()».Event;
 «ENDIF-»
 «IF hasOutgoingEvents() && entry.createInterfaceObserverSupport()-»

+ 3 - 0
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/ExecutionModelExtensions.ext

@@ -44,6 +44,9 @@ boolean hasOutgoingValuedEvents(Scope this) :
 	!declarations.typeSelect(EventDefinition).select(event|event.direction == Direction::OUT).select(event|!event.type.isVoid()).isEmpty;
 
 boolean hasEvents(Scope this) :
+	!declarations.typeSelect(EventDefinition).isEmpty;
+
+boolean hasUnvaluedEvents(Scope this) :
 	!declarations.typeSelect(EventDefinition).select(event|event.type.isVoid()).isEmpty;
 	
 boolean hasValuedEvents(Scope this) :

+ 0 - 11
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_hierarchy/Test_HierarchyCycleBasedStatemachine.java

@@ -104,7 +104,6 @@ public class Test_HierarchyCycleBasedStatemachine implements IStatemachine {
 				default :
 					break;
 			}
-
 			defaultInterface.setVarS1(defaultInterface.getVarS1() - (1));
 
 			defaultInterface.setVarS2(1);
@@ -153,7 +152,6 @@ public class Test_HierarchyCycleBasedStatemachine implements IStatemachine {
 				default :
 					break;
 			}
-
 			defaultInterface.setVarS1(defaultInterface.getVarS1() - (1));
 
 			defaultInterface.setVarS2(1);
@@ -235,7 +233,6 @@ public class Test_HierarchyCycleBasedStatemachine implements IStatemachine {
 				default :
 					break;
 			}
-
 			defaultInterface.setVarS2(defaultInterface.getVarS2() - (1));
 
 			defaultInterface.setVarS1(1);
@@ -358,7 +355,6 @@ public class Test_HierarchyCycleBasedStatemachine implements IStatemachine {
 				default :
 					break;
 			}
-
 			defaultInterface.setVarS2(defaultInterface.getVarS2() - (1));
 
 			defaultInterface.setVarS1(1);
@@ -406,7 +402,6 @@ public class Test_HierarchyCycleBasedStatemachine implements IStatemachine {
 					default :
 						break;
 				}
-
 				defaultInterface.setVarS2(defaultInterface.getVarS2() - (1));
 
 				defaultInterface.setVarS2(defaultInterface.getVarS2() + (1));
@@ -539,7 +534,6 @@ public class Test_HierarchyCycleBasedStatemachine implements IStatemachine {
 				default :
 					break;
 			}
-
 			defaultInterface.setVarS2(defaultInterface.getVarS2() - (1));
 
 			defaultInterface.setVarS1(1);
@@ -587,7 +581,6 @@ public class Test_HierarchyCycleBasedStatemachine implements IStatemachine {
 					default :
 						break;
 				}
-
 				defaultInterface.setVarS2(defaultInterface.getVarS2() - (1));
 
 				defaultInterface.setVarS2(defaultInterface.getVarS2() + (1));
@@ -619,7 +612,6 @@ public class Test_HierarchyCycleBasedStatemachine implements IStatemachine {
 						default :
 							break;
 					}
-
 					defaultInterface
 							.setVarS2(defaultInterface.getVarS2() - (1));
 
@@ -706,7 +698,6 @@ public class Test_HierarchyCycleBasedStatemachine implements IStatemachine {
 				default :
 					break;
 			}
-
 			defaultInterface.setVarS2(defaultInterface.getVarS2() - (1));
 
 			defaultInterface.setVarS1(1);
@@ -754,7 +745,6 @@ public class Test_HierarchyCycleBasedStatemachine implements IStatemachine {
 					default :
 						break;
 				}
-
 				defaultInterface.setVarS2(defaultInterface.getVarS2() - (1));
 
 				defaultInterface.setVarS2(defaultInterface.getVarS2() + (1));
@@ -786,7 +776,6 @@ public class Test_HierarchyCycleBasedStatemachine implements IStatemachine {
 						default :
 							break;
 					}
-
 					defaultInterface
 							.setVarS2(defaultInterface.getVarS2() - (1));
 

+ 0 - 12
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_parallelregions/Test_ParallelRegionsCycleBasedStatemachine.java

@@ -115,7 +115,6 @@ public class Test_ParallelRegionsCycleBasedStatemachine
 				default :
 					break;
 			}
-
 			//Handle exit of all possible states on position 1...
 			switch (stateVector[1]) {
 
@@ -127,7 +126,6 @@ public class Test_ParallelRegionsCycleBasedStatemachine
 				default :
 					break;
 			}
-
 			//Handle exit of all possible states on position 2...
 			switch (stateVector[2]) {
 
@@ -200,7 +198,6 @@ public class Test_ParallelRegionsCycleBasedStatemachine
 				default :
 					break;
 			}
-
 			//Handle exit of all possible states on position 1...
 			switch (stateVector[1]) {
 
@@ -212,7 +209,6 @@ public class Test_ParallelRegionsCycleBasedStatemachine
 				default :
 					break;
 			}
-
 			//Handle exit of all possible states on position 2...
 			switch (stateVector[2]) {
 
@@ -271,7 +267,6 @@ public class Test_ParallelRegionsCycleBasedStatemachine
 				default :
 					break;
 			}
-
 			//Handle exit of all possible states on position 1...
 			switch (stateVector[1]) {
 
@@ -283,7 +278,6 @@ public class Test_ParallelRegionsCycleBasedStatemachine
 				default :
 					break;
 			}
-
 			//Handle exit of all possible states on position 2...
 			switch (stateVector[2]) {
 
@@ -342,7 +336,6 @@ public class Test_ParallelRegionsCycleBasedStatemachine
 				default :
 					break;
 			}
-
 			//Handle exit of all possible states on position 1...
 			switch (stateVector[1]) {
 
@@ -354,7 +347,6 @@ public class Test_ParallelRegionsCycleBasedStatemachine
 				default :
 					break;
 			}
-
 			//Handle exit of all possible states on position 2...
 			switch (stateVector[2]) {
 
@@ -413,7 +405,6 @@ public class Test_ParallelRegionsCycleBasedStatemachine
 				default :
 					break;
 			}
-
 			//Handle exit of all possible states on position 1...
 			switch (stateVector[1]) {
 
@@ -425,7 +416,6 @@ public class Test_ParallelRegionsCycleBasedStatemachine
 				default :
 					break;
 			}
-
 			//Handle exit of all possible states on position 2...
 			switch (stateVector[2]) {
 
@@ -499,7 +489,6 @@ public class Test_ParallelRegionsCycleBasedStatemachine
 				default :
 					break;
 			}
-
 			//Handle exit of all possible states on position 1...
 			switch (stateVector[1]) {
 
@@ -511,7 +500,6 @@ public class Test_ParallelRegionsCycleBasedStatemachine
 				default :
 					break;
 			}
-
 			//Handle exit of all possible states on position 2...
 			switch (stateVector[2]) {
 

+ 2 - 1
test-plugins/org.yakindu.sct.generator.java.runtime.test/src/org/yakindu/sct/generator/java/runtime/test/AllEventBasedStatemachineTests.java

@@ -18,7 +18,8 @@ import org.junit.runners.Suite;
 		TestInterfaceTestEventBasedStatemachine.class,
 		TestLocalActionsEventBasedStatemachine.class,
 		TestExpressionEventBasedStatemachine.class,
-		TestHierarchyEventBasedStatemachine.class
+		TestHierarchyEventBasedStatemachine.class,
+		TestParallelRegionsEventBasedStatemachine.class
 		})
 
 public class AllEventBasedStatemachineTests {

+ 23 - 0
test-plugins/org.yakindu.sct.generator.java.runtime.test/src/org/yakindu/sct/generator/java/runtime/test/AllStatemachineTests.java

@@ -0,0 +1,23 @@
+/**
+ * Copyright (c) 2011 committers of YAKINDU and others.
+ * 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:
+ * 	@author markus muehlbrandt - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.generator.java.runtime.test;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({ 
+		AllCycleBasedStatemachineTests.class,
+		AllEventBasedStatemachineTests.class
+		})
+
+public class AllStatemachineTests {
+}

+ 12 - 7
test-plugins/org.yakindu.sct.generator.java.runtime.test/src/org/yakindu/sct/generator/java/runtime/test/TestParallelRegionsCycleBasedStatemachine.java

@@ -10,15 +10,12 @@
  */
 package org.yakindu.sct.generator.java.runtime.test;
 
-import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.yakindu.sct.runtime.java.interfacetest.InterfaceTestCycleBasedStatemachine;
 import org.yakindu.sct.runtime.java.test_parallelregions.Test_ParallelRegionsCycleBasedStatemachine;
 import org.yakindu.sct.runtime.java.test_parallelregions.Test_ParallelRegionsCycleBasedStatemachine.State;
 
@@ -59,7 +56,7 @@ public class TestParallelRegionsCycleBasedStatemachine {
 		assertTrue("Statemachine isn't in State: " + State.State7.name() + ".",
 				statemachine.isStateActive(State.State7));
 
-		statemachine.getDefaultInterface().raiseEvent3();
+		statemachine.getDefaultInterface().raiseEvent5();
 		statemachine.runCycle();
 		// Test if state is changed to State3 && State8
 		assertTrue("Statemachine isn't in State: " + State.State3.name() + ".",
@@ -80,6 +77,14 @@ public class TestParallelRegionsCycleBasedStatemachine {
 		assertFalse(
 				"Statemachine isn't in State: " + State.State8.name() + ".",
 				statemachine.isStateActive(State.State8));
+
+		statemachine.getDefaultInterface().raiseEvent3();
+		statemachine.runCycle();
+		// Test if state is back to State1
+		assertTrue(statemachine.isStateActive(State.State1));
+		assertFalse(statemachine.isStateActive(State.State3));
+		assertFalse(statemachine.isStateActive(State.State7));
+		assertFalse(statemachine.isStateActive(State.State8));
 	}
 
 	@Test
@@ -125,10 +130,10 @@ public class TestParallelRegionsCycleBasedStatemachine {
 				statemachine.isStateActive(State.State9));
 		assertTrue("Statemachine isn't in State: " + State.State6.name() + ".",
 				statemachine.isStateActive(State.State6));
-		assertTrue(
-				"Statemachine isn't in State: " + State.State7.name() + ".",
+		assertTrue("Statemachine isn't in State: " + State.State7.name() + ".",
 				statemachine.isStateActive(State.State7));
-		assertFalse("Statemachine isn't in State: " + State.State8.name() + ".",
+		assertFalse(
+				"Statemachine isn't in State: " + State.State8.name() + ".",
 				statemachine.isStateActive(State.State8));
 	}
 

+ 149 - 0
test-plugins/org.yakindu.sct.generator.java.runtime.test/src/org/yakindu/sct/generator/java/runtime/test/TestParallelRegionsEventBasedStatemachine.java

@@ -0,0 +1,149 @@
+/**
+ * Copyright (c) 2011 committers of YAKINDU and others.
+ * 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:
+ * 	@author markus muehlbrandt - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.generator.java.runtime.test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.yakindu.sct.runtime.java.RuntimeService;
+import org.yakindu.sct.runtime.java.TimerService;
+import org.yakindu.sct.runtime.java.test_parallelregions.Test_ParallelRegionsCycleBasedStatemachine.State;
+import org.yakindu.sct.runtime.java.test_parallelregions.Test_ParallelRegionsEventBasedStatemachine;
+
+/**
+ * Testcases for 'InterfaceTest' cycle based statemachine.
+ * 
+ * @author muehlbrandt
+ * 
+ */
+public class TestParallelRegionsEventBasedStatemachine {
+
+	private Test_ParallelRegionsEventBasedStatemachine statemachine;
+	
+	private RuntimeService runtimeService;
+
+	// Minimal cycletime
+	private final long cyclePeriod = 1;
+
+	@Before
+	public void setUp() {
+		statemachine = new Test_ParallelRegionsEventBasedStatemachine();
+		statemachine.enter();
+		runtimeService = new RuntimeService(cyclePeriod);
+		runtimeService.addStatemachine(statemachine);
+	}
+
+	@After
+	public void tearDown() {
+		statemachine = null;
+	}
+
+	@Test
+	public void testStatemachineEnter() {
+		assertTrue("Statemachine isn't in State: " + State.State1.name() + ".",
+				statemachine.isStateActive(State.State1));
+	}
+
+	@Test
+	public void testStatemachineHierarchyLevelOne() throws InterruptedException {
+		statemachine.getDefaultInterface().raiseEvent1();
+		Thread.sleep(5);
+		// Test if state is changed to State3 && State7
+		assertTrue("Statemachine isn't in State: " + State.State3.name() + ".",
+				statemachine.isStateActive(State.State3));
+		assertTrue("Statemachine isn't in State: " + State.State7.name() + ".",
+				statemachine.isStateActive(State.State7));
+
+		statemachine.getDefaultInterface().raiseEvent5();
+		Thread.sleep(5);
+		// Test if state is changed to State3 && State8
+		assertTrue("Statemachine isn't in State: " + State.State3.name() + ".",
+				statemachine.isStateActive(State.State3));
+		assertTrue("Statemachine isn't in State: " + State.State8.name() + ".",
+				statemachine.isStateActive(State.State8));
+		assertFalse(
+				"Statemachine isn't in State: " + State.State7.name() + ".",
+				statemachine.isStateActive(State.State7));
+
+		statemachine.getDefaultInterface().raiseEvent6();
+		Thread.sleep(5);
+		// Test if state is changed to State3 && State7
+		assertTrue("Statemachine isn't in State: " + State.State3.name() + ".",
+				statemachine.isStateActive(State.State3));
+		assertTrue("Statemachine isn't in State: " + State.State7.name() + ".",
+				statemachine.isStateActive(State.State7));
+		assertFalse(
+				"Statemachine isn't in State: " + State.State8.name() + ".",
+				statemachine.isStateActive(State.State8));
+
+		statemachine.getDefaultInterface().raiseEvent3();
+		Thread.sleep(5);
+		// Test if state is back to State1
+		assertTrue(statemachine.isStateActive(State.State1));
+		assertFalse(statemachine.isStateActive(State.State3));
+		assertFalse(statemachine.isStateActive(State.State7));
+		assertFalse(statemachine.isStateActive(State.State8));
+	}
+
+	@Test
+	public void testStatemachineHierarchyLevelTwo() throws InterruptedException {
+		statemachine.getDefaultInterface().raiseEvent1();
+		Thread.sleep(5);
+		// Test if state is changed to State3 && State7
+		assertTrue("Statemachine isn't in State: " + State.State3.name() + ".",
+				statemachine.isStateActive(State.State3));
+		assertTrue("Statemachine isn't in State: " + State.State7.name() + ".",
+				statemachine.isStateActive(State.State7));
+
+		statemachine.getDefaultInterface().raiseEvent2();
+		Thread.sleep(5);
+		// Test if state is changed to State9, State5 and State7
+		assertTrue("Statemachine isn't in State: " + State.State9.name() + ".",
+				statemachine.isStateActive(State.State9));
+		assertTrue("Statemachine isn't in State: " + State.State5.name() + ".",
+				statemachine.isStateActive(State.State5));
+		assertTrue("Statemachine isn't in State: " + State.State7.name() + ".",
+				statemachine.isStateActive(State.State7));
+		assertFalse(
+				"Statemachine isn't in State: " + State.State8.name() + ".",
+				statemachine.isStateActive(State.State8));
+
+		statemachine.getDefaultInterface().raiseEvent3();
+		Thread.sleep(5);
+		// Test if state is changed to State9, State6 and State8
+		assertTrue("Statemachine isn't in State: " + State.State9.name() + ".",
+				statemachine.isStateActive(State.State9));
+		assertTrue("Statemachine isn't in State: " + State.State6.name() + ".",
+				statemachine.isStateActive(State.State6));
+		assertFalse(
+				"Statemachine isn't in State: " + State.State7.name() + ".",
+				statemachine.isStateActive(State.State7));
+		assertTrue("Statemachine isn't in State: " + State.State8.name() + ".",
+				statemachine.isStateActive(State.State8));
+
+		statemachine.getDefaultInterface().raiseEvent6();
+		Thread.sleep(5);
+		// Test if state is changed to State9, State6 and State8
+		assertTrue("Statemachine isn't in State: " + State.State9.name() + ".",
+				statemachine.isStateActive(State.State9));
+		assertTrue("Statemachine isn't in State: " + State.State6.name() + ".",
+				statemachine.isStateActive(State.State6));
+		assertTrue("Statemachine isn't in State: " + State.State7.name() + ".",
+				statemachine.isStateActive(State.State7));
+		assertFalse(
+				"Statemachine isn't in State: " + State.State8.name() + ".",
+				statemachine.isStateActive(State.State8));
+	}
+
+}