Skip to content
Permalink
Browse files

Fix test failures on windows

(cherry picked from commit 4d681f0)
  • Loading branch information
jef-n committed Jul 17, 2015
1 parent 34de8df commit 15e5cf05819130a2b326fff2695b121226cf45d6
@@ -2098,9 +2098,10 @@ bool QgsVectorFileWriter::deleteShapeFile( QString theFileName )
bool ok = true;
foreach ( QString file, dir.entryList( filter ) )
{
if ( !QFile::remove( dir.canonicalPath() + "/" + file ) )
QFile f( dir.canonicalPath() + "/" + file );
if ( !f.remove( ) )
{
QgsDebugMsg( "Removing file failed : " + file );
QgsDebugMsg( QString( "Removing file %1 failed: %2" ).arg( file ).arg( f.errorString() ) );
ok = false;
}
}
@@ -16,10 +16,11 @@
#include "qgsogrconnpool.h"

QgsOgrConnPool QgsOgrConnPool::sInstance;
bool QgsOgrConnPool::sInstanceDestroyed = false;

QgsOgrConnPool* QgsOgrConnPool::instance()
{
return &sInstance;
return sInstanceDestroyed ? 0 : &sInstance;
}

QgsOgrConnPool::QgsOgrConnPool() : QgsConnectionPool<QgsOgrConn*, QgsOgrConnPoolGroup>()
@@ -30,4 +31,5 @@ QgsOgrConnPool::QgsOgrConnPool() : QgsConnectionPool<QgsOgrConn*, QgsOgrConnPool
QgsOgrConnPool::~QgsOgrConnPool()
{
QgsDebugCall;
sInstanceDestroyed = true;
}
@@ -111,6 +111,18 @@ class QgsOgrConnPool : public QgsConnectionPool<QgsOgrConn*, QgsOgrConnPoolGroup
mMutex.unlock();
}

static void refS( const QString &connInfo )
{
if ( instance() )
instance()->ref( connInfo );
}

static void unrefS( const QString &connInfo )
{
if ( instance() )
instance()->unref( connInfo );
}

protected:
Q_DISABLE_COPY( QgsOgrConnPool )

@@ -119,6 +131,7 @@ class QgsOgrConnPool : public QgsConnectionPool<QgsOgrConn*, QgsOgrConnPoolGroup
~QgsOgrConnPool();

static QgsOgrConnPool sInstance;
static bool sInstanceDestroyed;
};


@@ -342,12 +342,12 @@ QgsOgrFeatureSource::QgsOgrFeatureSource( const QgsOgrProvider* p )
mFields = p->mAttributeFields;
mDriverName = p->ogrDriverName;
mOgrGeometryTypeFilter = wkbFlatten( p->mOgrGeometryTypeFilter );
QgsOgrConnPool::instance()->ref( mFilePath );
QgsOgrConnPool::refS( mFilePath );
}

QgsOgrFeatureSource::~QgsOgrFeatureSource()
{
QgsOgrConnPool::instance()->unref( mFilePath );
QgsOgrConnPool::unrefS( mFilePath );
}

QgsFeatureIterator QgsOgrFeatureSource::getFeatures( const QgsFeatureRequest& request )
@@ -451,7 +451,7 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
<< QgsVectorDataProvider::NativeType( tr( "Date & Time" ), "datetime", QVariant::DateTime );
}

QgsOgrConnPool::instance()->ref( mFilePath );
QgsOgrConnPool::refS( mFilePath );
}

QgsOgrProvider::~QgsOgrProvider()
@@ -473,7 +473,7 @@ QgsOgrProvider::~QgsOgrProvider()
extent_ = 0;
}

QgsOgrConnPool::instance()->unref( mFilePath );
QgsOgrConnPool::unrefS( mFilePath );
}

QgsAbstractFeatureSource* QgsOgrProvider::featureSource() const
@@ -126,42 +126,45 @@ void Regression1141::diacriticalTest()
{
qDebug( "Creating test dataset: " );

QgsVectorFileWriter myWriter( mFileName,
mEncoding,
mFields,
QGis::WKBPoint,
&mCRS );

QgsPoint myPoint = QgsPoint( 10.0, 10.0 );
// NOTE: don't delete this pointer again -
// ownership is passed to the feature which will
// delete it in its dtor!
QgsGeometry * mypPointGeometry = QgsGeometry::fromPoint( myPoint );
QgsFeature myFeature;
myFeature.setGeometry( mypPointGeometry );
myFeature.initAttributes( 1 );
myFeature.setAttribute( 0, 10 );
//
// Write the feature to the filewriter
// and check for errors
//
QVERIFY( myWriter.addFeature( myFeature ) );
mError = myWriter.hasError();

if ( mError == QgsVectorFileWriter::ErrDriverNotFound )
{
std::cout << "Driver not found error" << std::endl;
}
else if ( mError == QgsVectorFileWriter::ErrCreateDataSource )
{
std::cout << "Create data source error" << std::endl;
}
else if ( mError == QgsVectorFileWriter::ErrCreateLayer )
{
std::cout << "Create layer error" << std::endl;
QgsVectorFileWriter myWriter( mFileName,
mEncoding,
mFields,
QGis::WKBPoint,
&mCRS );

QgsPoint myPoint = QgsPoint( 10.0, 10.0 );
// NOTE: don't delete this pointer again -
// ownership is passed to the feature which will
// delete it in its dtor!
QgsGeometry * mypPointGeometry = QgsGeometry::fromPoint( myPoint );
QgsFeature myFeature;
myFeature.setGeometry( mypPointGeometry );
myFeature.initAttributes( 1 );
myFeature.setAttribute( 0, 10 );
//
// Write the feature to the filewriter
// and check for errors
//
QVERIFY( myWriter.addFeature( myFeature ) );
mError = myWriter.hasError();

if ( mError == QgsVectorFileWriter::ErrDriverNotFound )
{
std::cout << "Driver not found error" << std::endl;
}
else if ( mError == QgsVectorFileWriter::ErrCreateDataSource )
{
std::cout << "Create data source error" << std::endl;
}
else if ( mError == QgsVectorFileWriter::ErrCreateLayer )
{
std::cout << "Create layer error" << std::endl;
}

QVERIFY( mError == QgsVectorFileWriter::NoError );
}

QVERIFY( mError == QgsVectorFileWriter::NoError );
// Now check we can delete it again ok
QVERIFY( QgsVectorFileWriter::deleteShapeFile( mFileName ) );

0 comments on commit 15e5cf0

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