From 17a28b4e797961b0af91fb9a908e69818ce1faee Mon Sep 17 00:00:00 2001 From: azv Date: Tue, 11 Dec 2018 14:40:27 +0300 Subject: [PATCH] [Code coverage FeaturesPlugin]: Cover errors of LinearCopy, AngularCopy and Fillet features --- src/FeaturesPlugin/CMakeLists.txt | 3 + .../FeaturesPlugin_MultiRotation.cpp | 1 + .../FeaturesPlugin_MultiTranslation.cpp | 17 +-- src/FeaturesPlugin/Test/TestFillet1.py | 50 ++++++++ .../Test/TestMultiRotation_ErrorMsg.py | 72 +++++++++++ .../Test/TestMultiTranslation_ErrorMsg.py | 114 ++++++++++++++++++ 6 files changed, 242 insertions(+), 15 deletions(-) create mode 100644 src/FeaturesPlugin/Test/TestFillet1.py create mode 100644 src/FeaturesPlugin/Test/TestMultiRotation_ErrorMsg.py create mode 100644 src/FeaturesPlugin/Test/TestMultiTranslation_ErrorMsg.py diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 1f3b8934d..35459c7f3 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -193,7 +193,9 @@ ADD_UNIT_TESTS(TestExtrusion.py TestRotation.py TestRotation_ErrorMsg.py TestMultiRotation_Part.py + TestMultiRotation_ErrorMsg.py TestMultiTranslation_Part.py + TestMultiTranslation_ErrorMsg.py TestSymmetry_Part.py TestBoolean1.py TestBoolean2.py @@ -410,6 +412,7 @@ ADD_UNIT_TESTS(TestExtrusion.py TestBooleanFuse_CompSolid_CompSolid.py TestBooleanFuse_CompSolidCompound_CompSolidCompound.py TestFillet.py + TestFillet1.py TestFillet_ErrorMsg.py Test1816.py Test2631.py diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp b/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp index 622ea8de8..4206e904f 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp @@ -85,6 +85,7 @@ void FeaturesPlugin_MultiRotation::performRotation1D() AttributeSelectionListPtr anObjectsSelList = selectionList(FeaturesPlugin_MultiRotation::OBJECTS_LIST_ID()); if (anObjectsSelList->size() == 0) { + setError("Error: empty selection list"); return; } for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) { diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp index d0e5360c4..ba1c1e8df 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp @@ -88,6 +88,7 @@ void FeaturesPlugin_MultiTranslation::performOneDirection() AttributeSelectionListPtr anObjectsSelList = selectionList(FeaturesPlugin_MultiTranslation::OBJECTS_LIST_ID()); if (anObjectsSelList->size() == 0) { + setError("Error: empty selection list"); return; } for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) { @@ -125,11 +126,6 @@ void FeaturesPlugin_MultiTranslation::performOneDirection() GeomAPI_ShapeIterator anIt(aShape); anEdge = anIt.current()->edge(); } - else - { - setError(aSelectionError); - return; - } if (!anEdge.get()) { @@ -222,6 +218,7 @@ void FeaturesPlugin_MultiTranslation::performTwoDirection() AttributeSelectionListPtr anObjectsSelList = selectionList(FeaturesPlugin_MultiTranslation::OBJECTS_LIST_ID()); if (anObjectsSelList->size() == 0) { + setError("Error: empty selection list"); return; } for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) { @@ -259,11 +256,6 @@ void FeaturesPlugin_MultiTranslation::performTwoDirection() GeomAPI_ShapeIterator anIt(aShape); anEdge = anIt.current()->edge(); } - else - { - setError(aSelectionError); - return; - } if (!anEdge.get()) { @@ -296,11 +288,6 @@ void FeaturesPlugin_MultiTranslation::performTwoDirection() GeomAPI_ShapeIterator anIt(aShape); anEdge = anIt.current()->edge(); } - else - { - setError(aSelectionError); - return; - } if (!anEdge.get()) { diff --git a/src/FeaturesPlugin/Test/TestFillet1.py b/src/FeaturesPlugin/Test/TestFillet1.py new file mode 100644 index 000000000..9c5bf9366 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestFillet1.py @@ -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 +## + +from salome.shaper import model +from GeomAPI import GeomAPI_Shape + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) + +Fillet_1 = model.addFillet(Part_1_doc, [model.selection("EDGE", "all-in-Box_1")], 2) +assert(Fillet_1.feature().error() == "") + +model.testNbResults(Fillet_1, 1) +model.testNbSubResults(Fillet_1, [0]) +model.testNbSubShapes(Fillet_1, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Fillet_1, GeomAPI_Shape.FACE, [26]) +model.testNbSubShapes(Fillet_1, GeomAPI_Shape.EDGE, [104]) +model.testNbSubShapes(Fillet_1, GeomAPI_Shape.VERTEX, [208]) +model.testResultsVolumes(Fillet_1, [907.704992710141368661425076425]) + +Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Box_1_1/Top")) +SketchCircle_1 = Sketch_1.addCircle(20, -15, 5) +SketchCircle_2 = Sketch_1.addCircle(30, 10, 3) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), 10, 0) + +Fillet_2 = model.addFillet(Part_1_doc, [model.selection("EDGE", "all-in-Extrusion_1")], 2) +assert(Fillet_2.feature().error() != "") + +model.end() diff --git a/src/FeaturesPlugin/Test/TestMultiRotation_ErrorMsg.py b/src/FeaturesPlugin/Test/TestMultiRotation_ErrorMsg.py new file mode 100644 index 000000000..4675f04e6 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestMultiRotation_ErrorMsg.py @@ -0,0 +1,72 @@ +## 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 +## + + +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() + +# Create auxiliary box +aSession.startOperation() +aBox = aPart.addFeature("Box") +aBox.string("CreationMethod").setValue("BoxByDimensions") +aBox.real("dx").setValue(50) +aBox.real("dy").setValue(50) +aBox.real("dz").setValue(50) +aSession.finishOperation() + +# Create auxiliary compound +aSession.startOperation() +aCompound = aPart.addFeature("Compound") +aCompound.selectionList("base_objects").append("Box_1_1", "SOLID") +aSession.finishOperation() + + +aSession.startOperation() +anAngularCopy1 = aPart.addFeature("AngularCopy") +anAngularCopy1.execute() +assert(anAngularCopy1.error() != "") +aSession.finishOperation() + +aSession.startOperation() +anAngularCopy1.selectionList("main_objects").append("Compound_1_1", "COMPOUND") +anAngularCopy1.execute() +assert(anAngularCopy1.error() != "") +aSession.finishOperation() + +aSession.startOperation() +anAngularCopy1.selection("axis_angular").selectSubShape("COMPOUND", "Compound_1_1") +anAngularCopy1.execute() +assert(anAngularCopy1.error() != "") +aSession.finishOperation() + +aSession.startOperation() +anAngularCopy1.selection("axis_angular").selectSubShape("EDGE", "PartSet/OX") +anAngularCopy1.integer("nb_angular").setValue(0) +anAngularCopy1.execute() +assert(anAngularCopy1.error() != "") +aSession.finishOperation() diff --git a/src/FeaturesPlugin/Test/TestMultiTranslation_ErrorMsg.py b/src/FeaturesPlugin/Test/TestMultiTranslation_ErrorMsg.py new file mode 100644 index 000000000..f5bbd13bc --- /dev/null +++ b/src/FeaturesPlugin/Test/TestMultiTranslation_ErrorMsg.py @@ -0,0 +1,114 @@ +## 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 +## + + +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() + +# Create auxiliary box +aSession.startOperation() +aBox = aPart.addFeature("Box") +aBox.string("CreationMethod").setValue("BoxByDimensions") +aBox.real("dx").setValue(50) +aBox.real("dy").setValue(50) +aBox.real("dz").setValue(50) +aSession.finishOperation() + +# Create auxiliary compound +aSession.startOperation() +aCompound = aPart.addFeature("Compound") +aCompound.selectionList("base_objects").append("Box_1_1", "SOLID") +aSession.finishOperation() + + +aSession.startOperation() +aLinearCopy1 = aPart.addFeature("LinearCopy") +aLinearCopy1.execute() +assert(aLinearCopy1.error() != "") +aSession.finishOperation() + +aSession.startOperation() +aLinearCopy1.selectionList("main_objects").append("Compound_1_1", "COMPOUND") +aLinearCopy1.execute() +assert(aLinearCopy1.error() != "") +aSession.finishOperation() + +aSession.startOperation() +aLinearCopy1.selection("axis_first_dir").selectSubShape("COMPOUND", "Compound_1_1") +aLinearCopy1.execute() +assert(aLinearCopy1.error() != "") +aSession.finishOperation() + +aSession.startOperation() +aLinearCopy1.selection("axis_first_dir").selectSubShape("EDGE", "PartSet/OX") +aLinearCopy1.integer("nb_first_dir").setValue(2) +aLinearCopy1.execute() +assert(aLinearCopy1.error() != "") +aSession.finishOperation() + + +aSession.startOperation() +aLinearCopy2 = aPart.addFeature("LinearCopy") +aLinearCopy2.string("use_second_dir").setValue("true") +aLinearCopy2.execute() +assert(aLinearCopy2.error() != "") +aSession.finishOperation() + +aSession.startOperation() +aLinearCopy2.selectionList("main_objects").append("Compound_1_1", "COMPOUND") +aLinearCopy2.execute() +assert(aLinearCopy2.error() != "") +aSession.finishOperation() + +aSession.startOperation() +aLinearCopy2.selection("axis_first_dir").selectSubShape("COMPOUND", "Compound_1_1") +aLinearCopy2.execute() +assert(aLinearCopy2.error() != "") +aSession.finishOperation() + +aSession.startOperation() +aLinearCopy2.selection("axis_first_dir").selectSubShape("EDGE", "PartSet/OX") +aLinearCopy2.selection("axis_second_dir").selectSubShape("COMPOUND", "Compound_1_1") +aLinearCopy2.execute() +assert(aLinearCopy2.error() != "") +aSession.finishOperation() + +aSession.startOperation() +aLinearCopy2.selection("axis_second_dir").selectSubShape("EDGE", "PartSet/OY") +aLinearCopy2.integer("nb_first_dir").setValue(0) +aLinearCopy2.integer("nb_second_dir").setValue(0) +aLinearCopy2.execute() +assert(aLinearCopy2.error() != "") +aSession.finishOperation() + +aSession.startOperation() +aLinearCopy2.integer("nb_first_dir").setValue(2) +aLinearCopy2.integer("nb_second_dir").setValue(2) +aLinearCopy2.execute() +assert(aLinearCopy2.error() != "") +aSession.finishOperation() -- 2.39.2