Browse Source

Added generated java tests

Andreas Mülder 13 years ago
parent
commit
59be2dadda

+ 16 - 0
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/raiseevent/IRaiseEventStatemachine.java

@@ -0,0 +1,16 @@
+package org.yakindu.scr.raiseevent;
+
+import org.yakindu.scr.IStatemachine;
+
+public interface IRaiseEventStatemachine extends IStatemachine {
+
+	public interface SCIDefault {
+		public boolean isRaisedE1();
+
+		public void raiseE2();
+
+	}
+
+	public SCIDefault getSCIDefault();
+
+}

+ 216 - 0
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/raiseevent/RaiseEventStatemachine.java

@@ -0,0 +1,216 @@
+package org.yakindu.scr.raiseevent;
+
+public class RaiseEventStatemachine implements IRaiseEventStatemachine {
+
+	private final class SCIDefaultImpl implements SCIDefault {
+
+		private boolean e1;
+
+		public boolean isRaisedE1() {
+			return e1;
+		}
+
+		private void raiseE1() {
+			e1 = true;
+		}
+
+		private boolean e2;
+
+		public void raiseE2() {
+			e2 = true;
+		}
+
+		public void clearEvents() {
+			e2 = false;
+		}
+
+		public void clearOutEvents() {
+			e1 = false;
+		}
+
+	}
+
+	private SCIDefaultImpl sCIDefault;
+
+	public enum State {
+		Main_region_StateA, Main_region_StateB, Second_region_SateA, Second_region_StateB, $NullState$
+	};
+
+	private final State[] stateVector = new State[2];
+
+	private int nextStateIndex;
+
+	public RaiseEventStatemachine() {
+
+		sCIDefault = new SCIDefaultImpl();
+
+	}
+
+	public void init() {
+		for (int i = 0; i < 2; i++) {
+			stateVector[i] = State.$NullState$;
+		}
+
+		clearEvents();
+		clearOutEvents();
+	}
+
+	protected void clearEvents() {
+		sCIDefault.clearEvents();
+
+	}
+
+	protected void clearOutEvents() {
+		sCIDefault.clearOutEvents();
+	}
+
+	public boolean isStateActive(State state) {
+		switch (state) {
+
+			case Main_region_StateA :
+				return stateVector[0] == State.Main_region_StateA;
+
+			case Main_region_StateB :
+				return stateVector[0] == State.Main_region_StateB;
+
+			case Second_region_SateA :
+				return stateVector[1] == State.Second_region_SateA;
+
+			case Second_region_StateB :
+				return stateVector[1] == State.Second_region_StateB;
+
+			default :
+				return false;
+		}
+		/*
+		for (int i=0;i<stateVector.length;i++){
+			if (stateVector[i]==state) {
+				return true;
+			}
+		}
+		return false;
+		 */
+	}
+
+	public SCIDefault getSCIDefault() {
+		return sCIDefault;
+	}
+
+	public boolean isRaisedE1() {
+		return sCIDefault.isRaisedE1();
+	}
+
+	public void raiseE2() {
+		sCIDefault.raiseE2();
+	}
+
+	public void enter() {
+		entryActionRaiseEvent();
+		nextStateIndex = 0;
+		stateVector[0] = State.Main_region_StateA;
+
+		nextStateIndex = 1;
+		stateVector[1] = State.Second_region_SateA;
+
+	}
+
+	public void exit() {
+		//Handle exit of all possible states (of main region) at position 0...
+		switch (stateVector[0]) {
+
+			case Main_region_StateA :
+				stateVector[0] = State.$NullState$;
+
+				break;
+
+			case Main_region_StateB :
+				stateVector[0] = State.$NullState$;
+
+				break;
+
+			default :
+				break;
+		}
+
+		//Handle exit of all possible states (of second region) at position 1...
+		switch (stateVector[1]) {
+
+			case Second_region_SateA :
+				stateVector[1] = State.$NullState$;
+
+				break;
+
+			case Second_region_StateB :
+				stateVector[1] = State.$NullState$;
+
+				break;
+
+			default :
+				break;
+		}
+
+		exitActionRaiseEvent();
+	}
+
+	private void entryActionRaiseEvent() {
+
+	}
+
+	private void exitActionRaiseEvent() {
+
+	}
+
+	private void reactMain_region_StateA() {
+		if (sCIDefault.e2) {
+			stateVector[0] = State.$NullState$;
+
+			sCIDefault.raiseE1();
+
+			nextStateIndex = 0;
+			stateVector[0] = State.Main_region_StateB;
+
+		}
+
+	}
+	private void reactMain_region_StateB() {
+
+	}
+	private void reactSecond_region_SateA() {
+		if (sCIDefault.e1) {
+			stateVector[1] = State.$NullState$;
+
+			nextStateIndex = 1;
+			stateVector[1] = State.Second_region_StateB;
+
+		}
+	}
+	private void reactSecond_region_StateB() {
+	}
+
+	public void runCycle() {
+
+		clearOutEvents();
+
+		for (nextStateIndex = 0; nextStateIndex < stateVector.length; nextStateIndex++) {
+
+			switch (stateVector[nextStateIndex]) {
+				case Main_region_StateA :
+					reactMain_region_StateA();
+					break;
+				case Main_region_StateB :
+					reactMain_region_StateB();
+					break;
+				case Second_region_SateA :
+					reactSecond_region_SateA();
+					break;
+				case Second_region_StateB :
+					reactSecond_region_StateB();
+					break;
+				default :
+					// $NullState$
+			}
+		}
+
+		clearEvents();
+	}
+}

+ 15 - 0
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/samenamedifferentregion/ISameNameDifferentRegionStatemachine.java

@@ -0,0 +1,15 @@
+package org.yakindu.scr.samenamedifferentregion;
+
+import org.yakindu.scr.IStatemachine;
+
+public interface ISameNameDifferentRegionStatemachine extends IStatemachine {
+
+	public interface SCIDefault {
+
+		public void raiseE1();
+
+	}
+
+	public SCIDefault getSCIDefault();
+
+}

+ 186 - 0
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/samenamedifferentregion/SameNameDifferentRegionStatemachine.java

@@ -0,0 +1,186 @@
+package org.yakindu.scr.samenamedifferentregion;
+
+public class SameNameDifferentRegionStatemachine
+		implements
+			ISameNameDifferentRegionStatemachine {
+
+	private final class SCIDefaultImpl implements SCIDefault {
+
+		private boolean e1;
+
+		public void raiseE1() {
+			e1 = true;
+		}
+
+		public void clearEvents() {
+			e1 = false;
+		}
+
+	}
+
+	private SCIDefaultImpl sCIDefault;
+
+	public enum State {
+		Main_region_StateA, Main_region_StateB, Main_region_StateB_r1_StateA, Main_region_StateB_r1_StateB, $NullState$
+	};
+
+	private final State[] stateVector = new State[1];
+
+	private int nextStateIndex;
+
+	public SameNameDifferentRegionStatemachine() {
+
+		sCIDefault = new SCIDefaultImpl();
+
+	}
+
+	public void init() {
+		for (int i = 0; i < 1; i++) {
+			stateVector[i] = State.$NullState$;
+		}
+
+		clearEvents();
+		clearOutEvents();
+	}
+
+	protected void clearEvents() {
+		sCIDefault.clearEvents();
+
+	}
+
+	protected void clearOutEvents() {
+	}
+
+	public boolean isStateActive(State state) {
+		switch (state) {
+
+			case Main_region_StateA :
+				return stateVector[0] == State.Main_region_StateA;
+
+			case Main_region_StateB :
+				return stateVector[0].ordinal() >= State.Main_region_StateB
+						.ordinal()
+						&& stateVector[0].ordinal() <= State.Main_region_StateB_r1_StateB
+								.ordinal();
+
+			case Main_region_StateB_r1_StateA :
+				return stateVector[0] == State.Main_region_StateB_r1_StateA;
+
+			case Main_region_StateB_r1_StateB :
+				return stateVector[0] == State.Main_region_StateB_r1_StateB;
+
+			default :
+				return false;
+		}
+		/*
+		for (int i=0;i<stateVector.length;i++){
+			if (stateVector[i]==state) {
+				return true;
+			}
+		}
+		return false;
+		 */
+	}
+
+	public SCIDefault getSCIDefault() {
+		return sCIDefault;
+	}
+
+	public void raiseE1() {
+		sCIDefault.raiseE1();
+	}
+
+	public void enter() {
+		entryActionSameNameDifferentRegion();
+		nextStateIndex = 0;
+		stateVector[0] = State.Main_region_StateA;
+
+	}
+
+	public void exit() {
+		//Handle exit of all possible states (of main region) at position 0...
+		switch (stateVector[0]) {
+
+			case Main_region_StateA :
+				stateVector[0] = State.$NullState$;
+
+				break;
+
+			case Main_region_StateB_r1_StateA :
+				stateVector[0] = State.$NullState$;
+
+				break;
+
+			case Main_region_StateB_r1_StateB :
+				stateVector[0] = State.$NullState$;
+
+				break;
+
+			default :
+				break;
+		}
+
+		exitActionSameNameDifferentRegion();
+	}
+
+	private void entryActionSameNameDifferentRegion() {
+
+	}
+
+	private void exitActionSameNameDifferentRegion() {
+
+	}
+
+	private void reactMain_region_StateA() {
+		if (sCIDefault.e1) {
+			stateVector[0] = State.$NullState$;
+
+			nextStateIndex = 0;
+			stateVector[0] = State.Main_region_StateB_r1_StateA;
+
+		}
+
+	}
+	private void reactMain_region_StateB() {
+	}
+	private void reactMain_region_StateB_r1_StateA() {
+		if (sCIDefault.e1) {
+			stateVector[0] = State.$NullState$;
+
+			nextStateIndex = 0;
+			stateVector[0] = State.Main_region_StateB_r1_StateB;
+
+		}
+
+	}
+	private void reactMain_region_StateB_r1_StateB() {
+
+	}
+
+	public void runCycle() {
+
+		clearOutEvents();
+
+		for (nextStateIndex = 0; nextStateIndex < stateVector.length; nextStateIndex++) {
+
+			switch (stateVector[nextStateIndex]) {
+				case Main_region_StateA :
+					reactMain_region_StateA();
+					break;
+				case Main_region_StateB :
+					reactMain_region_StateB();
+					break;
+				case Main_region_StateB_r1_StateA :
+					reactMain_region_StateB_r1_StateA();
+					break;
+				case Main_region_StateB_r1_StateB :
+					reactMain_region_StateB_r1_StateB();
+					break;
+				default :
+					// $NullState$
+			}
+		}
+
+		clearEvents();
+	}
+}

+ 88 - 16
test-plugins/org.yakindu.sct.generator.java.test/src/org/yakindu/sct/generator/java/JavaSCTGeneratorTest.java

@@ -11,16 +11,25 @@
 package org.yakindu.sct.generator.java;
 package org.yakindu.sct.generator.java;
 
 
 import static util.TestModels.ALWAYS_ONCYCLE;
 import static util.TestModels.ALWAYS_ONCYCLE;
+import static util.TestModels.BIT_EXPRESSIONS;
+import static util.TestModels.BOOLEAN_EXPRESSIONS;
 import static util.TestModels.CHOICE;
 import static util.TestModels.CHOICE;
+import static util.TestModels.C_KEYWORDS_M;
 import static util.TestModels.DEEP_HISTORY;
 import static util.TestModels.DEEP_HISTORY;
 import static util.TestModels.FEATURE_CALLS;
 import static util.TestModels.FEATURE_CALLS;
 import static util.TestModels.GUARD;
 import static util.TestModels.GUARD;
+import static util.TestModels.INTEGER_EXPRESSIONS;
+import static util.TestModels.JAVA_KEYWORDS_M;
 import static util.TestModels.PRIORITY_VALUES;
 import static util.TestModels.PRIORITY_VALUES;
+import static util.TestModels.RAISE_EVENTS;
+import static util.TestModels.REAL_EXPRESSIONS;
+import static util.TestModels.SAME_NAME_DIFFERENT_REGION;
 import static util.TestModels.SHALLOW_HISTORY;
 import static util.TestModels.SHALLOW_HISTORY;
 import static util.TestModels.SIMPLE_EVENT;
 import static util.TestModels.SIMPLE_EVENT;
 import static util.TestModels.SIMPLE_HIERACHY;
 import static util.TestModels.SIMPLE_HIERACHY;
 import static util.TestModels.STATECHART_LOCAL_REACTIONS;
 import static util.TestModels.STATECHART_LOCAL_REACTIONS;
 import static util.TestModels.STATE_ACTIVE;
 import static util.TestModels.STATE_ACTIVE;
+import static util.TestModels.STRING_EXPRESSIONS;
 import static util.TestModels.SYNC_FORK;
 import static util.TestModels.SYNC_FORK;
 import static util.TestModels.SYNC_JOIN;
 import static util.TestModels.SYNC_JOIN;
 import static util.TestModels.VALUED_EVENTS;
 import static util.TestModels.VALUED_EVENTS;
@@ -54,6 +63,39 @@ public class JavaSCTGeneratorTest extends AbstractJavaGeneratorTest {
 	@Inject
 	@Inject
 	private TestModels models;
 	private TestModels models;
 
 
+	private void failOnError(IMarker[] diagnostics) throws CoreException {
+		for (IMarker diagnostic : diagnostics) {
+			int severity = (Integer) diagnostic.getAttribute("severity");
+			if (severity == IMarker.SEVERITY_ERROR) {
+				Assert.fail(diagnostic.getAttribute(IMarker.MESSAGE, ""));
+			}
+		}
+	}
+
+	@Test
+	public void testAlwaysOnCycleModel() throws Exception {
+		Statechart statechart = models
+				.loadStatechartFromResource(ALWAYS_ONCYCLE);
+		failOnError(generateAndCompile(statechart));
+
+	}
+
+	@Test 
+	public void testBitExpressionsModel() throws Exception {
+		Statechart statechart = models
+				.loadStatechartFromResource(BIT_EXPRESSIONS);  
+		failOnError(generateAndCompile(statechart));
+		
+	}
+	
+	@Test 
+	public void testBooleanExpressionsModel() throws Exception {
+		Statechart statechart = models
+				.loadStatechartFromResource(BOOLEAN_EXPRESSIONS);  
+		failOnError(generateAndCompile(statechart));
+		
+	}
+	
 	@Test
 	@Test
 	public void testChoiceModel() throws Exception {
 	public void testChoiceModel() throws Exception {
 		Statechart statechart = models.loadStatechartFromResource(CHOICE);
 		Statechart statechart = models.loadStatechartFromResource(CHOICE);
@@ -62,11 +104,10 @@ public class JavaSCTGeneratorTest extends AbstractJavaGeneratorTest {
 	}
 	}
 
 
 	@Test
 	@Test
-	public void testAlwaysOnCycleModel() throws Exception {
-		Statechart statechart = models
-				.loadStatechartFromResource(ALWAYS_ONCYCLE);
+	public void testCKeywordsModel() throws Exception {
+		Statechart statechart = models.loadStatechartFromResource(C_KEYWORDS_M);
 		failOnError(generateAndCompile(statechart));
 		failOnError(generateAndCompile(statechart));
-
+		
 	}
 	}
 
 
 	@Test
 	@Test
@@ -90,6 +131,18 @@ public class JavaSCTGeneratorTest extends AbstractJavaGeneratorTest {
 		failOnError(generateAndCompile(statechart));
 		failOnError(generateAndCompile(statechart));
 	}
 	}
 
 
+	@Test
+	public void testIntegerExpressionsModel() throws Exception {
+		Statechart statechart = models.loadStatechartFromResource(INTEGER_EXPRESSIONS);
+		failOnError(generateAndCompile(statechart));
+	}
+
+	@Test
+	public void testJavaKeywordsModel() throws Exception {
+		Statechart statechart = models.loadStatechartFromResource(JAVA_KEYWORDS_M);
+		failOnError(generateAndCompile(statechart));
+	}
+
 	@Test
 	@Test
 	public void testPriorityValuesModel() throws Exception {
 	public void testPriorityValuesModel() throws Exception {
 		Statechart statechart = models
 		Statechart statechart = models
@@ -97,6 +150,27 @@ public class JavaSCTGeneratorTest extends AbstractJavaGeneratorTest {
 		failOnError(generateAndCompile(statechart));
 		failOnError(generateAndCompile(statechart));
 	}
 	}
 
 
+	@Test
+	public void testRaiseEventModel() throws Exception {
+		Statechart statechart = models
+				.loadStatechartFromResource(RAISE_EVENTS);
+		failOnError(generateAndCompile(statechart));
+	}
+
+	@Test
+	public void testRealExpressionsModel() throws Exception {
+		Statechart statechart = models
+				.loadStatechartFromResource(REAL_EXPRESSIONS);
+		failOnError(generateAndCompile(statechart));
+	}
+
+	@Test
+	public void testSameNameDifferentRegionModel() throws Exception {
+		Statechart statechart = models
+				.loadStatechartFromResource(SAME_NAME_DIFFERENT_REGION);
+		failOnError(generateAndCompile(statechart));
+	}
+
 	@Test
 	@Test
 	public void testShallowHistoryModel() throws Exception {
 	public void testShallowHistoryModel() throws Exception {
 		Statechart statechart = models
 		Statechart statechart = models
@@ -110,6 +184,7 @@ public class JavaSCTGeneratorTest extends AbstractJavaGeneratorTest {
 		failOnError(generateAndCompile(statechart));
 		failOnError(generateAndCompile(statechart));
 	}
 	}
 
 
+
 	@Test
 	@Test
 	public void testSimpleHierachyModel() throws Exception {
 	public void testSimpleHierachyModel() throws Exception {
 		Statechart statechart = models
 		Statechart statechart = models
@@ -119,18 +194,24 @@ public class JavaSCTGeneratorTest extends AbstractJavaGeneratorTest {
 
 
 	@Test
 	@Test
 	public void testStatechartLocalReactionsModel() throws Exception {
 	public void testStatechartLocalReactionsModel() throws Exception {
-		Statechart statechart = models
-				.loadStatechartFromResource(STATECHART_LOCAL_REACTIONS);
+		Statechart statechart = models.loadStatechartFromResource(STATECHART_LOCAL_REACTIONS);
 		failOnError(generateAndCompile(statechart));
 		failOnError(generateAndCompile(statechart));
-
 	}
 	}
 
 
+
 	@Test
 	@Test
 	public void testStateActiveModel() throws Exception {
 	public void testStateActiveModel() throws Exception {
 		Statechart statechart = models.loadStatechartFromResource(STATE_ACTIVE);
 		Statechart statechart = models.loadStatechartFromResource(STATE_ACTIVE);
 		failOnError(generateAndCompile(statechart));
 		failOnError(generateAndCompile(statechart));
 
 
 	}
 	}
+ 
+	@Test
+	public void testStringExpressionsModel() throws Exception {
+		Statechart statechart = models.loadStatechartFromResource(STRING_EXPRESSIONS);
+		failOnError(generateAndCompile(statechart));
+		
+	}
 
 
 	@Test
 	@Test
 	public void testSyncForkModel() throws Exception {
 	public void testSyncForkModel() throws Exception {
@@ -150,13 +231,4 @@ public class JavaSCTGeneratorTest extends AbstractJavaGeneratorTest {
 				.loadStatechartFromResource(VALUED_EVENTS);
 				.loadStatechartFromResource(VALUED_EVENTS);
 		failOnError(generateAndCompile(statechart));
 		failOnError(generateAndCompile(statechart));
 	}
 	}
-
-	private void failOnError(IMarker[] diagnostics) throws CoreException {
-		for (IMarker diagnostic : diagnostics) {
-			int severity = (Integer) diagnostic.getAttribute("severity");
-			if (severity == IMarker.SEVERITY_ERROR) {
-				Assert.fail(diagnostic.getAttribute(IMarker.MESSAGE, ""));
-			}
-		}
-	}
 }
 }