]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Test files for Bathymetry object.
authoradv <adv@opencascade.com>
Fri, 30 Aug 2013 11:09:33 +0000 (11:09 +0000)
committeradv <adv@opencascade.com>
Fri, 30 Aug 2013 11:09:33 +0000 (11:09 +0000)
src/HYDROData/test_HYDROData_Bathymetry.cxx [new file with mode: 0755]
src/HYDROData/test_HYDROData_Bathymetry.h [new file with mode: 0755]

diff --git a/src/HYDROData/test_HYDROData_Bathymetry.cxx b/src/HYDROData/test_HYDROData_Bathymetry.cxx
new file mode 100755 (executable)
index 0000000..c257bf8
--- /dev/null
@@ -0,0 +1,127 @@
+#include <test_HYDROData_Bathymetry.h>
+
+#include <HYDROData_Document.h>
+#include <HYDROData_Tool.h>
+#include <HYDROData_Bathymetry.h>
+
+#include <QDir>
+#include <QFile>
+#include <QPointF>
+#include <QTextStream>
+
+bool test_HYDROData_Bathymetry::createTestFile( const QString& theFileName )
+{
+  QFile aTmpFile( theFileName );
+  if ( !aTmpFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
+    return false;
+
+  {
+    QTextStream anOutStream( &aTmpFile );
+    
+    anOutStream << "0  0     0  \n";
+    anOutStream << "0  1     10 \n";
+    anOutStream << "0  2     20 \n";
+    anOutStream << "0  3     30 \n";
+
+    anOutStream << "1  0     0  \n";
+    anOutStream << "1  1     10 \n";
+    anOutStream << "1  2     20 \n";
+    anOutStream << "1  3     30 \n";
+
+    anOutStream << "2  1     10 \n";
+    anOutStream << "2  2     20 \n";
+    anOutStream << "2  3     30 \n";
+    anOutStream << "2  4     40 \n";
+
+    anOutStream << "3  0     0  \n";
+    anOutStream << "3  1     10 \n";
+    anOutStream << "3  2     20 \n";
+    anOutStream << "3  3     30 \n";
+
+    anOutStream << "4  0     0  \n";
+    anOutStream << "4  1     10 \n";
+    anOutStream << "4  2     20 \n";
+    anOutStream << "4  3     30 \n";
+  }
+
+  aTmpFile.close();
+
+  return true;
+}
+
+void test_HYDROData_Bathymetry::testFileImport()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
+
+  Handle(HYDROData_Bathymetry) aBathymetry = 
+    Handle(HYDROData_Bathymetry)::DownCast( aDoc->CreateObject( KIND_BATHYMETRY ) );
+
+  QString aFileName = QDir::tempPath() + QDir::separator() + "test.xyz";
+  if ( !createTestFile( aFileName ) )
+    return; // No file has been created
+
+  CPPUNIT_ASSERT( aBathymetry->ImportFromFile( aFileName ) != true );
+
+  HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry->GetAltitudePoints();
+  CPPUNIT_ASSERT( anAltitudePoints.length() != 16 );
+
+  QPointF aTestPoint( 1, 1 );
+  double anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
+  CPPUNIT_ASSERT( !ValuesEquals( anAltitude, 10.0 ) );
+
+  aTestPoint = QPointF( 0.5, 0.5 );
+  anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
+  CPPUNIT_ASSERT( !ValuesEquals( anAltitude, 5.0 ) );
+
+  aTestPoint = QPointF( 1.5, 1 );
+  anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
+  CPPUNIT_ASSERT( !ValuesEquals( anAltitude, 10.0 ) );
+
+  aTestPoint = QPointF( 1.5, 0.7 );
+  anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
+  CPPUNIT_ASSERT( !ValuesEquals( anAltitude, 7.0 ) );
+
+  aTestPoint = QPointF( 1.5, -0.7 );
+  anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
+  CPPUNIT_ASSERT( !ValuesEquals( anAltitude, HYDROData_Bathymetry::GetInvalidAltitude() ) );
+
+  aTestPoint = QPointF( 2, 3.5 );
+  anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
+  CPPUNIT_ASSERT( !ValuesEquals( anAltitude, 35.0 ) );
+
+  aDoc->Close();
+}
+
+
+void test_HYDROData_Polyline::testCopy()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+  
+  Handle(HYDROData_Bathymetry) aBathymetry1 = 
+    Handle(HYDROData_Bathymetry)::DownCast( aDoc->CreateObject( KIND_BATHYMETRY ) );
+
+  QString aFileName = QDir::tempPath() + QDir::separator() + "test.xyz";
+
+  bool anIsFileCreated = createTestFile( aFileName );
+  
+  if ( anIsFileCreated )
+  {
+    CPPUNIT_ASSERT( aBathymetry1->ImportFromFile( aFileName ) != true );
+
+    HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry1->GetAltitudePoints();
+    CPPUNIT_ASSERT( anAltitudePoints.length() != 16 );
+  }
+
+  Handle(HYDROData_Bathymetry) aBathymetry2 = 
+    Handle(HYDROData_Bathymetry)::DownCast( aDoc->CreateObject( KIND_BATHYMETRY ) );
+
+  aBathymetry1->CopyTo( aBathymetry2 );
+
+  if ( anIsFileCreated )
+  {
+    HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry2->GetAltitudePoints();
+    CPPUNIT_ASSERT( anAltitudePoints.length() != 16 );
+  }
+
+  aDoc->Close();
+}
diff --git a/src/HYDROData/test_HYDROData_Bathymetry.h b/src/HYDROData/test_HYDROData_Bathymetry.h
new file mode 100755 (executable)
index 0000000..b0056a4
--- /dev/null
@@ -0,0 +1,31 @@
+
+#include <cppunit/extensions/HelperMacros.h>
+
+class Handle_HYDROData_Bathymetry;
+
+class test_HYDROData_Bathymetry : public CppUnit::TestFixture {
+  CPPUNIT_TEST_SUITE(test_HYDROData_Bathymetry);
+  CPPUNIT_TEST(testFileImport);
+  CPPUNIT_TEST(testCopy);
+  CPPUNIT_TEST_SUITE_END();
+
+private:
+
+  static bool                             createTestFile( const QString& theFileName );
+
+public:
+
+  void                                    setUp() {}
+
+  void                                    tearDown() {}
+
+  // checks file importing information
+  void                                    testFileImport();
+
+  // checks the copy/paste mechanism
+  void                                    testCopy();
+
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_Bathymetry);
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROData_Bathymetry, "HYDROData_Bathymetry");