From d3c583650bcc9d95c88d904800a481ede33049d4 Mon Sep 17 00:00:00 2001 From: abn Date: Thu, 7 Apr 2016 11:29:00 +0200 Subject: [PATCH] First draft of a possible GUI testing framework. Still work todo: - pass directory where snapshot should be saved as an arg - automatically quit SALOME GUI with a proper event. --- CMakeLists.txt | 1 + idl/MEDEventListener.idl | 1 + src/MEDCalc/gui/CMakeLists.txt | 35 +++- src/MEDCalc/gui/DatasourceController.cxx | 12 +- src/MEDCalc/gui/MEDModule.cxx | 25 ++- src/MEDCalc/gui/MEDModule.hxx | 6 + src/MEDCalc/gui/MED_msg_fr.ts | 2 +- src/MEDCalc/gui/TestController.cxx | 151 ++++++++++++++++++ src/MEDCalc/gui/TestController.hxx | 61 +++++++ src/MEDCalc/gui/WorkspaceController.cxx | 3 + .../dialogs/WidgetPresentationParameters.hxx | 1 + src/MEDCalc/gui/test/CMakeLists.txt | 39 +++++ src/MEDCalc/gui/test/README.txt | 13 ++ .../gui/test/baselines/test_scalarmap.png | Bin 0 -> 3032 bytes src/MEDCalc/gui/test/medcalc_testutils.py.in | 36 +++++ .../gui/test/scenarios/test_scalarmap.xml | 20 +++ src/MEDCalc/gui/test/test_qttesting.py | 99 ++++++++++++ src/MEDCalc/gui/test/test_scalarmap.py | 37 +++++ src/MEDCalc/tui/CMakeLists.txt | 1 + src/MEDCalc/tui/__init__.py | 4 + src/MEDCalc/tui/medevents.py | 2 + src/MEDCalc/tui/medtest.py | 22 +++ 22 files changed, 562 insertions(+), 9 deletions(-) create mode 100644 src/MEDCalc/gui/TestController.cxx create mode 100644 src/MEDCalc/gui/TestController.hxx create mode 100644 src/MEDCalc/gui/test/CMakeLists.txt create mode 100644 src/MEDCalc/gui/test/baselines/test_scalarmap.png create mode 100644 src/MEDCalc/gui/test/medcalc_testutils.py.in create mode 100644 src/MEDCalc/gui/test/scenarios/test_scalarmap.xml create mode 100644 src/MEDCalc/gui/test/test_qttesting.py create mode 100644 src/MEDCalc/gui/test/test_scalarmap.py create mode 100644 src/MEDCalc/tui/medtest.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 54fbb953f..bfdcca99c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/idl/MEDEventListener.idl b/idl/MEDEventListener.idl index 1181a6e16..425238772 100644 --- a/idl/MEDEventListener.idl +++ b/idl/MEDEventListener.idl @@ -34,6 +34,7 @@ module MEDCALC EVENT_CLEAN_WORKSPACE, EVENT_ADD_DATASOURCE, EVENT_ADD_PRESENTATION, + EVENT_PLAY_TEST, EVENT_UNKNOWN }; diff --git a/src/MEDCalc/gui/CMakeLists.txt b/src/MEDCalc/gui/CMakeLists.txt index b51c1432b..f53d45075 100644 --- a/src/MEDCalc/gui/CMakeLists.txt +++ b/src/MEDCalc/gui/CMakeLists.txt @@ -17,14 +17,33 @@ # 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}") diff --git a/src/MEDCalc/gui/DatasourceController.cxx b/src/MEDCalc/gui/DatasourceController.cxx index a3f7cd0be..31a82b48b 100644 --- a/src/MEDCalc/gui/DatasourceController.cxx +++ b/src/MEDCalc/gui/DatasourceController.cxx @@ -45,6 +45,7 @@ #include #include #include +#include #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(); diff --git a/src/MEDCalc/gui/MEDModule.cxx b/src/MEDCalc/gui/MEDModule.cxx index c40bbe231..b16f71dd2 100644 --- a/src/MEDCalc/gui/MEDModule.cxx +++ b/src/MEDCalc/gui/MEDModule.cxx @@ -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) +{ + +} diff --git a/src/MEDCalc/gui/MEDModule.hxx b/src/MEDCalc/gui/MEDModule.hxx index f05d6616e..819fd80b1 100644 --- a/src/MEDCalc/gui/MEDModule.hxx +++ b/src/MEDCalc/gui/MEDModule.hxx @@ -32,6 +32,7 @@ #include "DatasourceController.hxx" #include "PresentationController.hxx" #include "ProcessingController.hxx" +#include "TestController.hxx" #include #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; }; diff --git a/src/MEDCalc/gui/MED_msg_fr.ts b/src/MEDCalc/gui/MED_msg_fr.ts index f09dc6717..7481ad5a8 100644 --- a/src/MEDCalc/gui/MED_msg_fr.ts +++ b/src/MEDCalc/gui/MED_msg_fr.ts @@ -205,7 +205,7 @@ LAB_BLUE_TO_RED - Arc-en-ciel blue vers rouge + Arc-en-ciel bleu vers rouge LAB_COOL_TO_WARM diff --git a/src/MEDCalc/gui/TestController.cxx b/src/MEDCalc/gui/TestController.cxx new file mode 100644 index 000000000..8023c6816 --- /dev/null +++ b/src/MEDCalc/gui/TestController.cxx @@ -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 // STDLOG() macro + +#include +#include + +#include +#include CORBA_CLIENT_HEADER(MEDEventListener) + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +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 index 000000000..5febf5275 --- /dev/null +++ b/src/MEDCalc/gui/TestController.hxx @@ -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 +#include + +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_ */ diff --git a/src/MEDCalc/gui/WorkspaceController.cxx b/src/MEDCalc/gui/WorkspaceController.cxx index cfb1b506e..8b2c6a2fd 100644 --- a/src/MEDCalc/gui/WorkspaceController.cxx +++ b/src/MEDCalc/gui/WorkspaceController.cxx @@ -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 + } } diff --git a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx index 0f8815759..7187e2ee6 100644 --- a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx +++ b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx @@ -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 index 000000000..0df51419e --- /dev/null +++ b/src/MEDCalc/gui/test/CMakeLists.txt @@ -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) diff --git a/src/MEDCalc/gui/test/README.txt b/src/MEDCalc/gui/test/README.txt index 751cbf465..ad68b0df1 100644 --- a/src/MEDCalc/gui/test/README.txt +++ b/src/MEDCalc/gui/test/README.txt @@ -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 index 0000000000000000000000000000000000000000..3e827f42a70d6bc4f56ea44a97cc4b2453c00ea3 GIT binary patch literal 3032 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 literal 0 HcmV?d00001 diff --git a/src/MEDCalc/gui/test/medcalc_testutils.py.in b/src/MEDCalc/gui/test/medcalc_testutils.py.in new file mode 100644 index 000000000..59880a57f --- /dev/null +++ b/src/MEDCalc/gui/test/medcalc_testutils.py.in @@ -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 index 000000000..edbc38fb4 --- /dev/null +++ b/src/MEDCalc/gui/test/scenarios/test_scalarmap.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/MEDCalc/gui/test/test_qttesting.py b/src/MEDCalc/gui/test/test_qttesting.py new file mode 100644 index 000000000..123812b8e --- /dev/null +++ b/src/MEDCalc/gui/test/test_qttesting.py @@ -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 index 000000000..a77762a27 --- /dev/null +++ b/src/MEDCalc/gui/test/test_scalarmap.py @@ -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() diff --git a/src/MEDCalc/tui/CMakeLists.txt b/src/MEDCalc/tui/CMakeLists.txt index f7eafee10..ba1b5b810 100644 --- a/src/MEDCalc/tui/CMakeLists.txt +++ b/src/MEDCalc/tui/CMakeLists.txt @@ -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) diff --git a/src/MEDCalc/tui/__init__.py b/src/MEDCalc/tui/__init__.py index 17cb536f4..c8e728a69 100644 --- a/src/MEDCalc/tui/__init__.py +++ b/src/MEDCalc/tui/__init__.py @@ -48,3 +48,7 @@ from medpresentation import MakePointSprite # Console commands import medconsole + +# Playing test scenarii +from medtest import PlayQtTestingScenario + diff --git a/src/MEDCalc/tui/medevents.py b/src/MEDCalc/tui/medevents.py index ac563982b..c30db75b7 100644 --- a/src/MEDCalc/tui/medevents.py +++ b/src/MEDCalc/tui/medevents.py @@ -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 index 000000000..929dd67e8 --- /dev/null +++ b/src/MEDCalc/tui/medtest.py @@ -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) -- 2.39.2