]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #1322: automatic tests for zoom in graphics view
authorasl <asl@opencascade.com>
Wed, 20 Sep 2017 13:45:25 +0000 (16:45 +0300)
committerasl <asl@opencascade.com>
Wed, 20 Sep 2017 13:45:25 +0000 (16:45 +0300)
src/HYDRO_tests/CMakeLists.txt
src/HYDRO_tests/reference_data/CMakeLists.txt
src/HYDRO_tests/reference_data/garonne.png [new file with mode: 0644]
src/HYDRO_tests/reference_data/gv_fitall.png [new file with mode: 0644]
src/HYDRO_tests/reference_data/gv_zoomed_1.png [new file with mode: 0644]
src/HYDRO_tests/reference_data/gv_zoomed_2.png [new file with mode: 0644]
src/HYDRO_tests/test_GraphicsView.cxx [new file with mode: 0644]
src/HYDRO_tests/test_GraphicsView.h [new file with mode: 0644]

index 20f22d15f8a23d3f468db107e7ca36c4525efd31..b6ec22e247d5f0a0a524dd5e668520eb5c071adc 100644 (file)
@@ -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
index 021ee7f6b4d234ec511eb7d819814c59f0343b48..dd4f5c16697c3cf195d89fdd38cb882e67c275f0 100644 (file)
@@ -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 (file)
index 0000000..2f652f6
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 (file)
index 0000000..64b1d7b
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 (file)
index 0000000..7d10027
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 (file)
index 0000000..b892b21
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 (file)
index 0000000..74d9897
--- /dev/null
@@ -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 <test_GraphicsView.h>
+#include <GraphicsView_ViewManager.h>
+#include <GraphicsView_Viewer.h>
+#include <GraphicsView_ViewFrame.h>
+#include <GraphicsView_ViewPort.h>
+#include <GraphicsView_Object.h>
+#include <GraphicsView_Scene.h>
+#include <QTest>
+#include <QGraphicsPixmapItem>
+#include <QGraphicsSceneWheelEvent>
+#include <TestViewer.h>
+
+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<GraphicsView_ViewFrame*>( 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 (file)
index 0000000..a609d75
--- /dev/null
@@ -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 <cppunit/extensions/HelperMacros.h>
+
+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