Browse Source

Created test framework that runs parameterized tests

Casper Thule 4 years ago
parent
commit
dcea5979ee
28 changed files with 511 additions and 70 deletions
  1. 2 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/META-INF/MANIFEST.MF
  2. 9 10
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppAutoTest.xtend
  3. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppBasicTest.xtend
  4. 0 43
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/ParameterizedXtextRunner.xtend
  5. 0 11
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/XtextParametersRunnerFactory.xtend
  6. 0 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/window_sa_canonical.BASE.sa
  7. 0 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window2/powerwindow_algebraic_loop_delay.sa
  8. 0 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window2/powerwindow_controller_delay.sa
  9. 0 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window2/powerwindow_model_only.sa
  10. 17 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.testframework/META-INF/MANIFEST.MF
  11. 17 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.testframework/build.properties
  12. 5 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.testframework/plugin.xml
  13. 23 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.testframework/pom.xml
  14. 54 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.testframework/src/be/uantwerpen/ansymo/semanticadaptation/testframework/InjectorProviders.java
  15. 13 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.testframework/src/be/uantwerpen/ansymo/semanticadaptation/testframework/XtextParametersRunnerFactory.java
  16. 68 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.testframework/src/be/uantwerpen/ansymo/semanticadaptation/testframework/XtextRunnerWithParameters.java
  17. 3 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/META-INF/MANIFEST.MF
  18. 0 3
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/src/be/uantwerpen/ansymo/semanticadaptation/tests/AbstractSemanticAdaptationTest.xtend
  19. 97 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/src/be/uantwerpen/ansymo/semanticadaptation/tests/BasicParserTest.xtend
  20. 41 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/src/be/uantwerpen/ansymo/semanticadaptation/tests/ParserFolderTest.xtend
  21. 34 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/src/be/uantwerpen/ansymo/semanticadaptation/tests/SingleFolderTest.xtend
  22. 13 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/testInputs/single_folder_spec/window/powerwindow_algebraic_loop_delay.sa
  23. 23 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/testInputs/single_folder_spec/window/powerwindow_controller_delay.sa
  24. 27 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/testInputs/single_folder_spec/window/powerwindow_model_only.sa
  25. 13 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/testInputs/single_folder_spec/window2/powerwindow_algebraic_loop_delay.sa
  26. 23 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/testInputs/single_folder_spec/window2/powerwindow_controller_delay.sa
  27. 27 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/testInputs/single_folder_spec/window2/powerwindow_model_only.sa
  28. 1 0
      DSL_SemanticAdaptation/pom.xml

+ 2 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/META-INF/MANIFEST.MF

@@ -14,7 +14,8 @@ Require-Bundle: org.junit;bundle-version="4.7.0",
  org.eclipse.xtext.xbase.testing,
  be.uantwerpen.ansymo.semanticadaptation.cg.cpp;bundle-version="1.0.0",
  be.uantwerpen.ansymo.semanticadaptation;bundle-version="1.0.0",
- be.uantwerpen.ansymo.semanticadaptation.tests;bundle-version="1.0.0"
+ be.uantwerpen.ansymo.semanticadaptation.tests;bundle-version="1.0.0",
+ be.uantwerpen.ansymo.semanticadaptation.testframework;bundle-version="1.0.0"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Export-Package: be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests;x-internal=true
 Import-Package: org.hamcrest.core,

+ 9 - 10
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppAutoTest.xtend

@@ -5,11 +5,14 @@ package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests
 
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.CppGenerator
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SemanticAdaptation
+import be.uantwerpen.ansymo.semanticadaptation.testframework.XtextParametersRunnerFactory
 import be.uantwerpen.ansymo.semanticadaptation.tests.AbstractSemanticAdaptationTest
 import be.uantwerpen.ansymo.semanticadaptation.tests.SemanticAdaptationInjectorProvider
 import com.google.inject.Inject
 import java.io.File
 import java.util.ArrayList
+import java.util.Arrays
+import java.util.Collection
 import java.util.List
 import java.util.regex.Pattern
 import org.eclipse.emf.ecore.EObject
@@ -22,13 +25,8 @@ import org.eclipse.xtext.testing.validation.ValidationTestHelper
 import org.junit.Test
 import org.junit.runner.RunWith
 import org.junit.runners.Parameterized
-
-import java.util.Arrays
-import java.util.Collection
 import org.junit.runners.Parameterized.Parameters
 
-import static org.junit.Assert.assertTrue
-
 @RunWith(typeof(Parameterized))
 @InjectWith(SemanticAdaptationInjectorProvider)
 @Parameterized.UseParametersRunnerFactory(XtextParametersRunnerFactory)
@@ -45,10 +43,12 @@ class CgCppAutoTest extends AbstractSemanticAdaptationTest {
 	@Parameters(name = "{index}")
 	def static Collection<Object[]> data() {
 		val files = new ArrayList<List<File>>();
-		listf("test_input", files);
+		listf("test_input/single_folder_spec", files);
 		val test = new ArrayList();
 		test.add(files.get(0));
-		return Arrays.asList(test.toArray(), test.toArray());
+		val test2 = new ArrayList();
+		test2.add(files.get(1));
+		return Arrays.asList(test.toArray(), test2.toArray());
 	}
 
 	def static void listf(String directoryName, List<List<File>> files) {
@@ -78,9 +78,8 @@ class CgCppAutoTest extends AbstractSemanticAdaptationTest {
 	var List<File> f;
 
 	@Test def allSemanticAdaptations() {
-		System.out.println("fail");
-		assertTrue(false);
-		//__parseNoErrors(f);
+		//assertTrue(false);
+		__parseNoErrors(f);
 	}
 
 	def __parseNoErrors(List<File> files) {

+ 1 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppBasicTest.xtend

@@ -20,7 +20,7 @@ import org.eclipse.xtext.generator.InMemoryFileSystemAccess
 import org.eclipse.xtext.generator.IGeneratorContext
 import org.eclipse.emf.ecore.resource.ResourceSet
 
-@RunWith(ParameterizedXtextRunner)
+@RunWith(XtextRunner)
 @InjectWith(SemanticAdaptationInjectorProvider)
 class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 

+ 0 - 43
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/ParameterizedXtextRunner.xtend

@@ -1,43 +0,0 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests
-
-import org.eclipse.xtext.testing.XtextRunner
-import org.junit.runners.parameterized.TestWithParameters
-import org.junit.runners.model.InitializationError
-import java.util.List
-import org.junit.runners.model.Statement
-import org.junit.runner.notification.RunNotifier
-
-class ParameterizedXtextRunner extends XtextRunner {
-	val Object[] parameters;
-	val String annotatedName;
-	
-	new(TestWithParameters test) throws InitializationError {
-		super(test.testClass.javaClass)
-		parameters = test.parameters;
-		annotatedName = test.name;
-	}
-	
-	override protected getName() {
-		return super.name + annotatedName;
-	}
-
-	override protected createTest() throws Exception {
-		val object = testClass.onlyConstructor.newInstance(parameters)
-		val injectorProvider = getOrCreateInjectorProvider
-		if (injectorProvider != null) {
-			val injector = injectorProvider.injector
-			if (injector != null)
-				injector.injectMembers(object)
-		}
-		return object;
-	}
-	
-	override public void run(RunNotifier notifier){
-		super.run(notifier);
-	}
-
-	override protected void validateConstructor(List<Throwable> errors) {
-		validateOnlyOneConstructor(errors)
-	}
-	
-}

+ 0 - 11
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/XtextParametersRunnerFactory.xtend

@@ -1,11 +0,0 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests
-
-import org.junit.runners.parameterized.ParametersRunnerFactory
-import org.junit.runners.parameterized.TestWithParameters
-import org.junit.runners.model.InitializationError
-
-class XtextParametersRunnerFactory implements ParametersRunnerFactory {
-	override createRunnerForTestWithParameters(TestWithParameters test) throws InitializationError {
-		new ParameterizedXtextRunner(test)
-	}
-}

DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/window/window_sa_canonical.BASE.sa → DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/window_sa_canonical.BASE.sa


DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/window2/powerwindow_algebraic_loop_delay.sa → DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window2/powerwindow_algebraic_loop_delay.sa


DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/window2/powerwindow_controller_delay.sa → DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window2/powerwindow_controller_delay.sa


DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/window2/powerwindow_model_only.sa → DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window2/powerwindow_model_only.sa


+ 17 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.testframework/META-INF/MANIFEST.MF

@@ -0,0 +1,17 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: be.uantwerpen.ansymo.semanticadaptation.testframework
+Bundle-Vendor: University of Antwerp, Ansymo Lab
+Bundle-Version: 1.0.0.qualifier
+Bundle-SymbolicName: be.uantwerpen.ansymo.semanticadaptation.testframework;singleton:=true
+Bundle-ActivationPolicy: lazy
+Require-Bundle: org.junit;bundle-version="4.7.0",
+ org.eclipse.xtext.junit4,
+ org.eclipse.xtext.xbase.junit,
+ org.eclipse.xtext.xbase.lib,
+ org.eclipse.jdt.core,
+ org.eclipse.xtext.testing,
+ org.eclipse.xtext.xbase.testing
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Import-Package: org.apache.log4j
+Export-Package: be.uantwerpen.ansymo.semanticadaptation.testframework

+ 17 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.testframework/build.properties

@@ -0,0 +1,17 @@
+source.. = src/,\
+           src-gen/,\
+           xtend-gen/
+bin.includes = .,\
+               META-INF/,\
+               plugin.xml
+additional.bundles = org.eclipse.xtext.xbase,\
+                     org.eclipse.xtext.common.types,\
+                     org.eclipse.xtext.xtext.generator,\
+                     org.eclipse.emf.codegen.ecore,\
+                     org.eclipse.emf.mwe.utils,\
+                     org.eclipse.emf.mwe2.launch,\
+                     org.eclipse.emf.mwe2.lib,\
+                     org.objectweb.asm,\
+                     org.apache.commons.logging,\
+                     org.apache.log4j,\
+                     com.ibm.icu

+ 5 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.testframework/plugin.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="windows-1252"?>
+<?eclipse version="3.0"?>
+<plugin>
+
+</plugin>

+ 23 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.testframework/pom.xml

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+	<modelVersion>4.0.0</modelVersion>
+
+	<parent>
+		<relativePath>../pom.xml</relativePath>
+		<groupId>be.uantwerpen.ansymo.semanticadaptation</groupId>
+		<artifactId>parent</artifactId>
+		<version>1.0.0-SNAPSHOT</version>
+	</parent>
+
+	<artifactId>be.uantwerpen.ansymo.semanticadaptation.testframework</artifactId>
+	<packaging>eclipse-plugin</packaging>
+
+	<name>be.uantwerpen.ansymo.semanticadaptation Testframework</name>
+
+	<properties>
+    <main.basedir>${project.parent.basedir}</main.basedir>
+	</properties>
+
+	
+
+</project>

+ 54 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.testframework/src/be/uantwerpen/ansymo/semanticadaptation/testframework/InjectorProviders.java

@@ -0,0 +1,54 @@
+package be.uantwerpen.ansymo.semanticadaptation.testframework;
+
+import static org.eclipse.xtext.util.Exceptions.throwUncheckedException;
+
+import org.eclipse.xtext.testing.IInjectorProvider;
+import org.eclipse.xtext.testing.InjectWith;
+import org.junit.runners.model.TestClass;
+
+import com.google.common.collect.ClassToInstanceMap;
+import com.google.common.collect.MutableClassToInstanceMap;
+
+public class InjectorProviders {
+
+	private static ClassToInstanceMap<IInjectorProvider> injectorProviderClassCache = MutableClassToInstanceMap.create();
+	
+	public static IInjectorProvider getOrCreateInjectorProvider(TestClass testClass) {
+		InjectWith injectWith = testClass.getJavaClass().getAnnotation(InjectWith.class);
+		if (injectWith != null) {
+			Class<? extends IInjectorProvider> klass = injectWith.value();
+			IInjectorProvider injectorProvider = injectorProviderClassCache.get(klass);
+			if (injectorProvider == null) {
+				try {
+					injectorProvider = klass.newInstance();
+					injectorProviderClassCache.put(klass, injectorProvider);
+				} catch (Exception e) {
+					throwUncheckedException(e);
+				}
+			}
+			return injectorProvider;
+		}
+		return null;
+	}
+
+	public static IInjectorProvider getInjectorProvider(TestClass testClass) {
+		InjectWith injectWith = testClass.getJavaClass().getAnnotation(InjectWith.class);
+		if (injectWith != null) {
+			return injectorProviderClassCache.get(injectWith.value());
+		}
+		return null;
+	}
+
+	public static IInjectorProvider createInjectorProvider(TestClass testClass) {
+		InjectWith injectWith = testClass.getJavaClass().getAnnotation(InjectWith.class);
+		if (injectWith != null) {
+			try {
+				return injectWith.value().newInstance();
+			} catch (Exception e) {
+				throwUncheckedException(e);
+			}
+		}
+		return null;
+	}
+
+}

+ 13 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.testframework/src/be/uantwerpen/ansymo/semanticadaptation/testframework/XtextParametersRunnerFactory.java

@@ -0,0 +1,13 @@
+package be.uantwerpen.ansymo.semanticadaptation.testframework;
+
+import org.junit.runner.Runner;
+import org.junit.runners.model.InitializationError;
+import org.junit.runners.parameterized.ParametersRunnerFactory;
+import org.junit.runners.parameterized.TestWithParameters;
+
+public class XtextParametersRunnerFactory implements ParametersRunnerFactory {
+	@Override
+	public Runner createRunnerForTestWithParameters(TestWithParameters test) throws InitializationError {
+		return new XtextRunnerWithParameters(test);
+	}
+}

+ 68 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.testframework/src/be/uantwerpen/ansymo/semanticadaptation/testframework/XtextRunnerWithParameters.java

@@ -0,0 +1,68 @@
+package be.uantwerpen.ansymo.semanticadaptation.testframework;
+
+import org.eclipse.xtext.testing.IInjectorProvider;
+import org.eclipse.xtext.testing.IRegistryConfigurator;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.Statement;
+import org.junit.runners.parameterized.BlockJUnit4ClassRunnerWithParameters;
+import org.junit.runners.parameterized.TestWithParameters;
+
+import com.google.inject.Injector;
+
+public class XtextRunnerWithParameters extends BlockJUnit4ClassRunnerWithParameters {
+	public XtextRunnerWithParameters(TestWithParameters test) throws InitializationError {
+		super(test);
+	}
+
+	@Override
+	public Object createTest() throws Exception {
+		Object object = super.createTest();
+		IInjectorProvider injectorProvider = getOrCreateInjectorProvider();
+		if (injectorProvider != null) {
+			Injector injector = injectorProvider.getInjector();
+			if (injector != null)
+				injector.injectMembers(object);
+		}
+		return object;
+	}
+
+	@Override
+	protected Statement methodBlock(FrameworkMethod method) {
+		IInjectorProvider injectorProvider = getOrCreateInjectorProvider();
+		if (injectorProvider instanceof IRegistryConfigurator) {
+			final IRegistryConfigurator registryConfigurator = (IRegistryConfigurator) injectorProvider;
+			registryConfigurator.setupRegistry();
+			final Statement methodBlock = superMethodBlock(method);
+			return new Statement() {
+				@Override
+				public void evaluate() throws Throwable {
+					try {
+						methodBlock.evaluate();
+					} finally {
+						registryConfigurator.restoreRegistry();
+					}
+				}
+			};
+		}else{
+			return superMethodBlock(method);
+		}
+	}
+
+	protected Statement superMethodBlock(FrameworkMethod method) {
+		return super.methodBlock(method);
+	}
+
+	protected IInjectorProvider getOrCreateInjectorProvider() {
+		return InjectorProviders.getOrCreateInjectorProvider(getTestClass());
+	}
+
+	protected IInjectorProvider getInjectorProvider() {
+		return InjectorProviders.getInjectorProvider(getTestClass());
+	}
+
+	protected IInjectorProvider createInjectorProvider() {
+		return InjectorProviders.createInjectorProvider(getTestClass());
+	}
+
+}

+ 3 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/META-INF/MANIFEST.MF

@@ -12,7 +12,9 @@ Require-Bundle: be.uantwerpen.ansymo.semanticadaptation,
  org.eclipse.xtext.xbase.lib,
  org.eclipse.jdt.core,
  org.eclipse.xtext.testing,
- org.eclipse.xtext.xbase.testing
+ org.eclipse.xtext.xbase.testing,
+ be.uantwerpen.ansymo.semanticadaptation.testframework;bundle-version="1.0.0",
+ org.apache.commons.io;bundle-version="2.2.0"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Export-Package: be.uantwerpen.ansymo.semanticadaptation.tests;x-internal=true
 Import-Package: org.hamcrest.core,

+ 0 - 3
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/src/be/uantwerpen/ansymo/semanticadaptation/tests/AbstractSemanticAdaptationTest.xtend

@@ -1,6 +1,3 @@
-/*
- * generated by Xtext 2.10.0
- */
 package be.uantwerpen.ansymo.semanticadaptation.tests
 
 import org.eclipse.xtext.junit4.InjectWith

+ 97 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/src/be/uantwerpen/ansymo/semanticadaptation/tests/BasicParserTest.xtend

@@ -0,0 +1,97 @@
+package be.uantwerpen.ansymo.semanticadaptation.tests
+
+import java.util.regex.Pattern
+import org.eclipse.emf.ecore.EObject
+import org.eclipse.emf.ecore.resource.ResourceSet
+import org.eclipse.xtext.testing.util.ParseHelper
+import com.google.inject.Inject
+import org.eclipse.xtext.testing.validation.ValidationTestHelper
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SemanticAdaptation
+import java.io.File
+import java.util.List
+import org.eclipse.xtext.util.Arrays
+import org.eclipse.xtext.validation.Issue
+import com.google.common.base.Predicate
+import static org.junit.Assert.fail
+import static com.google.common.collect.Iterables.isEmpty
+import static com.google.common.collect.Iterables.filter
+import org.eclipse.xtext.diagnostics.Severity
+
+abstract class BasicParserTest extends AbstractSemanticAdaptationTest {
+
+	@Inject extension ParseHelper<SemanticAdaptation>
+	@Inject extension  ValidationTestHelper
+
+	def __parseNoErrors(File filename) {
+		val model = __parse(filename)
+		__assertNoParseErrors(model, filename)
+	}
+
+	def __parseNoErrorsPrint(File filename) {
+		val root = __parse(filename)
+		print_ast(root)
+		__assertNoParseErrors(root, filename)
+	}
+
+	def __parse(File filename) {
+		val model = readFile(filename).parse
+		return model;
+	}
+
+	def __parse(File filename, ResourceSet resourceSetToUse) {
+
+		return readFile(filename).parse(resourceSetToUse)
+	}
+
+	def __assertNoParseIssues(EObject root, File filename) {
+
+		val List<Issue> validate = root.validate();
+		val Iterable<Issue> issues = filter(validate, new Predicate<Issue>() {
+
+			override apply(Issue input) {
+
+				return Severity.ERROR == input.getSeverity() && !input.code.contains("Linking");
+
+//				if (issuecode.equals(input.getCode())) {
+//					return userData == null || Arrays.contains(input.getData(), userData);
+//				}
+//				return false;
+			}
+
+		});
+		if (!isEmpty(issues))
+			// fail("Expected no errors, but got :" + root.getIssuesAsString(resource, issues, new StringBuilder()));
+			__assertNoParseErrors(root, filename) // we are bit lazy
+	}
+
+	def __assertNoParseErrors(EObject root, File filename) {
+		try {
+			root.assertNoErrors
+		} catch (AssertionError e) {
+			val p = Pattern.compile(".*, offset (?<offset>[0-9]+), length (?<length>[0-9]+)")
+			val code = readFile(filename)
+			for (String line : e.message.split("\n")) {
+				val m = p.matcher(line)
+				m.matches()
+				val count = __occurrencesInString(code.subSequence(0, Integer.valueOf(m.group("offset"))).toString(),
+					"\n")
+				print(filename + " at line " + (count + 1) + ": ")
+				println(line)
+			}
+			throw e
+		}
+	}
+
+	def __occurrencesInString(String str, String findstr) {
+		var lastIndex = 0
+		var count = 0
+		while (lastIndex != -1) {
+			lastIndex = str.indexOf(findstr, lastIndex)
+			if (lastIndex != -1) {
+				count++
+				lastIndex += findstr.length()
+			}
+		}
+		return count
+	}
+}

+ 41 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/src/be/uantwerpen/ansymo/semanticadaptation/tests/ParserFolderTest.xtend

@@ -0,0 +1,41 @@
+package be.uantwerpen.ansymo.semanticadaptation.tests
+
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SemanticAdaptation
+import be.uantwerpen.ansymo.semanticadaptation.testframework.XtextParametersRunnerFactory
+import java.io.File
+import org.apache.commons.io.FileUtils
+import org.eclipse.xtext.testing.InjectWith
+import org.junit.Assert
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.Parameterized
+
+@RunWith(typeof(Parameterized))
+@InjectWith(SemanticAdaptationInjectorProvider)
+@Parameterized.UseParametersRunnerFactory(XtextParametersRunnerFactory)
+abstract class ParserFolderTest extends BasicParserTest{
+	
+	val File directory;
+	new (File directory){
+		this.directory = directory; 
+	}
+	
+	@Test
+	def test() {
+		val File[] files = FileUtils.listFiles(this.directory, #["sa"], true);
+		Assert.assertFalse("The folder " + this.directory + " does not contain any .sa files", files.isEmpty);
+
+		var SemanticAdaptation model = null;
+		for (File file : files) {
+			System.out.println("Processing file: "+file)
+			if (model === null) {
+				model = __parse(file);
+			} else {
+				model = __parse(file, model.eResource.resourceSet);
+			}
+			
+			__assertNoParseIssues(model,file)
+		}
+			__assertNoParseErrors(model, null)
+	}
+}

+ 34 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/src/be/uantwerpen/ansymo/semanticadaptation/tests/SingleFolderTest.xtend

@@ -0,0 +1,34 @@
+package be.uantwerpen.ansymo.semanticadaptation.tests
+
+import java.io.File
+import java.util.Collection
+import java.util.List
+import java.util.Vector
+import org.junit.runners.Parameterized.Parameters
+import org.junit.runner.RunWith
+import org.junit.runners.Parameterized
+import org.eclipse.xtext.testing.InjectWith
+import be.uantwerpen.ansymo.semanticadaptation.testframework.XtextParametersRunnerFactory
+
+@RunWith(typeof(Parameterized))
+@InjectWith(SemanticAdaptationInjectorProvider)
+@Parameterized.UseParametersRunnerFactory(XtextParametersRunnerFactory)
+class SingleFolderTest extends ParserFolderTest {
+	
+	@Parameters(name = "{index} - {0}")
+	def static Collection<Object[]> data() {
+		
+		val List<Object[]> tests = new Vector
+		
+		for (file : new File("testInputs/single_folder_spec".replace('/',File.separatorChar)).listFiles) {
+			tests.add(#[file]);
+		}
+		
+		return tests;
+	}
+	
+	new(File directory) {
+		super(directory)
+	}
+	
+}

+ 13 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/testInputs/single_folder_spec/window/powerwindow_algebraic_loop_delay.sa

@@ -0,0 +1,13 @@
+import PowerWindowModel
+import Controller_SA
+
+module Algebraic_Loop_SA
+
+// this one could be joined with the one below, if we assume certain priorities in executing the rules
+semantic adaptation WindowSA window_sa
+at "./path/to/WindowSA.fmu"
+for fmu window
+out rules {
+	reaction_torque := -reaction_torque;
+	delay at reaction_torque and height;
+}

+ 23 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/testInputs/single_folder_spec/window/powerwindow_controller_delay.sa

@@ -0,0 +1,23 @@
+import PowerWindowModel
+
+module Controller_SA
+
+semantic adaptation ArmatureCurrentSA armature_current_sa
+at "./path/to/ArmatureCurrentSA.fmu"
+for fmu controller
+triggered by signal == true
+in rules with crossing absolute tolerance = 1e-8 and relative tolerance = 0.0001, no hold {
+	armature_current >! 5 -> obj_detected := true;
+	otherwise -> obj_detected := false;
+}
+
+semantic adaptation InOutSA in_out_sa
+at "./path/to/InOutSA.fmu"
+for fmu controller
+out rules with zero order hold {
+	"up" -> up := 1;
+	"stop" -> { up := 0; down := 0; };
+	"down" -> down := 1;
+	delay at up and down;
+}
+

+ 27 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/testInputs/single_folder_spec/window/powerwindow_model_only.sa

@@ -0,0 +1,27 @@
+module PowerWindowModel
+
+fmu Environment environment
+at "./path/to/Environment.fmu"
+output ports passenger_up, passenger_down, driver_up, driver_down
+
+fmu Controller controller
+at "./path/to/Controller.fmu"
+input ports obj_detected, passenger_up, passenger_down, driver_up, driver_down
+output ports up, down, stop
+
+fmu Power power
+at "./path/to/Power.fmu"
+input ports up, down, reaction_torque (N.m)
+output ports armature_current (mA), motor_speed (m/s)
+
+fmu Window window
+at "./path/to/Window.fmu"
+input ports motor_speed (m/s), reaction_force (N)
+output ports height (cm), reaction_torque (N.m)
+
+fmu Obstacle obstacle
+at "./path/to/Obstacle.fmu"
+input ports height (m)
+output ports reaction_force (N)
+
+power.armature_current -> controller.obj_detected

+ 13 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/testInputs/single_folder_spec/window2/powerwindow_algebraic_loop_delay.sa

@@ -0,0 +1,13 @@
+import PowerWindowModel
+import Controller_SA
+
+module Algebraic_Loop_SA
+
+// this one could be joined with the one below, if we assume certain priorities in executing the rules
+semantic adaptation WindowSA window_sa
+at "./path/to/WindowSA.fmu"
+for fmu window
+out rules {
+	reaction_torque := -reaction_torque;
+	delay at reaction_torque and height;
+}

+ 23 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/testInputs/single_folder_spec/window2/powerwindow_controller_delay.sa

@@ -0,0 +1,23 @@
+import PowerWindowModel
+
+module Controller_SA
+
+semantic adaptation ArmatureCurrentSA armature_current_sa
+at "./path/to/ArmatureCurrentSA.fmu"
+for fmu controller
+triggered by signal == true
+in rules with crossing absolute tolerance = 1e-8 and relative tolerance = 0.0001, no hold {
+	armature_current >! 5 -> obj_detected := true;
+	otherwise -> obj_detected := false;
+}
+
+semantic adaptation InOutSA in_out_sa
+at "./path/to/InOutSA.fmu"
+for fmu controller
+out rules with zero order hold {
+	"up" -> up := 1;
+	"stop" -> { up := 0; down := 0; };
+	"down" -> down := 1;
+	delay at up and down;
+}
+

+ 27 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/testInputs/single_folder_spec/window2/powerwindow_model_only.sa

@@ -0,0 +1,27 @@
+module PowerWindowModel
+
+fmu Environment environment
+at "./path/to/Environment.fmu"
+output ports passenger_up, passenger_down, driver_up, driver_down
+
+fmu Controller controller
+at "./path/to/Controller.fmu"
+input ports obj_detected, passenger_up, passenger_down, driver_up, driver_down
+output ports up, down, stop
+
+fmu Power power
+at "./path/to/Power.fmu"
+input ports up, down, reaction_torque (N.m)
+output ports armature_current (mA), motor_speed (m/s)
+
+fmu Window window
+at "./path/to/Window.fmu"
+input ports motor_speed (m/s), reaction_force (N)
+output ports height (cm), reaction_torque (N.m)
+
+fmu Obstacle obstacle
+at "./path/to/Obstacle.fmu"
+input ports height (m)
+output ports reaction_force (N)
+
+power.armature_current -> controller.obj_detected

+ 1 - 0
DSL_SemanticAdaptation/pom.xml

@@ -11,6 +11,7 @@
 
 	<!-- the mavenization is based on this approach https://github.com/xtext/maven-xtext-example -->
 	<modules>
+		<module>be.uantwerpen.ansymo.semanticadaptation.testframework</module>
 		<module>be.uantwerpen.ansymo.semanticadaptation</module>
 		<module>be.uantwerpen.ansymo.semanticadaptation.tests</module>
 		<module>be.uantwerpen.ansymo.semanticadaptation.ide</module>