Add test for sqlite_fetch_and_increment

This commit is contained in:
Matthias Kuhn 2018-12-20 10:43:37 +01:00
parent fea58316a4
commit 5d8f6371e1
No known key found for this signature in database
GPG Key ID: 7A7F1A1C90C3E6A7
2 changed files with 33 additions and 0 deletions

View File

@ -1556,6 +1556,39 @@ class TestQgsExpression: public QObject
}
}
void test_sqliteFetchAndIncrement()
{
QTemporaryDir dir;
QString testGpkgName = QStringLiteral( "humanbeings.gpkg" );
QFile::copy( QStringLiteral( TEST_DATA_DIR ) + '/' + testGpkgName, dir.filePath( testGpkgName ) );
QgsExpressionContext context;
QgsExpressionContextScope *scope = new QgsExpressionContextScope();
scope->setVariable( QStringLiteral( "test_database" ), dir.filePath( testGpkgName ) );
context << scope;
// Test failing
QgsExpression exp1( QStringLiteral( "sqlite_fetch_and_increment('/path/does/not/exist', 'T_KEY_OBJECT', 'T_LastUniqueId')" ) );
exp1.evaluate( &context );
QCOMPARE( exp1.hasEvalError(), true );
const QString evalErrorString = exp1.evalErrorString();
QVERIFY2( evalErrorString.contains( "/path/does/not/exist" ), QStringLiteral( "Path not found in %1" ).arg( evalErrorString ).toUtf8().constData() );
QVERIFY2( evalErrorString.contains( "Error" ), QStringLiteral( "\"Error\" not found in %1" ).arg( evalErrorString ).toUtf8().constData() );
// Test incrementation logic
QgsExpression exp( QStringLiteral( "sqlite_fetch_and_increment(@test_database, 'T_KEY_OBJECT', 'T_LastUniqueId', 'T_Key', 'T_Id', map('T_LastChange','date(''now'')','T_CreateDate','date(''now'')','T_User','''me'''))" ) );
QVariant res = exp.evaluate( &context );
QCOMPARE( res.toInt(), 0 );
res = exp.evaluate( &context );
if ( exp.hasEvalError() )
qDebug() << exp.evalErrorString();
QCOMPARE( exp.hasEvalError(), false );
QCOMPARE( res.toInt(), 1 );
}
void aggregate_data()
{
QTest::addColumn<QString>( "string" );

BIN
tests/testdata/humanbeings.gpkg vendored Normal file

Binary file not shown.