Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix test and add test cases
  • Loading branch information
signedav committed Dec 4, 2018
1 parent be9f6bb commit 73e3ead
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions tests/src/core/testqgsofflineediting.cpp
Expand Up @@ -143,13 +143,14 @@ void TestQgsOfflineEditing::createGeopackageAndSynchronizeBack()
it.nextFeature( firstFeatureInAction );

//compare some values
QCOMPARE( firstFeatureInAction.attribute( "Class" ).toString(), firstFeatureBeforeAction.attribute( "Class" ).toString() );
QCOMPARE( firstFeatureInAction.attribute( "Heading" ).toString(), firstFeatureBeforeAction.attribute( "Heading" ).toString() );
QCOMPARE( firstFeatureInAction.attribute( "Cabin Crew" ).toString(), firstFeatureBeforeAction.attribute( "Cabin Crew" ).toString() );
QCOMPARE( firstFeatureInAction.attribute( QStringLiteral( "Class" ) ).toString(), firstFeatureBeforeAction.attribute( QStringLiteral( "Class" ) ).toString() );
QCOMPARE( firstFeatureInAction.attribute( QStringLiteral( "Heading" ) ).toString(), firstFeatureBeforeAction.attribute( QStringLiteral( "Heading" ) ).toString() );
QCOMPARE( firstFeatureInAction.attribute( QStringLiteral( "Cabin Crew" ) ).toString(), firstFeatureBeforeAction.attribute( QStringLiteral( "Cabin Crew" ) ).toString() );

QgsFeature newFeature( mpLayer->fields() );
QgsFeature newFeature( mpLayer->dataProvider()->fields() );
newFeature.setAttribute( QStringLiteral( "Class" ), QStringLiteral( "Superjet" ) );
mpLayer->startEditing();
mpLayer->dataProvider()->addFeature( newFeature );
mpLayer->addFeature( newFeature );
mpLayer->commitChanges();
QCOMPARE( mpLayer->featureCount(), numberOfFeatures + 1 );

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

mpLayer = qobject_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayers().first() );
QCOMPARE( mpLayer->name(), QStringLiteral( "points" ) );
//following it's failing and I don't know why
//QCOMPARE( mpLayer->dataProvider()->featureCount(), numberOfFeatures + 1 );
QCOMPARE( mpLayer->dataProvider()->featureCount(), numberOfFeatures + 1 );
QCOMPARE( mpLayer->fields().size(), numberOfFields );
//get last feature
QgsFeature f = mpLayer->getFeature( mpLayer->dataProvider()->featureCount() - 1 );
qDebug() << "FID:" << f.id() << "Class:" << f.attribute( "Class" ).toString();
QCOMPARE( f.attribute( QStringLiteral( "Class" ) ).toString(), QStringLiteral( "Superjet" ) );

QgsFeature firstFeatureAfterAction;
it = mpLayer->getFeatures();
it.nextFeature( firstFeatureAfterAction );

QCOMPARE( firstFeatureAfterAction, firstFeatureBeforeAction );

//and delete the feature again
QgsFeatureIds idsToClean;
idsToClean << f.id();
mpLayer->dataProvider()->deleteFeatures( idsToClean );
QCOMPARE( mpLayer->dataProvider()->featureCount(), numberOfFeatures );
}

QGSTEST_MAIN( TestQgsOfflineEditing )
Expand Down

0 comments on commit 73e3ead

Please sign in to comment.