@@ -143,13 +143,14 @@ void TestQgsOfflineEditing::createGeopackageAndSynchronizeBack()
143
143
it.nextFeature ( firstFeatureInAction );
144
144
145
145
// compare some values
146
- QCOMPARE ( firstFeatureInAction.attribute ( " Class" ).toString (), firstFeatureBeforeAction.attribute ( " Class" ).toString () );
147
- QCOMPARE ( firstFeatureInAction.attribute ( " Heading" ).toString (), firstFeatureBeforeAction.attribute ( " Heading" ).toString () );
148
- QCOMPARE ( firstFeatureInAction.attribute ( " Cabin Crew" ).toString (), firstFeatureBeforeAction.attribute ( " Cabin Crew" ).toString () );
146
+ QCOMPARE ( firstFeatureInAction.attribute ( QStringLiteral ( " Class" ) ) .toString (), firstFeatureBeforeAction.attribute ( QStringLiteral ( " Class" ) ).toString () );
147
+ QCOMPARE ( firstFeatureInAction.attribute ( QStringLiteral ( " Heading" ) ) .toString (), firstFeatureBeforeAction.attribute ( QStringLiteral ( " Heading" ) ).toString () );
148
+ QCOMPARE ( firstFeatureInAction.attribute ( QStringLiteral ( " Cabin Crew" ) ) .toString (), firstFeatureBeforeAction.attribute ( QStringLiteral ( " Cabin Crew" ) ).toString () );
149
149
150
- QgsFeature newFeature ( mpLayer->fields () );
150
+ QgsFeature newFeature ( mpLayer->dataProvider ()->fields () );
151
+ newFeature.setAttribute ( QStringLiteral ( " Class" ), QStringLiteral ( " Superjet" ) );
151
152
mpLayer->startEditing ();
152
- mpLayer->dataProvider ()-> addFeature ( newFeature );
153
+ mpLayer->addFeature ( newFeature );
153
154
mpLayer->commitChanges ();
154
155
QCOMPARE ( mpLayer->featureCount (), numberOfFeatures + 1 );
155
156
@@ -158,15 +159,24 @@ void TestQgsOfflineEditing::createGeopackageAndSynchronizeBack()
158
159
159
160
mpLayer = qobject_cast<QgsVectorLayer *>( QgsProject::instance ()->mapLayers ().first () );
160
161
QCOMPARE ( mpLayer->name (), QStringLiteral ( " points" ) );
161
- // following it's failing and I don't know why
162
- // QCOMPARE( mpLayer->dataProvider()->featureCount(), numberOfFeatures + 1 );
162
+ QCOMPARE ( mpLayer->dataProvider ()->featureCount (), numberOfFeatures + 1 );
163
163
QCOMPARE ( mpLayer->fields ().size (), numberOfFields );
164
+ // get last feature
165
+ QgsFeature f = mpLayer->getFeature ( mpLayer->dataProvider ()->featureCount () - 1 );
166
+ qDebug () << " FID:" << f.id () << " Class:" << f.attribute ( " Class" ).toString ();
167
+ QCOMPARE ( f.attribute ( QStringLiteral ( " Class" ) ).toString (), QStringLiteral ( " Superjet" ) );
164
168
165
169
QgsFeature firstFeatureAfterAction;
166
170
it = mpLayer->getFeatures ();
167
171
it.nextFeature ( firstFeatureAfterAction );
168
172
169
173
QCOMPARE ( firstFeatureAfterAction, firstFeatureBeforeAction );
174
+
175
+ // and delete the feature again
176
+ QgsFeatureIds idsToClean;
177
+ idsToClean << f.id ();
178
+ mpLayer->dataProvider ()->deleteFeatures ( idsToClean );
179
+ QCOMPARE ( mpLayer->dataProvider ()->featureCount (), numberOfFeatures );
170
180
}
171
181
172
182
QGSTEST_MAIN ( TestQgsOfflineEditing )
0 commit comments