Skip to content

Commit ec085bf

Browse files
author
Sandro Santilli
committed
Add unit test for QgsMapToPixel (legacy only for now)
1 parent d65a6f7 commit ec085bf

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

tests/src/core/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ ADD_QGIS_TEST(shapebursttest testqgsshapeburst.cpp )
138138
ADD_QGIS_TEST(invertedpolygontest testqgsinvertedpolygonrenderer.cpp )
139139
ADD_QGIS_TEST(colorschemeregistry testqgscolorschemeregistry.cpp)
140140
ADD_QGIS_TEST(colorscheme testqgscolorscheme.cpp)
141+
ADD_QGIS_TEST(maptopixeltest testqgsmaptopixel.cpp)
141142
ADD_QGIS_TEST(networkcontentfetcher testqgsnetworkcontentfetcher.cpp )
142143
ADD_QGIS_TEST(legendrenderertest testqgslegendrenderer.cpp )
143144
ADD_QGIS_TEST(vectorlayerjoinbuffer testqgsvectorlayerjoinbuffer.cpp )

tests/src/core/testqgsmaptopixel.cpp

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/***************************************************************************
2+
testqgsmaptopixel.cpp
3+
--------------------------------------
4+
Date : Tue 9 Dec 2014
5+
Copyright : (C) 2014 by Sandro Santilli
6+
Email : strk@keybit.net
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
#include <QtTest/QtTest>
16+
#include <QObject>
17+
#include <QString>
18+
#include <QObject>
19+
//header for class being tested
20+
#include <qgsrectangle.h>
21+
#include <qgsmaptopixel.h>
22+
#include <qgspoint.h>
23+
#include "qgslogger.h"
24+
25+
class TestQgsMapToPixel: public QObject
26+
{
27+
Q_OBJECT
28+
private slots:
29+
void legacy();
30+
};
31+
32+
void TestQgsMapToPixel::legacy()
33+
{
34+
QgsMapToPixel m2p(2,10,-4,3);
35+
36+
QgsPoint p(0,0); // in geographical units
37+
QgsPoint d = m2p.transform(p); // to device pixels
38+
QCOMPARE( d.x(), -1.5 );
39+
QCOMPARE( d.y(), 8.0 );
40+
41+
QgsPoint b = m2p.toMapCoordinatesF( d.x(), d.y() ); // transform back
42+
QCOMPARE( p, b );
43+
44+
m2p.transform(&p); // in place transform
45+
QCOMPARE( p, d );
46+
47+
m2p.setParameters(0.2, -10, 7, 20);
48+
p = m2p.toMapCoordinates( -1, -1 );
49+
QCOMPARE( p.x(), -10.2 );
50+
QCOMPARE( p.y(), 11.2 );
51+
d = m2p.transform(p);
52+
QCOMPARE( d, QgsPoint(-1, -1) );
53+
54+
p = m2p.toMapCoordinates( 20, 20 );
55+
QCOMPARE( p.x(), -6.0 );
56+
QCOMPARE( p.y(), 7.0 );
57+
d = m2p.transform(p);
58+
QCOMPARE( d, QgsPoint(20, 20) );
59+
60+
};
61+
62+
QTEST_MAIN( TestQgsMapToPixel )
63+
#include "testqgsmaptopixel.moc"
64+
65+
66+
67+

0 commit comments

Comments
 (0)