Bläddra i källkod

Added SCT Unit test case for Parenthesis expressions

Andreas Mülder 13 år sedan
förälder
incheckning
302659d16b

+ 21 - 0
test-plugins/org.yakindu.sct.generator.c.test/gtests/Parenthesis/Parenthesis.cc

@@ -0,0 +1,21 @@
+/**
+* Copyright (c) 2012 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
+*/
+#include <string>
+#include "gtest/gtest.h"
+#include "Parenthesis.h"
+
+TEST(StatemachineTest, simple) {
+	Parenthesis handle;
+	parenthesis_init(&handle);
+	parenthesis_enter(&handle);
+	EXPECT_TRUE(parenthesis_isActive(&handle, Parenthesis_mainRegion_A));
+	EXPECT_TRUE(parenthesisIface_get_erg(&handle) == 8);
+}

+ 8 - 0
test-plugins/org.yakindu.sct.generator.c.test/gtests/Parenthesis/Parenthesis.sgen

@@ -0,0 +1,8 @@
+GeneratorModel for yakindu::c {
+	statechart Parenthesis {
+		feature Outlet {
+			targetProject = "gtests"
+			targetFolder = "Parenthesis"
+		}
+	}
+}

+ 39 - 0
test-plugins/org.yakindu.sct.generator.c.test/src-gen/org/yakindu/sct/generator/c/test/Parenthesis.java

@@ -0,0 +1,39 @@
+/**
+ * Copyright (c) 2012 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.c.test;
+
+import java.util.Collection;
+
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.yakindu.sct.generator.c.gtest.GTest;
+import org.yakindu.sct.generator.c.gtest.GTestRunner;
+import org.yakindu.sct.generator.c.gtest.GTestHelper;
+
+@GTest(sourceFile = "gtests/Parenthesis/Parenthesis.cc", program = "gtests/Parenthesis/Parenthesis", model = "testmodels/Parenthesis.sct")
+@RunWith(GTestRunner.class)
+public class Parenthesis {
+
+	protected final GTestHelper helper = new GTestHelper(this) {
+
+		@Override
+		protected void getSourceFiles(Collection<String> files) {
+			super.getSourceFiles(files);
+			files.add(getFileName(getTestProgram()) + ".c");
+		}
+	};
+
+	@Before
+	public void setUp() {
+		helper.generate();
+		helper.compile();
+	}
+}

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

@@ -0,0 +1,16 @@
+package org.yakindu.scr.parenthesis;
+
+import org.yakindu.scr.IStatemachine;
+
+public interface IParenthesisStatemachine extends IStatemachine {
+
+	public interface SCIDefault {
+
+		public int getErg();
+		public void setErg(int value);
+
+	}
+
+	public SCIDefault getSCIDefault();
+
+}

+ 136 - 0
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/parenthesis/ParenthesisStatemachine.java

@@ -0,0 +1,136 @@
+package org.yakindu.scr.parenthesis;
+
+public class ParenthesisStatemachine implements IParenthesisStatemachine {
+
+	private final class SCIDefaultImpl implements SCIDefault {
+
+		private int erg;
+
+		public int getErg() {
+			return erg;
+		}
+
+		public void setErg(int value) {
+			this.erg = value;
+		}
+
+	}
+
+	private SCIDefaultImpl sCIDefault;
+
+	public enum State {
+		MainRegion_A, $NullState$
+	};
+
+	private final State[] stateVector = new State[1];
+
+	private int nextStateIndex;
+
+	public ParenthesisStatemachine() {
+
+		sCIDefault = new SCIDefaultImpl();
+
+	}
+
+	public void init() {
+		for (int i = 0; i < 1; i++) {
+			stateVector[i] = State.$NullState$;
+		}
+
+		clearEvents();
+		clearOutEvents();
+	}
+
+	protected void clearEvents() {
+
+	}
+
+	protected void clearOutEvents() {
+	}
+
+	public boolean isStateActive(State state) {
+		switch (state) {
+
+			case MainRegion_A :
+				return stateVector[0] == State.MainRegion_A;
+
+			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 int getErg() {
+		return sCIDefault.getErg();
+	}
+
+	public void setErg(int value) {
+		sCIDefault.setErg(value);
+	}
+
+	public void enter() {
+		entryActionParenthesis();
+		sCIDefault.erg = (4 * (3 - 1));
+
+		nextStateIndex = 0;
+		stateVector[0] = State.MainRegion_A;
+
+	}
+
+	public void exit() {
+		//Handle exit of all possible states (of mainRegion) at position 0...
+		switch (stateVector[0]) {
+
+			case MainRegion_A :
+				stateVector[0] = State.$NullState$;
+
+				break;
+
+			default :
+				break;
+		}
+
+		exitActionParenthesis();
+	}
+
+	private void entryActionParenthesis() {
+
+	}
+
+	private void exitActionParenthesis() {
+
+	}
+
+	private void reactMainRegion_A() {
+
+	}
+
+	public void runCycle() {
+
+		clearOutEvents();
+
+		for (nextStateIndex = 0; nextStateIndex < stateVector.length; nextStateIndex++) {
+
+			switch (stateVector[nextStateIndex]) {
+				case MainRegion_A :
+					reactMainRegion_A();
+					break;
+				default :
+					// $NullState$
+			}
+		}
+
+		clearEvents();
+	}
+}

+ 44 - 0
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/sct/generator/java/test/ParenthesisTest.java

@@ -0,0 +1,44 @@
+/**
+ * Copyright (c) 2012 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.parenthesis.ParenthesisStatemachine;
+import org.yakindu.scr.parenthesis.ParenthesisStatemachine.State;
+/**
+ *  Unit TestCase for Parenthesis
+ */
+@SuppressWarnings("all")
+public class ParenthesisTest {
+
+	private ParenthesisStatemachine statemachine;
+
+	@Before
+	public void setUp() {
+		statemachine = new ParenthesisStatemachine();
+		statemachine.init();
+		statemachine.enter();
+	}
+
+	@After
+	public void tearDown() {
+		statemachine = null;
+	}
+
+	@Test
+	public void testsimple() {
+		assertTrue(statemachine.isStateActive(State.MainRegion_A));
+		assertTrue(statemachine.getErg() == 8);
+	}
+}

+ 46 - 0
test-plugins/org.yakindu.sct.model.sexec.interpreter.test/src-gen/org/yakindu/sct/model/sexec/interpreter/test/ParenthesisTest.java

@@ -0,0 +1,46 @@
+/**
+ * Copyright (c) 2012 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.model.sexec.interpreter.test;
+import org.eclipse.xtext.junit4.InjectWith;
+import org.eclipse.xtext.junit4.XtextRunner;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.yakindu.sct.model.sexec.interpreter.test.util.AbstractExecutionFlowTest;
+import org.yakindu.sct.model.sexec.interpreter.test.util.SExecInjectionProvider;
+import com.google.inject.Inject;
+import org.junit.Before;
+import org.yakindu.sct.model.sexec.interpreter.IExecutionFlowInterpreter;
+import org.yakindu.sct.model.sexec.ExecutionFlow;
+import util.TestModels;
+import static junit.framework.Assert.*;
+/**
+ *  Unit TestCase for Parenthesis
+ */
+@SuppressWarnings("all")
+@RunWith(XtextRunner.class)
+@InjectWith(SExecInjectionProvider.class)
+public class ParenthesisTest extends AbstractExecutionFlowTest {
+
+	@Inject
+	private TestModels models;
+
+	@Before
+	public void setup() throws Exception {
+		ExecutionFlow flow = models
+				.loadExecutionFlowFromResource("Parenthesis.sct");
+		initInterpreter(flow);
+	}
+	@Test
+	public void simple() throws Exception {
+		assertTrue(isActive("A"));
+		assertTrue(getInteger("erg") == 8);
+	}
+}

BIN
test-plugins/org.yakindu.sct.test.models/images/Parenthesis.png


+ 13 - 0
test-plugins/org.yakindu.sct.test.models/src/util/TestModels.java

@@ -44,6 +44,7 @@ public class TestModels {
 	public static final String GUARD = "Guard.sct";
 	public static final String INTEGER_EXPRESSIONS = "IntegerExpressions.sct";
 	public static final String JAVA_KEYWORDS_M = "JavaKeywords.sct";
+	public static final String PARENTHESIS = "Parenthesis.sct";
 	public static final String PRIORITY_VALUES = "PriorityValues.sct";
 	public static final String RAISE_EVENTS = "RaiseEvent.sct";
 	public static final String REAL_EXPRESSIONS = "RealExpressions.sct";
@@ -164,6 +165,18 @@ public class TestModels {
 		return loadExecutionFlowFromResource(JAVA_KEYWORDS_M);
 	}
 
+	
+	/**
+	 * <img src="../../images/Parenthesis.png" /> <br />
+	 * 
+	 * @return the {@link ExecutionFlow}
+	 * @throws IOException
+	 */
+	public ExecutionFlow createParenthesisModel() throws IOException {
+		return loadExecutionFlowFromResource(PARENTHESIS);
+	}
+	
+		
 	/**
 	 * <img src="../../images/PriorityValues.png" /> <br />
 	 * 

+ 72 - 0
test-plugins/org.yakindu.sct.test.models/testmodels/Parenthesis.sct

@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:sgraph="http://www.yakindu.org/sct/sgraph/2.0.0">
+  <sgraph:Statechart xmi:id="_C7hgcAJTEeKgI6gPkT8J7A" specification="interface: &#xD;&#xA;var erg : integer&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;" name="Parenthesis">
+    <regions xmi:id="_C7jVoAJTEeKgI6gPkT8J7A" name="mainRegion">
+      <vertices xsi:type="sgraph:Entry" xmi:id="_C7oOIQJTEeKgI6gPkT8J7A">
+        <outgoingTransitions xmi:id="_C7qqZQJTEeKgI6gPkT8J7A" target="_C7pcQQJTEeKgI6gPkT8J7A"/>
+      </vertices>
+      <vertices xsi:type="sgraph:State" xmi:id="_C7pcQQJTEeKgI6gPkT8J7A" specification="entry /&#xD;&#xA;erg =  4* (3 -1)&#xD;&#xA;" name="A" incomingTransitions="_C7qqZQJTEeKgI6gPkT8J7A"/>
+    </regions>
+  </sgraph:Statechart>
+  <notation:Diagram xmi:id="_C7iukAJTEeKgI6gPkT8J7A" type="org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor" element="_C7hgcAJTEeKgI6gPkT8J7A" measurementUnit="Pixel">
+    <children xmi:id="_C7lx4AJTEeKgI6gPkT8J7A" type="Region" element="_C7jVoAJTEeKgI6gPkT8J7A">
+      <children xsi:type="notation:DecorationNode" xmi:id="_C7nnEAJTEeKgI6gPkT8J7A" type="RegionName">
+        <styles xsi:type="notation:ShapeStyle" xmi:id="_C7nnEQJTEeKgI6gPkT8J7A"/>
+        <layoutConstraint xsi:type="notation:Location" xmi:id="_C7nnEgJTEeKgI6gPkT8J7A"/>
+      </children>
+      <children xsi:type="notation:Shape" xmi:id="_C7nnEwJTEeKgI6gPkT8J7A" type="RegionCompartment" fontName="Verdana" lineColor="4210752">
+        <children xmi:id="_C7oOIgJTEeKgI6gPkT8J7A" type="Entry" element="_C7oOIQJTEeKgI6gPkT8J7A">
+          <children xmi:id="_C7o1MAJTEeKgI6gPkT8J7A" type="BorderItemLabelContainer">
+            <children xsi:type="notation:DecorationNode" xmi:id="_C7o1MwJTEeKgI6gPkT8J7A" type="BorderItemLabel">
+              <styles xsi:type="notation:ShapeStyle" xmi:id="_C7o1NAJTEeKgI6gPkT8J7A"/>
+              <layoutConstraint xsi:type="notation:Location" xmi:id="_C7o1NQJTEeKgI6gPkT8J7A"/>
+            </children>
+            <styles xsi:type="notation:ShapeStyle" xmi:id="_C7o1MQJTEeKgI6gPkT8J7A" fontName="Verdana" lineColor="4210752"/>
+            <layoutConstraint xsi:type="notation:Bounds" xmi:id="_C7o1MgJTEeKgI6gPkT8J7A"/>
+          </children>
+          <styles xsi:type="notation:ShapeStyle" xmi:id="_C7oOIwJTEeKgI6gPkT8J7A" fontName="Verdana" lineColor="4210752"/>
+          <layoutConstraint xsi:type="notation:Bounds" xmi:id="_C7pcQAJTEeKgI6gPkT8J7A" x="119" y="39"/>
+        </children>
+        <children xmi:id="_C7pcQwJTEeKgI6gPkT8J7A" type="State" element="_C7pcQQJTEeKgI6gPkT8J7A">
+          <children xsi:type="notation:DecorationNode" xmi:id="_C7qDUAJTEeKgI6gPkT8J7A" type="StateName">
+            <styles xsi:type="notation:ShapeStyle" xmi:id="_C7qDUQJTEeKgI6gPkT8J7A"/>
+            <layoutConstraint xsi:type="notation:Location" xmi:id="_C7qDUgJTEeKgI6gPkT8J7A"/>
+          </children>
+          <children xsi:type="notation:Compartment" xmi:id="_C7qDUwJTEeKgI6gPkT8J7A" type="StateTextCompartment">
+            <children xsi:type="notation:Shape" xmi:id="_C7qqYAJTEeKgI6gPkT8J7A" type="StateTextCompartmentExpression" fontName="Verdana" lineColor="4210752">
+              <layoutConstraint xsi:type="notation:Bounds" xmi:id="_C7qqYQJTEeKgI6gPkT8J7A"/>
+            </children>
+          </children>
+          <children xsi:type="notation:Compartment" xmi:id="_C7qqYgJTEeKgI6gPkT8J7A" type="StateFigureCompartment"/>
+          <styles xsi:type="notation:ShapeStyle" xmi:id="_C7pcRAJTEeKgI6gPkT8J7A" fontName="Verdana" fillColor="15981773" lineColor="12632256"/>
+          <styles xsi:type="notation:FontStyle" xmi:id="_C7pcRQJTEeKgI6gPkT8J7A"/>
+          <styles xsi:type="notation:BooleanValueStyle" xmi:id="_C7qqYwJTEeKgI6gPkT8J7A"/>
+          <layoutConstraint xsi:type="notation:Bounds" xmi:id="_C7qqZAJTEeKgI6gPkT8J7A" x="4" y="74" width="201" height="76"/>
+        </children>
+        <layoutConstraint xsi:type="notation:Bounds" xmi:id="_C7nnFAJTEeKgI6gPkT8J7A"/>
+      </children>
+      <styles xsi:type="notation:ShapeStyle" xmi:id="_C7lx4QJTEeKgI6gPkT8J7A" fontName="Verdana" fillColor="15790320" lineColor="12632256"/>
+      <layoutConstraint xsi:type="notation:Bounds" xmi:id="_C7oOIAJTEeKgI6gPkT8J7A" x="220" y="10" width="331" height="206"/>
+    </children>
+    <children xsi:type="notation:Shape" xmi:id="_C7sfkAJTEeKgI6gPkT8J7A" type="StatechartText" fontName="Verdana" lineColor="4210752">
+      <children xsi:type="notation:DecorationNode" xmi:id="_C7sfkgJTEeKgI6gPkT8J7A" type="StatechartName">
+        <styles xsi:type="notation:ShapeStyle" xmi:id="_C7sfkwJTEeKgI6gPkT8J7A"/>
+        <layoutConstraint xsi:type="notation:Location" xmi:id="_C7sflAJTEeKgI6gPkT8J7A"/>
+      </children>
+      <children xsi:type="notation:Shape" xmi:id="_C7tGoAJTEeKgI6gPkT8J7A" type="StatechartTextExpression" fontName="Verdana" lineColor="4210752">
+        <layoutConstraint xsi:type="notation:Bounds" xmi:id="_C7tGoQJTEeKgI6gPkT8J7A"/>
+      </children>
+      <layoutConstraint xsi:type="notation:Bounds" xmi:id="_C7tGogJTEeKgI6gPkT8J7A" x="10" y="10" width="200" height="206"/>
+    </children>
+    <styles xsi:type="notation:DiagramStyle" xmi:id="_C7iukQJTEeKgI6gPkT8J7A"/>
+    <edges xmi:id="_C7r4gAJTEeKgI6gPkT8J7A" type="Transition" element="_C7qqZQJTEeKgI6gPkT8J7A" source="_C7oOIgJTEeKgI6gPkT8J7A" target="_C7pcQwJTEeKgI6gPkT8J7A">
+      <children xsi:type="notation:DecorationNode" xmi:id="_C7r4hAJTEeKgI6gPkT8J7A" type="TransitionExpression">
+        <styles xsi:type="notation:ShapeStyle" xmi:id="_C7r4hQJTEeKgI6gPkT8J7A"/>
+        <layoutConstraint xsi:type="notation:Location" xmi:id="_C7r4hgJTEeKgI6gPkT8J7A" y="10"/>
+      </children>
+      <styles xsi:type="notation:ConnectorStyle" xmi:id="_C7r4gQJTEeKgI6gPkT8J7A" lineColor="4210752"/>
+      <styles xsi:type="notation:FontStyle" xmi:id="_C7r4gwJTEeKgI6gPkT8J7A" fontName="Verdana"/>
+      <bendpoints xsi:type="notation:RelativeBendpoints" xmi:id="_C7r4ggJTEeKgI6gPkT8J7A" points="[0, 0, 0, 0]$[0, 0, 0, 0]"/>
+    </edges>
+  </notation:Diagram>
+</xmi:XMI>

+ 8 - 0
test-plugins/org.yakindu.sct.test.models/tests/Parenthesis.sctunit

@@ -0,0 +1,8 @@
+testgroup Parenthesis for statechart Parenthesis {
+	
+	test simple {
+		
+		assert active (Parenthesis.mainRegion.A)
+		assert erg == 8
+	}
+}