Commit 43fdb3de authored by Daniel Ratiu's avatar Daniel Ratiu
Browse files

Major refactorings of tests. We are reaching soon the yellow status.

refs 311
parent 6798d6d8
......@@ -22,7 +22,7 @@ import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.af3.component.utils.ComponentModelElementFactory;
import org.fortiss.af3.project.model.execution.ExecutionConfiguration;
import test.org.fortiss.af3.expression.ExpressionTestModelBase;
import test.org.fortiss.af3.expression.model.ExpressionTestModelBase;
/**
* Base class for component tests.
......@@ -30,7 +30,7 @@ import test.org.fortiss.af3.expression.ExpressionTestModelBase;
* @author ratiu
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
* @ConQAT.Rating YELLOW Hash: 0F3F5EB8694223419A5B4269290D0166
*/
public class ComponentTestModelBase extends ExpressionTestModelBase {
......
......@@ -42,24 +42,24 @@ import test.org.fortiss.af3.component.ComponentTestModelBase;
* @author ratiu
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
* @ConQAT.Rating YELLOW Hash: DAB413721838ABAADAE4478BD1D86EE4
*/
public class CounterTestModel extends ComponentTestModelBase {
/** The Counter component. */
protected Component counterComponent;
public Component counterComponent;
/** The input port of Counter component. */
protected InputPort inputPort;
public InputPort inputPort;
/** The feedback input port of Counter component. */
protected InputPort feedbackInputPort;
public InputPort feedbackInputPort;
/** The feedback channel. */
protected Channel feedbackChannel;
public Channel feedbackChannel;
/** The output port of Counter component. */
protected OutputPort outputPort;
public OutputPort outputPort;
/** Executable component. */
protected ExecutableComponent<?> executable;
......@@ -74,21 +74,6 @@ public class CounterTestModel extends ComponentTestModelBase {
createCounterComponent();
}
/** Returns the counter test component. */
public Component getCounterComponent() {
return counterComponent;
}
/** Returns the output port. */
public OutputPort getOutputPort() {
return outputPort;
}
/** Returns the input port. */
public InputPort getInputPort() {
return inputPort;
}
/** Creates the counter component. */
private void createCounterComponent() {
counterComponent = createComponent("Counter", "Counter");
......
......@@ -37,7 +37,7 @@ import test.org.fortiss.af3.component.ComponentTestModelBase;
* @author ratiu
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
* @ConQAT.Rating YELLOW Hash: 425CCDECB973F27D08CACDF64BE264F4
*/
public class OneBitHalfAdderTestModel extends ComponentTestModelBase {
......
<!--
$Id: package.html 894 2011-07-07 07:36:03Z ratiu $
@version $Rev: 894 $
@ConQAT.Rating YELLOW Hash: 2AE07908CA65C5FFDFE18A59636AFB22
-->
<body>
This package contains test-models.
</body>
<!--
$Id: package.html 894 2011-07-07 07:36:03Z ratiu $
@version $Rev: 894 $
@ConQAT.Rating YELLOW Hash: DC2B72A8A7F1A0B0AF33BAF2AC81B657
-->
<body>
Base package for component tests.
</body>
......@@ -17,18 +17,17 @@ $Id$
+--------------------------------------------------------------------------*/
package test.org.fortiss.af3.component.simulator;
import static org.fortiss.tooling.kernel.utils.ModelElementUtils.findReferencedElement;
import static org.fortiss.tooling.kernel.utils.TransformationUtils.createTransformedObjectFor;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.component.simulator.ExecutableComponent;
import org.fortiss.af3.project.extension.data.ExecutionConfigTransformationContext;
import org.fortiss.af3.project.model.execution.ExecutionConfiguration;
import org.fortiss.tooling.kernel.extension.exception.ChainTransformationFailedException;
import org.fortiss.tooling.kernel.utils.ModelElementUtils;
import org.fortiss.tooling.kernel.utils.TransformationUtils;
import test.org.fortiss.af3.testbase.ITestModel;
import test.org.fortiss.af3.component.ComponentTestModelBase;
import test.org.fortiss.af3.testbase.SimulatorTestBase;
/**
......@@ -37,41 +36,50 @@ import test.org.fortiss.af3.testbase.SimulatorTestBase;
* @author ratiu
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
* @ConQAT.Rating YELLOW Hash: 87C0601B9E172DE2016C434C7F819828
*/
public abstract class ComponentSimulatorTestBase extends SimulatorTestBase {
public abstract class ComponentSimulatorTestBase<T extends ComponentTestModelBase, S extends ExecutableComponent<?>>
extends SimulatorTestBase<T> {
/** The composite simulator. */
protected ExecutableComponent<?> topSimulator;
/** The current simulator. */
protected S currentSimulator;
/** Constructor. */
public ComponentSimulatorTestBase(ITestModel testModel) {
public ComponentSimulatorTestBase(T testModel) {
super(testModel);
}
/** Returns the {@link ExecutionConfiguration} used to start the simulator. */
public abstract ExecutionConfiguration getExecutionConfiguration();
/**
* Assigns the value of {@link #currentSimulator}. Can be overwritten by
* descendants.
*/
@SuppressWarnings("unchecked")
protected void computeCurrentSimulator() {
currentSimulator = (S) topSimulator.getSubElements().get(0);
}
/**
* Initializes the simulator using the configuration returned by
* {@link #getExecutionConfiguration()}. Sub-classes may override, but must
* call super implementation first.
* Initializes the simulator using the execution configuration. Sub-classes
* may override, but must call super implementation first.
*/
@Override
protected void setupSimulator() {
EObject source = ModelElementUtils
.findReferencedElement(getExecutionConfiguration());
EObject source = findReferencedElement(testModel.executionConfiguration);
assertNotNull(source);
try {
topSimulator = TransformationUtils.createTransformedObjectFor(
source, ExecutableComponent.class,
topSimulator = createTransformedObjectFor(source,
ExecutableComponent.class,
new ExecutionConfigTransformationContext(
getExecutionConfiguration()));
testModel.executionConfiguration));
assertNotNull(topSimulator);
topSimulator.initialize();
computeCurrentSimulator();
} catch (ChainTransformationFailedException ctfe) {
fail(ctfe.getMessage());
}
......@@ -84,5 +92,6 @@ public abstract class ComponentSimulatorTestBase extends SimulatorTestBase {
@Override
protected void disposeSimulator() {
topSimulator = null;
currentSimulator = null;
}
}
\ No newline at end of file
<!--
$Id: package.html 894 2011-07-07 07:36:03Z ratiu $
@version $Rev: 894 $
@ConQAT.Rating YELLOW Hash: B67C1D3A940416ACF2E1589F39A2BF8A
-->
<body>
This package contains base classes for the simulator test-cases.
</body>
......@@ -35,4 +35,5 @@ Export-Package: org.fortiss.af3.expression,
org.fortiss.af3.expression.model.types.util,
org.fortiss.af3.expression.model.util,
org.fortiss.af3.expression.utils,
test.org.fortiss.af3.expression
test.org.fortiss.af3.expression,
test.org.fortiss.af3.expression.model
......@@ -36,10 +36,16 @@ import test.org.fortiss.af3.expression.parser.TypeSystemParserTest;
* @version $Rev$
* @ConQAT.Rating RED Hash: 9BD23339E200E66A46797052A68864F4
*/
// @formatter:off
@RunWith(Suite.class)
@SuiteClasses({ ConstraintCheckerTest.class, EvaluatorTest.class,
EvaluatorTest3_Arith_NoVal_Vars.class, EvaluatorTest5_Strict.class,
ParserEvaluatorTest.class, TypeSystemParserTest.class })
@SuiteClasses({
ConstraintCheckerTest.class,
EvaluatorTest.class,
EvaluatorTest3_Arith_NoVal_Vars.class,
EvaluatorTest5_Strict.class,
ParserEvaluatorTest.class,
TypeSystemParserTest.class
})
public class AllTests {
// empty class: collection of test cases
}
......@@ -31,7 +31,7 @@ import org.junit.Before;
import org.junit.Test;
/**
* Junit test for constraint checkers of microAF3.
* Test for constraint checkers.
*
* @author hoelzlf
* @author $Author$
......
<!--
$Id: package.html 894 2011-07-07 07:36:03Z ratiu $
@version $Rev: 894 $
@ConQAT.Rating YELLOW Hash: 2AE07908CA65C5FFDFE18A59636AFB22
-->
<body>
This package contains tests for the constraint checker.
</body>
......@@ -35,6 +35,7 @@ import org.fortiss.af3.project.model.typesystem.ITerm;
import org.junit.Before;
import org.junit.Test;
import test.org.fortiss.af3.expression.evaluator.EvaluatorTest.TestModel;
import test.org.fortiss.af3.testbase.ModelTestBase;
/**
......@@ -45,7 +46,7 @@ import test.org.fortiss.af3.testbase.ModelTestBase;
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class EvaluatorTest extends ModelTestBase {
public class EvaluatorTest extends ModelTestBase<TestModel> {
/** Constructor. */
public EvaluatorTest() {
......@@ -55,18 +56,17 @@ public class EvaluatorTest extends ModelTestBase {
/** Testing the evaluate function. */
@Test
public void testComparison() {
TestModel tm = (TestModel) testModel;
Var accelerate = VarStaticImpl.create("Accelerate");
tm.context.setValue(accelerate, new IntValue(10));
testModel.context.setValue(accelerate, new IntValue(10));
assertEquals(BoolValue.TRUE,
tm.evaluator.evaluate(tm.comparisonExpression, tm.context));
assertEquals(BoolValue.TRUE, testModel.evaluator.evaluate(
testModel.comparisonExpression, testModel.context));
}
/** Testing the equality function. */
@Test
public void testEquality() {
TestModel tm = (TestModel) testModel;
TestModel tm = testModel;
Var accelerate = VarStaticImpl.create("Accelerate");
tm.context.setValue(accelerate, new IntValue(10));
......@@ -91,7 +91,7 @@ public class EvaluatorTest extends ModelTestBase {
*/
@Test
public void testRevealingBug194() {
TestModel tm = (TestModel) testModel;
TestModel tm = testModel;
Var accelerate = VarStaticImpl.create("Accelerate");
tm.context.setValue(accelerate, NoVal.NOVAL);
......@@ -103,7 +103,7 @@ public class EvaluatorTest extends ModelTestBase {
}
/** Test model. */
private static class TestModel extends EvaluatorTestModelBase {
protected static class TestModel extends EvaluatorTestModelBase {
/** Accelerate > 0 */
public FunctionCall comparisonExpression;
......
......@@ -29,7 +29,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import test.org.fortiss.af3.expression.ExpressionTestModelBase;
import test.org.fortiss.af3.expression.model.ExpressionTestModelBase;
/**
* Test base implementation for expressions.
......
......@@ -15,16 +15,22 @@ $Id$
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package test.org.fortiss.af3.expression;
package test.org.fortiss.af3.expression.model;
import org.fortiss.af3.expression.language.Compiler;
import org.fortiss.af3.expression.language.evaluation.EnumerationValue;
import org.fortiss.af3.expression.model.DataDictionary;
import org.fortiss.af3.expression.model.definitions.Enumeration;
import org.fortiss.af3.expression.model.definitions.EnumerationMember;
import org.fortiss.af3.expression.model.terms.FunctionCall;
import org.fortiss.af3.expression.utils.DataDictionaryUtils;
import org.fortiss.af3.expression.utils.ExpressionModelElementFactory;
import org.fortiss.af3.project.model.typesystem.ITypeSystem;
import test.org.fortiss.af3.project.ProjectTestModelBase;
/**
* Test base implementation for expressions.
* Base implementation for test models.
*
* @author trachtenherz
* @author hoelzl
......@@ -42,4 +48,19 @@ public abstract class ExpressionTestModelBase extends ProjectTestModelBase {
protected ITypeSystem setupTypeSystem() {
return ExpressionModelElementFactory.createMicroTypesystem();
}
/** creates an EnumValue from the given String */
protected EnumerationValue createEnumValue(int enumID, int enumMemberID) {
DataDictionary dd = DataDictionaryUtils.findDataDictionary(project,
"Data Dictionary");
Enumeration enumeration = (Enumeration) dd.getTypeDefinitions(enumID);
EnumerationMember enumMember = enumeration.getMembers(enumMemberID);
FunctionCall functionCall = (FunctionCall) compiler
.compileTerm(enumMember.getName() + "()");
return new EnumerationValue(functionCall, enumMember);
}
}
\ No newline at end of file
<!--
$Id: package.html 894 2011-07-07 07:36:03Z ratiu $
@version $Rev: 894 $
@ConQAT.Rating YELLOW Hash: 2AE07908CA65C5FFDFE18A59636AFB22
-->
<body>
Base package for expression tests.
</body>
......@@ -24,7 +24,7 @@ import org.fortiss.af3.project.model.typesystem.ITerm;
import org.junit.Assert;
import org.junit.Test;
import test.org.fortiss.af3.expression.ExpressionTestModelBase;
import test.org.fortiss.af3.expression.model.ExpressionTestModelBase;
/**
* Tests for the type system parser.
......
......@@ -28,10 +28,11 @@ import org.junit.Before;
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public abstract class GeneratorTestBase extends ModelTestBase {
public abstract class GeneratorTestBase<T extends ITestModel> extends
ModelTestBase<T> {
/** Constructor. */
public GeneratorTestBase(ITestModel testModel) {
public GeneratorTestBase(T testModel) {
super(testModel);
}
......
......@@ -30,13 +30,13 @@ import org.junit.Before;
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public abstract class ModelTestBase extends TestBase {
public abstract class ModelTestBase<T extends ITestModel> extends TestBase {
/** Stores the test model. */
protected final ITestModel testModel;
protected final T testModel;
/** Constructor. */
public ModelTestBase(ITestModel testModel) {
public ModelTestBase(T testModel) {
Assert.assertNotNull(testModel);
this.testModel = testModel;
}
......
......@@ -28,10 +28,11 @@ import org.junit.Before;
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public abstract class SimulatorTestBase extends ModelTestBase {
public abstract class SimulatorTestBase<T extends ITestModel> extends
ModelTestBase<T> {
/** Constructor. */
public SimulatorTestBase(ITestModel testModel) {
public SimulatorTestBase(T testModel) {
super(testModel);
}
......
......@@ -43,7 +43,7 @@ import org.fortiss.tooling.kernel.utils.EMFResourceUtils;
* @author becker
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
* @ConQAT.Rating YELLOW Hash: B5346BDAF1939D5DFBDB1BDC5A004FA4
*/
public final class SimpleTrafficLightsExampleWizard extends Wizard implements
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment