Skip to content

Commit 4d681f0

Browse files
committed
Fix test failures on windows
1 parent e5c5454 commit 4d681f0

File tree

6 files changed

+59
-40
lines changed

6 files changed

+59
-40
lines changed

src/core/qgsvectorfilewriter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,9 +2098,10 @@ bool QgsVectorFileWriter::deleteShapeFile( QString theFileName )
20982098
bool ok = true;
20992099
foreach ( QString file, dir.entryList( filter ) )
21002100
{
2101-
if ( !QFile::remove( dir.canonicalPath() + "/" + file ) )
2101+
QFile f( dir.canonicalPath() + "/" + file );
2102+
if ( !f.remove( ) )
21022103
{
2103-
QgsDebugMsg( "Removing file failed : " + file );
2104+
QgsDebugMsg( QString( "Removing file %1 failed: %2" ).arg( file ).arg( f.errorString() ) );
21042105
ok = false;
21052106
}
21062107
}

src/providers/ogr/qgsogrconnpool.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
#include "qgsogrconnpool.h"
1717

1818
QgsOgrConnPool QgsOgrConnPool::sInstance;
19+
bool QgsOgrConnPool::sInstanceDestroyed = false;
1920

2021
QgsOgrConnPool* QgsOgrConnPool::instance()
2122
{
22-
return &sInstance;
23+
return sInstanceDestroyed ? 0 : &sInstance;
2324
}
2425

2526
QgsOgrConnPool::QgsOgrConnPool() : QgsConnectionPool<QgsOgrConn*, QgsOgrConnPoolGroup>()
@@ -30,4 +31,5 @@ QgsOgrConnPool::QgsOgrConnPool() : QgsConnectionPool<QgsOgrConn*, QgsOgrConnPool
3031
QgsOgrConnPool::~QgsOgrConnPool()
3132
{
3233
QgsDebugCall;
34+
sInstanceDestroyed = true;
3335
}

src/providers/ogr/qgsogrconnpool.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ class QgsOgrConnPool : public QgsConnectionPool<QgsOgrConn*, QgsOgrConnPoolGroup
111111
mMutex.unlock();
112112
}
113113

114+
static void refS( const QString &connInfo )
115+
{
116+
if ( instance() )
117+
instance()->ref( connInfo );
118+
}
119+
120+
static void unrefS( const QString &connInfo )
121+
{
122+
if ( instance() )
123+
instance()->unref( connInfo );
124+
}
125+
114126
protected:
115127
Q_DISABLE_COPY( QgsOgrConnPool )
116128

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

121133
static QgsOgrConnPool sInstance;
134+
static bool sInstanceDestroyed;
122135
};
123136

124137

src/providers/ogr/qgsogrfeatureiterator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,12 @@ QgsOgrFeatureSource::QgsOgrFeatureSource( const QgsOgrProvider* p )
342342
mFields = p->mAttributeFields;
343343
mDriverName = p->ogrDriverName;
344344
mOgrGeometryTypeFilter = wkbFlatten( p->mOgrGeometryTypeFilter );
345-
QgsOgrConnPool::instance()->ref( mFilePath );
345+
QgsOgrConnPool::refS( mFilePath );
346346
}
347347

348348
QgsOgrFeatureSource::~QgsOgrFeatureSource()
349349
{
350-
QgsOgrConnPool::instance()->unref( mFilePath );
350+
QgsOgrConnPool::unrefS( mFilePath );
351351
}
352352

353353
QgsFeatureIterator QgsOgrFeatureSource::getFeatures( const QgsFeatureRequest& request )

src/providers/ogr/qgsogrprovider.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
451451
<< QgsVectorDataProvider::NativeType( tr( "Date & Time" ), "datetime", QVariant::DateTime );
452452
}
453453

454-
QgsOgrConnPool::instance()->ref( mFilePath );
454+
QgsOgrConnPool::refS( mFilePath );
455455
}
456456

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

476-
QgsOgrConnPool::instance()->unref( mFilePath );
476+
QgsOgrConnPool::unrefS( mFilePath );
477477
}
478478

479479
QgsAbstractFeatureSource* QgsOgrProvider::featureSource() const

tests/src/core/regression1141.cpp

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -126,42 +126,45 @@ void Regression1141::diacriticalTest()
126126
{
127127
qDebug( "Creating test dataset: " );
128128

129-
QgsVectorFileWriter myWriter( mFileName,
130-
mEncoding,
131-
mFields,
132-
QGis::WKBPoint,
133-
&mCRS );
134-
135-
QgsPoint myPoint = QgsPoint( 10.0, 10.0 );
136-
// NOTE: don't delete this pointer again -
137-
// ownership is passed to the feature which will
138-
// delete it in its dtor!
139-
QgsGeometry * mypPointGeometry = QgsGeometry::fromPoint( myPoint );
140-
QgsFeature myFeature;
141-
myFeature.setGeometry( mypPointGeometry );
142-
myFeature.initAttributes( 1 );
143-
myFeature.setAttribute( 0, 10 );
144-
//
145-
// Write the feature to the filewriter
146-
// and check for errors
147-
//
148-
QVERIFY( myWriter.addFeature( myFeature ) );
149-
mError = myWriter.hasError();
150-
151-
if ( mError == QgsVectorFileWriter::ErrDriverNotFound )
152129
{
153-
std::cout << "Driver not found error" << std::endl;
154-
}
155-
else if ( mError == QgsVectorFileWriter::ErrCreateDataSource )
156-
{
157-
std::cout << "Create data source error" << std::endl;
158-
}
159-
else if ( mError == QgsVectorFileWriter::ErrCreateLayer )
160-
{
161-
std::cout << "Create layer error" << std::endl;
130+
QgsVectorFileWriter myWriter( mFileName,
131+
mEncoding,
132+
mFields,
133+
QGis::WKBPoint,
134+
&mCRS );
135+
136+
QgsPoint myPoint = QgsPoint( 10.0, 10.0 );
137+
// NOTE: don't delete this pointer again -
138+
// ownership is passed to the feature which will
139+
// delete it in its dtor!
140+
QgsGeometry * mypPointGeometry = QgsGeometry::fromPoint( myPoint );
141+
QgsFeature myFeature;
142+
myFeature.setGeometry( mypPointGeometry );
143+
myFeature.initAttributes( 1 );
144+
myFeature.setAttribute( 0, 10 );
145+
//
146+
// Write the feature to the filewriter
147+
// and check for errors
148+
//
149+
QVERIFY( myWriter.addFeature( myFeature ) );
150+
mError = myWriter.hasError();
151+
152+
if ( mError == QgsVectorFileWriter::ErrDriverNotFound )
153+
{
154+
std::cout << "Driver not found error" << std::endl;
155+
}
156+
else if ( mError == QgsVectorFileWriter::ErrCreateDataSource )
157+
{
158+
std::cout << "Create data source error" << std::endl;
159+
}
160+
else if ( mError == QgsVectorFileWriter::ErrCreateLayer )
161+
{
162+
std::cout << "Create layer error" << std::endl;
163+
}
164+
165+
QVERIFY( mError == QgsVectorFileWriter::NoError );
162166
}
163167

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

0 commit comments

Comments
 (0)