Browse Source

Share project "org.yakindu.sct.simulation.runtime.test" into "https://svn.codespot.com/a/eclipselabs.org/yakindu"

terfloth@itemis.de 14 years ago
parent
commit
095915c5c5
15 changed files with 2524 additions and 0 deletions
  1. 7 0
      test-plugins/org.yakindu.sct.simulation.runtime.test/.classpath
  2. 28 0
      test-plugins/org.yakindu.sct.simulation.runtime.test/.project
  3. 7 0
      test-plugins/org.yakindu.sct.simulation.runtime.test/.settings/org.eclipse.jdt.core.prefs
  4. 15 0
      test-plugins/org.yakindu.sct.simulation.runtime.test/META-INF/MANIFEST.MF
  5. 4 0
      test-plugins/org.yakindu.sct.simulation.runtime.test/build.properties
  6. 35 0
      test-plugins/org.yakindu.sct.simulation.runtime.test/src/org/yakindu/sct/simulation/runtime/sgraph/builder/test/AllTests.java
  7. 355 0
      test-plugins/org.yakindu.sct.simulation.runtime.test/src/org/yakindu/sct/simulation/runtime/sgraph/builder/test/StatechartBuilderTest.java
  8. 35 0
      test-plugins/org.yakindu.sct.simulation.runtime.test/src/org/yakindu/sct/simulation/runtime/sgraph/test/AllTests.java
  9. 180 0
      test-plugins/org.yakindu.sct.simulation.runtime.test/src/org/yakindu/sct/simulation/runtime/sgraph/test/StatechartTest.java
  10. 34 0
      test-plugins/org.yakindu.sct.simulation.runtime.test/src/org/yakindu/sct/simulation/runtime/stext/builder/test/AllTests.java
  11. 864 0
      test-plugins/org.yakindu.sct.simulation.runtime.test/src/org/yakindu/sct/simulation/runtime/stext/builder/test/BuilderTest.java
  12. 37 0
      test-plugins/org.yakindu.sct.simulation.runtime.test/src/org/yakindu/sct/simulation/runtime/stext/test/AllTests.java
  13. 365 0
      test-plugins/org.yakindu.sct.simulation.runtime.test/src/org/yakindu/sct/simulation/runtime/stext/test/CoreFunctionsTest.java
  14. 373 0
      test-plugins/org.yakindu.sct.simulation.runtime.test/src/org/yakindu/sct/simulation/runtime/stext/test/ExpressionsTest.java
  15. 185 0
      test-plugins/org.yakindu.sct.simulation.runtime.test/src/org/yakindu/sct/simulation/runtime/stext/test/FunctionsTest.java

+ 7 - 0
test-plugins/org.yakindu.sct.simulation.runtime.test/.classpath

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 28 - 0
test-plugins/org.yakindu.sct.simulation.runtime.test/.project

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.yakindu.sct.simulation.runtime.test</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

+ 7 - 0
test-plugins/org.yakindu.sct.simulation.runtime.test/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,7 @@
+#Tue Nov 24 13:14:40 CET 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5

+ 15 - 0
test-plugins/org.yakindu.sct.simulation.runtime.test/META-INF/MANIFEST.MF

@@ -0,0 +1,15 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: YAKINDU SCT Runtime Test
+Bundle-SymbolicName: org.yakindu.sct.simulation.runtime.test
+Bundle-Version: 1.1.0.qualifier
+Bundle-Vendor: YAKINDU.org
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.junit;bundle-version="3.8.0",
+ org.yakindu.sct.model.sgraph;bundle-version="1.0.0",
+ org.yakindu.sct.simulation.runtime;bundle-version="1.1.0"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
+Export-Package: org.yakindu.sct.simulation.runtime.sgraph.builder.test,
+ org.yakindu.sct.simulation.runtime.sgraph.test

+ 4 - 0
test-plugins/org.yakindu.sct.simulation.runtime.test/build.properties

@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .

+ 35 - 0
test-plugins/org.yakindu.sct.simulation.runtime.test/src/org/yakindu/sct/simulation/runtime/sgraph/builder/test/AllTests.java

@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) 2010 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.simulation.runtime.sgraph.builder.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+@RunWith(value=Suite.class)
+@SuiteClasses(value={
+		ExpressionsTest.class, 
+		FunctionsTest.class,
+		CoreFunctionsTest.class
+		}) 
+*/
+public class AllTests extends TestSuite{
+	
+	public static Test suite() {
+		TestSuite suite = new AllTests();
+		suite.addTestSuite(StatechartBuilderTest.class);
+			
+		return suite;
+	}
+
+	
+
+}

+ 355 - 0
test-plugins/org.yakindu.sct.simulation.runtime.test/src/org/yakindu/sct/simulation/runtime/sgraph/builder/test/StatechartBuilderTest.java

@@ -0,0 +1,355 @@
+/**
+ * Copyright (c) 2010 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.simulation.runtime.sgraph.builder.test;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.yakindu.sct.model.sgraph.SGraphFactory;
+import org.yakindu.sct.model.sgraph.SGraphPackage;
+import org.yakindu.sct.simulation.runtime.stext.Assign;
+import org.yakindu.sct.simulation.runtime.stext.ProcedureCall;
+import org.yakindu.sct.simulation.runtime.stext.Raise;
+import org.yakindu.sct.simulation.runtime.stext.Statement;
+import org.yakindu.sct.simulation.runtime.stext.StatementSequence;
+import org.yakindu.sct.simulation.runtime.stext.UnaryOperation;
+import org.yakindu.sct.simulation.runtime.stext.VariableRef;
+import org.yakindu.sct.simulation.runtime.sgraph.Action;
+import org.yakindu.sct.simulation.runtime.sgraph.ActionStatement;
+import org.yakindu.sct.simulation.runtime.sgraph.CompoundState;
+import org.yakindu.sct.simulation.runtime.sgraph.FinalState;
+import org.yakindu.sct.simulation.runtime.sgraph.GuardExpression;
+import org.yakindu.sct.simulation.runtime.sgraph.Node;
+import org.yakindu.sct.simulation.runtime.sgraph.Pseudostate;
+import org.yakindu.sct.simulation.runtime.sgraph.PseudostateKind;
+import org.yakindu.sct.simulation.runtime.sgraph.Region;
+import org.yakindu.sct.simulation.runtime.sgraph.SimpleState;
+import org.yakindu.sct.simulation.runtime.sgraph.Statechart;
+import org.yakindu.sct.simulation.runtime.sgraph.Transition;
+import org.yakindu.sct.simulation.runtime.sgraph.builder.StatechartBuilder;
+
+public class StatechartBuilderTest extends TestCase {
+	
+
+	static {
+		// set up EMF - the EPackage.Registry requires a context class loader ...
+		if (Thread.currentThread().getContextClassLoader() == null) {
+			Thread.currentThread().setContextClassLoader(StatechartBuilderTest.class.getClassLoader());	
+		}
+		SGraphPackage.eINSTANCE.eClass();
+	}
+	
+	protected org.yakindu.sct.model.sgraph.Statechart sourceSC;
+	protected SGraphFactory factory;
+	StatechartBuilder builder;
+	
+	
+
+	@Override
+	protected void setUp() throws Exception {
+		super.setUp();
+		factory = SGraphFactory.eINSTANCE;
+		sourceSC = factory.createStatechart();
+		sourceSC.setName("SC");
+		sourceSC.setUUID("SC1");
+		builder = new StatechartBuilder();
+	}
+
+	
+
+	public void testEmptyStatechart() {
+		
+		Statechart tSC = builder.build(sourceSC);
+		assertNotNull(tSC);
+		//assertEquals(sSC.getName(), tSC.)
+	}
+	
+	
+	public void testVars() {
+		statemachine.Variable var_a = factory.createVariable();
+		var_a.setName("a");
+		var_a.setDataType(statemachine.DataTypes.INT);
+		sourceSC.getDataElement().add(var_a);
+
+		statemachine.Variable var_b = factory.createVariable();
+		var_b.setName("b");
+		var_b.setDataType(statemachine.DataTypes.BOOLEAN);
+		sourceSC.getDataElement().add(var_b);
+		
+		Statechart tSC = builder.build(sourceSC);
+		assertNotNull(tSC.getVariable(var_a.getName()));
+		assertNotNull(tSC.getVariable(var_b.getName()));
+		
+		assertEquals(0, tSC.getVariable("a").getValue());
+		assertEquals(false, tSC.getVariable("b").getValue());
+	}
+
+	
+	
+	public void testSignalEvents() {
+		statemachine.Event event_a = factory.createEvent();
+		event_a.setName("a");
+		sourceSC.getDataElement().add(event_a);
+
+		statemachine.Event event_b = factory.createEvent();
+		event_b.setName("b");
+		sourceSC.getDataElement().add(event_b);
+		
+		Statechart tSC = builder.build(sourceSC);
+		assertEquals(2, tSC.getSignalEvents().size());
+		assertNotNull(tSC.getSignalEvent(event_a.getName()));
+		assertNotNull(tSC.getSignalEvent(event_b.getName()));
+	}
+
+	
+	
+	public void testTopLevelRegions() throws Exception {
+		statemachine.Region reg_a = factory.createRegion();
+		reg_a.setPriority(3);
+		sourceSC.getRegion().add(reg_a);
+
+		statemachine.Region reg_b = factory.createRegion();
+		reg_b.setPriority(1);
+		sourceSC.getRegion().add(reg_b);
+
+		Statechart tSC = builder.build(sourceSC);
+		List<Region> regions = tSC.getRegions();
+		
+		assertEquals(2, regions.size());
+		assertEquals(1, regions.get(0).getPriority());
+		assertEquals("1", regions.get(0).getId());
+		assertEquals(3, regions.get(1).getPriority());
+		assertEquals("3", regions.get(1).getId());
+	}
+
+	
+
+	
+	public void testChoice() throws Exception {
+		testPseudoState(statemachine.PseudoTypes.CHOICE, PseudostateKind.CHOICE);
+	}
+
+	public void testJunction() throws Exception {
+		testPseudoState(statemachine.PseudoTypes.JUNCTION, PseudostateKind.JUNCTION);
+	}
+
+	public void testInitialState() throws Exception {
+		testPseudoState(statemachine.PseudoTypes.INITIAL, PseudostateKind.INITIAL);
+	}
+
+	public void testDeepHistory() throws Exception {
+		testPseudoState(statemachine.PseudoTypes.DEEP_HISTORY, PseudostateKind.DEEPHISTORY);
+	}
+	
+	public void testShallowHistory() throws Exception {
+		testPseudoState(statemachine.PseudoTypes.SHALLOW_HISTORY, PseudostateKind.SHALLOWHISTORY);
+	}
+
+	
+	public void testPseudoState(statemachine.PseudoTypes sourceType, PseudostateKind targetType) throws Exception {
+		statemachine.Region region = factory.createRegion();
+		region.setPriority(3);
+		sourceSC.getRegion().add(region);
+
+		statemachine.Pseudostate initial = factory.createPseudostate();
+		initial.setPseudoType(sourceType);
+		initial.setId(1);
+		region.getState().add(initial);
+		
+		Statechart tSC = builder.build(sourceSC);
+		List<Region> regions = tSC.getRegions();
+		
+		assertEquals(1, regions.size());
+		assertEquals(1, regions.get(0).getNodes().size());
+		Node node = regions.get(0).getNodes().iterator().next();
+		assertTrue(node instanceof Pseudostate);
+		assertEquals(targetType, ((Pseudostate)node).getKind());
+	}
+	
+	
+	public void testSimpleState() {
+		statemachine.Region region = factory.createRegion();
+		region.setPriority(3);
+		sourceSC.getRegion().add(region);
+
+		statemachine.State state = factory.createState();
+		state.setName("stateA");
+		state.setId(1);
+		state.setEntry("a=1;");
+		state.setDo("raise(abc);");
+		state.setExit("call();");
+		region.getState().add(state);
+		
+		Statechart tSC = builder.build(sourceSC);
+		List<Region> regions = tSC.getRegions();
+		
+		assertEquals(1, regions.size());
+		assertEquals(1, regions.get(0).getNodes().size());
+		Node node = regions.get(0).getNodes().iterator().next();
+		assertTrue(node instanceof SimpleState);
+
+		SimpleState tState = (SimpleState)node;
+		assertEquals(state.getName(), tState.getName());
+		
+		StatementSequence seq = (StatementSequence) ((ActionStatement)tState.getEntryAction()).getStatement();
+		assertTrue(firstFromSequence(tState.getEntryAction()) instanceof Assign);
+		assertTrue(firstFromSequence(tState.getDoAction()) instanceof Raise);
+		assertTrue(firstFromSequence(tState.getExitAction()) instanceof ProcedureCall);
+	}
+	
+	
+	public void testFinalState() {
+		statemachine.Region region = factory.createRegion();
+		region.setPriority(3);
+		sourceSC.getRegion().add(region);
+
+		statemachine.FinalState state = factory.createFinalState();
+		state.setId(1);
+		region.getState().add(state);
+		
+		Statechart tSC = builder.build(sourceSC);
+		List<Region> regions = tSC.getRegions();
+		
+		assertEquals(1, regions.size());
+		assertEquals(1, regions.get(0).getNodes().size());
+		Node node = regions.get(0).getNodes().iterator().next();
+		assertTrue(node instanceof FinalState);
+	}
+	
+
+	
+	/**
+	 * TODO: CompoundStates do not support do-Actions 
+	 */
+	public void testCompboundState() {
+		statemachine.Region region = factory.createRegion();
+		region.setPriority(3);
+		sourceSC.getRegion().add(region);
+
+		statemachine.State state = factory.createState();
+		state.setName("stateA");
+		state.setId(1);
+		state.setEntry("a=1;");
+		state.setDo("raise(abc);");
+		state.setExit("call();");
+		region.getState().add(state);
+
+		statemachine.Region subRegion = factory.createRegion();
+		region.setPriority(0);
+		state.getRegion().add(subRegion);
+
+		
+		Statechart tSC = builder.build(sourceSC);
+		List<Region> regions = tSC.getRegions();
+		
+
+		Node node = regions.get(0).getNodes().iterator().next();
+		assertTrue(node instanceof CompoundState);
+
+		CompoundState tState = (CompoundState)node;
+		assertEquals(state.getName(), tState.getName());
+		
+		StatementSequence seq = (StatementSequence) ((ActionStatement)tState.getEntryAction()).getStatement();
+		assertTrue(firstFromSequence(tState.getEntryAction()) instanceof Assign);
+		// assertTrue(firstFromSequence(tState.getDoAction()) instanceof Raise);
+		assertTrue(firstFromSequence(tState.getExitAction()) instanceof ProcedureCall);
+		
+		assertEquals(1, tState.getRegions().size());
+	}
+	
+	
+	
+	public void testTransition() {
+		statemachine.Event e1 = factory.createEvent();
+		e1.setName("e1");
+		sourceSC.getDataElement().add(e1);
+		
+		statemachine.Event e2 = factory.createEvent();
+		e2.setName("e2");
+		sourceSC.getDataElement().add(e2);
+		
+		statemachine.Region region = factory.createRegion();
+		region.setPriority(3);
+		sourceSC.getRegion().add(region);
+
+		statemachine.State state_a = factory.createState();
+		state_a.setId(1);
+		state_a.setName("a");
+		region.getState().add(state_a);
+		
+		statemachine.State state_b = factory.createState();
+		state_b.setId(2);
+		state_b.setName("b");
+		region.getState().add(state_b);
+		
+		statemachine.Transition trans = factory.createTransition();
+		trans.setSourceNode(state_a);
+		trans.setTargetNode(state_b);
+		trans.setId(1);
+		trans.setPriority(42);
+		trans.setExpression("e1,e2,after(200) [a] / a=false;");
+		
+		sourceSC.getTransition().add(trans);
+		
+		Statechart tSC = builder.build(sourceSC);
+		List<Region> regions = tSC.getRegions();
+		
+		assertEquals(1, regions.size());
+		assertEquals(2, regions.get(0).getNodes().size());
+		
+		// check if nodes and transition are properly connected...
+		Node node_a = (Node) tSC.getElementByAlias(state_a);
+		Node node_b = (Node) tSC.getElementByAlias(state_b);
+		
+		assertNotSame(node_a, node_b);
+		assertTrue(regions.get(0).getNodes().contains(node_a));
+		assertTrue(regions.get(0).getNodes().contains(node_b));
+		
+		assertEquals(1, node_a.getOutgoingTransitions().size());
+		assertEquals(1, node_b.getIncomingTransitions().size());
+		
+		assertSame(node_a.getOutgoingTransitions().get(0), node_b.getIncomingTransitions().get(0));
+		Transition tTrans = node_a.getOutgoingTransitions().get(0);
+		
+		assertSame(node_a, node_a.getOutgoingTransitions().get(0).getSourceNode());
+		assertSame(node_b, node_b.getIncomingTransitions().get(0).getTargetNode());
+		
+		
+		// check the properties of the transition
+		assertEquals(42, tTrans.getPriority());
+		assertEquals("t@1", tTrans.getId());
+		
+		assertNotNull(tTrans.getGuard());
+		// Unary expression because new grammar always put a VariableRef inside a positive unary expression
+		assertTrue(((GuardExpression)tTrans.getGuard()).getExpression() instanceof UnaryOperation);
+		assertTrue(((UnaryOperation)((GuardExpression)tTrans.getGuard()).getExpression()).getExpression() instanceof VariableRef);
+		
+		assertNotNull(tTrans.getAction());
+		assertTrue(((ActionStatement)tTrans.getAction()).getStatement() instanceof StatementSequence);
+
+		assertEquals(2, tTrans.getSignalTriggers().size());
+		assertTrue(tTrans.getSignalTriggers().contains(tSC.getSignalEvent("e1")));
+		assertTrue(tTrans.getSignalTriggers().contains(tSC.getSignalEvent("e2")));
+
+		assertNotNull(tTrans.getTimeTrigger());
+
+	}
+	
+	
+
+	private Statement firstFromSequence(Action action) {
+		return ((StatementSequence) ((ActionStatement)action).getStatement()).get(0);
+	}
+	
+	
+
+}

+ 35 - 0
test-plugins/org.yakindu.sct.simulation.runtime.test/src/org/yakindu/sct/simulation/runtime/sgraph/test/AllTests.java

@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) 2010 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.simulation.runtime.sgraph.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+@RunWith(value=Suite.class)
+@SuiteClasses(value={
+		ExpressionsTest.class, 
+		FunctionsTest.class,
+		CoreFunctionsTest.class
+		}) 
+*/
+public class AllTests extends TestSuite{
+	
+	public static Test suite() {
+		TestSuite suite = new AllTests();
+		suite.addTestSuite(StatechartTest.class);
+			
+		return suite;
+	}
+
+	
+
+}

+ 180 - 0
test-plugins/org.yakindu.sct.simulation.runtime.test/src/org/yakindu/sct/simulation/runtime/sgraph/test/StatechartTest.java

@@ -0,0 +1,180 @@
+/**
+ * Copyright (c) 2010 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.simulation.runtime.sgraph.test;
+
+import java.util.HashSet;
+
+import org.yakindu.sct.simulation.runtime.stext.Assign;
+import org.yakindu.sct.simulation.runtime.stext.Constant;
+import org.yakindu.sct.simulation.runtime.stext.Variable;
+import org.yakindu.sct.simulation.runtime.stext.VariableRef;
+import org.yakindu.sct.simulation.runtime.sgraph.ActionStatement;
+import org.yakindu.sct.simulation.runtime.sgraph.GuardExpression;
+import org.yakindu.sct.simulation.runtime.sgraph.Pseudostate;
+import org.yakindu.sct.simulation.runtime.sgraph.PseudostateKind;
+import org.yakindu.sct.simulation.runtime.sgraph.Region;
+import org.yakindu.sct.simulation.runtime.sgraph.SignalEvent;
+import org.yakindu.sct.simulation.runtime.sgraph.SimpleState;
+import org.yakindu.sct.simulation.runtime.sgraph.Statechart;
+import org.yakindu.sct.simulation.runtime.sgraph.Transition;
+
+import junit.framework.TestCase;
+
+public class StatechartTest extends TestCase {
+
+	
+	
+	private Region rootRegion;
+	protected Statechart statechart;
+	private Pseudostate initial;
+	private SimpleState state1;
+	private Transition trans;
+
+
+	/**
+	 * The setup creates a basic statechart that consists of a single root region, an initial state within this region, 
+	 * a simple state, and a transition from the initial state to the simple state. This statechart will be extended 
+	 * by the different test cases as appropriate.
+	 */
+	@Override
+	protected void setUp() throws Exception {
+		super.setUp();
+		statechart = new Statechart("SC");
+		rootRegion = new Region("r", 1, statechart);
+		initial = new Pseudostate("i", rootRegion, PseudostateKind.INITIAL);
+		state1 = new SimpleState("s1", "a", rootRegion, null, null, null);
+		trans = new Transition("t_i_s1", 1, null, null, null, null, initial, state1);
+	}
+
+
+	/**
+	 * The simple statechart as created by the setup must enter  {@link #state1}when the statechart is initially entered.
+	 * After a run cycle the current state must stioll be {@link #state1}. 
+	 */
+	public void testSimpleStatechart() {
+		
+		assertNull(rootRegion.getCurrentState());
+		
+		statechart.enter();		
+		assertEquals(state1, rootRegion.getCurrentState());
+
+		statechart.runCycle();
+		assertEquals(state1, rootRegion.getCurrentState());		
+	}
+
+	
+	/**
+	 * TODO: does not work currently. See bug #
+	 */
+	public void notestTransitionWithoutTrigger() {
+		
+		SimpleState state2 = new SimpleState("s2", "b", rootRegion, null, null, null);
+		new Transition("t_s1_s2", 1, null, null, null, null, state1, state2);
+		
+		assertNull(rootRegion.getCurrentState());
+		
+		statechart.enter();		
+		assertEquals(state1, rootRegion.getCurrentState());
+
+		statechart.runCycle();
+		assertEquals(state2, rootRegion.getCurrentState());		
+	}
+
+
+	/**
+	 * A transition with a trigger must only be taken if the event matches the signal event.
+	 */
+	public void testTransitionTrigger() {
+		
+		final SignalEvent event = new SignalEvent("event");
+		
+		SimpleState state2 = new SimpleState("s2", "b", rootRegion, null, null, null);
+		new Transition("t_s1_s2", 1, null, 
+				new HashSet<SignalEvent>(){{add(event);}}, 
+				null, null, state1, state2);
+		
+		assertNull(rootRegion.getCurrentState());
+		
+		statechart.enter();		
+		assertEquals(state1, rootRegion.getCurrentState());
+
+		statechart.runCycle();
+		assertEquals(state1, rootRegion.getCurrentState());		
+
+		statechart.setEvent(event);
+		statechart.runCycle();
+		assertEquals(state2, rootRegion.getCurrentState());		
+	}
+
+	
+	/**
+	 * Even if a transition trigger matches the transition will only be taken if an existing guard evaluates to true. 
+	 */
+	public void testTransitionWithTriggerAndGuard() {
+		
+		final SignalEvent event = new SignalEvent("event");
+		Variable var = new Variable("v");
+		statechart.addVariable(var);
+		
+		SimpleState state2 = new SimpleState("s2", "b", rootRegion, null, null, null);
+		new Transition("t_s1_s2", 1, null, 
+				new HashSet<SignalEvent>(){{add(event);}}, 
+				new GuardExpression(new VariableRef("v"), statechart), 
+				null, state1, state2);
+		
+		assertNull(rootRegion.getCurrentState());
+		
+		statechart.enter();		
+		assertEquals(state1, rootRegion.getCurrentState());
+
+		statechart.getVariable("v").setValue(false);
+		statechart.setEvent(event);
+		statechart.runCycle();
+		assertEquals(state1, rootRegion.getCurrentState());		
+
+		statechart.getVariable("v").setValue(true);
+		statechart.setEvent(event);
+		statechart.runCycle();
+		assertEquals(state2, rootRegion.getCurrentState());		
+	}
+	
+	
+	/**
+	 * When a transition is taken then the transition action must be performed.
+	 */
+	public void testTransitionWithAction() {
+		
+		final SignalEvent event = new SignalEvent("event");
+		Variable var = new Variable("v");
+		statechart.addVariable(var);
+		
+		SimpleState state2 = new SimpleState("s2", "b", rootRegion, null, null, null);
+		new Transition("t_s1_s2", 1, null, 
+				new HashSet<SignalEvent>(){{add(event);}}, 
+				null, 
+				new ActionStatement(new Assign(new VariableRef("v"), new Constant(42)), statechart), 
+				state1, state2);
+		
+		assertNull(rootRegion.getCurrentState());
+		
+		statechart.enter();		
+		assertEquals(state1, rootRegion.getCurrentState());
+
+		assertNull(statechart.getVariable("v").getValue());
+
+		statechart.setEvent(event);
+		statechart.runCycle();
+		assertEquals(state2, rootRegion.getCurrentState());		
+		assertEquals(42, statechart.getValue("v"));		
+	}
+	
+
+}

+ 34 - 0
test-plugins/org.yakindu.sct.simulation.runtime.test/src/org/yakindu/sct/simulation/runtime/stext/builder/test/AllTests.java

@@ -0,0 +1,34 @@
+/**
+ * Copyright (c) 2010 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.simulation.runtime.stext.builder.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+//import org.junit.runner.RunWith;
+//import org.junit.runners.Suite;
+//import org.junit.runners.Suite.SuiteClasses;
+
+/**
+@RunWith(value=Suite.class)
+@SuiteClasses(value={
+		BuilderTest.class
+		}) */
+public class AllTests extends TestSuite {
+	
+	public static Test suite() {
+		TestSuite suite = new AllTests();
+			suite.addTestSuite(BuilderTest.class);
+			
+		return suite;
+	}
+
+}

+ 864 - 0
test-plugins/org.yakindu.sct.simulation.runtime.test/src/org/yakindu/sct/simulation/runtime/stext/builder/test/BuilderTest.java

@@ -0,0 +1,864 @@
+/**
+ * Copyright (c) 2010 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.simulation.runtime.stext.builder.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.impl.DynamicEObjectImpl;
+import org.yakindu.sct.simulation.runtime.EvaluationException;
+import org.yakindu.sct.simulation.runtime.stext.Constant;
+import org.yakindu.sct.simulation.runtime.stext.Expression;
+import org.yakindu.sct.simulation.runtime.stext.Scope;
+import org.yakindu.sct.simulation.runtime.stext.Statement;
+import org.yakindu.sct.simulation.runtime.stext.StatementSequence;
+import org.yakindu.sct.simulation.runtime.stext.Trigger;
+import org.yakindu.sct.simulation.runtime.stext.Variable;
+import org.yakindu.sct.simulation.runtime.stext.VariableRef;
+import org.yakindu.sct.simulation.runtime.stext.builder.BuilderException;
+import org.yakindu.sct.simulation.runtime.stext.builder.ExpressionBuilder;
+
+
+/**
+ * @author terflothl@itemis.de
+ */
+public class BuilderTest extends TestCase {
+
+	static class TestScope extends Scope {
+
+		public List<String> trace = new ArrayList<String>();
+		public String called;
+		public String raised;
+		
+		@Override
+		public Variable getVariable(String varName) {
+			trace.add("var:" + varName);
+			return super.getVariable(varName);
+		}
+
+		@Override
+		public void call(String procedureId) {
+			trace.add("call:" + procedureId);
+			super.call(procedureId);
+			called = procedureId;
+		}
+
+		@Override
+		public void raise(String signal) {
+			trace.add("raise:" + signal);
+			super.raise(signal);
+			raised = signal;
+		}
+		
+		
+	}
+	
+	protected TestScope scope;
+	
+	
+	@Override
+	protected void setUp() throws Exception {
+		super.setUp();
+		scope = new TestScope();
+	}
+	
+	public void testEmptyExpression() {
+		Statement stmt = ExpressionBuilder.buildAction("");
+		assertNull(stmt);
+	}
+	
+
+	/**
+	 * TODO: check if IllegalArgumentException is the correct one
+	 */
+	public void testInvalidAction() {
+//		try {
+			Statement stmt = ExpressionBuilder.buildAction("1");
+			assertNull(stmt);
+//			fail("IllegalArgumentException expected !");
+//		} catch(IllegalArgumentException e) {}
+	}
+
+	
+	public void testRaise() {
+		Statement stmt = ExpressionBuilder.buildAction("raise abc;");
+		
+		assertNotNull(stmt);
+		assertTrue(stmt instanceof StatementSequence);
+		
+		assertEquals(1, ((StatementSequence)stmt).size());
+		
+		stmt.execute(scope);
+		assertEquals("abc", scope.raised);
+	}
+	
+	public void testProcedureCall() {
+		Statement stmt = ExpressionBuilder.buildAction("foo();");
+		
+		assertNotNull(stmt);
+		assertTrue(stmt instanceof StatementSequence);
+		
+		assertEquals(1, ((StatementSequence)stmt).size());
+		
+		stmt.execute(scope);
+		assertEquals("foo", scope.called);
+	}
+	
+	public void testMultiStatement() {
+		Statement stmt = ExpressionBuilder.buildAction("raise(abc);foo();");
+		
+		assertNotNull(stmt);
+		assertTrue(stmt instanceof StatementSequence);
+		
+		assertEquals(2, ((StatementSequence)stmt).size());
+		
+		stmt.execute(scope);
+		assertEquals("abc", scope.raised);
+		assertEquals("foo", scope.called);
+	}
+
+	public void testIntVariableAssignment() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 42;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(42, scope.getValue("a"));
+	}
+
+	public void testHexVariableAssignment() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 0xFF;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(0xFF, scope.getValue("a"));
+	}
+	
+	public void testBoolTrueVariableAssignment() {
+		Statement stmt = ExpressionBuilder.buildAction("a = true;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(true, scope.getValue("a"));
+	}
+
+	public void testBoolFalseVariableAssignment() {
+		Statement stmt = ExpressionBuilder.buildAction("a = false;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(false, scope.getValue("a"));
+	}
+	
+	public void testFloatVariableAssignment() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 42.0;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(42.0f, scope.getValue("a"));
+	}
+	
+	public void testStringVariableAssignment() {
+		Statement stmt = ExpressionBuilder.buildAction("a = \"fortytwo\";");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals("fortytwo", scope.getValue("a"));
+	}
+	
+	public void testIntStringVariableAssignment() {
+		Statement stmt = ExpressionBuilder.buildAction("a = \"42\";");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals("42", scope.getValue("a"));
+	}
+	
+	public void testConditioanlTrue() {
+		Statement stmt = ExpressionBuilder.buildAction("a = true ? 42 : 1;");
+		assertNotNull(stmt);
+		
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(42, scope.getValue("a"));	
+	}
+	
+	public void testConditioanlFalse() {
+		Statement stmt = ExpressionBuilder.buildAction("a = false ? 42 : 1;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(1, scope.getValue("a"));	
+	}
+	
+	public void testBooleanOr() {
+		Statement stmt = ExpressionBuilder.buildAction("a = true || false;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(true, scope.getValue("a"));	
+	}
+	
+	public void testBooleanAnd() {
+		Statement stmt = ExpressionBuilder.buildAction("a = true && false;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(false, scope.getValue("a"));	
+	}
+		
+	public void testBitwiseXor() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 0xF0F0 ^ 0xFF00;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(0x0FF0, scope.getValue("a"));	
+	}
+	
+	public void testBitwiseOr() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 0xF0F0 | 0xFFFF;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(0xFFFF, scope.getValue("a"));	
+	}
+	
+	public void testBitwiseAnd() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 0xF0F0 & 0xFFFF;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(0x0F0F0, scope.getValue("a"));	
+	}
+	
+	public void testBoolEqual() {
+		Statement stmt = ExpressionBuilder.buildAction("a = false == false;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(true, scope.getValue("a"));	
+	}
+	
+	public void testIntEqual() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 1 == 1;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(true, scope.getValue("a"));	
+	}
+	
+	public void testFloatEqual() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 1.0f == 1.0f;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(true, scope.getValue("a"));	
+	}
+	
+
+	
+	public void testBoolNotEqual() {
+		Statement stmt = ExpressionBuilder.buildAction("a = true != false;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(true, scope.getValue("a"));	
+	}
+	
+	public void testIntNotEqual() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 1 != 2;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(true, scope.getValue("a"));	
+	}
+	
+	public void testFloatNotEqual() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 1.0f != 2.0f;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(true, scope.getValue("a"));	
+	}
+	
+	
+
+	public void testIntGreaterEqual() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 2 >= 1;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(true, scope.getValue("a"));	
+	}
+	
+	public void testFloatGreaterEqual() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 2.0f >= 2.0f;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(true, scope.getValue("a"));	
+	}
+	
+	
+	public void testIntSmallerEqual() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 1 <= 2;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(true, scope.getValue("a"));	
+	}
+	
+	public void testFloatSmallerEqual() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 2.0f <= 2.0f;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(true, scope.getValue("a"));	
+	}
+	
+	
+	public void testIntGreater() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 2 > 1;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(true, scope.getValue("a"));	
+	}
+	
+	public void testFloatGreater() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 2.1f > 2.0f;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(true, scope.getValue("a"));	
+	}
+	
+	
+	public void testIntSmaller() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 1 < 2;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(true, scope.getValue("a"));	
+	}
+	
+	public void testFloatSmaller() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 2.0f < 2.1f;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(true, scope.getValue("a"));	
+	}
+	
+	
+	
+	public void testIntPositive() {
+		Statement stmt = ExpressionBuilder.buildAction("a = +1;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(1, scope.getValue("a"));
+	}
+	
+	public void testFloatPositive() {
+		Statement stmt = ExpressionBuilder.buildAction("a = +1.0;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(1.0f, scope.getValue("a"));
+	}
+	
+
+	public void testIntNegative() {
+		Statement stmt = ExpressionBuilder.buildAction("a = -1;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(-1, scope.getValue("a"));
+	}
+	
+	public void testFloatNegative() {
+		Statement stmt = ExpressionBuilder.buildAction("a = - 1.0f ;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(-1.0f, scope.getValue("a"));
+	}
+	
+	public void testIntPlus() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 42 + 1;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(43, scope.getValue("a"));
+	}
+	
+	public void testFloatPlus() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 42.0 + 1.0;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(43.0f, scope.getValue("a"));
+	}
+	
+	public void testIntMinus() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 42 - 1;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(41, scope.getValue("a"));
+	}
+	
+	public void testFloatMinus() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 42.0f - 1.0f;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(41.0f, scope.getValue("a"));
+	}
+
+	public void testIntMultiply() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 42 * 2;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(84, scope.getValue("a"));
+	}
+	
+	public void testFloatMultiply() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 42.0f * 2.0f;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(84.0f, scope.getValue("a"));
+	}
+	
+	public void testIntDivide() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 42 / 2;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(21, scope.getValue("a"));
+	}
+	
+	public void testFloatDivide() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 42.0f / 2.0f;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(21.0f, scope.getValue("a"));
+	}
+	
+	public void testIntModulo() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 42 % 2;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(0, scope.getValue("a"));
+	}
+	
+	public void testFloatModulo() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 42.0f % 2.0f;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(0.0f, scope.getValue("a"));
+	}
+	
+	public void testIntLeft() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 42 << 2;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(168, scope.getValue("a"));
+	}
+	
+	public void testFloatLeft() {
+		try {
+			Statement stmt = ExpressionBuilder.buildAction("a = 42.0f << 2.0f;");
+			scope.addVariable(new Variable("a"));
+			stmt.execute(scope);
+
+			assertEquals(168, scope.getValue("a"));
+			fail("EvaluationException expected");
+		} catch (EvaluationException e) {}
+	}
+	
+	public void testIntRight() {
+		Statement stmt = ExpressionBuilder.buildAction("a = 42 >> 2;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(10, scope.getValue("a"));
+	}
+	
+	public void testFloatRight() {
+		try {
+			Statement stmt = ExpressionBuilder.buildAction("a = 42.0f >> 2.0f;");
+			scope.addVariable(new Variable("a"));
+			stmt.execute(scope);
+	
+			assertEquals(168, scope.getValue("a"));
+			fail("EvaluationException expected");
+		} catch (EvaluationException e) {}
+	}
+	
+	public void testIntAnd() {
+		Statement stmt = ExpressionBuilder.buildAction("a= 9 & 12;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+	
+		assertEquals(8, scope.getValue("a"));
+	}
+	
+	public void testFloatAnd() {
+		try {
+			Statement stmt = ExpressionBuilder.buildAction("a= 9.0f & 12.0f;");
+			scope.addVariable(new Variable("a"));
+			stmt.execute(scope);
+		
+			assertEquals(8.0f, scope.getValue("a"));
+			fail("EvaluationException expected");
+		} catch (EvaluationException e) {}
+	}
+	
+	public void testIntXor() {
+		Statement stmt = ExpressionBuilder.buildAction("a= 9 ^ 12;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+	
+		assertEquals(5, scope.getValue("a"));
+	}
+	
+	public void testFloatXor() {
+		try {
+			Statement stmt = ExpressionBuilder.buildAction("a= 9.0f ^ 12.0f;");
+			scope.addVariable(new Variable("a"));
+			stmt.execute(scope);
+		
+			assertEquals(5.0f, scope.getValue("a"));
+			fail("EvaluationException expected");
+		} catch (EvaluationException e) {}
+	}
+	
+	public void testIntOr() {
+		Statement stmt = ExpressionBuilder.buildAction("a= 9 | 12;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+		
+		assertEquals(13, scope.getValue("a"));
+	}	
+	
+	public void testFloatOr() {
+		try {
+			Statement stmt = ExpressionBuilder.buildAction("a= 9.0f | 12.0f;");
+			scope.addVariable(new Variable("a"));
+			stmt.execute(scope);
+		
+			assertEquals(13.0f, scope.getValue("a"));
+			fail("EvaluationException expected");
+		} catch (EvaluationException e) {}
+	}	
+	
+	public void testIntBitComplement() {
+		Statement stmt = ExpressionBuilder.buildAction("a= ~9;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+		
+		assertEquals(-10, scope.getValue("a"));
+	}	
+	
+	public void testFloatBitComplement() {
+		try {
+			Statement stmt = ExpressionBuilder.buildAction("a= ~9.0f;");
+			scope.addVariable(new Variable("a"));
+			stmt.execute(scope);
+		
+			assertEquals(-10.0f, scope.getValue("a"));
+			fail("EvaluationException expected");
+		} catch (EvaluationException e) {}
+	}	
+	
+	public void testNot() {
+		Statement stmt = ExpressionBuilder.buildAction("a = ! true;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(false, scope.getValue("a"));
+	}
+
+	public void testPrirority() {		
+		Statement stmt = ExpressionBuilder.buildAction("a = 1 + 2 * 3;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(7, scope.getValue("a"));
+	}
+	
+	public void testNested() {		
+		Statement stmt = ExpressionBuilder.buildAction("a = (1 + 2) * 3;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(9, scope.getValue("a"));
+	}
+	
+	public void testIntPlusAssign() {
+		Statement stmt = ExpressionBuilder.buildAction("a=42; a+=42;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(84, scope.getValue("a"));
+	}
+	
+	public void testFloatPlusAssign() {
+		Statement stmt = ExpressionBuilder.buildAction("a=42.0; a+=42.0;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(84.0f, scope.getValue("a"));
+	}
+
+	public void testIntMinusAssign() {
+		Statement stmt = ExpressionBuilder.buildAction("a=42; a-=10;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(32, scope.getValue("a"));
+	}
+	
+	public void testFloatMinusAssign() {
+		Statement stmt = ExpressionBuilder.buildAction("a=42.0; a-=10.0;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(32.0f, scope.getValue("a"));
+	}
+	
+	public void testIntMultAssign() {
+		Statement stmt = ExpressionBuilder.buildAction("a=42; a*=1;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(42, scope.getValue("a"));
+	}
+	
+	public void testFloatMultAssign() {
+		Statement stmt = ExpressionBuilder.buildAction("a=42.0; a*=1.0;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(42.0f, scope.getValue("a"));
+	}
+	
+	public void testIntDivAssign() {
+		Statement stmt = ExpressionBuilder.buildAction("a=42; a/=1;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(42, scope.getValue("a"));
+	}
+		
+	public void testFloatDivAssign() {
+		Statement stmt = ExpressionBuilder.buildAction("a=42.0; a/=1.0;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(42.0f, scope.getValue("a"));
+	}
+	
+	public void testIntModAssign() {
+		Statement stmt = ExpressionBuilder.buildAction("a=42; a%=1;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(0, scope.getValue("a"));
+	}
+		
+	public void testFloatModAssign() {
+		Statement stmt = ExpressionBuilder.buildAction("a=42.0; a%=1.0;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+
+		assertEquals(0.0f, scope.getValue("a"));
+	}
+	
+	public void testIntLeftAssign() {
+		Statement stmt = ExpressionBuilder.buildAction("a=42; a<<=1;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+	
+		assertEquals(84, scope.getValue("a"));
+	}
+	
+	public void testFloatLeftAssign() {
+		try {
+			Statement stmt = ExpressionBuilder.buildAction("a=42.0f; a<<=1.0f;");
+			scope.addVariable(new Variable("a"));
+			stmt.execute(scope);
+
+			assertEquals(168, scope.getValue("a"));
+			fail("EvaluationException expected");
+		} catch (EvaluationException e) {}
+	}
+	
+	public void testIntRightAssign() {
+		Statement stmt = ExpressionBuilder.buildAction("a=42; a>>=1;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+	
+		assertEquals(21, scope.getValue("a"));
+	}
+	
+	public void testFloatRightAssign() {
+		try {
+			Statement stmt = ExpressionBuilder.buildAction("a=42.0f; a>>=1.0f;");
+			scope.addVariable(new Variable("a"));
+			stmt.execute(scope);
+
+			assertEquals(168, scope.getValue("a"));
+			fail("EvaluationException expected");
+		} catch (EvaluationException e) {}
+	}
+	
+	public void testIntAndAssign() {
+		Statement stmt = ExpressionBuilder.buildAction("a=9; a&=12;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+	
+		assertEquals(8, scope.getValue("a"));
+	}
+	
+	public void testFloatAndAssign() {
+		try {
+			Statement stmt = ExpressionBuilder.buildAction("a=42.0f; a&=1.0f;");
+			scope.addVariable(new Variable("a"));
+			stmt.execute(scope);
+
+			assertEquals(168, scope.getValue("a"));
+			fail("EvaluationException expected");
+		} catch (EvaluationException e) {}
+	}
+	
+	public void testIntXorAssign() {
+		Statement stmt = ExpressionBuilder.buildAction("a=9; a^=12;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+	
+		assertEquals(5, scope.getValue("a"));
+	}
+	
+	public void testFloatXorAssign() {
+		try {
+			Statement stmt = ExpressionBuilder.buildAction("a=42.0f; a^=1.0f;");
+			scope.addVariable(new Variable("a"));
+			stmt.execute(scope);
+
+			assertEquals(168, scope.getValue("a"));
+			fail("EvaluationException expected");
+		} catch (EvaluationException e) {}
+	}
+	
+	public void testIntOrAssign() {
+		Statement stmt = ExpressionBuilder.buildAction("a=9; a|=12;");
+		scope.addVariable(new Variable("a"));
+		stmt.execute(scope);
+	
+		assertEquals(13, scope.getValue("a"));
+	}	
+	
+	public void testFloatOrAssign() {
+		try {
+			Statement stmt = ExpressionBuilder.buildAction("a=42.0f; a|=1.0f;");
+			scope.addVariable(new Variable("a"));
+			stmt.execute(scope);
+
+			assertEquals(168, scope.getValue("a"));
+			fail("EvaluationException expected");
+		} catch (EvaluationException e) {}
+	}
+	
+	
+		
+	/** If there is no builder method for the eClass of an EObject then a BuilderException must be raised.
+	 */
+	public void testBuildFromUnknownEClass() {
+		
+		class TestBuilder extends ExpressionBuilder {
+			public Object testBuild(EObject obj) {
+				return build(obj);
+			}
+		};
+		
+		EClass eClass = EcoreFactory.eINSTANCE.createEClass();
+		eClass.setName("Bla");
+		
+		DynamicEObjectImpl eObj = new DynamicEObjectImpl(eClass);
+		
+		TestBuilder builder = new TestBuilder();
+		
+		try {
+			builder.testBuild(eObj);
+			
+			fail("BuilderException expected!");
+		} catch (BuilderException e) {}
+	}
+	
+	
+	
+	public void testSimpleGuardExpression() {
+		Expression expr = ExpressionBuilder.buildGuard("true");
+		assertEquals(true, expr.execute(scope));
+	}
+
+	
+	public void testGuardExpression() {
+		Expression expr = ExpressionBuilder.buildGuard("(a % 3) != 0");
+		scope.addVariable(new Variable("a"));
+		
+		scope.getVariable("a").setValue(1);
+		assertEquals(true, expr.execute(scope));
+
+		scope.getVariable("a").setValue(3);
+		assertEquals(false, expr.execute(scope));
+	}
+	
+	
+	public void testTriggerExpression() {
+		List<Trigger> triggers = ExpressionBuilder.buildTriggers("e1, after(100), e2");
+		
+		assertEquals(3, triggers.size());
+		
+		assertTrue(triggers.get(0) instanceof Trigger.SignalEvent);
+		assertEquals("e1", ((Trigger.SignalEvent)triggers.get(0)).getSignal());
+		
+		assertTrue(triggers.get(1) instanceof Trigger.TimeEvent);
+		assertTrue(((Trigger.TimeEvent)triggers.get(1)).getDurationExp() instanceof Constant);
+
+		assertEquals("e2", ((Trigger.SignalEvent)triggers.get(2)).getSignal());
+		assertTrue(triggers.get(2) instanceof Trigger.SignalEvent);
+	}
+
+	
+	public void testTimeTrigger() {
+		List<Trigger> triggers = ExpressionBuilder.buildTriggers("after(x)");
+		
+		assertEquals(1, triggers.size());
+		
+		assertTrue(triggers.get(0) instanceof Trigger.TimeEvent);
+		assertTrue(((Trigger.TimeEvent)triggers.get(0)).getDurationExp() instanceof VariableRef);
+	}
+}

+ 37 - 0
test-plugins/org.yakindu.sct.simulation.runtime.test/src/org/yakindu/sct/simulation/runtime/stext/test/AllTests.java

@@ -0,0 +1,37 @@
+/**
+ * Copyright (c) 2010 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.simulation.runtime.stext.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+@RunWith(value=Suite.class)
+@SuiteClasses(value={
+		ExpressionsTest.class, 
+		FunctionsTest.class,
+		CoreFunctionsTest.class
+		}) 
+*/
+public class AllTests extends TestSuite{
+	
+	public static Test suite() {
+		TestSuite suite = new AllTests();
+		suite.addTestSuite(ExpressionsTest.class);
+		suite.addTestSuite(FunctionsTest.class);
+		suite.addTestSuite(CoreFunctionsTest.class);
+			
+		return suite;
+	}
+
+	
+
+}

+ 365 - 0
test-plugins/org.yakindu.sct.simulation.runtime.test/src/org/yakindu/sct/simulation/runtime/stext/test/CoreFunctionsTest.java

@@ -0,0 +1,365 @@
+/**
+ * Copyright (c) 2010 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.simulation.runtime.stext.test;
+
+
+import junit.framework.TestCase;
+
+import org.yakindu.sct.simulation.runtime.stext.CoreFunction;
+import org.yakindu.sct.simulation.runtime.EvaluationException;
+import org.yakindu.sct.simulation.runtime.stext.Function;
+
+public class CoreFunctionsTest extends TestCase {
+	
+	public void testIntPlus() {
+		Object params[] = new Object[]{3, 2};
+		
+		Object result = Function.lookup(CoreFunction.class, "+", params).execute(params);
+		assertEquals(5, result);
+	}
+	
+	public void testFloatPlus() {
+		Object params[] = new Object[]{3.0f, 2.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "+", params).execute(params);
+		assertEquals(5.0f, result);
+	}
+	
+	public void testIntMin() {
+		Object params[] = new Object[]{3, 2};
+		
+		Object result = Function.lookup(CoreFunction.class, "-", params).execute(params);
+		assertEquals(1, result);
+	}
+	
+	public void testFloatMin() {
+		Object params[] = new Object[]{3.0f, 2.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "-", params).execute(params);
+		assertEquals(1.0f, result);
+	}
+	
+	public void testIntMul() {
+		Object params[] = new Object[]{3, 2};
+		
+		Object result = Function.lookup(CoreFunction.class, "*", params).execute(params);
+		assertEquals(6, result);
+	}
+	
+	public void testIntMulNegative() {
+		Object params[] = new Object[]{-3, -2};
+		
+		Object result = Function.lookup(CoreFunction.class, "*", params).execute(params);
+		assertEquals(6, result);
+	}
+	
+	public void testIntMulPositiveNegative() {
+		Object params[] = new Object[]{3, -2};
+		
+		Object result = Function.lookup(CoreFunction.class, "*", params).execute(params);
+		assertEquals(-6, result);
+	}
+	
+	public void testFloatMul() {
+		Object params[] = new Object[]{3.0f, 2.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "*", params).execute(params);
+		assertEquals(6.0f, result);
+	}
+	
+	public void testFloatMulNegative() {
+		Object params[] = new Object[]{-3.0f, -2.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "*", params).execute(params);
+		assertEquals(6.0f, result);
+	}
+	
+	public void testFloatMulPositiveNegative() {
+		Object params[] = new Object[]{-3.0f, 2.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "*", params).execute(params);
+		assertEquals(-6.0f, result);
+	}
+	
+	public void testIntDiv() {
+		Object params[] = new Object[]{6, 2};
+		
+		Object result = Function.lookup(CoreFunction.class, "/", params).execute(params);
+		assertEquals(3, result);
+	}
+	
+	public void testIntDivNotPerfect() {
+		Object params[] = new Object[]{7, 2};
+		
+		Object result = Function.lookup(CoreFunction.class, "/", params).execute(params);
+		assertEquals(3, result);
+	}
+	
+	public void testIntDivNegative() {
+		Object params[] = new Object[]{-6, -2};
+		
+		Object result = Function.lookup(CoreFunction.class, "/", params).execute(params);
+		assertEquals(3, result);
+	}
+	
+	public void testIntDivPositiveNegative() {
+		Object params[] = new Object[]{6, -2};
+		
+		Object result = Function.lookup(CoreFunction.class, "/", params).execute(params);
+		assertEquals(-3, result);
+	}
+		
+	public void testIntDivByZero() {
+		try {
+			Object params[] = new Object[]{3, 0};
+		
+			Object result = Function.lookup(CoreFunction.class, "/", params).execute(params);
+			assertEquals(6, result);
+			fail("EvaluationException expected");
+		} catch (EvaluationException e) {}
+	}
+	
+	public void testFloatDiv() {
+		Object params[] = new Object[]{6.0f, 2.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "/", params).execute(params);
+		assertEquals(3.0f, result);
+	}
+	
+	public void testFloatDivNotPerfect() {
+		Object params[] = new Object[]{7.0f, 2.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "/", params).execute(params);
+		assertEquals(3.5f, result);
+	}
+	
+	public void testFloatDivNegative() {
+		Object params[] = new Object[]{-6.0f, -2.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "/", params).execute(params);
+		assertEquals(3.0f, result);
+	}
+	
+	public void testFloatDivPositiveNegative() {
+		Object params[] = new Object[]{-6.0f, 2.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "/", params).execute(params);
+		assertEquals(-3.0f, result);
+	}
+	
+	public void testFloatDivByZero() {
+		Object params[] = new Object[]{6.0f, 0.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "/", params).execute(params);
+		assertEquals(Float.POSITIVE_INFINITY, result);
+	}
+	
+	public void testIntModulo() {
+		Object params[] = new Object[]{42, 2};
+		
+		Object result = Function.lookup(CoreFunction.class, "%", params).execute(params);
+		assertEquals(0, result);
+	}
+	
+	public void testIntModuloNotPerfect() {
+		Object params[] = new Object[]{42, 5};
+		
+		Object result = Function.lookup(CoreFunction.class, "%", params).execute(params);
+		assertEquals(2, result);
+	}
+	
+	public void testFloatModulo() {
+		Object params[] = new Object[]{42.0f, 2.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "%", params).execute(params);
+		assertEquals(0.0f, result);
+	}
+	
+	public void testFloatModuloNotPerfect() {
+		Object params[] = new Object[]{42.0f, 5.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "%", params).execute(params);
+		assertEquals(2.0f, result);
+	}
+	
+	
+	public void testIntLeft() {
+		Object params[] = new Object[]{42, 2};
+		
+		Object result = Function.lookup(CoreFunction.class, "<<", params).execute(params);
+		assertEquals(168, result);
+	}
+	
+	public void testFloatLeft() {
+		Object params[] = new Object[]{42.0f, 2.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "<<", params);
+		assertNull(result);			
+	}
+	
+	public void testIntRight() {
+		Object params[] = new Object[]{42, 2};
+		
+		Object result = Function.lookup(CoreFunction.class, ">>", params).execute(params);
+		assertEquals(10, result);
+	}
+	
+	public void testIntRightNull() {
+		Object params[] = new Object[]{42, 7};
+		
+		Object result = Function.lookup(CoreFunction.class, ">>", params).execute(params);
+		assertEquals(0, result);
+	}
+	
+	public void testFloatRight() {
+		Object params[] = new Object[]{42.0f, 2.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "<<", params);
+		assertNull(result);			
+	}
+	
+	public void testIntAnd() {
+		Object params[] = new Object[]{3, 2};
+		
+		Object result = Function.lookup(CoreFunction.class, "&", params).execute(params);
+		assertEquals(2, result);
+	}
+	
+	public void testFloatAnd() {
+		Object params[] = new Object[]{3.0f, 2.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "&", params);
+		assertNull(result);
+	}
+	
+	public void testIntOr() {
+		Object params[] = new Object[]{3, 2};
+		
+		Object result = Function.lookup(CoreFunction.class, "|", params).execute(params);
+		assertEquals(3, result);
+	}
+	
+	public void testFloatOr() {
+		Object params[] = new Object[]{3.0f, 2.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "|", params);
+		assertNull(result);
+	}
+	
+	public void testIntXor() {
+		Object params[] = new Object[]{3, 2};
+		
+		Object result = Function.lookup(CoreFunction.class, "^", params).execute(params);
+		assertEquals(1, result);
+	}
+	
+	public void testLongXor() {
+		Long l1 = new Long(3);
+		Long l2 = new Long(2);
+		Long l3 = new Long(1);
+		
+		Object params[] = new Object[]{l1, l2};
+		
+		Object result = Function.lookup(CoreFunction.class, "^", params).execute(params);
+		assertEquals(l3, result);
+	}
+	
+	public void testFloatXor() {
+		Object params[] = new Object[]{3.0f, 2.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "^", params);
+		assertNull(result);
+	}
+	
+	public void testIntEquals() {
+		Object params[] = new Object[]{3, 3};
+		
+		Object result = Function.lookup(CoreFunction.class, "==", params).execute(params);
+		assertEquals(true, result);
+	}
+	
+	public void testIntNotEquals() {
+		Object params[] = new Object[]{3, 2};
+		
+		Object result = Function.lookup(CoreFunction.class, "==", params).execute(params);
+		assertEquals(false, result);
+	}
+	
+	public void testFloatEquals() {
+		Object params[] = new Object[]{3.0f, 3.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "==", params).execute(params);
+		assertEquals(true, result);
+	}
+	
+	public void testFloatNotEquals() {
+		Object params[] = new Object[]{3.0f, 2.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "==", params).execute(params);
+		assertEquals(false, result);
+	}
+	
+	public void testIntDifferent() {
+		Object params[] = new Object[]{3, 2};
+		
+		Object result = Function.lookup(CoreFunction.class, "!=", params).execute(params);
+		assertEquals(true, result);
+	}
+	
+	public void testIntNotDifferent() {
+		Object params[] = new Object[]{3, 3};
+		
+		Object result = Function.lookup(CoreFunction.class, "!=", params).execute(params);
+		assertEquals(false, result);
+	}
+	
+	public void testFloatDifferent() {
+		Object params[] = new Object[]{3.0f, 2.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "!=", params).execute(params);
+		assertEquals(true, result);
+	}
+	
+	public void testFloatNotDifferent() {
+		Object params[] = new Object[]{3.0f, 3.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "!=", params).execute(params);
+		assertEquals(false, result);
+	}
+	
+	public void testIntBitComplement() {
+		Object params[] = new Object[]{9};
+		
+		Object result = Function.lookup(CoreFunction.class, "~", params).execute(params);
+		assertEquals(-10, result);
+	}	
+	
+	public void testFloatBitComplement() {
+		Object params[] = new Object[]{9.0f};
+		
+		Object result = Function.lookup(CoreFunction.class, "~", params);
+		assertNull(result);
+	}	
+	
+	public void testNotTrue() {
+		Object params[] = new Object[]{true};
+		
+		Object result = Function.lookup(CoreFunction.class, "!", params).execute(params);
+		assertEquals(false, result);
+	}
+	
+	public void testNotFalse() {
+		Object params[] = new Object[]{false};
+		
+		Object result = Function.lookup(CoreFunction.class, "!", params).execute(params);
+		assertEquals(true, result);
+	}
+}

+ 373 - 0
test-plugins/org.yakindu.sct.simulation.runtime.test/src/org/yakindu/sct/simulation/runtime/stext/test/ExpressionsTest.java

@@ -0,0 +1,373 @@
+/**
+ * Copyright (c) 2010 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.simulation.runtime.stext.test;
+
+import static org.yakindu.sct.simulation.runtime.stext.CoreFunction.BIT_AND;
+import static org.yakindu.sct.simulation.runtime.stext.CoreFunction.BIT_COMPLEMENT;
+import static org.yakindu.sct.simulation.runtime.stext.CoreFunction.BIT_OR;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.yakindu.sct.simulation.runtime.EvaluationException;
+import org.yakindu.sct.simulation.runtime.stext.Assert;
+import org.yakindu.sct.simulation.runtime.stext.Assign;
+import org.yakindu.sct.simulation.runtime.stext.BinaryOperation;
+import org.yakindu.sct.simulation.runtime.stext.Conditional;
+import org.yakindu.sct.simulation.runtime.stext.Constant;
+import org.yakindu.sct.simulation.runtime.stext.Expression;
+import org.yakindu.sct.simulation.runtime.stext.ProcedureCall;
+import org.yakindu.sct.simulation.runtime.stext.Raise;
+import org.yakindu.sct.simulation.runtime.stext.Scope;
+import org.yakindu.sct.simulation.runtime.stext.Statement;
+import org.yakindu.sct.simulation.runtime.stext.StatementSequence;
+import org.yakindu.sct.simulation.runtime.stext.UnaryOperation;
+import org.yakindu.sct.simulation.runtime.stext.Variable;
+import org.yakindu.sct.simulation.runtime.stext.VariableRef;
+
+public class ExpressionsTest extends TestCase {
+
+	static class TestScope extends Scope {
+
+		public List<String> trace = new ArrayList<String>();
+		public String called;
+		public String raised;
+		
+		@Override
+		public Variable getVariable(String varName) {
+			trace.add("var:" + varName);
+			return super.getVariable(varName);
+		}
+
+		@Override
+		public void call(String procedureId) {
+			trace.add("call:" + procedureId);
+			super.call(procedureId);
+			called = procedureId;
+		}
+
+		@Override
+		public void raise(String signal) {
+			trace.add("raise:" + signal);
+			super.raise(signal);
+			raised = signal;
+		}
+		
+		
+	}
+	
+	protected TestScope scope;
+	
+	@Override
+	protected void setUp() throws Exception {
+		super.setUp();
+		scope = new TestScope();
+	}
+
+	
+	public void testScopeVarAccess() {
+
+		assertNull(scope.getVariable("a"));
+		assertNull(scope.getValue("a"));
+		
+		scope.addVariable(new Variable("a"));
+		assertNotNull(scope.getVariable("a"));
+		scope.getVariable("a").setValue(42);
+		assertEquals(42, scope.getValue("a"));
+	}
+	
+	/** 
+	 * The initial value of a variable must be null
+	 */
+	public void testInitialVariableValue() {
+		assertNull( (new Variable("b")).getValue() );
+	}
+	
+	
+	/** 
+	 * A procedure call must be delegated to the scope instance.
+	 */
+	public void testProcedureCall() {
+		Statement stmt = new ProcedureCall("do");
+		
+		stmt.execute(scope);
+		assertEquals("do", scope.called);
+	}
+	
+
+	/** 
+	 * A signal raise must be delegated to the scope instance.
+	 */
+	public void testRaise() {
+		Statement stmt = new Raise("signal");
+		
+		stmt.execute(scope);
+		assertEquals("signal", scope.raised);
+	}
+	
+	
+
+	/**
+	 * An assignment must change a variable value
+	 */
+	public void testAssignConstant() {
+		scope.addVariable(new Variable("a"));
+		
+		Statement stmt = new Assign(new VariableRef("a"), new Constant(1));
+		
+		// stmt = ASSIGN(VAR("a"), CONST(1));
+		
+		stmt.execute(scope);
+		assertEquals(scope.getValue("a"), new Integer(1));
+	}
+
+	
+	/**
+	 * An assignment must change a variable value
+	 */
+	public void testAssignFromVar() {
+		scope.addVariable(new Variable("a"));
+		scope.addVariable(new Variable("b"));
+		scope.getVariable("a").setName(getName());
+		
+		Statement stmt = new Assign(new VariableRef("b"), new VariableRef("a"));
+		
+		stmt.execute(scope);
+		assertEquals(scope.getValue("a"), scope.getValue("b"));
+	}
+
+	
+	
+	/** 
+	 * A statement sequence must execute all containing statements in the defined order. 
+	 */
+	public void testStatementSequence() {
+		scope.addVariable(new Variable("a"));
+
+		StatementSequence seq = new StatementSequence();
+		seq.add( new Raise("signal"));
+		seq.add( new ProcedureCall("proc"));
+		seq.add( new Assign(new VariableRef("a"), new Constant(1)) );
+		
+		seq.execute(scope);
+		
+		assertEquals(3, scope.trace.size());
+		assertEquals("raise:signal", scope.trace.get(0));
+		assertEquals("call:proc", scope.trace.get(1));
+		assertEquals("var:a", scope.trace.get(2));
+	}
+	
+	
+	/** 
+	 * An empty statement sequence must have no side effects. 
+	 */
+	public void testEmptyStatementSequence() {
+		scope.addVariable(new Variable("a"));
+
+		StatementSequence seq = new StatementSequence();
+		
+		seq.execute(scope);
+		
+		assertEquals(0, scope.trace.size());
+	}
+	
+
+	/**
+	 * The execution of a constant must return the constant value.
+	 */
+	public void testConstant() {
+
+		Expression exp = new Constant(getName());
+		assertEquals(getName(), exp.execute(scope));
+	}
+
+	
+	/**
+	 * The execution of a variable ref as expression must return the variable value.
+	 */
+	public void testVariableRef() {
+		scope.addVariable(new Variable("x"));
+		scope.getVariable("x").setValue(getName());
+		
+		Expression exp = new VariableRef("x");
+		assertEquals(getName(), exp.execute(scope));
+	}
+
+	
+	/**
+	 * A conditional expression must return the first value if the condition is true.
+	 */
+	public void testConditionalTrue() {
+		
+		Expression exp = new Conditional(
+				new Constant(true),
+				new Constant("true"),
+				new Constant("false"));
+		
+		assertEquals("true", exp.execute(scope));
+	}
+	
+	
+	/**
+	 * A conditional expression must return the second value if the condition is true.
+	 */
+	public void testConditionalFalse() {
+		
+		Expression exp = new Conditional(
+				new Constant(false),
+				new Constant("true"),
+				new Constant("false"));
+		
+		assertEquals("false", exp.execute(scope));
+	}
+	
+
+	
+	public void testBooleanOr() {
+		Expression exp = 
+			new BinaryOperation(BinaryOperation.OR, 
+				new Constant(true), 
+				new Constant(true));	
+		assertTrue(Assert.filterBoolean(exp.execute(scope)));
+		
+		exp = new BinaryOperation(BinaryOperation.OR, 
+				new Constant(false), 
+				new Constant(true));	
+		assertTrue(Assert.filterBoolean(exp.execute(scope)));
+		
+		exp = new BinaryOperation(BinaryOperation.OR, 
+				new Constant(true), 
+				new Constant(false));	
+		assertTrue(Assert.filterBoolean(exp.execute(scope)));
+			
+		exp = new BinaryOperation(BinaryOperation.OR, 
+				new Constant(false), 
+				new Constant(false));	
+		assertFalse(Assert.filterBoolean(exp.execute(scope)));
+	}
+
+	
+	public void testBooleanOrWithNonBooleanValue() {
+		
+		try {
+			Expression exp = new BinaryOperation(BinaryOperation.OR, 
+					new Constant("a"), 
+					new Constant(false));	
+			exp.execute(scope);
+			fail("EvaluationException expected");
+		} catch (EvaluationException e) {}
+
+		try {
+			Expression exp = new BinaryOperation(BinaryOperation.OR, 
+					new Constant(false), 
+					new Constant("a"));	
+			exp.execute(scope);
+			fail("EvaluationException expected");
+		} catch (EvaluationException e) {}
+	
+	}
+
+	
+	public void testBooleanAnd() {
+		Expression exp = 
+			new BinaryOperation(BinaryOperation.AND, 
+				new Constant(true), 
+				new Constant(true));	
+		assertTrue(Assert.filterBoolean(exp.execute(scope)));
+		
+		exp = new BinaryOperation(BinaryOperation.AND, 
+				new Constant(false), 
+				new Constant(true));	
+		assertFalse(Assert.filterBoolean(exp.execute(scope)));
+		
+		exp = new BinaryOperation(BinaryOperation.AND, 
+				new Constant(true), 
+				new Constant(false));	
+		assertFalse(Assert.filterBoolean(exp.execute(scope)));
+			
+		exp = new BinaryOperation(BinaryOperation.AND, 
+				new Constant(false), 
+				new Constant(false));	
+		assertFalse(Assert.filterBoolean(exp.execute(scope)));
+	}
+
+	
+	public void testBooleanAndWithNonBooleanValue() {
+		
+		try {
+			Expression exp = new BinaryOperation(BinaryOperation.AND, 
+					new Constant("a"), 
+					new Constant(false));	
+			exp.execute(scope);
+			fail("EvaluationException expected");
+		} catch (EvaluationException e) {}
+
+		try {
+			Expression exp = new BinaryOperation(BinaryOperation.AND, 
+					new Constant(true), 
+					new Constant("a"));	
+			exp.execute(scope);
+			fail("EvaluationException expected");
+		} catch (EvaluationException e) {}
+	
+	}
+
+	
+	public void testBitwiseAndOnInteger() {
+		Expression exp = 
+			new BinaryOperation(BIT_AND, 
+				new Constant(0xFE), 
+				new Constant(0x03));	
+		assertEquals(2, exp.execute(scope));
+	}
+
+	
+	public void testBitwiseOrOnInteger() {
+		Expression exp = 
+			new BinaryOperation(BIT_OR, 
+				new Constant(0xF0), 
+				new Constant(0x0F));	
+		assertEquals(0xFF, exp.execute(scope));
+	}
+
+	
+	
+	public void testNonExistingBinaryOperation() {
+		try {
+			Expression exp = new BinaryOperation("?!", 
+				new Constant(1), 
+				new Constant(2));
+			exp.execute(scope);
+			
+			fail("EvaluationException expected !");
+		} catch (EvaluationException e) {}	
+	}
+
+	
+	public void testNonExistingUnaryOperation() {
+		try {
+			Expression exp = new UnaryOperation("?!", new Constant(4));
+			exp.execute(scope);
+			
+			fail("EvaluationException expected !");
+		} catch (Exception e) {}	
+	}
+
+	
+	public void testBitComplement() {
+		Expression exp = new UnaryOperation(BIT_COMPLEMENT, new Constant(0xF0F0F0F0));
+		assertEquals(0x0F0F0F0F, exp.execute(scope));
+	}
+
+
+}

+ 185 - 0
test-plugins/org.yakindu.sct.simulation.runtime.test/src/org/yakindu/sct/simulation/runtime/stext/test/FunctionsTest.java

@@ -0,0 +1,185 @@
+/**
+ * Copyright (c) 2010 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.simulation.runtime.stext.test;
+
+import java.math.BigDecimal;
+
+import junit.framework.TestCase;
+
+import org.yakindu.sct.simulation.runtime.EvaluationException;
+import org.yakindu.sct.simulation.runtime.stext.ExpressionRuntimeException;
+import org.yakindu.sct.simulation.runtime.stext.Function;
+import org.yakindu.sct.simulation.runtime.stext.FunctionMethod;
+
+
+/**
+ * TODO: Negativ-Tests
+ * 
+ * @author aterfloth
+ *
+ */
+public class FunctionsTest extends TestCase {
+	
+
+	public static class TestFunction extends Function {
+		
+		@FunctionMethod("?")
+		public Integer test(Integer i1, Integer i2) {
+			return i1 + 2 * i2;
+		}
+		
+		@FunctionMethod("+")
+		public float add(float f1, float f2) {
+			return f1 + f2;
+		}
+		
+		@FunctionMethod("fail")
+		public int fail() {
+			throw new RuntimeException();
+		}
+	}
+	
+	
+	
+	public void testLookupByMethodNameAndParamTypes() {
+		
+		Class<?> params[] = new Class<?>[]{Integer.class, Integer.class};
+		
+		Function function = Function.lookup(TestFunction.class, "test", params);
+		assertNotNull(function);
+	}
+
+	
+	public void testLookupByFunctionNameAndParamTypes() {
+		
+		Class<?> params[] = new Class<?>[]{Integer.class, Integer.class};
+		
+		Function function = Function.lookup(TestFunction.class, "?", params);
+		assertNotNull(function);
+	}
+
+	
+	public void testLookupByFunctionNameAndParamValues() {
+		
+		Object params[] = new Object[]{1, 2};
+		
+		Function function = Function.lookup(TestFunction.class, "?", params);
+		assertNotNull(function);
+	}
+
+	
+	public void testLookupNonMatchingMethodName() {
+		
+		Class<?> params[] = new Class<?>[]{Integer.class, Integer.class};
+		
+		Function function = Function.lookup(TestFunction.class, "blabla", params);
+		assertNull(function);
+	}
+
+	
+	public void testLookupNonParamTypes() {
+		
+		Class<?> params[] = new Class<?>[]{BigDecimal.class, BigDecimal.class};
+		
+		Function function = Function.lookup(TestFunction.class,  "test", params);
+		assertNull(function);
+	}
+
+	
+	public void testPrimitiveTypes() {
+		
+		Class<?> paramTypes[] = new Class<?>[]{Float.TYPE, Float.TYPE};
+		
+		assertNotNull( Function.lookup(TestFunction.class, "+", paramTypes) );
+	}
+
+	
+	public void testExecuteFunction() {
+		
+		Object params[] = new Object[]{1, 2};
+		
+		Object result = Function.lookup(TestFunction.class, "?", params).execute(params);
+		assertEquals(5, result);
+	}
+
+	
+	public void testExecutePrimitiveTypeFunction() {
+		
+		Object params[] = new Object[]{1.1f, 2.0f};
+		Class<?> paramTypes[] = new Class<?>[]{Float.TYPE, Float.TYPE};
+		
+		Object result = Function.lookup(TestFunction.class, "+", paramTypes).execute(params);
+		assertEquals(3.1f, result);
+	}
+	
+	
+	public void testIllegalArguments() {
+		Object params[] = new Object[]{1.1f, true};
+		Class<?> paramTypes[] = new Class<?>[]{Float.TYPE, Float.TYPE};
+		
+		try {
+			Function.lookup(TestFunction.class, "+", paramTypes).execute(params);
+			fail("expected EvaluationException !");
+		} catch (EvaluationException e) {}
+	}
+	
+	public void testTargetException() {
+		Object params[] = new Object[]{};
+		Class<?> paramTypes[] = new Class<?>[]{};
+		
+		try {
+			Function.lookup(TestFunction.class, "fail", paramTypes).execute(params);
+			fail("expected EvaluationException !");
+		} catch (EvaluationException e) {}
+	}
+	
+	
+	public void testFunctionWithoutDefaultConstructor() {
+		Class<?> paramTypes[] = new Class<?>[]{Object.class};
+		
+		try {
+			Function result = Function.lookup(FunctionWithoutDefaultConstructor.class, "foo", paramTypes);
+			fail("Expected ExpressionRuntimeException !");
+		} catch (ExpressionRuntimeException e) {}
+	}
+	
+	
+	public static class FunctionWithoutDefaultConstructor extends Function {
+		
+		public FunctionWithoutDefaultConstructor(String foo) {};
+		
+		@FunctionMethod("foo")
+		public Object foo(Object obj) { return null; }
+	}
+	
+
+	public void testFailingFunctionConstructor() {
+		Class<?> paramTypes[] = new Class<?>[]{Object.class};
+		
+		try {
+			Function result = Function.lookup(FunctionWithFailingConstructor.class, "foo", paramTypes);
+			fail("Expected ExpressionRuntimeException !");
+		} catch (ExpressionRuntimeException e) {}
+	}
+	
+	
+	public static class FunctionWithFailingConstructor extends Function {
+		
+		private FunctionWithFailingConstructor() {
+			super();
+			throw new RuntimeException("test...");
+		}
+
+		@FunctionMethod("foo")
+		public Object foo(Object obj) { return null; }
+	}
+
+}