1 #include <test_HYDROData_Bathymetry.h>
3 #include <HYDROData_Document.h>
4 #include <HYDROData_Tool.h>
5 #include <HYDROData_Bathymetry.h>
12 #include <QTextStream>
14 bool test_HYDROData_Bathymetry::createTestFile( const QString& theFileName )
16 QFile aTmpFile( theFileName );
17 if ( !aTmpFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
21 QTextStream anOutStream( &aTmpFile );
23 anOutStream << "0 0 0 \n";
24 anOutStream << "0 1 10 \n";
25 anOutStream << "0 2 20 \n";
26 anOutStream << "0 3 30 \n";
28 anOutStream << "1 0 0 \n";
29 anOutStream << "1 1 10 \n";
30 anOutStream << "1 2 20 \n";
31 anOutStream << "1 3 30 \n";
33 anOutStream << "2 1 10 \n";
34 anOutStream << "2 2 20 \n";
35 anOutStream << "2 3 30 \n";
36 anOutStream << "2 4 40 \n";
38 anOutStream << "3 0 0 \n";
39 anOutStream << "3 1 10 \n";
40 anOutStream << "3 2 20 \n";
41 anOutStream << "3 3 30 \n";
43 anOutStream << "4 0 0 \n";
44 anOutStream << "4 1 10 \n";
45 anOutStream << "4 2 20 \n";
46 anOutStream << "4 3 30 \n";
54 void test_HYDROData_Bathymetry::testFileImport()
56 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
58 Handle(HYDROData_Bathymetry) aBathymetry =
59 Handle(HYDROData_Bathymetry)::DownCast( aDoc->CreateObject( KIND_BATHYMETRY ) );
61 QString aFileName = QDir::tempPath() + QDir::separator() + "test.xyz";
62 if ( !createTestFile( aFileName ) )
63 return; // No file has been created
65 CPPUNIT_ASSERT( aBathymetry->ImportFromFile( aFileName ) );
67 HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry->GetAltitudePoints();
68 CPPUNIT_ASSERT( anAltitudePoints.length() == 20 );
70 gp_XY aTestPoint( 1, 1 );
71 double anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
72 CPPUNIT_ASSERT( ValuesEquals( anAltitude, 10.0 ) );
74 aTestPoint = gp_XY( 0.5, 0.5 );
75 anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
76 CPPUNIT_ASSERT( ValuesEquals( anAltitude, 5.0 ) );
78 aTestPoint = gp_XY( 1.5, 1 );
79 anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
80 CPPUNIT_ASSERT( ValuesEquals( anAltitude, 10.0 ) );
82 aTestPoint = gp_XY( 1.5, 0.7 );
83 anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
84 CPPUNIT_ASSERT( ValuesEquals( anAltitude, 7.0 ) );
86 aTestPoint = gp_XY( 1.5, -0.7 );
87 anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
88 CPPUNIT_ASSERT( ValuesEquals( anAltitude, HYDROData_Bathymetry::GetInvalidAltitude() ) );
90 aTestPoint = gp_XY( 2, 3.5 );
91 anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
92 CPPUNIT_ASSERT( ValuesEquals( anAltitude, 35.0 ) );
98 void test_HYDROData_Bathymetry::testCopy()
100 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
102 Handle(HYDROData_Bathymetry) aBathymetry1 =
103 Handle(HYDROData_Bathymetry)::DownCast( aDoc->CreateObject( KIND_BATHYMETRY ) );
105 QString aFileName = QDir::tempPath() + QDir::separator() + "test.xyz";
107 bool anIsFileCreated = createTestFile( aFileName );
109 if ( anIsFileCreated )
111 CPPUNIT_ASSERT( aBathymetry1->ImportFromFile( aFileName ) );
113 HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry1->GetAltitudePoints();
114 CPPUNIT_ASSERT( anAltitudePoints.length() == 20 );
117 Handle(HYDROData_Bathymetry) aBathymetry2 =
118 Handle(HYDROData_Bathymetry)::DownCast( aDoc->CreateObject( KIND_BATHYMETRY ) );
120 aBathymetry1->CopyTo( aBathymetry2 );
122 if ( anIsFileCreated )
124 HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry2->GetAltitudePoints();
125 CPPUNIT_ASSERT( anAltitudePoints.length() == 20 );