Salome HOME
refs #1341: debug of automatic tests
[modules/hydro.git] / src / HYDRO_tests / test_HYDROData_Profile.cxx
index cc3d3da00660a056f8124fbba4350e34903a937b..ee40097ffef461b39c7e7436083941421065fce5 100644 (file)
 #include <QDir>
 #include <QFile>
 #include <QTextStream>
+#include <QString>
 
 const double EPS = 1E-2;
+extern QString REF_DATA_PATH;
 
 bool test_HYDROData_Profile::createTestFile( const QString& theFileName,
                                              const bool     theIsParametric )
@@ -87,7 +89,7 @@ void test_HYDROData_Profile::testFileImport()
   TCollection_AsciiString aFileName( aParamFileName.toStdString().c_str() );
 
   NCollection_Sequence<int> 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 );
@@ -110,7 +112,9 @@ void test_HYDROData_Profile::testFileImport()
     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, &notEmpty ) );
+  CPPUNIT_ASSERT( notEmpty );
 
   // Check validity of imported profile
   CPPUNIT_ASSERT( aGeorefProfile->IsValid() );
@@ -145,8 +149,10 @@ void test_HYDROData_Profile::testCopy()
   
   if ( anIsFileCreated )
   {
+    bool notEmpty = false;
     TCollection_AsciiString anAsciiFileName( aFileName.toStdString().c_str() );
-    CPPUNIT_ASSERT( aProfile1->ImportFromFile( anAsciiFileName ) );
+    CPPUNIT_ASSERT( aProfile1->ImportFromFile( anAsciiFileName, true, &notEmpty ) );
+    CPPUNIT_ASSERT( notEmpty );
 
     CPPUNIT_ASSERT( aProfile1->IsValid() );
     CPPUNIT_ASSERT( aProfile1->NbPoints() == 5 );
@@ -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())<EPS && fabs(p1.Y()-p2.Y())<EPS && fabs(p1.Z()-p2.Z())<EPS;
+}
+
+void test_HYDROData_Profile::testProjection()
+{
+  std::string aPath = ( REF_DATA_PATH+"/profiles1.xyz" ).toStdString();
+
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
+
+  TCollection_AsciiString aFileName( aPath.c_str() );
+  NCollection_Sequence<int> 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();
+}