]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
automatic tests for GUI in HYDRO environment
authorasl <asl@opencascade.com>
Thu, 20 Mar 2014 07:49:47 +0000 (07:49 +0000)
committerasl <asl@opencascade.com>
Thu, 20 Mar 2014 07:49:47 +0000 (07:49 +0000)
src/HYDROGUI/CMakeLists.txt
src/HYDROGUI/HYDROGUI_ZLevelsModel.h
src/HYDROGUI/test_HYDROGUI_Main.cxx
src/HYDROGUI/test_HYDROGUI_ZLevelsModel.cxx
src/HYDROGUI/test_HYDROGUI_ZLevelsModel.h

index 1aa750d2979699bf6f4dc8a3a70f56b752f98177..5a0472cdfcb404bc19236c8c3d3a8f7ff574a347 100644 (file)
@@ -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)
 
index af30f4585e83a6b0713d680fc9d22569c5240a4f..fd2fb37444c8a0a2b0fdc2f2fbaa3fa9e9030eba 100644 (file)
@@ -23,8 +23,8 @@
 #ifndef HYDROGUI_ZLEVELSMODEL_H
 #define HYDROGUI_ZLEVELSMODEL_H
 
+#include <HYDROGUI.h>
 #include <HYDROData_Entity.h>
-
 #include <QAbstractListModel>
 #include <QPixmap>
 
@@ -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;
 };
index 67971549b411db94ffe56c773471771af4f2bb85..b85793c5e6fb905d6b812a7f779b755bc11a35ac 100644 (file)
@@ -5,10 +5,12 @@
 #include <cppunit/TestRunner.h>
 #include <cppunit/TextTestProgressListener.h>
 #include <stdexcept>
+#include <QApplication>
 
-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
index 3bbc4b5ccdd91e1c370ea259251af6df5bc311f5..b73e345b5baab3cd1a83fecd3ef027185577936d 100644 (file)
@@ -1,7 +1,55 @@
-#include<test_HYDROGUI_ZLevelsModel.h>
 
+#undef HYDROGUI_EXPORTS
+
+#include <test_HYDROGUI_ZLevelsModel.h>
+#include <HYDROData_Document.h>
+#include <HYDROGUI_ZLevelsModel.h>
+
+Handle_HYDROData_Document GetDocument()
+{
+  return HYDROData_Document::Document( 0 );
+}
+
+HYDROGUI_ZLevelsModel::Object2VisibleList CreateTestObjects( int theObjCount )
+{
+  HYDROGUI_ZLevelsModel::Object2VisibleList anObjects;
+
+  for( int i=0; i<theObjCount; i++ )
+  {
+    Handle_HYDROData_Entity anObj = GetDocument()->CreateObject( 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(); i<n; i++ )
+  {
+    std::string anObjName = theModel->myObjects[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;
 }
index eb8d5efbc7d320ca7a989e5ad1f1563d45fc82a7..4dfcefdc8fe7cf0f2aea481215509c946441f670 100644 (file)
@@ -1,14 +1,16 @@
 #include <cppunit/extensions/HelperMacros.h>
 
+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();
 };