Salome HOME
custom test runner to run only a subset of complete test suite
[modules/hydro.git] / src / HYDRO_tests / test_HYDROData_StricklerTable.cxx
index 4cf579891f65d205661c11874810eea6c2198c79..f59a19122998a49061d8f8517c194b2e9d8e83bf 100644 (file)
 
 #include <test_HYDROData_StricklerTable.h>
 #include <HYDROData_Document.h>
+#include <HYDROData_StricklerTable.h>
+#include <HYDROData_Tool.h>
+#include <QStringList>
+#include <QColor>
+#include <QDir>
 
-void test_HYDROData_StricklerTable::testImport()
+const QString DEF_STR_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/share/salome/resources/hydro/def_strickler_table.txt";
+
+void test_HYDROData_StricklerTable::test_import()
 {
   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
 
-  Handle(HYDROData_Entity) anObj = aDoc->CreateObject( KIND_STRICKLER_TABLE );
-  TCollection_AsciiString aFileName = "test_name";
-  
+  Handle(HYDROData_StricklerTable) aTable =
+    Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
+
+  CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) );
+
+  QStringList aTypes = aTable->GetTypes();
+  CPPUNIT_ASSERT_EQUAL( 8, aTypes.size() );
+  CPPUNIT_ASSERT_EQUAL( QString( "CODE_06" ), aTable->GetAttrName() );
+
+  QString aType = "Zones de champs cultivé à végétation basse";
+  CPPUNIT_ASSERT_EQUAL( aType, aTypes[3] );
+  CPPUNIT_ASSERT_EQUAL( QColor( 255, 255, 0 ), aTable->GetColor( aType ) );
+  CPPUNIT_ASSERT_EQUAL( QString( "512" ), aTable->GetAttrValue( aType ) );
+
+  aType = "Zones à forte urbanization (agglomération)";
+  CPPUNIT_ASSERT_EQUAL( aType, aTypes[7] );
+  CPPUNIT_ASSERT_EQUAL( QColor( 18, 52, 86 ), aTable->GetColor( aType ) );
+  CPPUNIT_ASSERT_EQUAL( QString( "" ), aTable->GetAttrValue( aType ) );
+
   aDoc->Close();
 }
+
+void test_HYDROData_StricklerTable::test_import_export_equivalence()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+
+  Handle(HYDROData_StricklerTable) aTable =
+    Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
+
+  CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) );
+  QString aTmpPath = QDir::tempPath() + "/stricker.txt";
+  CPPUNIT_ASSERT_EQUAL( true, aTable->Export( aTmpPath ) );
+
+  QFile aRefFile( DEF_STR_PATH ), aTmpFile( aTmpPath );
+  CPPUNIT_ASSERT_EQUAL( true, aRefFile.open( QFile::ReadOnly ) );
+  CPPUNIT_ASSERT_EQUAL( true, aTmpFile.open( QFile::ReadOnly ) );
+
+  QByteArray aRefContents = aRefFile.readAll();
+  QByteArray aTmpContents = aTmpFile.readAll();
+
+  bool isEqual = aRefContents.size()==aTmpContents.size();
+  CPPUNIT_ASSERT_EQUAL( true, isEqual );
+  for( int i=0, n=aRefContents.size(); isEqual && i<n; i++ )
+    if( aRefContents[i]!=aTmpContents[i] )
+      isEqual = false;
+
+  CPPUNIT_ASSERT_EQUAL( true, isEqual );
+
+  aRefFile.close();
+  aTmpFile.close();
+  aDoc->Close();
+}
+