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)
EVENT_CLEAN_WORKSPACE,
EVENT_ADD_DATASOURCE,
EVENT_ADD_PRESENTATION,
+ EVENT_PLAY_TEST,
+ EVENT_QUIT_SALOME,
EVENT_UNKNOWN
};
IF(SALOME_BUILD_GUI)
ADD_SUBDIRECTORY(gui)
+
+ IF(SALOME_MED_WITH_QTTESTING)
+ ADD_SUBDIRECTORY(test)
+ ENDIF()
+
ENDIF()
IF(SALOME_MED_ENABLE_PYTHON)
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
+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
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}
MEDCALC_msg_ja.ts
)
-SET(COMMON_FLAGS
+SET(link_libraries
${QT_MT_LIBRARIES}
${OMNIORB_LIBRARIES}
${PLATFORM_LIBRARIES}
${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}")
#include <QStringList>
#include <QString>
#include <QMessageBox>
+#include <QFileDialog>
#include "DlgAlias.hxx"
event->eventtype = DatasourceEvent::EVENT_ADD_DATASOURCE;
event->objectalias = filename;
emit datasourceSignal(event);
+//#ifdef MED_WITH_QTTESTING
+// _dirtyAddDataSource = true;
+// while(_dirtyAddDataSource)
+// QApplication::processEvents();
+//#endif
}
// After above data source creation, python console emits a signal, forwarded by workspace, to update the GUI
void
// update Object browser
_salomeModule->getApp()->updateObjectBrowser(true);
+
+//#ifdef MED_WITH_QTTESTING
+// _dirtyAddDataSource = false;
+//#endif
}
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();
#include "PVViewer_ViewModel.h"
#endif
+#include <QTimer>
+
#include <sstream>
//! The only instance of the reference to engine
MED_ORB::MED_Gen_var MEDModule::myEngine;
MEDModule::MEDModule() :
- SalomeApp_Module("MED"), _studyEditor(0), _datasourceController(0), _workspaceController(0), _presentationController(0), _processingController(0)
+ SalomeApp_Module("MED"), _studyEditor(0), _datasourceController(0), _workspaceController(0),
+ _presentationController(0), _processingController(0)
{
// Note also that we can't use the getApp() function here because
// the initialize(...) function has not been called yet.
}
}
+//void MEDModule::onEventLoopStarted()
+//{
+// if(!getApp()->isMainEventLoopStarted())
+// {
+// QTimer::singleShot(100, this, SLOT(onEventLoopStarted()));
+// return;
+// }
+//}
+
void
MEDModule::initialize( CAM_Application* app )
{
_presentationController->showDockWidgets(true);
//this->setDockLayout(StandardApp_Module::DOCKLAYOUT_LEFT_VLARGE);
+ // Mark the start of the main event loop - important for test playback:
+// QObject::connect(getApp(), SIGNAL(activated(SUIT_Application *)), this, SLOT(onEventLoopStarted(SUIT_Application *)));
+// QTimer::singleShot(0, this, SLOT(onEventLoopStarted()));
+
// return the activation status
return bOk;
}
_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*)));
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
_workspaceController->createActions();
_presentationController->createActions();
_processingController->createActions();
+#ifdef MED_HAS_QTTESTING
+ _testController->createActions();
+#endif
}
int
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,
STDLOG(" - Presentation name: " + name);
}
+
+void
+MEDModule::requestSALOMETermination() const
+{
+ STDLOG("Requesting SALOME termination!!");
+ SUIT_Session::session()->closeSession( SUIT_Session::DONT_SAVE, 1 ); // killServers = True
+}
+
+
+//bool MEDModule::hasMainEventLoopStarted() const
+//{
+// return _eventLoopStarted;
+//}
#include "DatasourceController.hxx"
#include "PresentationController.hxx"
#include "ProcessingController.hxx"
+#include "TestController.hxx"
#include <SALOMEconfig.h>
#include CORBA_CLIENT_HEADER(MED_Gen)
inline SALOME_AppStudyEditor* getStudyEditor() { return _studyEditor; }
+ void requestSALOMETermination() const;
+
+// bool hasMainEventLoopStarted() const;
+
public slots:
virtual bool activateModule(SUIT_Study* theStudy);
virtual bool deactivateModule(SUIT_Study* theStudy);
private:
void createModuleWidgets();
void createModuleActions();
+
static void init();
private:
XmedDataModel* _xmedDataModel;
PresentationController* _presentationController;
ProcessingController* _processingController;
+#ifdef MED_HAS_QTTESTING
+ TestController * _testController;
+#endif
static MED_ORB::MED_Gen_var myEngine;
};
</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>
--- /dev/null
+// 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>
+#include <QEvent>
+
+class PlayTestEvent: public QEvent {
+public:
+ PlayTestEvent(QEvent::Type type, const std::string & filename): QEvent(type), _filename(filename) {}
+ virtual ~PlayTestEvent() {}
+ const std::string _filename;
+};
+
+TestController::TestController(MEDModule* mod):
+ _salomeModule(mod),
+ _desk(SUIT_Session::session()->activeApplication()->desktop()),
+ _tester(0), _lock_action(0),
+ _quitEventType(QEvent::registerEventType()),
+ _playEventType(QEvent::registerEventType()),
+ _aboutToPlayTest(false)
+{
+ 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::onLockViewSize() const
+{
+ pqTestingReaction::lockViewSize(_lock_action->isChecked());
+}
+
+void TestController::onTakeSnapshot() const
+{
+ pqSaveScreenshotReaction::saveScreenshot();
+}
+
+void TestController::onRequestTermination()
+{
+ // Check if test playing
+ if (_tester->playingTest() || _aboutToPlayTest)
+ {
+ QEvent * e = new QEvent((QEvent::Type)_quitEventType);
+ QApplication::postEvent(this, e);
+ }
+ else
+ {
+ _salomeModule->requestSALOMETermination();
+ }
+}
+
+void
+TestController::customEvent(QEvent * event)
+{
+ if (event->type() == _quitEventType)
+ {
+ if(!_salomeModule->getApp()->isMainEventLoopStarted())
+ // Repost (=delay)
+ QApplication::postEvent(this, new QEvent((QEvent::Type)_quitEventType));
+ else
+ onRequestTermination();
+ }
+ else if (event->type() == _playEventType)
+ {
+ PlayTestEvent * e = dynamic_cast<PlayTestEvent *>(event);
+ if (e)
+ {
+// // Wait for main event loop to start:
+ if(!_salomeModule->getApp()->isMainEventLoopStarted())
+ // Repost (=delay)
+ QApplication::postEvent(this, new PlayTestEvent((QEvent::Type)_playEventType, e->_filename));
+ else
+ {
+ STDLOG("About to play test " << e->_filename);
+ _tester->playTests(e->_filename.c_str());
+ _aboutToPlayTest = false;
+ STDLOG("Done playing test " << e->_filename);
+ }
+ }
+ }
+ else
+ { QObject::customEvent(event); }
+}
+
+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)
+ */
+ _aboutToPlayTest = true; // to prevent an early quit!
+ PlayTestEvent * e = new PlayTestEvent((QEvent::Type)_playEventType, std::string(event->filename));
+ QApplication::postEvent(this, e);
+ }
+ else if ( event->type == MEDCALC::EVENT_QUIT_SALOME ) {
+ // [ABN] again: post as an event to give a chance to other events (piled up by test
+ // scenarios for example) to execute:
+ QEvent * e = new QEvent((QEvent::Type)_quitEventType);
+ QApplication::postEvent(this, e);
+ }
+}
+
--- /dev/null
+// 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();
+
+
+
+protected:
+ virtual void customEvent(QEvent * event);
+
+public slots:
+ void processWorkspaceEvent(const MEDCALC::MedEvent* event);
+
+ void onRecordTest();
+ void onPlayTest();
+// void onPlayTestFile();
+ void onLockViewSize() const;
+ void onTakeSnapshot() const;
+ void onRequestTermination();
+
+protected:
+ MEDModule* _salomeModule;
+ SUIT_Desktop * _desk;
+
+ pqTestUtility * _tester;
+ QAction * _lock_action;
+
+private:
+ const int _playEventType;
+ const int _quitEventType;
+
+ bool _aboutToPlayTest;
+};
+
+#endif /* SRC_MEDCALC_GUI_TESTCONTROLLER_HXX_ */
#include <SUIT_Desktop.h>
#include <SUIT_ResourceMgr.h>
+#include <QTimer>
+
/*!
* This class defines a DockWidget plugged in the SALOME application,
* and containing a tree view for rendering a hierarchical data
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
+ }
+ else if ( event->type == MEDCALC::EVENT_QUIT_SALOME ) {
+ emit workspaceSignal(event); // forward to TestController
+ }
}
/*!
void OnSaveWorkspace();
void OnCleanWorkspace();
+ void onRequestTermination();
+
signals:
void workspaceSignal(const MEDCALC::MedEvent* event);
class WidgetPresentationParameters : public QWidget
{
Q_OBJECT
+
public:
WidgetPresentationParameters(QWidget* parent = 0);
virtual ~WidgetPresentationParameters() {}
+++ /dev/null
-
-This is a simple Qt framework to test the dialog widgets.
-
-To build the project:
-* specify the sources files in the .pro file
-* run qmake, then make
-* run guiTester
-
-To clean the project:
-* run "make clean"
-* remove binary and Makefile
- $ rm guiTester Makefile
+++ /dev/null
-######################################################################
-# Automatically generated by qmake (2.01a) mer. oct. 6 14:46:48 2010
-######################################################################
-
-TEMPLATE = app
-TARGET =
-DEPENDPATH += .
-INCLUDEPATH += . ../dialogs
-
-# Input
-HEADERS += ../dialogs/DlgAlias.h
-FORMS += ../dialogs/dlgAlias.ui
-SOURCES += ../dialogs/DlgAlias.cxx ../dialogs/dlgTester.cxx
--- /dev/null
+# 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
+)
+
+SET(_test_files
+ medfiles/test_scalarmap.med
+)
+
+# Test rules - the test MEDCalcQtTesting must be run after install (since it starts SALOME)
+ADD_TEST(MEDCalcQtTesting ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_qttesting.py)
+
+# Install rules
+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)
+INSTALL(FILES ${_test_files} DESTINATION ${SALOME_MED_INSTALL_RES_DATA}/tests/medfiles)
--- /dev/null
+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.
+
+To build the project:
+* specify the sources files in the .pro file
+* run qmake, then make
+* run guiTester
+
+To clean the project:
+* run "make clean"
+* remove binary and Makefile
+ $ rm guiTester Makefile
--- /dev/null
+######################################################################
+# Automatically generated by qmake (2.01a) mer. oct. 6 14:46:48 2010
+######################################################################
+
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += . ../dialogs
+
+# Input
+HEADERS += ../dialogs/DlgAlias.h
+FORMS += ../dialogs/dlgAlias.ui
+SOURCES += ../dialogs/DlgAlias.cxx ../dialogs/dlgTester.cxx
--- /dev/null
+# 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)
+
+def GetMEDFileDir():
+ relativeDir = "@SALOME_MED_INSTALL_RES_DATA@/tests/medfiles"
+ return os.path.join(__getRootDir(), relativeDir)
+
--- /dev/null
+<?xml version="1.0" ?>
+<pqevents>
+ <pqevent object="1STD_TabDesktop0/1QMenuBar0" command="activate" arguments="Fic&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="/tmp/test_scalarmap.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&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>
--- /dev/null
+# 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, shutil
+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):
+ """ 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")
+ args = "args:%s" % self._tmpDir
+ pth = os.path.join(GetScriptDir(), scriptname)
+ # Launch SALOME with the test script:
+ status = subprocess.call([salomeCommand, pth, args])
+ if status:
+ raise Exception("SALOME exited abnormally for this test!")
+
+ def compareSnapshot(self, basename):
+ """ Compare the screenshot in the current temporary test directory with the reference baseline.
+ Assert if not matching. """
+ 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
+
+ def prepareScenario(self, scenario, baseline, med_file):
+ """ Copy scenario to current temporary test dir and substitute paths inside """
+ from medcalc_testutils import GetScenarioDir, GetMEDFileDir
+ scen_path = os.path.join(GetScenarioDir(), scenario)
+ scen_pth2 = os.path.join(self._tmpDir, scenario)
+ try:
+ shutil.copy(scen_path, scen_pth2)
+ except IOError:
+ raise Exception("Could not copy test scenario '%s' to local test directory!" % scen_path)
+ with open(scen_pth2,'r') as f:
+ filedata = f.read()
+ filedata = filedata.replace("/tmp/%s" % baseline, "%s/%s" % (self._tmpDir, baseline))
+ filedata = filedata.replace("/tmp/%s" % med_file, os.path.join(GetMEDFileDir(), med_file))
+ with open(scen_pth2,'w') as f:
+ f.write(filedata)
+
+ ##
+ ## Now the tests themselves
+ ##
+ def testScalarMap(self):
+ baseline = "test_scalarmap.png"
+ med_file = "test_scalarmap.med" # will change
+ scenario = "test_scalarmap.xml"
+ self.prepareScenario(scenario, baseline, med_file)
+ self.launchSalomeWithScript("test_scalarmap.py")
+ self.compareSnapshot(baseline)
+
+
+if __name__ == "__main__":
+ suite = unittest.TestSuite()
+ suite.addTest(MEDGUITest('testScalarMap'))
+# suite.addTest(MEDGUITest('testIsoContour'))
+ unittest.TextTestRunner().run(suite)
+
--- /dev/null
+# 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, sys
+import SalomePyQt
+from medcalc_testutils import GetScenarioDir
+
+sgPyQt = SalomePyQt.SalomePyQt()
+sgPyQt.activateModule('MED')
+
+import medcalc # After module activation !!
+localTestDir = sys.argv[1]
+medcalc.PlayQtTestingScenario(os.path.join(localTestDir, 'test_scalarmap.xml'))
+
+#medcalc.RequestSALOMETermination() # not equivalent to quit()!
medimages.py
medio.py
medpresentation.py
+ medtest.py
)
SALOME_INSTALL_SCRIPTS("${PYFILES_TO_INSTALL}" ${SALOME_INSTALL_PYTHON}/medcalc)
# Console commands
import medconsole
+
+# Playing test scenarii
+from medtest import PlayQtTestingScenario
+from medtest import RequestSALOMETermination
+
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)
+#
+def notifyGui_termination():
+ __notifyGui(MEDCALC.EVENT_QUIT_SALOME)
+
--- /dev/null
+# 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)
+
+def RequestSALOMETermination():
+ from medcalc.medevents import notifyGui_termination
+ notifyGui_termination()