Skip to content

Commit

Permalink
[gpkg] Add test for gpkg subsetstring don't unlock mutex twice
Browse files Browse the repository at this point in the history
I wanted to add the test for gpkg subsetstring even if
it was not bugged, while testing that, I hit an assert
in Qt core that pointed me to double unlocked locks.
  • Loading branch information
elpaso committed Jan 25, 2018
1 parent cd0559d commit 698befa
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -5258,7 +5258,6 @@ QGISEXTERN bool saveStyle( const QString &uri, const QString &qmlStyle, const QS
if ( !hLayer )
{
errCause = QObject::tr( "Unable to save layer style. It's not possible to create the destination table on the database." );
mutex->unlock();
return false;
}
bool ok = true;
Expand Down Expand Up @@ -5322,7 +5321,6 @@ QGISEXTERN bool saveStyle( const QString &uri, const QString &qmlStyle, const QS
if ( !ok )
{
errCause = QObject::tr( "Unable to save layer style. It's not possible to create the destination table on the database." );
mutex->unlock();
return false;
}
}
Expand Down Expand Up @@ -5379,7 +5377,6 @@ QGISEXTERN bool saveStyle( const QString &uri, const QString &qmlStyle, const QS
QMessageBox::Yes | QMessageBox::No ) == QMessageBox::No ) )
{
errCause = QObject::tr( "Operation aborted" );
mutex->unlock();
return false;
}
bNew = false;
Expand Down Expand Up @@ -5431,8 +5428,6 @@ QGISEXTERN bool saveStyle( const QString &uri, const QString &qmlStyle, const QS
else
bFeatureOK = OGR_L_SetFeature( hLayer, hFeature.get() ) == OGRERR_NONE;

mutex->unlock();

if ( !bFeatureOK )
{
QgsMessageLog::logMessage( QObject::tr( "Error updating style" ) );
Expand Down
37 changes: 37 additions & 0 deletions tests/src/python/test_provider_ogr_gpkg.py
Expand Up @@ -13,6 +13,7 @@
__revision__ = '$Format:%H$'

import os
import re
import shutil
import sys
import tempfile
Expand Down Expand Up @@ -860,6 +861,42 @@ def testSubSetStringEditable_bug17795(self):
vl.setSubsetString('')
self.assertTrue(vl.dataProvider().capabilities() & isEditable)

def testSubsetStringExtent_bug17863(self):
"""Check that the extent is correct when applied in the ctor and when
modified after a subset string is set """

def _lessdigits(s):
return re.sub(r'(\d+\.\d{3})\d+', r'\1', s)

testPath = TEST_DATA_DIR + '/' + 'provider/bug_17795.gpkg|layername=bug_17795'
subSetString = '"name" = \'int\''
subSet = '|layername=bug_17795|subset=%s' % subSetString

# unfiltered
vl = QgsVectorLayer(testPath, 'test', 'ogr')
self.assertTrue(vl.isValid())
unfiltered_extent = _lessdigits(vl.extent().toString())
del(vl)

# filter after construction ...
subSet_vl2 = QgsVectorLayer(testPath, 'test', 'ogr')
self.assertEqual(_lessdigits(subSet_vl2.extent().toString()), unfiltered_extent)
# ... apply filter now!
subSet_vl2.setSubsetString(subSetString)
self.assertEqual(subSet_vl2.subsetString(), subSetString)
self.assertNotEqual(_lessdigits(subSet_vl2.extent().toString()), unfiltered_extent)
filtered_extent = _lessdigits(subSet_vl2.extent().toString())
del(subSet_vl2)

# filtered in constructor
subSet_vl = QgsVectorLayer(testPath + subSet, 'subset_test', 'ogr')
self.assertEqual(subSet_vl.subsetString(), subSetString)
self.assertTrue(subSet_vl.isValid())

# This was failing in bug 17863
self.assertEqual(_lessdigits(subSet_vl.extent().toString()), filtered_extent)
self.assertNotEqual(_lessdigits(subSet_vl.extent().toString()), unfiltered_extent)


if __name__ == '__main__':
unittest.main()
Binary file modified tests/testdata/provider/bug_17795.gpkg
Binary file not shown.

0 comments on commit 698befa

Please sign in to comment.