diff options
| author | 2017-02-09 04:37:26 -0500 | |
|---|---|---|
| committer | 2017-02-09 04:37:26 -0500 | |
| commit | c9d6debf9015b7853c3e061bbc64a555d85e2fcd (patch) | |
| tree | 53341bc57ae9fbad2beb5b6c08d97a68bee0ec8e /SQLiteStudio3/Tests | |
| parent | d5caba2b1f36dc3b92fa705a06097d0597fa2ddd (diff) | |
| parent | d9aa870e5d509cc7309ab82dd102a937ab58613a (diff) | |
Merge tag 'upstream/3.1.1+dfsg1'
Upstream version 3.1.1+dfsg1
# gpg: Signature made Thu 09 Feb 2017 04:37:24 AM EST
# gpg: using RSA key 5001E1B09AA3744B
# gpg: issuer "unit193@ubuntu.com"
# gpg: Good signature from "Unit 193 <unit193@ubuntu.com>" [unknown]
# gpg: aka "Unit 193 <unit193@gmail.com>" [unknown]
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg: There is no indication that the signature belongs to the owner.
# Primary key fingerprint: 8DB3 E586 865D 2B4A 2B18 5A5C 5001 E1B0 9AA3 744B
Diffstat (limited to 'SQLiteStudio3/Tests')
| -rw-r--r-- | SQLiteStudio3/Tests/ParserTest/tst_parsertest.cpp | 10 | ||||
| -rw-r--r-- | SQLiteStudio3/Tests/SelectResolverTest/tst_selectresolvertest.cpp | 35 | ||||
| -rw-r--r-- | SQLiteStudio3/Tests/Tests.pro | 69 | ||||
| -rw-r--r-- | SQLiteStudio3/Tests/UtilsTest/UtilsTest.pro | 21 | ||||
| -rw-r--r-- | SQLiteStudio3/Tests/UtilsTest/tst_utilssqltest.cpp | 75 |
5 files changed, 169 insertions, 41 deletions
diff --git a/SQLiteStudio3/Tests/ParserTest/tst_parsertest.cpp b/SQLiteStudio3/Tests/ParserTest/tst_parsertest.cpp index 0dc58b0..7355616 100644 --- a/SQLiteStudio3/Tests/ParserTest/tst_parsertest.cpp +++ b/SQLiteStudio3/Tests/ParserTest/tst_parsertest.cpp @@ -21,6 +21,7 @@ class ParserTest : public QObject private Q_SLOTS: void test(); + void testScientificNumber(); void testUniqConflict(); void testGetTableTokens(); void testGetTableTokens2(); @@ -72,6 +73,15 @@ void ParserTest::test() TokenList tokens = query->getContextTableTokens(); } +void ParserTest::testScientificNumber() +{ + QString sql = "SELECT 1e100;"; + TokenList tokens = Lexer::tokenize(sql, Dialect::Sqlite3); + + QVERIFY(tokens.size() == 4); + QVERIFY(tokens[2]->type == Token::Type::FLOAT); +} + void ParserTest::testGetTableTokens() { QString sql = "select someTable.* FROM someTable;"; diff --git a/SQLiteStudio3/Tests/SelectResolverTest/tst_selectresolvertest.cpp b/SQLiteStudio3/Tests/SelectResolverTest/tst_selectresolvertest.cpp index 969ebad..2d6762e 100644 --- a/SQLiteStudio3/Tests/SelectResolverTest/tst_selectresolvertest.cpp +++ b/SQLiteStudio3/Tests/SelectResolverTest/tst_selectresolvertest.cpp @@ -29,6 +29,7 @@ class SelectResolverTest : public QObject void testWithCommonTableExpression(); void testStarWithJoinAndError(); void test1(); + void testSubselectWithAlias(); }; SelectResolverTest::SelectResolverTest() @@ -42,28 +43,28 @@ void SelectResolverTest::testTableHash() SelectResolver::Table t1; t1.database = "d1"; t1.table = "t1"; - t1.alias = "a1"; + t1.tableAlias = "a1"; tables << t1; // different alias and database SelectResolver::Table t2; t2.database = "d2"; t2.table = "t1"; - t2.alias = QString::null; + t2.tableAlias = QString::null; tables << t2; // different database SelectResolver::Table t3; t3.database = "d2"; t3.table = "t1"; - t3.alias = "a1"; + t3.tableAlias = "a1"; tables << t3; // same as t3 SelectResolver::Table t4; t4.database = "d2"; t4.table = "t1"; - t4.alias = "a1"; + t4.tableAlias = "a1"; tables << t4; // all null @@ -78,21 +79,21 @@ void SelectResolverTest::testTableHash() SelectResolver::Table t7; t7.database = "x"; t7.table = "t1"; - t7.alias = "a1"; + t7.tableAlias = "a1"; tables << t7; // similar to t1, but different table SelectResolver::Table t8; t8.database = "d1"; t8.table = "x"; - t8.alias = "a1"; + t8.tableAlias = "a1"; tables << t8; // similar to t1, but different alias SelectResolver::Table t9; t9.database = "d1"; t9.table = "t1"; - t9.alias = "x"; + t9.tableAlias = "x"; tables << t9; QVERIFY(tables.size() == 7); @@ -222,6 +223,26 @@ void SelectResolverTest::test1() QVERIFY(coreColumns[1].column == "col2"); } +void SelectResolverTest::testSubselectWithAlias() +{ + QString sql = "SELECT * FROM (SELECT m.col1, m.col2, secm.col3 FROM test AS m LEFT OUTER JOIN test AS secm ON secm.col1 = m.col2) alias3;"; + SelectResolver resolver(db, sql); + Parser parser(db->getDialect()); + QVERIFY(parser.parse(sql)); + + QList<QList<SelectResolver::Column> > columns = resolver.resolve(parser.getQueries().first().dynamicCast<SqliteSelect>().data()); + QList<SelectResolver::Column> coreColumns = columns.first(); + QVERIFY(coreColumns[0].tableAlias == "alias3"); + QVERIFY(coreColumns[1].tableAlias == "alias3"); + QVERIFY(coreColumns[2].tableAlias == "alias3"); + QVERIFY(coreColumns[0].oldTableAliases.size() == 1); + QVERIFY(coreColumns[1].oldTableAliases.size() == 1); + QVERIFY(coreColumns[2].oldTableAliases.size() == 1); + QVERIFY(coreColumns[0].oldTableAliases.first() == "m"); + QVERIFY(coreColumns[1].oldTableAliases.first() == "m"); + QVERIFY(coreColumns[2].oldTableAliases.first() == "secm"); +} + void SelectResolverTest::initTestCase() { initKeywords(); diff --git a/SQLiteStudio3/Tests/Tests.pro b/SQLiteStudio3/Tests/Tests.pro index 7995bf1..2690494 100644 --- a/SQLiteStudio3/Tests/Tests.pro +++ b/SQLiteStudio3/Tests/Tests.pro @@ -1,34 +1,35 @@ -TEMPLATE = subdirs - -test_utils.subdir = TestUtils - -completion_helper.subdir = CompletionHelperTest -completion_helper.depends = test_utils - -select_resolver.subdir = SelectResolverTest -select_resolver.depends = test_utils - -parser.subdir = ParserTest -parser.depends = test_utils - -table_modifier.subdir = TableModifierTest -table_modifier.depends = test_utils - -hash_tables.subdir = HashTablesTest -hash_tables.depends = test_utils - -db_ver_conv.subdir = DbVersionConverterTest -db_ver_conv.depends = test_utils - -dsv.subdir = DsvFormatsTest -dsv.depends = test_utils - -SUBDIRS += \ - test_utils \ - completion_helper \ - select_resolver \ - parser \ - table_modifier \ - hash_tables \ - db_ver_conv \ - dsv +TEMPLATE = subdirs
+
+test_utils.subdir = TestUtils
+
+completion_helper.subdir = CompletionHelperTest
+completion_helper.depends = test_utils
+
+select_resolver.subdir = SelectResolverTest
+select_resolver.depends = test_utils
+
+parser.subdir = ParserTest
+parser.depends = test_utils
+
+table_modifier.subdir = TableModifierTest
+table_modifier.depends = test_utils
+
+hash_tables.subdir = HashTablesTest
+hash_tables.depends = test_utils
+
+db_ver_conv.subdir = DbVersionConverterTest
+db_ver_conv.depends = test_utils
+
+dsv.subdir = DsvFormatsTest
+dsv.depends = test_utils
+
+SUBDIRS += \
+ test_utils \
+ completion_helper \
+ select_resolver \
+ parser \
+ table_modifier \
+ hash_tables \
+ db_ver_conv \
+ dsv \
+ UtilsTest
diff --git a/SQLiteStudio3/Tests/UtilsTest/UtilsTest.pro b/SQLiteStudio3/Tests/UtilsTest/UtilsTest.pro new file mode 100644 index 0000000..394c7b0 --- /dev/null +++ b/SQLiteStudio3/Tests/UtilsTest/UtilsTest.pro @@ -0,0 +1,21 @@ +#-------------------------------------------------
+#
+# Project created by QtCreator 2016-10-03T10:48:04
+#
+#-------------------------------------------------
+
+include($$PWD/../TestUtils/test_common.pri)
+
+QT += testlib
+
+QT -= gui
+
+TARGET = tst_utilssqltest
+CONFIG += console
+CONFIG -= app_bundle
+
+TEMPLATE = app
+
+
+SOURCES += tst_utilssqltest.cpp
+DEFINES += SRCDIR=\\\"$$PWD/\\\"
diff --git a/SQLiteStudio3/Tests/UtilsTest/tst_utilssqltest.cpp b/SQLiteStudio3/Tests/UtilsTest/tst_utilssqltest.cpp new file mode 100644 index 0000000..97c9234 --- /dev/null +++ b/SQLiteStudio3/Tests/UtilsTest/tst_utilssqltest.cpp @@ -0,0 +1,75 @@ +#include <QString>
+#include <QtTest>
+#include "common/utils_sql.h"
+
+class UtilsSqlTest : public QObject
+{
+ Q_OBJECT
+
+public:
+ UtilsSqlTest();
+
+private Q_SLOTS:
+ void testCaseDefault();
+ void testRemoveEmpties();
+ void testRemoveComments();
+ void testRemoveCommentsAndEmpties();
+};
+
+UtilsSqlTest::UtilsSqlTest()
+{
+}
+
+void UtilsSqlTest::testCaseDefault()
+{
+ QString sql = "select 'dfgh ;sdg '' dfga' from aa; insert into x values ('sdg', ';drghd;;;''', 4); select 1, ''; select 2;";
+ QStringList sp = quickSplitQueries(sql);
+
+ QString failure = "Failure, got: \"%1\"";
+
+ QVERIFY2(sp.size() == 4, failure.arg(sp.size()).toLatin1().data());
+ QVERIFY2(sp[0] == "select 'dfgh ;sdg '' dfga' from aa;", failure.arg(sp[0]).toLatin1().data());
+ QVERIFY2(sp[1] == " insert into x values ('sdg', ';drghd;;;''', 4);", failure.arg(sp[1]).toLatin1().data());
+ QVERIFY2(sp[2] == " select 1, '';", failure.arg(sp[2]).toLatin1().data());
+ QVERIFY2(sp[3] == " select 2;", failure.arg(sp[3]).toLatin1().data());
+}
+
+void UtilsSqlTest::testRemoveEmpties()
+{
+ QString sql = "select 'dfgh ;sdg '' dfga' from aa; ; select 1, '';";
+ QStringList sp = quickSplitQueries(sql, false);
+
+ QString failure = "Failure, got: \"%1\"";
+
+ QVERIFY2(sp.size() == 2, failure.arg(sp.size()).toLatin1().data());
+ QVERIFY2(sp[0] == "select 'dfgh ;sdg '' dfga' from aa;", failure.arg(sp[0]).toLatin1().data());
+ QVERIFY2(sp[1] == " select 1, '';", failure.arg(sp[1]).toLatin1().data());
+}
+
+void UtilsSqlTest::testRemoveComments()
+{
+ QString sql = "select 'dfgh ;sdg '' dfga' from aa; select 1/*, ''*/;--select 1\nselect 2;";
+ QStringList sp = quickSplitQueries(sql, true, true);
+
+ QString failure = "Failure, got: \"%1\"";
+
+ QVERIFY2(sp.size() == 3, failure.arg(sp.size()).toLatin1().data());
+ QVERIFY2(sp[0] == "select 'dfgh ;sdg '' dfga' from aa;", failure.arg(sp[0]).toLatin1().data());
+ QVERIFY2(sp[1] == " select 1;", failure.arg(sp[1]).toLatin1().data());
+ QVERIFY2(sp[2] == "select 2;", failure.arg(sp[2]).toLatin1().data());
+}
+
+void UtilsSqlTest::testRemoveCommentsAndEmpties()
+{
+ QString sql = "select 'dfgh ;sdg /*''*/ dfga' from aa; /*select 1, ''*/;--select 1\n--select 2;";
+ QStringList sp = quickSplitQueries(sql, false, true);
+
+ QString failure = "Failure, got: \"%1\"";
+
+ QVERIFY2(sp.size() == 1, failure.arg(sp.size()).toLatin1().data());
+ QVERIFY2(sp[0] == "select 'dfgh ;sdg /*''*/ dfga' from aa;", failure.arg(sp[0]).toLatin1().data());
+}
+
+QTEST_APPLESS_MAIN(UtilsSqlTest)
+
+#include "tst_utilssqltest.moc"
|
