Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix test failures on windows
  • Loading branch information
jef-n committed Jul 17, 2015
1 parent e5c5454 commit 4d681f0
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 40 deletions.
5 changes: 3 additions & 2 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -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;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/providers/ogr/qgsogrconnpool.cpp
Expand Up @@ -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>()
Expand All @@ -30,4 +31,5 @@ QgsOgrConnPool::QgsOgrConnPool() : QgsConnectionPool<QgsOgrConn*, QgsOgrConnPool
QgsOgrConnPool::~QgsOgrConnPool()
{
QgsDebugCall;
sInstanceDestroyed = true;
}
13 changes: 13 additions & 0 deletions src/providers/ogr/qgsogrconnpool.h
Expand Up @@ -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 )

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

static QgsOgrConnPool sInstance;
static bool sInstanceDestroyed;
};


Expand Down
4 changes: 2 additions & 2 deletions src/providers/ogr/qgsogrfeatureiterator.cpp
Expand Up @@ -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 )
Expand Down
4 changes: 2 additions & 2 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -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()
Expand All @@ -473,7 +473,7 @@ QgsOgrProvider::~QgsOgrProvider()
extent_ = 0;
}

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

QgsAbstractFeatureSource* QgsOgrProvider::featureSource() const
Expand Down
69 changes: 36 additions & 33 deletions tests/src/core/regression1141.cpp
Expand Up @@ -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 ) );

Expand Down

0 comments on commit 4d681f0

Please sign in to comment.