Skip to content
Permalink
Browse files

Add tests for quoting sqlite values

  • Loading branch information
m-kuhn committed Dec 19, 2018
1 parent 12a6d9b commit 0437d4ad68693a10eab106805e3605319102aaf3
Showing with 42 additions and 0 deletions.
  1. +42 −0 tests/src/core/testqgssqliteutils.cpp
@@ -48,6 +48,10 @@ class TestQgsSqliteUtils : public QObject
void testPrintfUtf8();
void testQuotedString_data();
void testQuotedString();
void testQuotedIdentifier_data();
void testQuotedIdentifier();
void testQuotedValue_data();
void testQuotedValue();
};


@@ -110,6 +114,44 @@ void TestQgsSqliteUtils::testQuotedString()
QCOMPARE( QgsSqliteUtils::quotedString( input ), expected );
}

void TestQgsSqliteUtils::testQuotedIdentifier_data()
{
QTest::addColumn<QString>( "input" );
QTest::addColumn<QString>( "expected" );

QTest::newRow( "myColumn" ) << "myColumn" << "\"myColumn\"";
QTest::newRow( "my column" ) << "my column" << "\"my column\"";
}

void TestQgsSqliteUtils::testQuotedIdentifier()
{
QFETCH( QString, input );
QFETCH( QString, expected );

QCOMPARE( QgsSqliteUtils::quotedIdentifier( input ), expected );
}

void TestQgsSqliteUtils::testQuotedValue_data()
{
QTest::addColumn<QVariant>( "input" );
QTest::addColumn<QString>( "expected" );

QTest::newRow( "String" ) << QVariant( "Test string" ) << "'Test string'";
QTest::newRow( "Integer" ) << QVariant( 5 ) << "5";
QTest::newRow( "Double" ) << QVariant( 3.2 ) << "3.2";
QTest::newRow( "Boolean" ) << QVariant( true ) << "1";
QTest::newRow( "Escaped string" ) << QVariant( "It's a test string" ) << "'It''s a test string'";
QTest::newRow( "NULL" ) << QVariant() << "NULL";
}

void TestQgsSqliteUtils::testQuotedValue()
{
QFETCH( QVariant, input );
QFETCH( QString, expected );

QCOMPARE( QgsSqliteUtils::quotedValue( input ), expected );
}


QGSTEST_MAIN( TestQgsSqliteUtils )
#include "testqgssqliteutils.moc"

0 comments on commit 0437d4a

Please sign in to comment.
You can’t perform that action at this time.