Browse Source

Updated generated code. Adapt JUnit tests to newly generated code. Added test for "Test_LocalActions" statemachine with soft-realtime timing test.

markus.muehlbrandt@itemis.de 13 years ago
parent
commit
44663b1056

+ 7 - 1
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_localactions/InterfaceDefault.java

@@ -10,13 +10,19 @@
  */
 package org.yakindu.sct.runtime.java.test_localactions;
 
+import org.yakindu.sct.runtime.java.Event;
+import org.yakindu.sct.runtime.java.INotificationSender;
 
-public interface InterfaceDefault {
+public interface InterfaceDefault extends INotificationSender {
 	
 	public void raiseEvent1();
 	public void raiseEvent2();
 	public void raiseEvent3();
 	public void raiseEvent4();
+	public boolean isRaisedEvent5();
+		
+	public Event<Void> getEventEvent5();
+	
 	
 	public int getVarI();
 	public void setVarI(int value);	

+ 17 - 1
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_localactions/InterfaceDefaultImpl.java

@@ -12,13 +12,15 @@ package org.yakindu.sct.runtime.java.test_localactions;
 
 import org.yakindu.sct.runtime.java.EventNotification;
 import org.yakindu.sct.runtime.java.Event;
+import org.yakindu.sct.runtime.java.NotificationSender;
 
-public class InterfaceDefaultImpl implements InterfaceDefault {
+public class InterfaceDefaultImpl extends NotificationSender implements InterfaceDefault {
 	
 	private final Event<Void> EventEvent1 = new Event<Void>("Event1", null); 
 	private final Event<Void> EventEvent2 = new Event<Void>("Event2", null); 
 	private final Event<Void> EventEvent3 = new Event<Void>("Event3", null); 
 	private final Event<Void> EventEvent4 = new Event<Void>("Event4", null); 
+	private final Event<Void> EventEvent5 = new Event<Void>("Event5", null); 
 	
 	private Test_LocalActionsAbstractBaseStatemachine statemachine; 
 	
@@ -62,6 +64,20 @@ public class InterfaceDefaultImpl implements InterfaceDefault {
 		return EventEvent4;
 	}
 	
+	public void raiseEvent5() {
+		statemachine.getOccuredEvents().add(EventEvent5);
+		statemachine.getOutEvents().add(EventEvent5);
+		notifyListeners(new EventNotification(EventEvent5));
+	}
+	
+	
+	public Event<Void> getEventEvent5() {
+		return EventEvent5;
+	}
+	
+	public boolean isRaisedEvent5() {
+		return statemachine.getOutEvents().contains(EventEvent5);
+	}
 	
 	private int varI;
 	

+ 1 - 0
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_localactions/Test_LocalActionsAbstractBaseStatemachine.java

@@ -138,6 +138,7 @@ entryActionsState2();
 	}
 	private void actionsState1Lr4() {
 	interfaceDefault.setVarC(interfaceDefault.getVarC() + (1));
+	interfaceDefault.raiseEvent5();
 
 	}
 	private void actionsState2Tr0() {

+ 10 - 0
test-plugins/org.yakindu.sct.generator.java.runtime.test/src/org/yakindu/sct/generator/java/runtime/test/AllCycleBasedStatemachineTests.java

@@ -1,3 +1,13 @@
+/**
+ * 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;

+ 17 - 1
test-plugins/org.yakindu.sct.generator.java.runtime.test/src/org/yakindu/sct/generator/java/runtime/test/TestInterfaceTestCycleBasedStatemachine.java

@@ -1,3 +1,13 @@
+/**
+ * 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.assertEquals;
@@ -10,6 +20,12 @@ import org.junit.Test;
 import org.yakindu.sct.runtime.java.interfacetest.InterfaceTestAbstractBaseStatemachine.State;
 import org.yakindu.sct.runtime.java.interfacetest.InterfaceTestCyleBasedStatemachine;
 
+/**
+ * Testcases for 'InterfaceTest' cycle based statemachine.
+ * 
+ * @author muehlbrandt
+ *
+ */
 public class TestInterfaceTestCycleBasedStatemachine {
 
 	private InterfaceTestCyleBasedStatemachine statemachine;
@@ -26,7 +42,7 @@ public class TestInterfaceTestCycleBasedStatemachine {
 	}
 
 	@Test
-	public void testStatemachineInitialisation() {
+	public void testStatemachineEntry() {
 		setUp();
 		assertEquals("InterfaceDefault.Var2 is not correct initialized:", 2.3,
 				statemachine.getInterfaceDefault().getVarVar2(),

+ 87 - 0
test-plugins/org.yakindu.sct.generator.java.runtime.test/src/org/yakindu/sct/generator/java/runtime/test/TestLocalActionsCycleBasedStatemachine.java

@@ -0,0 +1,87 @@
+/**
+ * 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.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.yakindu.sct.runtime.java.test_localactions.Test_LocalActionsAbstractBaseStatemachine.State;
+import org.yakindu.sct.runtime.java.test_localactions.Test_LocalActionsCyleBasedStatemachine;
+
+/**
+ * Testcases for 'Test_LocalActions' cycle based statemachine.
+ * 
+ * @author muehlbrandt
+ * 
+ */
+public class TestLocalActionsCycleBasedStatemachine {
+
+	private Test_LocalActionsCyleBasedStatemachine statemachine;
+
+	// Define the error threshold in ms. 10 ms are required to satisfy soft-realtime requirements.
+	private final long timerThreshold = 10;
+
+	@Before
+	public void setUp() {
+		statemachine = new Test_LocalActionsCyleBasedStatemachine();
+		statemachine.entry();
+	}
+
+	@After
+	public void tearDown() {
+		statemachine = null;
+	}
+
+	@Test
+	public void testStatemachineEntry() {
+		setUp();
+		assertTrue("Statemachine isn't in State: " + State.State1.name() + ".",
+				statemachine.getActiveStates().contains(State.State1));
+		assertEquals("More than one state is active.", 1, statemachine
+				.getActiveStates().size());
+		assertEquals("Variable i not set to 1", 1, statemachine
+				.getInterfaceDefault().getVarI());
+		tearDown();
+	}
+
+	@Test
+	public void testState1LocalReaction() throws InterruptedException {
+		setUp();
+		final long time = System.currentTimeMillis();
+		statemachine.runCycle();
+		// assertEquals("Error in local reaction \"onCycle / i=2;\" of State1",
+		// 2,
+		// statemachine.getInterfaceDefault().getVarI());
+
+		statemachine.getInterfaceDefault().raiseEvent2();
+		statemachine.runCycle();
+		assertEquals("Error in local reaction \"Event2 / i=3;\" of State1", 3,
+				statemachine.getInterfaceDefault().getVarI());
+
+		// Check timer behavior
+		while (statemachine.getInterfaceDefault().getVarC() < 10) {
+			statemachine.runCycle();
+			Thread.sleep(2);
+		}
+		final long time2 = System.currentTimeMillis() - time;
+		final long delta = time2 - statemachine.getInterfaceDefault().getVarC()
+				* 100;
+		assertTrue("Timer threshold overflow. Delta is " + delta
+				+ "ms. Threshold is: " + timerThreshold + "ms.",
+				time2 <= statemachine.getInterfaceDefault().getVarC() * 100
+						+ timerThreshold);
+
+		tearDown();
+	}
+}