TestViewer.h
TestLib_Listener.h
TestLib_Runner.h
+ random.h
)
set(PROJECT_SOURCES
TestViewer.cxx
TestLib_Listener.cxx
TestLib_Runner.cxx
+ random.cxx
)
add_definitions(
#include <TestViewer.h>
+#include <random.h>
#include <OCCViewer_ViewManager.h>
+#ifdef WIN32
+ #pragma warning ( disable: 4251 )
+#endif
#include <OCCViewer_ViewModel.h>
+#ifdef WIN32
+ #pragma warning ( disable: 4251 )
+#endif
#include <OCCViewer_ViewWindow.h>
+#ifdef WIN32
+ #pragma warning ( disable: 4251 )
+#endif
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
#include <TopoDS_Iterator.hxx>
+
#include <QDir>
#include <QPainter>
+#include <QHash>
+
+#ifdef WIN32
+ #pragma warning ( default: 4251 )
+#endif
+
#include <cppunit/TestAssert.h>
OCCViewer_ViewManager* TestViewer::myViewManager = 0;
OCCViewer_ViewWindow* TestViewer::myViewWindow = 0;
+QString TestViewer::myKey = "";
OCCViewer_ViewManager* TestViewer::viewManager()
{
return TestViewer::viewer()->getAISContext();
}
-void TestViewer::show( const TopoDS_Shape& theShape, const QColor& theColor, int theMode )
+QColor randomColor()
{
- QColor aColor = theColor;
- if( !aColor.isValid() )
- {
- // random color
- int aHue = rand()%255;
- aColor = QColor::fromHsl( aHue, 255, 128 );
- }
+ int aHue = rand()%255;
+ QColor aColor = QColor::fromHsl( aHue, 255, 128 );
+ return aColor;
+}
- double r = aColor.red() / 255.0;
- double g = aColor.green() / 255.0;
- double b = aColor.blue() / 255.0;
+void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const QColor& theColor )
+{
+ double r = theColor.red() / 255.0;
+ double g = theColor.green() / 255.0;
+ double b = theColor.blue() / 255.0;
Handle(AIS_Shape) aShape = new AIS_Shape( theShape );
aShape->SetMaterial( Graphic3d_NOM_PLASTIC );
aShape->SetColor( Quantity_Color( r, g, b, Quantity_TOC_RGB ) );
context()->Display( aShape, theMode, 0, Standard_False );
+
+ if( isFitAll )
+ {
+ viewWindow()->onTopView();
+ viewWindow()->onFitAll();
+ }
}
-void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll )
+void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, char* theKey )
{
context()->EraseAll();
+ myKey = theKey;
+ test_srand( qHash( theKey ) );
if( theShape.ShapeType()==TopAbs_COMPOUND )
{
TopoDS_Iterator anIt( theShape );
for( ; anIt.More(); anIt.Next() )
- show( anIt.Value(), QColor(), theMode );
+ show( anIt.Value(), theMode, false, randomColor() );
}
else
- show( theShape, QColor(), theMode );
+ show( theShape, theMode, false, randomColor() );
- viewWindow()->onTopView();
- viewWindow()->onFitAll();
+ if( isFitAll )
+ {
+ viewWindow()->onTopView();
+ viewWindow()->onFitAll();
+ }
}
bool AreImagesEqual( const QImage& theImage1, const QImage& theImage2, double theTolerance )
return true;
}
-bool TestViewer::AssertEqual( const QString& theUseCaseName )
+bool TestViewer::AssertImages( QString& theMessage )
{
QImage anActualImage = viewWindow()->dumpView();
QString anExpectedRefFilePath = qgetenv( "HYDRO_REFERENCE_DATA" );
- anExpectedRefFilePath += "/" + theUseCaseName + ".png";
+ anExpectedRefFilePath += "/" + myKey + ".png";
QImage anExpectedRefImage;
anExpectedRefImage.load( anExpectedRefFilePath );
- if( AreImagesEqual( anActualImage, anExpectedRefImage, 0.2 ) )
+ if( AreImagesEqual( anActualImage, anExpectedRefImage, 0.001 ) )
+ {
+ theMessage = "";
return true;
+ }
- QString aPath = QDir::tempPath() + "/" + theUseCaseName + ".png";
+ QString aPath = QDir::tempPath() + "/" + myKey + ".png";
anActualImage.save( aPath );
- std::string aMessage = "The viewer contents does not correspond to the reference image: " + theUseCaseName.toStdString();
+ theMessage = "The viewer contents does not correspond to the reference image: " + myKey;
QImage aDiff( anExpectedRefImage.width(), anExpectedRefImage.height(), QImage::Format_ARGB32 );
QPainter aPainter( &aDiff );
aPainter.setCompositionMode( QPainter::RasterOp_SourceXorDestination );
aPainter.drawImage( 0, 0, anActualImage );
- QString aDiffFilePath = QDir::tempPath() + "/" + theUseCaseName + "_diff.png";
+ QString aDiffFilePath = QDir::tempPath() + "/" + myKey + "_diff.png";
aDiff.save( aDiffFilePath );
- CPPUNIT_FAIL( aMessage.c_str() );
return false;
}
static OCCViewer_Viewer* viewer();
static OCCViewer_ViewWindow* viewWindow();
- 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 bool AssertEqual( const QString& theUseCaseName );
+ static void show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const QColor& theColor );
+ static void show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, char* theKey );
+ static bool AssertImages( QString& theMessage );
private:
static OCCViewer_ViewManager* myViewManager;
static OCCViewer_ViewWindow* myViewWindow;
+ static QString myKey;
};
+
+#define CPPUNIT_ASSERT_IMAGES \
+ { \
+ QString aMessage; \
+ if( !TestViewer::AssertImages( aMessage ) ) \
+ { \
+ std::string aMessageStl = aMessage.toStdString(); \
+ CPPUNIT_FAIL( aMessageStl.c_str() ); \
+ } \
+ } \
+
--- /dev/null
+
+#include <random.h>
+
+int m_w = 1;
+int m_z = 1;
+
+void test_srand( unsigned int theValue )
+{
+ m_w = theValue + 1;
+ m_z = theValue / 2;
+}
+
+unsigned int test_rand()
+{
+ m_z = 36969 * (m_z & 65535) + (m_z >> 16);
+ m_w = 18000 * (m_w & 65535) + (m_w >> 16);
+ return (m_z << 16) + m_w; /* 32-bit result */
+}
--- /dev/null
+
+#pragma once
+
+void test_srand( unsigned int theValue );
+unsigned int test_rand();
#include <gp_XY.hxx>
#include <gp_XYZ.hxx>
+#include <random.h>
#include <QDir>
#include <QFile>
{
QTextStream anOutStream( &aTmpFile );
- srand( 4587 );
+ test_srand( 4587 );
generateOne( anOutStream, 0, 5, 0, -5 );
generateOne( anOutStream, 10, 5, 10, -5 );
generateOne( anOutStream, 20, 5, 20, -5 );
generateOne( anOutStream, 1040.079834, -441.303467, 1017.623413, -459.9102175 );
generateOne( anOutStream, 1055.478516, -456.060547, 1034.946899, -475.9505 );
generateOne( anOutStream, 1074.085327, -474.025665, 1058.044922, -493.274017 );
- srand( 0 );
+ test_srand( 0 );
}
aTmpFile.close();
gp_XY aTestPoint( 1, 1 );
double anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
- CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.9755, anAltitude, EPS );
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.9186, anAltitude, EPS );
aTestPoint = gp_XY( 0.5, 0.5 );
anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
- CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0147, anAltitude, EPS );
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.3452, anAltitude, EPS );
aTestPoint = gp_XY( 1.5, 1 );
anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
- CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.9534, anAltitude, EPS );
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.9157, anAltitude, EPS );
aTestPoint = gp_XY( 1.5, 0.7 );
anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
- CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.5032, anAltitude, EPS );
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.8782, anAltitude, EPS );
aTestPoint = gp_XY( 1.5, -0.7 );
anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
- CPPUNIT_ASSERT_DOUBLES_EQUAL( 6.3088, anAltitude, EPS );
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.9678, anAltitude, EPS );
aTestPoint = gp_XY( 2, 3.5 );
anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
- CPPUNIT_ASSERT_DOUBLES_EQUAL( 11.090, anAltitude, EPS );
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 12.4364, anAltitude, EPS );
aDoc->Close();
}
TopoDS_Face aLC2 = LandCover( QList<double>() << 30 << 20 << 60 << 10 << 70 << 35 << 40 << 40 );
CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
- TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
- TestViewer::AssertEqual( "LandCoverMap_Add_2_Objects" );
+ TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Add_2_Objects" );
+ CPPUNIT_ASSERT_IMAGES
HYDROData_LandCoverMap::Iterator anIt( aMap );
CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
- TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
- TestViewer::show( aWire, QColor(), 0 );
- TestViewer::AssertEqual( "LandCoverMap_Split_1" );
+ TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Split_1" );
+ TestViewer::show( aWire, 0, true, Qt::blue );
+ CPPUNIT_ASSERT_IMAGES
HYDROData_LandCoverMap::Iterator anIt( aMap );
CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
- TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
- TestViewer::show( aWire, QColor(), 0 );
- TestViewer::AssertEqual( "LandCoverMap_Split_2" );
+ TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Split_2" );
+ TestViewer::show( aWire, 0, true, Qt::blue );
+ CPPUNIT_ASSERT_IMAGES
HYDROData_LandCoverMap::Iterator anIt( aMap );
CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
aList.Append( aMap->FindByPoint( aPnt2, aType2 ) );
CPPUNIT_ASSERT_EQUAL( true, aMap->Merge( aList, "new" ) );
- TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
+ TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Merge_1" );
//TestViewer::show( BRepBuilderAPI_MakeEdge( gp_Pnt(aPnt1.X(), aPnt1.Y(), 0), gp_Pnt(aPnt2.X(), aPnt2.Y(), 0) ).Edge(), QColor( Qt::blue ), AIS_Shaded );
- TestViewer::AssertEqual( "LandCoverMap_Merge_1" );
+ CPPUNIT_ASSERT_IMAGES
aDoc->Close();
}
aList.Append( aMap->FindByPoint( aPnt2, aType2 ) );
CPPUNIT_ASSERT_EQUAL( true, aMap->Remove( aList ) );
- TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
- TestViewer::AssertEqual( "LandCoverMap_Remove_1" );
+ TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Remove_1" );
+ CPPUNIT_ASSERT_IMAGES
aDoc->Close();
}
#include <SUIT_Session.h>
#include <QApplication>
#include <QColor>
-#include <time.h>
+#include <random.h>
int main( int argc, char* argv[] )
{
- srand( 0 );
+ test_srand( 0 );
QApplication anApp( argc, argv );
SUIT_Session aSession;