]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
test for lcm dbf writer
authorisn <isn@opencascade.com>
Mon, 19 Oct 2015 18:08:06 +0000 (21:08 +0300)
committerisn <isn@opencascade.com>
Mon, 19 Oct 2015 18:08:06 +0000 (21:08 +0300)
src/HYDROData/HYDROData_LandCoverMap.cxx
src/HYDROData/HYDROData_LandCoverMap.h
src/HYDRO_tests/reference_data/t1.dbf [new file with mode: 0644]
src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx
src/HYDRO_tests/test_HYDROData_LandCoverMap.h

index 449c443e57a404c5e0db173570de386dc22f87ef..df81386e0c7ea3f02c297d67a93d24375a30f739 100644 (file)
@@ -210,8 +210,10 @@ HYDROData_LandCoverMap::DBFStatus HYDROData_LandCoverMap::ImportDBF( const QStri
                                                                      const QStringList& theStricklerTypes,
                                                                      QMap<int, int> theIndices )
 {
+  if (theDBFValues.size() != theStricklerTypes.size())
+    return DBFStatus_DIFF_SIZE_ERROR;
   HYDROData_ShapeFile aDBFImporter;
-  if (aDBFImporter.DBF_OpenDBF(theDBFFileName))
+  if (!aDBFImporter.DBF_OpenDBF(theDBFFileName))
     return DBFStatus_OPEN_FILE_ERROR; //cant open file
 
   QStringList FieldList = aDBFImporter.DBF_GetFieldList();
@@ -230,7 +232,7 @@ HYDROData_LandCoverMap::DBFStatus HYDROData_LandCoverMap::ImportDBF( const QStri
     HYDROData_ShapeFile::DBF_AttrValue AValue = theAttrV[theIndices[CurIndex]];
     int StricklerTypesInd = theDBFValues.indexOf(QString(AValue.myStrVal));
     if ( StricklerTypesInd != -1)
-      anIt.SetStricklerType(theDBFValues[StricklerTypesInd]);
+      anIt.SetStricklerType(theStricklerTypes[StricklerTypesInd]);
     else
       allOK = false;
   }
index 7c3120bdbf653a90a5b6691da1f0b05510a0856f..cecb811d2bb65a75dfe959c194013147506e607f 100644 (file)
@@ -72,6 +72,7 @@ public:
   enum DBFStatus
   {
     DBFStatus_OK,
+    DBFStatus_DIFF_SIZE_ERROR,
     DBFStatus_OPEN_FILE_ERROR,
     DBFStatus_NO_SUCH_FIELD_ERROR,
     DBFStatus_NO_DBFVALUES_CORRESPONDENCE_WARNING
diff --git a/src/HYDRO_tests/reference_data/t1.dbf b/src/HYDRO_tests/reference_data/t1.dbf
new file mode 100644 (file)
index 0000000..65eed91
Binary files /dev/null and b/src/HYDRO_tests/reference_data/t1.dbf differ
index d9923b80919f992f0715220c8a7e90c4b7c7620c..a2219f248bb5725daf99a20134a7d187abcd7d96 100644 (file)
@@ -34,7 +34,7 @@
 #include <AIS_DisplayMode.hxx>
 #include <QString>
 #include <QColor>
-
+#include <QMap>
 #include <BRepTools.hxx>
 #include <BRep_Builder.hxx>
 
@@ -445,4 +445,45 @@ void test_HYDROData_LandCoverMap::test_merge_faces_circles()
     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
   }
 
+}
+
+void test_HYDROData_LandCoverMap::test_import_dbf()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+
+  Handle(HYDROData_LandCoverMap) aMap =
+    Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
+
+  CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
+  QString aFileName = REF_DATA_PATH + "/t1.dbf";
+  QStringList aDBFV;
+  QStringList aST;
+  aDBFV.append("100");
+  aDBFV.append("200");
+  aDBFV.append("300");
+  aST.append("water");
+  aST.append("forest");
+  aST.append("road");
+  // aST.size() == aDBFV.size()!!
+  Handle(HYDROData_PolylineXY) aPolyline =
+    Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
+  TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( Spline( QList<double>() << 10 << 40 << 30 << 10 << 40 << 10 << 60 << 10 ) ).Wire();
+  aPolyline->SetShape( aWire );
+  for (int i = 0; i < 3; i++)
+    aMap->Add(aPolyline, "");
+  TopoDS_Face aLC1 = LandCover( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
+  CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
+  
+  CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
+  QMap<int, int> Inds;
+  Inds.insert(1, 1);
+  Inds.insert(2, 2);
+  Inds.insert(3, 3);
+  aMap->ImportDBF(aFileName, "TESTFIELD1", aDBFV, aST, Inds);
+  HYDROData_LandCoverMap::Iterator anIt( aMap );
+  CPPUNIT_ASSERT_EQUAL(true, "water" == anIt.StricklerType());
+  anIt.Next();
+  CPPUNIT_ASSERT_EQUAL(true, "forest" == anIt.StricklerType());
+
 }
\ No newline at end of file
index a891c39c04680cf1211b840b1154926ad3817ca6..4f10b1edae96c4b2a00892e3a9ca4bfe48ae7e78 100644 (file)
@@ -32,6 +32,7 @@ class test_HYDROData_LandCoverMap : public CppUnit::TestFixture
   CPPUNIT_TEST( test_remove );
   CPPUNIT_TEST( test_merge_faces_boxes );
   CPPUNIT_TEST( test_merge_faces_circles );
+  CPPUNIT_TEST( test_import_dbf );
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -42,6 +43,7 @@ public:
   void test_remove();
   void test_merge_faces_boxes();
   void test_merge_faces_circles();
+  void test_import_dbf();
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION( test_HYDROData_LandCoverMap );