From: isn Date: Thu, 20 Sep 2018 13:41:15 +0000 (+0300) Subject: automatic tests for boundary polygons X-Git-Tag: HYDRO_V2_0_0~13 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7a00e93240a442a8b424f326ba826a2b5f36d483;p=modules%2Fhydro.git automatic tests for boundary polygons --- diff --git a/src/HYDRO_tests/CMakeLists.txt b/src/HYDRO_tests/CMakeLists.txt index fa147744..9b0cd57c 100644 --- a/src/HYDRO_tests/CMakeLists.txt +++ b/src/HYDRO_tests/CMakeLists.txt @@ -28,6 +28,7 @@ set(PROJECT_HEADERS test_Dependencies.h test_HYDROData_DTM.h + test_HYDROData_BoundaryPolygons.h test_GraphicsView.h test_Overview.h @@ -52,6 +53,7 @@ set(PROJECT_SOURCES test_HYDROData_ShapeFile.cxx test_HYDROData_StricklerTable.cxx test_HYDROData_DTM.cxx + test_HYDROData_BoundaryPolygons.cxx test_HYDROGUI_ListModel.cxx test_HYDROGUI_Shape.cxx test_HYDROGUI_LandCoverMapDlg.cxx diff --git a/src/HYDRO_tests/reference_data/CMakeLists.txt b/src/HYDRO_tests/reference_data/CMakeLists.txt index abc9163d..6732da78 100644 --- a/src/HYDRO_tests/reference_data/CMakeLists.txt +++ b/src/HYDRO_tests/reference_data/CMakeLists.txt @@ -121,6 +121,8 @@ SET(REFERENCE_DATA stream_dtm_2d.png stream_dtm_3d.png pb_1066.cbf + test_boundary_polygon_calc_case_1.cbf + test_boundary_polygon_calc_case_2.cbf f_cmp.brep rebuild_cmp_out.png garonne.png diff --git a/src/HYDRO_tests/reference_data/linux/test_boundary_polygon_calc_case_1.cbf b/src/HYDRO_tests/reference_data/linux/test_boundary_polygon_calc_case_1.cbf new file mode 100644 index 00000000..127ffc3d Binary files /dev/null and b/src/HYDRO_tests/reference_data/linux/test_boundary_polygon_calc_case_1.cbf differ diff --git a/src/HYDRO_tests/reference_data/linux/test_boundary_polygon_calc_case_2.cbf b/src/HYDRO_tests/reference_data/linux/test_boundary_polygon_calc_case_2.cbf new file mode 100644 index 00000000..ccc0d180 Binary files /dev/null and b/src/HYDRO_tests/reference_data/linux/test_boundary_polygon_calc_case_2.cbf differ diff --git a/src/HYDRO_tests/reference_data/win32/test_boundary_polygon_calc_case_1.cbf b/src/HYDRO_tests/reference_data/win32/test_boundary_polygon_calc_case_1.cbf new file mode 100644 index 00000000..e66f44d8 Binary files /dev/null and b/src/HYDRO_tests/reference_data/win32/test_boundary_polygon_calc_case_1.cbf differ diff --git a/src/HYDRO_tests/reference_data/win32/test_boundary_polygon_calc_case_2.cbf b/src/HYDRO_tests/reference_data/win32/test_boundary_polygon_calc_case_2.cbf new file mode 100644 index 00000000..ccc0d180 Binary files /dev/null and b/src/HYDRO_tests/reference_data/win32/test_boundary_polygon_calc_case_2.cbf differ diff --git a/src/HYDRO_tests/test_HYDROData_BoundaryPolygons.cxx b/src/HYDRO_tests/test_HYDROData_BoundaryPolygons.cxx new file mode 100644 index 00000000..18675aee --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_BoundaryPolygons.cxx @@ -0,0 +1,148 @@ +// Copyright (C) 2014-2015 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 +// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern QString REF_DATA_PATH; + +void test_HYDROData_BoundaryPolygons::test_bp_1() +{ + TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data(); + fname += "/test_boundary_polygon_calc_case_1.cbf"; + CPPUNIT_ASSERT_EQUAL( (int)DocError_OK, (int)HYDROData_Document::Load( fname.ToCString(), 1 ) ); + + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + //Calc case already contains already contains 4 boundary poltgons (3 cut, 1 include) + //Update it to recalculate the shape groups + Handle(HYDROData_CalculationCase) aCase = + Handle(HYDROData_CalculationCase)::DownCast( aDoc->FindObjectByName( "Case_1" ) ); + CPPUNIT_ASSERT_EQUAL( false, aCase.IsNull() ); + aCase->Update(); + CPPUNIT_ASSERT_EQUAL(4, aCase->GetBoundaryPolygons().Size()); + HYDROData_SequenceOfObjects aSplitGroups = aCase->GetSplitGroups(); + CPPUNIT_ASSERT_EQUAL(1, aSplitGroups.Size()); + + Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aSplitGroups.First() ); + std::string name = aGroup->GetName().toStdString(); + CPPUNIT_ASSERT_EQUAL( name, std::string("Case_1_Immersible zone_1_Outer") ); + + TopTools_SequenceOfShape aSeqShapes; + aGroup->GetShapes( aSeqShapes ); + CPPUNIT_ASSERT_EQUAL( 78, aSeqShapes.Size()); + BRep_Builder BB; + TopTools_IndexedMapOfShape ME, MV; + GProp_GProps G; + double total_len = 0; + for (int i=1; i<=aSeqShapes.Size();i++) + { + const TopoDS_Shape& aCSH = aSeqShapes(i); + TopExp::MapShapes(aCSH, TopAbs_EDGE, ME); + TopExp::MapShapes(aCSH, TopAbs_VERTEX, MV); + BRepGProp::LinearProperties(aCSH, G); + total_len += G.Mass(); + } + CPPUNIT_ASSERT_EQUAL( 78, ME.Extent()); + CPPUNIT_ASSERT_EQUAL( 78, MV.Extent()); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 22.074, total_len , 0.001); + + aDoc->Close(); +} + +void test_HYDROData_BoundaryPolygons::test_bp_2() +{ + TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data(); + fname += "/test_boundary_polygon_calc_case_2.cbf"; + CPPUNIT_ASSERT_EQUAL( (int)DocError_OK, (int)HYDROData_Document::Load( fname.ToCString(), 1 ) ); + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + //add boundary polygons to case_1 + Handle(HYDROData_CalculationCase) aCase = + Handle(HYDROData_CalculationCase)::DownCast( aDoc->FindObjectByName( "Case_1" ) ); + CPPUNIT_ASSERT_EQUAL( false, aCase.IsNull() ); + double len1=0, len2=0; + { + //check linear properties before applying of boundary polygons + CPPUNIT_ASSERT_EQUAL(0, aCase->GetBoundaryPolygons().Size()); + HYDROData_SequenceOfObjects aSplitGroups = aCase->GetSplitGroups(); + Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aSplitGroups.First() ); + std::string name = aGroup->GetName().toStdString(); + CPPUNIT_ASSERT_EQUAL( name, std::string("Case_1_Immersible zone_1_Outer") ); + TopTools_SequenceOfShape aSeqShapes; + aGroup->GetShapes( aSeqShapes ); + CPPUNIT_ASSERT_EQUAL( 36, aSeqShapes.Size()); + TopTools_IndexedMapOfShape ME, MV; + GProp_GProps G; + for (int i=1; i<=aSeqShapes.Size();i++) + { + const TopoDS_Shape& aCSH = aSeqShapes(i); + BRepGProp::LinearProperties(aCSH, G); + len1 += G.Mass(); + } + CPPUNIT_ASSERT_DOUBLES_EQUAL( 22.074, len1 , 0.001); + } + + //add boudnary polygons to case_1. (3 cut tools, 1 include tool) + Handle(HYDROData_BCPolygon) aBP3 = Handle(HYDROData_BCPolygon)::DownCast( aDoc->FindObjectByName("BP_poly3")); + aCase->AddBoundaryPolygon(aBP3); + Handle(HYDROData_BCPolygon) aBP4 = Handle(HYDROData_BCPolygon)::DownCast( aDoc->FindObjectByName("BP_poly4")); + aCase->AddBoundaryPolygon(aBP4); + Handle(HYDROData_BCPolygon) aBP5 = Handle(HYDROData_BCPolygon)::DownCast( aDoc->FindObjectByName("BP_poly5")); + aCase->AddBoundaryPolygon(aBP5); + Handle(HYDROData_BCPolygon) aBP6 = Handle(HYDROData_BCPolygon)::DownCast( aDoc->FindObjectByName("BP_poly6")); + aCase->AddBoundaryPolygon(aBP6); + + aCase->Update(); + { + //check linear properties after applying of boundary polygons + HYDROData_SequenceOfObjects aSplitGroups = aCase->GetSplitGroups(); + Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aSplitGroups.First() ); + std::string name = aGroup->GetName().toStdString(); + CPPUNIT_ASSERT_EQUAL( name, std::string("Case_1_Immersible zone_1_Outer") ); + + TopTools_SequenceOfShape aSeqShapes; + aGroup->GetShapes( aSeqShapes ); + CPPUNIT_ASSERT_EQUAL( 78, aSeqShapes.Size()); + BRep_Builder BB; + TopTools_IndexedMapOfShape ME, MV; + GProp_GProps G; + + for (int i=1; i<=aSeqShapes.Size();i++) + { + const TopoDS_Shape& aCSH = aSeqShapes(i); + TopExp::MapShapes(aCSH, TopAbs_EDGE, ME); + TopExp::MapShapes(aCSH, TopAbs_VERTEX, MV); + BRepGProp::LinearProperties(aCSH, G); + len2 += G.Mass(); + } + CPPUNIT_ASSERT_EQUAL( 78, ME.Extent()); + CPPUNIT_ASSERT_EQUAL( 78, MV.Extent()); + //len1 == len2 + CPPUNIT_ASSERT_DOUBLES_EQUAL( 22.074, len2, 0.001); + } + + aDoc->Close(); +} + diff --git a/src/HYDRO_tests/test_HYDROData_BoundaryPolygons.h b/src/HYDRO_tests/test_HYDROData_BoundaryPolygons.h new file mode 100644 index 00000000..52833da8 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_BoundaryPolygons.h @@ -0,0 +1,37 @@ +// Copyright (C) 2014-2015 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 +// + +#include + +class test_HYDROData_BoundaryPolygons : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( test_HYDROData_BoundaryPolygons ); + CPPUNIT_TEST( test_bp_1 ); + CPPUNIT_TEST( test_bp_2 ); + CPPUNIT_TEST_SUITE_END(); + +public: + //void setUp(); + //void tearDown() {} + void test_bp_1(); + void test_bp_2(); + +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( test_HYDROData_BoundaryPolygons ); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( test_HYDROData_BoundaryPolygons, "HYDROData_BoundaryPolygons" );