Skip to content

Commit

Permalink
Add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jul 6, 2024
1 parent 667eb85 commit f00e9a9
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/src/gui/testqgsattributeform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class TestQgsAttributeForm : public QObject
void testAttributeFormInterface();
void testDefaultValueUpdate();
void testDefaultValueUpdateRecursion();
void testParentFeatureUpdate();
void testSameFieldSync();
void testZeroDoubles();
void testMinimumWidth();
Expand Down Expand Up @@ -1111,6 +1112,38 @@ void TestQgsAttributeForm::testDefaultValueUpdateRecursion()
QCOMPARE( ww3->value().toInt(), 43 );
}

void TestQgsAttributeForm::testParentFeatureUpdate()
{
// make a temporary layer to check through
const QString def = QStringLiteral( "Point?field=col0:integer" );
QgsVectorLayer *layer = new QgsVectorLayer( def, QStringLiteral( "test" ), QStringLiteral( "memory" ) );
layer->setDefaultValueDefinition( 0, QgsDefaultValue( QStringLiteral( "current_parent_value('colZero\')" ), true ) );
layer->startEditing();

// initalize parent feature
QgsFields parentFields;
parentFields.append( QgsField( QStringLiteral( "colZero" ), QMetaType::Type::Int ) );

QgsFeature parentFeature( parentFields, 1 );
parentFeature.setAttribute( QStringLiteral( "colZero" ), 10 );

// initalize child feature
QgsFeature feature( layer->dataProvider()->fields(), 1 );

// build a form
QgsAttributeEditorContext context;
context.setParentFormFeature( parentFeature );
QgsAttributeForm form( layer, feature, context );

// get wrappers for each widget
QgsEditorWidgetWrapper *ww0;
ww0 = qobject_cast<QgsEditorWidgetWrapper *>( form.mWidgets[0] );

form.parentFormValueChanged( QStringLiteral( "colZero" ), 20 );

QCOMPARE( ww0->value().toInt(), 20 );
}

void TestQgsAttributeForm::testSameFieldSync()
{
// Check that widget synchronisation works when a form contains the same field several times
Expand Down

0 comments on commit f00e9a9

Please sign in to comment.