Skip to content

Commit

Permalink
Merge pull request #2892 from SebDieBln/Test_CanvasPanByKeyboard
Browse files Browse the repository at this point in the history
added a test for panning the canvas by keyboard
  • Loading branch information
Sandro Santilli committed Mar 11, 2016
2 parents 145f246 + 4c88fc0 commit 73caf35
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/src/gui/testqgsmapcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class TestQgsMapCanvas : public QObject
void cleanupTestCase(); // will be called after the last testfunction was executed.

void testMapRendererInteraction();
void testPanByKeyboard();

private:
QgsMapCanvas* mCanvas;
Expand Down Expand Up @@ -124,6 +125,33 @@ void TestQgsMapCanvas::testMapRendererInteraction()
// TODO: set map units
}

void TestQgsMapCanvas::testPanByKeyboard()
{
// The keys to simulate
QList<Qt::Key> keys = QList<Qt::Key>() << Qt::Key_Left << Qt::Key_Down << Qt::Key_Right << Qt::Key_Up;

// The canvas rotations to test
QList<double> rotations = QList<double>() << 0.0 << 30.0;

QgsRectangle initialExtent( 100, 100, 110, 110 );

Q_FOREACH ( double rotation, rotations )
{
// Set rotation and initial extent
mCanvas->setRotation( rotation );
mCanvas->setExtent( initialExtent );

// Save actual extent, simulate panning by keyboard and verify the extent is unchanged
QgsRectangle originalExtent = mCanvas->extent();
Q_FOREACH ( Qt::Key key, keys )
{
QKeyEvent keyEvent( QEvent::KeyPress, key, Qt::NoModifier );
QApplication::sendEvent( mCanvas, &keyEvent );

This comment has been minimized.

Copy link
@3nids

3nids Mar 11, 2016

Member

isn't it worth adding QVERIFY( mCanvas->extent() != originalExtent );here?

}
QVERIFY( mCanvas->extent() == originalExtent );
}
}


QTEST_MAIN( TestQgsMapCanvas )
#include "testqgsmapcanvas.moc"

0 comments on commit 73caf35

Please sign in to comment.