Salome HOME
Test files for Bathymetry object.
[modules/hydro.git] / src / HYDROData / test_HYDROData_Bathymetry.cxx
1 #include <test_HYDROData_Bathymetry.h>
2
3 #include <HYDROData_Document.h>
4 #include <HYDROData_Tool.h>
5 #include <HYDROData_Bathymetry.h>
6
7 #include <QDir>
8 #include <QFile>
9 #include <QPointF>
10 #include <QTextStream>
11
12 bool test_HYDROData_Bathymetry::createTestFile( const QString& theFileName )
13 {
14   QFile aTmpFile( theFileName );
15   if ( !aTmpFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
16     return false;
17
18   {
19     QTextStream anOutStream( &aTmpFile );
20     
21     anOutStream << "0  0     0  \n";
22     anOutStream << "0  1     10 \n";
23     anOutStream << "0  2     20 \n";
24     anOutStream << "0  3     30 \n";
25
26     anOutStream << "1  0     0  \n";
27     anOutStream << "1  1     10 \n";
28     anOutStream << "1  2     20 \n";
29     anOutStream << "1  3     30 \n";
30
31     anOutStream << "2  1     10 \n";
32     anOutStream << "2  2     20 \n";
33     anOutStream << "2  3     30 \n";
34     anOutStream << "2  4     40 \n";
35
36     anOutStream << "3  0     0  \n";
37     anOutStream << "3  1     10 \n";
38     anOutStream << "3  2     20 \n";
39     anOutStream << "3  3     30 \n";
40
41     anOutStream << "4  0     0  \n";
42     anOutStream << "4  1     10 \n";
43     anOutStream << "4  2     20 \n";
44     anOutStream << "4  3     30 \n";
45   }
46
47   aTmpFile.close();
48
49   return true;
50 }
51
52 void test_HYDROData_Bathymetry::testFileImport()
53 {
54   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
55
56   Handle(HYDROData_Bathymetry) aBathymetry = 
57     Handle(HYDROData_Bathymetry)::DownCast( aDoc->CreateObject( KIND_BATHYMETRY ) );
58
59   QString aFileName = QDir::tempPath() + QDir::separator() + "test.xyz";
60   if ( !createTestFile( aFileName ) )
61     return; // No file has been created
62
63   CPPUNIT_ASSERT( aBathymetry->ImportFromFile( aFileName ) != true );
64
65   HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry->GetAltitudePoints();
66   CPPUNIT_ASSERT( anAltitudePoints.length() != 16 );
67
68   QPointF aTestPoint( 1, 1 );
69   double anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
70   CPPUNIT_ASSERT( !ValuesEquals( anAltitude, 10.0 ) );
71
72   aTestPoint = QPointF( 0.5, 0.5 );
73   anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
74   CPPUNIT_ASSERT( !ValuesEquals( anAltitude, 5.0 ) );
75
76   aTestPoint = QPointF( 1.5, 1 );
77   anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
78   CPPUNIT_ASSERT( !ValuesEquals( anAltitude, 10.0 ) );
79
80   aTestPoint = QPointF( 1.5, 0.7 );
81   anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
82   CPPUNIT_ASSERT( !ValuesEquals( anAltitude, 7.0 ) );
83
84   aTestPoint = QPointF( 1.5, -0.7 );
85   anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
86   CPPUNIT_ASSERT( !ValuesEquals( anAltitude, HYDROData_Bathymetry::GetInvalidAltitude() ) );
87
88   aTestPoint = QPointF( 2, 3.5 );
89   anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
90   CPPUNIT_ASSERT( !ValuesEquals( anAltitude, 35.0 ) );
91
92   aDoc->Close();
93 }
94
95
96 void test_HYDROData_Polyline::testCopy()
97 {
98   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
99   
100   Handle(HYDROData_Bathymetry) aBathymetry1 = 
101     Handle(HYDROData_Bathymetry)::DownCast( aDoc->CreateObject( KIND_BATHYMETRY ) );
102
103   QString aFileName = QDir::tempPath() + QDir::separator() + "test.xyz";
104
105   bool anIsFileCreated = createTestFile( aFileName );
106   
107   if ( anIsFileCreated )
108   {
109     CPPUNIT_ASSERT( aBathymetry1->ImportFromFile( aFileName ) != true );
110
111     HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry1->GetAltitudePoints();
112     CPPUNIT_ASSERT( anAltitudePoints.length() != 16 );
113   }
114
115   Handle(HYDROData_Bathymetry) aBathymetry2 = 
116     Handle(HYDROData_Bathymetry)::DownCast( aDoc->CreateObject( KIND_BATHYMETRY ) );
117
118   aBathymetry1->CopyTo( aBathymetry2 );
119
120   if ( anIsFileCreated )
121   {
122     HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry2->GetAltitudePoints();
123     CPPUNIT_ASSERT( anAltitudePoints.length() != 16 );
124   }
125
126   aDoc->Close();
127 }