1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <test_HYDROData_StricklerTable.h>
20 #include <HYDROData_Document.h>
21 #include <HYDROData_StricklerTable.h>
22 #include <HYDROData_Tool.h>
23 #include <QStringList>
27 const QString DEF_STR_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/share/salome/resources/hydro/def_strickler_table.txt";
29 void test_HYDROData_StricklerTable::test_import()
31 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
33 Handle(HYDROData_StricklerTable) aTable =
34 Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
36 CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) );
38 QStringList aTypes = aTable->GetTypes();
39 CPPUNIT_ASSERT_EQUAL( 8, aTypes.size() );
40 CPPUNIT_ASSERT_EQUAL( QString( "CODE_06" ), aTable->GetAttrName() );
42 QString aType = "Zones de champs cultivé à végétation basse";
43 CPPUNIT_ASSERT_EQUAL( aType, aTypes[3] );
44 CPPUNIT_ASSERT_EQUAL( QColor( 255, 255, 0 ), aTable->GetColor( aType ) );
45 CPPUNIT_ASSERT_EQUAL( QString( "512" ), aTable->GetAttrValue( aType ) );
47 aType = "Zones à forte urbanization (agglomération)";
48 CPPUNIT_ASSERT_EQUAL( aType, aTypes[7] );
49 CPPUNIT_ASSERT_EQUAL( QColor( 18, 52, 86 ), aTable->GetColor( aType ) );
50 CPPUNIT_ASSERT_EQUAL( QString( "" ), aTable->GetAttrValue( aType ) );
55 void test_HYDROData_StricklerTable::test_import_export_equivalence()
57 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
59 Handle(HYDROData_StricklerTable) aTable =
60 Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
62 CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) );
63 QString aTmpPath = QDir::tempPath() + "/stricker.txt";
64 CPPUNIT_ASSERT_EQUAL( true, aTable->Export( aTmpPath ) );
66 QFile aRefFile( DEF_STR_PATH ), aTmpFile( aTmpPath );
67 CPPUNIT_ASSERT_EQUAL( true, aRefFile.open( QFile::ReadOnly ) );
68 CPPUNIT_ASSERT_EQUAL( true, aTmpFile.open( QFile::ReadOnly ) );
70 QByteArray aRefContents = aRefFile.readAll();
71 QByteArray aTmpContents = aTmpFile.readAll();
73 bool isEqual = aRefContents.size()==aTmpContents.size();
74 CPPUNIT_ASSERT_EQUAL( true, isEqual );
75 for( int i=0, n=aRefContents.size(); isEqual && i<n; i++ )
76 if( aRefContents[i]!=aTmpContents[i] )
79 CPPUNIT_ASSERT_EQUAL( true, isEqual );