Skip to content

Commit 36c42d2

Browse files
committedDec 21, 2018
Check for proper error reporting in sqlite_fetch_and_increment
1 parent b4bc072 commit 36c42d2

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed
 

‎tests/src/core/testqgsexpression.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,16 +1565,24 @@ class TestQgsExpression: public QObject
15651565
QgsExpressionContext context;
15661566
QgsExpressionContextScope *scope = new QgsExpressionContextScope();
15671567
scope->setVariable( QStringLiteral( "test_database" ), dir.filePath( testGpkgName ) );
1568+
scope->setVariable( QStringLiteral( "username" ), "some_username" );
15681569
context << scope;
15691570

1570-
// Test failing
1571-
QgsExpression exp1( QStringLiteral( "sqlite_fetch_and_increment('/path/does/not/exist', 'T_KEY_OBJECT', 'T_LastUniqueId')" ) );
1571+
// Test database file does not exist
1572+
QgsExpression exp1( QStringLiteral( "sqlite_fetch_and_increment('/path/does/not/exist', 'T_KEY_OBJECT', 'T_LastUniqueId', 'T_Key', 'T_Id')" ) );
15721573

15731574
exp1.evaluate( &context );
15741575
QCOMPARE( exp1.hasEvalError(), true );
1575-
const QString evalErrorString = exp1.evalErrorString();
1576-
QVERIFY2( evalErrorString.contains( "/path/does/not/exist" ), QStringLiteral( "Path not found in %1" ).arg( evalErrorString ).toUtf8().constData() );
1577-
QVERIFY2( evalErrorString.contains( "Error" ), QStringLiteral( "\"Error\" not found in %1" ).arg( evalErrorString ).toUtf8().constData() );
1576+
const QString evalErrorString1 = exp1.evalErrorString();
1577+
QVERIFY2( evalErrorString1.contains( "/path/does/not/exist" ), QStringLiteral( "Path not found in %1" ).arg( evalErrorString1 ).toUtf8().constData() );
1578+
QVERIFY2( evalErrorString1.contains( "Error" ), QStringLiteral( "\"Error\" not found in %1" ).arg( evalErrorString1 ).toUtf8().constData() );
1579+
1580+
// Test default values are not properly quoted
1581+
QgsExpression exp2( 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', @username))" ) );
1582+
exp2.evaluate( &context );
1583+
QCOMPARE( exp2.hasEvalError(), true );
1584+
const QString evalErrorString2 = exp2.evalErrorString();
1585+
QVERIFY2( evalErrorString2.contains( "some_username" ), QStringLiteral( "'some_username' not found in '%1'" ).arg( evalErrorString2 ).toUtf8().constData() );
15781586

15791587
// Test incrementation logic
15801588
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'''))" ) );

0 commit comments

Comments
 (0)
Please sign in to comment.