Skip to content

Commit

Permalink
Merge pull request #37 from lunkpeter/CPPtest
Browse files Browse the repository at this point in the history
Added test cases for the basic CPP types
  • Loading branch information
abelhegedus committed Apr 29, 2015
2 parents 03e9145 + 4e88dec commit be12e1a
Show file tree
Hide file tree
Showing 16 changed files with 1,115 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class TransformationTest<XtumlObject extends EObject, CPPObject extends

@Parameters(name="{index}: {1}")
public static def transformations() {
val alternatives = ImmutableList.builder// .add(new DummyWrapper())
val alternatives = ImmutableList.builder
.add(new XtumlCPPTransformationWrapper()).build

alternatives.map [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ class TransformationTestUtil {
root.entities += comp
comp
}

static def createXtComponent(Model root, String name) {
var comp = xtumlFactory.createXTComponent => [
it.name = name
]
root.topEntities += comp
comp
}

static def createXtClass(XTComponent root, String name) {
var xtclass = xtumlFactory.createXTClass => [
Expand All @@ -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 => [
Expand All @@ -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 => [
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<XTClass, CPPClass> {
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<XTComponent, CPPComponent> {
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
}

}
Original file line number Diff line number Diff line change
@@ -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<XTPackage, CPPPackage> {
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<Model, CPPModel> {
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<XTComponent, CPPComponent> {
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
}

}
Loading

0 comments on commit be12e1a

Please sign in to comment.