From 7323b677186e0b8d27dde50edb7b6ce69b2aaa20 Mon Sep 17 00:00:00 2001 From: isn Date: Mon, 19 Oct 2015 21:08:06 +0300 Subject: [PATCH] test for lcm dbf writer --- src/HYDROData/HYDROData_LandCoverMap.cxx | 6 ++- src/HYDROData/HYDROData_LandCoverMap.h | 1 + src/HYDRO_tests/reference_data/t1.dbf | Bin 0 -> 182 bytes .../test_HYDROData_LandCoverMap.cxx | 43 +++++++++++++++++- src/HYDRO_tests/test_HYDROData_LandCoverMap.h | 2 + 5 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 src/HYDRO_tests/reference_data/t1.dbf diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index 449c443e..df81386e 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -210,8 +210,10 @@ HYDROData_LandCoverMap::DBFStatus HYDROData_LandCoverMap::ImportDBF( const QStri const QStringList& theStricklerTypes, QMap 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; } diff --git a/src/HYDROData/HYDROData_LandCoverMap.h b/src/HYDROData/HYDROData_LandCoverMap.h index 7c3120bd..cecb811d 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.h +++ b/src/HYDROData/HYDROData_LandCoverMap.h @@ -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 index 0000000000000000000000000000000000000000..65eed91de89b2bde449f93c2d28642c60af167b2 GIT binary patch literal 182 zcmZSK=MrXSU|>jOkO7hm3|Uimv49yM0w@vU8XV&0>FVQR#Nf;b6ykzQLKtv)Lk4GV kppYP%Jg #include #include - +#include #include #include @@ -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() << 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() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 ); + CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) ); + + CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) ); + QMap 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 diff --git a/src/HYDRO_tests/test_HYDROData_LandCoverMap.h b/src/HYDRO_tests/test_HYDROData_LandCoverMap.h index a891c39c..4f10b1ed 100644 --- a/src/HYDRO_tests/test_HYDROData_LandCoverMap.h +++ b/src/HYDRO_tests/test_HYDROData_LandCoverMap.h @@ -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 ); -- 2.39.2