]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
[Code coverage BuildPlugin]: Unit tests to check error messages in Face and Solid...
authorazv <azv@opencascade.com>
Mon, 10 Dec 2018 11:11:34 +0000 (14:11 +0300)
committerazv <azv@opencascade.com>
Mon, 10 Dec 2018 11:11:34 +0000 (14:11 +0300)
src/BuildPlugin/BuildPlugin_Validators.cpp
src/BuildPlugin/CMakeLists.txt
src/BuildPlugin/Test/TestFace_ErrorMsg.py [new file with mode: 0644]
src/BuildPlugin/Test/TestSolid_ErrorMsg.py [new file with mode: 0644]

index 1dc69c0a38c5566aaf2b651693ef48bd452604cb..3b4c4b950c4d645d2f844163f730110eb815196f 100644 (file)
@@ -26,6 +26,7 @@
 #include <GeomAPI_PlanarEdges.h>
 #include <GeomAPI_Pln.h>
 #include <GeomAPI_ShapeExplorer.h>
+#include <GeomAPI_ShapeIterator.h>
 
 #include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_PaveFiller.h>
@@ -34,8 +35,7 @@
 #include <GeomAlgoAPI_SketchBuilder.h>
 #include <GeomAlgoAPI_WireBuilder.h>
 #include <GeomAlgoAPI_MakeVolume.h>
-#include <GeomAPI_ShapeIterator.h>
-#include <GeomAPI_ShapeExplorer.h>
+#include <GeomAlgoAPI_Tools.h>
 
 #include <GeomValidators_FeatureKind.h>
 #include <GeomValidators_ShapeType.h>
@@ -292,16 +292,9 @@ bool BuildPlugin_ValidatorBaseForSolids::isValid(
   std::shared_ptr<GeomAlgoAPI_MakeVolume> anAlgorithm(
     new GeomAlgoAPI_MakeVolume(anOriginalShapes, false));
 
-  if (!anAlgorithm->isDone()) {
-    theError = "MakeVolume algorithm failed.";
-    return false;
-  }
-  if (anAlgorithm->shape()->isNull()) {
-    theError = "Resulting shape of MakeVolume is Null.";
-    return false;
-  }
-  if (!anAlgorithm->isValid()) {
-    theError = "Resulting shape of MakeVolume is not valid.";
+  std::string anErr;
+  if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(anAlgorithm, "MakeVolume", anErr)) {
+    theError = anErr;
     return false;
   }
 
index e8201b95e6381707a6ca38d59ce5dda83ad8cafe..ac7d138a2689cc8451a73a684913c371ae130510 100644 (file)
@@ -113,8 +113,10 @@ ADD_UNIT_TESTS(TestVertex.py
                TestPolyline.py
                TestInterpolation.py
                TestFace.py
+               TestFace_ErrorMsg.py
                TestShell.py
                TestSolid.py
+               TestSolid_ErrorMsg.py
                TestCompSolid.py
                TestCompound.py
                TestCompound_ErrorMsg.py
diff --git a/src/BuildPlugin/Test/TestFace_ErrorMsg.py b/src/BuildPlugin/Test/TestFace_ErrorMsg.py
new file mode 100644 (file)
index 0000000..4c3a5b9
--- /dev/null
@@ -0,0 +1,50 @@
+## Copyright (C) 2018-20xx  CEA/DEN, EDF R&D
+##
+## This library is free software; you can redistribute it and/or
+## modify it under the terms of the GNU Lesser General Public
+## License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+##
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public
+## License along with this library; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+## See http:##www.salome-platform.org/ or
+## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+##
+
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
+SketchLine_1 = Sketch_1.addLine(30, -30, -30, -30)
+SketchLine_2 = Sketch_1.addLine(-30, -30, -30, 30)
+SketchLine_3 = Sketch_1.addLine(-30, 30, 30, 30)
+SketchLine_4 = Sketch_1.addLine(30, 30, 30, -30)
+SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
+SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
+SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
+SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
+SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
+SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
+SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result())
+SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result())
+model.do()
+
+Face_1 = model.addFace(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchLine_1"), model.selection("EDGE", "Sketch_1/SketchLine_2")])
+assert(Face_1.feature().error() != "")
+Part_1_doc.removeFeature(Face_1.feature())
+
+Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "PartSet/XOY")])
+assert(Face_1.feature().error() != "")
+Part_1_doc.removeFeature(Face_1.feature())
+
+model.end()
diff --git a/src/BuildPlugin/Test/TestSolid_ErrorMsg.py b/src/BuildPlugin/Test/TestSolid_ErrorMsg.py
new file mode 100644 (file)
index 0000000..be02055
--- /dev/null
@@ -0,0 +1,35 @@
+## Copyright (C) 2018-20xx  CEA/DEN, EDF R&D
+##
+## This library is free software; you can redistribute it and/or
+## modify it under the terms of the GNU Lesser General Public
+## License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+##
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public
+## License along with this library; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+## See http:##www.salome-platform.org/ or
+## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+##
+
+from ModelAPI import *
+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()
+
+aSession.startOperation()
+Solid_1 = aPart.addFeature("Solid")
+aSession.finishOperation()
+assert(Solid_1.error() != "")