Skip to content

Commit 0437d4a

Browse files
committed
Add tests for quoting sqlite values
1 parent 12a6d9b commit 0437d4a

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/src/core/testqgssqliteutils.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ class TestQgsSqliteUtils : public QObject
4848
void testPrintfUtf8();
4949
void testQuotedString_data();
5050
void testQuotedString();
51+
void testQuotedIdentifier_data();
52+
void testQuotedIdentifier();
53+
void testQuotedValue_data();
54+
void testQuotedValue();
5155
};
5256

5357

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

117+
void TestQgsSqliteUtils::testQuotedIdentifier_data()
118+
{
119+
QTest::addColumn<QString>( "input" );
120+
QTest::addColumn<QString>( "expected" );
121+
122+
QTest::newRow( "myColumn" ) << "myColumn" << "\"myColumn\"";
123+
QTest::newRow( "my column" ) << "my column" << "\"my column\"";
124+
}
125+
126+
void TestQgsSqliteUtils::testQuotedIdentifier()
127+
{
128+
QFETCH( QString, input );
129+
QFETCH( QString, expected );
130+
131+
QCOMPARE( QgsSqliteUtils::quotedIdentifier( input ), expected );
132+
}
133+
134+
void TestQgsSqliteUtils::testQuotedValue_data()
135+
{
136+
QTest::addColumn<QVariant>( "input" );
137+
QTest::addColumn<QString>( "expected" );
138+
139+
QTest::newRow( "String" ) << QVariant( "Test string" ) << "'Test string'";
140+
QTest::newRow( "Integer" ) << QVariant( 5 ) << "5";
141+
QTest::newRow( "Double" ) << QVariant( 3.2 ) << "3.2";
142+
QTest::newRow( "Boolean" ) << QVariant( true ) << "1";
143+
QTest::newRow( "Escaped string" ) << QVariant( "It's a test string" ) << "'It''s a test string'";
144+
QTest::newRow( "NULL" ) << QVariant() << "NULL";
145+
}
146+
147+
void TestQgsSqliteUtils::testQuotedValue()
148+
{
149+
QFETCH( QVariant, input );
150+
QFETCH( QString, expected );
151+
152+
QCOMPARE( QgsSqliteUtils::quotedValue( input ), expected );
153+
}
154+
113155

114156
QGSTEST_MAIN( TestQgsSqliteUtils )
115157
#include "testqgssqliteutils.moc"

0 commit comments

Comments
 (0)