From: asl Date: Wed, 14 Oct 2015 08:44:15 +0000 (+0300) Subject: #650: land cover addition test uses now the images comparison X-Git-Tag: v1.5~128 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=158b3949f0d12e3a4b36c6f37b270e0f7f037262;p=modules%2Fhydro.git #650: land cover addition test uses now the images comparison --- diff --git a/src/HYDRO_tests/TestViewer.cxx b/src/HYDRO_tests/TestViewer.cxx index e0a532c4..96eaec90 100644 --- a/src/HYDRO_tests/TestViewer.cxx +++ b/src/HYDRO_tests/TestViewer.cxx @@ -7,6 +7,7 @@ #include #include #include +#include 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; idumpView(); + + 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; } diff --git a/src/HYDRO_tests/TestViewer.h b/src/HYDRO_tests/TestViewer.h index 8b843ad1..e825208b 100644 --- a/src/HYDRO_tests/TestViewer.h +++ b/src/HYDRO_tests/TestViewer.h @@ -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 index 00000000..86bdba35 Binary files /dev/null and b/src/HYDRO_tests/reference_data/LandCoverMap_Add_2_Objects.png differ diff --git a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx index d2df73aa..aa9135f4 100644 --- a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx +++ b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx @@ -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(); } diff --git a/src/HYDRO_tests/test_HYDROData_Main.cxx b/src/HYDRO_tests/test_HYDROData_Main.cxx index 157fee69..5b1367cb 100644 --- a/src/HYDRO_tests/test_HYDROData_Main.cxx +++ b/src/HYDRO_tests/test_HYDROData_Main.cxx @@ -78,6 +78,6 @@ int main( int argc, char* argv[] ) return 0; } - anApp.exec(); + //anApp.exec(); return result.wasSuccessful() ? 0 : 1; }