]> SALOME platform Git repositories - modules/med.git/commitdiff
Salome HOME
First draft of a possible GUI testing framework. Still work todo:
authorabn <adrien.bruneton@cea.fr>
Thu, 7 Apr 2016 09:29:00 +0000 (11:29 +0200)
committerabn <adrien.bruneton@cea.fr>
Thu, 7 Apr 2016 09:29:00 +0000 (11:29 +0200)
    - pass directory where snapshot should be saved as an arg
    - automatically quit SALOME GUI with a proper event.

22 files changed:
CMakeLists.txt
idl/MEDEventListener.idl
src/MEDCalc/gui/CMakeLists.txt
src/MEDCalc/gui/DatasourceController.cxx
src/MEDCalc/gui/MEDModule.cxx
src/MEDCalc/gui/MEDModule.hxx
src/MEDCalc/gui/MED_msg_fr.ts
src/MEDCalc/gui/TestController.cxx [new file with mode: 0644]
src/MEDCalc/gui/TestController.hxx [new file with mode: 0644]
src/MEDCalc/gui/WorkspaceController.cxx
src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx
src/MEDCalc/gui/test/CMakeLists.txt [new file with mode: 0644]
src/MEDCalc/gui/test/README.txt
src/MEDCalc/gui/test/baselines/test_scalarmap.png [new file with mode: 0644]
src/MEDCalc/gui/test/medcalc_testutils.py.in [new file with mode: 0644]
src/MEDCalc/gui/test/scenarios/test_scalarmap.xml [new file with mode: 0644]
src/MEDCalc/gui/test/test_qttesting.py [new file with mode: 0644]
src/MEDCalc/gui/test/test_scalarmap.py [new file with mode: 0644]
src/MEDCalc/tui/CMakeLists.txt
src/MEDCalc/tui/__init__.py
src/MEDCalc/tui/medevents.py
src/MEDCalc/tui/medtest.py [new file with mode: 0644]

index 54fbb953f70ae48fe801418bffede89b8bbc7149..bfdcca99ca6ad5a3131c22eb63ed8ce34b90b3af 100644 (file)
@@ -67,6 +67,7 @@ FIND_PACKAGE(SalomeOmniORB REQUIRED)
 INCLUDE(CMakeDependentOption)
 OPTION(SALOME_MED_ENABLE_PYTHON "Build PYTHON bindings." ON)
 OPTION(SALOME_MED_WITH_FILE_EXAMPLES "Install examples of files containing meshes and fields of different formats." ON)
+OPTION(SALOME_MED_WITH_QTTESTING "Build MED with QtTesting support." OFF)
 OPTION(SALOME_USE_MPI "(Use MPI containers) - For MED this triggers the build of ParaMEDMEM." ${_default_MPI})
 OPTION(SALOME_BUILD_GUI "Build GUI of MED." ON)
 OPTION(SALOME_BUILD_TESTS "Build MED tests." ON)
index 1181a6e1697dfd083c3cd9e4a86bc5f00ba6dd9d..425238772f78ff2dd08e1ca3a7193bb586adca36 100644 (file)
@@ -34,6 +34,7 @@ module MEDCALC
     EVENT_CLEAN_WORKSPACE,
     EVENT_ADD_DATASOURCE,
     EVENT_ADD_PRESENTATION,
+    EVENT_PLAY_TEST,
     EVENT_UNKNOWN
   };
 
index b51c1432b4ef48d174f7a46ab5ecde1ec7cd714a..f53d45075d18ce60a1239e750a98052252138607 100644 (file)
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
+ADD_SUBDIRECTORY(test)
+
+IF(SALOME_MED_WITH_QTTESTING)
+  ADD_DEFINITIONS(-DMED_HAS_QTTESTING)
+ENDIF()
+
 ADD_DEFINITIONS(${MEDFILE_DEFINITIONS} ${XDR_DEFINITIONS} ${OMNIORB_DEFINITIONS})
 SET(QT_LIBS "${QT_LIBRARIES}")
 INCLUDE(UseQtExt)
 
 ADD_SUBDIRECTORY(dialogs)
 
+SET(MEDCALCGUI_SOURCES 
+    DatasourceController.cxx
+    factory.cxx
+    MEDEventListener_i.cxx
+    MEDModule.cxx
+    PresentationController.cxx
+    ProcessingController.cxx
+    WorkspaceController.cxx
+    XmedConsoleDriver.cxx
+    XmedDataModel.cxx
+)
 
-FILE(GLOB MEDCALCGUI_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cxx")
+IF(SALOME_MED_WITH_QTTESTING)
+  LIST(APPEND MEDCALCGUI_SOURCES TestController.cxx)
+ENDIF()
 
 SET(MEDCALCGUI_HEADERS
   MEDModule.hxx
@@ -34,8 +53,12 @@ SET(MEDCALCGUI_HEADERS
   PresentationController.hxx
   ProcessingController.hxx
   )
-QT_WRAP_MOC(MEDCALCGUI_HEADERS_MOC ${MEDCALCGUI_HEADERS})
+IF(SALOME_MED_WITH_QTTESTING)
+  LIST(APPEND MEDCALCGUI_HEADERS TestController.hxx)
+ENDIF()
 
+QT_WRAP_MOC(MEDCALCGUI_HEADERS_MOC ${MEDCALCGUI_HEADERS})
 
 INCLUDE_DIRECTORIES(
   ${OMNIORB_INCLUDE_DIR} ${OMNIORB_INCLUDE_DIRS}
@@ -63,7 +86,7 @@ SET(MEDCALCGUITS_SOURCES
   MEDCALC_msg_ja.ts
 )
 
-SET(COMMON_FLAGS
+SET(link_libraries
   ${QT_MT_LIBRARIES}
   ${OMNIORB_LIBRARIES}
   ${PLATFORM_LIBRARIES}
@@ -88,11 +111,15 @@ SET(COMMON_FLAGS
   ${MEDCoupling_medcouplingremapper}
 )
 
+IF(SALOME_MED_WITH_QTTESTING)
+  LIST(APPEND link_libraries QtTesting)  # from ParaView
+ENDIF()
+
 ADD_LIBRARY(MEDCALCGUI SHARED ${MEDCALCGUI_SOURCES} ${MEDCALCGUI_HEADERS_MOC})
 IF(WITH_MEDMEMGUI)
   SET_TARGET_PROPERTIES(MEDCALCGUI PROPERTIES COMPILE_FLAGS "-D__WITH_MEDMEMGUI__")
 ENDIF(WITH_MEDMEMGUI)
-TARGET_LINK_LIBRARIES(MEDCALCGUI ${COMMON_FLAGS})
+TARGET_LINK_LIBRARIES(MEDCALCGUI ${link_libraries})
 
 INSTALL(TARGETS MEDCALCGUI DESTINATION ${SALOME_INSTALL_LIBS})
 QT_INSTALL_TS_RESOURCES("${MEDCALCGUITS_SOURCES}" "${SALOME_MED_INSTALL_RES_DATA}")
index a3f7cd0be7db6396f53d0767f64f43931b716ad0..31a82b48b0632b23d247dc0069b098ecc1ad0c40 100644 (file)
@@ -45,6 +45,7 @@
 #include <QStringList>
 #include <QString>
 #include <QMessageBox>
+#include <QFileDialog>
 
 #include "DlgAlias.hxx"
 
@@ -149,10 +150,15 @@ void DatasourceController::OnAddDatasource()
   if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
     anInitialPath = QDir::currentPath();
 
-  QStringList filenames = SUIT_FileDlg::getOpenFileNames( _salomeModule->getApp()->desktop(),
+//  QStringList filenames = SUIT_FileDlg::getOpenFileNames( _salomeModule->getApp()->desktop(),
+//                                                          anInitialPath,
+//                                                          filter,
+//                                                          tr("IMPORT_MED_FIELDS") );
+  // [ABN] the below to be compatible with QtTesting:
+  QStringList filenames = QFileDialog::getOpenFileNames( _salomeModule->getApp()->desktop(),
+                                                          tr("IMPORT_MED_FIELDS"),
                                                           anInitialPath,
-                                                          filter,
-                                                          tr("IMPORT_MED_FIELDS") );
+                                                          tr("FILE_FILTER_MED") );
 
   if ( filenames.count() <= 0 ) return;
   for ( QStringList::ConstIterator itFile = filenames.begin();
index c40bbe231b300f1c340483d29da6de13206ef4f9..b16f71dd2d7fb0b9bccf27a65f4c2588e82394fb 100644 (file)
@@ -222,6 +222,9 @@ MEDModule::createModuleWidgets() {
   _workspaceController->setDataModel(_xmedDataModel);
   _presentationController = new PresentationController(this);
   _processingController = new ProcessingController(this);
+#ifdef MED_HAS_QTTESTING
+  _testController = new TestController(this);
+#endif
 
   connect(_datasourceController, SIGNAL(datasourceSignal(const DatasourceEvent*)),
     _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent*)));
@@ -237,6 +240,11 @@ MEDModule::createModuleWidgets() {
 
   connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
     _presentationController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
+
+#ifdef MED_HAS_QTTESTING
+  connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
+    _testController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
+#endif
 }
 
 void
@@ -245,6 +253,9 @@ MEDModule::createModuleActions() {
   _workspaceController->createActions();
   _presentationController->createActions();
   _processingController->createActions();
+#ifdef MED_HAS_QTTESTING
+  _testController->createActions();
+#endif
 }
 
 int
@@ -262,9 +273,15 @@ MEDModule::createStandardAction(const QString& label,
   if ( effToolTip.isEmpty() )
     effToolTip = label;
 
+  QIcon ico;
+  if (iconName.isEmpty())
+    ico = QIcon();
+  else
+    ico = QIcon(resMgr->loadPixmap("MED", iconName));
+
   QAction* action = createAction(-1,
                                  label,
-                                 resMgr->loadPixmap("MED", iconName),
+                                 ico,
                                  label,
                                  effToolTip,
                                  0,
@@ -349,3 +366,9 @@ MEDModule::onDblClick(const QModelIndex& index)
   STDLOG("    - Presentation name: " + name);
 
 }
+
+void
+MEDModule::onPlayTest(const char * filename)
+{
+
+}
index f05d6616e834e2d5b5c745e9831bff3886e7ce0c..819fd80b10ec1cbaae13b99fc891afcea4f63d93 100644 (file)
@@ -32,6 +32,7 @@
 #include "DatasourceController.hxx"
 #include "PresentationController.hxx"
 #include "ProcessingController.hxx"
+#include "TestController.hxx"
 
 #include <SALOMEconfig.h>
 #include CORBA_CLIENT_HEADER(MED_Gen)
@@ -86,10 +87,12 @@ public slots:
   virtual bool activateModule(SUIT_Study* theStudy);
   virtual bool deactivateModule(SUIT_Study* theStudy);
   virtual void onDblClick(const QModelIndex& index);
+  virtual void onPlayTest(const char * filename);
 
 private:
   void createModuleWidgets();
   void createModuleActions();
+
   static void init();
 
 private:
@@ -99,6 +102,9 @@ private:
   XmedDataModel* _xmedDataModel;
   PresentationController* _presentationController;
   ProcessingController* _processingController;
+#ifdef MED_HAS_QTTESTING
+  TestController * _testController;
+#endif
   static MED_ORB::MED_Gen_var myEngine;
 };
 
index f09dc6717584ab52ebe985a92deae7bf1c61b8f5..7481ad5a8c563170041cde48130aafebfff15fb0 100644 (file)
     </message>
     <message>
       <source>LAB_BLUE_TO_RED</source>
-      <translation>Arc-en-ciel blue vers rouge</translation>
+      <translation>Arc-en-ciel bleu vers rouge</translation>
     </message>
     <message>
       <source>LAB_COOL_TO_WARM</source>
diff --git a/src/MEDCalc/gui/TestController.cxx b/src/MEDCalc/gui/TestController.cxx
new file mode 100644 (file)
index 0000000..8023c68
--- /dev/null
@@ -0,0 +1,151 @@
+// Copyright (C) 2016  CEA/DEN, 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 "TestController.hxx"
+#include "MEDModule.hxx"
+
+#include <Basics_Utils.hxx>  // STDLOG() macro
+
+#include <SUIT_Session.h>
+#include <SUIT_Desktop.h>
+
+#include <SALOMEconfig.h>
+#include CORBA_CLIENT_HEADER(MEDEventListener)
+
+#include <pqTestUtility.h>
+#include <pqXMLEventObserver.h>
+#include <pqXMLEventSource.h>
+
+#include <pqQVTKWidgetEventPlayer.h>
+#include <pqQVTKWidgetEventTranslator.h>
+
+#include <pqTabbedMultiViewWidget.h>
+#include <pqApplicationCore.h>
+#include <pqTestingReaction.h>
+#include <pqSaveScreenshotReaction.h>
+
+#include <QFileDialog>
+#include <QString>
+#include <QDir>
+#include <QIcon>
+#include <QTimer>
+
+TestController::TestController(MEDModule* mod):
+  _salomeModule(mod),
+  _desk(SUIT_Session::session()->activeApplication()->desktop()),
+  _tester(0), _lock_action(0)
+{
+  STDLOG("Creating a TestController");
+  _tester = new pqTestUtility(_desk);
+  _tester->addEventObserver("xml", new pqXMLEventObserver(_desk));
+  _tester->addEventSource("xml", new pqXMLEventSource(_desk));
+}
+
+TestController::~TestController()
+{
+  if (_tester)
+    delete _tester;
+  _tester = 0;
+}
+
+void
+TestController::createActions() {
+  //
+  // Main actions
+  //
+  QString label   = tr("LAB_RECORD_TEST");
+  QString tooltip = tr("TIP_RECORD_TEST");
+  int actionId;
+  actionId = _salomeModule->createStandardAction(label,this, SLOT(onRecordTest()),QString(),tooltip);
+
+  // This action has to be placed in the general file menu
+  int menuId = _salomeModule->createMenu( tr( "MEN_FILE" ), -1,  1 );
+  _salomeModule->action(actionId)->setIconVisibleInMenu(false);
+  _salomeModule->createMenu(actionId, menuId, 60);
+
+  label   = tr("LAB_PLAY_TEST");
+  tooltip = tr("TIP_PLAY_TEST");
+  actionId = _salomeModule->createStandardAction(label,this, SLOT(onPlayTest()),QString(),tooltip);
+  _salomeModule->action(actionId)->setIconVisibleInMenu(false);
+  _salomeModule->createMenu(actionId, menuId, 70);
+
+  label   = tr("LAB_LOCK_TEST");
+  tooltip = tr("TIP_LOCK_TEST");
+  actionId = _salomeModule->createStandardAction(label,this, SLOT(onLockViewSize()),QString(),tooltip);
+  _salomeModule->action(actionId)->setIconVisibleInMenu(false);
+  _salomeModule->action(actionId)->setCheckable(true);
+  _lock_action = _salomeModule->action(actionId);
+  _salomeModule->createMenu(actionId, menuId, 70);
+
+  label   = tr("LAB_SNAP_TEST");
+  tooltip = tr("TIP_SNAP_TEST");
+  actionId = _salomeModule->createStandardAction(label,this, SLOT(onTakeSnapshot()),QString(),tooltip);
+  _salomeModule->action(actionId)->setIconVisibleInMenu(false);
+  _salomeModule->createMenu(actionId, menuId, 70);
+}
+
+void TestController::onRecordTest()
+{
+  QString fileName =
+      QFileDialog::getSaveFileName(_desk, "Save test", QString(), QString("XML file (*.xml)"));
+  if (!fileName.isEmpty())
+    {
+      QApplication::setActiveWindow(_desk); //mandatory otherwise record pop up doesn't show up
+      _tester->recordTests(fileName);
+    }
+}
+
+
+void TestController::onPlayTest()
+{
+  QString fileName =
+      QFileDialog::getOpenFileName(_desk, "Open test", QString(), QString("XML file (*.xml)"));
+  if (!fileName.isEmpty())
+    _tester->playTests(fileName);
+}
+
+void TestController::onPlayTestScenario()
+{
+  STDLOG("@@@@ About to play test " << _test_scenario.toStdString());
+  _tester->playTests(_test_scenario);
+  STDLOG("@@@@ Done playing test " << _test_scenario.toStdString());
+}
+
+void TestController::onLockViewSize()
+{
+  pqTestingReaction::lockViewSize(_lock_action->isChecked());
+}
+
+void TestController::onTakeSnapshot()
+{
+  pqSaveScreenshotReaction::saveScreenshot();
+}
+
+void
+TestController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
+{
+  if ( event->type == MEDCALC::EVENT_PLAY_TEST ) {
+      /* [ABN] Post an event. Indeed, calling the function directly would prevent the proper refresh of the
+       * GUI which also needs to go through the MED event loop (WorkspaceController::processWorkspaceEvent)
+       */
+      _test_scenario = QString(event->filename);
+      QTimer::singleShot(100, this, SLOT(onPlayTestScenario()));
+  }
+}
+
diff --git a/src/MEDCalc/gui/TestController.hxx b/src/MEDCalc/gui/TestController.hxx
new file mode 100644 (file)
index 0000000..5febf52
--- /dev/null
@@ -0,0 +1,61 @@
+// Copyright (C) 2016  CEA/DEN, 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
+//
+
+#ifndef SRC_MEDCALC_GUI_TESTCONTROLLER_HXX_
+#define SRC_MEDCALC_GUI_TESTCONTROLLER_HXX_
+
+#include <QObject>
+#include <QString>
+
+class pqTestUtility;
+class MEDModule;
+class SUIT_Desktop;
+class QAction;
+namespace MEDCALC {
+  class MedEvent;
+};
+
+class TestController: public QObject {
+  Q_OBJECT
+
+public:
+  TestController(MEDModule* mod);
+  virtual ~TestController();
+
+  void createActions();
+
+public slots:
+  void processWorkspaceEvent(const MEDCALC::MedEvent* event);
+
+  void onRecordTest();
+  void onPlayTest();
+  void onPlayTestScenario();
+  void onLockViewSize();
+  void onTakeSnapshot();
+
+protected:
+  MEDModule* _salomeModule;
+  SUIT_Desktop * _desk;
+
+  pqTestUtility * _tester;
+  QAction * _lock_action;
+  QString _test_scenario;
+};
+
+#endif /* SRC_MEDCALC_GUI_TESTCONTROLLER_HXX_ */
index cfb1b506e6610479cca1f89a5c1cb5d6b9e809f4..8b2c6a2fd2456c7bcc464d5f0986663533525853 100644 (file)
@@ -308,6 +308,9 @@ void WorkspaceController::processMedEvent(const MEDCALC::MedEvent* event) {
   else if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
     emit workspaceSignal(event); // forward to DatasourceController
   }
+  else if ( event->type == MEDCALC::EVENT_PLAY_TEST ) {
+    emit workspaceSignal(event); // forward to TestController
+  }
 
 }
 
index 0f88157598db1635c24623018b6d757f97df5fb3..7187e2ee65dc75b0a138720a6b1300d79f2f6a28 100644 (file)
@@ -32,6 +32,7 @@
 class WidgetPresentationParameters : public QWidget
 {
   Q_OBJECT
+
 public:
   WidgetPresentationParameters(QWidget* parent = 0);
   virtual ~WidgetPresentationParameters() {}
diff --git a/src/MEDCalc/gui/test/CMakeLists.txt b/src/MEDCalc/gui/test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0df5141
--- /dev/null
@@ -0,0 +1,39 @@
+# Copyright (C) 2012-2016  CEA/DEN, 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
+#
+
+SALOME_CONFIGURE_FILE(medcalc_testutils.py.in ${CMAKE_CURRENT_BINARY_DIR}/medcalc_testutils.py)
+
+SET(_test_scripts
+    test_qttesting.py    # main entry point
+    test_scalarmap.py
+)
+
+SET(_test_scenarii
+   scenarios/test_scalarmap.xml
+)
+
+SET(_test_baselines
+    baselines/test_scalarmap.png
+)
+
+SALOME_INSTALL_SCRIPTS("${_test_scripts}" ${SALOME_INSTALL_PYTHON}/tests)
+SALOME_INSTALL_SCRIPTS(${CMAKE_CURRENT_BINARY_DIR}/medcalc_testutils.py ${SALOME_INSTALL_PYTHON})
+INSTALL(FILES ${_test_scenarii} DESTINATION ${SALOME_MED_INSTALL_RES_DATA}/tests/scenarios)
+INSTALL(FILES ${_test_baselines} DESTINATION ${SALOME_MED_INSTALL_RES_DATA}/tests/baselines)
index 751cbf465e34cf4b5c123aa8b170054882c1b15e..ad68b0df12895106e96dd8ba7f6f18e27e47aad8 100644 (file)
@@ -1,3 +1,16 @@
+test_qttesting.py
+=================
+
+Tests based on QtTesting framework from ParaView.
+Main entry point is test_qttesting.py.
+Each scenario is described in a XML file and can be recorded directly in the GUI via the "Record test" button. 
+
+A scneario must save a final screenshot of the ParaView view in a file located in the temp directory (TODO: review
+this). This file is compared against a baseline saved in the baselines subdirectory.
+
+
+guiTester.pro 
+=============
 
 This is a simple Qt framework to test the dialog widgets.
 
diff --git a/src/MEDCalc/gui/test/baselines/test_scalarmap.png b/src/MEDCalc/gui/test/baselines/test_scalarmap.png
new file mode 100644 (file)
index 0000000..3e827f4
Binary files /dev/null and b/src/MEDCalc/gui/test/baselines/test_scalarmap.png differ
diff --git a/src/MEDCalc/gui/test/medcalc_testutils.py.in b/src/MEDCalc/gui/test/medcalc_testutils.py.in
new file mode 100644 (file)
index 0000000..59880a5
--- /dev/null
@@ -0,0 +1,36 @@
+# Copyright (C) 2011-2016  CEA/DEN, 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
+#
+
+import os
+
+def __getRootDir():  
+  rootDir = os.environ.get("MED_ROOT_DIR", "")
+  return rootDir 
+
+def GetScriptDir():
+  relativeDir = "@SALOME_INSTALL_PYTHON@/tests"
+  return os.path.join(__getRootDir(), relativeDir)
+
+def GetScenarioDir():
+  relativeDir = "@SALOME_MED_INSTALL_RES_DATA@/tests/scenarios"
+  return os.path.join(__getRootDir(), relativeDir)
+
+def GetBaselineDir():
+  relativeDir = "@SALOME_MED_INSTALL_RES_DATA@/tests/baselines"
+  return os.path.join(__getRootDir(), relativeDir)
diff --git a/src/MEDCalc/gui/test/scenarios/test_scalarmap.xml b/src/MEDCalc/gui/test/scenarios/test_scalarmap.xml
new file mode 100644 (file)
index 0000000..edbc38f
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0" ?>
+<pqevents>
+  <pqevent object="1STD_TabDesktop0/1QMenuBar0" command="activate" arguments="Fic&amp;hier" />
+  <pqevent object="1QMenu0" command="activate" arguments="LAB_LOCK_TEST" />
+  <pqevent object="1STD_TabDesktop0/DatasourceToolbar/1QToolButton0" command="activate" arguments="" />
+  <pqevent object="Qt-subapplication-app" command="FilesOpen" arguments="/home/ab205030/agi_BKP.med" />
+  <pqevent object="1STD_TabDesktop0/objectBrowserDock/objectBrowser/1QtxTreeView0" command="expand" arguments="0.0" />
+  <pqevent object="1STD_TabDesktop0/objectBrowserDock/objectBrowser/1QtxTreeView0" command="expand" arguments="0.0.0.0" />
+  <pqevent object="1STD_TabDesktop0/objectBrowserDock/objectBrowser/1QtxTreeView0" command="expand" arguments="0.0.0.0.0.0" />
+  <pqevent object="1STD_TabDesktop0/objectBrowserDock/objectBrowser/1QtxTreeView0/qt_scrollarea_vcontainer/1QScrollBar0" command="mouseWheel" arguments="-120,0,0,88,5" />
+  <pqevent object="1STD_TabDesktop0/objectBrowserDock/objectBrowser/1QtxTreeView0/qt_scrollarea_vcontainer/1QScrollBar0" command="mouseWheel" arguments="-120,0,0,88,5" />
+  <pqevent object="1STD_TabDesktop0/objectBrowserDock/objectBrowser/1QtxTreeView0" command="setCurrent" arguments="0.0.0.0.0.0.0.0" />
+  <pqevent object="1STD_TabDesktop0/PresentationToolbar/1QToolButton0" command="activate" arguments="" />
+  <pqevent object="1STD_TabDesktop0/1QMenuBar0" command="activate" arguments="Fic&amp;hier" />
+  <pqevent object="1QMenu0" command="activate" arguments="LAB_SNAP_TEST" />
+  <pqevent object="1STD_TabDesktop0/SaveSnapshotDialog/ok" command="activate" arguments="" />
+  <pqevent object="1STD_TabDesktop0/FileSaveScreenshotDialog" command="key" arguments="16777248" />
+  <pqevent object="1STD_TabDesktop0/FileSaveScreenshotDialog/mainSplitter/widget/FileName" command="set_string" arguments="/tmp/test_scalarmap.png" />
+  <pqevent object="1STD_TabDesktop0/FileSaveScreenshotDialog/mainSplitter/widget/OK" command="activate" arguments="" />
+</pqevents>
diff --git a/src/MEDCalc/gui/test/test_qttesting.py b/src/MEDCalc/gui/test/test_qttesting.py
new file mode 100644 (file)
index 0000000..123812b
--- /dev/null
@@ -0,0 +1,99 @@
+# Copyright (C) 2011-2016  CEA/DEN, 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
+#
+# Author: A. Bruneton (CEA)
+
+import unittest, os
+from posixpath import basename
+
+class MEDGUITest(unittest.TestCase):
+  def __init__(self, methodName='runTest'):
+    unittest.TestCase.__init__(self, methodName=methodName)
+    self._tmpDir = ""
+    self._removeDir = True
+    
+  def setUp(self):
+    import tempfile
+    self._tmpDir = tempfile.mkdtemp(prefix="med_gui_tests_")
+    self._removeDir = True  # reset for each new test in the TestCase
+
+  def tearDown(self):
+    import shutil
+    unittest.TestCase.tearDown(self)
+#    if self._removeDir:
+#      shutil.rmtree(self._tmpDir, False)
+    
+  def getTestName(self):
+    """ Return name of the test being currently executed. """
+    return self.id().split(".")[-1]
+
+  def launchSalomeWithScript(self, scriptname, baseline):
+    """ TODO: review this - what is the nicest way to launch SALOME GUI from a Python script? """
+    import shutil, subprocess
+    from medcalc_testutils import GetScriptDir
+    # TODO: review this!
+    salomeCommand = os.path.join(os.environ.get("KERNEL_ROOT_DIR", ""), "bin", "salome", "runSalome.py")
+    pth = os.path.join(GetScriptDir(), scriptname)
+    # Remove a potentially already present image file from the tmp directory:
+    gen_image = os.path.join("/tmp", baseline)
+    try:
+      shutil.rmtree(gen_image)
+    except OSError:
+      pass
+    # Launch SALOME with the test script:
+    status = subprocess.call([salomeCommand, pth])
+    if status:
+      raise Exception("SALOME exited abnormally for this test!")
+    try:
+      # Move generated image to the temporary test directory - ideally test should produce image there directly ...
+      shutil.move(gen_image, self._tmpDir)
+    except IOError:
+      raise Exception("Test script didn't produce expected image '%s'!" % gen_image)
+
+  def compareSnapshot(self, basename):
+    import filecmp
+    from medcalc_testutils import GetBaselineDir
+    
+    base_pth = os.path.join(GetBaselineDir(), basename)
+    gen_path = os.path.join(self._tmpDir, basename)
+    print base_pth, gen_path
+    try:
+      ret = filecmp.cmp(base_pth, gen_path, shallow=False)
+    except OSError:
+      ret = False
+    if not ret:
+      # Keep file if comparison fails
+      self._removeDir = False
+      self.assertTrue(ret, "[%s] -- Failed screenshot equality, or unable to open baseline file - directory is kept alive: %s" % (self.getTestName(), self._tmpDir))
+    return ret
+
+  ##
+  ## Now the tests themselves
+  ##
+  
+  def testScalarMap(self):
+    baseline = "test_scalarmap.png"
+    self.launchSalomeWithScript("test_scalarmap.py", baseline)
+    self.compareSnapshot(baseline)
+    
+if __name__ == "__main__":
+  suite = unittest.TestSuite()
+  suite.addTest(MEDGUITest('testScalarMap'))
+#  suite.addTest(MEDGUITest('testIsoContour'))
+  unittest.TextTestRunner().run(suite)
+
diff --git a/src/MEDCalc/gui/test/test_scalarmap.py b/src/MEDCalc/gui/test/test_scalarmap.py
new file mode 100644 (file)
index 0000000..a77762a
--- /dev/null
@@ -0,0 +1,37 @@
+# Copyright (C) 2011-2016  CEA/DEN, 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
+#
+
+""" Test of the scalarmap. 
+
+This script is to be passed as an argument of the ./salome command and will be executed within the SALOME
+Python console.
+"""
+
+import os
+import SalomePyQt
+from medcalc_testutils import GetScenarioDir
+
+sgPyQt = SalomePyQt.SalomePyQt()
+sgPyQt.activateModule('MED')
+
+import medcalc  # After module activation !!
+medcalc.PlayQtTestingScenario(os.path.join(GetScenarioDir(), 'test_scalarmap.xml'))
+
+#medcalc.RequestTermination()
+#quit()
index f7eafee102ec355ba3eb3f2ec70c06f476ded1e8..ba1b5b810a0b39cca2b5fb8905ae433d15418bbf 100644 (file)
@@ -26,6 +26,7 @@ SET(PYFILES_TO_INSTALL
   medimages.py
   medio.py
   medpresentation.py
+  medtest.py
   )
 
 SALOME_INSTALL_SCRIPTS("${PYFILES_TO_INSTALL}" ${SALOME_INSTALL_PYTHON}/medcalc)
index 17cb536f4d7228bb86e6889d5a64e4c938967864..c8e728a69c73a318c2b423eb08ce2b4cd8cbc5b4 100644 (file)
@@ -48,3 +48,7 @@ from medpresentation import MakePointSprite
 
 # Console commands
 import medconsole
+
+# Playing test scenarii
+from medtest import PlayQtTestingScenario
+
index ac563982b7a4b35e7e6c5d1f861b0838e79087c9..c30db75b71947611fc1cb4219447fe0e10a29a3f 100644 (file)
@@ -115,3 +115,5 @@ def notifyGui_addDatasource(filename):
 def notifyGui_addPresentation(fieldId, presId):
   __notifyGui(MEDCALC.EVENT_ADD_PRESENTATION, dataId=fieldId, presentationId=presId)
 #
+def notifyGui_playQtTestingScenario(filename):
+  __notifyGui(MEDCALC.EVENT_PLAY_TEST, filename=filename)
diff --git a/src/MEDCalc/tui/medtest.py b/src/MEDCalc/tui/medtest.py
new file mode 100644 (file)
index 0000000..929dd67
--- /dev/null
@@ -0,0 +1,22 @@
+# Copyright (C) 2011-2016  CEA/DEN, 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
+#
+
+def PlayQtTestingScenario(filename):
+  from medcalc.medevents import notifyGui_playQtTestingScenario
+  notifyGui_playQtTestingScenario(filename)