]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
automatic tests for boundary polygons
authorisn <isn@opencascade.com>
Thu, 20 Sep 2018 13:41:15 +0000 (16:41 +0300)
committerisn <isn@opencascade.com>
Thu, 20 Sep 2018 14:58:46 +0000 (17:58 +0300)
src/HYDRO_tests/CMakeLists.txt
src/HYDRO_tests/reference_data/CMakeLists.txt
src/HYDRO_tests/reference_data/linux/test_boundary_polygon_calc_case_1.cbf [new file with mode: 0644]
src/HYDRO_tests/reference_data/linux/test_boundary_polygon_calc_case_2.cbf [new file with mode: 0644]
src/HYDRO_tests/reference_data/win32/test_boundary_polygon_calc_case_1.cbf [new file with mode: 0644]
src/HYDRO_tests/reference_data/win32/test_boundary_polygon_calc_case_2.cbf [new file with mode: 0644]
src/HYDRO_tests/test_HYDROData_BoundaryPolygons.cxx [new file with mode: 0644]
src/HYDRO_tests/test_HYDROData_BoundaryPolygons.h [new file with mode: 0644]

index fa147744b754e6aae198cd798489f1b70e4482f4..9b0cd57cabcf3fff88cb0c62ef885524ef1a1586 100644 (file)
@@ -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
index abc9163ddeccee4cb1695eca51cab9f67fcfd8ca..6732da7866c8161986270bc889759dd5cdd16870 100644 (file)
@@ -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 (file)
index 0000000..127ffc3
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 (file)
index 0000000..ccc0d18
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 (file)
index 0000000..e66f44d
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 (file)
index 0000000..ccc0d18
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 (file)
index 0000000..18675ae
--- /dev/null
@@ -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 <test_HYDROData_BoundaryPolygons.h>
+#include <HYDROData_Document.h>
+#include <HYDROData_CalculationCase.h>
+#include <QTest>
+#include <BRep_Builder.hxx>
+#include <TopExp.hxx>
+#include <GProp_GProps.hxx>
+#include <BRepGProp.hxx>
+#include <HYDROData_ShapesGroup.h>
+#include <HYDROData_BCPolygon.h>
+
+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 (file)
index 0000000..52833da
--- /dev/null
@@ -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 <cppunit/extensions/HelperMacros.h>
+
+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" );