From: asl Date: Thu, 15 Oct 2015 13:29:41 +0000 (+0300) Subject: #659: synchronization tests X-Git-Tag: v1.5~109^2~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=87982cd6d5e60a396533ae209d91b22edeb831fe;p=modules%2Fhydro.git #659: synchronization tests --- diff --git a/src/HYDROData/HYDROData_StricklerTable.cxx b/src/HYDROData/HYDROData_StricklerTable.cxx index 212f9543..13a6e529 100644 --- a/src/HYDROData/HYDROData_StricklerTable.cxx +++ b/src/HYDROData/HYDROData_StricklerTable.cxx @@ -18,6 +18,7 @@ #include #include +#include #include @@ -241,9 +242,22 @@ QString HYDROData_StricklerTable::GetAttrName() const } return QString();} -void HYDROData_StricklerTable::SetAttrName( const QString& theAttrName ) const +bool HYDROData_StricklerTable::SetAttrName( const QString& theAttrName ) const { + HYDROData_Iterator anIt( HYDROData_Document::Document( myLab ), KIND_STRICKLER_TABLE ); + for( ; anIt.More(); anIt.Next() ) + { + Handle( HYDROData_StricklerTable ) aTable = + Handle( HYDROData_StricklerTable )::DownCast( anIt.Current() ); + if( aTable->Label()==myLab ) + continue; + + if( theAttrName==aTable->GetAttrName() ) + return false; + } + TDataStd_AsciiString::Set( myLab.FindChild( DataTag_AttrName ), HYDROData_Tool::toExtString( theAttrName ) ); + return true; } QString HYDROData_StricklerTable::GetAttrValue( const QString& theType ) const @@ -265,6 +279,9 @@ void HYDROData_StricklerTable::SetAttrValue( const QString& theType, const QStri QString HYDROData_StricklerTable::GetType( const QString& theAttrValue ) const { + if( theAttrValue.isEmpty() ) + return ""; + Handle( TDataStd_NamedData ) aMap = Map(); TCollection_ExtendedString anAttrValue = HYDROData_Tool::toExtString( theAttrValue ); for( TDataStd_DataMapIteratorOfDataMapOfStringString it( aMap->GetStringsContainer() ); it.More(); it.Next() ) @@ -303,4 +320,17 @@ void HYDROData_StricklerTable::SetColor( const QString& theType, const QColor& t int b = theColor.blue(); int aColorInt = ( r<<16 ) + ( g<<8 ) + b; aMap->SetInteger( aType, aColorInt ); + + // synchronize the color for the same type in other maps + HYDROData_Iterator anIt( HYDROData_Document::Document( myLab ), KIND_STRICKLER_TABLE ); + for( ; anIt.More(); anIt.Next() ) + { + Handle( HYDROData_StricklerTable ) aTable = + Handle( HYDROData_StricklerTable )::DownCast( anIt.Current() ); + if( aTable->Label()==myLab ) + continue; + + if( aTable->HasType( theType ) ) + aTable->Map()->SetInteger( aType, aColorInt ); + } } diff --git a/src/HYDROData/HYDROData_StricklerTable.h b/src/HYDROData/HYDROData_StricklerTable.h index 34d2b304..6c081e1b 100644 --- a/src/HYDROData/HYDROData_StricklerTable.h +++ b/src/HYDROData/HYDROData_StricklerTable.h @@ -62,7 +62,7 @@ public: HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; HYDRODATA_EXPORT QString GetAttrName() const; - HYDRODATA_EXPORT void SetAttrName( const QString& ) const; + HYDRODATA_EXPORT bool SetAttrName( const QString& ) const; HYDRODATA_EXPORT QString GetAttrValue( const QString& theType ) const; HYDRODATA_EXPORT void SetAttrValue( const QString& theType, const QString& theAttrValue ) const; diff --git a/src/HYDRO_tests/test_HYDROData_StricklerTable.cxx b/src/HYDRO_tests/test_HYDROData_StricklerTable.cxx index f59a1912..a7c2da12 100644 --- a/src/HYDRO_tests/test_HYDROData_StricklerTable.cxx +++ b/src/HYDRO_tests/test_HYDROData_StricklerTable.cxx @@ -83,3 +83,70 @@ void test_HYDROData_StricklerTable::test_import_export_equivalence() aDoc->Close(); } +void test_HYDROData_StricklerTable::test_type_by_attr() +{ + 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 ) ); + + CPPUNIT_ASSERT_EQUAL( QString( "Zones de champs cultivé à végétation basse" ), aTable->GetType( "512" ) ); + CPPUNIT_ASSERT_EQUAL( QString( "" ), aTable->GetType( "123" ) ); + CPPUNIT_ASSERT_EQUAL( QString( "" ), aTable->GetType( "" ) ); + + aDoc->Close(); +} + +void test_HYDROData_StricklerTable::test_unique_attr_name() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_StricklerTable) aTable1 = + Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) ); + Handle(HYDROData_StricklerTable) aTable2 = + Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) ); + + CPPUNIT_ASSERT_EQUAL( true, aTable1->SetAttrName( "CODE_06" ) ); + CPPUNIT_ASSERT_EQUAL( QString( "CODE_06" ), aTable1->GetAttrName() ); + CPPUNIT_ASSERT_EQUAL( QString( "" ), aTable2->GetAttrName() ); + + CPPUNIT_ASSERT_EQUAL( false, aTable2->SetAttrName( "CODE_06" ) ); + CPPUNIT_ASSERT_EQUAL( QString( "CODE_06" ), aTable1->GetAttrName() ); + CPPUNIT_ASSERT_EQUAL( QString( "" ), aTable2->GetAttrName() ); + + CPPUNIT_ASSERT_EQUAL( true, aTable2->SetAttrName( "CODE_07" ) ); + CPPUNIT_ASSERT_EQUAL( QString( "CODE_06" ), aTable1->GetAttrName() ); + CPPUNIT_ASSERT_EQUAL( QString( "CODE_07" ), aTable2->GetAttrName() ); + + CPPUNIT_ASSERT_EQUAL( false, aTable1->SetAttrName( "CODE_07" ) ); + CPPUNIT_ASSERT_EQUAL( QString( "CODE_06" ), aTable1->GetAttrName() ); + CPPUNIT_ASSERT_EQUAL( QString( "CODE_07" ), aTable2->GetAttrName() ); + + aDoc->Close(); +} + +void test_HYDROData_StricklerTable::test_colors_sync() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_StricklerTable) aTable1 = + Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) ); + Handle(HYDROData_StricklerTable) aTable2 = + Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) ); + + aTable1->Set( "test1", 10 ); + aTable1->Set( "test2", 20 ); + aTable1->SetColor( "test1", QColor( 255, 0, 0 ) ); + aTable1->SetColor( "test2", QColor( 255, 0, 1 ) ); + CPPUNIT_ASSERT_EQUAL( QColor( 255, 0, 0 ), aTable1->GetColor( "test1" ) ); + CPPUNIT_ASSERT_EQUAL( QColor( 255, 0, 1 ), aTable1->GetColor( "test2" ) ); + + aTable2->Set( "test1", 15 ); + aTable2->SetColor( "test1", QColor( 255, 255, 0 ) ); + CPPUNIT_ASSERT_EQUAL( QColor( 255, 255, 0 ), aTable1->GetColor( "test1" ) ); + CPPUNIT_ASSERT_EQUAL( QColor( 255, 255, 0 ), aTable2->GetColor( "test1" ) ); + + aDoc->Close(); +} diff --git a/src/HYDRO_tests/test_HYDROData_StricklerTable.h b/src/HYDRO_tests/test_HYDROData_StricklerTable.h index c19705f0..d12244ce 100644 --- a/src/HYDRO_tests/test_HYDROData_StricklerTable.h +++ b/src/HYDRO_tests/test_HYDROData_StricklerTable.h @@ -27,11 +27,17 @@ class test_HYDROData_StricklerTable : public CppUnit::TestFixture CPPUNIT_TEST_SUITE( test_HYDROData_StricklerTable ); CPPUNIT_TEST( test_import ); CPPUNIT_TEST( test_import_export_equivalence ); + CPPUNIT_TEST( test_type_by_attr ); + CPPUNIT_TEST( test_unique_attr_name ); + CPPUNIT_TEST( test_colors_sync ); CPPUNIT_TEST_SUITE_END(); public: void test_import(); void test_import_export_equivalence(); + void test_type_by_attr(); + void test_unique_attr_name(); + void test_colors_sync(); }; CPPUNIT_TEST_SUITE_REGISTRATION( test_HYDROData_StricklerTable );