Browse Source

changed Name of TimeTrigger Tests, added DeepEntry and EntryChoice Test, updated AllTests

malknet42 11 years ago
parent
commit
64792b8fab

+ 10 - 0
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/timedtransitions/ITimedTransitionsStatemachine.java

@@ -0,0 +1,10 @@
+package org.yakindu.scr.timedtransitions;
+import org.yakindu.scr.IStatemachine;
+import org.yakindu.scr.ITimerCallback;
+
+public interface ITimedTransitionsStatemachine
+		extends
+			ITimerCallback,
+			IStatemachine {
+
+}

+ 160 - 0
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/timedtransitions/TimedTransitionsStatemachine.java

@@ -0,0 +1,160 @@
+package org.yakindu.scr.timedtransitions;
+import org.yakindu.scr.ITimer;
+
+public class TimedTransitionsStatemachine
+		implements
+			ITimedTransitionsStatemachine {
+
+	private final boolean[] timeEvents = new boolean[1];
+
+	public enum State {
+		main_region_Start, main_region_End, $NullState$
+	};
+
+	private final State[] stateVector = new State[1];
+
+	private int nextStateIndex;
+
+	private ITimer timer;
+
+	public TimedTransitionsStatemachine() {
+
+	}
+
+	public void init() {
+		if (timer == null) {
+			throw new IllegalStateException("timer not set.");
+		}
+		for (int i = 0; i < 1; i++) {
+			stateVector[i] = State.$NullState$;
+		}
+
+		clearEvents();
+		clearOutEvents();
+
+	}
+
+	public void enter() {
+		if (timer == null) {
+			throw new IllegalStateException("timer not set.");
+		}
+		entryAction();
+
+		timer.setTimer(this, 0, 2 * 1000, false);
+
+		nextStateIndex = 0;
+		stateVector[0] = State.main_region_Start;
+	}
+
+	public void exit() {
+		switch (stateVector[0]) {
+			case main_region_Start :
+				nextStateIndex = 0;
+				stateVector[0] = State.$NullState$;
+
+				timer.unsetTimer(this, 0);
+				break;
+
+			case main_region_End :
+				nextStateIndex = 0;
+				stateVector[0] = State.$NullState$;
+				break;
+
+			default :
+				break;
+		}
+
+		exitAction();
+	}
+
+	protected void clearEvents() {
+
+		for (int i = 0; i < timeEvents.length; i++) {
+			timeEvents[i] = false;
+		}
+	}
+
+	protected void clearOutEvents() {
+	}
+
+	public boolean isStateActive(State state) {
+		switch (state) {
+			case main_region_Start :
+				return stateVector[0] == State.main_region_Start;
+			case main_region_End :
+				return stateVector[0] == State.main_region_End;
+			default :
+				return false;
+		}
+	}
+
+	/**
+	 * Set the {@link ITimer} for the state machine. It must be set
+	 * externally on a timed state machine before a run cycle can be correct
+	 * executed.
+	 * 
+	 * @param timer
+	 */
+	public void setTimer(ITimer timer) {
+		this.timer = timer;
+	}
+
+	/**
+	 * Returns the currently used timer.
+	 * 
+	 * @return {@link ITimer}
+	 */
+	public ITimer getTimer() {
+		return timer;
+	}
+
+	public void timeElapsed(int eventID) {
+		timeEvents[eventID] = true;
+	}
+
+	/* Entry action for statechart 'TimedTransitions'. */
+	private void entryAction() {
+	}
+
+	/* Exit action for state 'TimedTransitions'. */
+	private void exitAction() {
+	}
+
+	/* The reactions of state Start. */
+	private void reactMain_region_Start() {
+		if (timeEvents[0]) {
+			nextStateIndex = 0;
+			stateVector[0] = State.$NullState$;
+
+			timer.unsetTimer(this, 0);
+
+			nextStateIndex = 0;
+			stateVector[0] = State.main_region_End;
+		}
+	}
+
+	/* The reactions of state End. */
+	private void reactMain_region_End() {
+	}
+
+	public void runCycle() {
+
+		clearOutEvents();
+
+		for (nextStateIndex = 0; nextStateIndex < stateVector.length; nextStateIndex++) {
+
+			switch (stateVector[nextStateIndex]) {
+				case main_region_Start :
+					reactMain_region_Start();
+					break;
+				case main_region_End :
+					reactMain_region_End();
+					break;
+				default :
+					// $NullState$
+			}
+		}
+
+		clearEvents();
+	}
+}

+ 9 - 8
test-plugins/org.yakindu.sct.generator.java.test/test-gen/org/yakindu/sct/generator/java/test/AllTestsTest.java

@@ -18,18 +18,19 @@ import org.junit.runners.Suite.SuiteClasses;
 		BitExpressionsTest.class, BooleanExpressionsTest.class,
 		ChoiceTest.class, CKeywordsTest.class, DeclarationsTest.class,
 		DeepEntryTest.class, DeepHistoryTest.class, EnterStateTest.class,
-		ExitOnSelfTransitionTest.class, ExitStateTest.class, GuardTest.class,
-		GuardedEntryTest.class, GuardedExitTest.class,
-		HistoryWithoutInitialStepTest.class, InEventLifeCycleTest.class,
-		IntegerExpressionsTest.class, InternalEventLifeCycleTest.class,
-		LogicalAndTestsTest.class, LogicalOrTestsTest.class,
-		NamedInterfaceAccessTest.class, OutEventLifeCycleTest.class,
-		ParenthesisTest.class, PriorityValuesTest.class, RaiseEventTest.class,
+		EntryChoiceTest.class, ExitOnSelfTransitionTest.class,
+		ExitStateTest.class, GuardTest.class, GuardedEntryTest.class,
+		GuardedExitTest.class, HistoryWithoutInitialStepTest.class,
+		InEventLifeCycleTest.class, IntegerExpressionsTest.class,
+		InternalEventLifeCycleTest.class, LogicalAndTestsTest.class,
+		LogicalOrTestsTest.class, NamedInterfaceAccessTest.class,
+		OutEventLifeCycleTest.class, ParenthesisTest.class,
+		PriorityValuesTest.class, RaiseEventTest.class,
 		SameNameDifferentRegionTest.class, ShallowHistoryTest.class,
 		SimpleEventTest.class, StatechartLocalReactionsTest.class,
 		SimpleHierachyTest.class, StateIsActiveTest.class,
 		STextKeywordsInStatesAndRegionsTest.class, StringExpressionsTest.class,
-		SyncForkTest.class, SyncJoinTest.class,
+		SyncForkTest.class, SyncJoinTest.class, TimedTransitionsTest.class,
 		TransitionWithoutConditionTest.class, ValuedEventsTest.class,
 		EntryChoiceTest.class})
 public class AllTestsTest {

+ 46 - 46
test-plugins/org.yakindu.sct.generator.java.test/test-gen/org/yakindu/sct/generator/java/test/EntryChoiceTest.java

@@ -1,46 +1,46 @@
-/**
- * Copyright (c) 2013 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:
- *     committers of YAKINDU - initial API and implementation
- */
-
-package org.yakindu.sct.generator.java.test;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import static org.junit.Assert.*;
-import org.yakindu.scr.entrychoice.EntryChoiceStatemachine;
-import org.yakindu.scr.entrychoice.EntryChoiceStatemachine.State;
-/**
- *  Unit TestCase for EntryChoice
- */
-@SuppressWarnings("all")
-public class EntryChoiceTest {
-
-	private EntryChoiceStatemachine statemachine;
-
-	@Before
-	public void setUp() {
-		statemachine = new EntryChoiceStatemachine();
-		statemachine.init();
-	}
-
-	@After
-	public void tearDown() {
-		statemachine = null;
-	}
-
-	@Test
-	public void testEntryChoiceTest() {
-		statemachine.enter();
-		statemachine.runCycle();
-		statemachine.runCycle();
-		assertTrue(statemachine.isStateActive(State.main_region_A));
-	}
-}
+/**
+ * Copyright (c) 2013 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:
+ *     committers of YAKINDU - initial API and implementation
+ */
+
+package org.yakindu.sct.generator.java.test;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.yakindu.scr.entrychoice.EntryChoiceStatemachine;
+import org.yakindu.scr.entrychoice.EntryChoiceStatemachine.State;
+/**
+ *  Unit TestCase for EntryChoice
+ */
+@SuppressWarnings("all")
+public class EntryChoiceTest {
+
+	private EntryChoiceStatemachine statemachine;
+
+	@Before
+	public void setUp() {
+		statemachine = new EntryChoiceStatemachine();
+		statemachine.init();
+	}
+
+	@After
+	public void tearDown() {
+		statemachine = null;
+	}
+
+	@Test
+	public void testEntryChoiceTest() {
+		statemachine.enter();
+		statemachine.runCycle();
+		statemachine.runCycle();
+		assertTrue(statemachine.isStateActive(State.main_region_A));
+	}
+}

+ 52 - 0
test-plugins/org.yakindu.sct.generator.java.test/test-gen/org/yakindu/sct/generator/java/test/TimedTransitionsTest.java

@@ -0,0 +1,52 @@
+/**
+ * Copyright (c) 2013 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:
+ *     committers of YAKINDU - initial API and implementation
+ */
+
+package org.yakindu.sct.generator.java.test;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.yakindu.scr.timedtransitions.TimedTransitionsStatemachine;
+import org.yakindu.scr.timedtransitions.TimedTransitionsStatemachine.State;
+import org.yakindu.scr.TimerService;
+/**
+ *  Unit TestCase for TimedTransitions
+ */
+@SuppressWarnings("all")
+public class TimedTransitionsTest {
+
+	private TimedTransitionsStatemachine statemachine;
+
+	@Before
+	public void setUp() {
+		statemachine = new TimedTransitionsStatemachine();
+		statemachine.setTimer(new TimerService());
+		statemachine.init();
+	}
+
+	@After
+	public void tearDown() {
+		statemachine = null;
+	}
+
+	@Test
+	public void testTimer01() {
+		statemachine.enter();
+		assertTrue(statemachine.isStateActive(State.main_region_Start));
+		try {
+			Thread.sleep(2030);
+		} catch (InterruptedException e) {
+		}
+		statemachine.runCycle();
+		assertTrue(statemachine.isStateActive(State.main_region_End));
+	}
+}