From fec2fc9cc5b707e95da547b422d98c08c2b3f00d Mon Sep 17 00:00:00 2001 From: azv Date: Sun, 9 Dec 2018 16:25:18 +0300 Subject: [PATCH] [Code coverage BuildPlugin]: Improve coverage of Filling and SubShapes features --- src/BuildPlugin/BuildPlugin_Filling.cpp | 4 ++- src/BuildPlugin/Test/TestFilling_ErrorMsg.py | 30 ++++++++++++++++ .../Test/TestSubShapes_ErrorMsg.py | 34 +++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/BuildPlugin/BuildPlugin_Filling.cpp b/src/BuildPlugin/BuildPlugin_Filling.cpp index 73da8375d..6e95dd32c 100644 --- a/src/BuildPlugin/BuildPlugin_Filling.cpp +++ b/src/BuildPlugin/BuildPlugin_Filling.cpp @@ -95,8 +95,10 @@ void BuildPlugin_Filling::execute() // get base objects list AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID()); - if (aSelectionList->size() <= 1) + if (aSelectionList->size() <= 1) { + setError("Not enough objects is selected"); return; + } // collect base shapes for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { diff --git a/src/BuildPlugin/Test/TestFilling_ErrorMsg.py b/src/BuildPlugin/Test/TestFilling_ErrorMsg.py index 8ec5a724f..23ed7e49c 100644 --- a/src/BuildPlugin/Test/TestFilling_ErrorMsg.py +++ b/src/BuildPlugin/Test/TestFilling_ErrorMsg.py @@ -54,9 +54,39 @@ aSession = ModelAPI_Session.get() aSession.startOperation() aFillingFeature = featureToCompositeFeature(Part_1.feature()).addFeature("Filling") aFillingFeature.string("advanced_options").setValue("") +aFillingFeature.execute() +assert(aFillingFeature.error() != "") +aSession.finishOperation() + +aSession.startOperation() aBaseObjectsList = aFillingFeature.selectionList("base_objects") aBaseObjectsList.append("Polyline_1_1/Generated_Edge&Point_1/Point_1", "EDGE") aBaseObjectsList.append("Box_1_1/Top", "FACE") aFillingFeature.execute() assert(aFillingFeature.error() != "") aSession.finishOperation() + + +model.begin() +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() + +Filling_1 = model.addFilling(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchLine_3"), model.selection("EDGE", ""), model.selection("EDGE", "Sketch_1/SketchLine_1")], "auto_correct", 1, 1, 0, 0.0001, 0.0001, False) +assert(Filling_1.feature().error() != "") +Part_1_doc.removeFeature(Filling_1.feature()) + +Filling_1 = model.addFilling(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchLine_3"), model.selection("EDGE", "Sketch_1/SketchLine_4"), model.selection("EDGE", "Sketch_1/SketchLine_1")], "auto_correct", 1, 1, 0, 0.0001, 0.0001, False) +assert(Filling_1.feature().error() != "") +model.end() diff --git a/src/BuildPlugin/Test/TestSubShapes_ErrorMsg.py b/src/BuildPlugin/Test/TestSubShapes_ErrorMsg.py index 9edac3a6f..4260d36da 100644 --- a/src/BuildPlugin/Test/TestSubShapes_ErrorMsg.py +++ b/src/BuildPlugin/Test/TestSubShapes_ErrorMsg.py @@ -29,6 +29,10 @@ Polyline_1_objects = [model.selection("VERTEX", "[Box_1_1/Back][Box_1_1/Left][Bo Polyline_1 = model.addPolyline3D(Part_1_doc, Polyline_1_objects, False) model.do() +SubShapes_1 = model.addSubShapes(Part_1_doc, model.selection("WIRE", "Polyline_1_1"), [model.selection("EDGE", "[Box_1_1/Left][Box_1_1/Top]")]) +assert(SubShapes_1.feature().error() != "") +Part_1_doc.removeFeature(SubShapes_1.feature()) + SubShapes_1 = model.addSubShapes(Part_1_doc, model.selection("WIRE", "Polyline_1_1"), [model.selection("EDGE", "Polyline_1_1/Generated_Edge&weak_name_4")]) assert(SubShapes_1.feature().error() == "") @@ -42,3 +46,33 @@ SubShapes_2 = featureToCompositeFeature(Part_1.feature()).addFeature("SubShapes" SubShapes_2.execute() assert(SubShapes_2.error() == "") aSession.finishOperation() + +model.begin() +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() + +SubShapes_1 = model.addSubShapes(Part_1_doc, model.selection("FACE", "Sketch_1/Face-SketchLine4r-SketchLine3r-SketchLine2r-SketchLine1r"), [model.selection("EDGE", "Sketch_1/SketchLine_1")]) +assert(SubShapes_1.feature().error() != "") +Part_1_doc.removeFeature(SubShapes_1.feature()) + +SubShapes_1 = model.addSubShapes(Part_1_doc, model.selection("WIRE", "Polyline_1_1"), [model.selection("EDGE", "Sketch_1/SketchLine_1")]) +assert(SubShapes_1.feature().error() != "") +Part_1_doc.removeFeature(SubShapes_1.feature()) + +SubShapes_1 = model.addSubShapes(Part_1_doc, model.selection("WIRE", "Polyline_1_1"), [model.selection("VERTEX", "Sketch_1/SketchLine_1_StartVertex")]) +assert(SubShapes_1.feature().error() != "") +Part_1_doc.removeFeature(SubShapes_1.feature()) + +model.end() -- 2.39.2