From: asl Date: Wed, 20 Sep 2017 13:45:25 +0000 (+0300) Subject: refs #1322: automatic tests for zoom in graphics view X-Git-Tag: v2.1~66^2~32 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f78019efb924f06dbe2fc7f8a36b7f5b44dfede9;p=modules%2Fhydro.git refs #1322: automatic tests for zoom in graphics view --- diff --git a/src/HYDRO_tests/CMakeLists.txt b/src/HYDRO_tests/CMakeLists.txt index 20f22d15..b6ec22e2 100644 --- a/src/HYDRO_tests/CMakeLists.txt +++ b/src/HYDRO_tests/CMakeLists.txt @@ -25,6 +25,7 @@ set(PROJECT_HEADERS test_Dependencies.h test_HYDROData_DTM.h + test_GraphicsView.h TestShape.h TestViewer.h @@ -54,6 +55,7 @@ set(PROJECT_SOURCES test_HYDROData_Stream.cxx test_Dependencies.cxx test_HYDROData_Tool.cxx + test_GraphicsView.cxx TestShape.cxx TestViewer.cxx diff --git a/src/HYDRO_tests/reference_data/CMakeLists.txt b/src/HYDRO_tests/reference_data/CMakeLists.txt index 021ee7f6..dd4f5c16 100644 --- a/src/HYDRO_tests/reference_data/CMakeLists.txt +++ b/src/HYDRO_tests/reference_data/CMakeLists.txt @@ -120,6 +120,10 @@ SET(REFERENCE_DATA pb_1066.cbf f_cmp.brep rebuild_cmp_out.png + garonne.png + gv_fitall.png + gv_zoomed_1.png + gv_zoomed_2.png ) # Application tests diff --git a/src/HYDRO_tests/reference_data/garonne.png b/src/HYDRO_tests/reference_data/garonne.png new file mode 100644 index 00000000..2f652f6a Binary files /dev/null and b/src/HYDRO_tests/reference_data/garonne.png differ diff --git a/src/HYDRO_tests/reference_data/gv_fitall.png b/src/HYDRO_tests/reference_data/gv_fitall.png new file mode 100644 index 00000000..64b1d7bc Binary files /dev/null and b/src/HYDRO_tests/reference_data/gv_fitall.png differ diff --git a/src/HYDRO_tests/reference_data/gv_zoomed_1.png b/src/HYDRO_tests/reference_data/gv_zoomed_1.png new file mode 100644 index 00000000..7d100270 Binary files /dev/null and b/src/HYDRO_tests/reference_data/gv_zoomed_1.png differ diff --git a/src/HYDRO_tests/reference_data/gv_zoomed_2.png b/src/HYDRO_tests/reference_data/gv_zoomed_2.png new file mode 100644 index 00000000..b892b218 Binary files /dev/null and b/src/HYDRO_tests/reference_data/gv_zoomed_2.png differ diff --git a/src/HYDRO_tests/test_GraphicsView.cxx b/src/HYDRO_tests/test_GraphicsView.cxx new file mode 100644 index 00000000..74d98977 --- /dev/null +++ b/src/HYDRO_tests/test_GraphicsView.cxx @@ -0,0 +1,121 @@ +// 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern QString REF_DATA_PATH; + +class TestObject : public GraphicsView_Object +{ +public: + TestObject(); + virtual ~TestObject(); + + virtual void compute(); + virtual QRectF getRect() const; + virtual QRectF boundingRect() const; + +private: + QGraphicsPixmapItem* myItem; +}; + + +TestObject::TestObject() + : myItem( 0 ) +{ + compute(); +} + +TestObject::~TestObject() +{ +} + +void TestObject::compute() +{ + QPixmap image( REF_DATA_PATH + "/garonne.png" ); + myItem = new QGraphicsPixmapItem( image ); + addToGroup( myItem ); +} + +QRectF TestObject::getRect() const +{ + return QRectF( 0, 0, 400, 300 ); +} + +QRectF TestObject::boundingRect() const +{ + if( myItem ) + return myItem->boundingRect(); + else + return QRectF(); +} + + + +#define CPPUNIT_ASSERT_VIEW( theCase ) \ + { \ + qApp->processEvents(); \ + QImage im = aViewPort->dumpView(); \ + CPPUNIT_ASSERT_IMAGES2( &im, theCase ); \ + } + +void test_GraphicsView::test_wheel_zoom() +{ + GraphicsView_ViewManager* aViewManager = new GraphicsView_ViewManager( 0, 0 ); + GraphicsView_Viewer* aViewer = new GraphicsView_Viewer( "test", 0 ); + + aViewManager->setViewModel( aViewer ); + GraphicsView_ViewFrame* aWindow = dynamic_cast( aViewManager->createViewWindow() ); + aWindow->setGeometry( 100, 100, 600, 450 ); + aWindow->show(); + + qApp->processEvents(); + + // 1. Initialize presentation + GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort(); + aViewPort->setInteractionFlag( GraphicsView_ViewPort::GlobalWheelScaling ); + // This is necessary to activate wheeling zoom + + TestObject* obj = new TestObject(); + aViewPort->addItem( obj ); + aViewPort->fitAll(); + CPPUNIT_ASSERT_VIEW( "gv_fitall" ); + + // 2. Mouse wheel zoom + QWheelEvent we1( QPoint( 10, 10 ), 120*10, Qt::NoButton, Qt::NoModifier ); + qApp->sendEvent( aViewPort->viewport(), &we1 ); + CPPUNIT_ASSERT_VIEW( "gv_zoomed_1" ); + + //QTest::qWait( 50000 ); + + QWheelEvent we2( QPoint( 650, 500 ), 120*10, Qt::NoButton, Qt::NoModifier ); + qApp->sendEvent( aViewPort->viewport(), &we2 ); + CPPUNIT_ASSERT_VIEW( "gv_zoomed_2" ); + + //QTest::qWait( 50000 ); +} diff --git a/src/HYDRO_tests/test_GraphicsView.h b/src/HYDRO_tests/test_GraphicsView.h new file mode 100644 index 00000000..a609d758 --- /dev/null +++ b/src/HYDRO_tests/test_GraphicsView.h @@ -0,0 +1,40 @@ +// 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 +// + +#ifdef WIN32 + #pragma warning( disable: 4251 ) +#endif + +#include + +class test_GraphicsView : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( test_GraphicsView ); + CPPUNIT_TEST( test_wheel_zoom ); + CPPUNIT_TEST_SUITE_END(); + +public: + void test_wheel_zoom(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( test_GraphicsView ); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( test_GraphicsView, "GraphicsView" ); + +#ifdef WIN32 + #pragma warning( default: 4251 ) +#endif