Skip to content

Commit 73e3ead

Browse files
committedDec 4, 2018
fix test and add test cases
1 parent be9f6bb commit 73e3ead

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed
 

‎tests/src/core/testqgsofflineediting.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,14 @@ void TestQgsOfflineEditing::createGeopackageAndSynchronizeBack()
143143
it.nextFeature( firstFeatureInAction );
144144

145145
//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() );
149149

150-
QgsFeature newFeature( mpLayer->fields() );
150+
QgsFeature newFeature( mpLayer->dataProvider()->fields() );
151+
newFeature.setAttribute( QStringLiteral( "Class" ), QStringLiteral( "Superjet" ) );
151152
mpLayer->startEditing();
152-
mpLayer->dataProvider()->addFeature( newFeature );
153+
mpLayer->addFeature( newFeature );
153154
mpLayer->commitChanges();
154155
QCOMPARE( mpLayer->featureCount(), numberOfFeatures + 1 );
155156

@@ -158,15 +159,24 @@ void TestQgsOfflineEditing::createGeopackageAndSynchronizeBack()
158159

159160
mpLayer = qobject_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayers().first() );
160161
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 );
163163
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" ) );
164168

165169
QgsFeature firstFeatureAfterAction;
166170
it = mpLayer->getFeatures();
167171
it.nextFeature( firstFeatureAfterAction );
168172

169173
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 );
170180
}
171181

172182
QGSTEST_MAIN( TestQgsOfflineEditing )

0 commit comments

Comments
 (0)
Please sign in to comment.