From: asl Date: Thu, 28 Sep 2017 06:20:00 +0000 (+0300) Subject: refs #1332: first automatic test on profiles dialog size X-Git-Tag: v2.1~66^2~12^2~3^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5ee99b059fc03388b419fc8020f58212fcd9a47c;p=modules%2Fhydro.git refs #1332: first automatic test on profiles dialog size --- diff --git a/src/HYDROGUI/HYDROGUI_ProfileDlg.cxx b/src/HYDROGUI/HYDROGUI_ProfileDlg.cxx index 5b724bbd..81cb8239 100644 --- a/src/HYDROGUI/HYDROGUI_ProfileDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ProfileDlg.cxx @@ -90,14 +90,18 @@ HYDROGUI_ProfileDlg::HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QStr sizes.append( 25 ); splitter()->setSizes( sizes ); +#ifndef TEST_MODE QSettings settings; splitter()->restoreState( settings.value( splitter_key ).toByteArray() ); +#endif } HYDROGUI_ProfileDlg::~HYDROGUI_ProfileDlg() { +#ifndef TEST_MODE QSettings settings; settings.setValue( splitter_key, splitter()->saveState() ); +#endif } void HYDROGUI_ProfileDlg::reset() diff --git a/src/HYDROGUI/HYDROGUI_ViewerDlg.cxx b/src/HYDROGUI/HYDROGUI_ViewerDlg.cxx index 4465443d..f82ae06e 100644 --- a/src/HYDROGUI/HYDROGUI_ViewerDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ViewerDlg.cxx @@ -47,7 +47,9 @@ HYDROGUI_ViewerDlg::HYDROGUI_ViewerDlg( HYDROGUI_Module* theModule, const QStrin : HYDROGUI_InputPanel( theModule, theTitle, true, isSplitter ) { SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - myViewManager = new OCCViewer_ViewManager( theModule->getApp()->activeStudy(), 0 ); + SUIT_Study* aStudy = theModule ? theModule->getApp()->activeStudy() : 0; + + myViewManager = new OCCViewer_ViewManager( aStudy, 0 ); OCCViewer_Viewer* aViewer = new OCCViewer_Viewer( true ); aViewer->setBackground( OCCViewer_ViewFrame::TOP_LEFT, diff --git a/src/HYDRO_tests/CMakeLists.txt b/src/HYDRO_tests/CMakeLists.txt index b6ec22e2..dcd654ff 100644 --- a/src/HYDRO_tests/CMakeLists.txt +++ b/src/HYDRO_tests/CMakeLists.txt @@ -56,6 +56,7 @@ set(PROJECT_SOURCES test_Dependencies.cxx test_HYDROData_Tool.cxx test_GraphicsView.cxx + test_HYDROGUI_ProfilesDlg.cxx TestShape.cxx TestViewer.cxx @@ -63,7 +64,7 @@ set(PROJECT_SOURCES TestLib_Runner.cxx ) -add_definitions( -DLIGHT_MODE -DHYDRODATA_STATIC -DHYDROGUI_STATIC ) +add_definitions( -DLIGHT_MODE -DHYDRODATA_STATIC -DHYDROGUI_STATIC -DTEST_MODE) IF( ${WIN32} ) add_definitions( -DWNT -D__WIN32__ -D__x86__ -D_WIN64 -D_WIN32_WINNT=0x0400 -D__NT__ -D__OSVERSION__=4 ) diff --git a/src/HYDRO_tests/ExternalFiles.cmake b/src/HYDRO_tests/ExternalFiles.cmake index b093912a..5a5af45f 100644 --- a/src/HYDRO_tests/ExternalFiles.cmake +++ b/src/HYDRO_tests/ExternalFiles.cmake @@ -77,6 +77,9 @@ set( EXTERNAL_FILES ../HYDROGUI/HYDROGUI_StreamDlg.cxx ../HYDROGUI/HYDROGUI_ListSelector.cxx ../HYDROGUI/HYDROGUI_OrderedListWidget.cxx + ../HYDROGUI/HYDROGUI_ProfileDlg.cxx + ../HYDROGUI/HYDROGUI_ViewerDlg.cxx + ../HYDROGUI/HYDROGUI_AISTrihedron.cxx ) set( MOC_HEADERS @@ -85,6 +88,8 @@ set( MOC_HEADERS ../HYDROGUI/HYDROGUI_StreamDlg.h ../HYDROGUI/HYDROGUI_ListSelector.h ../HYDROGUI/HYDROGUI_OrderedListWidget.h + ../HYDROGUI/HYDROGUI_ProfileDlg.h + ../HYDROGUI/HYDROGUI_ViewerDlg.h ) QT_WRAP_MOC( PROJECT_MOC_HEADERS ${MOC_HEADERS} ) diff --git a/src/HYDRO_tests/TestViewer.cxx b/src/HYDRO_tests/TestViewer.cxx index 34763265..f7876baa 100644 --- a/src/HYDRO_tests/TestViewer.cxx +++ b/src/HYDRO_tests/TestViewer.cxx @@ -266,7 +266,7 @@ bool AreImagesEqual( const QImage& theImage1, const QImage& theImage2, double th return true; } -bool TestViewer::AssertImages( QString& theMessage, const QImage* theImage, const char* theCase ) +bool TestViewer::AssertImages( QString& theMessage, const QImage* theImage, const char* theCase, bool swapRGB ) { QImage anActualImage; if( theImage ) @@ -274,8 +274,7 @@ bool TestViewer::AssertImages( QString& theMessage, const QImage* theImage, cons else anActualImage = viewWindow()->dumpView(); - const bool SWAP_RGB_ORDER = true; - if( SWAP_RGB_ORDER ) + if( swapRGB ) { // A temporary patch for bug in SALOME/OCC dump; the result image contains swapped RGB colors anActualImage = anActualImage.rgbSwapped(); diff --git a/src/HYDRO_tests/TestViewer.h b/src/HYDRO_tests/TestViewer.h index 90aac840..7bfe1a84 100644 --- a/src/HYDRO_tests/TestViewer.h +++ b/src/HYDRO_tests/TestViewer.h @@ -45,7 +45,7 @@ public: int theUIANb = 10, int theVIANb = 10); static void show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const char* theKey, int theUIANb = 10, int theVIANb = 10); - static bool AssertImages( QString& theMessage, const QImage* = 0, const char* theCase = 0 ); + static bool AssertImages( QString& theMessage, const QImage* = 0, const char* theCase = 0, bool swapRGB = true ); static QColor GetColor(int i); static Handle(AIS_ColorScale) colorScale(); diff --git a/src/HYDRO_tests/reference_data/CMakeLists.txt b/src/HYDRO_tests/reference_data/CMakeLists.txt index dd4f5c16..41dd3c0e 100644 --- a/src/HYDRO_tests/reference_data/CMakeLists.txt +++ b/src/HYDRO_tests/reference_data/CMakeLists.txt @@ -124,6 +124,7 @@ SET(REFERENCE_DATA gv_fitall.png gv_zoomed_1.png gv_zoomed_2.png + profiles_dlg_presentation.png ) # Application tests diff --git a/src/HYDRO_tests/reference_data/profiles_dlg_presentation.png b/src/HYDRO_tests/reference_data/profiles_dlg_presentation.png new file mode 100644 index 00000000..f5483cf6 Binary files /dev/null and b/src/HYDRO_tests/reference_data/profiles_dlg_presentation.png differ diff --git a/src/HYDRO_tests/test_HYDROGUI_ProfilesDlg.cxx b/src/HYDRO_tests/test_HYDROGUI_ProfilesDlg.cxx new file mode 100644 index 00000000..fb2cc843 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROGUI_ProfilesDlg.cxx @@ -0,0 +1,52 @@ +// Copyright (C) 2014-2015 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 +// + +#undef HYDROGUI_EXPORTS + +#include +#include +#include +#include +#include + +#define CPPUNIT_ASSERT_WIDGET( theWidget, theCase ) \ + { \ + QPixmap aPixmap = QPixmap::grabWindow( theWidget->winId() ); \ + QImage anImage = aPixmap.toImage(); \ + QString aMessage; \ + if( !TestViewer::AssertImages( aMessage, &anImage, theCase, false ) ) \ + { \ + TestViewer::showColorScale( false ); \ + std::string aMessageStl = aMessage.toStdString(); \ + CPPUNIT_FAIL( aMessageStl.c_str() ); \ + } \ + } \ + + +void test_HYDROGUI_ProfilesDlg::test_default_size() +{ + HYDROGUI_ProfileDlg* dlg = new HYDROGUI_ProfileDlg( 0, "test" ); + dlg->resize( 320, 640 ); + dlg->show(); + QTest::qWaitForWindowExposed( dlg ); + + CPPUNIT_ASSERT_WIDGET( dlg, "profiles_dlg_presentation" ); + + dlg->deleteLater(); + qApp->processEvents(); +} diff --git a/src/HYDRO_tests/test_HYDROGUI_ProfilesDlg.h b/src/HYDRO_tests/test_HYDROGUI_ProfilesDlg.h new file mode 100644 index 00000000..0c40ecfe --- /dev/null +++ b/src/HYDRO_tests/test_HYDROGUI_ProfilesDlg.h @@ -0,0 +1,32 @@ +// Copyright (C) 2014-2015 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 + +class test_HYDROGUI_ProfilesDlg : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(test_HYDROGUI_ProfilesDlg); + CPPUNIT_TEST(test_default_size); + CPPUNIT_TEST_SUITE_END(); + +public: + void test_default_size(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROGUI_ProfilesDlg); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROGUI_ProfilesDlg, "HYDROGUI_ProfilesDlg");