@@ -194,6 +194,54 @@ class TestQgsVectorLayer : public QObject
194194 QVERIFY ( myCount == 3 );
195195 }
196196
197+ void QgsVectorLayerGetValues ()
198+ {
199+ QgsVectorLayer* layer = new QgsVectorLayer ( " Point?field=col1:real" , " layer" , " memory" );
200+ QVERIFY ( layer->isValid () );
201+ QgsFeature f1 ( layer->dataProvider ()->fields (), 1 );
202+ f1.setAttribute ( " col1" , 1 );
203+ QgsFeature f2 ( layer->dataProvider ()->fields (), 2 );
204+ f2.setAttribute ( " col1" , 2 );
205+ QgsFeature f3 ( layer->dataProvider ()->fields (), 3 );
206+ f3.setAttribute ( " col1" , 3 );
207+ QgsFeature f4 ( layer->dataProvider ()->fields (), 4 );
208+ f4.setAttribute ( " col1" , QVariant () );
209+ layer->dataProvider ()->addFeatures ( QgsFeatureList () << f1 << f2 << f3 << f4 );
210+
211+ bool ok;
212+ QList<QVariant> varList = layer->getValues ( " col1" , ok );
213+ QVERIFY ( ok );
214+ QCOMPARE ( varList.length (), 4 );
215+ QCOMPARE ( varList.at ( 0 ), QVariant ( 1 ) );
216+ QCOMPARE ( varList.at ( 1 ), QVariant ( 2 ) );
217+ QCOMPARE ( varList.at ( 2 ), QVariant ( 3 ) );
218+ QCOMPARE ( varList.at ( 3 ), QVariant () );
219+
220+ QList<double > doubleList = layer->getDoubleValues ( " col1" , ok );
221+ QVERIFY ( ok );
222+ QCOMPARE ( doubleList.length (), 3 );
223+ QCOMPARE ( doubleList.at ( 0 ), 1.0 );
224+ QCOMPARE ( doubleList.at ( 1 ), 2.0 );
225+ QCOMPARE ( doubleList.at ( 2 ), 3.0 );
226+
227+ QList<QVariant> expVarList = layer->getValues ( " tostring(col1) || ' '" , ok );
228+ QVERIFY ( ok );
229+ QCOMPARE ( expVarList.length (), 4 );
230+ QCOMPARE ( expVarList.at ( 0 ).toString (), QString ( " 1 " ) );
231+ QCOMPARE ( expVarList.at ( 1 ).toString (), QString ( " 2 " ) );
232+ QCOMPARE ( expVarList.at ( 2 ).toString (), QString ( " 3 " ) );
233+ QCOMPARE ( expVarList.at ( 3 ), QVariant () );
234+
235+ QList<double > expDoubleList = layer->getDoubleValues ( " col1 * 2" , ok );
236+ QVERIFY ( ok );
237+ QCOMPARE ( expDoubleList.length (), 3 );
238+ QCOMPARE ( expDoubleList.at ( 0 ), 2.0 );
239+ QCOMPARE ( expDoubleList.at ( 1 ), 4.0 );
240+ QCOMPARE ( expDoubleList.at ( 2 ), 6.0 );
241+
242+ delete layer;
243+ }
244+
197245 void QgsVectorLayerstorageType () {}
198246 void QgsVectorLayercapabilitiesString () {}
199247 void QgsVectorLayerdataComment () {}
0 commit comments