Skip to content
Permalink
Browse files

Add provider test for getting feature count with subset string set,

fix memory provider invalid count when subset set
  • Loading branch information
nyalldawson committed Feb 4, 2016
1 parent 9c91dd2 commit 27f1637fb1465f0d50dfaa3eddc5df5a857849da
Showing with 19 additions and 1 deletion.
  1. +12 −1 src/providers/memory/qgsmemoryprovider.cpp
  2. +7 −0 tests/src/python/providertestbase.py
@@ -289,7 +289,18 @@ QGis::WkbType QgsMemoryProvider::geometryType() const

long QgsMemoryProvider::featureCount() const
{
return mFeatures.count();
if ( mSubsetString.isEmpty() )
return mFeatures.count();

// subset string set, no alternative but testing each feature
QgsFeatureIterator fit = QgsFeatureIterator( new QgsMemoryFeatureIterator( new QgsMemoryFeatureSource( this ), true, QgsFeatureRequest().setSubsetOfAttributes( QgsAttributeList() ) ) );
int count = 0;
QgsFeature feature;
while ( fit.nextFeature( feature ) )
{
count++;
}
return count;
}

const QgsFields & QgsMemoryProvider::fields() const
@@ -363,6 +363,13 @@ def testUnique(self):
def testFeatureCount(self):
assert self.provider.featureCount() == 5, 'Got {}'.format(self.provider.featureCount())

#Add a subset string and test feature count
subset = self.getSubsetString()
self.provider.setSubsetString(subset)
count = self.provider.featureCount()
self.provider.setSubsetString(None)
assert count == 3, 'Got {}'.format(count)

def testClosedIterators(self):
""" Test behaviour of closed iterators """

0 comments on commit 27f1637

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