From 4b701f5a73a1abd11528a237fbef40ccc2670eb9 Mon Sep 17 00:00:00 2001 From: dbv Date: Fri, 6 May 2016 19:35:01 +0300 Subject: [PATCH] Tests for Build plug-in features. --- src/BuildPlugin/CMakeLists.txt | 5 ++- src/BuildPlugin/Test/TestEdge.py | 56 +++++++++++++++++++++++++ src/BuildPlugin/Test/TestFace.py | 65 ++++++++++++++++++++++++++++++ src/BuildPlugin/Test/TestVertex.py | 57 ++++++++++++++++++++++++++ src/BuildPlugin/Test/TestWire.py | 65 ++++++++++++++++++++++++++++++ 5 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 src/BuildPlugin/Test/TestEdge.py create mode 100644 src/BuildPlugin/Test/TestFace.py create mode 100644 src/BuildPlugin/Test/TestVertex.py create mode 100644 src/BuildPlugin/Test/TestWire.py diff --git a/src/BuildPlugin/CMakeLists.txt b/src/BuildPlugin/CMakeLists.txt index 8c3b62d88..97e9633ad 100644 --- a/src/BuildPlugin/CMakeLists.txt +++ b/src/BuildPlugin/CMakeLists.txt @@ -62,4 +62,7 @@ INSTALL(TARGETS BuildPlugin DESTINATION ${SHAPER_INSTALL_PLUGIN_FILES}) INSTALL(FILES ${XML_RESOURCES} DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}) INSTALL(DIRECTORY icons/ DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}/icons/Build) -# ADD_UNIT_TESTS() +ADD_UNIT_TESTS(TestVertex.py + TestEdge.py + TestWire.py + TestFace.py) diff --git a/src/BuildPlugin/Test/TestEdge.py b/src/BuildPlugin/Test/TestEdge.py new file mode 100644 index 000000000..5c5ebb590 --- /dev/null +++ b/src/BuildPlugin/Test/TestEdge.py @@ -0,0 +1,56 @@ +# Initialization of the test +from ModelAPI import * +from GeomDataAPI import * +from GeomAlgoAPI import * +from GeomAPI import * + +import random + +def createLine(theSketchFeature): + aSketchLineFeature = theSketchFeature.addFeature("SketchLine") + aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint")) + aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint")) + aSketchLineStartPoint.setValue(random.uniform(0, 100), random.uniform(0, 100)) + aSketchLineEndPoint.setValue(random.uniform(0, 100), random.uniform(0, 100)) + +# Get document +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() + +# Create a part +aSession.startOperation() +aPartFeature = aDocument.addFeature("Part") +aSession.finishOperation() +aPartResult = modelAPI_ResultPart(aPartFeature.firstResult()) +aPart = aPartResult.partDoc() + +# Create a sketch +aSession.startOperation() +aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch")) +anOrigin = geomDataAPI_Point(aSketchFeature.attribute("Origin")) +anOrigin.setValue(0, 0, 0) +aDirX = geomDataAPI_Dir(aSketchFeature.attribute("DirX")) +aDirX.setValue(1, 0, 0) +aNorm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")) +aNorm.setValue(0, 0, 1) + +# Create lines +aNumOfLines = 10 +for i in range(aNumOfLines): + createLine(aSketchFeature) +aSession.finishOperation() +aSketchResult = aSketchFeature.firstResult() +aSketchShape = aSketchResult.shape() + +# Create edges +aSession.startOperation() +anEdgeFeature = aPart.addFeature("Edge") +aBaseObjectsList = anEdgeFeature.selectionList("base_objects") +aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE) +while aShapeExplorer.more(): + aBaseObjectsList.append(aSketchResult, aShapeExplorer.current()) + aShapeExplorer.next() +aSession.finishOperation() + +# Test results +assert (len(anEdgeFeature.results()) == aNumOfLines) diff --git a/src/BuildPlugin/Test/TestFace.py b/src/BuildPlugin/Test/TestFace.py new file mode 100644 index 000000000..9cf158a05 --- /dev/null +++ b/src/BuildPlugin/Test/TestFace.py @@ -0,0 +1,65 @@ +# Initialization of the test +from ModelAPI import * +from GeomDataAPI import * +from GeomAlgoAPI import * +from GeomAPI import * + +# Get document +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() + +# Create a part +aSession.startOperation() +aPartFeature = aDocument.addFeature("Part") +aSession.finishOperation() +aPartResult = modelAPI_ResultPart(aPartFeature.firstResult()) +aPart = aPartResult.partDoc() + +# Create a sketch +aSession.startOperation() +aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch")) +anOrigin = geomDataAPI_Point(aSketchFeature.attribute("Origin")) +anOrigin.setValue(0, 0, 0) +aDirX = geomDataAPI_Dir(aSketchFeature.attribute("DirX")) +aDirX.setValue(1, 0, 0) +aNorm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")) +aNorm.setValue(0, 0, 1) + +# Create lines +aNumOfLines = 10 +aSketchLineFeature = aSketchFeature.addFeature("SketchLine") +aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint")) +aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint")) +aSketchLineStartPoint.setValue(0, 0) +aSketchLineEndPoint.setValue(0, 50) +aSketchLineFeature = aSketchFeature.addFeature("SketchLine") +aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint")) +aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint")) +aSketchLineStartPoint.setValue(0, 50) +aSketchLineEndPoint.setValue(50, 50) +aSketchLineFeature = aSketchFeature.addFeature("SketchLine") +aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint")) +aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint")) +aSketchLineStartPoint.setValue(50, 50) +aSketchLineEndPoint.setValue(50, 0) +aSketchLineFeature = aSketchFeature.addFeature("SketchLine") +aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint")) +aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint")) +aSketchLineStartPoint.setValue(50, 0) +aSketchLineEndPoint.setValue(0, 0) +aSession.finishOperation() +aSketchResult = aSketchFeature.firstResult() +aSketchShape = aSketchResult.shape() + +# Create face +aSession.startOperation() +aFaceFeature = aPart.addFeature("Face") +aBaseObjectsList = aFaceFeature.selectionList("base_objects") +aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE) +while aShapeExplorer.more(): + aBaseObjectsList.append(aSketchResult, aShapeExplorer.current()) + aShapeExplorer.next() +aSession.finishOperation() + +# Test results +assert (len(aFaceFeature.results()) > 0) diff --git a/src/BuildPlugin/Test/TestVertex.py b/src/BuildPlugin/Test/TestVertex.py new file mode 100644 index 000000000..cc2da7929 --- /dev/null +++ b/src/BuildPlugin/Test/TestVertex.py @@ -0,0 +1,57 @@ +# Initialization of the test +from ModelAPI import * +from GeomDataAPI import * +from GeomAlgoAPI import * +from GeomAPI import * + +import random + +def createPoint(theSketchFeature): + aSketchPointFeature = theSketchFeature.addFeature("SketchPoint") + aPointCoordindates = geomDataAPI_Point2D(aSketchPointFeature.attribute("PointCoordindates")) + aPointCoordindates.setValue(random.uniform(0, 100), random.uniform(0, 100)) + return aSketchPointFeature + +# Get document +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() + +# Create a part +aSession.startOperation() +aPartFeature = aDocument.addFeature("Part") +aSession.finishOperation() +aPartResult = modelAPI_ResultPart(aPartFeature.firstResult()) +aPart = aPartResult.partDoc() + +# Create a sketch +aSession.startOperation() +aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch")) +anOrigin = geomDataAPI_Point(aSketchFeature.attribute("Origin")) +anOrigin.setValue(0, 0, 0) +aDirX = geomDataAPI_Dir(aSketchFeature.attribute("DirX")) +aDirX.setValue(1, 0, 0) +aNorm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")) +aNorm.setValue(0, 0, 1) + +# Create points +aNumOfPoints = 10 +aPoints = [] +for i in range(aNumOfPoints): + aSession.startOperation() + aSketchPointFeature = createPoint(aSketchFeature) + aSession.finishOperation() + aPoints.append(aSketchPointFeature.firstResult().shape()) +aSession.finishOperation() +aSketchResult = aSketchFeature.firstResult() + +# Create vertices +aSession.startOperation() +aVertexFeature = aPart.addFeature("Vertex") +aBaseObjectsList = aVertexFeature.selectionList("base_objects") + +for aPoint in aPoints: + aBaseObjectsList.append(aSketchResult, aPoint) +aSession.finishOperation() + +# Test results +assert (len(aVertexFeature.results()) == aNumOfPoints) diff --git a/src/BuildPlugin/Test/TestWire.py b/src/BuildPlugin/Test/TestWire.py new file mode 100644 index 000000000..f5d2098e3 --- /dev/null +++ b/src/BuildPlugin/Test/TestWire.py @@ -0,0 +1,65 @@ +# Initialization of the test +from ModelAPI import * +from GeomDataAPI import * +from GeomAlgoAPI import * +from GeomAPI import * + +# Get document +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() + +# Create a part +aSession.startOperation() +aPartFeature = aDocument.addFeature("Part") +aSession.finishOperation() +aPartResult = modelAPI_ResultPart(aPartFeature.firstResult()) +aPart = aPartResult.partDoc() + +# Create a sketch +aSession.startOperation() +aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch")) +anOrigin = geomDataAPI_Point(aSketchFeature.attribute("Origin")) +anOrigin.setValue(0, 0, 0) +aDirX = geomDataAPI_Dir(aSketchFeature.attribute("DirX")) +aDirX.setValue(1, 0, 0) +aNorm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")) +aNorm.setValue(0, 0, 1) + +# Create lines +aNumOfLines = 10 +aSketchLineFeature = aSketchFeature.addFeature("SketchLine") +aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint")) +aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint")) +aSketchLineStartPoint.setValue(0, 0) +aSketchLineEndPoint.setValue(0, 50) +aSketchLineFeature = aSketchFeature.addFeature("SketchLine") +aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint")) +aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint")) +aSketchLineStartPoint.setValue(0, 50) +aSketchLineEndPoint.setValue(50, 50) +aSketchLineFeature = aSketchFeature.addFeature("SketchLine") +aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint")) +aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint")) +aSketchLineStartPoint.setValue(50, 50) +aSketchLineEndPoint.setValue(50, 0) +aSketchLineFeature = aSketchFeature.addFeature("SketchLine") +aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint")) +aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint")) +aSketchLineStartPoint.setValue(50, 0) +aSketchLineEndPoint.setValue(0, 0) +aSession.finishOperation() +aSketchResult = aSketchFeature.firstResult() +aSketchShape = aSketchResult.shape() + +# Create wire +aSession.startOperation() +aWireFeature = aPart.addFeature("Wire") +aBaseObjectsList = aWireFeature.selectionList("base_objects") +aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE) +while aShapeExplorer.more(): + aBaseObjectsList.append(aSketchResult, aShapeExplorer.current()) + aShapeExplorer.next() +aSession.finishOperation() + +# Test results +assert (len(aWireFeature.results()) > 0) -- 2.39.2