From: sbh Date: Thu, 24 Jul 2014 13:22:09 +0000 (+0400) Subject: TestSketchBasics.py has been refactored X-Git-Tag: V_0.4.4~146^2~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=94585b6c7026d6ba622a5560ff538a145d911849;p=modules%2Fshaper.git TestSketchBasics.py has been refactored --- diff --git a/src/GeomDataAPI/CMakeLists.txt b/src/GeomDataAPI/CMakeLists.txt index 389463212..d956835d1 100644 --- a/src/GeomDataAPI/CMakeLists.txt +++ b/src/GeomDataAPI/CMakeLists.txt @@ -1,6 +1,7 @@ FIND_PACKAGE(SWIG REQUIRED) INCLUDE(${SWIG_USE_FILE}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) +INCLUDE(UnitTest) SET(PROJECT_HEADERS GeomDataAPI.h @@ -36,3 +37,5 @@ ENDIF(WIN32) INSTALL(TARGETS _GeomDataAPI DESTINATION swig) INSTALL(FILES ${SWIG_SCRIPTS} DESTINATION swig) + +ADD_UNIT_TESTS(TestConstants.py) diff --git a/src/GeomDataAPI/Test/TestConstants.py b/src/GeomDataAPI/Test/TestConstants.py new file mode 100644 index 000000000..bb6bc044a --- /dev/null +++ b/src/GeomDataAPI/Test/TestConstants.py @@ -0,0 +1,7 @@ +#=============================================================================== +# Test GeomDataAPI static methods +#=============================================================================== +from GeomDataAPI import * +assert (GeomDataAPI_Point.type() == "Point") +assert (GeomDataAPI_Dir.type() == "Dir") +assert (GeomDataAPI_Point2D.type() == "Point2D") \ No newline at end of file diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index c92f95df6..4d10c9ce1 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -77,5 +77,5 @@ INSTALL(TARGETS _ModelAPI DESTINATION swig) INSTALL(TARGETS ModelAPI DESTINATION bin) INSTALL(FILES ${SWIG_SCRIPTS} DESTINATION swig) -ADD_UNIT_TESTS(TestUndoRedo.py - ) +ADD_UNIT_TESTS(TestConstants.py + TestUndoRedo.py) diff --git a/src/ModelAPI/Test/TestConstants.py b/src/ModelAPI/Test/TestConstants.py new file mode 100644 index 000000000..fd851f310 --- /dev/null +++ b/src/ModelAPI/Test/TestConstants.py @@ -0,0 +1,10 @@ +#=============================================================================== +# Test ModelAPI static methods +#=============================================================================== +from ModelAPI import * +assert (ModelAPI_Feature.group() == "Features") +assert (ModelAPI_AttributeDocRef.type() == "DocRef") +assert (ModelAPI_AttributeDouble.type() == "Double") +assert (ModelAPI_AttributeReference.type() == "Reference") +assert (ModelAPI_AttributeRefAttr.type() == "RefAttr") +assert (ModelAPI_AttributeRefList.type() == "RefList") \ No newline at end of file diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 79404ee70..cbcfdc7a8 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -61,4 +61,4 @@ INCLUDE_DIRECTORIES( INSTALL(TARGETS SketchPlugin DESTINATION plugins) INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins) -ADD_UNIT_TESTS(TestSketchBasics.py) +ADD_UNIT_TESTS(TestSketchPointLine.py) diff --git a/src/SketchPlugin/Test/TestSketchBasics.py b/src/SketchPlugin/Test/TestSketchBasics.py deleted file mode 100644 index b4889ea98..000000000 --- a/src/SketchPlugin/Test/TestSketchBasics.py +++ /dev/null @@ -1,130 +0,0 @@ -#========================================================================= -# Initialization of the test -#========================================================================= -from GeomDataAPI import * -from ModelAPI import * - -__updated__ = "2014-07-24" - -aPluginManager = ModelAPI_PluginManager.get() -aDocument = aPluginManager.rootDocument() -#=============================================================================== -# Test ModelAPI static methods -# TODO: Move this test in the ModelAPI progect -#=============================================================================== -assert (ModelAPI_Feature.group() == "Features") -assert (ModelAPI_AttributeDocRef.type() == "DocRef") -assert (ModelAPI_AttributeDouble.type() == "Double") -assert (ModelAPI_AttributeReference.type() == "Reference") -assert (ModelAPI_AttributeRefAttr.type() == "RefAttr") -assert (ModelAPI_AttributeRefList.type() == "RefList") -#=============================================================================== -# Test GeomDataAPI static methods -# TODO: Move this test in the GeomDataAPI progect -#=============================================================================== -assert (GeomDataAPI_Point.type() == "Point") -assert (GeomDataAPI_Dir.type() == "Dir") -assert (GeomDataAPI_Point2D.type() == "Point2D") -#========================================================================= -# Creation of a sketch -#========================================================================= -aDocument.startOperation() -aSketchFeature = aDocument.addFeature("Sketch") -assert (aSketchFeature.getKind() == "Sketch") -aSketchFeatureData = aSketchFeature.data() -origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin")) -origin.setValue(0, 0, 0) -dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX")) -dirx.setValue(1, 0, 0) -diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY")) -diry.setValue(0, 1, 0) -norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm")) -norm.setValue(0, 0, 1) -# check that values have been changed -origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin")) -assert (origin.x() == 0) -assert (origin.y() == 0) -assert (origin.z() == 0) -dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX")) -assert (dirx.x() == 1) -assert (dirx.y() == 0) -assert (dirx.z() == 0) -diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY")) -assert (diry.x() == 0) -assert (diry.y() == 1) -assert (diry.z() == 0) -norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm")) -assert (norm.x() == 0) -assert (norm.y() == 0) -assert (norm.z() == 1) -aDocument.finishOperation() -#========================================================================= -# Creation of a point -#========================================================================= -aDocument.startOperation() -aSketchReflist = aSketchFeatureData.reflist("Features") -assert (not aSketchReflist.isInitialized()) -assert(aSketchReflist.size() == 0) -assert (len(aSketchReflist.list()) == 0) -aSketchPoint = aDocument.addFeature("SketchPoint") -assert (aSketchPoint.getKind() == "SketchPoint") -aSketchReflist.append(aSketchPoint) -aSketchPointData = aSketchPoint.data() -coords = geomDataAPI_Point2D(aSketchPointData.attribute("PointCoordindates")) -assert (coords.x() == 0) -assert (coords.y() == 0) -assert (not coords.isInitialized()) -# Simulate SketchPlugin_Point::move(...) -coords.setValue(10., 10.) -assert (coords.isInitialized()) -# check that values have been changed -aSketchReflist = aSketchFeatureData.reflist("Features") -assert (aSketchReflist.size() == 1) -assert (len(aSketchReflist.list()) == 1) -aSketchPointData = aSketchPoint.data() -coords = geomDataAPI_Point2D(aSketchPointData.attribute("PointCoordindates")) -assert (coords.x() == 10.0) -assert (coords.y() == 10.0) -aDocument.finishOperation() -#=============================================================================== -# Creation of a line -#=============================================================================== -aDocument.startOperation() -aSketchLine = aDocument.addFeature("SketchLine") -aSketchReflist.append(aSketchLine) -assert (aSketchReflist.size() == 2) -assert (len(aSketchReflist.list()) == 2) -aSketchLineData = aSketchLine.data() -aLineStartPoint = geomDataAPI_Point2D(aSketchLineData.attribute("StartPoint")) -aLineEndPoint= geomDataAPI_Point2D(aSketchLineData.attribute("EndPoint")) -assert (aLineStartPoint.x() == 0) -assert (aLineStartPoint.y() == 0) -assert (not aLineStartPoint.isInitialized()) -assert (aLineEndPoint.x() == 0) -assert (aLineEndPoint.y() == 0) -assert (not aLineEndPoint.isInitialized()) -# Simulate SketchPlugin_Line::move(...) -aLineStartPoint.setValue(50., 50.) -aLineEndPoint.setValue(60., 60.) -assert (aLineStartPoint.isInitialized()) -assert (aLineEndPoint.isInitialized()) -# check that values have been changed -aSketchLineData = aSketchLine.data() -aLineStartPoint = geomDataAPI_Point2D(aSketchLineData.attribute("StartPoint")) -aLineEndPoint= geomDataAPI_Point2D(aSketchLineData.attribute("EndPoint")) -assert (aLineStartPoint.x() == 50.0) -assert (aLineStartPoint.y() == 50.0) -assert (aLineEndPoint.x() == 60.0) -assert (aLineEndPoint.y() == 60.0) -aDocument.finishOperation() -#=============================================================================== -# Check results -#=============================================================================== -aResult = aSketchLine.firstResult() -aResultConstruction = modelAPI_ResultConstruction(aResult) -aShape = aResultConstruction.shape() -assert (aShape is not None) -assert (not aShape.isNull()) - #============================================================================== - # Finish the test - #============================================================================== diff --git a/src/SketchPlugin/Test/TestSketchPointLine.py b/src/SketchPlugin/Test/TestSketchPointLine.py new file mode 100644 index 000000000..a03ca8fdf --- /dev/null +++ b/src/SketchPlugin/Test/TestSketchPointLine.py @@ -0,0 +1,111 @@ +#========================================================================= +# Initialization of the test +#========================================================================= +from GeomDataAPI import * +from ModelAPI import * + +__updated__ = "2014-07-24" + +aPluginManager = ModelAPI_PluginManager.get() +aDocument = aPluginManager.rootDocument() +#========================================================================= +# Creation of a sketch +#========================================================================= +aDocument.startOperation() +aSketchFeature = aDocument.addFeature("Sketch") +assert (aSketchFeature.getKind() == "Sketch") +aSketchFeatureData = aSketchFeature.data() +origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX")) +dirx.setValue(1, 0, 0) +diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY")) +diry.setValue(0, 1, 0) +norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm")) +norm.setValue(0, 0, 1) +# check that values have been changed +origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin")) +assert (origin.x() == 0) +assert (origin.y() == 0) +assert (origin.z() == 0) +dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX")) +assert (dirx.x() == 1) +assert (dirx.y() == 0) +assert (dirx.z() == 0) +diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY")) +assert (diry.x() == 0) +assert (diry.y() == 1) +assert (diry.z() == 0) +norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm")) +assert (norm.x() == 0) +assert (norm.y() == 0) +assert (norm.z() == 1) +aDocument.finishOperation() +#========================================================================= +# Creation of a point +#========================================================================= +aDocument.startOperation() +aSketchReflist = aSketchFeatureData.reflist("Features") +assert (not aSketchReflist.isInitialized()) +assert(aSketchReflist.size() == 0) +assert (len(aSketchReflist.list()) == 0) +aSketchPoint = aDocument.addFeature("SketchPoint") +assert (aSketchPoint.getKind() == "SketchPoint") +aSketchReflist.append(aSketchPoint) +aSketchPointData = aSketchPoint.data() +coords = geomDataAPI_Point2D(aSketchPointData.attribute("PointCoordindates")) +assert (coords.x() == 0) +assert (coords.y() == 0) +assert (not coords.isInitialized()) +# Simulate SketchPlugin_Point::move(...) +coords.setValue(10., 10.) +assert (coords.isInitialized()) +# check that values have been changed +aSketchReflist = aSketchFeatureData.reflist("Features") +assert (aSketchReflist.size() == 1) +assert (len(aSketchReflist.list()) == 1) +aSketchPointData = aSketchPoint.data() +coords = geomDataAPI_Point2D(aSketchPointData.attribute("PointCoordindates")) +assert (coords.x() == 10.0) +assert (coords.y() == 10.0) +aDocument.finishOperation() +#=============================================================================== +# Creation of a line +#=============================================================================== +aDocument.startOperation() +aSketchLine = aDocument.addFeature("SketchLine") +assert (aSketchLine.getKind() == "SketchLine") +aSketchReflist.append(aSketchLine) +assert (aSketchReflist.size() == 2) +assert (len(aSketchReflist.list()) == 2) +aSketchLineData = aSketchLine.data() +aLineStartPoint = geomDataAPI_Point2D(aSketchLineData.attribute("StartPoint")) +aLineEndPoint= geomDataAPI_Point2D(aSketchLineData.attribute("EndPoint")) +assert (aLineStartPoint.x() == 0) +assert (aLineStartPoint.y() == 0) +assert (not aLineStartPoint.isInitialized()) +assert (aLineEndPoint.x() == 0) +assert (aLineEndPoint.y() == 0) +assert (not aLineEndPoint.isInitialized()) +# Simulate SketchPlugin_Line::move(...) +aLineStartPoint.setValue(50., 50.) +aLineEndPoint.setValue(60., 60.) +assert (aLineStartPoint.isInitialized()) +assert (aLineEndPoint.isInitialized()) +# check that values have been changed +aSketchLineData = aSketchLine.data() +aLineStartPoint = geomDataAPI_Point2D(aSketchLineData.attribute("StartPoint")) +aLineEndPoint= geomDataAPI_Point2D(aSketchLineData.attribute("EndPoint")) +assert (aLineStartPoint.x() == 50.0) +assert (aLineStartPoint.y() == 50.0) +assert (aLineEndPoint.x() == 60.0) +assert (aLineEndPoint.y() == 60.0) +aDocument.finishOperation() +#=============================================================================== +# Check the results +#=============================================================================== +aResult = aSketchLine.firstResult() +aResultConstruction = modelAPI_ResultConstruction(aResult) +aShape = aResultConstruction.shape() +assert (aShape is not None) +assert (not aShape.isNull())