Skip to content

Commit

Permalink
prepared tests for gpkg - not yet active
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed Jan 7, 2019
1 parent e9e7c39 commit ae1ab67
Showing 1 changed file with 98 additions and 1 deletion.
99 changes: 98 additions & 1 deletion tests/src/gui/testqgsvaluerelationwidgetwrapper.cpp
Expand Up @@ -33,6 +33,9 @@ class TestQgsValueRelationWidgetWrapper : public QObject
public:
TestQgsValueRelationWidgetWrapper() = default;

private:
QTemporaryDir tempDir;

private slots:
void initTestCase(); // will be called before the first testfunction is executed.
void cleanupTestCase(); // will be called after the last testfunction was executed.
Expand All @@ -45,6 +48,7 @@ class TestQgsValueRelationWidgetWrapper : public QObject
//! Checks that a related value of 0 is not interpreted as a NULL
void testZeroIndexInRelatedTable();
void testWithJsonInPostgres();
void testWithJsonInGPKG();
};

void TestQgsValueRelationWidgetWrapper::initTestCase()
Expand Down Expand Up @@ -389,7 +393,7 @@ void TestQgsValueRelationWidgetWrapper::testWithJsonInPostgres()

QCOMPARE( vl_json->fields().at( 1 ).type(), QVariant::Map );

// build a value relation widget wrapper for bikes
// build a value relation widget wrapper
QgsValueRelationWidgetWrapper w_favoriteauthors( vl_json, vl_json->fields().indexOf( QStringLiteral( "jvalue" ) ), nullptr, nullptr );
QVariantMap cfg_favoriteautors;
cfg_favoriteautors.insert( QStringLiteral( "Layer" ), vl_authors->id() );
Expand Down Expand Up @@ -450,5 +454,98 @@ void TestQgsValueRelationWidgetWrapper::testWithJsonInPostgres()
QCOMPARE( w_favoriteauthors.mTableWidget->item( 5, 0 )->checkState(), Qt::Checked );
}


void TestQgsValueRelationWidgetWrapper::testWithJsonInGPKG()
{
/* prepared - functionality needs to be integrated first
// create ogr gpkg layers
QString myFileName( TEST_DATA_DIR ); //defined in CmakeLists.txt
QString myTempDirName = tempDir.path();
QFile::copy( myFileName + "/provider/test_json.gpkg", myTempDirName + "/test_json.gpkg" );
QString myTempFileName = myTempDirName + "/test_json.gpkg";
QFileInfo myMapFileInfo( myTempFileName );
QgsVectorLayer *vl_json = new QgsVectorLayer( myMapFileInfo.filePath()+"|layername=reader", "test", QStringLiteral( "ogr" ) );
QgsVectorLayer *vl_authors = new QgsVectorLayer( myMapFileInfo.filePath()+"|layername=author", "test", QStringLiteral( "ogr" ) );
QVERIFY( vl_json->isValid() );
QVERIFY( vl_authors->isValid() );
QgsProject::instance()->addMapLayer( vl_json, false, false );
QgsProject::instance()->addMapLayer( vl_authors, false, false );
// build a value relation widget wrapper for bikes
QgsValueRelationWidgetWrapper w_favoriteauthors( vl_json, vl_json->fields().indexOf( QStringLiteral( "json_content" ) ), nullptr, nullptr );
QVariantMap cfg_favoriteautors;
cfg_favoriteautors.insert( QStringLiteral( "Layer" ), vl_authors->id() );
cfg_favoriteautors.insert( QStringLiteral( "Key" ), QStringLiteral( "fid" ) );
cfg_favoriteautors.insert( QStringLiteral( "Value" ), QStringLiteral( "NAME" ) );
cfg_favoriteautors.insert( QStringLiteral( "AllowMulti" ), true );
cfg_favoriteautors.insert( QStringLiteral( "NofColumns" ), 1 );
cfg_favoriteautors.insert( QStringLiteral( "AllowNull" ), false );
cfg_favoriteautors.insert( QStringLiteral( "OrderByValue" ), false );
cfg_favoriteautors.insert( QStringLiteral( "UseCompleter" ), false );
w_favoriteauthors.setConfig( cfg_favoriteautors );
w_favoriteauthors.widget();
w_favoriteauthors.setEnabled( true );
//check if set up nice
QCOMPARE( w_favoriteauthors.mTableWidget->rowCount(), 6 );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 0, 0 )->text(), QStringLiteral( "Erich Gamma" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 0, 0 )->data( Qt::UserRole ).toString(), QStringLiteral( "1" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 1, 0 )->text(), QStringLiteral( "Richard Helm" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 1, 0 )->data( Qt::UserRole ).toString(), QStringLiteral( "2" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 2, 0 )->text(), QStringLiteral( "Ralph Johnson" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 2, 0 )->data( Qt::UserRole ).toString(), QStringLiteral( "3" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 3, 0 )->text(), QStringLiteral( "John Vlissides" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 3, 0 )->data( Qt::UserRole ).toString(), QStringLiteral( "4" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 4, 0 )->text(), QStringLiteral( "Douglas Adams" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 4, 0 )->data( Qt::UserRole ).toString(), QStringLiteral( "5" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 5, 0 )->text(), QStringLiteral( "Ken Follett" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 5, 0 )->data( Qt::UserRole ).toString(), QStringLiteral( "6" ) );
//check if first feature checked correctly [4]
w_favoriteauthors.setFeature( vl_json->getFeature( 1 ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 0, 0 )->text(), QStringLiteral( "Erich Gamma" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 0, 0 )->checkState(), Qt::Unchecked );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 1, 0 )->text(), QStringLiteral( "Richard Helm" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 1, 0 )->checkState(), Qt::Unchecked );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 2, 0 )->text(), QStringLiteral( "Ralph Johnson" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 2, 0 )->checkState(), Qt::Unchecked );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 3, 0 )->text(), QStringLiteral( "John Vlissides" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 3, 0 )->checkState(), Qt::Unchecked );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 4, 0 )->text(), QStringLiteral( "Douglas Adams" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 4, 0 )->checkState(), Qt::Checked );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 5, 0 )->text(), QStringLiteral( "Ken Follett" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 5, 0 )->checkState(), Qt::Unchecked );
//check other authors
w_favoriteauthors.mTableWidget->item( 0, 0 )->setCheckState( Qt::Checked);
w_favoriteauthors.mTableWidget->item( 2, 0 )->setCheckState( Qt::Checked);
w_favoriteauthors.mTableWidget->item( 5, 0 )->setCheckState( Qt::Checked);
//check if first feature checked correctly 0, 2, 4, 5
w_favoriteauthors.setFeature( vl_json->getFeature( 1 ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 0, 0 )->text(), QStringLiteral( "Erich Gamma" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 0, 0 )->checkState(), Qt::Checked );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 1, 0 )->text(), QStringLiteral( "Richard Helm" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 1, 0 )->checkState(), Qt::Unchecked );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 2, 0 )->text(), QStringLiteral( "Ralph Johnson" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 2, 0 )->checkState(), Qt::Checked );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 3, 0 )->text(), QStringLiteral( "John Vlissides" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 3, 0 )->checkState(), Qt::Unchecked );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 4, 0 )->text(), QStringLiteral( "Douglas Adams" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 4, 0 )->checkState(), Qt::Checked );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 5, 0 )->text(), QStringLiteral( "Ken Follett" ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 5, 0 )->checkState(), Qt::Checked );
// check if stored correctly
vl_json->commitChanges();
QVariantList expected_vl;
expected_vl << 0 << 2 << 4 << 5;
QCOMPARE( vl_json->getFeature( 1 ).attribute( QStringLiteral( "json_content" ) ), expected_vl );
*/
}


QGSTEST_MAIN( TestQgsValueRelationWidgetWrapper )
#include "testqgsvaluerelationwidgetwrapper.moc"

0 comments on commit ae1ab67

Please sign in to comment.