From 4e88dec65619b4dbac88893db5afa9a502136e07 Mon Sep 17 00:00:00 2001 From: Peter Lunk Date: Wed, 29 Apr 2015 13:09:23 +0200 Subject: [PATCH] Added test cases for the basic CPP types --- .../test/TransformationTest.xtend | 2 +- .../test/TransformationTestUtil.xtend | 27 +++- .../test/dynamicbehavior/DummyTest.xtend | 31 ---- .../mappings/CPPAttributeMappingTest.xtend | 103 ++++++++++++ .../test/mappings/CPPClassMappingTest.xtend | 153 ++++++++++++++++++ .../mappings/CPPComponentMappingTest.xtend | 108 +++++++++++++ ...ngTest.xtend => CPPEventMappingTest.xtend} | 29 ++-- .../mappings/CPPOperationMappingTest.xtend | 104 ++++++++++++ .../test/mappings/CPPPackageMappingTest.xtend | 92 +++++++++++ .../test/mappings/CPPPortMappingTest.xtend | 69 ++++++++ .../mappings/CPPProtocolMappingTest.xtend | 97 +++++++++++ .../test/mappings/CPPSignalMappingTest.xtend | 57 +++++++ .../test/mappings/CPPStateMappingTest.xtend | 108 +++++++++++++ .../mappings/CPPTransitionMappingTest.xtend | 134 +++++++++++++++ .../test/mappings/MappingBaseTest.xtend | 46 ++++++ .../test/wrappers/DummyWrapper.xtend | 20 --- 16 files changed, 1115 insertions(+), 65 deletions(-) delete mode 100644 com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/dynamicbehavior/DummyTest.xtend create mode 100644 com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPAttributeMappingTest.xtend create mode 100644 com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPClassMappingTest.xtend create mode 100644 com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPComponentMappingTest.xtend rename com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/{StateMappingTest.xtend => CPPEventMappingTest.xtend} (72%) create mode 100644 com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPOperationMappingTest.xtend create mode 100644 com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPPackageMappingTest.xtend create mode 100644 com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPPortMappingTest.xtend create mode 100644 com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPProtocolMappingTest.xtend create mode 100644 com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPSignalMappingTest.xtend create mode 100644 com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPStateMappingTest.xtend create mode 100644 com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPTransitionMappingTest.xtend create mode 100644 com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/MappingBaseTest.xtend delete mode 100644 com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/wrappers/DummyWrapper.xtend diff --git a/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/TransformationTest.xtend b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/TransformationTest.xtend index 7f352c54..80bdaf0e 100644 --- a/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/TransformationTest.xtend +++ b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/TransformationTest.xtend @@ -25,7 +25,7 @@ abstract class TransformationTest [ + it.name = name + ] + root.topEntities += comp + comp + } static def createXtClass(XTComponent root, String name) { var xtclass = xtumlFactory.createXTClass => [ @@ -122,14 +130,23 @@ class TransformationTestUtil { root.entities += xtclass xtclass } + + static def createXtClass(Model root, String name) { + var xtclass = xtumlFactory.createXTClass => [ + it.name = name + ] + root.topEntities += xtclass + xtclass + } - static def createStateMachine(XTClass root, String name) { + static def createStateMachine(Entity root, String name) { var sm = commonFactory.createStateMachine => [ it.name = name ] root.behaviour = sm sm } + static def createXtProtocol(XTPackage root, String name) { var protocol = xtumlFactory.createXTProtocol => [ @@ -138,6 +155,14 @@ class TransformationTestUtil { root.protocols += protocol protocol } + + static def createXtProtocol(Model root, String name) { + var protocol = xtumlFactory.createXTProtocol => [ + it.name = name + ] + root.topProtocols += protocol + protocol + } static def createSignal(XTProtocol root, String name) { var signal = commonFactory.createSignal => [ diff --git a/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/dynamicbehavior/DummyTest.xtend b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/dynamicbehavior/DummyTest.xtend deleted file mode 100644 index aa943e9c..00000000 --- a/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/dynamicbehavior/DummyTest.xtend +++ /dev/null @@ -1,31 +0,0 @@ -package com.incquerylabs.emdw.cpp.transformation.test.dynamicbehavior - -import com.ericsson.xtumlrt.oopl.cppmodel.CPPClass -import com.ericsson.xtumlrt.oopl.cppmodel.CPPModel -import com.incquerylabs.emdw.cpp.transformation.test.TransformationTest -import com.incquerylabs.emdw.cpp.transformation.test.wrappers.TransformationWrapper -import org.eclipse.papyrusrt.xtumlrt.common.Model -import org.eclipse.papyrusrt.xtumlrt.xtuml.XTClass -import org.junit.runner.RunWith -import org.junit.runners.Parameterized - -import static org.junit.Assert.assertEquals - -@RunWith(Parameterized) -class DummyTest extends TransformationTest { - - new(TransformationWrapper wrapper, String wrapperType) { - super(wrapper, wrapperType) - } - - override protected prepareXtUmlModel(Model xtumlmodel) { - } - - override protected prepareCppModel(CPPModel cppModel) { - } - - override protected assertResult(Model input, CPPModel result, XTClass xtObject, CPPClass cppObject) { - assertEquals("","") - } - -} \ No newline at end of file diff --git a/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPAttributeMappingTest.xtend b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPAttributeMappingTest.xtend new file mode 100644 index 00000000..a2ac2f44 --- /dev/null +++ b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPAttributeMappingTest.xtend @@ -0,0 +1,103 @@ +package com.incquerylabs.emdw.cpp.transformation.test.mappings + +import com.ericsson.xtumlrt.oopl.cppmodel.CPPAttribute +import com.ericsson.xtumlrt.oopl.cppmodel.CPPClass +import com.ericsson.xtumlrt.oopl.cppmodel.CPPComponent +import com.ericsson.xtumlrt.oopl.cppmodel.CPPModel +import com.incquerylabs.emdw.cpp.transformation.test.wrappers.TransformationWrapper +import org.eclipse.papyrusrt.xtumlrt.common.Model +import org.eclipse.papyrusrt.xtumlrt.common.VisibilityKind +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTClass +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTComponent +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTPackage +import org.junit.runner.RunWith +import org.junit.runners.Parameterized + +import static org.junit.Assert.* + +import static extension com.incquerylabs.emdw.cpp.transformation.test.TransformationTestUtil.* + +@RunWith(Parameterized) +class CPPAttributeInClassTest extends MappingBaseTest { + new(TransformationWrapper wrapper, String wrapperType) { + super(wrapper, wrapperType) + } + + override protected prepareXtUmlModel(Model model) { + val pack = model.createXtPackage("RootPackage") + val component = pack.createXtComponent("Component") + val xtClass = component.createXtClass("Class") + xtClass.createSingleAttribute(xtClass, VisibilityKind.PUBLIC, false, "Attribute") + + xtClass + } + + override protected prepareCppModel(CPPModel cppModel) { + val xtmodel = cppModel.commonModel + val xtPackage = xtmodel.rootPackages.head as XTPackage + val cppPackage = createCPPPackage(cppModel, xtPackage) + val xtComponent = xtPackage.entities.head as XTComponent + val cppComponent = createCPPComponent(cppPackage, xtComponent, null, null, null, null) + val xtClass = xtComponent.ownedClasses.head as XTClass + val cppClass = createCPPClass(cppComponent, xtClass, null, null) + + cppClass + } + + override protected assertResult(Model input, CPPModel result, XTClass xtObject, CPPClass cppObject) { + val xtAttr = xtObject.attributes + val cppAttrs = cppObject.subElements.filter(CPPAttribute) + assertEquals(xtAttr.size,cppAttrs.size) + cppAttrs.forEach[ + assertNotNull(ooplNameProvider) + assertNotNull(commonAttribute) + ] + } + + override protected clearXtUmlElement(XTClass xtObject) { + xtObject.attributes.clear + } + +} + + +@RunWith(Parameterized) +class CPPAttributeInComponentTest extends MappingBaseTest { + new(TransformationWrapper wrapper, String wrapperType) { + super(wrapper, wrapperType) + } + + override protected prepareXtUmlModel(Model model) { + val pack = model.createXtPackage("RootPackage") + val component = pack.createXtComponent("Component") + val xtClass = component.createXtClass("Class") + component.createSingleAttribute(xtClass, VisibilityKind.PUBLIC, false, "Attribute") + + component + } + + override protected prepareCppModel(CPPModel cppModel) { + val xtmodel = cppModel.commonModel + val xtPackage = xtmodel.rootPackages.head as XTPackage + val cppPackage = createCPPPackage(cppModel, xtPackage) + val xtComponent = xtPackage.entities.head as XTComponent + val cppComponent = createCPPComponent(cppPackage, xtComponent, null, null, null, null) + + cppComponent + } + + override protected assertResult(Model input, CPPModel result, XTComponent xtObject, CPPComponent cppObject) { + val xtAttr = xtObject.attributes + val cppAttrs = cppObject.subElements.filter(CPPAttribute) + assertEquals(xtAttr.size,cppAttrs.size) + cppAttrs.forEach[ + assertNotNull(ooplNameProvider) + assertNotNull(commonAttribute) + ] + } + + override protected clearXtUmlElement(XTComponent xtObject) { + xtObject.attributes.clear + } + +} \ No newline at end of file diff --git a/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPClassMappingTest.xtend b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPClassMappingTest.xtend new file mode 100644 index 00000000..fc96404a --- /dev/null +++ b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPClassMappingTest.xtend @@ -0,0 +1,153 @@ +package com.incquerylabs.emdw.cpp.transformation.test.mappings + +import com.ericsson.xtumlrt.oopl.cppmodel.CPPClass +import com.ericsson.xtumlrt.oopl.cppmodel.CPPComponent +import com.ericsson.xtumlrt.oopl.cppmodel.CPPDirectory +import com.ericsson.xtumlrt.oopl.cppmodel.CPPModel +import com.ericsson.xtumlrt.oopl.cppmodel.CPPPackage +import com.incquerylabs.emdw.cpp.transformation.test.wrappers.TransformationWrapper +import org.eclipse.papyrusrt.xtumlrt.common.Model +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTClass +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTComponent +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTPackage +import org.junit.runner.RunWith +import org.junit.runners.Parameterized + +import static org.junit.Assert.* + +import static extension com.incquerylabs.emdw.cpp.transformation.test.TransformationTestUtil.* + +@RunWith(Parameterized) +class CPPClassInPackageTest extends MappingBaseTest { + CPPDirectory rootDir; + + new(TransformationWrapper wrapper, String wrapperType) { + super(wrapper, wrapperType) + } + + override protected prepareXtUmlModel(Model model) { + val pack = model.createXtPackage("RootPackage") + pack.createXtClass("Class") + + pack + } + + override protected prepareCppModel(CPPModel cppModel) { + val res = cppModel.eResource + rootDir = res.createCPPDirectory + val xtmodel = cppModel.commonModel + val xtPackage = xtmodel.rootPackages.head as XTPackage + val cppPackage = createCPPPackage(cppModel, xtPackage) + + cppPackage + } + + override protected assertResult(Model input, CPPModel result, XTPackage xtObject, CPPPackage cppObject) { + val xtClasses = xtObject.entities.filter(XTClass) + val cppClasses = cppObject.subElements.filter(CPPClass) + assertEquals(xtClasses.size,cppClasses.size) + assertEquals(xtClasses.size,rootDir.countCppHeaderFiles) + assertEquals(xtClasses.size,rootDir.countCppBodyFiles) + cppClasses.forEach[ + assertNotNull(ooplNameProvider) + assertNotNull(xtClass) + assertNotNull(headerFile) + assertNotNull(bodyFile) + ] + } + + override protected clearXtUmlElement(XTPackage xtObject) { + val classes = xtObject.entities.filter(XTComponent) + xtObject.entities.removeAll(classes) + } + +} + + +@RunWith(Parameterized) +class CPPClassInModelTest extends MappingBaseTest { + CPPDirectory rootDir; + + new(TransformationWrapper wrapper, String wrapperType) { + super(wrapper, wrapperType) + } + + override protected prepareXtUmlModel(Model model) { + model.createXtClass("Class") + + model + } + + override protected prepareCppModel(CPPModel cppModel) { + val res = cppModel.eResource + rootDir = res.createCPPDirectory + cppModel + } + + override protected assertResult(Model input, CPPModel result, Model xtObject, CPPModel cppObject) { + val xtClasses = xtObject.topEntities.filter(XTClass) + val cppClasses = cppObject.subElements.filter(CPPClass) + assertEquals(xtClasses.size,cppClasses.size) + assertEquals(xtClasses.size,rootDir.countCppHeaderFiles) + assertEquals(xtClasses.size,rootDir.countCppBodyFiles) + cppClasses.forEach[ + assertNotNull(ooplNameProvider) + assertNotNull(xtClass) + assertNotNull(headerFile) + assertNotNull(bodyFile) + ] + } + + override protected clearXtUmlElement(Model xtObject) { + val classes = xtObject.topEntities.filter(XTComponent) + xtObject.topEntities.removeAll(classes) + } + +} + +@RunWith(Parameterized) +class CPPClassInComponentTest extends MappingBaseTest { + CPPDirectory rootDir; + + new(TransformationWrapper wrapper, String wrapperType) { + super(wrapper, wrapperType) + } + + override protected prepareXtUmlModel(Model model) { + val pack = model.createXtPackage("RootPackage") + val component = pack.createXtComponent("Component") + component.createXtClass("Class") + + component + } + + override protected prepareCppModel(CPPModel cppModel) { + val res = cppModel.eResource + rootDir = res.createCPPDirectory + val xtmodel = cppModel.commonModel + val xtPackage = xtmodel.rootPackages.head as XTPackage + val cppPackage = createCPPPackage(cppModel, xtPackage) + val xtComponent = xtPackage.entities.head as XTComponent + val cppComponent = createCPPComponent(cppPackage, xtComponent, null, null, null, null) + cppComponent + } + + override protected assertResult(Model input, CPPModel result, XTComponent xtObject, CPPComponent cppObject) { + val xtClasses = xtObject.ownedClasses + val cppClasses = cppObject.subElements.filter(CPPClass) + assertEquals(xtClasses.size,cppClasses.size) + assertEquals(xtClasses.size,rootDir.countCppHeaderFiles) + assertEquals(xtClasses.size,rootDir.countCppBodyFiles) + cppClasses.forEach[ + assertNotNull(ooplNameProvider) + assertNotNull(xtClass) + assertNotNull(headerFile) + assertNotNull(bodyFile) + ] + } + + override protected clearXtUmlElement(XTComponent xtObject) { + xtObject.ownedClasses.clear + } + +} diff --git a/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPComponentMappingTest.xtend b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPComponentMappingTest.xtend new file mode 100644 index 00000000..bb98905f --- /dev/null +++ b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPComponentMappingTest.xtend @@ -0,0 +1,108 @@ +package com.incquerylabs.emdw.cpp.transformation.test.mappings + +import com.ericsson.xtumlrt.oopl.cppmodel.CPPComponent +import com.ericsson.xtumlrt.oopl.cppmodel.CPPDirectory +import com.ericsson.xtumlrt.oopl.cppmodel.CPPModel +import com.ericsson.xtumlrt.oopl.cppmodel.CPPPackage +import com.incquerylabs.emdw.cpp.transformation.test.wrappers.TransformationWrapper +import org.eclipse.papyrusrt.xtumlrt.common.Model +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTComponent +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTPackage +import org.junit.runner.RunWith +import org.junit.runners.Parameterized + +import static org.junit.Assert.* + +import static extension com.incquerylabs.emdw.cpp.transformation.test.TransformationTestUtil.* + +@RunWith(Parameterized) +class CPPComponentInPackageTest extends MappingBaseTest { + CPPDirectory rootDir; + + new(TransformationWrapper wrapper, String wrapperType) { + super(wrapper, wrapperType) + } + + override protected prepareXtUmlModel(Model model) { + val pack = model.createXtPackage("RootPackage") + pack.createXtComponent("component") + + pack + } + + override protected prepareCppModel(CPPModel cppModel) { + val res = cppModel.eResource + rootDir = res.createCPPDirectory + val xtmodel = cppModel.commonModel + val xtPackage = xtmodel.rootPackages.head as XTPackage + val cppPackage = createCPPPackage(cppModel, xtPackage) + + cppPackage + } + + override protected assertResult(Model input, CPPModel result, XTPackage xtObject, CPPPackage cppObject) { + val xtComponents = xtObject.entities.filter(XTComponent) + val cppComponents = cppObject.subElements.filter(CPPComponent) + assertEquals(xtComponents.size,cppComponents.size) + assertEquals(xtComponents.size*3,rootDir.countCppHeaderFiles) + assertEquals(xtComponents.size,rootDir.countCppBodyFiles) + cppComponents.forEach[ + assertNotNull(ooplNameProvider) + assertNotNull(xtComponent) + assertNotNull(mainHeaderFile) + assertNotNull(mainBodyFile) + assertNotNull(declHeaderFile) + assertNotNull(defHeaderFile) + ] + } + + override protected clearXtUmlElement(XTPackage xtObject) { + val components = xtObject.entities.filter(XTComponent) + xtObject.entities.removeAll(components) + } + +} + + +@RunWith(Parameterized) +class CPPComponentInModelTest extends MappingBaseTest { + CPPDirectory rootDir; + + new(TransformationWrapper wrapper, String wrapperType) { + super(wrapper, wrapperType) + } + + override protected prepareXtUmlModel(Model model) { + model.createXtComponent("component") + + model + } + + override protected prepareCppModel(CPPModel cppModel) { + val res = cppModel.eResource + rootDir = res.createCPPDirectory + cppModel + } + + override protected assertResult(Model input, CPPModel result, Model xtObject, CPPModel cppObject) { + val xtComponents = xtObject.topEntities.filter(XTComponent) + val cppComponents = cppObject.subElements.filter(CPPComponent) + assertEquals(xtComponents.size,cppComponents.size) + assertEquals(xtComponents.size*3,rootDir.countCppHeaderFiles) + assertEquals(xtComponents.size,rootDir.countCppBodyFiles) + cppComponents.forEach[ + assertNotNull(ooplNameProvider) + assertNotNull(xtComponent) + assertNotNull(mainHeaderFile) + assertNotNull(mainBodyFile) + assertNotNull(declHeaderFile) + assertNotNull(defHeaderFile) + ] + } + + override protected clearXtUmlElement(Model xtObject) { + val components = xtObject.topEntities.filter(XTComponent) + xtObject.topEntities.removeAll(components) + } + +} diff --git a/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/StateMappingTest.xtend b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPEventMappingTest.xtend similarity index 72% rename from com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/StateMappingTest.xtend rename to com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPEventMappingTest.xtend index 88bd47a7..99a1e144 100644 --- a/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/StateMappingTest.xtend +++ b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPEventMappingTest.xtend @@ -1,12 +1,10 @@ package com.incquerylabs.emdw.cpp.transformation.test.mappings import com.ericsson.xtumlrt.oopl.cppmodel.CPPClass +import com.ericsson.xtumlrt.oopl.cppmodel.CPPEvent import com.ericsson.xtumlrt.oopl.cppmodel.CPPModel -import com.ericsson.xtumlrt.oopl.cppmodel.CPPState -import com.incquerylabs.emdw.cpp.transformation.test.TransformationTest import com.incquerylabs.emdw.cpp.transformation.test.wrappers.TransformationWrapper import org.eclipse.papyrusrt.xtumlrt.common.Model -import org.eclipse.papyrusrt.xtumlrt.common.State import org.eclipse.papyrusrt.xtumlrt.xtuml.XTClass import org.eclipse.papyrusrt.xtumlrt.xtuml.XTComponent import org.eclipse.papyrusrt.xtumlrt.xtuml.XTPackage @@ -18,7 +16,7 @@ import static org.junit.Assert.* import static extension com.incquerylabs.emdw.cpp.transformation.test.TransformationTestUtil.* @RunWith(Parameterized) -class StateMappingTest extends TransformationTest { +class CPPEventMappingTest extends MappingBaseTest { new(TransformationWrapper wrapper, String wrapperType) { super(wrapper, wrapperType) @@ -32,9 +30,10 @@ class StateMappingTest extends TransformationTest { val classEvent = xtClass.createXtClassEvent("ClassEvent") val s1 = topState.createSimpleState("s1") val s2 = topState.createSimpleState("s2") - topState.createTransition(s1,s2,"t2", "SAMPLE_CODE").createXTEventTrigger(classEvent, "Trigger") + val trans = topState.createTransition(s1,s2,"t2", "SAMPLE_CODE") + trans.createXTEventTrigger(classEvent, "Trigger") - topState + xtClass } override protected prepareCppModel(CPPModel cppModel) { @@ -49,13 +48,19 @@ class StateMappingTest extends TransformationTest { cppClass } - override protected assertResult(Model input, CPPModel result, State xtObject, CPPClass cppObject) { - val cppStates = cppObject.subElements.filter(CPPState) - assertFalse(cppStates.exists[commonState == xtObject]) - assertEquals(2,cppStates.size) - cppStates.forEach[ - assertNotNull(commonState) + override protected assertResult(Model input, CPPModel result, XTClass xtObject, CPPClass cppObject) { + val xtEvents = xtObject.events + val cppEvents = cppObject.subElements.filter(CPPEvent) + assertEquals(xtEvents.size,cppEvents.size) + cppEvents.forEach[ + assertNotNull(ooplNameProvider) + assertNotNull(xtEvent) ] } + override protected clearXtUmlElement(XTClass xtObject) { + xtObject.events.clear + } + + } \ No newline at end of file diff --git a/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPOperationMappingTest.xtend b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPOperationMappingTest.xtend new file mode 100644 index 00000000..9808fb33 --- /dev/null +++ b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPOperationMappingTest.xtend @@ -0,0 +1,104 @@ +package com.incquerylabs.emdw.cpp.transformation.test.mappings + +import com.ericsson.xtumlrt.oopl.cppmodel.CPPClass +import com.ericsson.xtumlrt.oopl.cppmodel.CPPComponent +import com.ericsson.xtumlrt.oopl.cppmodel.CPPModel +import com.ericsson.xtumlrt.oopl.cppmodel.CPPOperation +import com.incquerylabs.emdw.cpp.transformation.test.wrappers.TransformationWrapper +import org.eclipse.papyrusrt.xtumlrt.common.DirectionKind +import org.eclipse.papyrusrt.xtumlrt.common.Model +import org.eclipse.papyrusrt.xtumlrt.common.VisibilityKind +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTClass +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTComponent +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTPackage +import org.junit.runner.RunWith +import org.junit.runners.Parameterized + +import static org.junit.Assert.* + +import static extension com.incquerylabs.emdw.cpp.transformation.test.TransformationTestUtil.* + +@RunWith(Parameterized) +class CPPOperationInClassTest extends MappingBaseTest { + new(TransformationWrapper wrapper, String wrapperType) { + super(wrapper, wrapperType) + } + + override protected prepareXtUmlModel(Model model) { + val pack = model.createXtPackage("RootPackage") + val component = pack.createXtComponent("Component") + val xtClass = component.createXtClass("Class") + xtClass.createOperation(VisibilityKind.PUBLIC, false, null,"Attribute", "Body",createParameter(xtClass,"Param",DirectionKind.IN)) + + xtClass + } + + override protected prepareCppModel(CPPModel cppModel) { + val xtmodel = cppModel.commonModel + val xtPackage = xtmodel.rootPackages.head as XTPackage + val cppPackage = createCPPPackage(cppModel, xtPackage) + val xtComponent = xtPackage.entities.head as XTComponent + val cppComponent = createCPPComponent(cppPackage, xtComponent, null, null, null, null) + val xtClass = xtComponent.ownedClasses.head as XTClass + val cppClass = createCPPClass(cppComponent, xtClass, null, null) + + cppClass + } + + override protected assertResult(Model input, CPPModel result, XTClass xtObject, CPPClass cppObject) { + val xtOp = xtObject.operations + val cppOp = cppObject.subElements.filter(CPPOperation) + assertEquals(xtOp.size,cppOp.size) + cppOp.forEach[ + assertNotNull(ooplNameProvider) + assertNotNull(commonOperation) + ] + } + + override protected clearXtUmlElement(XTClass xtObject) { + xtObject.operations.clear + } + +} + + +@RunWith(Parameterized) +class CPPOperationInComponentTest extends MappingBaseTest { + new(TransformationWrapper wrapper, String wrapperType) { + super(wrapper, wrapperType) + } + + override protected prepareXtUmlModel(Model model) { + val pack = model.createXtPackage("RootPackage") + val component = pack.createXtComponent("Component") + val xtClass = component.createXtClass("Class") + component.createOperation(VisibilityKind.PUBLIC, false, null,"Attribute", "Body",createParameter(xtClass,"Param",DirectionKind.IN)) + + component + } + + override protected prepareCppModel(CPPModel cppModel) { + val xtmodel = cppModel.commonModel + val xtPackage = xtmodel.rootPackages.head as XTPackage + val cppPackage = createCPPPackage(cppModel, xtPackage) + val xtComponent = xtPackage.entities.head as XTComponent + val cppComponent = createCPPComponent(cppPackage, xtComponent, null, null, null, null) + + cppComponent + } + + override protected assertResult(Model input, CPPModel result, XTComponent xtObject, CPPComponent cppObject) { + val xtOp = xtObject.operations + val cppOp = cppObject.subElements.filter(CPPOperation) + assertEquals(xtOp.size,cppOp.size) + cppOp.forEach[ + assertNotNull(ooplNameProvider) + assertNotNull(commonOperation) + ] + } + + override protected clearXtUmlElement(XTComponent xtObject) { + xtObject.operations.clear + } + +} \ No newline at end of file diff --git a/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPPackageMappingTest.xtend b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPPackageMappingTest.xtend new file mode 100644 index 00000000..6becccf0 --- /dev/null +++ b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPPackageMappingTest.xtend @@ -0,0 +1,92 @@ +package com.incquerylabs.emdw.cpp.transformation.test.mappings + +import com.ericsson.xtumlrt.oopl.cppmodel.CPPDirectory +import com.ericsson.xtumlrt.oopl.cppmodel.CPPModel +import com.ericsson.xtumlrt.oopl.cppmodel.CPPPackage +import com.incquerylabs.emdw.cpp.transformation.test.wrappers.TransformationWrapper +import org.eclipse.papyrusrt.xtumlrt.common.Model +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTPackage +import org.junit.runner.RunWith +import org.junit.runners.Parameterized + +import static org.junit.Assert.* + +import static extension com.incquerylabs.emdw.cpp.transformation.test.TransformationTestUtil.* + +@RunWith(Parameterized) +class CPPPackageInPackageTest extends MappingBaseTest { + CPPDirectory rootDir; + + new(TransformationWrapper wrapper, String wrapperType) { + super(wrapper, wrapperType) + } + + override protected prepareXtUmlModel(Model model) { + val pack = model.createXtPackage("RootPackage") + pack.createXtPackage("component") + + pack + } + + override protected prepareCppModel(CPPModel cppModel) { + val res = cppModel.eResource + rootDir = res.createCPPDirectory + val xtmodel = cppModel.commonModel + val xtPackage = xtmodel.rootPackages.head as XTPackage + val cppPackage = createCPPPackage(cppModel, xtPackage) + + cppPackage + } + + override protected assertResult(Model input, CPPModel result, XTPackage xtObject, CPPPackage cppObject) { + val xtPackages = xtObject.packages + val cppPackages = cppObject.subElements.filter(CPPPackage) + assertEquals(xtPackages.size,cppPackages.size) + cppPackages.forEach[ + assertNotNull(ooplNameProvider) + assertNotNull(xtPackage) + ] + } + + override protected clearXtUmlElement(XTPackage xtObject) { + xtObject.packages.clear + } + +} + + +@RunWith(Parameterized) +class CPPPackageInModelTest extends MappingBaseTest { + CPPDirectory rootDir; + + new(TransformationWrapper wrapper, String wrapperType) { + super(wrapper, wrapperType) + } + + override protected prepareXtUmlModel(Model model) { + model.createXtPackage("component") + + model + } + + override protected prepareCppModel(CPPModel cppModel) { + val res = cppModel.eResource + rootDir = res.createCPPDirectory + cppModel + } + + override protected assertResult(Model input, CPPModel result, Model xtObject, CPPModel cppObject) { + val xtPackages = xtObject.rootPackages + val cppPackages = cppObject.subElements.filter(CPPPackage) + assertEquals(xtPackages.size,cppPackages.size) + cppPackages.forEach[ + assertNotNull(ooplNameProvider) + assertNotNull(xtPackage) + ] + } + + override protected clearXtUmlElement(Model xtObject) { + xtObject.rootPackages.clear + } + +} diff --git a/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPPortMappingTest.xtend b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPPortMappingTest.xtend new file mode 100644 index 00000000..5ab4c690 --- /dev/null +++ b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPPortMappingTest.xtend @@ -0,0 +1,69 @@ +package com.incquerylabs.emdw.cpp.transformation.test.mappings + +import com.ericsson.xtumlrt.oopl.cppmodel.CPPComponent +import com.ericsson.xtumlrt.oopl.cppmodel.CPPDirectory +import com.ericsson.xtumlrt.oopl.cppmodel.CPPModel +import com.ericsson.xtumlrt.oopl.cppmodel.CPPPort +import com.incquerylabs.emdw.cpp.transformation.test.wrappers.TransformationWrapper +import org.eclipse.papyrusrt.xtumlrt.common.Model +import org.eclipse.papyrusrt.xtumlrt.common.VisibilityKind +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTComponent +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTPackage +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTProtocol +import org.junit.runner.RunWith +import org.junit.runners.Parameterized + +import static org.junit.Assert.* + +import static extension com.incquerylabs.emdw.cpp.transformation.test.TransformationTestUtil.* + +@RunWith(Parameterized) +class CPPPortMappingTest extends MappingBaseTest { + CPPDirectory rootDir; + + new(TransformationWrapper wrapper, String wrapperType) { + super(wrapper, wrapperType) + } + + override protected prepareXtUmlModel(Model model) { + val pack = model.createXtPackage("RootPackage") + val component = pack.createXtComponent("Component") + val protocol = pack.createXtProtocol("Protocol") + component.createPort(protocol, "Port", VisibilityKind.PUBLIC) + + component + } + + override protected prepareCppModel(CPPModel cppModel) { + val res = cppModel.eResource + rootDir = res.createCPPDirectory + val xtmodel = cppModel.commonModel + val xtPackage = xtmodel.rootPackages.head as XTPackage + val cppPackage = createCPPPackage(cppModel, xtPackage) + val xtComponent = xtPackage.entities.head as XTComponent + val cppComponent = createCPPComponent(cppPackage, xtComponent, null, null, null, null) + val xtProt = xtPackage.protocols.head as XTProtocol + createCPPProtocol(cppPackage,xtProt, null) + + cppComponent + } + + override protected assertResult(Model input, CPPModel result, XTComponent xtObject, CPPComponent cppObject) { + val xtPorts = xtObject.ports + val cppPorts = cppObject.subElements.filter(CPPPort) + assertEquals(xtPorts.size,cppPorts.size) + assertEquals(xtPorts.size,rootDir.countCppHeaderFiles) + assertEquals(xtPorts.size,rootDir.countCppBodyFiles) + cppPorts.forEach[ + assertNotNull(ooplNameProvider) + assertNotNull(xtPort) + assertNotNull(headerFile) + assertNotNull(bodyFile) + ] + } + + override protected clearXtUmlElement(XTComponent xtObject) { + xtObject.ports.clear + } + +} diff --git a/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPProtocolMappingTest.xtend b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPProtocolMappingTest.xtend new file mode 100644 index 00000000..744cab58 --- /dev/null +++ b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPProtocolMappingTest.xtend @@ -0,0 +1,97 @@ +package com.incquerylabs.emdw.cpp.transformation.test.mappings + +import com.ericsson.xtumlrt.oopl.cppmodel.CPPDirectory +import com.ericsson.xtumlrt.oopl.cppmodel.CPPModel +import com.ericsson.xtumlrt.oopl.cppmodel.CPPPackage +import com.ericsson.xtumlrt.oopl.cppmodel.CPPProtocol +import com.incquerylabs.emdw.cpp.transformation.test.wrappers.TransformationWrapper +import org.eclipse.papyrusrt.xtumlrt.common.Model +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTPackage +import org.junit.runner.RunWith +import org.junit.runners.Parameterized + +import static org.junit.Assert.* + +import static extension com.incquerylabs.emdw.cpp.transformation.test.TransformationTestUtil.* + +@RunWith(Parameterized) +class CPPProtocolInPackageTest extends MappingBaseTest { + CPPDirectory rootDir; + + new(TransformationWrapper wrapper, String wrapperType) { + super(wrapper, wrapperType) + } + + override protected prepareXtUmlModel(Model model) { + val pack = model.createXtPackage("RootPackage") + pack.createXtProtocol("Protocol") + + pack + } + + override protected prepareCppModel(CPPModel cppModel) { + val res = cppModel.eResource + rootDir = res.createCPPDirectory + val xtmodel = cppModel.commonModel + val xtPackage = xtmodel.rootPackages.head as XTPackage + val cppPackage = createCPPPackage(cppModel, xtPackage) + + cppPackage + } + + override protected assertResult(Model input, CPPModel result, XTPackage xtObject, CPPPackage cppObject) { + val xtProtocols = xtObject.protocols + val cppProtocols = cppObject.subElements.filter(CPPProtocol) + assertEquals(xtProtocols.size,cppProtocols.size) + assertEquals(xtProtocols.size,rootDir.countCppHeaderFiles) + cppProtocols.forEach[ + assertNotNull(ooplNameProvider) + assertNotNull(xtProtocol) + assertNotNull(headerFile) + ] + } + + override protected clearXtUmlElement(XTPackage xtObject) { + xtObject.protocols.clear + } + +} + + +@RunWith(Parameterized) +class CPPProtocolInModelTest extends MappingBaseTest { + CPPDirectory rootDir; + + new(TransformationWrapper wrapper, String wrapperType) { + super(wrapper, wrapperType) + } + + override protected prepareXtUmlModel(Model model) { + model.createXtProtocol("Protocol") + + model + } + + override protected prepareCppModel(CPPModel cppModel) { + val res = cppModel.eResource + rootDir = res.createCPPDirectory + cppModel + } + + override protected assertResult(Model input, CPPModel result, Model xtObject, CPPModel cppObject) { + val xtProtocols = xtObject.topProtocols + val cppProtocols = cppObject.subElements.filter(CPPProtocol) + assertEquals(xtProtocols.size,cppProtocols.size) + assertEquals(xtProtocols.size,rootDir.countCppHeaderFiles) + cppProtocols.forEach[ + assertNotNull(ooplNameProvider) + assertNotNull(xtProtocol) + assertNotNull(headerFile) + ] + } + + override protected clearXtUmlElement(Model xtObject) { + xtObject.topProtocols.clear + } + +} diff --git a/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPSignalMappingTest.xtend b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPSignalMappingTest.xtend new file mode 100644 index 00000000..9779f407 --- /dev/null +++ b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPSignalMappingTest.xtend @@ -0,0 +1,57 @@ +package com.incquerylabs.emdw.cpp.transformation.test.mappings + +import com.ericsson.xtumlrt.oopl.cppmodel.CPPModel +import com.ericsson.xtumlrt.oopl.cppmodel.CPPProtocol +import com.ericsson.xtumlrt.oopl.cppmodel.CPPSignal +import com.incquerylabs.emdw.cpp.transformation.test.wrappers.TransformationWrapper +import org.eclipse.papyrusrt.xtumlrt.common.Model +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTPackage +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTProtocol +import org.junit.runner.RunWith +import org.junit.runners.Parameterized + +import static org.junit.Assert.* + +import static extension com.incquerylabs.emdw.cpp.transformation.test.TransformationTestUtil.* + +@RunWith(Parameterized) +class CPPSignalMappingTest extends MappingBaseTest { + + new(TransformationWrapper wrapper, String wrapperType) { + super(wrapper, wrapperType) + } + + override protected prepareXtUmlModel(Model model) { + val pack = model.createXtPackage("RootPackage") + val protocol = pack.createXtProtocol("Protocol") + protocol.createSignal("Signal") + + protocol + } + + override protected prepareCppModel(CPPModel cppModel) { + val xtmodel = cppModel.commonModel + val xtPackage = xtmodel.rootPackages.head as XTPackage + val cppPackage = createCPPPackage(cppModel, xtPackage) + val xtProt = xtPackage.protocols.head as XTProtocol + val cppProtocol = createCPPProtocol(cppPackage,xtProt, null) + + cppProtocol + } + + override protected assertResult(Model input, CPPModel result, XTProtocol xtObject, CPPProtocol cppObject) { + val xtSignals = xtObject.protocolBehaviourFeatures + val cppSignals = cppObject.subElements.filter(CPPSignal) + assertEquals(xtSignals.size,cppSignals.size) + cppSignals.forEach[ + assertNotNull(ooplNameProvider) + assertNotNull(commonSignal) + ] + } + + override protected clearXtUmlElement(XTProtocol xtObject) { + xtObject.protocolBehaviourFeatures.clear + } + + +} \ No newline at end of file diff --git a/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPStateMappingTest.xtend b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPStateMappingTest.xtend new file mode 100644 index 00000000..5cd054f6 --- /dev/null +++ b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPStateMappingTest.xtend @@ -0,0 +1,108 @@ +package com.incquerylabs.emdw.cpp.transformation.test.mappings + +import com.ericsson.xtumlrt.oopl.cppmodel.CPPClass +import com.ericsson.xtumlrt.oopl.cppmodel.CPPComponent +import com.ericsson.xtumlrt.oopl.cppmodel.CPPModel +import com.ericsson.xtumlrt.oopl.cppmodel.CPPState +import com.incquerylabs.emdw.cpp.transformation.test.wrappers.TransformationWrapper +import org.eclipse.papyrusrt.xtumlrt.common.CompositeState +import org.eclipse.papyrusrt.xtumlrt.common.Model +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTClass +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTComponent +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTPackage +import org.junit.runner.RunWith +import org.junit.runners.Parameterized + +import static org.junit.Assert.* + +import static extension com.incquerylabs.emdw.cpp.transformation.test.TransformationTestUtil.* + +@RunWith(Parameterized) +class CPPStateInClassTest extends MappingBaseTest { + + new(TransformationWrapper wrapper, String wrapperType) { + super(wrapper, wrapperType) + } + + override protected prepareXtUmlModel(Model model) { + val pack = model.createXtPackage("RootPackage") + val component = pack.createXtComponent("Component") + val xtClass = component.createXtClass("Class") + val topState = xtClass.createStateMachine("SM").createCompositeState("top") + val classEvent = xtClass.createXtClassEvent("ClassEvent") + val s1 = topState.createSimpleState("s1") + val s2 = topState.createSimpleState("s2") + topState.createTransition(s1,s2,"t2", "SAMPLE_CODE").createXTEventTrigger(classEvent, "Trigger") + + topState + } + + override protected prepareCppModel(CPPModel cppModel) { + val xtmodel = cppModel.commonModel + val xtPackage = xtmodel.rootPackages.head as XTPackage + val cppPackage = createCPPPackage(cppModel, xtPackage) + val xtComponent = xtPackage.entities.head as XTComponent + val cppComponent = createCPPComponent(cppPackage, xtComponent, null, null, null, null) + val xtClass = xtComponent.ownedClasses.head as XTClass + val cppClass = createCPPClass(cppComponent, xtClass, null, null) + + cppClass + } + + override protected assertResult(Model input, CPPModel result, CompositeState xtObject, CPPClass cppObject) { + val cppStates = cppObject.subElements.filter(CPPState) + assertFalse(cppStates.exists[commonState == xtObject]) + assertEquals(2,cppStates.size) + cppStates.forEach[ + assertNotNull(ooplNameProvider) + assertNotNull(commonState) + ] + } + + override protected clearXtUmlElement(CompositeState xtObject) { + xtObject.substates.clear + } + +} + +@RunWith(Parameterized) +class CPPStateInComponentTest extends MappingBaseTest { + new(TransformationWrapper wrapper, String wrapperType) { + super(wrapper, wrapperType) + } + + override protected prepareXtUmlModel(Model model) { + val pack = model.createXtPackage("RootPackage") + val component = pack.createXtComponent("Component") + val topState = component.createStateMachine("SM").createCompositeState("top") + val s1 = topState.createSimpleState("s1") + val s2 = topState.createSimpleState("s2") + topState.createTransition(s1,s2,"t2", "SAMPLE_CODE") + topState + } + + override protected prepareCppModel(CPPModel cppModel) { + val xtmodel = cppModel.commonModel + val xtPackage = xtmodel.rootPackages.head as XTPackage + val cppPackage = createCPPPackage(cppModel, xtPackage) + val xtComponent = xtPackage.entities.head as XTComponent + val cppComponent = createCPPComponent(cppPackage, xtComponent, null, null, null, null) + + cppComponent + } + + override protected assertResult(Model input, CPPModel result, CompositeState xtObject, CPPComponent cppObject) { + val cppStates = cppObject.subElements.filter(CPPState) + assertFalse(cppStates.exists[commonState == xtObject]) + assertEquals(2,cppStates.size) + cppStates.forEach[ + assertNotNull(ooplNameProvider) + assertNotNull(commonState) + ] + } + + override protected clearXtUmlElement(CompositeState xtObject) { + xtObject.substates.clear + } + +} \ No newline at end of file diff --git a/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPTransitionMappingTest.xtend b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPTransitionMappingTest.xtend new file mode 100644 index 00000000..053ac2eb --- /dev/null +++ b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/CPPTransitionMappingTest.xtend @@ -0,0 +1,134 @@ +package com.incquerylabs.emdw.cpp.transformation.test.mappings + +import com.ericsson.xtumlrt.oopl.cppmodel.CPPClass +import com.ericsson.xtumlrt.oopl.cppmodel.CPPComponent +import com.ericsson.xtumlrt.oopl.cppmodel.CPPModel +import com.ericsson.xtumlrt.oopl.cppmodel.CPPTransition +import com.incquerylabs.emdw.cpp.transformation.test.wrappers.TransformationWrapper +import java.util.ArrayList +import java.util.List +import org.eclipse.papyrusrt.xtumlrt.common.CompositeState +import org.eclipse.papyrusrt.xtumlrt.common.Model +import org.eclipse.papyrusrt.xtumlrt.common.Transition +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTClass +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTComponent +import org.eclipse.papyrusrt.xtumlrt.xtuml.XTPackage +import org.junit.runner.RunWith +import org.junit.runners.Parameterized + +import static org.junit.Assert.* + +import static extension com.incquerylabs.emdw.cpp.transformation.test.TransformationTestUtil.* + +@RunWith(Parameterized) +class CPPTransitionInClassTest extends MappingBaseTest { + + new(TransformationWrapper wrapper, String wrapperType) { + super(wrapper, wrapperType) + } + + override protected prepareXtUmlModel(Model model) { + val pack = model.createXtPackage("RootPackage") + val component = pack.createXtComponent("Component") + val xtClass = component.createXtClass("Class") + val topState = xtClass.createStateMachine("SM").createCompositeState("top") + val classEvent = xtClass.createXtClassEvent("ClassEvent") + val s1 = topState.createSimpleState("s1") + val s2 = topState.createSimpleState("s2") + val trans = topState.createTransition(s1,s2,"t2", "SAMPLE_CODE") + trans.createXTEventTrigger(classEvent, "Trigger") + + xtClass + } + + override protected prepareCppModel(CPPModel cppModel) { + val xtmodel = cppModel.commonModel + val xtPackage = xtmodel.rootPackages.head as XTPackage + val cppPackage = createCPPPackage(cppModel, xtPackage) + val xtComponent = xtPackage.entities.head as XTComponent + val cppComponent = createCPPComponent(cppPackage, xtComponent, null, null, null, null) + val xtClass = xtComponent.ownedClasses.head as XTClass + val cppClass = createCPPClass(cppComponent, xtClass, null, null) + + cppClass + } + + override protected assertResult(Model input, CPPModel result, XTClass xtObject, CPPClass cppObject) { + val xtTrans = xtObject.behaviour.top.allTransitions + val cppTrans = cppObject.subElements.filter(CPPTransition) + assertEquals(xtTrans.size,cppTrans.size) + cppTrans.forEach[ + assertNotNull(ooplNameProvider) + assertNotNull(commonTransition) + ] + } + + private def List getAllTransitions(CompositeState comp){ + val compstates = comp.substates.filter(CompositeState) + val transitions = new ArrayList() + compstates.forEach[ + transitions.addAll(allTransitions) + ] + transitions.addAll(comp.transitions) + transitions + } + + override protected clearXtUmlElement(XTClass xtObject) { + xtObject.behaviour.top.transitions.clear + } + +} + + +@RunWith(Parameterized) +class CPPTransitionInComponentTest extends MappingBaseTest { + new(TransformationWrapper wrapper, String wrapperType) { + super(wrapper, wrapperType) + } + + override protected prepareXtUmlModel(Model model) { + val pack = model.createXtPackage("RootPackage") + val component = pack.createXtComponent("Component") + val topState = component.createStateMachine("SM").createCompositeState("top") + val s1 = topState.createSimpleState("s1") + val s2 = topState.createSimpleState("s2") + topState.createTransition(s1,s2,"t2", "SAMPLE_CODE") + + component + } + + override protected prepareCppModel(CPPModel cppModel) { + val xtmodel = cppModel.commonModel + val xtPackage = xtmodel.rootPackages.head as XTPackage + val cppPackage = createCPPPackage(cppModel, xtPackage) + val xtComponent = xtPackage.entities.head as XTComponent + val cppComponent = createCPPComponent(cppPackage, xtComponent, null, null, null, null) + + cppComponent + } + + override protected assertResult(Model input, CPPModel result, XTComponent xtObject, CPPComponent cppObject) { + val xtTrans = xtObject.behaviour.top.allTransitions + val cppTrans = cppObject.subElements.filter(CPPTransition) + assertEquals(xtTrans.size,cppTrans.size) + cppTrans.forEach[ + assertNotNull(ooplNameProvider) + assertNotNull(commonTransition) + ] + } + + private def List getAllTransitions(CompositeState comp){ + val compstates = comp.substates.filter(CompositeState) + val transitions = new ArrayList() + compstates.forEach[ + transitions.addAll(allTransitions) + ] + transitions.addAll(comp.transitions) + transitions + } + + override protected clearXtUmlElement(XTComponent xtObject) { + xtObject.behaviour.top.transitions.clear + } + +} \ No newline at end of file diff --git a/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/MappingBaseTest.xtend b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/MappingBaseTest.xtend new file mode 100644 index 00000000..2da9626b --- /dev/null +++ b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/mappings/MappingBaseTest.xtend @@ -0,0 +1,46 @@ +package com.incquerylabs.emdw.cpp.transformation.test.mappings + +import com.incquerylabs.emdw.cpp.transformation.test.TransformationTest +import com.incquerylabs.emdw.cpp.transformation.test.wrappers.TransformationWrapper +import org.eclipse.emf.ecore.EObject +import org.junit.Test + +import static com.incquerylabs.emdw.cpp.transformation.test.TransformationTestUtil.* + +abstract class MappingBaseTest extends TransformationTest { + + new(TransformationWrapper wrapper, String wrapperType) { + super(wrapper, wrapperType) + } + + @Test + def deletion() { + + val testId = "single" + startTest(testId) + // Create xtuml model + val xtModel = createEmptyXtumlModel(this.class.simpleName + "_" + testId) + val xtObject = prepareXtUmlModel(xtModel) + // init cpp model + val cppResource = createCPPResource(xtModel) + val cppModel = createCPPModel(cppResource, xtModel) + val cppObject = prepareCppModel(cppModel) + // transform to CPP + initializeTransformation(cppModel) + executeTransformation + // Check if added properly + assertResult(xtModel, cppModel, xtObject, cppObject) + //remove added xtuml element + clearXtUmlElement(xtObject) + //check if removed properly + assertResult(xtModel, cppModel, xtObject, cppObject) + endTest(testId) + } + + + protected def void clearXtUmlElement(XtumlObject xtObject) + + + + +} \ No newline at end of file diff --git a/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/wrappers/DummyWrapper.xtend b/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/wrappers/DummyWrapper.xtend deleted file mode 100644 index 5686b1ca..00000000 --- a/com.incquerylabs.emdw.cpp.transformation.test/src/com/incquerylabs/emdw/cpp/transformation/test/wrappers/DummyWrapper.xtend +++ /dev/null @@ -1,20 +0,0 @@ -package com.incquerylabs.emdw.cpp.transformation.test.wrappers - -import com.ericsson.xtumlrt.oopl.cppmodel.CPPModel - -class DummyWrapper extends TransformationWrapper { - - - override executeTransformation() { - info("This is a dummy transformation") - } - - override cleanupTransformation() { - info("This is a dummy transformation") - } - - override initializeTransformation(CPPModel cppmodel) { - info("This is a dummy transformation") - } - -}