Skip to content
This repository has been archived by the owner on Jan 5, 2021. It is now read-only.

Issue 565 #591

Merged
merged 8 commits into from
Apr 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/traffic_light/model/TrafficLightCtrl.sgen
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ GeneratorModel for yakindu::java {
TimerService = true
}

feature RunnableWrapper {
namePrefix = ""
nameSuffix = "Runnable"
feature SynchronizedWrapper {
namePrefix = "Synchronized"
nameSuffix = ""
}

feature LicenseHeader {
licenseText = "
Copyright (c) 2012-2015 committers of YAKINDU and others.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,13 @@ public void checkExpression(Guard expression) {

@Check(CheckType.FAST)
public void transitionsWithNoTrigger(Transition trans) {
if (trans.getSource() instanceof Entry || trans.getSource() instanceof Choice
|| trans.getSource() instanceof Synchronization) {
return;
}

if (trans.getSource() instanceof Entry
|| trans.getSource() instanceof Choice
|| trans.getSource() instanceof Synchronization
|| (trans.getTarget() instanceof Synchronization && (trans.getTarget().getIncomingTransitions().size() > 1))
) { return; }

if (trans.getSource() instanceof org.yakindu.sct.model.sgraph.State) {
org.yakindu.sct.model.sgraph.State state = (org.yakindu.sct.model.sgraph.State) trans.getSource();
if (state.isComposite()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2012 committers of YAKINDU and others.
* Copyright (c) 2012-2016 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
Expand All @@ -13,14 +13,22 @@
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import org.yakindu.sct.model.stext.test.validation.STextJavaValidatorTest;
import org.yakindu.sct.model.stext.test.validation.TransitionsWithNoTriggerTest;

/**
* @author andreas muelder - Initial contribution and API
* @author terfloth - extensions
*
*/
@RunWith(value = Suite.class)
@SuiteClasses(value = { TypeInferrerTest.class, STextJavaValidatorTest.class, StextParserRuleTest.class,
TestModelsContainErrorsTest.class, SCTUnitClassifierTest.class })
public class AllTests {
@SuiteClasses(value = {
TypeInferrerTest.class,
StextParserRuleTest.class,
TestModelsContainErrorsTest.class,
SCTUnitClassifierTest.class,
STextJavaValidatorTest.class,
TransitionsWithNoTriggerTest.class })

public class AllTests {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package org.yakindu.sct.model.stext.test.validation;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.yakindu.sct.test.models.AbstractTestModelsUtil.VALIDATION_TESTMODEL_DIR;

import java.util.HashMap;

import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.junit4.validation.ValidatorTester;
import org.junit.After;
import org.junit.Before;
import org.yakindu.sct.model.sgraph.SGraphFactory;
import org.yakindu.sct.model.sgraph.Statechart;
import org.yakindu.sct.model.sgraph.Transition;
import org.yakindu.sct.model.sgraph.Vertex;
import org.yakindu.sct.model.stext.resource.StextResource;
import org.yakindu.sct.model.stext.test.util.AbstractSTextTest;
import org.yakindu.sct.model.stext.validation.STextJavaValidator;
import org.yakindu.sct.test.models.AbstractTestModelsUtil;

import com.google.inject.Inject;
import com.google.inject.Injector;

public abstract class AbstractSTextValidationTest extends AbstractSTextTest {

@Inject
public STextJavaValidator validator;
@Inject
public Injector injector;

protected ValidatorTester<STextJavaValidator> tester;
protected BasicDiagnostic diagnostics;
protected SGraphFactory factory;
protected Statechart statechart;
protected StextResource resource;

@Before public void setup() {
factory = SGraphFactory.eINSTANCE;

resource = new StextResource(URI.createURI(""));
injector.injectMembers(resource);
statechart = factory.createStatechart();
resource.getContents().add(statechart);

diagnostics = new BasicDiagnostic();
tester = new ValidatorTester<STextJavaValidator>(validator, injector);
}

@After public void teardown() {
tester = null;
}

protected void resetDiagnostics() {
diagnostics = new BasicDiagnostic();
}

protected Transition createTransition(Vertex source, Vertex target) {
Transition trans = SGraphFactory.eINSTANCE.createTransition();
trans.setSource(source);
trans.setTarget(target);
source.getOutgoingTransitions().add(trans);
target.getIncomingTransitions().add(trans);
return trans;
}

protected void assertError(Diagnostic diag, String message) {
Diagnostic d = issueByName(diag, message);
assertNotNull("Issue '" + message + "' does not exist.", issueByName(diag, message));
assertEquals("Issue '" + message + "' is no error.", Diagnostic.ERROR, d.getSeverity());
}

protected void assertWarning(Diagnostic diag, String message) {
Diagnostic d = issueByName(diag, message);
assertNotNull("Issue '" + message + "' does not exist.", issueByName(diag, message));
assertEquals("Issue '" + message + "' is no warning.", Diagnostic.WARNING, d.getSeverity());
}

protected void assertIssueCount(Diagnostic diag, int count) {
int c = diag.getChildren().size();
assertEquals("expected " + count + " issue(s) but were " + c + " [" + diag.toString() + "]", count, c);
}

protected Diagnostic issueByName(Diagnostic diag, String message) {
for (Diagnostic issue : diag.getChildren()) {
if (message.equals(issue.getMessage()))
return issue;
}
return null;
}

protected boolean validate(EObject obj) {
return validator.validate(obj, diagnostics,
new HashMap<Object, Object>());
}

protected Statechart loadStatechart(String modelName) {
return AbstractTestModelsUtil
.loadStatechart(VALIDATION_TESTMODEL_DIR
+ modelName);
}

}
Loading