#include <AIS_Shape.hxx>
#include <TopoDS_Iterator.hxx>
#include <QDir>
+#include <cppunit/TestAssert.h>
OCCViewer_ViewManager* TestViewer::myViewManager = 0;
OCCViewer_ViewWindow* TestViewer::myViewWindow = 0;
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;
}
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;