From kde-commits Tue Jun 30 22:09:05 2015 From: Jaroslaw Staniek Date: Tue, 30 Jun 2015 22:09:05 +0000 To: kde-commits Subject: [kdb] autotests/tools: Add autotest for all KDb::escapeIdentifier() variants Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=143570215411535 Git commit fa9bc21e022ee1a4f186ee6245811676ebd804c7 by Jaroslaw Staniek. Committed on 30/06/2015 at 16:51. Pushed by staniek into branch 'master'. Add autotest for all KDb::escapeIdentifier() variants M +29 -7 autotests/tools/IdentifierTest.cpp M +2 -0 autotests/tools/IdentifierTest.h http://commits.kde.org/kdb/fa9bc21e022ee1a4f186ee6245811676ebd804c7 diff --git a/autotests/tools/IdentifierTest.cpp b/autotests/tools/Identifie= rTest.cpp index b1228f2..a0b81bf 100644 --- a/autotests/tools/IdentifierTest.cpp +++ b/autotests/tools/IdentifierTest.cpp @@ -56,13 +56,13 @@ void IdentifierTest::testIsIdentifier_data() QTest::addColumn("result"); QTest::newRow("empty") << "" << false; QTest::newRow("empty") << QString() << false; - QTest::newRow("empty") << "\0" << false; - QTest::newRow("empty") << " " << false; - QTest::newRow("empty") << "7" << false; - QTest::newRow("empty") << "_" << true; - QTest::newRow("empty") << "abc_2" << true; - QTest::newRow("empty") << "Abc_2" << true; - QTest::newRow("empty") << "_7" << true; + QTest::newRow("zero") << "\0" << false; + QTest::newRow("space") << " " << false; + QTest::newRow("number") << "7" << false; + QTest::newRow("underscore") << "_" << true; + QTest::newRow("alpha") << "abc_2" << true; + QTest::newRow("upper") << "Abc_2" << true; + QTest::newRow("upper2") << "_7" << true; } = void IdentifierTest::testIsIdentifier() @@ -72,6 +72,28 @@ void IdentifierTest::testIsIdentifier() QCOMPARE(KDb::isIdentifier(string), result); } = +void IdentifierTest::escapeIdentifier_data() +{ + QTest::addColumn("string"); + QTest::addColumn("result"); + QTest::newRow("empty") << "" << QString(); + QTest::newRow("empty") << QString() << QString(); + QTest::newRow("\"") << "\"" << "\"\""; + QTest::newRow("\"-\"") << "\"-\"" << "\"\"-\"\""; + QTest::newRow("\t") << "\t" << "\t"; + QTest::newRow("alpha") << "a b" << "a b"; +} + +void IdentifierTest::escapeIdentifier() +{ + QFETCH(QString, string); + QFETCH(QString, result); + QCOMPARE(KDb::escapeIdentifier(string), result); + QCOMPARE(KDb::escapeIdentifier(string.toLatin1()), result.toLatin1()); + QCOMPARE(KDb::escapeIdentifierAndAddQuotes(string), QString::fromLatin= 1("\"%1\"").arg(result)); + QCOMPARE(KDb::escapeIdentifierAndAddQuotes(string.toLatin1()), '"' + r= esult.toLatin1() + '"'); +} + void IdentifierTest::cleanupTestCase() { } diff --git a/autotests/tools/IdentifierTest.h b/autotests/tools/IdentifierT= est.h index d7627d4..3a1f27c 100644 --- a/autotests/tools/IdentifierTest.h +++ b/autotests/tools/IdentifierTest.h @@ -31,6 +31,8 @@ private Q_SLOTS: void testStringToIdentifier(); void testIsIdentifier_data(); void testIsIdentifier(); + void escapeIdentifier_data(); + void escapeIdentifier(); void cleanupTestCase(); }; =