]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
automatic tests stabilization
authorasl <asl@opencascade.com>
Tue, 13 Oct 2015 08:22:29 +0000 (11:22 +0300)
committerasl <asl@opencascade.com>
Tue, 13 Oct 2015 08:22:29 +0000 (11:22 +0300)
src/HYDRO_tests/CMakeLists.txt
src/HYDRO_tests/test_HYDROData_Bathymetry.cxx
src/HYDRO_tests/test_HYDROData_Entity.cxx
src/HYDRO_tests/test_HYDROData_Main.cxx
src/HYDRO_tests/test_HYDROData_PolylineXY.cxx
src/HYDRO_tests/test_HYDROData_Profile.cxx

index 82c0156ee8c533863f0de0561ce13f7ecff9da6c..ebc2802ce76e1724430452d7e2f58c5e4141aca3 100644 (file)
@@ -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()
index e3b2509a4ec903299251ce162cf76151133e039e..45a8e2563fcec7fce8dd0f0101201ec2b181e01b 100644 (file)
 
 #include <gp_Pnt2d.hxx>
 
+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();
index e55530bbfb3525c98b23239c3a473111b7536767..9bdeb4c5380d230aaf0954d8021cddc5d53d97ed 100644 (file)
@@ -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());
index e3796b370a7ffdbeaed00e5449ed66abb1d4f225..1ffc9358766d418570fa85623de29d6c32716f96 100644 (file)
 #include <cppunit/TestRunner.h>
 #include <cppunit/TextTestProgressListener.h>
 #include <stdexcept>
+#include <QApplication>
 
-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
   {
index 99b61069f176803719f92e44a540f220e17fd2ff..95a89ee86bb8bc1074e2554fb872a164a8b19e2b 100644 (file)
@@ -42,13 +42,14 @@ void test_HYDROData_PolylineXY::testPolyline()
   NCollection_Sequence<bool>                              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();
 }
index 49872918376602d09366ab05fa63f86edf4c9681..cc3d3da00660a056f8124fbba4350e34903a937b 100644 (file)
@@ -32,6 +32,8 @@
 #include <QFile>
 #include <QTextStream>
 
+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();
 }