From 4b703f0d4b20bb8cb3ef5074db5973eddf1fe357 Mon Sep 17 00:00:00 2001 From: adv Date: Fri, 30 Aug 2013 11:09:33 +0000 Subject: [PATCH] Test files for Bathymetry object. --- src/HYDROData/test_HYDROData_Bathymetry.cxx | 127 ++++++++++++++++++++ src/HYDROData/test_HYDROData_Bathymetry.h | 31 +++++ 2 files changed, 158 insertions(+) create mode 100755 src/HYDROData/test_HYDROData_Bathymetry.cxx create mode 100755 src/HYDROData/test_HYDROData_Bathymetry.h diff --git a/src/HYDROData/test_HYDROData_Bathymetry.cxx b/src/HYDROData/test_HYDROData_Bathymetry.cxx new file mode 100755 index 00000000..c257bf8f --- /dev/null +++ b/src/HYDROData/test_HYDROData_Bathymetry.cxx @@ -0,0 +1,127 @@ +#include + +#include +#include +#include + +#include +#include +#include +#include + +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 index 00000000..b0056a4a --- /dev/null +++ b/src/HYDROData/test_HYDROData_Bathymetry.h @@ -0,0 +1,31 @@ + +#include + +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"); -- 2.39.2