Skip to content
Permalink
Browse files
[BACKPORT] in progress test updates / fixes
  • Loading branch information
timlinux committed Apr 6, 2012
1 parent 845856e commit 6adf0f8037a6ab0f219df8d573691b09b73b5abe
@@ -211,7 +211,8 @@ bool QgsCoordinateReferenceSystem::createFromEpsg( 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 ) );
}

@@ -252,13 +253,19 @@ bool QgsCoordinateReferenceSystem::loadFromDb( QString db, QString expression, Q
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";
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
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 );
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(),
mySql.toUtf8().length(),
&myPreparedStatement, &myTail );
// XXX Need to free memory from the error msg if one is set
if ( myResult == SQLITE_OK && sqlite3_step( myPreparedStatement ) == SQLITE_ROW )
{
mSrsId = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 0 ) ).toLong();
mDescription = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 1 ) );
mSrsId = QString::fromUtf8(( char * )sqlite3_column_text(
myPreparedStatement, 0 ) ).toLong();
mDescription = QString::fromUtf8(( char * )sqlite3_column_text(
myPreparedStatement, 1 ) );
mProjectionAcronym = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 2 ) );
mEllipsoidAcronym = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 3 ) );
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)
*/
// 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() )
{
// Ticket #722 - aaronr
@@ -471,7 +478,7 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
myStart2 = myLat2RegExp.indexIn( theProj4String, myStart2 );
theProj4StringModified.replace( myStart2 + LAT_PREFIX_LEN, myLength2 - LAT_PREFIX_LEN, lat1Str );
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() )
{
myRecord = getRecord( sql + delim + datum + " order by deprecated" );
myRecord = getRecord( sql + delim + datum );
}

if ( myRecord.empty() )
{
// 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 )
{
// 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() )
{
// It's not, so try to add it
@@ -560,7 +567,7 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
if ( mIsValidFlag )
{
// 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" );
OSRDestroySpatialReference( mCRS );
mCRS = OSRNewSpatialReference( NULL );
mIsValidFlag = OSRImportFromProj4( mCRS, theProj4String.toLatin1().constData() ) == OGRERR_NONE;
mIsValidFlag =
OSRImportFromProj4( mCRS, theProj4String.toLatin1().constData() )
== OGRERR_NONE;
mWkt.clear();
setMapUnits();

@@ -901,9 +910,11 @@ void QgsCoordinateReferenceSystem::setMapUnits()
long QgsCoordinateReferenceSystem::findMatchingProj()
{
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!" );
return 0;
}
@@ -913,8 +924,10 @@ long QgsCoordinateReferenceSystem::findMatchingProj()
sqlite3_stmt *myPreparedStatement;
int myResult;

// Set up the query to retrieve the projection information needed to populate the list
QString mySql = QString( "select srs_id,parameters from tbl_srs where projection_acronym=%1 and ellipsoid_acronym=%2 order by deprecated" )
// Set up the query to retrieve the projection information
// 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( mEllipsoidAcronym ) );
// 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
{
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
@@ -1187,7 +1202,7 @@ QString QgsCoordinateReferenceSystem::proj4FromSrsId( const int theSrsId )

QString myDatabaseFileName;
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( "USER_CRS_START_ID = " + QString::number( USER_CRS_START_ID ) );
@@ -1419,7 +1434,7 @@ int QgsCoordinateReferenceSystem::syncDb()

const char *tail;
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 )
{
qCritical( "Could not prepare: %s [%s]\n", sql.toAscii().constData(), sqlite3_errmsg( database ) );
@@ -34,7 +34,8 @@ QgsRenderChecker::QgsRenderChecker( ) :
{

}
bool QgsRenderChecker::runTest( QString theTestName )
bool QgsRenderChecker::runTest( QString theTestName,
unsigned int theMismatchCount )
{
if ( mExpectedImageFile.isEmpty() )
{
@@ -53,11 +54,16 @@ bool QgsRenderChecker::runTest( QString theTestName )
//
// 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 ) );
QPainter myPainter( &myImage );
myPainter.setRenderHint( QPainter::Antialiasing );
mpMapRenderer->setOutputSize( QSize(
myExpectedImage.width(), myExpectedImage.height() ), myExpectedImage.logicalDpiX() );
myExpectedImage.width(),
myExpectedImage.height() ),
myExpectedImage.logicalDpiX() );
QTime myTime;
myTime.start();
mpMapRenderer->render( &myPainter );
@@ -69,12 +75,13 @@ bool QgsRenderChecker::runTest( QString theTestName )
//
mRenderedImageFile = QDir::tempPath() + QDir::separator() + theTestName + "_result.png";
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() )
{
@@ -190,7 +197,7 @@ bool QgsRenderChecker::compareImages( QString theTestName )
mReport += "</td></tr>";


if ( mMismatchCount == 0 )
if ( mMismatchCount <= theMismatchCount )
{
mReport += "<tr><td colspan = 3>\n";
mReport += "Test image and result image for " + theTestName + " are matched<br>";
@@ -49,17 +49,25 @@ class QgsRenderChecker
* Test using renderer to generate the image to be compared.
* @param theTestName - to be used as the basis for writing a file to
* 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
*/
bool runTest( QString theTestName );
bool runTest( QString theTestName, unsigned int theMismatchCount=0 );

/**
* Test using two arbitary images (map renderer will not be used)
* @param theTestName - to be used as the basis for writing a file to
* 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.
*/
bool compareImages( QString theTestName );
bool compareImages( QString theTestName, unsigned int theMismatchCount=0 );
private:
QString mReport;
QString mExpectedImageFile;
@@ -97,7 +97,7 @@ void Regression1141::diacriticalTest()
mEncoding = "UTF-8";
QgsField myField( "ąęćń", QVariant::Int, "int", 10, 0, "Value on lon" );
mFields.insert( 0, myField );
mCRS = QgsCoordinateReferenceSystem( GEOWkt );
mCRS = QgsCoordinateReferenceSystem( GEOWKT );

qDebug( "Checking test dataset exists...\n%s", mFileName.toLocal8Bit().constData() );

@@ -110,7 +110,8 @@ void Regression992::regression992()
QgsRenderChecker myChecker;
myChecker.setExpectedImage( myTestDataDir + "expected_rgbwcmyk01_YeGeo.jp2.png" );
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();
QVERIFY( myResultFlag );
}

0 comments on commit 6adf0f8

Please sign in to comment.