[BACKPORT] in progress test updates / fixes

This commit is contained in:
Tim Sutton 2012-04-06 23:42:32 +02:00
parent 845856e637
commit 6adf0f8037
9 changed files with 99 additions and 81 deletions

View File

@ -211,7 +211,8 @@ bool QgsCoordinateReferenceSystem::createFromEpsg( long id )
bool QgsCoordinateReferenceSystem::createFromSrsId( long id ) bool QgsCoordinateReferenceSystem::createFromSrsId( long id )
{ {
return loadFromDb( id < USER_CRS_START_ID ? QgsApplication::srsDbFilePath() : QgsApplication::qgisUserDbFilePath(), return loadFromDb( id < USER_CRS_START_ID ? QgsApplication::srsDbFilePath() :
QgsApplication::qgisUserDbFilePath(),
"srs_id", QString::number( id ) ); "srs_id", QString::number( id ) );
} }
@ -252,13 +253,19 @@ bool QgsCoordinateReferenceSystem::loadFromDb( QString db, QString expression, Q
is_geo integer NOT NULL); is_geo integer NOT NULL);
*/ */
QString mySql = "select srs_id,description,projection_acronym,ellipsoid_acronym,parameters,srid,auth_name||':'||auth_id,is_geo from tbl_srs where " + expression + "=" + quotedValue( value ) + " order by deprecated"; QString mySql = "select srs_id,description,projection_acronym,"
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail ); "ellipsoid_acronym,parameters,srid,auth_name||':'||auth_id,is_geo "
"from tbl_srs where " + expression + "=" + quotedValue( value );
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(),
mySql.toUtf8().length(),
&myPreparedStatement, &myTail );
// XXX Need to free memory from the error msg if one is set // XXX Need to free memory from the error msg if one is set
if ( myResult == SQLITE_OK && sqlite3_step( myPreparedStatement ) == SQLITE_ROW ) if ( myResult == SQLITE_OK && sqlite3_step( myPreparedStatement ) == SQLITE_ROW )
{ {
mSrsId = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 0 ) ).toLong(); mSrsId = QString::fromUtf8(( char * )sqlite3_column_text(
mDescription = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 1 ) ); myPreparedStatement, 0 ) ).toLong();
mDescription = QString::fromUtf8(( char * )sqlite3_column_text(
myPreparedStatement, 1 ) );
mProjectionAcronym = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 2 ) ); mProjectionAcronym = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 2 ) );
mEllipsoidAcronym = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 3 ) ); mEllipsoidAcronym = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 3 ) );
QString toProj4 = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 4 ) ); QString toProj4 = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 4 ) );
@ -436,7 +443,7 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
* - if the above does not match perform a whole text search on proj4 string (if not null) * - if the above does not match perform a whole text search on proj4 string (if not null)
*/ */
// QgsDebugMsg( "wholetext match on name failed, trying proj4string match" ); // QgsDebugMsg( "wholetext match on name failed, trying proj4string match" );
myRecord = getRecord( "select * from tbl_srs where parameters=" + quotedValue( theProj4String.trimmed() ) + " order by deprecated" ); myRecord = getRecord( "select * from tbl_srs where parameters=" + quotedValue( theProj4String.trimmed() ) );
if ( myRecord.empty() ) if ( myRecord.empty() )
{ {
// Ticket #722 - aaronr // Ticket #722 - aaronr
@ -471,7 +478,7 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
myStart2 = myLat2RegExp.indexIn( theProj4String, myStart2 ); myStart2 = myLat2RegExp.indexIn( theProj4String, myStart2 );
theProj4StringModified.replace( myStart2 + LAT_PREFIX_LEN, myLength2 - LAT_PREFIX_LEN, lat1Str ); theProj4StringModified.replace( myStart2 + LAT_PREFIX_LEN, myLength2 - LAT_PREFIX_LEN, lat1Str );
QgsDebugMsg( "trying proj4string match with swapped lat_1,lat_2" ); QgsDebugMsg( "trying proj4string match with swapped lat_1,lat_2" );
myRecord = getRecord( "select * from tbl_srs where parameters=" + quotedValue( theProj4StringModified.trimmed() ) + " order by deprecated" ); myRecord = getRecord( "select * from tbl_srs where parameters=" + quotedValue( theProj4StringModified.trimmed() ) );
} }
} }
@ -504,13 +511,13 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
if ( !datum.isEmpty() ) if ( !datum.isEmpty() )
{ {
myRecord = getRecord( sql + delim + datum + " order by deprecated" ); myRecord = getRecord( sql + delim + datum );
} }
if ( myRecord.empty() ) if ( myRecord.empty() )
{ {
// datum might have disappeared in definition - retry without it // datum might have disappeared in definition - retry without it
myRecord = getRecord( sql + " order by deprecated" ); myRecord = getRecord( sql );
} }
} }
@ -550,7 +557,7 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
if ( mIsValidFlag ) if ( mIsValidFlag )
{ {
// but the proj.4 parsed string might already be in our database // but the proj.4 parsed string might already be in our database
myRecord = getRecord( "select * from tbl_srs where parameters=" + quotedValue( toProj4() ) + " order by deprecated" ); myRecord = getRecord( "select * from tbl_srs where parameters=" + quotedValue( toProj4() ) );
if ( myRecord.empty() ) if ( myRecord.empty() )
{ {
// It's not, so try to add it // It's not, so try to add it
@ -560,7 +567,7 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
if ( mIsValidFlag ) if ( mIsValidFlag )
{ {
// but validate that it's there afterwards // but validate that it's there afterwards
myRecord = getRecord( "select * from tbl_srs where parameters=" + quotedValue( toProj4() ) + " order by deprecated" ); myRecord = getRecord( "select * from tbl_srs where parameters=" + quotedValue( toProj4() ) );
} }
} }
@ -805,7 +812,9 @@ void QgsCoordinateReferenceSystem::setProj4String( QString theProj4String )
setlocale( LC_NUMERIC, "C" ); setlocale( LC_NUMERIC, "C" );
OSRDestroySpatialReference( mCRS ); OSRDestroySpatialReference( mCRS );
mCRS = OSRNewSpatialReference( NULL ); mCRS = OSRNewSpatialReference( NULL );
mIsValidFlag = OSRImportFromProj4( mCRS, theProj4String.toLatin1().constData() ) == OGRERR_NONE; mIsValidFlag =
OSRImportFromProj4( mCRS, theProj4String.toLatin1().constData() )
== OGRERR_NONE;
mWkt.clear(); mWkt.clear();
setMapUnits(); setMapUnits();
@ -901,9 +910,11 @@ void QgsCoordinateReferenceSystem::setMapUnits()
long QgsCoordinateReferenceSystem::findMatchingProj() long QgsCoordinateReferenceSystem::findMatchingProj()
{ {
QgsDebugMsg( "entered." ); QgsDebugMsg( "entered." );
if ( mEllipsoidAcronym.isNull() || mProjectionAcronym.isNull() || !mIsValidFlag ) if ( mEllipsoidAcronym.isNull() || mProjectionAcronym.isNull()
|| !mIsValidFlag )
{ {
QgsDebugMsg( "QgsCoordinateReferenceSystem::findMatchingProj will only work if prj acr ellipsoid acr and proj4string are set" QgsDebugMsg( "QgsCoordinateReferenceSystem::findMatchingProj will only "
"work if prj acr ellipsoid acr and proj4string are set"
" and the current projection is valid!" ); " and the current projection is valid!" );
return 0; return 0;
} }
@ -913,8 +924,10 @@ long QgsCoordinateReferenceSystem::findMatchingProj()
sqlite3_stmt *myPreparedStatement; sqlite3_stmt *myPreparedStatement;
int myResult; int myResult;
// Set up the query to retrieve the projection information needed to populate the list // Set up the query to retrieve the projection information
QString mySql = QString( "select srs_id,parameters from tbl_srs where projection_acronym=%1 and ellipsoid_acronym=%2 order by deprecated" ) // needed to populate the list
QString mySql = QString( "select srs_id,parameters from tbl_srs where "
"projection_acronym=%1 and ellipsoid_acronym=%2" )
.arg( quotedValue( mProjectionAcronym ) ) .arg( quotedValue( mProjectionAcronym ) )
.arg( quotedValue( mEllipsoidAcronym ) ); .arg( quotedValue( mEllipsoidAcronym ) );
// Get the full path name to the sqlite3 spatial reference database. // Get the full path name to the sqlite3 spatial reference database.
@ -999,7 +1012,9 @@ long QgsCoordinateReferenceSystem::findMatchingProj()
bool QgsCoordinateReferenceSystem::operator==( const QgsCoordinateReferenceSystem &theSrs ) const bool QgsCoordinateReferenceSystem::operator==( const QgsCoordinateReferenceSystem &theSrs ) const
{ {
return mIsValidFlag && theSrs.mIsValidFlag && toWkt() == theSrs.toWkt(); QString myWkt = toWkt();
QString theirWkt = theSrs.toWkt();
return mIsValidFlag && theSrs.mIsValidFlag && myWkt == theirWkt;
} }
bool QgsCoordinateReferenceSystem::operator!=( const QgsCoordinateReferenceSystem &theSrs ) const bool QgsCoordinateReferenceSystem::operator!=( const QgsCoordinateReferenceSystem &theSrs ) const
@ -1187,7 +1202,7 @@ QString QgsCoordinateReferenceSystem::proj4FromSrsId( const int theSrsId )
QString myDatabaseFileName; QString myDatabaseFileName;
QString myProjString; QString myProjString;
QString mySql = QString( "select parameters from tbl_srs where srs_id = %1 order by deprecated" ).arg( theSrsId ); QString mySql = QString( "select parameters from tbl_srs where srs_id = %1" ).arg( theSrsId );
QgsDebugMsg( "mySrsId = " + QString::number( theSrsId ) ); QgsDebugMsg( "mySrsId = " + QString::number( theSrsId ) );
QgsDebugMsg( "USER_CRS_START_ID = " + QString::number( USER_CRS_START_ID ) ); QgsDebugMsg( "USER_CRS_START_ID = " + QString::number( USER_CRS_START_ID ) );
@ -1419,7 +1434,7 @@ int QgsCoordinateReferenceSystem::syncDb()
const char *tail; const char *tail;
sqlite3_stmt *select; sqlite3_stmt *select;
QString sql = "select auth_name,auth_id,parameters from tbl_srs WHERE auth_name IS NOT NULL AND auth_id IS NOT NULL order by deprecated"; QString sql = "select auth_name,auth_id,parameters from tbl_srs WHERE auth_name IS NOT NULL AND auth_id IS NOT NULL";
if ( sqlite3_prepare( database, sql.toAscii(), sql.size(), &select, &tail ) != SQLITE_OK ) if ( sqlite3_prepare( database, sql.toAscii(), sql.size(), &select, &tail ) != SQLITE_OK )
{ {
qCritical( "Could not prepare: %s [%s]\n", sql.toAscii().constData(), sqlite3_errmsg( database ) ); qCritical( "Could not prepare: %s [%s]\n", sql.toAscii().constData(), sqlite3_errmsg( database ) );

View File

@ -34,7 +34,8 @@ QgsRenderChecker::QgsRenderChecker( ) :
{ {
} }
bool QgsRenderChecker::runTest( QString theTestName ) bool QgsRenderChecker::runTest( QString theTestName,
unsigned int theMismatchCount )
{ {
if ( mExpectedImageFile.isEmpty() ) if ( mExpectedImageFile.isEmpty() )
{ {
@ -53,11 +54,16 @@ bool QgsRenderChecker::runTest( QString theTestName )
// //
// Now render our layers onto a pixmap // Now render our layers onto a pixmap
// //
QImage myImage( myExpectedImage.width(), myExpectedImage.height(), QImage::Format_RGB32 ); QImage myImage( myExpectedImage.width(),
myExpectedImage.height(),
QImage::Format_RGB32 );
myImage.fill( qRgb( 152, 219, 249 ) ); myImage.fill( qRgb( 152, 219, 249 ) );
QPainter myPainter( &myImage ); QPainter myPainter( &myImage );
myPainter.setRenderHint( QPainter::Antialiasing );
mpMapRenderer->setOutputSize( QSize( mpMapRenderer->setOutputSize( QSize(
myExpectedImage.width(), myExpectedImage.height() ), myExpectedImage.logicalDpiX() ); myExpectedImage.width(),
myExpectedImage.height() ),
myExpectedImage.logicalDpiX() );
QTime myTime; QTime myTime;
myTime.start(); myTime.start();
mpMapRenderer->render( &myPainter ); mpMapRenderer->render( &myPainter );
@ -69,12 +75,13 @@ bool QgsRenderChecker::runTest( QString theTestName )
// //
mRenderedImageFile = QDir::tempPath() + QDir::separator() + theTestName + "_result.png"; mRenderedImageFile = QDir::tempPath() + QDir::separator() + theTestName + "_result.png";
myImage.save( mRenderedImageFile ); myImage.save( mRenderedImageFile );
return compareImages( theTestName ); return compareImages( theTestName, theMismatchCount );
} }
bool QgsRenderChecker::compareImages( QString theTestName ) bool QgsRenderChecker::compareImages( QString theTestName,
unsigned int theMismatchCount )
{ {
if ( mExpectedImageFile.isEmpty() ) if ( mExpectedImageFile.isEmpty() )
{ {
@ -190,7 +197,7 @@ bool QgsRenderChecker::compareImages( QString theTestName )
mReport += "</td></tr>"; mReport += "</td></tr>";
if ( mMismatchCount == 0 ) if ( mMismatchCount <= theMismatchCount )
{ {
mReport += "<tr><td colspan = 3>\n"; mReport += "<tr><td colspan = 3>\n";
mReport += "Test image and result image for " + theTestName + " are matched<br>"; mReport += "Test image and result image for " + theTestName + " are matched<br>";

View File

@ -49,17 +49,25 @@ public:
* Test using renderer to generate the image to be compared. * Test using renderer to generate the image to be compared.
* @param theTestName - to be used as the basis for writing a file to * @param theTestName - to be used as the basis for writing a file to
* e.g. /tmp/theTestName.png * e.g. /tmp/theTestName.png
* @param theMismatchCount - defaults to 0 - the number of pixels that
* are allowed to be different from the control image. In some cases
* rendering may be non-deterministic. This parameter allows you to account
* for that by providing a tolerance.
* @note make sure to call setExpectedImage and setMapRenderer first * @note make sure to call setExpectedImage and setMapRenderer first
*/ */
bool runTest( QString theTestName ); bool runTest( QString theTestName, unsigned int theMismatchCount=0 );
/** /**
* Test using two arbitary images (map renderer will not be used) * Test using two arbitary images (map renderer will not be used)
* @param theTestName - to be used as the basis for writing a file to * @param theTestName - to be used as the basis for writing a file to
* e.g. /tmp/theTestName.png * e.g. /tmp/theTestName.png
* @param theMismatchCount - defaults to 0 - the number of pixels that
* are allowed to be different from the control image. In some cases
* rendering may be non-deterministic. This parameter allows you to account
* for that by providing a tolerance.
* @note: make sure to call setExpectedImage and setRenderedImage first. * @note: make sure to call setExpectedImage and setRenderedImage first.
*/ */
bool compareImages( QString theTestName ); bool compareImages( QString theTestName, unsigned int theMismatchCount=0 );
private: private:
QString mReport; QString mReport;
QString mExpectedImageFile; QString mExpectedImageFile;

View File

@ -97,7 +97,7 @@ void Regression1141::diacriticalTest()
mEncoding = "UTF-8"; mEncoding = "UTF-8";
QgsField myField( "ąęćń", QVariant::Int, "int", 10, 0, "Value on lon" ); QgsField myField( "ąęćń", QVariant::Int, "int", 10, 0, "Value on lon" );
mFields.insert( 0, myField ); mFields.insert( 0, myField );
mCRS = QgsCoordinateReferenceSystem( GEOWkt ); mCRS = QgsCoordinateReferenceSystem( GEOWKT );
qDebug( "Checking test dataset exists...\n%s", mFileName.toLocal8Bit().constData() ); qDebug( "Checking test dataset exists...\n%s", mFileName.toLocal8Bit().constData() );

View File

@ -110,7 +110,8 @@ void Regression992::regression992()
QgsRenderChecker myChecker; QgsRenderChecker myChecker;
myChecker.setExpectedImage( myTestDataDir + "expected_rgbwcmyk01_YeGeo.jp2.png" ); myChecker.setExpectedImage( myTestDataDir + "expected_rgbwcmyk01_YeGeo.jp2.png" );
myChecker.setMapRenderer( mpMapRenderer ); myChecker.setMapRenderer( mpMapRenderer );
bool myResultFlag = myChecker.runTest( "regression992" ); // allow up to 300 mismatched pixels
bool myResultFlag = myChecker.runTest( "regression992", 300 );
mReport += "\n\n\n" + myChecker.report(); mReport += "\n\n\n" + myChecker.report();
QVERIFY( myResultFlag ); QVERIFY( myResultFlag );
} }

View File

@ -22,6 +22,7 @@ Email : sherman at mrcc dot com
//header for class being tested //header for class being tested
#include <qgscoordinatereferencesystem.h> #include <qgscoordinatereferencesystem.h>
#include <qgis.h>
class TestQgsCoordinateReferenceSystem: public QObject class TestQgsCoordinateReferenceSystem: public QObject
{ {
@ -40,7 +41,6 @@ class TestQgsCoordinateReferenceSystem: public QObject
void createFromProj4(); void createFromProj4();
void isValid(); void isValid();
void validate(); void validate();
void findMatchingProj();
void equality(); void equality();
void noEquality(); void noEquality();
void equals(); void equals();
@ -48,7 +48,6 @@ class TestQgsCoordinateReferenceSystem: public QObject
void writeXML(); void writeXML();
void setCustomSrsValidation(); void setCustomSrsValidation();
void customSrsValidation(); void customSrsValidation();
void srsid();
void postgisSrid(); void postgisSrid();
void ellipsoidAcronym(); void ellipsoidAcronym();
void toWkt(); void toWkt();
@ -75,27 +74,30 @@ void TestQgsCoordinateReferenceSystem::initTestCase()
void TestQgsCoordinateReferenceSystem::wktCtor() void TestQgsCoordinateReferenceSystem::wktCtor()
{ {
QString myWkt( "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AUTHORITY[\"EPSG\",\"4326\"]]" ) ; QString myWkt = GEOWKT;
QgsCoordinateReferenceSystem myCrs( myWkt ); QgsCoordinateReferenceSystem myCrs( myWkt );
debugPrint( myCrs ); debugPrint( myCrs );
QVERIFY( myCrs.isValid() ); QVERIFY( myCrs.isValid() );
} }
void TestQgsCoordinateReferenceSystem::idCtor() void TestQgsCoordinateReferenceSystem::idCtor()
{ {
QgsCoordinateReferenceSystem myCrs( 4326, QgsCoordinateReferenceSystem::EpsgCrsId ); QgsCoordinateReferenceSystem myCrs( GEOSRID,
QgsCoordinateReferenceSystem::EpsgCrsId );
debugPrint( myCrs ); debugPrint( myCrs );
QVERIFY( myCrs.isValid() ); QVERIFY( myCrs.isValid() );
} }
void TestQgsCoordinateReferenceSystem::copyCtor() void TestQgsCoordinateReferenceSystem::copyCtor()
{ {
QgsCoordinateReferenceSystem myCrs( 4326, QgsCoordinateReferenceSystem::EpsgCrsId ); QgsCoordinateReferenceSystem myCrs( GEOSRID,
QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem myCrs2( myCrs ); QgsCoordinateReferenceSystem myCrs2( myCrs );
debugPrint( myCrs2 ); debugPrint( myCrs2 );
QVERIFY( myCrs2.isValid() ); QVERIFY( myCrs2.isValid() );
} }
void TestQgsCoordinateReferenceSystem::assignmentCtor() void TestQgsCoordinateReferenceSystem::assignmentCtor()
{ {
QgsCoordinateReferenceSystem myCrs( 4326, QgsCoordinateReferenceSystem::EpsgCrsId ); QgsCoordinateReferenceSystem myCrs( GEOSRID,
QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem myCrs2 = myCrs; QgsCoordinateReferenceSystem myCrs2 = myCrs;
debugPrint( myCrs2 ); debugPrint( myCrs2 );
QVERIFY( myCrs2.isValid() ); QVERIFY( myCrs2.isValid() );
@ -103,7 +105,7 @@ void TestQgsCoordinateReferenceSystem::assignmentCtor()
void TestQgsCoordinateReferenceSystem::createFromId() void TestQgsCoordinateReferenceSystem::createFromId()
{ {
QgsCoordinateReferenceSystem myCrs; QgsCoordinateReferenceSystem myCrs;
myCrs.createFromId( 4326, QgsCoordinateReferenceSystem::EpsgCrsId ); myCrs.createFromId( GEOSRID, QgsCoordinateReferenceSystem::EpsgCrsId );
debugPrint( myCrs ); debugPrint( myCrs );
QVERIFY( myCrs.isValid() ); QVERIFY( myCrs.isValid() );
} }
@ -117,80 +119,71 @@ void TestQgsCoordinateReferenceSystem::createFromOgcWmsCrs()
void TestQgsCoordinateReferenceSystem::createFromSrid() void TestQgsCoordinateReferenceSystem::createFromSrid()
{ {
QgsCoordinateReferenceSystem myCrs; QgsCoordinateReferenceSystem myCrs;
myCrs.createFromSrid( 4326 ); myCrs.createFromSrid( GEOSRID );
debugPrint( myCrs ); debugPrint( myCrs );
QVERIFY( myCrs.isValid() ); QVERIFY( myCrs.isValid() );
} }
void TestQgsCoordinateReferenceSystem::createFromWkt() void TestQgsCoordinateReferenceSystem::createFromWkt()
{ {
QgsCoordinateReferenceSystem myCrs; QgsCoordinateReferenceSystem myCrs;
QString myWkt = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AUTHORITY[\"EPSG\",\"4326\"]]" ; QVERIFY( !myCrs.createFromWkt( GEOWKT ) );
QVERIFY( !myCrs.createFromWkt( myWkt ) );
} }
void TestQgsCoordinateReferenceSystem::createFromSrsId() void TestQgsCoordinateReferenceSystem::createFromSrsId()
{ {
QgsCoordinateReferenceSystem myCrs; QgsCoordinateReferenceSystem myCrs;
QVERIFY( myCrs.createFromSrsId( 4326 ) ); QVERIFY( myCrs.createFromSrid( GEOSRID ) );
debugPrint( myCrs ); debugPrint( myCrs );
} }
void TestQgsCoordinateReferenceSystem::createFromProj4() void TestQgsCoordinateReferenceSystem::createFromProj4()
{ {
QgsCoordinateReferenceSystem myCrs; QgsCoordinateReferenceSystem myCrs;
QVERIFY( myCrs.createFromProj4( "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" ) ); QVERIFY( myCrs.createFromProj4( GEOPROJ4 ) );
debugPrint( myCrs ); debugPrint( myCrs );
} }
void TestQgsCoordinateReferenceSystem::isValid() void TestQgsCoordinateReferenceSystem::isValid()
{ {
QgsCoordinateReferenceSystem myCrs; QgsCoordinateReferenceSystem myCrs;
myCrs.createFromSrsId( 4326 ); myCrs.createFromSrid( GEOSRID );
QVERIFY( myCrs.isValid() ); QVERIFY( myCrs.isValid() );
debugPrint( myCrs ); debugPrint( myCrs );
} }
void TestQgsCoordinateReferenceSystem::validate() void TestQgsCoordinateReferenceSystem::validate()
{ {
QgsCoordinateReferenceSystem myCrs; QgsCoordinateReferenceSystem myCrs;
myCrs.createFromSrsId( 4326 ); myCrs.createFromSrid( GEOSRID );
myCrs.validate(); myCrs.validate();
QVERIFY( myCrs.isValid() ); QVERIFY( myCrs.isValid() );
debugPrint( myCrs ); debugPrint( myCrs );
} }
void TestQgsCoordinateReferenceSystem::findMatchingProj()
{
QgsCoordinateReferenceSystem myCrs;
myCrs.createFromSrsId( 4326 );
int myLong = myCrs.findMatchingProj();
QVERIFY( myLong == 4326 );
debugPrint( myCrs );
}
void TestQgsCoordinateReferenceSystem::equality() void TestQgsCoordinateReferenceSystem::equality()
{ {
QgsCoordinateReferenceSystem myCrs; QgsCoordinateReferenceSystem myCrs;
myCrs.createFromSrsId( 4326 ); myCrs.createFromSrid( GEOSRID );
QgsCoordinateReferenceSystem myCrs2; QgsCoordinateReferenceSystem myCrs2;
myCrs2.createFromSrsId( 4326 ); myCrs2.createFromSrsId( GEOSRID );
QVERIFY( myCrs == myCrs2 );
debugPrint( myCrs ); debugPrint( myCrs );
QVERIFY( myCrs == myCrs2 );
} }
void TestQgsCoordinateReferenceSystem::noEquality() void TestQgsCoordinateReferenceSystem::noEquality()
{ {
QgsCoordinateReferenceSystem myCrs; QgsCoordinateReferenceSystem myCrs;
myCrs.createFromSrsId( 4326 ); myCrs.createFromSrid( GEOSRID );
QgsCoordinateReferenceSystem myCrs2; QgsCoordinateReferenceSystem myCrs2;
myCrs2.createFromSrsId( 4327 ); myCrs2.createFromSrsId( 4327 );
QVERIFY( myCrs != myCrs2 );
debugPrint( myCrs ); debugPrint( myCrs );
QVERIFY( myCrs != myCrs2 );
} }
void TestQgsCoordinateReferenceSystem::equals() void TestQgsCoordinateReferenceSystem::equals()
{ {
QgsCoordinateReferenceSystem myCrs; QgsCoordinateReferenceSystem myCrs;
myCrs.createFromSrsId( 4326 ); myCrs.createFromSrid( GEOSRID );
QVERIFY( myCrs.equals( "proj4 string" ) );
debugPrint( myCrs ); debugPrint( myCrs );
QVERIFY( myCrs.equals( GEOPROJ4 ) );
} }
void TestQgsCoordinateReferenceSystem::readXML() void TestQgsCoordinateReferenceSystem::readXML()
{ {
//QgsCoordinateReferenceSystem myCrs; //QgsCoordinateReferenceSystem myCrs;
//myCrs.createFromSrsId( 4326 ); //myCrs.createFromSrid( GEOSRID );
//QgsCoordinateReferenceSystem myCrs2; //QgsCoordinateReferenceSystem myCrs2;
//QVERIFY( myCrs2.readXML( QDomNode & theNode ) ); //QVERIFY( myCrs2.readXML( QDomNode & theNode ) );
} }
@ -215,54 +208,47 @@ void TestQgsCoordinateReferenceSystem::customSrsValidation()
QVERIFY( myCrs.isValid() ); QVERIFY( myCrs.isValid() );
*/ */
} }
void TestQgsCoordinateReferenceSystem::srsid()
{
QgsCoordinateReferenceSystem myCrs;
myCrs.createFromSrsId( 4326 );
QVERIFY( myCrs.srsid() == 4326 );
debugPrint( myCrs );
}
void TestQgsCoordinateReferenceSystem::postgisSrid() void TestQgsCoordinateReferenceSystem::postgisSrid()
{ {
QgsCoordinateReferenceSystem myCrs; QgsCoordinateReferenceSystem myCrs;
myCrs.createFromSrsId( 4326 ); myCrs.createFromSrid( GEOSRID );
QVERIFY( myCrs.postgisSrid() == 4326 ); QVERIFY( myCrs.postgisSrid() == GEOSRID );
debugPrint( myCrs ); debugPrint( myCrs );
} }
void TestQgsCoordinateReferenceSystem::ellipsoidAcronym() void TestQgsCoordinateReferenceSystem::ellipsoidAcronym()
{ {
QgsCoordinateReferenceSystem myCrs; QgsCoordinateReferenceSystem myCrs;
myCrs.createFromSrsId( 4326 ); myCrs.createFromSrid( GEOSRID );
QString myAcronym = myCrs.ellipsoidAcronym(); QString myAcronym = myCrs.ellipsoidAcronym();
QVERIFY( myAcronym == "foo" );
debugPrint( myCrs ); debugPrint( myCrs );
QVERIFY( myAcronym == "WGS84" );
} }
void TestQgsCoordinateReferenceSystem::toWkt() void TestQgsCoordinateReferenceSystem::toWkt()
{ {
QgsCoordinateReferenceSystem myCrs; QgsCoordinateReferenceSystem myCrs;
myCrs.createFromSrsId( 4326 ); myCrs.createFromSrid( GEOSRID );
QString myWkt = myCrs.toWkt(); QString myWkt = myCrs.toWkt();
QVERIFY( myWkt == "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AUTHORITY[\"EPSG\",\"4326\"]]" );
debugPrint( myCrs ); debugPrint( myCrs );
QVERIFY( myWkt == GEOWKT );
} }
void TestQgsCoordinateReferenceSystem::toProj4() void TestQgsCoordinateReferenceSystem::toProj4()
{ {
QgsCoordinateReferenceSystem myCrs; QgsCoordinateReferenceSystem myCrs;
myCrs.createFromSrsId( 4326 ); myCrs.createFromSrid( GEOSRID );
QVERIFY( myCrs.toProj4() == "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" );
debugPrint( myCrs ); debugPrint( myCrs );
QVERIFY( myCrs.toProj4() == GEOPROJ4 );
} }
void TestQgsCoordinateReferenceSystem::geographicFlag() void TestQgsCoordinateReferenceSystem::geographicFlag()
{ {
QgsCoordinateReferenceSystem myCrs; QgsCoordinateReferenceSystem myCrs;
myCrs.createFromSrsId( 4326 ); myCrs.createFromSrid( GEOSRID );
QVERIFY( myCrs.geographicFlag() ); QVERIFY( myCrs.geographicFlag() );
debugPrint( myCrs ); debugPrint( myCrs );
} }
void TestQgsCoordinateReferenceSystem::mapUnits() void TestQgsCoordinateReferenceSystem::mapUnits()
{ {
QgsCoordinateReferenceSystem myCrs; QgsCoordinateReferenceSystem myCrs;
myCrs.createFromSrsId( 4326 ); myCrs.createFromSrid( GEOSRID );
QVERIFY( myCrs.mapUnits() == QGis::Degrees ); QVERIFY( myCrs.mapUnits() == QGis::Degrees );
debugPrint( myCrs ); debugPrint( myCrs );
} }
@ -274,10 +260,12 @@ void TestQgsCoordinateReferenceSystem::setValidationHint()
debugPrint( myCrs ); debugPrint( myCrs );
} }
void TestQgsCoordinateReferenceSystem::debugPrint( QgsCoordinateReferenceSystem &theCrs ) void TestQgsCoordinateReferenceSystem::debugPrint(
QgsCoordinateReferenceSystem &theCrs )
{ {
QgsDebugMsg( "***SpatialRefSystem***" ); QgsDebugMsg( "***SpatialRefSystem***" );
QgsDebugMsg( "* Valid : " + ( theCrs.isValid() ? QString( "true" ) : QString( "false" ) ) ); QgsDebugMsg( "* Valid : " + ( theCrs.isValid() ? QString( "true" ) :
QString( "false" ) ) );
QgsDebugMsg( "* SrsId : " + QString::number( theCrs.srsid() ) ); QgsDebugMsg( "* SrsId : " + QString::number( theCrs.srsid() ) );
QgsDebugMsg( "* Proj4 : " + theCrs.toProj4() ); QgsDebugMsg( "* Proj4 : " + theCrs.toProj4() );
QgsDebugMsg( "* WKT : " + theCrs.toWkt() ); QgsDebugMsg( "* WKT : " + theCrs.toWkt() );
@ -298,4 +286,3 @@ void TestQgsCoordinateReferenceSystem::debugPrint( QgsCoordinateReferenceSystem
QTEST_MAIN( TestQgsCoordinateReferenceSystem ) QTEST_MAIN( TestQgsCoordinateReferenceSystem )
#include "moc_testqgscoordinatereferencesystem.cxx" #include "moc_testqgscoordinatereferencesystem.cxx"

View File

@ -89,7 +89,7 @@ void TestQgsMapRenderer::initTestCase()
mEncoding = "UTF-8"; mEncoding = "UTF-8";
QgsField myField1( "Value", QVariant::Int, "int", 10, 0, "Value on lon" ); QgsField myField1( "Value", QVariant::Int, "int", 10, 0, "Value on lon" );
mFields.insert( 0, myField1 ); mFields.insert( 0, myField1 );
mCRS = QgsCoordinateReferenceSystem( GEOWkt ); mCRS = QgsCoordinateReferenceSystem( GEOWKT );
// //
// Create the test dataset if it doesnt exist // Create the test dataset if it doesnt exist
// //

View File

@ -100,7 +100,7 @@ void TestQgsVectorFileWriter::initTestCase()
mEncoding = "UTF-8"; mEncoding = "UTF-8";
QgsField myField1( "Field1", QVariant::String, "String", 10, 0, "Field 1 comment" ); QgsField myField1( "Field1", QVariant::String, "String", 10, 0, "Field 1 comment" );
mFields.insert( 0, myField1 ); mFields.insert( 0, myField1 );
mCRS = QgsCoordinateReferenceSystem( GEOWkt ); mCRS = QgsCoordinateReferenceSystem( GEOWKT );
mPoint1 = QgsPoint( 10.0, 10.0 ); mPoint1 = QgsPoint( 10.0, 10.0 );
mPoint2 = QgsPoint( 15.0, 10.0 ); mPoint2 = QgsPoint( 15.0, 10.0 );
mPoint3 = QgsPoint( 15.0, 12.0 ); mPoint3 = QgsPoint( 15.0, 12.0 );

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 32 KiB