Skip to content
Permalink
Browse files

Merge pull request #5081 from nyalldawson/fix_c4566

Fix C4566 warning on Windows build
  • Loading branch information
nyalldawson committed Aug 29, 2017
2 parents 99ef3ff + 21a3b8a commit 9171da6dc750c2a64942d8fa334c9c38a770ea3f
@@ -21,6 +21,7 @@ Email : nyall dot dawson at gmail dot com
#include "qgsrastermatrix.h"
#include "qgsapplication.h"
#include "qgsproject.h"
#include "qgstestutils.h"

Q_DECLARE_METATYPE( QgsRasterCalcNode::Operator )

@@ -212,7 +213,7 @@ void TestQgsRasterCalculator::singleOp()
QVERIFY( node.calculate( rasterData, result ) );

qDebug() << "Result: " << result.number() << " expected: " << expected;
QVERIFY( qgsDoubleNear( result.number(), expected, 0.0000000001 ) );
QGSCOMPARENEAR( result.number(), expected, 0.0000000001 );

}

@@ -28,6 +28,7 @@
#include "qgsvectorfilewriter.h"

#include "qgstest.h"
#include "qgstestutils.h"

/** \ingroup UnitTests
* This is a unit test for the attribute table dialog
@@ -114,7 +115,7 @@ void TestQgsAttributeTable::testFieldCalculation()
QgsFeature f;
QVERIFY( fit.nextFeature( f ) );
double expected = 26932.156;
QVERIFY( qgsDoubleNear( f.attribute( "col1" ).toDouble(), expected, 0.001 ) );
QGSCOMPARENEAR( f.attribute( "col1" ).toDouble(), expected, 0.001 );

// change project length unit, check calculation respects unit
QgsProject::instance()->setDistanceUnits( QgsUnitTypes::DistanceFeet );
@@ -126,7 +127,7 @@ void TestQgsAttributeTable::testFieldCalculation()
fit = tempLayer->dataProvider()->getFeatures();
QVERIFY( fit.nextFeature( f ) );
expected = 88360.0918635;
QVERIFY( qgsDoubleNear( f.attribute( "col1" ).toDouble(), expected, 0.001 ) );
QGSCOMPARENEAR( f.attribute( "col1" ).toDouble(), expected, 0.001 );
}

void TestQgsAttributeTable::testFieldCalculationArea()
@@ -164,7 +165,7 @@ void TestQgsAttributeTable::testFieldCalculationArea()
QgsFeature f;
QVERIFY( fit.nextFeature( f ) );
double expected = 1009089817.0;
QVERIFY( qgsDoubleNear( f.attribute( "col1" ).toDouble(), expected, 1.0 ) );
QGSCOMPARENEAR( f.attribute( "col1" ).toDouble(), expected, 1.0 );

// change project area unit, check calculation respects unit
QgsProject::instance()->setAreaUnits( QgsUnitTypes::AreaSquareMiles );
@@ -176,7 +177,7 @@ void TestQgsAttributeTable::testFieldCalculationArea()
fit = tempLayer->dataProvider()->getFeatures();
QVERIFY( fit.nextFeature( f ) );
expected = 389.6117565069;
QVERIFY( qgsDoubleNear( f.attribute( "col1" ).toDouble(), expected, 0.001 ) );
QGSCOMPARENEAR( f.attribute( "col1" ).toDouble(), expected, 0.001 );
}

void TestQgsAttributeTable::testNoGeom()
@@ -24,6 +24,7 @@
#include "qgsproject.h"
#include "qgsmapcanvas.h"
#include "qgsunittypes.h"
#include "qgstestutils.h"

/** \ingroup UnitTests
* This is a unit test for the field calculator
@@ -107,7 +108,7 @@ void TestQgsFieldCalculator::testLengthCalculations()
QgsFeature f;
QVERIFY( fit.nextFeature( f ) );
double expected = 26932.156;
QVERIFY( qgsDoubleNear( f.attribute( "col1" ).toDouble(), expected, 0.001 ) );
QGSCOMPARENEAR( f.attribute( "col1" ).toDouble(), expected, 0.001 );

// change project length unit, check calculation respects unit
QgsProject::instance()->setDistanceUnits( QgsUnitTypes::DistanceFeet );
@@ -122,7 +123,7 @@ void TestQgsFieldCalculator::testLengthCalculations()
fit = tempLayer->dataProvider()->getFeatures();
QVERIFY( fit.nextFeature( f ) );
expected = 88360.0918635;
QVERIFY( qgsDoubleNear( f.attribute( "col1" ).toDouble(), expected, 0.001 ) );
QGSCOMPARENEAR( f.attribute( "col1" ).toDouble(), expected, 0.001 );

}

@@ -168,7 +169,7 @@ void TestQgsFieldCalculator::testAreaCalculations()
QgsFeature f;
QVERIFY( fit.nextFeature( f ) );
double expected = 1009089817.0;
QVERIFY( qgsDoubleNear( f.attribute( "col1" ).toDouble(), expected, 1.0 ) );
QGSCOMPARENEAR( f.attribute( "col1" ).toDouble(), expected, 1.0 );

// change project area unit, check calculation respects unit
QgsProject::instance()->setAreaUnits( QgsUnitTypes::AreaSquareMiles );
@@ -183,7 +184,7 @@ void TestQgsFieldCalculator::testAreaCalculations()
fit = tempLayer->dataProvider()->getFeatures();
QVERIFY( fit.nextFeature( f ) );
expected = 389.6117565069;
QVERIFY( qgsDoubleNear( f.attribute( "col1" ).toDouble(), expected, 0.001 ) );
QGSCOMPARENEAR( f.attribute( "col1" ).toDouble(), expected, 0.001 );
}

QGSTEST_MAIN( TestQgsFieldCalculator )
@@ -26,6 +26,7 @@
#include "qgsunittypes.h"
#include "qgsmaptoolidentifyaction.h"
#include "qgssettings.h"
#include "qgstestutils.h"

#include "cpl_conv.h"

@@ -142,23 +143,23 @@ void TestQgsMapToolIdentifyAction::lengthCalculation()
QCOMPARE( result.length(), 1 );
QString derivedLength = result.at( 0 ).mDerivedAttributes[tr( "Length" )];
double length = derivedLength.remove( ',' ).split( ' ' ).at( 0 ).toDouble();
QVERIFY( qgsDoubleNear( length, 26932.2, 0.1 ) );
QGSCOMPARENEAR( length, 26932.2, 0.1 );

//check that project units are respected
QgsProject::instance()->setDistanceUnits( QgsUnitTypes::DistanceFeet );
result = action->identify( mapPoint.x(), mapPoint.y(), QList<QgsMapLayer *>() << tempLayer.get() );
QCOMPARE( result.length(), 1 );
derivedLength = result.at( 0 ).mDerivedAttributes[tr( "Length" )];
length = derivedLength.remove( ',' ).split( ' ' ).at( 0 ).toDouble();
QVERIFY( qgsDoubleNear( length, 88360.1, 0.1 ) );
QGSCOMPARENEAR( length, 88360.1, 0.1 );

//test unchecked "keep base units" setting
s.setValue( QStringLiteral( "/qgis/measure/keepbaseunit" ), false );
result = action->identify( mapPoint.x(), mapPoint.y(), QList<QgsMapLayer *>() << tempLayer.get() );
QCOMPARE( result.length(), 1 );
derivedLength = result.at( 0 ).mDerivedAttributes[tr( "Length" )];
length = derivedLength.remove( ',' ).split( ' ' ).at( 0 ).toDouble();
QVERIFY( qgsDoubleNear( length, 16.735, 0.001 ) );
QGSCOMPARENEAR( length, 16.735, 0.001 );
}

void TestQgsMapToolIdentifyAction::perimeterCalculation()
@@ -203,15 +204,15 @@ void TestQgsMapToolIdentifyAction::perimeterCalculation()
QCOMPARE( result.length(), 1 );
derivedPerimeter = result.at( 0 ).mDerivedAttributes[tr( "Perimeter" )];
perimeter = derivedPerimeter.remove( ',' ).split( ' ' ).at( 0 ).toDouble();
QVERIFY( qgsDoubleNear( perimeter, 420896.0, 0.1 ) );
QGSCOMPARENEAR( perimeter, 420896.0, 0.1 );

//test unchecked "keep base units" setting
s.setValue( QStringLiteral( "/qgis/measure/keepbaseunit" ), false );
result = action->identify( mapPoint.x(), mapPoint.y(), QList<QgsMapLayer *>() << tempLayer.get() );
QCOMPARE( result.length(), 1 );
derivedPerimeter = result.at( 0 ).mDerivedAttributes[tr( "Perimeter" )];
perimeter = derivedPerimeter.remove( ',' ).split( ' ' ).at( 0 ).toDouble();
QVERIFY( qgsDoubleNear( perimeter, 79.715, 0.001 ) );
QGSCOMPARENEAR( perimeter, 79.715, 0.001 );
}

void TestQgsMapToolIdentifyAction::areaCalculation()
@@ -249,15 +250,15 @@ void TestQgsMapToolIdentifyAction::areaCalculation()
QCOMPARE( result.length(), 1 );
QString derivedArea = result.at( 0 ).mDerivedAttributes[tr( "Area" )];
double area = derivedArea.remove( ',' ).split( ' ' ).at( 0 ).toDouble();
QVERIFY( qgsDoubleNear( area, 1009089817.0, 1.0 ) );
QGSCOMPARENEAR( area, 1009089817.0, 1.0 );

//check that project units are respected
QgsProject::instance()->setAreaUnits( QgsUnitTypes::AreaSquareMiles );
result = action->identify( mapPoint.x(), mapPoint.y(), QList<QgsMapLayer *>() << tempLayer.get() );
QCOMPARE( result.length(), 1 );
derivedArea = result.at( 0 ).mDerivedAttributes[tr( "Area" )];
area = derivedArea.remove( ',' ).split( ' ' ).at( 0 ).toDouble();
QVERIFY( qgsDoubleNear( area, 389.6117, 0.001 ) );
QGSCOMPARENEAR( area, 389.6117, 0.001 );

//test unchecked "keep base units" setting
s.setValue( QStringLiteral( "/qgis/measure/keepbaseunit" ), false );
@@ -266,7 +267,7 @@ void TestQgsMapToolIdentifyAction::areaCalculation()
QCOMPARE( result.length(), 1 );
derivedArea = result.at( 0 ).mDerivedAttributes[tr( "Area" )];
area = derivedArea.remove( ',' ).split( ' ' ).at( 0 ).toDouble();
QVERIFY( qgsDoubleNear( area, 389.6117, 0.001 ) );
QGSCOMPARENEAR( area, 389.6117, 0.001 );
}

// private
@@ -29,6 +29,7 @@
#include "qgsproperty.h"
#include <QObject>
#include "qgstest.h"
#include "qgstestutils.h"

class TestQgsComposerMap : public QObject
{
@@ -176,34 +177,34 @@ void TestQgsComposerMap::worldFileGeneration()
double a, b, c, d, e, f;
mComposition->computeWorldFileParameters( a, b, c, d, e, f );

QVERIFY( qgsDoubleNear( a, 4.18048, 0.001 ) );
QVERIFY( qgsDoubleNear( b, 2.41331, 0.001 ) );
QVERIFY( qgsDoubleNear( c, 779444, 1 ) );
QVERIFY( qgsDoubleNear( d, 2.4136, 0.001 ) );
QVERIFY( qgsDoubleNear( e, -4.17997, 0.001 ) );
QVERIFY( qgsDoubleNear( f, 3.34241e+06, 1e+03 ) );
QGSCOMPARENEAR( a, 4.18048, 0.001 );
QGSCOMPARENEAR( b, 2.41331, 0.001 );
QGSCOMPARENEAR( c, 779444, 1 );
QGSCOMPARENEAR( d, 2.4136, 0.001 );
QGSCOMPARENEAR( e, -4.17997, 0.001 );
QGSCOMPARENEAR( f, 3.34241e+06, 1e+03 );

//test with map on second page. Parameters should be the same
mComposerMap->setItemPosition( 20, 20, QgsComposerItem::UpperLeft, 2 );
mComposition->computeWorldFileParameters( a, b, c, d, e, f );

QVERIFY( qgsDoubleNear( a, 4.18048, 0.001 ) );
QVERIFY( qgsDoubleNear( b, 2.41331, 0.001 ) );
QVERIFY( qgsDoubleNear( c, 779444, 1 ) );
QVERIFY( qgsDoubleNear( d, 2.4136, 0.001 ) );
QVERIFY( qgsDoubleNear( e, -4.17997, 0.001 ) );
QVERIFY( qgsDoubleNear( f, 3.34241e+06, 1e+03 ) );
QGSCOMPARENEAR( a, 4.18048, 0.001 );
QGSCOMPARENEAR( b, 2.41331, 0.001 );
QGSCOMPARENEAR( c, 779444, 1 );
QGSCOMPARENEAR( d, 2.4136, 0.001 );
QGSCOMPARENEAR( e, -4.17997, 0.001 );
QGSCOMPARENEAR( f, 3.34241e+06, 1e+03 );

//test computing parameters for specific region
mComposerMap->setItemPosition( 20, 20, QgsComposerItem::UpperLeft, 2 );
mComposition->computeWorldFileParameters( QRectF( 10, 5, 260, 200 ), a, b, c, d, e, f );

QVERIFY( qgsDoubleNear( a, 4.18061, 0.001 ) );
QVERIFY( qgsDoubleNear( b, 2.41321, 0.001 ) );
QVERIFY( qgsDoubleNear( c, 773810, 1 ) );
QVERIFY( qgsDoubleNear( d, 2.4137, 0.001 ) );
QVERIFY( qgsDoubleNear( e, -4.1798, 0.001 ) );
QVERIFY( qgsDoubleNear( f, 3.35331e+06, 1e+03 ) );
QGSCOMPARENEAR( a, 4.18061, 0.001 );
QGSCOMPARENEAR( b, 2.41321, 0.001 );
QGSCOMPARENEAR( c, 773810, 1 );
QGSCOMPARENEAR( d, 2.4137, 0.001 );
QGSCOMPARENEAR( e, -4.1798, 0.001 );
QGSCOMPARENEAR( f, 3.35331e+06, 1e+03 );

mComposition->setGenerateWorldFile( false );
mComposerMap->setMapRotation( 0.0 );

0 comments on commit 9171da6

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