Browse Source

Added Operations-test and extended CustomTest

malknet42 11 years ago
parent
commit
deb134fcf4

+ 9 - 1
test-plugins/org.yakindu.sct.generator.java.test/model/test.sgen

@@ -249,7 +249,15 @@ GeneratorModel for sctunit::java {
 			targetFolder = "test-gen"			
 		}			
 	}
-
+	
+	test Operations{
+		
+		feature Outlet{ 
+			targetProject = "org.yakindu.sct.generator.java.test" 
+			targetFolder = "test-gen"			
+		}			
+	}
+	
 	test OutEventLifeCycle{
 		
 		feature Outlet{ 

+ 6 - 1
test-plugins/org.yakindu.sct.generator.java.test/pom.xml

@@ -19,7 +19,12 @@
 				<artifactId>tycho-surefire-plugin</artifactId>
 				<version>${tycho-version}</version>
 				<configuration>
-					 		
+					 						 		
+					<includes>
+						<!--include>**/AllTestsTest.class</include-->
+						<include>**/AllTestsTestCustom.class</include>
+					</includes>
+					 	 		
 					<useUIHarness>false</useUIHarness>
 					<useUIThread>false</useUIThread>
 					<testFailureIgnore>${testFailureIgnore}</testFailureIgnore>

+ 40 - 21
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/operations/OperationsStatemachine.java

@@ -38,7 +38,7 @@ public class OperationsStatemachine implements IOperationsStatemachine {
 	private SCInterfaceImpl sCInterface;
 
 	public enum State {
-		main_region_A, main_region_B, main_region_C, $NullState$
+		main_region_B, main_region_C, main_region_D, main_region_A, $NullState$
 	};
 
 	private boolean myBool;
@@ -69,27 +69,28 @@ public class OperationsStatemachine implements IOperationsStatemachine {
 	public void enter() {
 		entryAction();
 
-		operationCallback.internalOperation1();
-
-		myBool = operationCallback.internalOperation2(4);
-
 		nextStateIndex = 0;
 		stateVector[0] = State.main_region_A;
 	}
 
 	public void exit() {
 		switch (stateVector[0]) {
-			case main_region_A :
+			case main_region_B :
 				nextStateIndex = 0;
 				stateVector[0] = State.$NullState$;
 				break;
 
-			case main_region_B :
+			case main_region_C :
 				nextStateIndex = 0;
 				stateVector[0] = State.$NullState$;
 				break;
 
-			case main_region_C :
+			case main_region_D :
+				nextStateIndex = 0;
+				stateVector[0] = State.$NullState$;
+				break;
+
+			case main_region_A :
 				nextStateIndex = 0;
 				stateVector[0] = State.$NullState$;
 				break;
@@ -120,12 +121,14 @@ public class OperationsStatemachine implements IOperationsStatemachine {
 	 */
 	public boolean isStateActive(State state) {
 		switch (state) {
-			case main_region_A :
-				return stateVector[0] == State.main_region_A;
 			case main_region_B :
 				return stateVector[0] == State.main_region_B;
 			case main_region_C :
 				return stateVector[0] == State.main_region_C;
+			case main_region_D :
+				return stateVector[0] == State.main_region_D;
+			case main_region_A :
+				return stateVector[0] == State.main_region_A;
 			default :
 				return false;
 		}
@@ -155,8 +158,8 @@ public class OperationsStatemachine implements IOperationsStatemachine {
 	private void exitAction() {
 	}
 
-	/* The reactions of state A. */
-	private void reactMain_region_A() {
+	/* The reactions of state B. */
+	private void reactMain_region_B() {
 		if (sCInterface.ev) {
 			nextStateIndex = 0;
 			stateVector[0] = State.$NullState$;
@@ -166,12 +169,12 @@ public class OperationsStatemachine implements IOperationsStatemachine {
 			sCIInterface1.operationCallback.interfaceOperation2(4);
 
 			nextStateIndex = 0;
-			stateVector[0] = State.main_region_B;
+			stateVector[0] = State.main_region_C;
 		}
 	}
 
-	/* The reactions of state B. */
-	private void reactMain_region_B() {
+	/* The reactions of state C. */
+	private void reactMain_region_C() {
 		if (sCInterface.ev) {
 			nextStateIndex = 0;
 			stateVector[0] = State.$NullState$;
@@ -181,12 +184,25 @@ public class OperationsStatemachine implements IOperationsStatemachine {
 			sCInterface.operationCallback.unnamedInterfaceOperation2(4);
 
 			nextStateIndex = 0;
-			stateVector[0] = State.main_region_C;
+			stateVector[0] = State.main_region_D;
 		}
 	}
 
-	/* The reactions of state C. */
-	private void reactMain_region_C() {
+	/* The reactions of state D. */
+	private void reactMain_region_D() {
+	}
+
+	/* The reactions of state A. */
+	private void reactMain_region_A() {
+		nextStateIndex = 0;
+		stateVector[0] = State.$NullState$;
+
+		operationCallback.internalOperation1();
+
+		myBool = operationCallback.internalOperation2(4);
+
+		nextStateIndex = 0;
+		stateVector[0] = State.main_region_B;
 	}
 
 	public void runCycle() {
@@ -196,15 +212,18 @@ public class OperationsStatemachine implements IOperationsStatemachine {
 		for (nextStateIndex = 0; nextStateIndex < stateVector.length; nextStateIndex++) {
 
 			switch (stateVector[nextStateIndex]) {
-				case main_region_A :
-					reactMain_region_A();
-					break;
 				case main_region_B :
 					reactMain_region_B();
 					break;
 				case main_region_C :
 					reactMain_region_C();
 					break;
+				case main_region_D :
+					reactMain_region_D();
+					break;
+				case main_region_A :
+					reactMain_region_A();
+					break;
 				default :
 					// $NullState$
 			}

+ 19 - 0
test-plugins/org.yakindu.sct.generator.java.test/src/org/yakindu/sct/generator/java/AllTestsTestCustom.java

@@ -0,0 +1,19 @@
+/**
+ * Copyright (c) 2014 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;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+@RunWith(Suite.class)
+@SuiteClasses({OperationsTestCustom.class})
+public class AllTestsTestCustom {
+}

+ 102 - 0
test-plugins/org.yakindu.sct.generator.java.test/src/org/yakindu/sct/generator/java/OperationsTestCustom.java

@@ -0,0 +1,102 @@
+/**
+ * Copyright (c) 2014 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;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+import org.yakindu.scr.operations.IOperationsStatemachine.SCIInterface1OperationCallback;
+import org.yakindu.scr.operations.IOperationsStatemachine.SCInterfaceOperationCallback;
+import org.yakindu.scr.operations.OperationsStatemachine;
+import org.yakindu.scr.operations.IOperationsStatemachine.InternalOperationCallback;
+import org.yakindu.scr.operations.OperationsStatemachine.State;
+/**
+ *  Unit TestCase for Operations
+ */
+@SuppressWarnings("all")
+public class OperationsTestCustom implements InternalOperationCallback, SCIInterface1OperationCallback, SCInterfaceOperationCallback{
+
+	private OperationsStatemachine statemachine;
+
+	private boolean internalOpration1visited = false;
+	private boolean interfaceOperation1visited = false;
+	private boolean unnamedInterfaceOperation1visited = false;
+	
+	@Before
+	public void setUp() {
+		statemachine = new OperationsStatemachine();
+		statemachine.init();
+		statemachine.setInternalOperationCallback(this);
+		statemachine.getSCInterface().setSCInterfaceOperationCallback(this);
+		statemachine.getSCIInterface1().setSCIInterface1OperationCallback(this);
+	}
+
+	@After
+	public void tearDown() {
+		statemachine = null;
+	}
+
+	@Test
+	public void testOperationsSimpleTest() {
+		statemachine.enter();
+		assertTrue(statemachine.isStateActive(State.main_region_A));
+		statemachine.runCycle();
+		assertTrue(statemachine.isStateActive(State.main_region_B));
+	}
+	
+	@Test
+	public void testOperationsTest() {
+		statemachine.enter();
+		assertTrue(statemachine.isStateActive(State.main_region_A));
+		statemachine.runCycle();
+		assertTrue(statemachine.isStateActive(State.main_region_B));
+		statemachine.raiseEv();
+		statemachine.runCycle();
+		assertTrue(statemachine.isStateActive(State.main_region_C));
+		statemachine.raiseEv();
+		statemachine.runCycle();
+		assertTrue(statemachine.isStateActive(State.main_region_D));
+		
+		// Operations used
+		assertTrue(interfaceOperation1visited && internalOpration1visited && unnamedInterfaceOperation1visited);
+	}
+
+	public void internalOperation1() {
+		internalOpration1visited = true;
+	}
+
+	public boolean internalOperation2(long param1) {
+		assertTrue(param1 == 4);		
+		return false;
+	}
+
+	public void interfaceOperation1() {
+		interfaceOperation1visited = true;		
+	}
+
+	public boolean interfaceOperation2(long param1) {
+		assertTrue(param1 == 4);	
+		return false;
+	}
+
+	public void unnamedInterfaceOperation1() {
+		unnamedInterfaceOperation1visited = true;
+	}
+
+	public boolean unnamedInterfaceOperation2(long param1) {
+		assertTrue(param1 == 4);	
+		return false;
+	}
+}

+ 3 - 2
test-plugins/org.yakindu.sct.generator.java.test/test-gen/org/yakindu/sct/generator/java/test/AllTestsTest.java

@@ -26,8 +26,9 @@ import org.junit.runners.Suite.SuiteClasses;
 		InEventLifeCycleTest.class, IntegerExpressionsTest.class,
 		InternalEventLifeCycleTest.class, LocalReactionsTest.class,
 		LogicalAndTestsTest.class, LogicalOrTestsTest.class,
-		NamedInterfaceAccessTest.class, OutEventLifeCycleTest.class,
-		ParenthesisTest.class, PriorityValuesTest.class, RaiseEventTest.class,
+		NamedInterfaceAccessTest.class, OperationsTest.class,
+		OutEventLifeCycleTest.class, ParenthesisTest.class,
+		PriorityValuesTest.class, RaiseEventTest.class,
 		SameNameDifferentRegionTest.class, ShallowHistoryTest.class,
 		SimpleEventTest.class, StatechartLocalReactionsTest.class,
 		SimpleHierachyTest.class, StateIsActiveTest.class,

+ 43 - 0
test-plugins/org.yakindu.sct.generator.java.test/test-gen/org/yakindu/sct/generator/java/test/OperationsTest.java

@@ -0,0 +1,43 @@
+/**
+ * Copyright (c) 2014 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.operations.OperationsStatemachine;
+import org.yakindu.scr.operations.OperationsStatemachine.State;
+/**
+ *  Unit TestCase for Operations
+ */
+@SuppressWarnings("all")
+public class OperationsTest {
+
+	private OperationsStatemachine statemachine;
+
+	@Before
+	public void setUp() {
+		statemachine = new OperationsStatemachine();
+		statemachine.init();
+	}
+
+	@After
+	public void tearDown() {
+		statemachine = null;
+	}
+
+	@Test
+	public void testOperationsSimpleTest() {
+		statemachine.enter();
+	}
+}

+ 30 - 0
test-plugins/org.yakindu.sct.test.models/tests/Operations.sctunit

@@ -0,0 +1,30 @@
+
+testgroup Operations for statechart Operations{
+	test OperationsSimpleTest { 
+		enter
+//		assert active (Operations.main_region.A)
+//		
+//		cycle
+//		assert active (Operations.main_region.B)
+		 
+	}
+	
+	
+//	test OperationsTest { 
+//		enter
+//		assert active (Operations.main_region.A)
+//		
+//		cycle
+//		assert active (Operations.main_region.B)
+//		raise ev
+//		cycle
+//		
+//		assert active (Operations.main_region.C)
+//		raise ev	
+//		cycle	
+//	
+//		assert active (Operations.main_region.D)		
+//		 
+//	}  
+}
+