From: asl Date: Tue, 13 Oct 2015 06:26:32 +0000 (+0300) Subject: redesigned test system X-Git-Tag: v1.5~141 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=557f5f91d30a5fae83a018a79eeb445c8c51ec3d;p=modules%2Fhydro.git redesigned test system --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 601d0ab6..3c46f782 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,8 @@ INCLUDE(CMakeDependentOption) PROJECT(SalomeHYDRO C CXX) +ADD_SUBDIRECTORY (src/HYDRO_tests) + # Ensure a proper linker behavior: CMAKE_POLICY(SET CMP0003 NEW) diff --git a/src/HYDROData/CMakeLists.txt b/src/HYDROData/CMakeLists.txt index 0a7bfff5..9addb41b 100644 --- a/src/HYDROData/CMakeLists.txt +++ b/src/HYDROData/CMakeLists.txt @@ -143,40 +143,4 @@ INSTALL(TARGETS HYDROData EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME set(PROJECT_LIBRARIES shapelib HYDROData) -# tests -if(SALOME_BUILD_TESTS) - - set(TEST_HEADERS - test_HYDROData_Bathymetry.h - test_HYDROData_BSplineOperation.h - test_HYDROData_CalculationCase.h - test_HYDROData_Document.h - test_HYDROData_Entity.h - test_HYDROData_Image.h - test_HYDROData_Iterator.h - test_HYDROData_OperationsFactory.h - test_HYDROData_PolylineXY.h - test_HYDROData_StricklerTable.h - ) - - set(TEST_SOURCES - test_HYDROData_Main.cxx - test_HYDROData_Bathymetry.cxx - test_HYDROData_BSplineOperation.cxx - test_HYDROData_CalculationCase.cxx - test_HYDROData_Document.cxx - test_HYDROData_Entity.cxx - test_HYDROData_Image.cxx - test_HYDROData_Iterator.cxx - test_HYDROData_OperationsFactory.cxx - test_HYDROData_PolylineXY.cxx - test_HYDROData_StricklerTable.cxx - ) - - set(TEST_EXE test_HYDROData) - include(../../CMake/CPPUnitTests.cmake) - target_link_libraries(test_HYDROData ${CAS_OCAF} ${CAS_MODELER} ${QT_LIBRARIES} ${CPPUNIT_LIBRARIES} HYDROData) - -endif(SALOME_BUILD_TESTS) - #include(../../CMake/CommonInstall.cmake) diff --git a/src/HYDROData/HYDROData.h b/src/HYDROData/HYDROData.h index c6e59e81..2616c84e 100644 --- a/src/HYDROData/HYDROData.h +++ b/src/HYDROData/HYDROData.h @@ -19,18 +19,22 @@ #ifndef HYDRODATA_H #define HYDRODATA_H -#if defined HYDRODATA_EXPORTS -#if defined WIN32 -#define HYDRODATA_EXPORT __declspec( dllexport ) +#ifdef HYDRODATA_STATIC + #define HYDRODATA_EXPORT #else -#define HYDRODATA_EXPORT -#endif -#else -#if defined WIN32 -#define HYDRODATA_EXPORT __declspec( dllimport ) -#else -#define HYDRODATA_EXPORT -#endif + #ifdef HYDRODATA_EXPORTS + #ifdef WIN32 + #define HYDRODATA_EXPORT __declspec( dllexport ) + #else + #define HYDRODATA_EXPORT + #endif + #else + #ifdef WIN32 + #define HYDRODATA_EXPORT __declspec( dllimport ) + #else + #define HYDRODATA_EXPORT + #endif + #endif #endif #endif diff --git a/src/HYDROData/HYDROData_BSplineOperation.cxx b/src/HYDROData/HYDROData_BSplineOperation.cxx index 5b0d4b70..058005d9 100644 --- a/src/HYDROData/HYDROData_BSplineOperation.cxx +++ b/src/HYDROData/HYDROData_BSplineOperation.cxx @@ -22,7 +22,10 @@ #include #include #include + +#ifndef LIGHT_MODE #include +#endif Handle(Geom_BSplineCurve) HYDROData_BSplineOperation::ComputeCurve( const NCollection_Sequence& thePoints, @@ -55,9 +58,11 @@ Handle(Geom_BSplineCurve) HYDROData_BSplineOperation::ComputeCurve( // compute BSpline Handle(Geom_BSplineCurve) aBSpline; +#ifndef LIGHT_MODE if( CurveCreator_Utils::constructBSpline( aHCurvePoints, theIsClosed, aBSpline ) ) return aBSpline; else +#endif return Handle(Geom_BSplineCurve)(); } diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index 55bb858b..2cf4fc27 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -35,7 +35,9 @@ #include "HYDROData_Tool.h" #include "HYDROData_GeomTool.h" +#ifndef LIGHT_MODE #include +#endif #include @@ -1063,14 +1065,19 @@ Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedG QString HYDROData_CalculationCase::Export( int theStudyId ) const { +#ifdef LIGHT_MODE + return ""; +#else GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen(); SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId ); QString aGeomObjEntry, anErrorMsg; bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry, anErrorMsg ); return isOK ? aGeomObjEntry : QString(); +#endif } +#ifndef LIGHT_MODE bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy, QString& theGeomObjEntry, @@ -1284,6 +1291,7 @@ bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var return true; } +#endif void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag, const bool theIsSetToUpdate ) diff --git a/src/HYDROData/HYDROData_CalculationCase.h b/src/HYDROData/HYDROData_CalculationCase.h index 77c1481d..4320e4fc 100644 --- a/src/HYDROData/HYDROData_CalculationCase.h +++ b/src/HYDROData/HYDROData_CalculationCase.h @@ -25,9 +25,11 @@ #include #include +#ifndef LIGHT_MODE // IDL includes #include #include CORBA_SERVER_HEADER(GEOM_Gen) +#endif class gp_XY; @@ -301,10 +303,12 @@ public: * \param theErrorMsg the error message * \return true in case of success */ +#ifndef LIGHT_MODE HYDRODATA_EXPORT virtual bool Export( GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy, QString& theGeomObjEntry, QString& theErrorMsg ) const; +#endif public: // Public methods to work with Calculation services @@ -440,11 +444,13 @@ private: * \param theSplittedGroups the list of groups * \return true in case of success */ +#ifndef LIGHT_MODE bool Export( GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy, const TopTools_ListOfShape& theFaces, const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs, QString& theGeomObjEntry ) const; +#endif void CreateRegionsDef( const Handle(HYDROData_Document)& theDoc, const HYDROData_SplitToZonesTool::SplitDataList& theZones, diff --git a/src/HYDROData/HYDROData_GeomTool.cxx b/src/HYDROData/HYDROData_GeomTool.cxx index a83258e6..037306f3 100644 --- a/src/HYDROData/HYDROData_GeomTool.cxx +++ b/src/HYDROData/HYDROData_GeomTool.cxx @@ -18,6 +18,8 @@ #include "HYDROData_GeomTool.h" +#ifndef LIGHT_MODE + #include #include @@ -195,3 +197,5 @@ QString HYDROData_GeomTool::publishGEOMObject( GEOM::GEOM_Gen_var theGeomEngine, return anEntry; } + +#endif diff --git a/src/HYDROData/HYDROData_GeomTool.h b/src/HYDROData/HYDROData_GeomTool.h index 554aede3..8f87204f 100644 --- a/src/HYDROData/HYDROData_GeomTool.h +++ b/src/HYDROData/HYDROData_GeomTool.h @@ -21,6 +21,7 @@ #include "HYDROData.h" +#ifndef LIGHT_MODE #include class TopoDS_Shape; @@ -108,4 +109,6 @@ public: #endif +#endif + diff --git a/src/HYDROData/HYDROData_Obstacle.cxx b/src/HYDROData/HYDROData_Obstacle.cxx index 1218bbc4..1eeb8a83 100644 --- a/src/HYDROData/HYDROData_Obstacle.cxx +++ b/src/HYDROData/HYDROData_Obstacle.cxx @@ -24,7 +24,9 @@ #include "HYDROData_Tool.h" #include "HYDROData_GeomTool.h" +#ifndef LIGHT_MODE #include +#endif #include #include @@ -218,6 +220,7 @@ bool HYDROData_Obstacle::ImportFromGeomIOR( const TCollection_AsciiString& theIO { bool aRes = false; +#ifndef LIGHT_MODE if ( theIOR.IsEmpty() ) { return aRes; } @@ -234,7 +237,8 @@ bool HYDROData_Obstacle::ImportFromGeomIOR( const TCollection_AsciiString& theIO SetShape3D( aShape ); aRes = true; } - +#endif + return aRes; } @@ -267,6 +271,7 @@ TCollection_AsciiString HYDROData_Obstacle::GetGeomObjectName() const return aRes; } +#ifndef LIGHT_MODE SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( aDocId ); if ( !aDSStudy->_is_nil() ) { @@ -276,7 +281,7 @@ TCollection_AsciiString HYDROData_Obstacle::GetGeomObjectName() const aRes = TCollection_AsciiString( aSObject->GetName() ); } } - +#endif return aRes; } @@ -309,6 +314,7 @@ TopoDS_Shape HYDROData_Obstacle::ImportIGES( const QString& theFilePath ) const { TopoDS_Shape aResShape; +#ifndef LIGHT_MODE // Set "C" numeric locale to save numbers correctly Kernel_Utils::Localizer loc; @@ -343,6 +349,7 @@ TopoDS_Shape HYDROData_Obstacle::ImportIGES( const QString& theFilePath ) const catch(Standard_Failure) { aResShape.Nullify(); } +#endif return aResShape; } @@ -351,6 +358,7 @@ TopoDS_Shape HYDROData_Obstacle::ImportSTEP( const QString& theFilePath ) const { TopoDS_Shape aResShape; +#ifndef LIGHT_MODE // Set "C" numeric locale to save numbers correctly Kernel_Utils::Localizer loc; @@ -454,6 +462,7 @@ TopoDS_Shape HYDROData_Obstacle::ImportSTEP( const QString& theFilePath ) const catch (Standard_Failure) { aResShape.Nullify(); } +#endif return aResShape; } diff --git a/src/HYDROData/HYDROData_PolylineOperator.cxx b/src/HYDROData/HYDROData_PolylineOperator.cxx index 3a4183e8..7e44abef 100644 --- a/src/HYDROData/HYDROData_PolylineOperator.cxx +++ b/src/HYDROData/HYDROData_PolylineOperator.cxx @@ -20,7 +20,9 @@ #include #include +#ifndef LIGHT_MODE #include +#endif #include #include @@ -45,6 +47,7 @@ #include #include #include +#include template void append( std::vector& theList, const std::vector& theList2 ) { @@ -331,7 +334,9 @@ double HYDROData_PolylineOperator::ReduceDeflection( } Handle(Geom_BSplineCurve) aBSpline2; const bool isClosed = theCurve.IsClosed(); +#ifndef LIGHT_MODE if (!CurveCreator_Utils::constructBSpline(aPs2, isClosed, aBSpline2)) +#endif { return -1; } diff --git a/src/HYDROData/HYDROData_PolylineXY.cxx b/src/HYDROData/HYDROData_PolylineXY.cxx index 839e949a..a3942aff 100755 --- a/src/HYDROData/HYDROData_PolylineXY.cxx +++ b/src/HYDROData/HYDROData_PolylineXY.cxx @@ -30,7 +30,9 @@ #include #include +#ifndef LIGHT_MODE #include +#endif #include #include @@ -212,6 +214,9 @@ QColor HYDROData_PolylineXY::DefaultWireColor() bool HYDROData_PolylineXY::ImportFromGeomIOR( const TCollection_AsciiString& theIOR ) { +#ifdef LIGHT_MODE + return false; +#else if ( theIOR.IsEmpty() ) return false; @@ -220,6 +225,7 @@ bool HYDROData_PolylineXY::ImportFromGeomIOR( const TCollection_AsciiString& the return false; return ImportShape( aShape ); +#endif } void HYDROData_PolylineXY::SetGeomObjectEntry( const TCollection_AsciiString& theEntry ) diff --git a/src/HYDROData/HYDROData_StricklerTable.cxx b/src/HYDROData/HYDROData_StricklerTable.cxx index 7a165907..1cd27704 100644 --- a/src/HYDROData/HYDROData_StricklerTable.cxx +++ b/src/HYDROData/HYDROData_StricklerTable.cxx @@ -105,30 +105,28 @@ bool HYDROData_StricklerTable::Export( const TCollection_AsciiString& theFileNam if( aMap.IsNull() ) return false; - std::ofstream aStream( theFileName.ToCString(), std::ios::out | std::ios::binary ); - if( !aStream ) + QFile aFile( theFileName.ToCString() ); + if( !aFile.open( QFile::WriteOnly | QFile::Text ) ) return false; - aStream << GetAttrName().toStdString() << "\r\n"; + QTextStream aStream( &aFile ); + aStream.setCodec( "UTF-8" ); + + aStream << GetAttrName() << "\n"; bool aRes = true; for ( TDataStd_DataMapIteratorOfDataMapOfStringReal it( aMap->GetRealsContainer() ); it.More() && aRes; it.Next() ) { - TCollection_ExtendedString aType = it.Key(); - TCollection_ExtendedString aLine = TCollection_ExtendedString( '\"' ) + aType + TCollection_ExtendedString( '\"' ) + - TCollection_ExtendedString( ' ' ) + TCollection_ExtendedString( it.Value() ); - Standard_PCharacter aBuf = (Standard_PCharacter)malloc( aLine.LengthOfCString() + 1 ); - aStream.write( aBuf, aLine.ToUTF8CString( aBuf ) ); - - QString aColor = QString::number( aMap->GetInteger( aType ), 16 ); - QString anAttrValue = toQString( aMap->GetString( aType ) ); - - aStream << " " << aColor.toStdString() << " " << anAttrValue.toStdString(); - aStream.write( "\r\n", 2 ); - free( aBuf ); + QString aType = toQString( it.Key() ); + aStream << "\"" << aType << "\" " << it.Value(); + + QString aColor = QString::number( aMap->GetInteger( it.Key() ), 16 ).toUpper(); + QString anAttrValue = toQString( aMap->GetString( it.Key() ) ); + + aStream << " " << aColor << " " << anAttrValue << "\n"; } - aStream.close(); + aFile.close(); return aRes; } diff --git a/src/HYDROData/test_HYDROData_BSplineOperation.cxx b/src/HYDROData/test_HYDROData_BSplineOperation.cxx deleted file mode 100644 index 66d27970..00000000 --- a/src/HYDROData/test_HYDROData_BSplineOperation.cxx +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -#include -#include -#include - -const double LOCAL_SELECTION_TOLERANCE = 0.0001; - -void test_HYDROData_BSplineOperation::testCurve() -{ - /*// prepare points: function of sin(x) - NCollection_Sequence aPoints; - for ( double x = 0; x < 6.28; x += 0.1 ) - { - gp_XYZ aPoint( x, sin( x ), 0.0 ); - aPoints.Append( aPoint ); - } - // compute BSpline - HYDROData_BSplineOperation aBSpline( aPoints, false, LOCAL_SELECTION_TOLERANCE ); - - Handle(Geom_BSplineCurve) aBS = aBSpline.Curve(); - CPPUNIT_ASSERT( !aBS.IsNull() ); - CPPUNIT_ASSERT( !aBS->IsClosed() ); - CPPUNIT_ASSERT_EQUAL( aBS->Continuity(), GeomAbs_C2 ); - - // check that values of BSpline are not far from original "sin" function - // in all points of the curve - for ( double x = 0; x < 6.29; x += 0.001 ) - { - double aDiff = aBS->Value( x ).Y() - sin( aBS->Value( x ).X() ); - if ( aDiff < 0 ) aDiff = -aDiff; - CPPUNIT_ASSERT( aDiff < 3.e-6 ); // this number is found manually - }*/ -} - -void test_HYDROData_BSplineOperation::testPath() -{ - /*// prepare points: function of sin(x) - static const double aScale = 10000000.; - - NCollection_Sequence aPoints; - for ( double x = 0; x < 6.28; x += 0.1 ) - { - gp_XYZ aPoint( x * aScale, sin( x ) * aScale, 0.0 ); - aPoints.Append( aPoint ); - } - - // convert to QPainterPath - HYDROData_BSplineOperation aBSpline( aPoints, false, LOCAL_SELECTION_TOLERANCE ); - - CPPUNIT_ASSERT( !aBSpline.Curve().IsNull() ); - - QPainterPath aPath; - aBSpline.ComputePath( aPath ); - CPPUNIT_ASSERT( !aPath.isEmpty() );*/ - - /* - QImage aPic(1300, 600, QImage::Format_RGB32); - QPainter aPainter(&aPic); - aPainter.setBrush(QBrush(Qt::white)); - aPainter.drawPath(aPath); - aPic.save("pic.bmp"); - */ - - /*// check that values of Path are not far from original "sin" function - // in all points of the curve - QList aPolyF = aPath.toSubpathPolygons( QTransform() ); - QList::iterator aFIter = aPolyF.begin(); - for(; aFIter != aPolyF.end();aFIter++) { - QPolygon aPoly = aFIter->toPolygon(); - QPolygon::iterator aPoints = aPoly.begin(); - for(; aPoints != aPoly.end(); aPoints++) { - double aDiff = aPoints->y() / aScale - sin(aPoints->x() / aScale); - if (aDiff < 0) aDiff = -aDiff; - CPPUNIT_ASSERT(aDiff < 4.e-6); // this number is found manually - } - }*/ -} diff --git a/src/HYDROData/test_HYDROData_BSplineOperation.h b/src/HYDROData/test_HYDROData_BSplineOperation.h deleted file mode 100644 index 3d615257..00000000 --- a/src/HYDROData/test_HYDROData_BSplineOperation.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -class test_HYDROData_BSplineOperation : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(test_HYDROData_BSplineOperation); - CPPUNIT_TEST(testCurve); - CPPUNIT_TEST(testPath); - CPPUNIT_TEST_SUITE_END(); - -private: - -public: - - void setUp() {} - - void tearDown() {} - - // checks generation of BSpline curve by points - void testCurve(); - - // checks generation of QPainterPath - void testPath(); - -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_BSplineOperation); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROData_BSplineOperation, "HYDROData_BSplineOperation"); diff --git a/src/HYDROData/test_HYDROData_Bathymetry.cxx b/src/HYDROData/test_HYDROData_Bathymetry.cxx deleted file mode 100755 index e3b2509a..00000000 --- a/src/HYDROData/test_HYDROData_Bathymetry.cxx +++ /dev/null @@ -1,197 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -#include -#include -#include - -#include -#include - -#include -#include -#include - -#include - -void generateOne( QTextStream& theStream, - double theFirstX, double theFirstY, - double theLastX, double theLastY ) -{ - const int aNbPoints = 50; - - double aComDist = gp_Pnt2d( theFirstX, theFirstY ).Distance( gp_Pnt2d( theLastX, theLastY ) ); - double aStep = aComDist / (double)aNbPoints; - - double aStepZ = -5; - double aCurDist = 0.0; - for ( int i = 0; i <= aNbPoints; ++i ) - { - double aRatio = ( aCurDist / ( aComDist - aCurDist ) ); - - double anX = ( theFirstX + aRatio * theLastX ) / ( 1 + aRatio ); - double anY = ( theFirstY + aRatio * theLastY ) / ( 1 + aRatio ); - double aZ = aStepZ * aStepZ + sin( (float)rand() ); - theStream << anX << " " << anY << " " << aZ << " \n"; - - aCurDist += aStep; - aStepZ += 0.2; - } -} - -bool test_HYDROData_Bathymetry::createTestFile( const QString& theFileName ) -{ - QFile aTmpFile( theFileName ); - if ( !aTmpFile.open( QIODevice::WriteOnly | QIODevice::Text ) ) - return false; - - { - QTextStream anOutStream( &aTmpFile ); - - srand( 4587 ); - generateOne( anOutStream, 0, 5, 0, -5 ); - generateOne( anOutStream, 10, 5, 10, -5 ); - generateOne( anOutStream, 20, 5, 20, -5 ); - generateOne( anOutStream, 30, 5, 30, -5 ); - generateOne( anOutStream, 40, 5, 40, -5 ); - generateOne( anOutStream, 45.833271, 6.703101, 50.85397, -3.794724 ); - generateOne( anOutStream, 50.85397, 11.267372, 56.787525, 2.367043 ); - generateOne( anOutStream, 52.67968, 16.516285, 62.721077, 10.354518 ); - generateOne( anOutStream, 55.190029, 23.819118, 65.23143, 17.657352 ); - generateOne( anOutStream, 58.385021, 31.806595, 68.198204, 23.819118 ); - generateOne( anOutStream, 65.916069, 38.653004, 75.044609, 27.470537 ); - generateOne( anOutStream, 76.870323, 41.847992, 82.575661, 28.38339 ); - generateOne( anOutStream, 92.845276, 40.022282, 91.932419, 26.557682 ); - generateOne( anOutStream, 106.081657, 35.686226, 98.778824, 21.99341 ); - generateOne( anOutStream, 119.774475, 29.980886, 106.994514, 14.91879 ); - generateOne( anOutStream, 133.239075, 26.785896, 115.666634, 5.790246 ); - generateOne( anOutStream, 150.811523, 20.167702, 125.47982, -4.707579 ); - generateOne( anOutStream, 163.591476, 13.777717, 135.977631, -12.92327 ); - generateOne( anOutStream, 183.446045, 11.267367, 151.496155, -24.105736 ); - generateOne( anOutStream, 197.367081, 8.98523100, 172.720016, -31.180355 ); - generateOne( anOutStream, 214.026672, 9.669872, 197.823502, -38.483189 ); - generateOne( anOutStream, 235.706985, 9.89809100, 220.873108, -47.155304 ); - generateOne( anOutStream, 266.744019, 9.213447, 248.715134, -58.565987 ); - generateOne( anOutStream, 307.366028, 10.354514, 278.611145, -67.922737 ); - generateOne( anOutStream, 342.510925, 7.159524, 316.951019, -84.81053 ); - generateOne( anOutStream, 384.659393, -4.55408, 350.913635, -100.02983 ); - generateOne( anOutStream, 443.097107, -21.015415, 391.243927, -118.960365 ); - generateOne( anOutStream, 500.711792, -34.184483, 440.62793, -147.7677 ); - generateOne( anOutStream, 547.626587, -52.291954, 482.604309, -169.990509 ); - generateOne( anOutStream, 589.603027, -68.753288, 534.45752, -193.8594 ); - generateOne( anOutStream, 633.225525, -97.560631, 569.026306, -206.205444 ); - generateOne( anOutStream, 673.555786, -120.606499, 601.948975, -224.312912 ); - generateOne( anOutStream, 719.647522, -148.590775, 654.625305, -248.181854 ); - generateOne( anOutStream, 770.677673, -183.982635, 708.947693, -278.635315 ); - generateOne( anOutStream, 824.177002, -225.959045, 742.69342, -314.027191 ); - generateOne( anOutStream, 855.937317, -260.368958, 793.05932, -341.853638 ); - generateOne( anOutStream, 884.168213, -294.37439, 838.6137700, -355.969116 ); - generateOne( anOutStream, 915.607178, -327.096588, 875.185669, -366.234894 ); - generateOne( anOutStream, 940.630066, -348.269775, 903.416565, -381.633575 ); - generateOne( anOutStream, 963.728088, -370.726166, 936.780396, -397.032257 ); - generateOne( anOutStream, 983.618042, -390.61615, 959.878418, -411.789337 ); - generateOne( anOutStream, 999.658325, -407.939667, 978.485107, -425.904785 ); - generateOne( anOutStream, 1018.265076, -422.696716, 996.450256, -443.228302 ); - generateOne( anOutStream, 1040.079834, -441.303467, 1017.623413, -459.9102175 ); - generateOne( anOutStream, 1055.478516, -456.060547, 1034.946899, -475.9505 ); - generateOne( anOutStream, 1074.085327, -474.025665, 1058.044922, -493.274017 ); - } - - 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.toStdString().c_str() ) ); - - HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry->GetAltitudePoints(); - CPPUNIT_ASSERT( anAltitudePoints.Length() == 20 ); - - gp_XY aTestPoint( 1, 1 ); - double anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint ); - CPPUNIT_ASSERT( ValuesEquals( anAltitude, 10.0 ) ); - - aTestPoint = gp_XY( 0.5, 0.5 ); - anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint ); - CPPUNIT_ASSERT( ValuesEquals( anAltitude, 5.0 ) ); - - aTestPoint = gp_XY( 1.5, 1 ); - anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint ); - CPPUNIT_ASSERT( ValuesEquals( anAltitude, 10.0 ) ); - - aTestPoint = gp_XY( 1.5, 0.7 ); - anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint ); - CPPUNIT_ASSERT( ValuesEquals( anAltitude, 7.0 ) ); - - aTestPoint = gp_XY( 1.5, -0.7 ); - anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint ); - CPPUNIT_ASSERT( ValuesEquals( anAltitude, HYDROData_Bathymetry::GetInvalidAltitude() ) ); - - aTestPoint = gp_XY( 2, 3.5 ); - anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint ); - CPPUNIT_ASSERT( ValuesEquals( anAltitude, 35.0 ) ); - - aDoc->Close(); -} - - -void test_HYDROData_Bathymetry::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.toStdString().c_str() ) ); - - HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry1->GetAltitudePoints(); - CPPUNIT_ASSERT( anAltitudePoints.Length() == 20 ); - } - - Handle(HYDROData_Bathymetry) aBathymetry2 = - Handle(HYDROData_Bathymetry)::DownCast( aDoc->CreateObject( KIND_BATHYMETRY ) ); - - aBathymetry1->CopyTo( aBathymetry2, true ); - - if ( anIsFileCreated ) - { - HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry2->GetAltitudePoints(); - CPPUNIT_ASSERT( anAltitudePoints.Length() == 20 ); - } - - aDoc->Close(); -} diff --git a/src/HYDROData/test_HYDROData_Bathymetry.h b/src/HYDROData/test_HYDROData_Bathymetry.h deleted file mode 100755 index 421933c0..00000000 --- a/src/HYDROData/test_HYDROData_Bathymetry.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -class Handle_HYDROData_Bathymetry; -class QString; - -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"); diff --git a/src/HYDROData/test_HYDROData_CalculationCase.cxx b/src/HYDROData/test_HYDROData_CalculationCase.cxx deleted file mode 100755 index 97bb75a0..00000000 --- a/src/HYDROData/test_HYDROData_CalculationCase.cxx +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -#include - diff --git a/src/HYDROData/test_HYDROData_CalculationCase.h b/src/HYDROData/test_HYDROData_CalculationCase.h deleted file mode 100755 index 650a5f36..00000000 --- a/src/HYDROData/test_HYDROData_CalculationCase.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -class Handle_HYDROData_CalculationCase; -class QString; - -class test_HYDROData_CalculationCase : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(test_HYDROData_CalculationCase); - CPPUNIT_TEST_SUITE_END(); - -public: - - void setUp() {} - - void tearDown() {} - -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_CalculationCase); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROData_CalculationCase, "HYDROData_CalculationCase"); diff --git a/src/HYDROData/test_HYDROData_Document.cxx b/src/HYDROData/test_HYDROData_Document.cxx deleted file mode 100644 index 9469ec38..00000000 --- a/src/HYDROData/test_HYDROData_Document.cxx +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -#include -#include - -void test_HYDROData_Document::testSaveOpen() -{ - // temporarly created file name (in the current directory) - const char* aTestFile = "TestDoc.cbf"; - // save - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); - CPPUNIT_ASSERT(!aDoc.IsNull()); - // keep some saved information to check after retreive - aDoc->NewID(); - int anID = aDoc->NewID(); - Data_DocError aStatus = aDoc->Save(aTestFile); - CPPUNIT_ASSERT(aStatus == DocError_OK); - aDoc->Close(); - CPPUNIT_ASSERT(!HYDROData_Document::HasDocument(1)); - - // open - aStatus = HYDROData_Document::Load(aTestFile, 2); - CPPUNIT_ASSERT(aStatus == DocError_OK); - CPPUNIT_ASSERT(HYDROData_Document::HasDocument(2)); - aDoc = HYDROData_Document::Document(2); - CPPUNIT_ASSERT(!aDoc.IsNull()); - // check that retreived correctly - CPPUNIT_ASSERT(aDoc->NewID() == anID + 1); - - // remove the created file using Qt functionality - QFile aFile(aTestFile); - aFile.remove(); - - aDoc->Close(); -} - -void test_HYDROData_Document::testOperations() -{ - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); - CPPUNIT_ASSERT(!aDoc.IsNull()); - CPPUNIT_ASSERT(!aDoc->IsOperation()); - CPPUNIT_ASSERT(!aDoc->IsModified()); - // commit operation - aDoc->StartOperation(); - CPPUNIT_ASSERT(aDoc->IsOperation()); - int anID = aDoc->NewID(); - aDoc->CommitOperation(); - CPPUNIT_ASSERT(!aDoc->IsOperation()); - CPPUNIT_ASSERT(aDoc->IsModified()); - // abort operation - aDoc->StartOperation(); - CPPUNIT_ASSERT(aDoc->IsOperation()); - int anIDAborted = aDoc->NewID(); - aDoc->AbortOperation(); - CPPUNIT_ASSERT(!aDoc->IsOperation()); - CPPUNIT_ASSERT(aDoc->IsModified()); - - CPPUNIT_ASSERT(anID + 1 == aDoc->NewID()); - - aDoc->Close(); -} - -void test_HYDROData_Document::testUndoRedo() -{ - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); - CPPUNIT_ASSERT(!aDoc.IsNull()); - CPPUNIT_ASSERT(!aDoc->CanUndo()); - CPPUNIT_ASSERT(!aDoc->CanRedo()); - // commit operation - aDoc->StartOperation(); - CPPUNIT_ASSERT(aDoc->IsOperation()); - int anID = aDoc->NewID(); - aDoc->CommitOperation(); - CPPUNIT_ASSERT(aDoc->CanUndo()); - CPPUNIT_ASSERT(!aDoc->CanRedo()); - CPPUNIT_ASSERT(aDoc->IsModified()); - // undo - aDoc->Undo(); - CPPUNIT_ASSERT(!aDoc->CanUndo()); - CPPUNIT_ASSERT(aDoc->CanRedo()); - CPPUNIT_ASSERT(anID == aDoc->NewID()); - CPPUNIT_ASSERT(!aDoc->IsModified()); - // redo - aDoc->Redo(); - CPPUNIT_ASSERT(aDoc->CanUndo()); - CPPUNIT_ASSERT(!aDoc->CanRedo()); - CPPUNIT_ASSERT(aDoc->IsModified()); - - aDoc->Close(); -} diff --git a/src/HYDROData/test_HYDROData_Document.h b/src/HYDROData/test_HYDROData_Document.h deleted file mode 100644 index cec13ecb..00000000 --- a/src/HYDROData/test_HYDROData_Document.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -class test_HYDROData_Document : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(test_HYDROData_Document); - CPPUNIT_TEST(testSaveOpen); - CPPUNIT_TEST(testOperations); - CPPUNIT_TEST(testUndoRedo); - CPPUNIT_TEST_SUITE_END(); - -private: - -public: - - void setUp() {} - - void tearDown() {} - - // checks the save and open document as a file - void testSaveOpen(); - - // checks the operations management: open/commit/abort, etc - void testOperations(); - - // checks the operations undo/redo - void testUndoRedo(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_Document); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROData_Document, "HYDROData_Document"); diff --git a/src/HYDROData/test_HYDROData_Entity.cxx b/src/HYDROData/test_HYDROData_Entity.cxx deleted file mode 100644 index e55530bb..00000000 --- a/src/HYDROData/test_HYDROData_Entity.cxx +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -#include -#include - -#include - -void test_HYDROData_Entity::testName() -{ - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); - - Handle(HYDROData_Entity) anObj = aDoc->CreateObject(KIND_IMAGE); // any object - static const QString aName("test_name"); - anObj->SetName(aName); - CPPUNIT_ASSERT_EQUAL(aName.toStdString(), anObj->GetName().toStdString()); - - aDoc->Close(); -} - -void test_HYDROData_Entity::testRemove() -{ - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); - - Handle(HYDROData_Entity) anObj = aDoc->CreateObject(KIND_IMAGE); // any object - CPPUNIT_ASSERT(!anObj->IsRemoved()); - anObj->Remove(); - CPPUNIT_ASSERT(anObj->IsRemoved()); - - aDoc->Close(); -} - -void test_HYDROData_Entity::testCopy() -{ - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); - - Handle(HYDROData_Entity) anObj = aDoc->CreateObject(KIND_IMAGE); // any object - static const QString aName("test_name"); - anObj->SetName(aName); - - Handle(HYDROData_Entity) aCopy = aDoc->CreateObject(KIND_IMAGE); // object for copy - CPPUNIT_ASSERT(aCopy->GetName().isEmpty()); - anObj->CopyTo(aCopy, true); - - // check the copied object has same name as original - CPPUNIT_ASSERT_EQUAL(aName.toStdString(), aCopy->GetName().toStdString()); - - aDoc->Close(); -} diff --git a/src/HYDROData/test_HYDROData_Entity.h b/src/HYDROData/test_HYDROData_Entity.h deleted file mode 100644 index 8a0dec7e..00000000 --- a/src/HYDROData/test_HYDROData_Entity.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -class test_HYDROData_Entity : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(test_HYDROData_Entity); - CPPUNIT_TEST(testName); - CPPUNIT_TEST(testRemove); - CPPUNIT_TEST(testCopy); - CPPUNIT_TEST_SUITE_END(); - -private: - -public: - - void setUp() {} - - void tearDown() {} - - // checks the "name" methods - void testName(); - - // checks the remove of object - void testRemove(); - - // checks the copying of object - void testCopy(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_Entity); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROData_Entity, "HYDROData_Entity"); diff --git a/src/HYDROData/test_HYDROData_Image.cxx b/src/HYDROData/test_HYDROData_Image.cxx deleted file mode 100644 index ddeeeb87..00000000 --- a/src/HYDROData/test_HYDROData_Image.cxx +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -#include -#include -#include - -static QImage TestImage() { - QImage aPic(50, 40, QImage::Format_RGB32); - QPainter aPainter(&aPic); - aPainter.drawEllipse(6, 7, 38, 30); - aPainter.drawLine(0, 40, 10, 0); - aPainter.drawLine(10, 0, 25, 35); - aPainter.drawLine(25, 35, 40, 0); - aPainter.drawLine(40, 0, 50, 40); - return aPic; -} - -void test_HYDROData_Image::testQImage() -{ - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); - - Handle(HYDROData_Image) anImage = - Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE)); - // empty image - QImage anEmpty = anImage->Image(); - CPPUNIT_ASSERT(anEmpty.isNull()); - - // prepare Qt Image for testing - QImage aPic(TestImage()); - anImage->SetImage(aPic); - QImage aRestored = anImage->Image(); - - CPPUNIT_ASSERT(!aRestored.isNull()); - //aRestored.save("pic2.bmp"); - CPPUNIT_ASSERT(aPic == aRestored); - - aDoc->Close(); -} - -void test_HYDROData_Image::testTrsf() -{ - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); - - Handle(HYDROData_Image) anImage = - Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE)); - // empty trsf - QTransform anEmpty = anImage->Trsf(); - CPPUNIT_ASSERT(anEmpty.isIdentity()); - - // prepare Qt transformation for testing - QTransform aTrsf; - aTrsf.translate(50, 50); - aTrsf.rotate(45); - aTrsf.scale(0.5, 1.0); - - anImage->SetTrsf(aTrsf); - QTransform aRestored = anImage->Trsf(); - - CPPUNIT_ASSERT(!aRestored.isIdentity()); - CPPUNIT_ASSERT(aTrsf == aRestored); - - aDoc->Close(); -} - -void test_HYDROData_Image::testReferences() -{ - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); - - Handle(HYDROData_Image) anImage1 = - Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE)); - Handle(HYDROData_Image) anImage2 = - Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE)); - Handle(HYDROData_Image) anImage3 = - Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE)); - - // check initially there is no references - CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 0); - - // append reference - anImage3->AppendReference(anImage1); - CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 1); - CPPUNIT_ASSERT(IsEqual(anImage3->Reference(0), anImage1)); - - // change reference - anImage3->ChangeReference(0, anImage2); - CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 1); - CPPUNIT_ASSERT(IsEqual(anImage3->Reference(0), anImage2)); - - // append one more reference - anImage3->AppendReference(anImage1); - CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 2); - CPPUNIT_ASSERT(IsEqual(anImage3->Reference(0), anImage2)); - CPPUNIT_ASSERT(IsEqual(anImage3->Reference(1), anImage1)); - - // remove reference - anImage3->RemoveReference(0); - CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 1); - CPPUNIT_ASSERT(IsEqual(anImage3->Reference(0), anImage1)); - - // remove reference - anImage3->RemoveReference(0); - CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 0); - - // append two references once again and remove all references - anImage3->ChangeReference(0, anImage1); - anImage3->ChangeReference(1, anImage2); - CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 2); - CPPUNIT_ASSERT(IsEqual(anImage3->Reference(0), anImage1)); - CPPUNIT_ASSERT(IsEqual(anImage3->Reference(1), anImage2)); - anImage3->ClearReferences(); - CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 0); - - aDoc->Close(); -} - -void test_HYDROData_Image::testCopy() -{ - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); - - Handle(HYDROData_Image) anImage1 = - Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE)); - // fill image 1 - anImage1->SetImage(TestImage()); - - QTransform aTrsf; - aTrsf.translate(50, 50); - aTrsf.rotate(45); - aTrsf.scale(0.5, 1.0); - anImage1->SetTrsf(aTrsf); - - Handle(HYDROData_Image) anImage2 = - Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE)); - - anImage1->AppendReference(anImage2); - - // copy image to the new one - Handle(HYDROData_Image) anImage3 = - Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE)); - anImage1->CopyTo(anImage3, true); - - // check all fields are correctly copied - CPPUNIT_ASSERT(anImage1->Image() == anImage3->Image()); - CPPUNIT_ASSERT(anImage1->Trsf() == anImage3->Trsf()); - CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 1); - CPPUNIT_ASSERT(IsEqual(anImage3->Reference(0), anImage2)); - - aDoc->Close(); -} diff --git a/src/HYDROData/test_HYDROData_Image.h b/src/HYDROData/test_HYDROData_Image.h deleted file mode 100644 index c649ece7..00000000 --- a/src/HYDROData/test_HYDROData_Image.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -class test_HYDROData_Image : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(test_HYDROData_Image); - CPPUNIT_TEST(testQImage); - CPPUNIT_TEST(testTrsf); - CPPUNIT_TEST(testReferences); - CPPUNIT_TEST(testCopy); - CPPUNIT_TEST_SUITE_END(); - -private: - -public: - - void setUp() {} - - void tearDown() {} - - // checks save/restore QImages information - void testQImage(); - - // checks the transformations - void testTrsf(); - - // checks the references management - void testReferences(); - - // checks the image properties copy/paste - void testCopy(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_Image); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROData_Image, "HYDROData_Image"); diff --git a/src/HYDROData/test_HYDROData_Iterator.cxx b/src/HYDROData/test_HYDROData_Iterator.cxx deleted file mode 100644 index 7381a4e7..00000000 --- a/src/HYDROData/test_HYDROData_Iterator.cxx +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -#include -#include - -#include - -void test_HYDROData_Iterator::testOneKind() -{ - static const QString aName1("test_name1"); - static const QString aName2("test_name2"); - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); - - Handle(HYDROData_Entity) anObj = aDoc->CreateObject(KIND_IMAGE); // image object - anObj->SetName(aName1); - // first HYDROData_Entity must be destroyed because there is no hander pointer naymore - anObj = aDoc->CreateObject(KIND_IMAGE); // second image object - anObj->SetName(aName2); - - HYDROData_Iterator anIter(aDoc, KIND_IMAGE); - CPPUNIT_ASSERT(anIter.More()); - CPPUNIT_ASSERT(!anIter.Current().IsNull()); - CPPUNIT_ASSERT_EQUAL(aName1.toStdString(), anIter.Current()->GetName().toStdString()); - - anIter.Next(); - CPPUNIT_ASSERT(anIter.More()); - CPPUNIT_ASSERT(!anIter.Current().IsNull()); - CPPUNIT_ASSERT_EQUAL(aName2.toStdString(), anIter.Current()->GetName().toStdString()); - - anIter.Next(); - CPPUNIT_ASSERT(!anIter.More()); - - aDoc->Close(); -} - -void test_HYDROData_Iterator::testAllKinds() -{ - static const QString aName1("test_name1"); - static const QString aName2("test_name2"); - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); - - Handle(HYDROData_Entity) anObj = aDoc->CreateObject(KIND_IMAGE); // image object - anObj->SetName(aName1); - // first HYDROData_Entity must be destroyed because there is no hander pointer naymore - anObj = aDoc->CreateObject(KIND_IMAGE); // second image object - anObj->SetName(aName2); - - HYDROData_Iterator anIter(aDoc, KIND_UNKNOWN); - CPPUNIT_ASSERT(anIter.More()); - CPPUNIT_ASSERT(!anIter.Current().IsNull()); - CPPUNIT_ASSERT_EQUAL(aName1.toStdString(), anIter.Current()->GetName().toStdString()); - - anIter.Next(); - CPPUNIT_ASSERT(anIter.More()); - CPPUNIT_ASSERT(!anIter.Current().IsNull()); - CPPUNIT_ASSERT_EQUAL(aName2.toStdString(), anIter.Current()->GetName().toStdString()); - - anIter.Next(); - CPPUNIT_ASSERT(!anIter.More()); - - aDoc->Close(); -} diff --git a/src/HYDROData/test_HYDROData_Iterator.h b/src/HYDROData/test_HYDROData_Iterator.h deleted file mode 100644 index 1ba38a62..00000000 --- a/src/HYDROData/test_HYDROData_Iterator.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -class test_HYDROData_Iterator : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(test_HYDROData_Iterator); - CPPUNIT_TEST(testOneKind); - CPPUNIT_TEST(testAllKinds); - CPPUNIT_TEST_SUITE_END(); - -private: - -public: - - void setUp() {} - - void tearDown() {} - - // checks iteration by one kind - void testOneKind(); - - // checks iteration by all kinds - void testAllKinds(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_Iterator); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROData_Iterator, "HYDROData_Iterator"); diff --git a/src/HYDROData/test_HYDROData_Main.cxx b/src/HYDROData/test_HYDROData_Main.cxx deleted file mode 100644 index e3796b37..00000000 --- a/src/HYDROData/test_HYDROData_Main.cxx +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include -#include -#include -#include -#include -#include -#include - -int - main( int argc, char* argv[] ) -{ - std::string testPath = (argc > 1) ? std::string(argv[1]) : ""; - - // Create the event manager and test controller - CppUnit::TestResult controller; - - // Add a listener that colllects test result - CppUnit::TestResultCollector result; - controller.addListener( &result ); - - // Add a listener that print dots as test run. - CppUnit::TextTestProgressListener progress; - controller.addListener( &progress ); - - CppUnit::TestFactoryRegistry& registry = - CppUnit::TestFactoryRegistry::getRegistry(); - // Add the top suite to the test runner - CppUnit::TestRunner runner; - runner.addTest( registry.makeTest() ); - try - { - std::cout << "Running " << testPath; - runner.run( controller, testPath ); - - std::cerr << std::endl; - - // Print test in a compiler compatible format. - CppUnit::CompilerOutputter outputter( &result, std::cerr ); - outputter.write(); - } - catch ( std::invalid_argument &e ) // Test path not resolved - { - std::cerr << std::endl - << "ERROR: " << e.what() - << std::endl; - return 0; - } - - return result.wasSuccessful() ? 0 : 1; -} diff --git a/src/HYDROData/test_HYDROData_OperationsFactory.cxx b/src/HYDROData/test_HYDROData_OperationsFactory.cxx deleted file mode 100644 index f9c08ec5..00000000 --- a/src/HYDROData/test_HYDROData_OperationsFactory.cxx +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -#include -#include -#include -#include - -#include - -#include - -#include - -void test_HYDROData_OperationsFactory::testCreate() -{ - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); - - HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory(); - CPPUNIT_ASSERT(aFactory); - Handle(HYDROData_Image) anImage = aFactory->CreateImage(aDoc, NULL); - CPPUNIT_ASSERT(!anImage.IsNull()); - CPPUNIT_ASSERT(anImage->Image().isNull()); - - aDoc->Close(); -} - -static QImage TestImage() { - QImage aPic(50, 40, QImage::Format_RGB32); - aPic.fill(Qt::white); - QPainter aPainter(&aPic); - aPainter.drawEllipse(6, 7, 38, 30); - aPainter.drawLine(0, 40, 10, 0); - aPainter.drawLine(10, 0, 25, 35); - aPainter.drawLine(25, 35, 40, 0); - aPainter.drawLine(40, 0, 50, 40); - return aPic; -} - -void test_HYDROData_OperationsFactory::testCrop() -{ - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); - HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory(); - - // prepare the original image and crop-path - Handle(HYDROData_Image) anOriImage = - Handle(HYDROData_Image)::DownCast( aDoc->CreateObject( KIND_IMAGE ) ); - - QImage aTestImage = TestImage(); - anOriImage->SetImage( aTestImage ); - - Handle(HYDROData_PolylineXY) aCropPolyline = - Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); - - aCropPolyline->AddSection( "", HYDROData_PolylineXY::SECTION_POLYLINE, true ); - - aCropPolyline->AddPoint( 0, HYDROData_PolylineXY::Point( 25, 0 ) ); - aCropPolyline->AddPoint( 0, HYDROData_PolylineXY::Point( 0, 20 ) ); - aCropPolyline->AddPoint( 0, HYDROData_PolylineXY::Point( 25, 40 ) ); - aCropPolyline->AddPoint( 0, HYDROData_PolylineXY::Point( 50, 20 ) ); - - // prepare Composer Operation - ImageComposer_Operator* aCropOp = - aFactory->Operator( ImageComposer_CropOperator::Type() ); - - CPPUNIT_ASSERT( aCropOp ); - - aCropOp->setArgs( Qt::red ); - - // create crop - image - Handle(HYDROData_Image) aCropImage = aFactory->CreateImage( aDoc, aCropOp ); - CPPUNIT_ASSERT( !aCropImage.IsNull() ); - - aCropImage->AppendReference( anOriImage ); - aCropImage->AppendReference( aCropPolyline ); - aCropImage->Update(); - - // check crop operation was performed - CPPUNIT_ASSERT( !aCropImage->Image().isNull() ); - CPPUNIT_ASSERT( aCropImage->Image() != aTestImage ); - - aDoc->Close(); -} diff --git a/src/HYDROData/test_HYDROData_OperationsFactory.h b/src/HYDROData/test_HYDROData_OperationsFactory.h deleted file mode 100644 index 3b5f7fd8..00000000 --- a/src/HYDROData/test_HYDROData_OperationsFactory.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -class test_HYDROData_OperationsFactory : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(test_HYDROData_OperationsFactory); - CPPUNIT_TEST(testCreate); - CPPUNIT_TEST(testCrop); - CPPUNIT_TEST_SUITE_END(); - -private: - -public: - - void setUp() {} - - void tearDown() {} - - // checks creation of images using null operators - void testCreate(); - - // checks creation of images using crop operator - void testCrop(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_OperationsFactory); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROData_OperationsFactory, "HYDROData_OperationsFactory"); diff --git a/src/HYDROData/test_HYDROData_PolylineXY.cxx b/src/HYDROData/test_HYDROData_PolylineXY.cxx deleted file mode 100644 index 99b61069..00000000 --- a/src/HYDROData/test_HYDROData_PolylineXY.cxx +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -#include -#include - -#include -#include - -void test_HYDROData_PolylineXY::testPolyline() -{ - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); - - Handle(HYDROData_PolylineXY) aPolyline = - Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY)); - - aPolyline->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, false ); - aPolyline->AddSection( "Section_2", HYDROData_PolylineXY::SECTION_SPLINE, true ); - - int aNbSections = aPolyline->NbSections(); - CPPUNIT_ASSERT( aNbSections == 2 ); - - NCollection_Sequence aSectNames; - NCollection_Sequence aSectTypes; - NCollection_Sequence aSectClosures; - aPolyline->GetSections( aSectNames, aSectTypes, aSectClosures ); - - CPPUNIT_ASSERT( aSectNames.Value( 0 ) == "Section_1" ); - CPPUNIT_ASSERT( aSectTypes.Value( 0 ) == HYDROData_PolylineXY::SECTION_POLYLINE ); - CPPUNIT_ASSERT( aSectClosures.Value( 0 ) == false ); - - CPPUNIT_ASSERT( aSectNames.Value( 1 ) == "Section_2" ); - CPPUNIT_ASSERT( aSectTypes.Value( 1 ) == HYDROData_PolylineXY::SECTION_SPLINE ); - CPPUNIT_ASSERT( aSectClosures.Value( 1 ) == true ); - - aDoc->Close(); -} - - -void test_HYDROData_PolylineXY::testCopy() -{ - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); - Handle(HYDROData_PolylineXY) aPolyline1 = - Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY)); - - -// aPolyline1->setPoints(aPoints); - - Handle(HYDROData_PolylineXY) aPolyline2 = - Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY)); - - aPolyline1->CopyTo(aPolyline2, true); - - - aDoc->Close(); -} diff --git a/src/HYDROData/test_HYDROData_PolylineXY.h b/src/HYDROData/test_HYDROData_PolylineXY.h deleted file mode 100755 index 24623b3c..00000000 --- a/src/HYDROData/test_HYDROData_PolylineXY.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -class test_HYDROData_PolylineXY : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(test_HYDROData_PolylineXY); - CPPUNIT_TEST(testPolyline); - CPPUNIT_TEST(testCopy); - CPPUNIT_TEST_SUITE_END(); - -private: - -public: - - void setUp() {} - - void tearDown() {} - - // checks save/restore QImages information - void testPolyline(); - - // checks the image properties copy/paste - void testCopy(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_PolylineXY); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROData_PolylineXY, "HYDROData_PolylineXY"); diff --git a/src/HYDROData/test_HYDROData_Profile.cxx b/src/HYDROData/test_HYDROData_Profile.cxx deleted file mode 100755 index a9154867..00000000 --- a/src/HYDROData/test_HYDROData_Profile.cxx +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -#include -#include -#include -#include - -#include - -#include -#include - -#include -#include -#include - -bool test_HYDROData_Profile::createTestFile( const QString& theFileName, - const bool theIsParametric ) -{ - QFile aTmpFile( theFileName ); - if ( !aTmpFile.open( QIODevice::WriteOnly | QIODevice::Text ) ) - return false; - - if ( theIsParametric ) - { - QTextStream anOutStream( &aTmpFile ); - - anOutStream << "0 182.15 \n"; - anOutStream << "4 181.95 \n"; - anOutStream << "10.18 181.63 \n"; - anOutStream << "14.75 179.27 \n"; - anOutStream << "19.75 178.87 \n"; - - anOutStream << "\n"; - - anOutStream << "-5 50 \n"; - anOutStream << "0 15 \n"; - anOutStream << "10.1 10 \n"; - anOutStream << "20 20 \n"; - anOutStream << "250 0.005 \n"; - } - else - { - QTextStream anOutStream( &aTmpFile ); - - anOutStream << "1040499.17 6788618.13 182.15 \n"; - anOutStream << "1040503.12 6788618.79 181.95 \n"; - anOutStream << "1040509.21 6788619.81 181.63 \n"; - anOutStream << "1040513.72 6788620.56 179.27 \n"; - anOutStream << "1040518.65 6788621.38 178.87 \n"; - } - - aTmpFile.close(); - - return true; -} - -void test_HYDROData_Profile::testFileImport() -{ - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); - - QString aParamFileName = QDir::tempPath() + QDir::separator() + "parametric.pa"; - QString aGeorefFileName = QDir::tempPath() + QDir::separator() + "georef.pa"; - if ( !createTestFile( aParamFileName, true ) || !createTestFile( aGeorefFileName, false ) ) - return; // No file has been created - - TCollection_AsciiString aFileName( aParamFileName.toStdString().c_str() ); - - CPPUNIT_ASSERT( HYDROData_Profile::ImportFromFile( aDoc, aFileName ) ); - - int aProfileCount = 0; - HYDROData_Iterator aDocIter( aDoc, KIND_PROFILE ); - for ( ; aDocIter.More(); aDocIter.Next() ) - { - Handle(HYDROData_Profile) aProfile = - Handle(HYDROData_Profile)::DownCast( aDocIter.Current() ); - if ( aProfile.IsNull() ) - continue; - - CPPUNIT_ASSERT( aProfile->IsValid() == false ); - CPPUNIT_ASSERT( aProfile->NbPoints() == 5 ); - - aProfileCount++; - } - - CPPUNIT_ASSERT( aProfileCount == 2 ); - - Handle(HYDROData_Profile) aGeorefProfile = - Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); - - aFileName = TCollection_AsciiString( aGeorefFileName.toStdString().c_str() ); - CPPUNIT_ASSERT( aGeorefProfile->ImportFromFile( aFileName ) ); - - // Check validity of imported profile - CPPUNIT_ASSERT( aGeorefProfile->IsValid() ); - - CPPUNIT_ASSERT( aGeorefProfile->GetTopShape().IsNull() == false ); - - aGeorefProfile->UpdateShape3D(); - CPPUNIT_ASSERT( aGeorefProfile->GetShape3D().IsNull() == false ); - - HYDROData_Profile::ProfilePoints aProfilePoints = aGeorefProfile->GetProfilePoints(); - CPPUNIT_ASSERT( aProfilePoints.Length() == 5 ); - - HYDROData_Profile::ProfilePoint aProfilePoint = aProfilePoints.Value( 3 ); - CPPUNIT_ASSERT( ValuesEquals( aProfilePoint.X(), 1040509.21 ) ); - CPPUNIT_ASSERT( ValuesEquals( aProfilePoint.Y(), 6788619.81 ) ); - CPPUNIT_ASSERT( ValuesEquals( aProfilePoint.Z(), 181.63 ) ); - - aDoc->Close(); -} - - -void test_HYDROData_Profile::testCopy() -{ - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); - - Handle(HYDROData_Profile) aProfile1 = - Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); - - QString aFileName = QDir::tempPath() + QDir::separator() + "georef.pa"; - - bool anIsFileCreated = createTestFile( aFileName, false ); - - if ( anIsFileCreated ) - { - TCollection_AsciiString anAsciiFileName( aFileName.toStdString().c_str() ); - CPPUNIT_ASSERT( aProfile1->ImportFromFile( anAsciiFileName ) ); - - CPPUNIT_ASSERT( aProfile1->IsValid() ); - CPPUNIT_ASSERT( aProfile1->NbPoints() == 5 ); - } - - Handle(HYDROData_Profile) aProfile2 = - Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); - - aProfile1->CopyTo( aProfile2 ); - - if ( anIsFileCreated ) - { - CPPUNIT_ASSERT( aProfile2->IsValid() ); - CPPUNIT_ASSERT( aProfile2->NbPoints() == 5 ); - } - - aDoc->Close(); -} diff --git a/src/HYDROData/test_HYDROData_Profile.h b/src/HYDROData/test_HYDROData_Profile.h deleted file mode 100755 index 9785cf72..00000000 --- a/src/HYDROData/test_HYDROData_Profile.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -class Handle_HYDROData_Profile; -class QString; - -class test_HYDROData_Profile : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(test_HYDROData_Profile); - CPPUNIT_TEST(testFileImport); - CPPUNIT_TEST(testCopy); - CPPUNIT_TEST_SUITE_END(); - -private: - - static bool createTestFile( const QString& theFileName, - const bool theIsParametric ); - -public: - - void setUp() {} - - void tearDown() {} - - // checks file importing information - void testFileImport(); - - // checks the copy/paste mechanism - void testCopy(); - -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_Profile); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROData_Profile, "HYDROData_Profile"); diff --git a/src/HYDROData/test_HYDROData_StricklerTable.cxx b/src/HYDROData/test_HYDROData_StricklerTable.cxx deleted file mode 100644 index 4cf57989..00000000 --- a/src/HYDROData/test_HYDROData_StricklerTable.cxx +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include -#include - -void test_HYDROData_StricklerTable::testImport() -{ - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); - - Handle(HYDROData_Entity) anObj = aDoc->CreateObject( KIND_STRICKLER_TABLE ); - TCollection_AsciiString aFileName = "test_name"; - - aDoc->Close(); -} diff --git a/src/HYDROData/test_HYDROData_StricklerTable.h b/src/HYDROData/test_HYDROData_StricklerTable.h deleted file mode 100644 index fcd1a388..00000000 --- a/src/HYDROData/test_HYDROData_StricklerTable.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#ifdef WIN32 - #pragma warning( disable: 4251 ) -#endif - -#include - -class test_HYDROData_StricklerTable : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( test_HYDROData_StricklerTable ); - CPPUNIT_TEST( testImport ); - CPPUNIT_TEST_SUITE_END(); - -public: - void testImport(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION( test_HYDROData_StricklerTable ); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( test_HYDROData_StricklerTable, "HYDROData_StricklerTable" ); - -#ifdef WIN32 - #pragma warning( default: 4251 ) -#endif diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 46728208..769496f8 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -328,24 +328,3 @@ FILE(GLOB GUIXML_DATA "${CMAKE_CURRENT_SOURCE_DIR}/resources/*.xml") FILE(GLOB GUITXT_DATA "${CMAKE_CURRENT_SOURCE_DIR}/resources/*.txt") SET(GUI_DATA ${GUIPNG_DATA} ${GUIXML_DATA} ${GUITXT_DATA}) INSTALL(FILES ${GUI_DATA} DESTINATION ${SALOME_HYDRO_INSTALL_RES_DATA}) - -# tests -if(SALOME_BUILD_TESTS) - - set(TEST_HEADERS - test_HYDROGUI_ListModel.h - ) - - set(TEST_SOURCES - test_HYDROGUI_Main.cxx - test_HYDROGUI_ListModel.cxx - ) - - set(TEST_EXE test_HYDROGUI) - include(../../CMake/CPPUnitTests.cmake) - target_link_libraries(test_HYDROGUI ${CPPUNIT_LIBRARIES} HYDROData HYDROGUI) - - INSTALL(TARGETS test_HYDROGUI EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_BINS}) - -endif(SALOME_BUILD_TESTS) - diff --git a/src/HYDROGUI/HYDROGUI.h b/src/HYDROGUI/HYDROGUI.h index 79004321..ab5b70b0 100644 --- a/src/HYDROGUI/HYDROGUI.h +++ b/src/HYDROGUI/HYDROGUI.h @@ -19,18 +19,22 @@ #ifndef HYDROGUI_H #define HYDROGUI_H -#if defined HYDROGUI_EXPORTS -#if defined WNT -#define HYDRO_EXPORT __declspec( dllexport ) +#ifdef HYDROGUI_STATIC + #define HYDRO_EXPORT #else -#define HYDRO_EXPORT -#endif -#else -#if defined WNT -#define HYDRO_EXPORT __declspec( dllimport ) -#else -#define HYDRO_EXPORT -#endif + #if defined HYDROGUI_EXPORTS + #if defined WNT + #define HYDRO_EXPORT __declspec( dllexport ) + #else + #define HYDRO_EXPORT + #endif + #else + #if defined WNT + #define HYDRO_EXPORT __declspec( dllimport ) + #else + #define HYDRO_EXPORT + #endif + #endif #endif #ifdef WNT diff --git a/src/HYDROGUI/HYDROGUI_ListModel.h b/src/HYDROGUI/HYDROGUI_ListModel.h index 46a8487d..adc0e42c 100644 --- a/src/HYDROGUI/HYDROGUI_ListModel.h +++ b/src/HYDROGUI/HYDROGUI_ListModel.h @@ -33,8 +33,6 @@ const int HYDROGUI_EntryRole = Qt::UserRole + 2; */ class HYDRO_EXPORT HYDROGUI_ListModel : public QAbstractListModel { - Q_OBJECT - public: enum OpType { Top, Up, Down, Bottom, DragAndDrop }; diff --git a/src/HYDROGUI/test_HYDROGUI_ListModel.cxx b/src/HYDROGUI/test_HYDROGUI_ListModel.cxx deleted file mode 100644 index f5b0ea49..00000000 --- a/src/HYDROGUI/test_HYDROGUI_ListModel.cxx +++ /dev/null @@ -1,427 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#undef HYDROGUI_EXPORTS - -#include -#include -#include - -Handle_HYDROData_Document GetDocument() -{ - return HYDROData_Document::Document( 0 ); -} - -HYDROGUI_ListModel::Object2VisibleList CreateTestObjects( int theObjCount ) -{ - HYDROGUI_ListModel::Object2VisibleList anObjects; - - for( int i=0; iCreateObject( KIND_IMMERSIBLE_ZONE ); - - std::string aName = " "; - aName[0] = 'A' + i; - anObj->SetName( QString::fromStdString( aName ) ); - - bool isVisible = i%2==0; - - anObjects.append( HYDROGUI_ListModel::Object2Visible( anObj, isVisible ) ); - } - return anObjects; -} - -std::string test_HYDROGUI_ListModel::GetObjects( HYDROGUI_ListModel* theModel ) const -{ - std::string anObjects; - for( int i=0, n=theModel->myObjects.size(); imyObjects[i].first->GetName().toStdString(); - if( theModel->isObjectVisible( i ) ) - anObjName = "*" + anObjName; - if( i>0 ) - anObjects += ", "; - anObjects += anObjName; - } - return anObjects; -} - -/** - Test move up algorithm. -*/ -void test_HYDROGUI_ListModel::testMoveUp() -{ - HYDROGUI_ListModel* aModel = new HYDROGUI_ListModel(); - aModel->setObjects( CreateTestObjects( 6 ) ); - const HYDROGUI_ListModel::OpType anUp = HYDROGUI_ListModel::Up; - - // 0. Check the initial state - CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); - - // 1. [ *A ] / ALL OBJECTS - aModel->move( QList() << 0, anUp, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); - - // 2. [ *A, B ] / ALL OBJECTS - aModel->move( QList() << 0 << 1, anUp, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); - - // 3. [ *A, *C ] / ALL OBJECTS - aModel->move( QList() << 0 << 2, anUp, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); - - // 4. [ *A, F ] / ALL OBJECTS - aModel->move( QList() << 0 << 5, anUp, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); - - // 5. [ F ] X 6 times / ALL OBJECTS - aModel->move( QList() << 5, anUp, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, F, *E" ), GetObjects( aModel ) ); - aModel->move( QList() << 4, anUp, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, F, D, *E" ), GetObjects( aModel ) ); - aModel->move( QList() << 3, anUp, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, F, *C, D, *E" ), GetObjects( aModel ) ); - aModel->move( QList() << 2, anUp, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, F, B, *C, D, *E" ), GetObjects( aModel ) ); - aModel->move( QList() << 1, anUp, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, B, *C, D, *E" ), GetObjects( aModel ) ); - aModel->move( QList() << 0, anUp, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, B, *C, D, *E" ), GetObjects( aModel ) ); - - // 6. [ *A, B ] / ALL OBJECTS - aModel->move( QList() << 1 << 2, anUp, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, F, *C, D, *E" ), GetObjects( aModel ) ); - - // 7. [ B, *C, *E ] / ALL OBJECTS - aModel->move( QList() << 1 << 3 << 5, anUp, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "B, *A, *C, F, *E, D" ), GetObjects( aModel ) ); - - // 8. [ *A, *C, F, *E, D ] / ALL OBJECTS - aModel->move( QList() << 1 << 2 << 3 << 4 << 5, anUp, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, *C, F, *E, D, B" ), GetObjects( aModel ) ); - - // 9. [ *E ] / VISIBLE OBJECTS - aModel->move( QList() << 3, anUp, true ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, *E, *C, F, D, B" ), GetObjects( aModel ) ); - - // 10. [ *E, *C ] / VISIBLE OBJECTS - aModel->move( QList() << 1 << 2, anUp, true ); - CPPUNIT_ASSERT_EQUAL( std::string( "*E, *C, *A, F, D, B" ), GetObjects( aModel ) ); - - // 11. [ *A, F ] / ALL OBJECTS - aModel->move( QList() << 2 << 3, anUp, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*E, *A, F, *C, D, B" ), GetObjects( aModel ) ); - - // 12. [ *A, *C ] / VISIBLE OBJECTS - aModel->move( QList() << 1 << 3, anUp, true ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, *C, *E, F, D, B" ), GetObjects( aModel ) ); - - // 13. [] / ALL OBJECTS - aModel->move( QList(), anUp, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, *C, *E, F, D, B"), GetObjects( aModel ) ); - - // 14. [ *A, *C, *E, F, D, B ] / ALL OBJECTS - aModel->move( QList() << 0 << 1 << 2 << 3 << 4 << 5, anUp, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, *C, *E, F, D, B"), GetObjects( aModel ) ); - - delete aModel; -} - -/** - Test move on top algorithm. -*/ -void test_HYDROGUI_ListModel::testMoveOnTop() -{ - HYDROGUI_ListModel* aModel = new HYDROGUI_ListModel(); - aModel->setObjects( CreateTestObjects( 6 ) ); - const HYDROGUI_ListModel::OpType aTop = HYDROGUI_ListModel::Top; - - // 0. Check the initial state - CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); - - // 1. [ *A ] / ALL OBJECTS - aModel->move( QList() << 0, aTop, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); - - // 2. [ *A ] / VISIBLE OBJECTS - aModel->move( QList() << 0, aTop, true ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); - - // 3. [ F ] / ALL OBJECTS - aModel->move( QList() << 5, aTop, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, B, *C, D, *E" ), GetObjects( aModel ) ); - - // 4. [ *E ] / VISIBLE OBJECTS - aModel->move( QList() << 5, aTop, true ); - CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, B, *C, D" ), GetObjects( aModel ) ); - - // 5. [ *E, F ] / ALL OBJECTS - aModel->move( QList() << 0 << 1, aTop, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, B, *C, D" ), GetObjects( aModel ) ); - - // 6. [ *E, *A ] / ALL OBJECTS - aModel->move( QList() << 0 << 2, aTop, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*E, *A, F, B, *C, D" ), GetObjects( aModel ) ); - - // 7. [ *A, F, *C ] / ALL OBJECTS - aModel->move( QList() << 1 << 2 << 4, aTop, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, F, *C, *E, B, D" ), GetObjects( aModel ) ); - - // 8. [ F, *C, *E, B, D ] / ALL OBJECTS - aModel->move( QList() << 1 << 2 << 3 << 4 << 5, aTop, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, *E, B, D, *A" ), GetObjects( aModel ) ); - - // 9. [] / ALL OBJECTS - aModel->move( QList(), aTop, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, *E, B, D, *A" ), GetObjects( aModel ) ); - - // 10. [*F, *C, *E, B, D, *A] / ALL OBJECTS - aModel->move( QList() << 0 << 1 << 2 << 3 << 4 << 5, aTop, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, *E, B, D, *A" ), GetObjects( aModel ) ); - - delete aModel; -} - -/** - Test move down algorithm. -*/ -void test_HYDROGUI_ListModel::testMoveDown() -{ - HYDROGUI_ListModel* aModel = new HYDROGUI_ListModel(); - aModel->setObjects( CreateTestObjects( 6 ) ); - const HYDROGUI_ListModel::OpType aDown = HYDROGUI_ListModel::Down; - - // 0. Check the initial state - CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); - - // 1. [ F ] / ALL OBJECTS - aModel->move( QList() << 5, aDown, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); - - // 2. [ *E, F ] / ALL OBJECTS - aModel->move( QList() << 4 << 5, aDown, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); - - // 3. [ D, F ] / ALL OBJECTS - aModel->move( QList() << 3 << 5, aDown, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); - - // 4. [ *A, F ] / ALL OBJECTS - aModel->move( QList() << 0 << 5, aDown, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); - - // 5. [ *A ] X 6 times / ALL OBJECTS - aModel->move( QList() << 0, aDown, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "B, *A, *C, D, *E, F" ), GetObjects( aModel ) ); - aModel->move( QList() << 1, aDown, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *A, D, *E, F" ), GetObjects( aModel ) ); - aModel->move( QList() << 2, aDown, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *A, *E, F" ), GetObjects( aModel ) ); - aModel->move( QList() << 3, aDown, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *E, *A, F" ), GetObjects( aModel ) ); - aModel->move( QList() << 4, aDown, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *E, F, *A" ), GetObjects( aModel ) ); - aModel->move( QList() << 5, aDown, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *E, F, *A" ), GetObjects( aModel ) ); - - // 6. [ *E, *F ] / ALL OBJECTS - aModel->move( QList() << 3 << 4, aDown, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *A, *E, F" ), GetObjects( aModel ) ); - - // 7. [ B, D, *E ] / ALL OBJECTS - aModel->move( QList() << 0 << 2 << 4, aDown, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*C, B, *A, D, F, *E" ), GetObjects( aModel ) ); - - // 8. [ *C, B, *A, D, F ] / ALL OBJECTS - aModel->move( QList() << 0 << 1 << 2 << 3 << 4, aDown, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*E, *C, B, *A, D, F" ), GetObjects( aModel ) ); - - // 9. [ *C ] / VISIBLE OBJECTS - aModel->move( QList() << 1, aDown, true ); - CPPUNIT_ASSERT_EQUAL( std::string( "*E, B, *A, *C, D, F" ), GetObjects( aModel ) ); - - // 10. [ *E, *A ] / VISIBLE OBJECTS - aModel->move( QList() << 0 << 2, aDown, true ); - CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F" ), GetObjects( aModel ) ); - - // 11. [ *E, *A ] / VISIBLE OBJECTS - aModel->move( QList() << 2 << 3, aDown, true ); - CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F" ), GetObjects( aModel ) ); - - // 12. [ *C, *E, *A ] / VISIBLE OBJECTS - aModel->move( QList() << 1 << 2 << 3, aDown, true ); - CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F" ), GetObjects( aModel ) ); - - // 13. [] / ALL OBJECTS - aModel->move( QList(), aDown, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F"), GetObjects( aModel ) ); - - // 14. [ B, *C, *E, *A, D, F ] / ALL OBJECTS - aModel->move( QList() << 0 << 1 << 2 << 3 << 4 << 5, aDown, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F"), GetObjects( aModel ) ); - - delete aModel; -} - -/** - Test move on bottom algorithm. -*/ -void test_HYDROGUI_ListModel::testMoveOnBottom() -{ - HYDROGUI_ListModel* aModel = new HYDROGUI_ListModel(); - aModel->setObjects( CreateTestObjects( 6 ) ); - const HYDROGUI_ListModel::OpType aBottom = HYDROGUI_ListModel::Bottom; - - // 0. Check the initial state - CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); - - // 1. [ F ] / ALL OBJECTS - aModel->move( QList() << 5, aBottom, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); - - // 2. [ F ] / VISIBLE OBJECTS - aModel->move( QList() << 5, aBottom, true ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); - - // 3. [ *A ] / ALL OBJECTS - aModel->move( QList() << 0, aBottom, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *E, F, *A" ), GetObjects( aModel ) ); - - // 4. [ *C ] / VISIBLE OBJECTS - aModel->move( QList() << 1, aBottom, true ); - CPPUNIT_ASSERT_EQUAL( std::string( "B, D, *E, F, *A, *C" ), GetObjects( aModel ) ); - - // 5. [ B, D ] / ALL OBJECTS - aModel->move( QList() << 0 << 1, aBottom, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, *C, B, D" ), GetObjects( aModel ) ); - - // 6. [ *C, *D ] / ALL OBJECTS - aModel->move( QList() << 3 << 5, aBottom, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, B, *C, D" ), GetObjects( aModel ) ); - - // 7. [ *E, *A, *C ] / ALL OBJECTS - aModel->move( QList() << 0 << 2 << 4, aBottom, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "F, B, D, *E, *A, *C" ), GetObjects( aModel ) ); - - // 8. [ B, D, *E, *A ] / ALL OBJECTS - aModel->move( QList() << 1 << 2 << 3 << 4 , aBottom, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, B, D, *E, *A" ), GetObjects( aModel ) ); - - // 9. [] / ALL OBJECTS - aModel->move( QList(), aBottom, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, B, D, *E, *A" ), GetObjects( aModel ) ); - - // 10. [F, *C, B, D, *E, *A] / ALL OBJECTS - aModel->move( QList() << 0 << 1 << 2 << 3 << 4 << 5, aBottom, false ); - CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, B, D, *E, *A" ), GetObjects( aModel ) ); - - delete aModel; -} - -/** - Test drag and drop algorithm. -*/ -void test_HYDROGUI_ListModel::testDragAndDrop() -{ - HYDROGUI_ListModel* aModel = new HYDROGUI_ListModel(); - aModel->setObjects( CreateTestObjects( 8 ) ); - const HYDROGUI_ListModel::OpType aDnD = HYDROGUI_ListModel::DragAndDrop; - - // 0. Check the initial state - std::string anInitialState = std::string( "*A, B, *C, D, *E, F, *G, H" ); - CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) ); - - // 1. [] -> B ( i=1 ) - bool aRes = aModel->move( QList(), aDnD, false, 1 ); - CPPUNIT_ASSERT_EQUAL( false, aRes ); - CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) ); - - // 2. ALL -> B ( i=1 ) - QList anAll; - anAll << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7; - aRes = aModel->move( anAll, aDnD, false, 1 ); - CPPUNIT_ASSERT_EQUAL( false, aRes ); - CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) ); - - // 3. [D, *E, *G] -> D : drop item is among dragged items ( at the beginning ) - aRes = aModel->move( QList() << 3 << 4 << 6, aDnD, false, 3 ); - CPPUNIT_ASSERT_EQUAL( false, aRes ); - CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) ); - - // 4. [D, *E, *G] -> *E : drop item is among dragged items ( in the middle ) - aRes = aModel->move( QList() << 3 << 4 << 6, aDnD, false, 4 ); - CPPUNIT_ASSERT_EQUAL( false, aRes ); - CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) ); - - // 5. [D, *E, *G] -> *G : drop item is among dragged items ( at the end ) - aRes = aModel->move( QList() << 3 << 4 << 6, aDnD, false, 6 ); - CPPUNIT_ASSERT_EQUAL( false, aRes ); - CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) ); - - // 6. [D, *E, *G] -> -1 : drop item index is out of range ( less than zero ) - aRes = aModel->move( QList() << 3 << 4 << 6, aDnD, false, -1 ); - CPPUNIT_ASSERT_EQUAL( false, aRes ); - CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) ); - - // 7. [D, *E, *G] -> -1 : drop item index is out of range ( more than than list length ) - aRes = aModel->move( QList() << 3 << 4 << 6, aDnD, false, 9 ); - CPPUNIT_ASSERT_EQUAL( false, aRes ); - CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) ); - - // 8. [D, *E, *G] -> B ( i = 1 ) - aRes = aModel->move( QList() << 3 << 4 << 6, aDnD, false, 1 ); - CPPUNIT_ASSERT_EQUAL( true, aRes ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, D, *E, *G, B, *C, F, H" ), GetObjects( aModel ) ); - - // 9. [*E, F] -> *G - aRes = aModel->move( QList() << 2 << 6, aDnD, false, 3 ); - CPPUNIT_ASSERT_EQUAL( true, aRes ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, D, *E, F, *G, B, *C, H" ), GetObjects( aModel ) ); - - // 10. [*E, F, *G] -> *A - aRes = aModel->move( QList() << 2 << 3 << 4, aDnD, false, 0 ); - CPPUNIT_ASSERT_EQUAL( true, aRes ); - CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *G, *A, D, B, *C, H" ), GetObjects( aModel ) ); - - // 11. [*G, D, *C, H] -> B - aRes = aModel->move( QList() << 2 << 4 << 6 << 7, aDnD, false, 5 ); - CPPUNIT_ASSERT_EQUAL( true, aRes ); - CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, *G, D, *C, H, B" ), GetObjects( aModel ) ); - - // 12. [F, *A, *G, D, *C, H, B] -> *E - QList anAllWithoutFirst; - anAllWithoutFirst << 1 << 2 << 3 << 4 << 5 << 6 << 7; - aRes = aModel->move( anAllWithoutFirst, aDnD, false, 0 ); - CPPUNIT_ASSERT_EQUAL( true, aRes ); - CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, *G, D, *C, H, B, *E" ), GetObjects( aModel ) ); - - // 13. [*A, *G] -> D : no changes - aRes = aModel->move( QList() << 1 << 2, aDnD, false, 3 ); - CPPUNIT_ASSERT_EQUAL( true, aRes ); - CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, *G, D, *C, H, B, *E" ), GetObjects( aModel ) ); - - // 14. [F, *G] -> D - aRes = aModel->move( QList() << 0 << 2, aDnD, false, 3 ); - CPPUNIT_ASSERT_EQUAL( true, aRes ); - CPPUNIT_ASSERT_EQUAL( std::string( "*A, F, *G, D, *C, H, B, *E" ), GetObjects( aModel ) ); - - // 15. [*A, *G, *C, H, *E] -> D - aRes = aModel->move( QList() << 0 << 2 << 4 << 5 << 7, aDnD, false, 3 ); - CPPUNIT_ASSERT_EQUAL( true, aRes ); - CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, *G, *C, H, *E, D, B" ), GetObjects( aModel ) ); -} \ No newline at end of file diff --git a/src/HYDROGUI/test_HYDROGUI_ListModel.h b/src/HYDROGUI/test_HYDROGUI_ListModel.h deleted file mode 100644 index 28dc153b..00000000 --- a/src/HYDROGUI/test_HYDROGUI_ListModel.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -class HYDROGUI_ListModel; - -class test_HYDROGUI_ListModel : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(test_HYDROGUI_ListModel); - CPPUNIT_TEST(testMoveUp); - CPPUNIT_TEST(testMoveOnTop); - CPPUNIT_TEST(testMoveDown); - CPPUNIT_TEST(testMoveOnBottom); - CPPUNIT_TEST(testDragAndDrop); - CPPUNIT_TEST_SUITE_END(); - -private: - std::string GetObjects( HYDROGUI_ListModel* theModel ) const; - -public: - void testMoveUp(); - void testMoveOnTop(); - void testMoveDown(); - void testMoveOnBottom(); - void testDragAndDrop(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROGUI_ListModel); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROGUI_ListModel, "HYDROGUI_ListModel"); diff --git a/src/HYDROGUI/test_HYDROGUI_Main.cxx b/src/HYDROGUI/test_HYDROGUI_Main.cxx deleted file mode 100644 index a12862d7..00000000 --- a/src/HYDROGUI/test_HYDROGUI_Main.cxx +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (C) 2014-2015 EDF-R&D -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include -#include -#include -#include -#include -#include -#include -#include - -int main( int argc, char* argv[] ) -{ - QApplication anApp( argc, argv ); - - std::string testPath = (argc > 1) ? std::string(argv[1]) : ""; - - // Create the event manager and test controller - CppUnit::TestResult controller; - - // Add a listener that colllects test result - CppUnit::TestResultCollector result; - controller.addListener( &result ); - - // Add a listener that print dots as test run. - CppUnit::TextTestProgressListener progress; - controller.addListener( &progress ); - - CppUnit::TestFactoryRegistry& registry = - CppUnit::TestFactoryRegistry::getRegistry(); - // Add the top suite to the test runner - CppUnit::TestRunner runner; - runner.addTest( registry.makeTest() ); - try - { - std::cout << "Running " << testPath; - runner.run( controller, testPath ); - - std::cerr << std::endl; - - // Print test in a compiler compatible format. - CppUnit::CompilerOutputter outputter( &result, std::cerr ); - outputter.write(); - } - catch ( std::invalid_argument &e ) // Test path not resolved - { - std::cerr << std::endl - << "ERROR: " << e.what() - << std::endl; - return 0; - } - - return result.wasSuccessful() ? 0 : 1; -} diff --git a/src/HYDRO_tests/CMakeLists.txt b/src/HYDRO_tests/CMakeLists.txt new file mode 100644 index 00000000..82c0156e --- /dev/null +++ b/src/HYDRO_tests/CMakeLists.txt @@ -0,0 +1,126 @@ +#include(../../CMake/Common.cmake) + +set(PROJECT_HEADERS + test_HYDROData_Bathymetry.h + test_HYDROData_Document.h + test_HYDROData_Entity.h + test_HYDROData_Image.h + test_HYDROData_Iterator.h + test_HYDROData_OperationsFactory.h + test_HYDROData_PolylineXY.h + test_HYDROData_Profile.h + test_HYDROData_StricklerTable.h + test_HYDROGUI_ListModel.h +) + +set(PROJECT_SOURCES + test_HYDROData_Bathymetry.cxx + test_HYDROData_Document.cxx + test_HYDROData_Entity.cxx + test_HYDROData_Image.cxx + test_HYDROData_Iterator.cxx + test_HYDROData_Main.cxx + test_HYDROData_OperationsFactory.cxx + test_HYDROData_PolylineXY.cxx + test_HYDROData_Profile.cxx + test_HYDROData_StricklerTable.cxx + test_HYDROGUI_ListModel.cxx + + ../HYDROData/HYDROData_AltitudeObject.cxx + ../HYDROData/HYDROData_Application.cxx + ../HYDROData/HYDROData_ArtificialObject.cxx + ../HYDROData/HYDROData_Bathymetry.cxx + ../HYDROData/HYDROData_BSplineOperation.cxx + ../HYDROData/HYDROData_CalculationCase.cxx + ../HYDROData/HYDROData_Channel.cxx + ../HYDROData/HYDROData_Confluence.cxx + ../HYDROData/HYDROData_Digue.cxx + ../HYDROData/HYDROData_Document.cxx + ../HYDROData/HYDROData_DummyObject3D.cxx + ../HYDROData/HYDROData_Entity.cxx + ../HYDROData/HYDROData_IAltitudeObject.cxx + ../HYDROData/HYDROData_IInterpolator.cxx + ../HYDROData/HYDROData_Image.cxx + ../HYDROData/HYDROData_ImmersibleZone.cxx + ../HYDROData/HYDROData_IPolyline.cxx + ../HYDROData/HYDROData_Iterator.cxx + ../HYDROData/HYDROData_Lambert93.cxx + ../HYDROData/HYDROData_NaturalObject.cxx + ../HYDROData/HYDROData_Object.cxx + ../HYDROData/HYDROData_Obstacle.cxx + ../HYDROData/HYDROData_ObstacleAltitude.cxx + ../HYDROData/HYDROData_OperationsFactory.cxx + ../HYDROData/HYDROData_Pipes.cxx + ../HYDROData/HYDROData_PolylineOperator.cxx + ../HYDROData/HYDROData_PolylineXY.cxx + ../HYDROData/HYDROData_Polyline3D.cxx + ../HYDROData/HYDROData_PriorityQueue.cxx + ../HYDROData/HYDROData_Profile.cxx + ../HYDROData/HYDROData_ProfileUZ.cxx + ../HYDROData/HYDROData_Projection.cxx + ../HYDROData/HYDROData_Region.cxx + ../HYDROData/HYDROData_River.cxx + ../HYDROData/HYDROData_ShapesGroup.cxx + ../HYDROData/HYDROData_ShapesTool.cxx + ../HYDROData/HYDROData_SplittedShapesGroup.cxx + ../HYDROData/HYDROData_SplitToZonesTool.cxx + ../HYDROData/HYDROData_Stream.cxx + ../HYDROData/HYDROData_StreamAltitude.cxx + ../HYDROData/HYDROData_StricklerTable.cxx + ../HYDROData/HYDROData_LandCover.cxx + ../HYDROData/HYDROData_Tool.cxx + ../HYDROData/HYDROData_TopoCurve.cxx + ../HYDROData/HYDROData_Transform.cxx + ../HYDROData/HYDROData_VisualState.cxx + ../HYDROData/HYDROData_Zone.cxx + ../HYDROData/HYDROData_GeomTool.cxx + ../HYDROData/HYDROData_IProfilesInterpolator.cxx + ../HYDROData/HYDROData_LinearInterpolator.cxx + ../HYDROData/HYDROData_InterpolatorsFactory.cxx + ../HYDROData/HYDROData_SinusX.cxx + ../HYDROData/HYDROData_ShapeFile.cxx + ../HYDROData/HYDROData_LandCoverMap.cxx + + ../HYDROGUI/HYDROGUI_ListModel.cxx + ../HYDROGUI/HYDROGUI_DataObject.cxx +) + +add_definitions( + -DLIGHT_MODE -DHYDRODATA_STATIC -DHYDROGUI_STATIC +) + +IF( ${WIN32} ) + add_definitions( -DWNT ) +ENDIF() + +SET( BOOST_INCLUDES $ENV{BOOST_ROOT_DIR}/include/boost-1_52 ) +SET( CPPUNIT_INCLUDES $ENV{CPPUNIT_ROOT_DIR}/include ) +SET( QT_INCLUDES $ENV{QT_ROOT_DIR}/include $ENV{QT_ROOT_DIR}/include/QtCore $ENV{QT_ROOT_DIR}/include/QtGui ) +SET( GUI_INCLUDES $ENV{GUI_ROOT_DIR}/include/salome ) + +link_directories( $ENV{CAS_ROOT_DIR}/win32/libd ) #TODO: more correct for release, linux etc +SET( CAS_LIBRARIES TKernel TKLCAF TKCAF TKCDF TKMath TKG2d TKG3d TKBRep TKGeomBase TKTopAlgo TKGeomAlgo TKBool TKShHealing TKXSBase TKOffset TKHLR TKBO ) + +link_directories( $ENV{QT_ROOT_DIR}/lib ) +SET( QT_LIBRARIES QtCored4 QtGuid4 ) + +link_directories( $ENV{CPPUNIT_ROOT_DIR}/lib ) +SET( CPPUNIT_LIBRARIES cppunitd ) + +link_directories( $ENV{GUI_ROOT_DIR}/lib/salome ) +SET( GUI_LIBRARIES ImageComposer Qtx SUIT LightApp CAM ) + +include_directories( + ${BOOST_INCLUDES} + ${CAS_INCLUDE_DIRS} + ${QT_INCLUDES} + ${CPPUNIT_INCLUDES} + ${GUI_INCLUDES} + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../HYDROData + ${CMAKE_CURRENT_SOURCE_DIR}/../HYDROGUI + ${CMAKE_CURRENT_SOURCE_DIR}/../shapelib +) + +add_executable( HYDROData_tests ${PROJECT_SOURCES} ${PROJECT_HEADERS}) +target_link_libraries( HYDROData_tests ${GUI_LIBRARIES} ${CAS_LIBRARIES} ${QT_LIBRARIES} ${CPPUNIT_LIBRARIES} shapelib ) diff --git a/src/HYDRO_tests/test_HYDROData_Bathymetry.cxx b/src/HYDRO_tests/test_HYDROData_Bathymetry.cxx new file mode 100644 index 00000000..e3b2509a --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_Bathymetry.cxx @@ -0,0 +1,197 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include + +void generateOne( QTextStream& theStream, + double theFirstX, double theFirstY, + double theLastX, double theLastY ) +{ + const int aNbPoints = 50; + + double aComDist = gp_Pnt2d( theFirstX, theFirstY ).Distance( gp_Pnt2d( theLastX, theLastY ) ); + double aStep = aComDist / (double)aNbPoints; + + double aStepZ = -5; + double aCurDist = 0.0; + for ( int i = 0; i <= aNbPoints; ++i ) + { + double aRatio = ( aCurDist / ( aComDist - aCurDist ) ); + + double anX = ( theFirstX + aRatio * theLastX ) / ( 1 + aRatio ); + double anY = ( theFirstY + aRatio * theLastY ) / ( 1 + aRatio ); + double aZ = aStepZ * aStepZ + sin( (float)rand() ); + theStream << anX << " " << anY << " " << aZ << " \n"; + + aCurDist += aStep; + aStepZ += 0.2; + } +} + +bool test_HYDROData_Bathymetry::createTestFile( const QString& theFileName ) +{ + QFile aTmpFile( theFileName ); + if ( !aTmpFile.open( QIODevice::WriteOnly | QIODevice::Text ) ) + return false; + + { + QTextStream anOutStream( &aTmpFile ); + + srand( 4587 ); + generateOne( anOutStream, 0, 5, 0, -5 ); + generateOne( anOutStream, 10, 5, 10, -5 ); + generateOne( anOutStream, 20, 5, 20, -5 ); + generateOne( anOutStream, 30, 5, 30, -5 ); + generateOne( anOutStream, 40, 5, 40, -5 ); + generateOne( anOutStream, 45.833271, 6.703101, 50.85397, -3.794724 ); + generateOne( anOutStream, 50.85397, 11.267372, 56.787525, 2.367043 ); + generateOne( anOutStream, 52.67968, 16.516285, 62.721077, 10.354518 ); + generateOne( anOutStream, 55.190029, 23.819118, 65.23143, 17.657352 ); + generateOne( anOutStream, 58.385021, 31.806595, 68.198204, 23.819118 ); + generateOne( anOutStream, 65.916069, 38.653004, 75.044609, 27.470537 ); + generateOne( anOutStream, 76.870323, 41.847992, 82.575661, 28.38339 ); + generateOne( anOutStream, 92.845276, 40.022282, 91.932419, 26.557682 ); + generateOne( anOutStream, 106.081657, 35.686226, 98.778824, 21.99341 ); + generateOne( anOutStream, 119.774475, 29.980886, 106.994514, 14.91879 ); + generateOne( anOutStream, 133.239075, 26.785896, 115.666634, 5.790246 ); + generateOne( anOutStream, 150.811523, 20.167702, 125.47982, -4.707579 ); + generateOne( anOutStream, 163.591476, 13.777717, 135.977631, -12.92327 ); + generateOne( anOutStream, 183.446045, 11.267367, 151.496155, -24.105736 ); + generateOne( anOutStream, 197.367081, 8.98523100, 172.720016, -31.180355 ); + generateOne( anOutStream, 214.026672, 9.669872, 197.823502, -38.483189 ); + generateOne( anOutStream, 235.706985, 9.89809100, 220.873108, -47.155304 ); + generateOne( anOutStream, 266.744019, 9.213447, 248.715134, -58.565987 ); + generateOne( anOutStream, 307.366028, 10.354514, 278.611145, -67.922737 ); + generateOne( anOutStream, 342.510925, 7.159524, 316.951019, -84.81053 ); + generateOne( anOutStream, 384.659393, -4.55408, 350.913635, -100.02983 ); + generateOne( anOutStream, 443.097107, -21.015415, 391.243927, -118.960365 ); + generateOne( anOutStream, 500.711792, -34.184483, 440.62793, -147.7677 ); + generateOne( anOutStream, 547.626587, -52.291954, 482.604309, -169.990509 ); + generateOne( anOutStream, 589.603027, -68.753288, 534.45752, -193.8594 ); + generateOne( anOutStream, 633.225525, -97.560631, 569.026306, -206.205444 ); + generateOne( anOutStream, 673.555786, -120.606499, 601.948975, -224.312912 ); + generateOne( anOutStream, 719.647522, -148.590775, 654.625305, -248.181854 ); + generateOne( anOutStream, 770.677673, -183.982635, 708.947693, -278.635315 ); + generateOne( anOutStream, 824.177002, -225.959045, 742.69342, -314.027191 ); + generateOne( anOutStream, 855.937317, -260.368958, 793.05932, -341.853638 ); + generateOne( anOutStream, 884.168213, -294.37439, 838.6137700, -355.969116 ); + generateOne( anOutStream, 915.607178, -327.096588, 875.185669, -366.234894 ); + generateOne( anOutStream, 940.630066, -348.269775, 903.416565, -381.633575 ); + generateOne( anOutStream, 963.728088, -370.726166, 936.780396, -397.032257 ); + generateOne( anOutStream, 983.618042, -390.61615, 959.878418, -411.789337 ); + generateOne( anOutStream, 999.658325, -407.939667, 978.485107, -425.904785 ); + generateOne( anOutStream, 1018.265076, -422.696716, 996.450256, -443.228302 ); + generateOne( anOutStream, 1040.079834, -441.303467, 1017.623413, -459.9102175 ); + generateOne( anOutStream, 1055.478516, -456.060547, 1034.946899, -475.9505 ); + generateOne( anOutStream, 1074.085327, -474.025665, 1058.044922, -493.274017 ); + } + + 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.toStdString().c_str() ) ); + + HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry->GetAltitudePoints(); + CPPUNIT_ASSERT( anAltitudePoints.Length() == 20 ); + + gp_XY aTestPoint( 1, 1 ); + double anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint ); + CPPUNIT_ASSERT( ValuesEquals( anAltitude, 10.0 ) ); + + aTestPoint = gp_XY( 0.5, 0.5 ); + anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint ); + CPPUNIT_ASSERT( ValuesEquals( anAltitude, 5.0 ) ); + + aTestPoint = gp_XY( 1.5, 1 ); + anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint ); + CPPUNIT_ASSERT( ValuesEquals( anAltitude, 10.0 ) ); + + aTestPoint = gp_XY( 1.5, 0.7 ); + anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint ); + CPPUNIT_ASSERT( ValuesEquals( anAltitude, 7.0 ) ); + + aTestPoint = gp_XY( 1.5, -0.7 ); + anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint ); + CPPUNIT_ASSERT( ValuesEquals( anAltitude, HYDROData_Bathymetry::GetInvalidAltitude() ) ); + + aTestPoint = gp_XY( 2, 3.5 ); + anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint ); + CPPUNIT_ASSERT( ValuesEquals( anAltitude, 35.0 ) ); + + aDoc->Close(); +} + + +void test_HYDROData_Bathymetry::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.toStdString().c_str() ) ); + + HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry1->GetAltitudePoints(); + CPPUNIT_ASSERT( anAltitudePoints.Length() == 20 ); + } + + Handle(HYDROData_Bathymetry) aBathymetry2 = + Handle(HYDROData_Bathymetry)::DownCast( aDoc->CreateObject( KIND_BATHYMETRY ) ); + + aBathymetry1->CopyTo( aBathymetry2, true ); + + if ( anIsFileCreated ) + { + HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry2->GetAltitudePoints(); + CPPUNIT_ASSERT( anAltitudePoints.Length() == 20 ); + } + + aDoc->Close(); +} diff --git a/src/HYDRO_tests/test_HYDROData_Bathymetry.h b/src/HYDRO_tests/test_HYDROData_Bathymetry.h new file mode 100644 index 00000000..421933c0 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_Bathymetry.h @@ -0,0 +1,49 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +class Handle_HYDROData_Bathymetry; +class QString; + +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"); diff --git a/src/HYDRO_tests/test_HYDROData_Document.cxx b/src/HYDRO_tests/test_HYDROData_Document.cxx new file mode 100644 index 00000000..9469ec38 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_Document.cxx @@ -0,0 +1,108 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +#include +#include + +void test_HYDROData_Document::testSaveOpen() +{ + // temporarly created file name (in the current directory) + const char* aTestFile = "TestDoc.cbf"; + // save + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + CPPUNIT_ASSERT(!aDoc.IsNull()); + // keep some saved information to check after retreive + aDoc->NewID(); + int anID = aDoc->NewID(); + Data_DocError aStatus = aDoc->Save(aTestFile); + CPPUNIT_ASSERT(aStatus == DocError_OK); + aDoc->Close(); + CPPUNIT_ASSERT(!HYDROData_Document::HasDocument(1)); + + // open + aStatus = HYDROData_Document::Load(aTestFile, 2); + CPPUNIT_ASSERT(aStatus == DocError_OK); + CPPUNIT_ASSERT(HYDROData_Document::HasDocument(2)); + aDoc = HYDROData_Document::Document(2); + CPPUNIT_ASSERT(!aDoc.IsNull()); + // check that retreived correctly + CPPUNIT_ASSERT(aDoc->NewID() == anID + 1); + + // remove the created file using Qt functionality + QFile aFile(aTestFile); + aFile.remove(); + + aDoc->Close(); +} + +void test_HYDROData_Document::testOperations() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + CPPUNIT_ASSERT(!aDoc.IsNull()); + CPPUNIT_ASSERT(!aDoc->IsOperation()); + CPPUNIT_ASSERT(!aDoc->IsModified()); + // commit operation + aDoc->StartOperation(); + CPPUNIT_ASSERT(aDoc->IsOperation()); + int anID = aDoc->NewID(); + aDoc->CommitOperation(); + CPPUNIT_ASSERT(!aDoc->IsOperation()); + CPPUNIT_ASSERT(aDoc->IsModified()); + // abort operation + aDoc->StartOperation(); + CPPUNIT_ASSERT(aDoc->IsOperation()); + int anIDAborted = aDoc->NewID(); + aDoc->AbortOperation(); + CPPUNIT_ASSERT(!aDoc->IsOperation()); + CPPUNIT_ASSERT(aDoc->IsModified()); + + CPPUNIT_ASSERT(anID + 1 == aDoc->NewID()); + + aDoc->Close(); +} + +void test_HYDROData_Document::testUndoRedo() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + CPPUNIT_ASSERT(!aDoc.IsNull()); + CPPUNIT_ASSERT(!aDoc->CanUndo()); + CPPUNIT_ASSERT(!aDoc->CanRedo()); + // commit operation + aDoc->StartOperation(); + CPPUNIT_ASSERT(aDoc->IsOperation()); + int anID = aDoc->NewID(); + aDoc->CommitOperation(); + CPPUNIT_ASSERT(aDoc->CanUndo()); + CPPUNIT_ASSERT(!aDoc->CanRedo()); + CPPUNIT_ASSERT(aDoc->IsModified()); + // undo + aDoc->Undo(); + CPPUNIT_ASSERT(!aDoc->CanUndo()); + CPPUNIT_ASSERT(aDoc->CanRedo()); + CPPUNIT_ASSERT(anID == aDoc->NewID()); + CPPUNIT_ASSERT(!aDoc->IsModified()); + // redo + aDoc->Redo(); + CPPUNIT_ASSERT(aDoc->CanUndo()); + CPPUNIT_ASSERT(!aDoc->CanRedo()); + CPPUNIT_ASSERT(aDoc->IsModified()); + + aDoc->Close(); +} diff --git a/src/HYDRO_tests/test_HYDROData_Document.h b/src/HYDRO_tests/test_HYDROData_Document.h new file mode 100644 index 00000000..cec13ecb --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_Document.h @@ -0,0 +1,47 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +class test_HYDROData_Document : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(test_HYDROData_Document); + CPPUNIT_TEST(testSaveOpen); + CPPUNIT_TEST(testOperations); + CPPUNIT_TEST(testUndoRedo); + CPPUNIT_TEST_SUITE_END(); + +private: + +public: + + void setUp() {} + + void tearDown() {} + + // checks the save and open document as a file + void testSaveOpen(); + + // checks the operations management: open/commit/abort, etc + void testOperations(); + + // checks the operations undo/redo + void testUndoRedo(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_Document); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROData_Document, "HYDROData_Document"); diff --git a/src/HYDRO_tests/test_HYDROData_Entity.cxx b/src/HYDRO_tests/test_HYDROData_Entity.cxx new file mode 100644 index 00000000..e55530bb --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_Entity.cxx @@ -0,0 +1,66 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +#include +#include + +#include + +void test_HYDROData_Entity::testName() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Entity) anObj = aDoc->CreateObject(KIND_IMAGE); // any object + static const QString aName("test_name"); + anObj->SetName(aName); + CPPUNIT_ASSERT_EQUAL(aName.toStdString(), anObj->GetName().toStdString()); + + aDoc->Close(); +} + +void test_HYDROData_Entity::testRemove() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Entity) anObj = aDoc->CreateObject(KIND_IMAGE); // any object + CPPUNIT_ASSERT(!anObj->IsRemoved()); + anObj->Remove(); + CPPUNIT_ASSERT(anObj->IsRemoved()); + + aDoc->Close(); +} + +void test_HYDROData_Entity::testCopy() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Entity) anObj = aDoc->CreateObject(KIND_IMAGE); // any object + static const QString aName("test_name"); + anObj->SetName(aName); + + Handle(HYDROData_Entity) aCopy = aDoc->CreateObject(KIND_IMAGE); // object for copy + CPPUNIT_ASSERT(aCopy->GetName().isEmpty()); + anObj->CopyTo(aCopy, true); + + // check the copied object has same name as original + CPPUNIT_ASSERT_EQUAL(aName.toStdString(), aCopy->GetName().toStdString()); + + aDoc->Close(); +} diff --git a/src/HYDRO_tests/test_HYDROData_Entity.h b/src/HYDRO_tests/test_HYDROData_Entity.h new file mode 100644 index 00000000..8a0dec7e --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_Entity.h @@ -0,0 +1,47 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +class test_HYDROData_Entity : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(test_HYDROData_Entity); + CPPUNIT_TEST(testName); + CPPUNIT_TEST(testRemove); + CPPUNIT_TEST(testCopy); + CPPUNIT_TEST_SUITE_END(); + +private: + +public: + + void setUp() {} + + void tearDown() {} + + // checks the "name" methods + void testName(); + + // checks the remove of object + void testRemove(); + + // checks the copying of object + void testCopy(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_Entity); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROData_Entity, "HYDROData_Entity"); diff --git a/src/HYDRO_tests/test_HYDROData_Image.cxx b/src/HYDRO_tests/test_HYDROData_Image.cxx new file mode 100644 index 00000000..ddeeeb87 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_Image.cxx @@ -0,0 +1,166 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +#include +#include +#include + +static QImage TestImage() { + QImage aPic(50, 40, QImage::Format_RGB32); + QPainter aPainter(&aPic); + aPainter.drawEllipse(6, 7, 38, 30); + aPainter.drawLine(0, 40, 10, 0); + aPainter.drawLine(10, 0, 25, 35); + aPainter.drawLine(25, 35, 40, 0); + aPainter.drawLine(40, 0, 50, 40); + return aPic; +} + +void test_HYDROData_Image::testQImage() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Image) anImage = + Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE)); + // empty image + QImage anEmpty = anImage->Image(); + CPPUNIT_ASSERT(anEmpty.isNull()); + + // prepare Qt Image for testing + QImage aPic(TestImage()); + anImage->SetImage(aPic); + QImage aRestored = anImage->Image(); + + CPPUNIT_ASSERT(!aRestored.isNull()); + //aRestored.save("pic2.bmp"); + CPPUNIT_ASSERT(aPic == aRestored); + + aDoc->Close(); +} + +void test_HYDROData_Image::testTrsf() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Image) anImage = + Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE)); + // empty trsf + QTransform anEmpty = anImage->Trsf(); + CPPUNIT_ASSERT(anEmpty.isIdentity()); + + // prepare Qt transformation for testing + QTransform aTrsf; + aTrsf.translate(50, 50); + aTrsf.rotate(45); + aTrsf.scale(0.5, 1.0); + + anImage->SetTrsf(aTrsf); + QTransform aRestored = anImage->Trsf(); + + CPPUNIT_ASSERT(!aRestored.isIdentity()); + CPPUNIT_ASSERT(aTrsf == aRestored); + + aDoc->Close(); +} + +void test_HYDROData_Image::testReferences() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Image) anImage1 = + Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE)); + Handle(HYDROData_Image) anImage2 = + Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE)); + Handle(HYDROData_Image) anImage3 = + Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE)); + + // check initially there is no references + CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 0); + + // append reference + anImage3->AppendReference(anImage1); + CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 1); + CPPUNIT_ASSERT(IsEqual(anImage3->Reference(0), anImage1)); + + // change reference + anImage3->ChangeReference(0, anImage2); + CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 1); + CPPUNIT_ASSERT(IsEqual(anImage3->Reference(0), anImage2)); + + // append one more reference + anImage3->AppendReference(anImage1); + CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 2); + CPPUNIT_ASSERT(IsEqual(anImage3->Reference(0), anImage2)); + CPPUNIT_ASSERT(IsEqual(anImage3->Reference(1), anImage1)); + + // remove reference + anImage3->RemoveReference(0); + CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 1); + CPPUNIT_ASSERT(IsEqual(anImage3->Reference(0), anImage1)); + + // remove reference + anImage3->RemoveReference(0); + CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 0); + + // append two references once again and remove all references + anImage3->ChangeReference(0, anImage1); + anImage3->ChangeReference(1, anImage2); + CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 2); + CPPUNIT_ASSERT(IsEqual(anImage3->Reference(0), anImage1)); + CPPUNIT_ASSERT(IsEqual(anImage3->Reference(1), anImage2)); + anImage3->ClearReferences(); + CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 0); + + aDoc->Close(); +} + +void test_HYDROData_Image::testCopy() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Image) anImage1 = + Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE)); + // fill image 1 + anImage1->SetImage(TestImage()); + + QTransform aTrsf; + aTrsf.translate(50, 50); + aTrsf.rotate(45); + aTrsf.scale(0.5, 1.0); + anImage1->SetTrsf(aTrsf); + + Handle(HYDROData_Image) anImage2 = + Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE)); + + anImage1->AppendReference(anImage2); + + // copy image to the new one + Handle(HYDROData_Image) anImage3 = + Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE)); + anImage1->CopyTo(anImage3, true); + + // check all fields are correctly copied + CPPUNIT_ASSERT(anImage1->Image() == anImage3->Image()); + CPPUNIT_ASSERT(anImage1->Trsf() == anImage3->Trsf()); + CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 1); + CPPUNIT_ASSERT(IsEqual(anImage3->Reference(0), anImage2)); + + aDoc->Close(); +} diff --git a/src/HYDRO_tests/test_HYDROData_Image.h b/src/HYDRO_tests/test_HYDROData_Image.h new file mode 100644 index 00000000..c649ece7 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_Image.h @@ -0,0 +1,51 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +class test_HYDROData_Image : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(test_HYDROData_Image); + CPPUNIT_TEST(testQImage); + CPPUNIT_TEST(testTrsf); + CPPUNIT_TEST(testReferences); + CPPUNIT_TEST(testCopy); + CPPUNIT_TEST_SUITE_END(); + +private: + +public: + + void setUp() {} + + void tearDown() {} + + // checks save/restore QImages information + void testQImage(); + + // checks the transformations + void testTrsf(); + + // checks the references management + void testReferences(); + + // checks the image properties copy/paste + void testCopy(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_Image); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROData_Image, "HYDROData_Image"); diff --git a/src/HYDRO_tests/test_HYDROData_Iterator.cxx b/src/HYDRO_tests/test_HYDROData_Iterator.cxx new file mode 100644 index 00000000..7381a4e7 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_Iterator.cxx @@ -0,0 +1,80 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +#include +#include + +#include + +void test_HYDROData_Iterator::testOneKind() +{ + static const QString aName1("test_name1"); + static const QString aName2("test_name2"); + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Entity) anObj = aDoc->CreateObject(KIND_IMAGE); // image object + anObj->SetName(aName1); + // first HYDROData_Entity must be destroyed because there is no hander pointer naymore + anObj = aDoc->CreateObject(KIND_IMAGE); // second image object + anObj->SetName(aName2); + + HYDROData_Iterator anIter(aDoc, KIND_IMAGE); + CPPUNIT_ASSERT(anIter.More()); + CPPUNIT_ASSERT(!anIter.Current().IsNull()); + CPPUNIT_ASSERT_EQUAL(aName1.toStdString(), anIter.Current()->GetName().toStdString()); + + anIter.Next(); + CPPUNIT_ASSERT(anIter.More()); + CPPUNIT_ASSERT(!anIter.Current().IsNull()); + CPPUNIT_ASSERT_EQUAL(aName2.toStdString(), anIter.Current()->GetName().toStdString()); + + anIter.Next(); + CPPUNIT_ASSERT(!anIter.More()); + + aDoc->Close(); +} + +void test_HYDROData_Iterator::testAllKinds() +{ + static const QString aName1("test_name1"); + static const QString aName2("test_name2"); + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Entity) anObj = aDoc->CreateObject(KIND_IMAGE); // image object + anObj->SetName(aName1); + // first HYDROData_Entity must be destroyed because there is no hander pointer naymore + anObj = aDoc->CreateObject(KIND_IMAGE); // second image object + anObj->SetName(aName2); + + HYDROData_Iterator anIter(aDoc, KIND_UNKNOWN); + CPPUNIT_ASSERT(anIter.More()); + CPPUNIT_ASSERT(!anIter.Current().IsNull()); + CPPUNIT_ASSERT_EQUAL(aName1.toStdString(), anIter.Current()->GetName().toStdString()); + + anIter.Next(); + CPPUNIT_ASSERT(anIter.More()); + CPPUNIT_ASSERT(!anIter.Current().IsNull()); + CPPUNIT_ASSERT_EQUAL(aName2.toStdString(), anIter.Current()->GetName().toStdString()); + + anIter.Next(); + CPPUNIT_ASSERT(!anIter.More()); + + aDoc->Close(); +} diff --git a/src/HYDRO_tests/test_HYDROData_Iterator.h b/src/HYDRO_tests/test_HYDROData_Iterator.h new file mode 100644 index 00000000..1ba38a62 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_Iterator.h @@ -0,0 +1,43 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +class test_HYDROData_Iterator : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(test_HYDROData_Iterator); + CPPUNIT_TEST(testOneKind); + CPPUNIT_TEST(testAllKinds); + CPPUNIT_TEST_SUITE_END(); + +private: + +public: + + void setUp() {} + + void tearDown() {} + + // checks iteration by one kind + void testOneKind(); + + // checks iteration by all kinds + void testAllKinds(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_Iterator); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROData_Iterator, "HYDROData_Iterator"); diff --git a/src/HYDRO_tests/test_HYDROData_Main.cxx b/src/HYDRO_tests/test_HYDROData_Main.cxx new file mode 100644 index 00000000..e3796b37 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_Main.cxx @@ -0,0 +1,68 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include +#include +#include +#include +#include +#include +#include + +int + main( int argc, char* argv[] ) +{ + std::string testPath = (argc > 1) ? std::string(argv[1]) : ""; + + // Create the event manager and test controller + CppUnit::TestResult controller; + + // Add a listener that colllects test result + CppUnit::TestResultCollector result; + controller.addListener( &result ); + + // Add a listener that print dots as test run. + CppUnit::TextTestProgressListener progress; + controller.addListener( &progress ); + + CppUnit::TestFactoryRegistry& registry = + CppUnit::TestFactoryRegistry::getRegistry(); + // Add the top suite to the test runner + CppUnit::TestRunner runner; + runner.addTest( registry.makeTest() ); + try + { + std::cout << "Running " << testPath; + runner.run( controller, testPath ); + + std::cerr << std::endl; + + // Print test in a compiler compatible format. + CppUnit::CompilerOutputter outputter( &result, std::cerr ); + outputter.write(); + } + catch ( std::invalid_argument &e ) // Test path not resolved + { + std::cerr << std::endl + << "ERROR: " << e.what() + << std::endl; + return 0; + } + + return result.wasSuccessful() ? 0 : 1; +} diff --git a/src/HYDRO_tests/test_HYDROData_OperationsFactory.cxx b/src/HYDRO_tests/test_HYDROData_OperationsFactory.cxx new file mode 100644 index 00000000..f9c08ec5 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_OperationsFactory.cxx @@ -0,0 +1,100 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +#include +#include +#include +#include + +#include + +#include + +#include + +void test_HYDROData_OperationsFactory::testCreate() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory(); + CPPUNIT_ASSERT(aFactory); + Handle(HYDROData_Image) anImage = aFactory->CreateImage(aDoc, NULL); + CPPUNIT_ASSERT(!anImage.IsNull()); + CPPUNIT_ASSERT(anImage->Image().isNull()); + + aDoc->Close(); +} + +static QImage TestImage() { + QImage aPic(50, 40, QImage::Format_RGB32); + aPic.fill(Qt::white); + QPainter aPainter(&aPic); + aPainter.drawEllipse(6, 7, 38, 30); + aPainter.drawLine(0, 40, 10, 0); + aPainter.drawLine(10, 0, 25, 35); + aPainter.drawLine(25, 35, 40, 0); + aPainter.drawLine(40, 0, 50, 40); + return aPic; +} + +void test_HYDROData_OperationsFactory::testCrop() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); + HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory(); + + // prepare the original image and crop-path + Handle(HYDROData_Image) anOriImage = + Handle(HYDROData_Image)::DownCast( aDoc->CreateObject( KIND_IMAGE ) ); + + QImage aTestImage = TestImage(); + anOriImage->SetImage( aTestImage ); + + Handle(HYDROData_PolylineXY) aCropPolyline = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); + + aCropPolyline->AddSection( "", HYDROData_PolylineXY::SECTION_POLYLINE, true ); + + aCropPolyline->AddPoint( 0, HYDROData_PolylineXY::Point( 25, 0 ) ); + aCropPolyline->AddPoint( 0, HYDROData_PolylineXY::Point( 0, 20 ) ); + aCropPolyline->AddPoint( 0, HYDROData_PolylineXY::Point( 25, 40 ) ); + aCropPolyline->AddPoint( 0, HYDROData_PolylineXY::Point( 50, 20 ) ); + + // prepare Composer Operation + ImageComposer_Operator* aCropOp = + aFactory->Operator( ImageComposer_CropOperator::Type() ); + + CPPUNIT_ASSERT( aCropOp ); + + aCropOp->setArgs( Qt::red ); + + // create crop - image + Handle(HYDROData_Image) aCropImage = aFactory->CreateImage( aDoc, aCropOp ); + CPPUNIT_ASSERT( !aCropImage.IsNull() ); + + aCropImage->AppendReference( anOriImage ); + aCropImage->AppendReference( aCropPolyline ); + aCropImage->Update(); + + // check crop operation was performed + CPPUNIT_ASSERT( !aCropImage->Image().isNull() ); + CPPUNIT_ASSERT( aCropImage->Image() != aTestImage ); + + aDoc->Close(); +} diff --git a/src/HYDRO_tests/test_HYDROData_OperationsFactory.h b/src/HYDRO_tests/test_HYDROData_OperationsFactory.h new file mode 100644 index 00000000..3b5f7fd8 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_OperationsFactory.h @@ -0,0 +1,43 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +class test_HYDROData_OperationsFactory : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(test_HYDROData_OperationsFactory); + CPPUNIT_TEST(testCreate); + CPPUNIT_TEST(testCrop); + CPPUNIT_TEST_SUITE_END(); + +private: + +public: + + void setUp() {} + + void tearDown() {} + + // checks creation of images using null operators + void testCreate(); + + // checks creation of images using crop operator + void testCrop(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_OperationsFactory); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROData_OperationsFactory, "HYDROData_OperationsFactory"); diff --git a/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx b/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx new file mode 100644 index 00000000..99b61069 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx @@ -0,0 +1,73 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +#include +#include + +#include +#include + +void test_HYDROData_PolylineXY::testPolyline() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); + + Handle(HYDROData_PolylineXY) aPolyline = + Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY)); + + aPolyline->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, false ); + aPolyline->AddSection( "Section_2", HYDROData_PolylineXY::SECTION_SPLINE, true ); + + int aNbSections = aPolyline->NbSections(); + CPPUNIT_ASSERT( aNbSections == 2 ); + + NCollection_Sequence aSectNames; + NCollection_Sequence aSectTypes; + NCollection_Sequence aSectClosures; + aPolyline->GetSections( aSectNames, aSectTypes, aSectClosures ); + + CPPUNIT_ASSERT( aSectNames.Value( 0 ) == "Section_1" ); + CPPUNIT_ASSERT( aSectTypes.Value( 0 ) == HYDROData_PolylineXY::SECTION_POLYLINE ); + CPPUNIT_ASSERT( aSectClosures.Value( 0 ) == false ); + + CPPUNIT_ASSERT( aSectNames.Value( 1 ) == "Section_2" ); + CPPUNIT_ASSERT( aSectTypes.Value( 1 ) == HYDROData_PolylineXY::SECTION_SPLINE ); + CPPUNIT_ASSERT( aSectClosures.Value( 1 ) == true ); + + aDoc->Close(); +} + + +void test_HYDROData_PolylineXY::testCopy() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + Handle(HYDROData_PolylineXY) aPolyline1 = + Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY)); + + +// aPolyline1->setPoints(aPoints); + + Handle(HYDROData_PolylineXY) aPolyline2 = + Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY)); + + aPolyline1->CopyTo(aPolyline2, true); + + + aDoc->Close(); +} diff --git a/src/HYDRO_tests/test_HYDROData_PolylineXY.h b/src/HYDRO_tests/test_HYDROData_PolylineXY.h new file mode 100644 index 00000000..24623b3c --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_PolylineXY.h @@ -0,0 +1,43 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +class test_HYDROData_PolylineXY : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(test_HYDROData_PolylineXY); + CPPUNIT_TEST(testPolyline); + CPPUNIT_TEST(testCopy); + CPPUNIT_TEST_SUITE_END(); + +private: + +public: + + void setUp() {} + + void tearDown() {} + + // checks save/restore QImages information + void testPolyline(); + + // checks the image properties copy/paste + void testCopy(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_PolylineXY); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROData_PolylineXY, "HYDROData_PolylineXY"); diff --git a/src/HYDRO_tests/test_HYDROData_Profile.cxx b/src/HYDRO_tests/test_HYDROData_Profile.cxx new file mode 100644 index 00000000..49872918 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_Profile.cxx @@ -0,0 +1,165 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include + +bool test_HYDROData_Profile::createTestFile( const QString& theFileName, + const bool theIsParametric ) +{ + QFile aTmpFile( theFileName ); + if ( !aTmpFile.open( QIODevice::WriteOnly | QIODevice::Text ) ) + return false; + + if ( theIsParametric ) + { + QTextStream anOutStream( &aTmpFile ); + + anOutStream << "0 182.15 \n"; + anOutStream << "4 181.95 \n"; + anOutStream << "10.18 181.63 \n"; + anOutStream << "14.75 179.27 \n"; + anOutStream << "19.75 178.87 \n"; + + anOutStream << "\n"; + + anOutStream << "-5 50 \n"; + anOutStream << "0 15 \n"; + anOutStream << "10.1 10 \n"; + anOutStream << "20 20 \n"; + anOutStream << "250 0.005 \n"; + } + else + { + QTextStream anOutStream( &aTmpFile ); + + anOutStream << "1040499.17 6788618.13 182.15 \n"; + anOutStream << "1040503.12 6788618.79 181.95 \n"; + anOutStream << "1040509.21 6788619.81 181.63 \n"; + anOutStream << "1040513.72 6788620.56 179.27 \n"; + anOutStream << "1040518.65 6788621.38 178.87 \n"; + } + + aTmpFile.close(); + + return true; +} + +void test_HYDROData_Profile::testFileImport() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); + + QString aParamFileName = QDir::tempPath() + QDir::separator() + "parametric.pa"; + QString aGeorefFileName = QDir::tempPath() + QDir::separator() + "georef.pa"; + if ( !createTestFile( aParamFileName, true ) || !createTestFile( aGeorefFileName, false ) ) + return; // No file has been created + + TCollection_AsciiString aFileName( aParamFileName.toStdString().c_str() ); + + NCollection_Sequence aBadProfilesList; + CPPUNIT_ASSERT( HYDROData_Profile::ImportFromFile( aDoc, aFileName, aBadProfilesList ) ); + + int aProfileCount = 0; + HYDROData_Iterator aDocIter( aDoc, KIND_PROFILE ); + for ( ; aDocIter.More(); aDocIter.Next() ) + { + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aDocIter.Current() ); + if ( aProfile.IsNull() ) + continue; + + CPPUNIT_ASSERT( aProfile->IsValid() == false ); + CPPUNIT_ASSERT( aProfile->NbPoints() == 5 ); + + aProfileCount++; + } + + CPPUNIT_ASSERT( aProfileCount == 2 ); + + Handle(HYDROData_Profile) aGeorefProfile = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + + aFileName = TCollection_AsciiString( aGeorefFileName.toStdString().c_str() ); + CPPUNIT_ASSERT( aGeorefProfile->ImportFromFile( aFileName ) ); + + // Check validity of imported profile + CPPUNIT_ASSERT( aGeorefProfile->IsValid() ); + + CPPUNIT_ASSERT( aGeorefProfile->GetTopShape().IsNull() == false ); + + aGeorefProfile->Update(); + CPPUNIT_ASSERT( aGeorefProfile->GetShape3D().IsNull() == false ); + + HYDROData_Profile::ProfilePoints aProfilePoints = aGeorefProfile->GetProfilePoints(); + CPPUNIT_ASSERT( aProfilePoints.Length() == 5 ); + + HYDROData_Profile::ProfilePoint aProfilePoint = aProfilePoints.Value( 3 ); + CPPUNIT_ASSERT( ValuesEquals( aProfilePoint.X(), 1040509.21 ) ); + CPPUNIT_ASSERT( ValuesEquals( aProfilePoint.Y(), 6788619.81 ) ); + CPPUNIT_ASSERT( ValuesEquals( aProfilePoint.Z(), 181.63 ) ); + + aDoc->Close(); +} + + +void test_HYDROData_Profile::testCopy() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Profile) aProfile1 = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + + QString aFileName = QDir::tempPath() + QDir::separator() + "georef.pa"; + + bool anIsFileCreated = createTestFile( aFileName, false ); + + if ( anIsFileCreated ) + { + TCollection_AsciiString anAsciiFileName( aFileName.toStdString().c_str() ); + CPPUNIT_ASSERT( aProfile1->ImportFromFile( anAsciiFileName ) ); + + CPPUNIT_ASSERT( aProfile1->IsValid() ); + CPPUNIT_ASSERT( aProfile1->NbPoints() == 5 ); + } + + Handle(HYDROData_Profile) aProfile2 = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + + aProfile1->CopyTo( aProfile2, false ); + + if ( anIsFileCreated ) + { + CPPUNIT_ASSERT( aProfile2->IsValid() ); + CPPUNIT_ASSERT( aProfile2->NbPoints() == 5 ); + } + + aDoc->Close(); +} diff --git a/src/HYDRO_tests/test_HYDROData_Profile.h b/src/HYDRO_tests/test_HYDROData_Profile.h new file mode 100644 index 00000000..9785cf72 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_Profile.h @@ -0,0 +1,50 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +class Handle_HYDROData_Profile; +class QString; + +class test_HYDROData_Profile : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(test_HYDROData_Profile); + CPPUNIT_TEST(testFileImport); + CPPUNIT_TEST(testCopy); + CPPUNIT_TEST_SUITE_END(); + +private: + + static bool createTestFile( const QString& theFileName, + const bool theIsParametric ); + +public: + + void setUp() {} + + void tearDown() {} + + // checks file importing information + void testFileImport(); + + // checks the copy/paste mechanism + void testCopy(); + +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_Profile); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROData_Profile, "HYDROData_Profile"); diff --git a/src/HYDRO_tests/test_HYDROData_StricklerTable.cxx b/src/HYDRO_tests/test_HYDROData_StricklerTable.cxx new file mode 100644 index 00000000..4cf57989 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_StricklerTable.cxx @@ -0,0 +1,30 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include +#include + +void test_HYDROData_StricklerTable::testImport() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Entity) anObj = aDoc->CreateObject( KIND_STRICKLER_TABLE ); + TCollection_AsciiString aFileName = "test_name"; + + aDoc->Close(); +} diff --git a/src/HYDRO_tests/test_HYDROData_StricklerTable.h b/src/HYDRO_tests/test_HYDROData_StricklerTable.h new file mode 100644 index 00000000..fcd1a388 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_StricklerTable.h @@ -0,0 +1,40 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifdef WIN32 + #pragma warning( disable: 4251 ) +#endif + +#include + +class test_HYDROData_StricklerTable : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( test_HYDROData_StricklerTable ); + CPPUNIT_TEST( testImport ); + CPPUNIT_TEST_SUITE_END(); + +public: + void testImport(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( test_HYDROData_StricklerTable ); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( test_HYDROData_StricklerTable, "HYDROData_StricklerTable" ); + +#ifdef WIN32 + #pragma warning( default: 4251 ) +#endif diff --git a/src/HYDRO_tests/test_HYDROGUI_ListModel.cxx b/src/HYDRO_tests/test_HYDROGUI_ListModel.cxx new file mode 100644 index 00000000..f5b0ea49 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROGUI_ListModel.cxx @@ -0,0 +1,427 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#undef HYDROGUI_EXPORTS + +#include +#include +#include + +Handle_HYDROData_Document GetDocument() +{ + return HYDROData_Document::Document( 0 ); +} + +HYDROGUI_ListModel::Object2VisibleList CreateTestObjects( int theObjCount ) +{ + HYDROGUI_ListModel::Object2VisibleList anObjects; + + for( int i=0; iCreateObject( KIND_IMMERSIBLE_ZONE ); + + std::string aName = " "; + aName[0] = 'A' + i; + anObj->SetName( QString::fromStdString( aName ) ); + + bool isVisible = i%2==0; + + anObjects.append( HYDROGUI_ListModel::Object2Visible( anObj, isVisible ) ); + } + return anObjects; +} + +std::string test_HYDROGUI_ListModel::GetObjects( HYDROGUI_ListModel* theModel ) const +{ + std::string anObjects; + for( int i=0, n=theModel->myObjects.size(); imyObjects[i].first->GetName().toStdString(); + if( theModel->isObjectVisible( i ) ) + anObjName = "*" + anObjName; + if( i>0 ) + anObjects += ", "; + anObjects += anObjName; + } + return anObjects; +} + +/** + Test move up algorithm. +*/ +void test_HYDROGUI_ListModel::testMoveUp() +{ + HYDROGUI_ListModel* aModel = new HYDROGUI_ListModel(); + aModel->setObjects( CreateTestObjects( 6 ) ); + const HYDROGUI_ListModel::OpType anUp = HYDROGUI_ListModel::Up; + + // 0. Check the initial state + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 1. [ *A ] / ALL OBJECTS + aModel->move( QList() << 0, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 2. [ *A, B ] / ALL OBJECTS + aModel->move( QList() << 0 << 1, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 3. [ *A, *C ] / ALL OBJECTS + aModel->move( QList() << 0 << 2, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 4. [ *A, F ] / ALL OBJECTS + aModel->move( QList() << 0 << 5, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 5. [ F ] X 6 times / ALL OBJECTS + aModel->move( QList() << 5, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, F, *E" ), GetObjects( aModel ) ); + aModel->move( QList() << 4, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, F, D, *E" ), GetObjects( aModel ) ); + aModel->move( QList() << 3, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, F, *C, D, *E" ), GetObjects( aModel ) ); + aModel->move( QList() << 2, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, F, B, *C, D, *E" ), GetObjects( aModel ) ); + aModel->move( QList() << 1, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, B, *C, D, *E" ), GetObjects( aModel ) ); + aModel->move( QList() << 0, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, B, *C, D, *E" ), GetObjects( aModel ) ); + + // 6. [ *A, B ] / ALL OBJECTS + aModel->move( QList() << 1 << 2, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, F, *C, D, *E" ), GetObjects( aModel ) ); + + // 7. [ B, *C, *E ] / ALL OBJECTS + aModel->move( QList() << 1 << 3 << 5, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *A, *C, F, *E, D" ), GetObjects( aModel ) ); + + // 8. [ *A, *C, F, *E, D ] / ALL OBJECTS + aModel->move( QList() << 1 << 2 << 3 << 4 << 5, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, *C, F, *E, D, B" ), GetObjects( aModel ) ); + + // 9. [ *E ] / VISIBLE OBJECTS + aModel->move( QList() << 3, anUp, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, *E, *C, F, D, B" ), GetObjects( aModel ) ); + + // 10. [ *E, *C ] / VISIBLE OBJECTS + aModel->move( QList() << 1 << 2, anUp, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "*E, *C, *A, F, D, B" ), GetObjects( aModel ) ); + + // 11. [ *A, F ] / ALL OBJECTS + aModel->move( QList() << 2 << 3, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*E, *A, F, *C, D, B" ), GetObjects( aModel ) ); + + // 12. [ *A, *C ] / VISIBLE OBJECTS + aModel->move( QList() << 1 << 3, anUp, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, *C, *E, F, D, B" ), GetObjects( aModel ) ); + + // 13. [] / ALL OBJECTS + aModel->move( QList(), anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, *C, *E, F, D, B"), GetObjects( aModel ) ); + + // 14. [ *A, *C, *E, F, D, B ] / ALL OBJECTS + aModel->move( QList() << 0 << 1 << 2 << 3 << 4 << 5, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, *C, *E, F, D, B"), GetObjects( aModel ) ); + + delete aModel; +} + +/** + Test move on top algorithm. +*/ +void test_HYDROGUI_ListModel::testMoveOnTop() +{ + HYDROGUI_ListModel* aModel = new HYDROGUI_ListModel(); + aModel->setObjects( CreateTestObjects( 6 ) ); + const HYDROGUI_ListModel::OpType aTop = HYDROGUI_ListModel::Top; + + // 0. Check the initial state + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 1. [ *A ] / ALL OBJECTS + aModel->move( QList() << 0, aTop, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 2. [ *A ] / VISIBLE OBJECTS + aModel->move( QList() << 0, aTop, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 3. [ F ] / ALL OBJECTS + aModel->move( QList() << 5, aTop, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, B, *C, D, *E" ), GetObjects( aModel ) ); + + // 4. [ *E ] / VISIBLE OBJECTS + aModel->move( QList() << 5, aTop, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, B, *C, D" ), GetObjects( aModel ) ); + + // 5. [ *E, F ] / ALL OBJECTS + aModel->move( QList() << 0 << 1, aTop, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, B, *C, D" ), GetObjects( aModel ) ); + + // 6. [ *E, *A ] / ALL OBJECTS + aModel->move( QList() << 0 << 2, aTop, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*E, *A, F, B, *C, D" ), GetObjects( aModel ) ); + + // 7. [ *A, F, *C ] / ALL OBJECTS + aModel->move( QList() << 1 << 2 << 4, aTop, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, F, *C, *E, B, D" ), GetObjects( aModel ) ); + + // 8. [ F, *C, *E, B, D ] / ALL OBJECTS + aModel->move( QList() << 1 << 2 << 3 << 4 << 5, aTop, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, *E, B, D, *A" ), GetObjects( aModel ) ); + + // 9. [] / ALL OBJECTS + aModel->move( QList(), aTop, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, *E, B, D, *A" ), GetObjects( aModel ) ); + + // 10. [*F, *C, *E, B, D, *A] / ALL OBJECTS + aModel->move( QList() << 0 << 1 << 2 << 3 << 4 << 5, aTop, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, *E, B, D, *A" ), GetObjects( aModel ) ); + + delete aModel; +} + +/** + Test move down algorithm. +*/ +void test_HYDROGUI_ListModel::testMoveDown() +{ + HYDROGUI_ListModel* aModel = new HYDROGUI_ListModel(); + aModel->setObjects( CreateTestObjects( 6 ) ); + const HYDROGUI_ListModel::OpType aDown = HYDROGUI_ListModel::Down; + + // 0. Check the initial state + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 1. [ F ] / ALL OBJECTS + aModel->move( QList() << 5, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 2. [ *E, F ] / ALL OBJECTS + aModel->move( QList() << 4 << 5, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 3. [ D, F ] / ALL OBJECTS + aModel->move( QList() << 3 << 5, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 4. [ *A, F ] / ALL OBJECTS + aModel->move( QList() << 0 << 5, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 5. [ *A ] X 6 times / ALL OBJECTS + aModel->move( QList() << 0, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *A, *C, D, *E, F" ), GetObjects( aModel ) ); + aModel->move( QList() << 1, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *A, D, *E, F" ), GetObjects( aModel ) ); + aModel->move( QList() << 2, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *A, *E, F" ), GetObjects( aModel ) ); + aModel->move( QList() << 3, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *E, *A, F" ), GetObjects( aModel ) ); + aModel->move( QList() << 4, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *E, F, *A" ), GetObjects( aModel ) ); + aModel->move( QList() << 5, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *E, F, *A" ), GetObjects( aModel ) ); + + // 6. [ *E, *F ] / ALL OBJECTS + aModel->move( QList() << 3 << 4, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *A, *E, F" ), GetObjects( aModel ) ); + + // 7. [ B, D, *E ] / ALL OBJECTS + aModel->move( QList() << 0 << 2 << 4, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*C, B, *A, D, F, *E" ), GetObjects( aModel ) ); + + // 8. [ *C, B, *A, D, F ] / ALL OBJECTS + aModel->move( QList() << 0 << 1 << 2 << 3 << 4, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*E, *C, B, *A, D, F" ), GetObjects( aModel ) ); + + // 9. [ *C ] / VISIBLE OBJECTS + aModel->move( QList() << 1, aDown, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "*E, B, *A, *C, D, F" ), GetObjects( aModel ) ); + + // 10. [ *E, *A ] / VISIBLE OBJECTS + aModel->move( QList() << 0 << 2, aDown, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F" ), GetObjects( aModel ) ); + + // 11. [ *E, *A ] / VISIBLE OBJECTS + aModel->move( QList() << 2 << 3, aDown, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F" ), GetObjects( aModel ) ); + + // 12. [ *C, *E, *A ] / VISIBLE OBJECTS + aModel->move( QList() << 1 << 2 << 3, aDown, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F" ), GetObjects( aModel ) ); + + // 13. [] / ALL OBJECTS + aModel->move( QList(), aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F"), GetObjects( aModel ) ); + + // 14. [ B, *C, *E, *A, D, F ] / ALL OBJECTS + aModel->move( QList() << 0 << 1 << 2 << 3 << 4 << 5, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F"), GetObjects( aModel ) ); + + delete aModel; +} + +/** + Test move on bottom algorithm. +*/ +void test_HYDROGUI_ListModel::testMoveOnBottom() +{ + HYDROGUI_ListModel* aModel = new HYDROGUI_ListModel(); + aModel->setObjects( CreateTestObjects( 6 ) ); + const HYDROGUI_ListModel::OpType aBottom = HYDROGUI_ListModel::Bottom; + + // 0. Check the initial state + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 1. [ F ] / ALL OBJECTS + aModel->move( QList() << 5, aBottom, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 2. [ F ] / VISIBLE OBJECTS + aModel->move( QList() << 5, aBottom, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 3. [ *A ] / ALL OBJECTS + aModel->move( QList() << 0, aBottom, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *E, F, *A" ), GetObjects( aModel ) ); + + // 4. [ *C ] / VISIBLE OBJECTS + aModel->move( QList() << 1, aBottom, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, D, *E, F, *A, *C" ), GetObjects( aModel ) ); + + // 5. [ B, D ] / ALL OBJECTS + aModel->move( QList() << 0 << 1, aBottom, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, *C, B, D" ), GetObjects( aModel ) ); + + // 6. [ *C, *D ] / ALL OBJECTS + aModel->move( QList() << 3 << 5, aBottom, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, B, *C, D" ), GetObjects( aModel ) ); + + // 7. [ *E, *A, *C ] / ALL OBJECTS + aModel->move( QList() << 0 << 2 << 4, aBottom, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, B, D, *E, *A, *C" ), GetObjects( aModel ) ); + + // 8. [ B, D, *E, *A ] / ALL OBJECTS + aModel->move( QList() << 1 << 2 << 3 << 4 , aBottom, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, B, D, *E, *A" ), GetObjects( aModel ) ); + + // 9. [] / ALL OBJECTS + aModel->move( QList(), aBottom, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, B, D, *E, *A" ), GetObjects( aModel ) ); + + // 10. [F, *C, B, D, *E, *A] / ALL OBJECTS + aModel->move( QList() << 0 << 1 << 2 << 3 << 4 << 5, aBottom, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, B, D, *E, *A" ), GetObjects( aModel ) ); + + delete aModel; +} + +/** + Test drag and drop algorithm. +*/ +void test_HYDROGUI_ListModel::testDragAndDrop() +{ + HYDROGUI_ListModel* aModel = new HYDROGUI_ListModel(); + aModel->setObjects( CreateTestObjects( 8 ) ); + const HYDROGUI_ListModel::OpType aDnD = HYDROGUI_ListModel::DragAndDrop; + + // 0. Check the initial state + std::string anInitialState = std::string( "*A, B, *C, D, *E, F, *G, H" ); + CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) ); + + // 1. [] -> B ( i=1 ) + bool aRes = aModel->move( QList(), aDnD, false, 1 ); + CPPUNIT_ASSERT_EQUAL( false, aRes ); + CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) ); + + // 2. ALL -> B ( i=1 ) + QList anAll; + anAll << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7; + aRes = aModel->move( anAll, aDnD, false, 1 ); + CPPUNIT_ASSERT_EQUAL( false, aRes ); + CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) ); + + // 3. [D, *E, *G] -> D : drop item is among dragged items ( at the beginning ) + aRes = aModel->move( QList() << 3 << 4 << 6, aDnD, false, 3 ); + CPPUNIT_ASSERT_EQUAL( false, aRes ); + CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) ); + + // 4. [D, *E, *G] -> *E : drop item is among dragged items ( in the middle ) + aRes = aModel->move( QList() << 3 << 4 << 6, aDnD, false, 4 ); + CPPUNIT_ASSERT_EQUAL( false, aRes ); + CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) ); + + // 5. [D, *E, *G] -> *G : drop item is among dragged items ( at the end ) + aRes = aModel->move( QList() << 3 << 4 << 6, aDnD, false, 6 ); + CPPUNIT_ASSERT_EQUAL( false, aRes ); + CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) ); + + // 6. [D, *E, *G] -> -1 : drop item index is out of range ( less than zero ) + aRes = aModel->move( QList() << 3 << 4 << 6, aDnD, false, -1 ); + CPPUNIT_ASSERT_EQUAL( false, aRes ); + CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) ); + + // 7. [D, *E, *G] -> -1 : drop item index is out of range ( more than than list length ) + aRes = aModel->move( QList() << 3 << 4 << 6, aDnD, false, 9 ); + CPPUNIT_ASSERT_EQUAL( false, aRes ); + CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) ); + + // 8. [D, *E, *G] -> B ( i = 1 ) + aRes = aModel->move( QList() << 3 << 4 << 6, aDnD, false, 1 ); + CPPUNIT_ASSERT_EQUAL( true, aRes ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, D, *E, *G, B, *C, F, H" ), GetObjects( aModel ) ); + + // 9. [*E, F] -> *G + aRes = aModel->move( QList() << 2 << 6, aDnD, false, 3 ); + CPPUNIT_ASSERT_EQUAL( true, aRes ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, D, *E, F, *G, B, *C, H" ), GetObjects( aModel ) ); + + // 10. [*E, F, *G] -> *A + aRes = aModel->move( QList() << 2 << 3 << 4, aDnD, false, 0 ); + CPPUNIT_ASSERT_EQUAL( true, aRes ); + CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *G, *A, D, B, *C, H" ), GetObjects( aModel ) ); + + // 11. [*G, D, *C, H] -> B + aRes = aModel->move( QList() << 2 << 4 << 6 << 7, aDnD, false, 5 ); + CPPUNIT_ASSERT_EQUAL( true, aRes ); + CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, *G, D, *C, H, B" ), GetObjects( aModel ) ); + + // 12. [F, *A, *G, D, *C, H, B] -> *E + QList anAllWithoutFirst; + anAllWithoutFirst << 1 << 2 << 3 << 4 << 5 << 6 << 7; + aRes = aModel->move( anAllWithoutFirst, aDnD, false, 0 ); + CPPUNIT_ASSERT_EQUAL( true, aRes ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, *G, D, *C, H, B, *E" ), GetObjects( aModel ) ); + + // 13. [*A, *G] -> D : no changes + aRes = aModel->move( QList() << 1 << 2, aDnD, false, 3 ); + CPPUNIT_ASSERT_EQUAL( true, aRes ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, *G, D, *C, H, B, *E" ), GetObjects( aModel ) ); + + // 14. [F, *G] -> D + aRes = aModel->move( QList() << 0 << 2, aDnD, false, 3 ); + CPPUNIT_ASSERT_EQUAL( true, aRes ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, F, *G, D, *C, H, B, *E" ), GetObjects( aModel ) ); + + // 15. [*A, *G, *C, H, *E] -> D + aRes = aModel->move( QList() << 0 << 2 << 4 << 5 << 7, aDnD, false, 3 ); + CPPUNIT_ASSERT_EQUAL( true, aRes ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, *G, *C, H, *E, D, B" ), GetObjects( aModel ) ); +} \ No newline at end of file diff --git a/src/HYDRO_tests/test_HYDROGUI_ListModel.h b/src/HYDRO_tests/test_HYDROGUI_ListModel.h new file mode 100644 index 00000000..28dc153b --- /dev/null +++ b/src/HYDRO_tests/test_HYDROGUI_ListModel.h @@ -0,0 +1,44 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +class HYDROGUI_ListModel; + +class test_HYDROGUI_ListModel : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(test_HYDROGUI_ListModel); + CPPUNIT_TEST(testMoveUp); + CPPUNIT_TEST(testMoveOnTop); + CPPUNIT_TEST(testMoveDown); + CPPUNIT_TEST(testMoveOnBottom); + CPPUNIT_TEST(testDragAndDrop); + CPPUNIT_TEST_SUITE_END(); + +private: + std::string GetObjects( HYDROGUI_ListModel* theModel ) const; + +public: + void testMoveUp(); + void testMoveOnTop(); + void testMoveDown(); + void testMoveOnBottom(); + void testDragAndDrop(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROGUI_ListModel); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROGUI_ListModel, "HYDROGUI_ListModel"); diff --git a/src/HYDRO_tests/test_HYDROGUI_Main.cxx b/src/HYDRO_tests/test_HYDROGUI_Main.cxx new file mode 100644 index 00000000..a12862d7 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROGUI_Main.cxx @@ -0,0 +1,70 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include +#include +#include +#include +#include +#include +#include +#include + +int main( int argc, char* argv[] ) +{ + QApplication anApp( argc, argv ); + + std::string testPath = (argc > 1) ? std::string(argv[1]) : ""; + + // Create the event manager and test controller + CppUnit::TestResult controller; + + // Add a listener that colllects test result + CppUnit::TestResultCollector result; + controller.addListener( &result ); + + // Add a listener that print dots as test run. + CppUnit::TextTestProgressListener progress; + controller.addListener( &progress ); + + CppUnit::TestFactoryRegistry& registry = + CppUnit::TestFactoryRegistry::getRegistry(); + // Add the top suite to the test runner + CppUnit::TestRunner runner; + runner.addTest( registry.makeTest() ); + try + { + std::cout << "Running " << testPath; + runner.run( controller, testPath ); + + std::cerr << std::endl; + + // Print test in a compiler compatible format. + CppUnit::CompilerOutputter outputter( &result, std::cerr ); + outputter.write(); + } + catch ( std::invalid_argument &e ) // Test path not resolved + { + std::cerr << std::endl + << "ERROR: " << e.what() + << std::endl; + return 0; + } + + return result.wasSuccessful() ? 0 : 1; +}