]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
#659: synchronization tests
authorasl <asl@opencascade.com>
Thu, 15 Oct 2015 13:29:41 +0000 (16:29 +0300)
committerasl <asl@opencascade.com>
Thu, 15 Oct 2015 13:29:41 +0000 (16:29 +0300)
src/HYDROData/HYDROData_StricklerTable.cxx
src/HYDROData/HYDROData_StricklerTable.h
src/HYDRO_tests/test_HYDROData_StricklerTable.cxx
src/HYDRO_tests/test_HYDROData_StricklerTable.h

index 212f9543f51193b9919010ef3f4dc26ff63a3138..13a6e529a47284cc10aa7481f25da4e64aa834a2 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <HYDROData_StricklerTable.h>
 #include <HYDROData_Tool.h>
+#include <HYDROData_Iterator.h>
 
 #include <TDataStd_NamedData.hxx>
 
@@ -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 );
+  }
 }
index 34d2b3048d046aa7ea4b550e96e2d923937a32f4..6c081e1b81794d363625c6cfd251dfabda923904 100644 (file)
@@ -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;
index f59a19122998a49061d8f8517c194b2e9d8e83bf..a7c2da126e81bec5763c0da90480f39290d411fd 100644 (file)
@@ -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();
+}
index c19705f0a443e33dac3193514b6423a821208d89..d12244ce276f38adb4197b59dc9d176bd70dd4c5 100644 (file)
@@ -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 );