From a729d4fbad2b0eae4e3086b522a97d8ce67b1543 Mon Sep 17 00:00:00 2001 From: asl Date: Thu, 20 Mar 2014 07:49:47 +0000 Subject: [PATCH] automatic tests for GUI in HYDRO environment --- src/HYDROGUI/CMakeLists.txt | 5 +- src/HYDROGUI/HYDROGUI_ZLevelsModel.h | 6 ++- src/HYDROGUI/test_HYDROGUI_Main.cxx | 6 ++- src/HYDROGUI/test_HYDROGUI_ZLevelsModel.cxx | 52 ++++++++++++++++++++- src/HYDROGUI/test_HYDROGUI_ZLevelsModel.h | 4 +- 5 files changed, 65 insertions(+), 8 deletions(-) diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 1aa750d2..5a0472cd 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -211,6 +211,7 @@ target_link_libraries(HYDROGUI HYDROData HYDROCurveCreator ${GUI_Event} ${GUI_OCCViewer} ${GEOM_GEOM} ${GEOM_GEOMBase} ${VTK_LIBRARIES} ${SVTK} ${SalomeObject} ${SalomePrs} ) + INSTALL(TARGETS HYDROGUI EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) set(PROJECT_LIBRARIES HYDROGUI) @@ -245,7 +246,9 @@ if(SALOME_BUILD_TESTS) set(TEST_EXE test_HYDROGUI) include(../../CMake/CPPUnitTests.cmake) - target_link_libraries(test_HYDROGUI ${CAS_OCAF} ${CAS_MODELER} ${QT_LIBRARIES} ${CPPUNIT_LIBRARIES} HYDROData HYDROGUI) + 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_ZLevelsModel.h b/src/HYDROGUI/HYDROGUI_ZLevelsModel.h index af30f458..fd2fb374 100644 --- a/src/HYDROGUI/HYDROGUI_ZLevelsModel.h +++ b/src/HYDROGUI/HYDROGUI_ZLevelsModel.h @@ -23,8 +23,8 @@ #ifndef HYDROGUI_ZLEVELSMODEL_H #define HYDROGUI_ZLEVELSMODEL_H +#include #include - #include #include @@ -34,7 +34,7 @@ const int HYDROGUI_VisibleRole = Qt::UserRole + 1; * \class HYDROGUI_ZLevelsModel * \brief The class representing custom list model for the Z levels */ -class HYDROGUI_ZLevelsModel : public QAbstractListModel +class HYDRO_EXPORT HYDROGUI_ZLevelsModel : public QAbstractListModel { Q_OBJECT @@ -77,6 +77,8 @@ protected: bool isObjectVisible( int theIndex ) const; private: + friend class test_HYDROGUI_ZLevelsModel; + Object2VisibleList myObjects; QPixmap myEmpty, myEye; }; diff --git a/src/HYDROGUI/test_HYDROGUI_Main.cxx b/src/HYDROGUI/test_HYDROGUI_Main.cxx index 67971549..b85793c5 100644 --- a/src/HYDROGUI/test_HYDROGUI_Main.cxx +++ b/src/HYDROGUI/test_HYDROGUI_Main.cxx @@ -5,10 +5,12 @@ #include #include #include +#include -int - main( int argc, char* argv[] ) +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 diff --git a/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.cxx b/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.cxx index 3bbc4b5c..b73e345b 100644 --- a/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.cxx +++ b/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.cxx @@ -1,7 +1,55 @@ -#include +#undef HYDROGUI_EXPORTS + +#include +#include +#include + +Handle_HYDROData_Document GetDocument() +{ + return HYDROData_Document::Document( 0 ); +} + +HYDROGUI_ZLevelsModel::Object2VisibleList CreateTestObjects( int theObjCount ) +{ + HYDROGUI_ZLevelsModel::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_ZLevelsModel::Object2Visible( anObj, isVisible ) ); + } + return anObjects; +} + +std::string test_HYDROGUI_ZLevelsModel::GetObjects( HYDROGUI_ZLevelsModel* 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; +} void test_HYDROGUI_ZLevelsModel::testMoveUp() { - CPPUNIT_ASSERT(1 == 2); + HYDROGUI_ZLevelsModel* aModel = new HYDROGUI_ZLevelsModel(); + aModel->setObjects( CreateTestObjects( 6 ) ); + + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + delete aModel; } diff --git a/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.h b/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.h index eb8d5efb..4dfcefdc 100644 --- a/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.h +++ b/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.h @@ -1,14 +1,16 @@ #include +class HYDROGUI_ZLevelsModel; + class test_HYDROGUI_ZLevelsModel : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(test_HYDROGUI_ZLevelsModel); CPPUNIT_TEST(testMoveUp); CPPUNIT_TEST_SUITE_END(); private: + std::string GetObjects( HYDROGUI_ZLevelsModel* theModel ) const; public: - // checks move up void testMoveUp(); }; -- 2.39.2