Search in sources :

Example 61 with Statechart

use of org.yakindu.sct.model.sgraph.Statechart in project statecharts by Yakindu.

the class FlowOptimizer_ExecutionEntryTest method testNoNullCall.

@Test
public void testNoNullCall() {
    Statechart sc = _createStatechart("sc");
    {
        InterfaceScope s_scope = _createInterfaceScope("Interface", sc);
        VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, s_scope);
        Region r = _createRegion("r", sc);
        {
            Entry r_entry = _createEntry(EntryKind.INITIAL, null, r);
            State s1 = _createState("s1", r);
            State s2 = _createState("s2", r);
            {
                _createEntryAssignment(v1, s2, 3);
                Region r2 = _createRegion("r2", s2);
                {
                    Entry e = _createEntry(EntryKind.INITIAL, null, r2);
                    Entry history = _createEntry(EntryKind.SHALLOW_HISTORY, "history", r2);
                    State s3 = _createState("s3", r2);
                    {
                        _createEntryAssignment(v1, s3, 4);
                    }
                    State s4 = _createState("s4", r2);
                    {
                        Region r4 = _createRegion("r4", s4);
                        {
                            Entry e4 = _createEntry(EntryKind.INITIAL, null, r2);
                            State s5 = _createState("s5", r4);
                            _createTransition(e4, s5);
                            _createTransition(s5, s1);
                        }
                    }
                    _createTransition(e, s3);
                    _createTransition(history, s3);
                    _createTransition(s3, s4);
                    _createTransition(s1, history);
                }
            }
            _createTransition(r_entry, s1);
            _createTransition(s1, s2);
        }
    }
    ExecutionFlow flow = sequencer.transform(sc);
    optimizer.inlineChoices(true);
    optimizer.inlineEnterSequences(true);
    optimizer.inlineEntryActions(true);
    optimizer.inlineExitActions(true);
    optimizer.inlineExitRegion(true);
    optimizer.inlineExitSequences(true);
    optimizer.inlineReactions(true);
    optimizer.inlineEntries(true);
    optimizer.transform(flow);
    TreeIterator<EObject> iter = flow.eAllContents();
    while (iter.hasNext()) {
        EObject child = iter.next();
        if (child instanceof Call) {
            Call childCall = (Call) child;
            if (childCall.getStep() == null) {
                if (childCall.eContainer() instanceof Sequence) {
                    Sequence sequence = (Sequence) childCall.eContainer();
                    fail(sequence.getName() + ": " + sequence.getComment());
                } else {
                    fail("Call of null-Step in " + childCall.eContainer());
                }
            }
        }
    }
}
Also used : Call(org.yakindu.sct.model.sexec.Call) Entry(org.yakindu.sct.model.sgraph.Entry) SGraphTestFactory._createEntry(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createEntry) VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) SGraphTestFactory._createState(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState) State(org.yakindu.sct.model.sgraph.State) EObject(org.eclipse.emf.ecore.EObject) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) Statechart(org.yakindu.sct.model.sgraph.Statechart) SGraphTestFactory._createStatechart(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) StextTestFactory._createInterfaceScope(org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope) Region(org.yakindu.sct.model.sgraph.Region) SGraphTestFactory._createRegion(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion) Sequence(org.yakindu.sct.model.sexec.Sequence) Test(org.junit.Test)

Example 62 with Statechart

use of org.yakindu.sct.model.sgraph.Statechart in project statecharts by Yakindu.

the class STextJavaValidatorTest method checkValueDefinitionExpression.

@Test
public void checkValueDefinitionExpression() {
    Statechart statechart = AbstractTestModelsUtil.loadStatechart(VALIDATION_TESTMODEL_DIR + "ConstWithVariable.sct");
    Diagnostic diagnostics = Diagnostician.INSTANCE.validate(statechart);
    // 
    assertIssueCount(diagnostics, 3);
    assertError(diagnostics, REFERENCE_TO_VARIABLE);
    assertError(diagnostics, CONST_MUST_HAVE_VALUE_MSG);
}
Also used : Statechart(org.yakindu.sct.model.sgraph.Statechart) Diagnostic(org.eclipse.emf.common.util.Diagnostic) Test(org.junit.Test)

Example 63 with Statechart

use of org.yakindu.sct.model.sgraph.Statechart in project statecharts by Yakindu.

the class StateBasedRefactoringTest method testRefactoringIsExecutableOnState.

protected void testRefactoringIsExecutableOnState(String pathToInitialSct, String pathToExpectedSct, String stateName, boolean expectedResult) {
    Statechart initial = models.loadStatechartFromResource(pathToInitialSct);
    State state = getStateByName(initial, stateName);
    AbstractRefactoring<?> refactoring = getRefactoring(state);
    if (expectedResult) {
        Assert.assertTrue("Refactoring on state '" + stateName + "' was not executable, although it should be.", refactoring.isExecutable());
    } else {
        Assert.assertFalse("Refactoring on state '" + stateName + "' was executable, although it should not be.", refactoring.isExecutable());
    }
}
Also used : State(org.yakindu.sct.model.sgraph.State) Statechart(org.yakindu.sct.model.sgraph.Statechart)

Example 64 with Statechart

use of org.yakindu.sct.model.sgraph.Statechart in project statecharts by Yakindu.

the class StateBasedRefactoringTest method testRefactoringOnState.

protected void testRefactoringOnState(String pathToInitialSct, String pathToExpectedSct, String stateName) {
    Statechart initial = models.loadStatechartFromResource(pathToInitialSct);
    State state = getStateByName(initial, stateName);
    AbstractRefactoring<?> refactoring = getRefactoring(state);
    AbstractSCTResource initialRes = (AbstractSCTResource) initial.eResource();
    initialRes.setSerializerEnabled(true);
    refactoring.executeRefactoring();
    initialRes.setSerializerEnabled(false);
    Statechart expected = models.loadStatechartFromResource(pathToExpectedSct);
    compareStatecharts(initial, expected);
}
Also used : AbstractSCTResource(org.yakindu.sct.model.sgraph.resource.AbstractSCTResource) State(org.yakindu.sct.model.sgraph.State) Statechart(org.yakindu.sct.model.sgraph.Statechart)

Example 65 with Statechart

use of org.yakindu.sct.model.sgraph.Statechart in project statecharts by Yakindu.

the class CCodeGeneratorModule method configureEventDriven.

protected void configureEventDriven(GeneratorEntry entry, Binder binder) {
    Statechart statechart = (Statechart) entry.getElementRef();
    Annotation eventDrivenAnnotation = statechart.getAnnotationOfType(EVENT_DRIVEN_ANNOTATION);
    if (eventDrivenAnnotation != null) {
        binder.bind(StatemachineHeader.class).to(EventDrivenStatemachineHeader.class);
        binder.bind(StatemachineSource.class).to(EventDrivenStatemachineSource.class);
        binder.bind(CExpressionsGenerator.class).to(EventDrivenExpressionCode.class);
    }
}
Also used : EventDrivenStatemachineSource(org.yakindu.sct.generator.c.eventdriven.EventDrivenStatemachineSource) Statechart(org.yakindu.sct.model.sgraph.Statechart) EventDrivenStatemachineHeader(org.yakindu.sct.generator.c.eventdriven.EventDrivenStatemachineHeader) Annotation(org.yakindu.base.types.Annotation)

Aggregations

Statechart (org.yakindu.sct.model.sgraph.Statechart)132 Test (org.junit.Test)89 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)65 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)63 Region (org.yakindu.sct.model.sgraph.Region)59 State (org.yakindu.sct.model.sgraph.State)59 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)57 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)57 SGraphTestFactory._createState (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState)51 VariableDefinition (org.yakindu.sct.model.stext.stext.VariableDefinition)48 StextTestFactory._createInterfaceScope (org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope)48 InterfaceScope (org.yakindu.sct.model.stext.stext.InterfaceScope)47 StextTestFactory._createVariableDefinition (org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition)47 Sequence (org.yakindu.sct.model.sexec.Sequence)40 Entry (org.yakindu.sct.model.sgraph.Entry)30 SCTTestUtil.findState (org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.findState)29 SGraphTestFactory._createEntry (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createEntry)29 Reaction (org.yakindu.sct.model.sexec.Reaction)25 Scope (org.yakindu.sct.model.sgraph.Scope)25 EnterState (org.yakindu.sct.model.sexec.EnterState)21