SemanticAdaptationGeneratorTest.xtend 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * generated by Xtext 2.10.0
  3. */
  4. package be.uantwerpen.ansymo.semanticadaptation.tests
  5. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Adaptation
  6. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Assignment
  7. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.AtomicUnity
  8. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.BoolLiteral
  9. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CompositeOutputFunction
  10. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CustomControlRule
  11. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.InnerFMU
  12. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.MultiplyUnity
  13. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Port
  14. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SemanticAdaptation
  15. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Variable
  16. import com.google.inject.Inject
  17. import org.eclipse.xtext.testing.InjectWith
  18. import org.eclipse.xtext.testing.XtextRunner
  19. import org.eclipse.xtext.util.IAcceptor
  20. import org.eclipse.xtext.xbase.testing.CompilationTestHelper
  21. import org.eclipse.xtext.xbase.testing.CompilationTestHelper.Result
  22. import org.junit.Assert
  23. import org.junit.Test
  24. import org.junit.runner.RunWith
  25. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Declaration
  26. @RunWith(XtextRunner)
  27. @InjectWith(SemanticAdaptationInjectorProvider)
  28. class SemanticAdaptationGeneratorTest extends AbstractSemanticAdaptationTest{
  29. @Inject extension CompilationTestHelper
  30. @Test def test_inferTypesAndUnits_sample1() { __generate('input/canonical_generation/sample1.sa', new IAcceptor<CompilationTestHelper.Result>(){
  31. override accept(Result t) {
  32. var Adaptation sa = t.resourceSet.resources.head.allContents.toIterable.filter(SemanticAdaptation).last.elements.filter(Adaptation).head
  33. sa.name == "outerFMU"
  34. sa.eAllContents.filter(Port).filter[p | p.name=="ext_input_port3"].head.unity instanceof MultiplyUnity
  35. sa.eAllContents.filter(InnerFMU).filter[f | f.name=="innerFMU2"].head
  36. .eAllContents.filter(Port).filter[p | p.name=="innerFMU2__input_port1"].head.type == "Real"
  37. sa.eAllContents.filter(InnerFMU).filter[f | f.name=="innerFMU2"].head
  38. .eAllContents.filter(Port).filter[p | p.name=="innerFMU2__outout_port1"].head.type == "Real"
  39. sa.eAllContents.filter(InnerFMU).filter[f | f.name=="innerFMU2"].head
  40. .eAllContents.filter(Port).filter[p | p.name=="innerFMU2__outout_port1"].head.unity instanceof AtomicUnity
  41. }
  42. }) }
  43. @Test def test_addInputPorts_sample1() { __generate('input/canonical_generation/sample1.sa', new IAcceptor<CompilationTestHelper.Result>(){
  44. override accept(Result t) {
  45. var Adaptation sa = t.resourceSet.resources.head.allContents.toIterable.filter(SemanticAdaptation).last.elements.filter(Adaptation).head
  46. sa.inports.filter[p | p.name=="innerFMU1__input_port2"].head.type == "Bool"
  47. sa.inports.filter[p | p.name=="innerFMU1__input_port1"].size == 0
  48. //sa.inports.filter[p | p.name=="innerFMU2__input_port3"].head.targetdependency.owner.name == "innerFMU2"
  49. //sa.inports.filter[p | p.name=="innerFMU2__input_port3"].head.targetdependency.port.name == "input_port3"
  50. }
  51. }) }
  52. @Test def test_addParams_sample1() { __generate('input/canonical_generation/sample1.sa', new IAcceptor<CompilationTestHelper.Result>(){
  53. override accept(Result t) {
  54. var Adaptation sa = t.resourceSet.resources.head.allContents.toIterable.filter(SemanticAdaptation).last.elements.filter(Adaptation).head
  55. sa.params.head.declarations.filter[p | p.name=="INIT_EXT_INPUT_PORT3"].head.type == "Real"
  56. sa.params.head.declarations.filter[p | p.name=="INIT_INNERFMU1__INPUT_PORT2"].head.expr instanceof BoolLiteral
  57. }
  58. }) }
  59. @Test def test_addInVars_sample1() { __generate('input/canonical_generation/sample1.sa', new IAcceptor<CompilationTestHelper.Result>(){
  60. override accept(Result t) {
  61. var Adaptation sa = t.resourceSet.resources.head.allContents.toIterable.filter(SemanticAdaptation).last.elements.filter(Adaptation).head
  62. sa.in.globalInVars.head.declarations.filter[p | p.name=="stored__innerFMU2__input_port2"].head.type == "Bool"
  63. sa.in.globalInVars.head.declarations.filter[p | p.name=="stored__innerFMU2__input_port3"].head.expr instanceof Variable
  64. }
  65. }) }
  66. @Test def test_addOutVars_sample1() { __generate('input/canonical_generation/sample1.sa', new IAcceptor<CompilationTestHelper.Result>(){
  67. override accept(Result t) {
  68. var Adaptation sa = t.resourceSet.resources.head.allContents.toIterable.filter(SemanticAdaptation).last.elements.filter(Adaptation).head
  69. sa.out.globalOutVars.head.declarations.filter[p | p.name=="stored__innerFMU1__output_port2"].head.type == "Integer"
  70. }
  71. }) }
  72. @Test def test_addExternal2InputPortStoredAssignments_sample1() { __generate('input/canonical_generation/sample1.sa', new IAcceptor<CompilationTestHelper.Result>(){
  73. override accept(Result t) {
  74. var Adaptation sa = t.resourceSet.resources.head.allContents.toIterable.filter(SemanticAdaptation).last.elements.filter(Adaptation).head
  75. sa.in.rules.head.statetransitionfunction.statements.head instanceof Assignment
  76. (sa.in.rules.head.statetransitionfunction.statements.head as Assignment).lvalue.ref.name == "stored__innerFMU2__input_port3"
  77. ((sa.in.rules.head.statetransitionfunction.statements.head as Assignment).expr as Variable).ref.name == "innerFMU2__input_port3"
  78. }
  79. }) }
  80. @Test def test_addInternal2OutputPortStoredAssignments_sample1() { __generate('input/canonical_generation/sample1.sa', new IAcceptor<CompilationTestHelper.Result>(){
  81. override accept(Result t) {
  82. var Adaptation sa = t.resourceSet.resources.head.allContents.toIterable.filter(SemanticAdaptation).last.elements.filter(Adaptation).head
  83. var firstAssignment = sa.out.rules.head.statetransitionfunction.statements.head as Assignment
  84. Assert.assertNotEquals((firstAssignment.expr as Variable).owner.name, "outerFMU_BASE")
  85. }
  86. }) }
  87. @Test def test_addInRules_External2Internal_Assignments_sample1() { __generate('input/canonical_generation/sample1.sa', new IAcceptor<CompilationTestHelper.Result>(){
  88. override accept(Result t) {
  89. var Adaptation sa = t.resourceSet.resources.head.allContents.toIterable.filter(SemanticAdaptation).last.elements.filter(Adaptation).head
  90. val outFunction = sa.in.rules.head.outputfunction as CompositeOutputFunction
  91. val firstAssignment = outFunction.statements.head as Assignment
  92. firstAssignment.lvalue.ref.name == "input_port3"
  93. (firstAssignment.expr as Variable).ref.name == "innerFMU2__input_port3"
  94. }
  95. }) }
  96. @Test def test_addOutRules_Internal2External_Assignments_sample1() { __generate('input/canonical_generation/sample1.sa', new IAcceptor<CompilationTestHelper.Result>(){
  97. override accept(Result t) {
  98. var Adaptation sa = t.resourceSet.resources.head.allContents.toIterable.filter(SemanticAdaptation).last.elements.filter(Adaptation).head
  99. val outFunction = sa.out.rules.head.outputfunction as CompositeOutputFunction
  100. val firstAssignment = outFunction.statements.head as Assignment
  101. firstAssignment.lvalue.ref.name == "innerFMU2__output_port2"
  102. (firstAssignment.expr as Variable).owner.name == "innerFMU2"
  103. }
  104. }) }
  105. @Test def test_removeInBindings_sample1() { __generate('input/canonical_generation/sample1.sa', new IAcceptor<CompilationTestHelper.Result>(){
  106. override accept(Result t) {
  107. var Adaptation sa = t.resourceSet.resources.head.allContents.toIterable.filter(SemanticAdaptation).last.elements.filter(Adaptation).head
  108. sa.inports.forall[p | p.targetdependency === null]
  109. }
  110. }) }
  111. @Test def test_removeOutBindings_sample1() { __generate('input/canonical_generation/sample1.sa', new IAcceptor<CompilationTestHelper.Result>(){
  112. override accept(Result t) {
  113. var Adaptation sa = t.resourceSet.resources.head.allContents.toIterable.filter(SemanticAdaptation).last.elements.filter(Adaptation).head
  114. sa.outports.forall[p | p.sourcedependency === null]
  115. }
  116. }) }
  117. @Test def test_addOutParams_sample1() { __generate('input/canonical_generation/sample1.sa', new IAcceptor<CompilationTestHelper.Result>(){
  118. override accept(Result t) {
  119. var Adaptation sa = t.resourceSet.resources.head.allContents.toIterable.filter(SemanticAdaptation).last.elements.filter(Adaptation).head
  120. sa.params.head.declarations.filter[p | p.name == "INIT_INNERFMU2__OUTPUT_PORT2"].size == 1
  121. }
  122. }) }
  123. @Test def test_createCoSimStepInstructions_sample2() { __generate('input/canonical_generation/sample2.sa', new IAcceptor<CompilationTestHelper.Result>(){
  124. override accept(Result t) {
  125. var Adaptation sa = t.resourceSet.resources.head.allContents.toIterable.filter(SemanticAdaptation).last.elements.filter(Adaptation).head()
  126. (sa.control.rule as CustomControlRule).controlRulestatements.filter[s | s instanceof Declaration].size>4
  127. }
  128. }) }
  129. @Test def test_createInternalBindingAssignments_sample2() { __generate('input/canonical_generation/sample2.sa', new IAcceptor<CompilationTestHelper.Result>(){
  130. override accept(Result t) {
  131. var Adaptation sa = t.resourceSet.resources.head.allContents.toIterable.filter(SemanticAdaptation).last.elements.filter(Adaptation).head()
  132. (sa.control.rule as CustomControlRule).controlRulestatements.filter[s | s instanceof Assignment].size>4
  133. }
  134. }) }
  135. @Test def window_SA_parseNoExceptions() { __generate('input/power_window_case_study/window_sa.BASE.sa', new IAcceptor<CompilationTestHelper.Result>(){
  136. override accept(Result t) { }
  137. }) }
  138. @Test def window_SA_parseNoExceptions2() { __generate('input/power_window_case_study/window_sa_comp_units.sa', new IAcceptor<CompilationTestHelper.Result>(){
  139. override accept(Result t) { }
  140. }) }
  141. @Test def lazy_SA_parseNoExceptions() { __generate('input/power_window_case_study/lazy.sa', new IAcceptor<CompilationTestHelper.Result>(){
  142. override accept(Result t) { }
  143. }) }
  144. def void __generate(String filename, IAcceptor<CompilationTestHelper.Result> acceptor) {
  145. //readFile(filename).assertCompilesTo('oracles/power_window_case_study/lazy.BASE.sa')
  146. readFile(filename).compile(acceptor)
  147. }
  148. }