2 #include <test_HYDROData_Profile.h>
4 #include <HYDROData_Document.h>
5 #include <HYDROData_Tool.h>
6 #include <HYDROData_Profile.h>
7 #include <HYDROData_Iterator.h>
9 #include <TopoDS_Shape.hxx>
16 #include <QTextStream>
18 bool test_HYDROData_Profile::createTestFile( const QString& theFileName,
19 const bool theIsParametric )
21 QFile aTmpFile( theFileName );
22 if ( !aTmpFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
25 if ( theIsParametric )
27 QTextStream anOutStream( &aTmpFile );
29 anOutStream << "0 182.15 \n";
30 anOutStream << "4 181.95 \n";
31 anOutStream << "10.18 181.63 \n";
32 anOutStream << "14.75 179.27 \n";
33 anOutStream << "19.75 178.87 \n";
37 anOutStream << "-5 50 \n";
38 anOutStream << "0 15 \n";
39 anOutStream << "10.1 10 \n";
40 anOutStream << "20 20 \n";
41 anOutStream << "250 0.005 \n";
45 QTextStream anOutStream( &aTmpFile );
47 anOutStream << "1040499.17 6788618.13 182.15 \n";
48 anOutStream << "1040503.12 6788618.79 181.95 \n";
49 anOutStream << "1040509.21 6788619.81 181.63 \n";
50 anOutStream << "1040513.72 6788620.56 179.27 \n";
51 anOutStream << "1040518.65 6788621.38 178.87 \n";
59 void test_HYDROData_Profile::testFileImport()
61 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
63 QString aParamFileName = QDir::tempPath() + QDir::separator() + "parametric.pa";
64 QString aGeorefFileName = QDir::tempPath() + QDir::separator() + "georef.pa";
65 if ( !createTestFile( aParamFileName, true ) || !createTestFile( aGeorefFileName, false ) )
66 return; // No file has been created
68 TCollection_AsciiString aFileName( aParamFileName.toStdString().c_str() );
70 CPPUNIT_ASSERT( HYDROData_Profile::ImportFromFile( aDoc, aFileName ) );
72 int aProfileCount = 0;
73 HYDROData_Iterator aDocIter( aDoc, KIND_PROFILE );
74 for ( ; aDocIter.More(); aDocIter.Next() )
76 Handle(HYDROData_Profile) aProfile =
77 Handle(HYDROData_Profile)::DownCast( aDocIter.Current() );
78 if ( aProfile.IsNull() )
81 CPPUNIT_ASSERT( aProfile->IsValid() == false );
82 CPPUNIT_ASSERT( aProfile->NbPoints() == 5 );
87 CPPUNIT_ASSERT( aProfileCount == 2 );
89 Handle(HYDROData_Profile) aGeorefProfile =
90 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
92 aFileName = TCollection_AsciiString( aGeorefFileName.toStdString().c_str() );
93 CPPUNIT_ASSERT( aGeorefProfile->ImportFromFile( aFileName ) );
95 // Check validity of imported profile
96 CPPUNIT_ASSERT( aGeorefProfile->IsValid() );
98 CPPUNIT_ASSERT( aGeorefProfile->GetTopShape().IsNull() == false );
100 aGeorefProfile->UpdateShape3D();
101 CPPUNIT_ASSERT( aGeorefProfile->GetShape3D().IsNull() == false );
103 HYDROData_Profile::ProfilePoints aProfilePoints = aGeorefProfile->GetProfilePoints();
104 CPPUNIT_ASSERT( aProfilePoints.Length() == 5 );
106 HYDROData_Profile::ProfilePoint aProfilePoint = aProfilePoints.Value( 3 );
107 CPPUNIT_ASSERT( ValuesEquals( aProfilePoint.X(), 1040509.21 ) );
108 CPPUNIT_ASSERT( ValuesEquals( aProfilePoint.Y(), 6788619.81 ) );
109 CPPUNIT_ASSERT( ValuesEquals( aProfilePoint.Z(), 181.63 ) );
115 void test_HYDROData_Profile::testCopy()
117 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
119 Handle(HYDROData_Profile) aProfile1 =
120 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
122 QString aFileName = QDir::tempPath() + QDir::separator() + "georef.pa";
124 bool anIsFileCreated = createTestFile( aFileName, false );
126 if ( anIsFileCreated )
128 TCollection_AsciiString anAsciiFileName( aFileName.toStdString().c_str() );
129 CPPUNIT_ASSERT( aProfile1->ImportFromFile( anAsciiFileName ) );
131 CPPUNIT_ASSERT( aProfile1->IsValid() );
132 CPPUNIT_ASSERT( aProfile1->NbPoints() == 5 );
135 Handle(HYDROData_Profile) aProfile2 =
136 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
138 aProfile1->CopyTo( aProfile2 );
140 if ( anIsFileCreated )
142 CPPUNIT_ASSERT( aProfile2->IsValid() );
143 CPPUNIT_ASSERT( aProfile2->NbPoints() == 5 );