X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDRO_tests%2Ftest_HYDROData_Profile.cxx;h=a4c6824fa8c5edb6e917dfe9cb173f91ba4cd3ce;hb=3bece499e83cc9ca95536228c7f6740030e9d5d8;hp=cc3d3da00660a056f8124fbba4350e34903a937b;hpb=143e6a0c49d1e9eab9efb1cacba588a81fb07049;p=modules%2Fhydro.git diff --git a/src/HYDRO_tests/test_HYDROData_Profile.cxx b/src/HYDRO_tests/test_HYDROData_Profile.cxx index cc3d3da0..a4c6824f 100644 --- a/src/HYDRO_tests/test_HYDROData_Profile.cxx +++ b/src/HYDRO_tests/test_HYDROData_Profile.cxx @@ -31,8 +31,11 @@ #include #include #include +#include const double EPS = 1E-2; +extern QString REF_DATA_PATH; +extern QString TMP_DIR; bool test_HYDROData_Profile::createTestFile( const QString& theFileName, const bool theIsParametric ) @@ -44,7 +47,7 @@ bool test_HYDROData_Profile::createTestFile( const QString& theFileName, if ( theIsParametric ) { QTextStream anOutStream( &aTmpFile ); - + anOutStream << "0 182.15 \n"; anOutStream << "4 181.95 \n"; anOutStream << "10.18 181.63 \n"; @@ -77,40 +80,41 @@ bool test_HYDROData_Profile::createTestFile( const QString& theFileName, void test_HYDROData_Profile::testFileImport() { - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(); - QString aParamFileName = QDir::tempPath() + QDir::separator() + "parametric.pa"; - QString aGeorefFileName = QDir::tempPath() + QDir::separator() + "georef.pa"; + QString aParamFileName = TMP_DIR + QDir::separator() + "parametric.pa"; + QString aGeorefFileName = TMP_DIR + QDir::separator() + "georef.pa"; if ( !createTestFile( aParamFileName, true ) || !createTestFile( aGeorefFileName, false ) ) return; // No file has been created TCollection_AsciiString aFileName( aParamFileName.toStdString().c_str() ); NCollection_Sequence aBadProfilesList; - CPPUNIT_ASSERT( HYDROData_Profile::ImportFromFile( aDoc, aFileName, aBadProfilesList ) ); + CPPUNIT_ASSERT( HYDROData_Profile::ImportFromFile( aDoc, aFileName, aBadProfilesList, true ) ); int aProfileCount = 0; HYDROData_Iterator aDocIter( aDoc, KIND_PROFILE ); for ( ; aDocIter.More(); aDocIter.Next() ) { - Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( aDocIter.Current() ); if ( aProfile.IsNull() ) continue; - + CPPUNIT_ASSERT( aProfile->IsValid() == false ); CPPUNIT_ASSERT( aProfile->NbPoints() == 5 ); - + aProfileCount++; } - CPPUNIT_ASSERT( aProfileCount == 2 ); - Handle(HYDROData_Profile) aGeorefProfile = + Handle(HYDROData_Profile) aGeorefProfile = Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); aFileName = TCollection_AsciiString( aGeorefFileName.toStdString().c_str() ); - CPPUNIT_ASSERT( aGeorefProfile->ImportFromFile( aFileName ) ); + bool notEmpty = false; + CPPUNIT_ASSERT( aGeorefProfile->ImportFromFile( aFileName, true, ¬Empty ) ); + CPPUNIT_ASSERT( notEmpty ); // Check validity of imported profile CPPUNIT_ASSERT( aGeorefProfile->IsValid() ); @@ -134,25 +138,27 @@ void test_HYDROData_Profile::testFileImport() void test_HYDROData_Profile::testCopy() { - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); - - Handle(HYDROData_Profile) aProfile1 = + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(); + + Handle(HYDROData_Profile) aProfile1 = Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); - QString aFileName = QDir::tempPath() + QDir::separator() + "georef.pa"; + QString aFileName = TMP_DIR + QDir::separator() + "georef.pa"; bool anIsFileCreated = createTestFile( aFileName, false ); - + if ( anIsFileCreated ) { + bool notEmpty = false; TCollection_AsciiString anAsciiFileName( aFileName.toStdString().c_str() ); - CPPUNIT_ASSERT( aProfile1->ImportFromFile( anAsciiFileName ) ); + CPPUNIT_ASSERT( aProfile1->ImportFromFile( anAsciiFileName, true, ¬Empty ) ); + CPPUNIT_ASSERT( notEmpty ); CPPUNIT_ASSERT( aProfile1->IsValid() ); CPPUNIT_ASSERT( aProfile1->NbPoints() == 5 ); } - Handle(HYDROData_Profile) aProfile2 = + Handle(HYDROData_Profile) aProfile2 = Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); aProfile1->CopyTo( aProfile2, false ); @@ -165,3 +171,59 @@ void test_HYDROData_Profile::testCopy() aDoc->Close(); } + +void operator << ( std::ostream& s, const gp_XYZ& p ) +{ + s << "(" << p.X() << "; " << p.Y() << "; " << p.Z() << ") "; +} + +bool operator == ( const gp_XYZ& p1, const gp_XYZ& p2 ) +{ + return fabs(p1.X()-p2.X()) aBadProfilesList; + CPPUNIT_ASSERT( HYDROData_Profile::ImportFromFile( aDoc, aFileName, aBadProfilesList, false ) ); + CPPUNIT_ASSERT( HYDROData_Profile::ImportFromFile( aDoc, aFileName, aBadProfilesList, true ) ); + + HYDROData_Iterator it( aDoc, KIND_PROFILE ); + CPPUNIT_ASSERT( it.More() ); + Handle(HYDROData_Profile) p1 = Handle(HYDROData_Profile)::DownCast( it.Current() ); it.Next(); + CPPUNIT_ASSERT( it.More() ); + Handle(HYDROData_Profile) p2 = Handle(HYDROData_Profile)::DownCast( it.Current() ); it.Next(); + CPPUNIT_ASSERT( !it.More() ); + + CPPUNIT_ASSERT_EQUAL( QString( "Profile_1" ), p1->GetName() ); + CPPUNIT_ASSERT_EQUAL( QString( "Profile_2" ), p2->GetName() ); + + HYDROData_Profile::ProfilePoints pp1 = p1->GetProfilePoints(); + int low1 = pp1.Lower(), up1 = pp1.Upper(); + CPPUNIT_ASSERT_EQUAL( 1, low1 ); + CPPUNIT_ASSERT_EQUAL( 6, up1 ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 1.0, 2.0, 5.0 ), pp1.Value( 1 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 2.04019, 4.0838, 4.0 ), pp1.Value( 2 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 2.9601, 5.9202, 3.0 ), pp1.Value( 3 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 4.08026, 8.16052, 3.0 ), pp1.Value( 4 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 4.9202, 9.84041, 4.0 ), pp1.Value( 5 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 6.0, 12.0, 5.0 ), pp1.Value( 6 ) ); + + HYDROData_Profile::ProfilePoints pp2 = p2->GetProfilePoints(); + int low2 = pp2.Lower(), up2 = pp2.Upper(); + CPPUNIT_ASSERT_EQUAL( 1, low2 ); + CPPUNIT_ASSERT_EQUAL( 6, up2 ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 1.0, 2.0, 5.0 ), pp2.Value( 1 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 2.04019, 4.0838, 4.0 ), pp2.Value( 2 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 2.9601, 5.9202, 3.0 ), pp2.Value( 3 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 4.08, 8.16, 3.0 ), pp2.Value( 4 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 4.92, 9.84, 4.0 ), pp2.Value( 5 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 6.0, 12.0, 5.0 ), pp2.Value( 6 ) ); + + aDoc->Close(); +}