]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
#650: land cover addition test uses now the images comparison
authorasl <asl@opencascade.com>
Wed, 14 Oct 2015 08:44:15 +0000 (11:44 +0300)
committerasl <asl@opencascade.com>
Wed, 14 Oct 2015 08:44:15 +0000 (11:44 +0300)
src/HYDRO_tests/TestViewer.cxx
src/HYDRO_tests/TestViewer.h
src/HYDRO_tests/reference_data/LandCoverMap_Add_2_Objects.png [new file with mode: 0644]
src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx
src/HYDRO_tests/test_HYDROData_Main.cxx

index e0a532c4a49a887f37d83a439ad1a98ac0a092b1..96eaec9030fb8af7154b31e822d530c164c64bc6 100644 (file)
@@ -7,6 +7,7 @@
 #include <AIS_Shape.hxx>
 #include <TopoDS_Iterator.hxx>
 #include <QDir>
+#include <cppunit/TestAssert.h>
 
 OCCViewer_ViewManager* TestViewer::myViewManager = 0;
 OCCViewer_ViewWindow* TestViewer::myViewWindow = 0;
@@ -82,11 +83,39 @@ void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll
   viewWindow()->onFitAll();
 }
 
-void TestViewer::dump( const TopoDS_Shape& theShape, int theMode, const QString& theName )
+bool AreImagesEqual( const QImage& theImage1, const QImage& theImage2, double theTolerance = 0.0 )
 {
-  show( theShape, theMode, true );
-  QImage anImage = viewWindow()->dumpView();
+  if( theImage1.isNull() || theImage2.isNull() )
+    return theImage1.isNull() == theImage2.isNull();
 
-  QString aPath = QDir::tempPath() + "/" + theName + ".png";
-  anImage.save( aPath );
+  if( theImage1.size() != theImage2.size() )
+    return false;
+
+  int aBytesCount = theImage1.byteCount();
+  const uchar *aBytes1 = theImage1.constBits();
+  const uchar *aBytes2 = theImage2.constBits();
+  for( int i=0; i<aBytesCount; i++ )
+    if( aBytes1[i] != aBytes2[i] )
+      return false;
+
+  return true;
+}
+
+bool TestViewer::AssertEqual( const QString& theUseCaseName )
+{
+  QImage anActualImage = viewWindow()->dumpView();
+
+  QString anExpectedRefFilePath = qgetenv( "HYDRO_REFERENCE_DATA" );
+  anExpectedRefFilePath += "/" + theUseCaseName + ".png";
+  QImage anExpectedRefImage; 
+  anExpectedRefImage.load( anExpectedRefFilePath );
+
+  if( AreImagesEqual( anActualImage, anExpectedRefImage ) )
+    return true;
+
+  QString aPath = QDir::tempPath() + "/" + theUseCaseName + ".png";
+  anActualImage.save( aPath );
+  std::string aMessage = "The viewer contents does not correspond to the reference image: " + theUseCaseName.toStdString();
+  CPPUNIT_FAIL( aMessage.c_str() );
+  return false;
 }
index 8b843ad1917767f4782d7afab75ddd35933b8d06..e825208bd147763461d40ebfa20e2a2db636a7c4 100644 (file)
@@ -17,7 +17,7 @@ public:
 
   static void show( const TopoDS_Shape& theShape, const QColor& theColor, int theMode );
   static void show( const TopoDS_Shape& theShape, int theMode, bool isFitAll = true );
-  static void dump( const TopoDS_Shape& theShape, int theMode, const QString& theName );
+  static bool AssertEqual( const QString& theUseCaseName );
 
 private:
   static OCCViewer_ViewManager* myViewManager;
diff --git a/src/HYDRO_tests/reference_data/LandCoverMap_Add_2_Objects.png b/src/HYDRO_tests/reference_data/LandCoverMap_Add_2_Objects.png
new file mode 100644 (file)
index 0000000..86bdba3
Binary files /dev/null and b/src/HYDRO_tests/reference_data/LandCoverMap_Add_2_Objects.png differ
index d2df73aa702fd9062c131f65d78368dd27ad9c3e..aa9135f47f6073a29ae4445688e8c170dc80f201 100644 (file)
@@ -81,6 +81,7 @@ void test_HYDROData_LandCoverMap::test_local_partition()
   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
 
   TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
+  TestViewer::AssertEqual( "LandCoverMap_Add_2_Objects" );
 
   aDoc->Close();
 }
index 157fee69a0e2cf241ddc35421b9a77624b0ee465..5b1367cbd1f5020e586b10b1f8014ea601d5e5d6 100644 (file)
@@ -78,6 +78,6 @@ int main( int argc, char* argv[] )
     return 0;
   }
 
-  anApp.exec();
+  //anApp.exec();
   return result.wasSuccessful() ? 0 : 1;
 }