Skip to content
Permalink
Browse files

Basic test of QgsDistanceArea

  • Loading branch information
homann committed Sep 3, 2012
1 parent ff7b21d commit 182a64eb399596156c9ff984011c637a03ce5d4c
@@ -13,6 +13,12 @@ class QgsDistanceArea
//! Destructor
~QgsDistanceArea();

//! Copy constructor
QgsDistanceArea(const QgsDistanceArea & origDA );

//! Assignment operator
operator=(const QgsDistanceArea & origDA );

//! sets whether coordinates must be projected to ellipsoid before measuring
void setEllipsoidalMode(bool flag);
void setProjectionsEnabled(bool flag) /Deprecated/;
@@ -48,11 +48,41 @@ QgsDistanceArea::QgsDistanceArea()
}


//! Copy constructor
QgsDistanceArea::QgsDistanceArea(const QgsDistanceArea & origDA )
{
_copy( origDA );
}

QgsDistanceArea::~QgsDistanceArea()
{
delete mCoordTransform;
}

//! Assignment operator
QgsDistanceArea & QgsDistanceArea::operator=(const QgsDistanceArea & origDA )
{
if (this == & origDA )
{
// Do not copy unto self
return *this;
}
_copy( origDA );
return *this;
}

//! Copy helper. Avoid Sqlite3 accesses.
void QgsDistanceArea::_copy( const QgsDistanceArea & origDA )
{
mEllipsoidalMode = origDA.mEllipsoidalMode;
mEllipsoid = origDA.mEllipsoid;
mSemiMajor = origDA.mSemiMajor;
mSemiMinor = origDA.mSemiMinor;
mInvFlattening = origDA.mInvFlattening;
mSourceRefSys = origDA.mSourceRefSys;
mCoordTransform = new QgsCoordinateTransform( origDA.mCoordTransform->sourceCrs(), origDA.mCoordTransform->destCRS() );
}

void QgsDistanceArea::setEllipsoidalMode( bool flag )
{
mEllipsoidalMode = flag;
@@ -40,6 +40,12 @@ class CORE_EXPORT QgsDistanceArea
//! Destructor
~QgsDistanceArea();

//! Copy constructor
QgsDistanceArea(const QgsDistanceArea & origDA );

//! Assignment operator
QgsDistanceArea & operator=(const QgsDistanceArea & origDA );

//! sets whether coordinates must be projected to ellipsoid before measuring
void setEllipsoidalMode( bool flag );
Q_DECL_DEPRECATED void setProjectionsEnabled( bool flag ) { setEllipsoidalMode( flag ); };
@@ -134,6 +140,8 @@ class CORE_EXPORT QgsDistanceArea
void computeAreaInit();

private:
//! Copy helper
void _copy( const QgsDistanceArea & origDA );

//! used for transforming coordinates from source CRS to ellipsoid's coordinates
QgsCoordinateTransform* mCoordTransform;
@@ -78,6 +78,7 @@ ENDMACRO (ADD_QGIS_TEST)
#############################################################
# Tests:

ADD_QGIS_TEST(distanceareatest testqgsdistancearea.cpp)
ADD_QGIS_TEST(applicationtest testqgsapplication.cpp)
ADD_QGIS_TEST(expressiontest testqgsexpression.cpp)
ADD_QGIS_TEST(filewritertest testqgsvectorfilewriter.cpp)
@@ -0,0 +1,94 @@
/***************************************************************************
testqgsdistancearea.cpp
--------------------------------------
Date : Tue 14 Aug 2012
Copyright : (C) 2012 by Magnus Homann
Email : magnus at homann dot se
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <QtTest>
#include <QObject>
#include <QString>
#include <QObject>
#include <qgsapplication.h>
//header for class being tested
#include <qgsdistancearea.h>
#include <qgspoint.h>
#include "qgslogger.h"

class TestQgsDistanceArea: public QObject
{

Q_OBJECT;
private slots:
void initTestCase();
void basic();
void test_distances();
void unit_conversions();
};

void TestQgsDistanceArea::initTestCase()
{
//
// Runs once before any tests are run
//
// init QGIS's paths - true means that all path will be inited from prefix
QgsApplication::init();
QgsApplication::initQgis();
QgsApplication::showSettings();
}

void TestQgsDistanceArea::basic()
{
QgsPoint p1( 1.0, 3.0 ), p2(-2.0, -1.0 );
QgsDistanceArea daA;
double resultA, resultB;

daA.setEllipsoid( "NONE" );
resultA = daA.measureLine( p1, p2 );
QCOMPARE( resultA, 5.0 );

// Now, on an ellipsoid. Always less?
daA.setSourceCrs( 3006 );
daA.setEllipsoid( "WGS84" );
daA.setEllipsoidalMode( true );
resultA = daA.measureLine( p1, p2 );
QVERIFY( resultA < 5.0 );

// Test copy constructor
QgsDistanceArea daB( daA );
resultB = daB.measureLine( p1, p2 );
QCOMPARE( resultA, resultB );

// Different Ellipsoid
daB.setEllipsoid( "WGS72" );
resultB = daB.measureLine( p1, p2 );
QVERIFY( ! qFuzzyCompare( resultA, resultB ) );

// Test assignment
daA = daB;
resultA = daA.measureLine( p1, p2 );
QCOMPARE( resultA, resultB );

};

void TestQgsDistanceArea::test_distances()
{
};

void TestQgsDistanceArea::unit_conversions()
{
};

QTEST_MAIN( TestQgsDistanceArea )
#include "moc_testqgsdistancearea.cxx"




0 comments on commit 182a64e

Please sign in to comment.
You can’t perform that action at this time.