Skip to content

Commit e95a8a9

Browse files
committedJun 29, 2016
Followup 172953, add unit tests
1 parent 1729531 commit e95a8a9

File tree

2 files changed

+46
-32
lines changed

2 files changed

+46
-32
lines changed
 

‎src/core/qgstestutils.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
* @note added in QGIS 2.16
2424
*/
2525

26-
#define QGSCOMPARENEAR(a,b,epsilon) { \
27-
bool _xxxresult = qgsDoubleNear( a, b, epsilon ); \
26+
#define QGSCOMPARENEAR(value,expected,epsilon) { \
27+
bool _xxxresult = qgsDoubleNear( value, expected, epsilon ); \
2828
if ( !_xxxresult ) \
2929
{ \
30-
qDebug( "Expecting %f got %f (diff %f > %f)", static_cast< double >( a ), static_cast< double >( b ), qAbs( static_cast< double >( a ) - b ), static_cast< double >( epsilon ) ); \
30+
qDebug( "Expecting %f got %f (diff %f > %f)", static_cast< double >( expected ), static_cast< double >( value ), qAbs( static_cast< double >( expected ) - value ), static_cast< double >( epsilon ) ); \
3131
} \
32-
QVERIFY( qgsDoubleNear( a, b, epsilon ) ); \
32+
QVERIFY( qgsDoubleNear( value, expected, epsilon ) ); \
3333
}
3434

3535

‎tests/src/core/testqgsgeometry.cpp

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "qgscircularstringv2.h"
3737
#include "qgsgeometrycollectionv2.h"
3838
#include "qgsgeometryfactory.h"
39+
#include "qgstestutils.h"
3940

4041
//qgs unit test utility class
4142
#include "qgsrenderchecker.h"
@@ -600,19 +601,24 @@ void TestQgsGeometry::pointV2()
600601
QgsCoordinateReferenceSystem sourceSrs;
601602
sourceSrs.createFromSrid( 3994 );
602603
QgsCoordinateReferenceSystem destSrs;
603-
destSrs.createFromSrid( 4326 );
604+
destSrs.createFromSrid( 4202 ); // want a transform with ellipsoid change
604605
QgsCoordinateTransform tr( sourceSrs, destSrs );
605606
QgsPointV2 p16( QgsWKBTypes::PointZM, 6374985, -3626584, 1, 2 );
606607
p16.transform( tr, QgsCoordinateTransform::ForwardTransform );
607-
QVERIFY( qgsDoubleNear( p16.x(), 175.771, 0.001 ) );
608-
QVERIFY( qgsDoubleNear( p16.y(), -39.722, 0.001 ) );
609-
QVERIFY( qgsDoubleNear( p16.z(), 1.0, 0.001 ) );
608+
QGSCOMPARENEAR( p16.x(), 175.771, 0.001 );
609+
QGSCOMPARENEAR( p16.y(), -39.724, 0.001 );
610+
QGSCOMPARENEAR( p16.z(), 1.0, 0.001 );
610611
QCOMPARE( p16.m(), 2.0 );
611612
p16.transform( tr, QgsCoordinateTransform::ReverseTransform );
612-
QVERIFY( qgsDoubleNear( p16.x(), 6374985, 1 ) );
613-
QVERIFY( qgsDoubleNear( p16.y(), -3626584, 1 ) );
614-
QVERIFY( qgsDoubleNear( p16.z(), 1.0, 0.001 ) );
613+
QGSCOMPARENEAR( p16.x(), 6374985, 1 );
614+
QGSCOMPARENEAR( p16.y(), -3626584, 1 );
615+
QGSCOMPARENEAR( p16.z(), 1.0, 0.001 );
615616
QCOMPARE( p16.m(), 2.0 );
617+
//test with z transform
618+
p16.transform( tr, QgsCoordinateTransform::ForwardTransform, true );
619+
QGSCOMPARENEAR( p16.z(), -19.249, 0.001 );
620+
p16.transform( tr, QgsCoordinateTransform::ReverseTransform, true );
621+
QGSCOMPARENEAR( p16.z(), 1.0, 0.001 );
616622

617623
//QTransform transform
618624
QTransform qtr = QTransform::fromScale( 2, 3 );
@@ -1467,48 +1473,56 @@ void TestQgsGeometry::lineStringV2()
14671473
QgsCoordinateReferenceSystem sourceSrs;
14681474
sourceSrs.createFromSrid( 3994 );
14691475
QgsCoordinateReferenceSystem destSrs;
1470-
destSrs.createFromSrid( 4326 );
1476+
destSrs.createFromSrid( 4202 ); // want a transform with ellipsoid change
14711477
QgsCoordinateTransform tr( sourceSrs, destSrs );
14721478

14731479
// 2d CRS transform
14741480
QgsLineStringV2 l21;
14751481
l21.setPoints( QgsPointSequenceV2() << QgsPointV2( 6374985, -3626584 )
14761482
<< QgsPointV2( 6474985, -3526584 ) );
14771483
l21.transform( tr, QgsCoordinateTransform::ForwardTransform );
1478-
QVERIFY( qgsDoubleNear( l21.pointN( 0 ).x(), 175.771, 0.001 ) );
1479-
QVERIFY( qgsDoubleNear( l21.pointN( 0 ).y(), -39.722, 0.001 ) );
1480-
QVERIFY( qgsDoubleNear( l21.pointN( 1 ).x(), 176.959, 0.001 ) );
1481-
QVERIFY( qgsDoubleNear( l21.pointN( 1 ).y(), -38.798, 0.001 ) );
1482-
QVERIFY( qgsDoubleNear( l21.boundingBox().xMinimum(), 175.771, 0.001 ) );
1483-
QVERIFY( qgsDoubleNear( l21.boundingBox().yMinimum(), -39.722, 0.001 ) );
1484-
QVERIFY( qgsDoubleNear( l21.boundingBox().xMaximum(), 176.959, 0.001 ) );
1485-
QVERIFY( qgsDoubleNear( l21.boundingBox().yMaximum(), -38.798, 0.001 ) );
1484+
QGSCOMPARENEAR( l21.pointN( 0 ).x(), 175.771, 0.001 );
1485+
QGSCOMPARENEAR( l21.pointN( 0 ).y(), -39.724, 0.001 );
1486+
QGSCOMPARENEAR( l21.pointN( 1 ).x(), 176.959, 0.001 );
1487+
QGSCOMPARENEAR( l21.pointN( 1 ).y(), -38.7999, 0.001 );
1488+
QGSCOMPARENEAR( l21.boundingBox().xMinimum(), 175.771, 0.001 );
1489+
QGSCOMPARENEAR( l21.boundingBox().yMinimum(), -39.724, 0.001 );
1490+
QGSCOMPARENEAR( l21.boundingBox().xMaximum(), 176.959, 0.001 );
1491+
QGSCOMPARENEAR( l21.boundingBox().yMaximum(), -38.7999, 0.001 );
14861492

14871493
//3d CRS transform
14881494
QgsLineStringV2 l22;
14891495
l22.setPoints( QgsPointSequenceV2() << QgsPointV2( QgsWKBTypes::PointZM, 6374985, -3626584, 1, 2 )
14901496
<< QgsPointV2( QgsWKBTypes::PointZM, 6474985, -3526584, 3, 4 ) );
14911497
l22.transform( tr, QgsCoordinateTransform::ForwardTransform );
1492-
QVERIFY( qgsDoubleNear( l22.pointN( 0 ).x(), 175.771, 0.001 ) );
1493-
QVERIFY( qgsDoubleNear( l22.pointN( 0 ).y(), -39.722, 0.001 ) );
1494-
QVERIFY( qgsDoubleNear( l22.pointN( 0 ).z(), 1.0, 0.001 ) );
1498+
QGSCOMPARENEAR( l22.pointN( 0 ).x(), 175.771, 0.001 );
1499+
QGSCOMPARENEAR( l22.pointN( 0 ).y(), -39.724, 0.001 );
1500+
QGSCOMPARENEAR( l22.pointN( 0 ).z(), 1.0, 0.001 );
14951501
QCOMPARE( l22.pointN( 0 ).m(), 2.0 );
1496-
QVERIFY( qgsDoubleNear( l22.pointN( 1 ).x(), 176.959, 0.001 ) );
1497-
QVERIFY( qgsDoubleNear( l22.pointN( 1 ).y(), -38.798, 0.001 ) );
1498-
QVERIFY( qgsDoubleNear( l22.pointN( 1 ).z(), 3.0, 0.001 ) );
1502+
QGSCOMPARENEAR( l22.pointN( 1 ).x(), 176.959, 0.001 );
1503+
QGSCOMPARENEAR( l22.pointN( 1 ).y(), -38.7999, 0.001 );
1504+
QGSCOMPARENEAR( l22.pointN( 1 ).z(), 3.0, 0.001 );
14991505
QCOMPARE( l22.pointN( 1 ).m(), 4.0 );
15001506

15011507
//reverse transform
15021508
l22.transform( tr, QgsCoordinateTransform::ReverseTransform );
1503-
QVERIFY( qgsDoubleNear( l22.pointN( 0 ).x(), 6374985, 0.01 ) );
1504-
QVERIFY( qgsDoubleNear( l22.pointN( 0 ).y(), -3626584, 0.01 ) );
1505-
QVERIFY( qgsDoubleNear( l22.pointN( 0 ).z(), 1, 0.001 ) );
1509+
QGSCOMPARENEAR( l22.pointN( 0 ).x(), 6374985, 0.01 );
1510+
QGSCOMPARENEAR( l22.pointN( 0 ).y(), -3626584, 0.01 );
1511+
QGSCOMPARENEAR( l22.pointN( 0 ).z(), 1, 0.001 );
15061512
QCOMPARE( l22.pointN( 0 ).m(), 2.0 );
1507-
QVERIFY( qgsDoubleNear( l22.pointN( 1 ).x(), 6474985, 0.01 ) );
1508-
QVERIFY( qgsDoubleNear( l22.pointN( 1 ).y(), -3526584, 0.01 ) );
1509-
QVERIFY( qgsDoubleNear( l22.pointN( 1 ).z(), 3, 0.001 ) );
1513+
QGSCOMPARENEAR( l22.pointN( 1 ).x(), 6474985, 0.01 );
1514+
QGSCOMPARENEAR( l22.pointN( 1 ).y(), -3526584, 0.01 );
1515+
QGSCOMPARENEAR( l22.pointN( 1 ).z(), 3, 0.001 );
15101516
QCOMPARE( l22.pointN( 1 ).m(), 4.0 );
15111517

1518+
//z value transform
1519+
l22.transform( tr, QgsCoordinateTransform::ForwardTransform, true );
1520+
QGSCOMPARENEAR( l22.pointN( 0 ).z(), -19.249066, 0.001 );
1521+
QGSCOMPARENEAR( l22.pointN( 1 ).z(), -21.092128, 0.001 );
1522+
l22.transform( tr, QgsCoordinateTransform::ReverseTransform, true );
1523+
QGSCOMPARENEAR( l22.pointN( 0 ).z(), 1.0, 0.001 );
1524+
QGSCOMPARENEAR( l22.pointN( 1 ).z(), 3.0, 0.001 );
1525+
15121526
//QTransform transform
15131527
QTransform qtr = QTransform::fromScale( 2, 3 );
15141528
QgsLineStringV2 l23;

0 commit comments

Comments
 (0)
Please sign in to comment.