Salome HOME
4c0b5f80a3e17f4bcb607bd901e79d839737a635
[modules/hydro.git] / src / HYDRO_tests / test_HYDROData_StricklerTable.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include <test_HYDROData_StricklerTable.h>
20 #include <HYDROData_Document.h>
21 #include <HYDROData_StricklerTable.h>
22 #include <QStringList>
23 #include <QColor>
24 #include <QDir>
25 #include <operators.h>
26
27 const QString DEF_STR_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/share/salome/resources/hydro/def_strickler_table.txt";
28
29 void test_HYDROData_StricklerTable::test_import()
30 {
31   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
32
33   Handle(HYDROData_StricklerTable) aTable =
34     Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
35
36   CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) );
37
38   QStringList aTypes = aTable->GetTypes();
39   CPPUNIT_ASSERT_EQUAL( 8, aTypes.size() );
40   CPPUNIT_ASSERT_EQUAL( QString( "CODE_06" ), aTable->GetAttrName() );
41
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 ) );
46
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 ) );
51
52   aDoc->Close();
53 }
54
55 void test_HYDROData_StricklerTable::test_import_export_equivalence()
56 {
57   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
58
59   Handle(HYDROData_StricklerTable) aTable =
60     Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
61
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 ) );
65
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 ) );
69
70   QByteArray aRefContents = aRefFile.readAll();
71   QByteArray aTmpContents = aTmpFile.readAll();
72
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] )
77       isEqual = false;
78
79   CPPUNIT_ASSERT_EQUAL( true, isEqual );
80
81   aRefFile.close();
82   aTmpFile.close();
83   aDoc->Close();
84 }
85