From: asl Date: Tue, 13 Oct 2015 08:22:29 +0000 (+0300) Subject: automatic tests stabilization X-Git-Tag: v1.5~140 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=143e6a0c49d1e9eab9efb1cacba588a81fb07049;p=modules%2Fhydro.git automatic tests stabilization --- diff --git a/src/HYDRO_tests/CMakeLists.txt b/src/HYDRO_tests/CMakeLists.txt index 82c0156e..ebc2802c 100644 --- a/src/HYDRO_tests/CMakeLists.txt +++ b/src/HYDRO_tests/CMakeLists.txt @@ -124,3 +124,7 @@ include_directories( add_executable( HYDROData_tests ${PROJECT_SOURCES} ${PROJECT_HEADERS}) target_link_libraries( HYDROData_tests ${GUI_LIBRARIES} ${CAS_LIBRARIES} ${QT_LIBRARIES} ${CPPUNIT_LIBRARIES} shapelib ) + +IF( ${WIN32} ) + add_custom_command( TARGET HYDROData_tests POST_BUILD COMMAND $(TargetPath) COMMENT "Running tests" ) +ENDIF() diff --git a/src/HYDRO_tests/test_HYDROData_Bathymetry.cxx b/src/HYDRO_tests/test_HYDROData_Bathymetry.cxx index e3b2509a..45a8e256 100644 --- a/src/HYDRO_tests/test_HYDROData_Bathymetry.cxx +++ b/src/HYDRO_tests/test_HYDROData_Bathymetry.cxx @@ -31,27 +31,23 @@ #include +const double EPS = 1E-4; + void generateOne( QTextStream& theStream, double theFirstX, double theFirstY, double theLastX, double theLastY ) { const int aNbPoints = 50; - - double aComDist = gp_Pnt2d( theFirstX, theFirstY ).Distance( gp_Pnt2d( theLastX, theLastY ) ); - double aStep = aComDist / (double)aNbPoints; - double aStepZ = -5; - double aCurDist = 0.0; - for ( int i = 0; i <= aNbPoints; ++i ) + const double dt = 1.0 / aNbPoints; + + for( double t=0.0; t<=1.0; t += dt ) { - double aRatio = ( aCurDist / ( aComDist - aCurDist ) ); - - double anX = ( theFirstX + aRatio * theLastX ) / ( 1 + aRatio ); - double anY = ( theFirstY + aRatio * theLastY ) / ( 1 + aRatio ); + double anX = theFirstX * (1-t) + theLastX * t; + double anY = theFirstY * (1-t) + theLastY * t; double aZ = aStepZ * aStepZ + sin( (float)rand() ); theStream << anX << " " << anY << " " << aZ << " \n"; - aCurDist += aStep; aStepZ += 0.2; } } @@ -133,31 +129,31 @@ void test_HYDROData_Bathymetry::testFileImport() CPPUNIT_ASSERT( aBathymetry->ImportFromFile( aFileName.toStdString().c_str() ) ); HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry->GetAltitudePoints(); - CPPUNIT_ASSERT( anAltitudePoints.Length() == 20 ); + CPPUNIT_ASSERT_EQUAL( 2300, anAltitudePoints.Length() ); gp_XY aTestPoint( 1, 1 ); double anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint ); - CPPUNIT_ASSERT( ValuesEquals( anAltitude, 10.0 ) ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.9755, anAltitude, EPS ); aTestPoint = gp_XY( 0.5, 0.5 ); anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint ); - CPPUNIT_ASSERT( ValuesEquals( anAltitude, 5.0 ) ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0147, anAltitude, EPS ); aTestPoint = gp_XY( 1.5, 1 ); anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint ); - CPPUNIT_ASSERT( ValuesEquals( anAltitude, 10.0 ) ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.9534, anAltitude, EPS ); aTestPoint = gp_XY( 1.5, 0.7 ); anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint ); - CPPUNIT_ASSERT( ValuesEquals( anAltitude, 7.0 ) ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.5032, anAltitude, EPS ); aTestPoint = gp_XY( 1.5, -0.7 ); anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint ); - CPPUNIT_ASSERT( ValuesEquals( anAltitude, HYDROData_Bathymetry::GetInvalidAltitude() ) ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 6.3088, anAltitude, EPS ); aTestPoint = gp_XY( 2, 3.5 ); anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint ); - CPPUNIT_ASSERT( ValuesEquals( anAltitude, 35.0 ) ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 11.090, anAltitude, EPS ); aDoc->Close(); } @@ -179,7 +175,7 @@ void test_HYDROData_Bathymetry::testCopy() CPPUNIT_ASSERT( aBathymetry1->ImportFromFile( aFileName.toStdString().c_str() ) ); HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry1->GetAltitudePoints(); - CPPUNIT_ASSERT( anAltitudePoints.Length() == 20 ); + CPPUNIT_ASSERT_EQUAL( 2300, anAltitudePoints.Length() ); } Handle(HYDROData_Bathymetry) aBathymetry2 = @@ -190,7 +186,7 @@ void test_HYDROData_Bathymetry::testCopy() if ( anIsFileCreated ) { HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry2->GetAltitudePoints(); - CPPUNIT_ASSERT( anAltitudePoints.Length() == 20 ); + CPPUNIT_ASSERT_EQUAL( 2300, anAltitudePoints.Length() ); } aDoc->Close(); diff --git a/src/HYDRO_tests/test_HYDROData_Entity.cxx b/src/HYDRO_tests/test_HYDROData_Entity.cxx index e55530bb..9bdeb4c5 100644 --- a/src/HYDRO_tests/test_HYDROData_Entity.cxx +++ b/src/HYDRO_tests/test_HYDROData_Entity.cxx @@ -57,7 +57,7 @@ void test_HYDROData_Entity::testCopy() Handle(HYDROData_Entity) aCopy = aDoc->CreateObject(KIND_IMAGE); // object for copy CPPUNIT_ASSERT(aCopy->GetName().isEmpty()); - anObj->CopyTo(aCopy, true); + anObj->CopyTo(aCopy, false); // check the copied object has same name as original CPPUNIT_ASSERT_EQUAL(aName.toStdString(), aCopy->GetName().toStdString()); diff --git a/src/HYDRO_tests/test_HYDROData_Main.cxx b/src/HYDRO_tests/test_HYDROData_Main.cxx index e3796b37..1ffc9358 100644 --- a/src/HYDRO_tests/test_HYDROData_Main.cxx +++ b/src/HYDRO_tests/test_HYDROData_Main.cxx @@ -23,10 +23,12 @@ #include #include #include +#include -int - main( int argc, char* argv[] ) +int main( int argc, char* argv[] ) { + QApplication anApp( argc, argv ); + std::string testPath = (argc > 1) ? std::string(argv[1]) : ""; // Create the event manager and test controller @@ -53,8 +55,8 @@ int std::cerr << std::endl; // Print test in a compiler compatible format. - CppUnit::CompilerOutputter outputter( &result, std::cerr ); - outputter.write(); + CPPUNIT_NS::CompilerOutputter outputter( &result, CPPUNIT_NS::stdCOut() ); + outputter.write(); } catch ( std::invalid_argument &e ) // Test path not resolved { diff --git a/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx b/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx index 99b61069..95a89ee8 100644 --- a/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx +++ b/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx @@ -42,13 +42,14 @@ void test_HYDROData_PolylineXY::testPolyline() NCollection_Sequence aSectClosures; aPolyline->GetSections( aSectNames, aSectTypes, aSectClosures ); - CPPUNIT_ASSERT( aSectNames.Value( 0 ) == "Section_1" ); - CPPUNIT_ASSERT( aSectTypes.Value( 0 ) == HYDROData_PolylineXY::SECTION_POLYLINE ); - CPPUNIT_ASSERT( aSectClosures.Value( 0 ) == false ); - - CPPUNIT_ASSERT( aSectNames.Value( 1 ) == "Section_2" ); - CPPUNIT_ASSERT( aSectTypes.Value( 1 ) == HYDROData_PolylineXY::SECTION_SPLINE ); - CPPUNIT_ASSERT( aSectClosures.Value( 1 ) == true ); + CPPUNIT_ASSERT_EQUAL( 2, aSectNames.Size() ); + CPPUNIT_ASSERT( aSectNames.Value( 1 ) == "Section_1" ); + CPPUNIT_ASSERT( aSectTypes.Value( 1 ) == HYDROData_PolylineXY::SECTION_POLYLINE ); + CPPUNIT_ASSERT( aSectClosures.Value( 1 ) == false ); + + CPPUNIT_ASSERT( aSectNames.Value( 2 ) == "Section_2" ); + CPPUNIT_ASSERT( aSectTypes.Value( 2 ) == HYDROData_PolylineXY::SECTION_SPLINE ); + CPPUNIT_ASSERT( aSectClosures.Value( 2 ) == true ); aDoc->Close(); } diff --git a/src/HYDRO_tests/test_HYDROData_Profile.cxx b/src/HYDRO_tests/test_HYDROData_Profile.cxx index 49872918..cc3d3da0 100644 --- a/src/HYDRO_tests/test_HYDROData_Profile.cxx +++ b/src/HYDRO_tests/test_HYDROData_Profile.cxx @@ -32,6 +32,8 @@ #include #include +const double EPS = 1E-2; + bool test_HYDROData_Profile::createTestFile( const QString& theFileName, const bool theIsParametric ) { @@ -122,9 +124,9 @@ void test_HYDROData_Profile::testFileImport() CPPUNIT_ASSERT( aProfilePoints.Length() == 5 ); HYDROData_Profile::ProfilePoint aProfilePoint = aProfilePoints.Value( 3 ); - CPPUNIT_ASSERT( ValuesEquals( aProfilePoint.X(), 1040509.21 ) ); - CPPUNIT_ASSERT( ValuesEquals( aProfilePoint.Y(), 6788619.81 ) ); - CPPUNIT_ASSERT( ValuesEquals( aProfilePoint.Z(), 181.63 ) ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( aProfilePoint.X(), 1040509.21, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( aProfilePoint.Y(), 6788619.81, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( aProfilePoint.Z(), 181.63, EPS ); aDoc->Close(); }