[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdb] autotests: Add KDbConnection::drv_getTableNames for low level list of table names,
From:       Jaroslaw Staniek <null () kde ! org>
Date:       2018-04-09 9:54:14
Message-ID: E1f5TV8-0007jL-Q2 () code ! kde ! org
[Download RAW message or body]

Git commit 219c02d1bb58fde744e9150c35914cc594ad3138 by Jaroslaw Staniek.
Committed on 26/03/2018 at 22:22.
Pushed by staniek into branch 'master'.

Add KDbConnection::drv_getTableNames for low level list of table names, make \
tableNames() skip names with non-existing physical tables

Summary:
- KDbTestUtils: add convenience APIs for connecting and using db, support connection \
                options, use it in parser test
- Add KDbConnection::drv_getTableNames for low level list of table names, make \
                tableNames() skip names with non-existing physical tables
- This change is backward compatible since metadata without physical table is not \
usable anyway.

CCBUG:392112
FIXED-IN:3.2.0

+ Add autotest for handling missing physical tables

Test Plan: Run ctest

Reviewers: piggz

Tags: #kdb

Differential Revision: https://phabricator.kde.org/D11547

M  +3    -0    autotests/CMakeLists.txt
A  +84   -0    autotests/MissingTableTest.cpp     [License: LGPL (v2+)]
A  +-    --    autotests/data/missingTableTest.kexi

https://commits.kde.org/kdb/219c02d1bb58fde744e9150c35914cc594ad3138

diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt
index a239e9d3..ee4d65a6 100644
--- a/autotests/CMakeLists.txt
+++ b/autotests/CMakeLists.txt
@@ -42,6 +42,7 @@ ecm_add_tests(
     ConnectionTest.cpp
     DriverTest.cpp
     ExpressionsTest.cpp
+    MissingTableTest.cpp
     QuerySchemaTest.cpp
     KDbTest.cpp
 
@@ -49,6 +50,8 @@ ecm_add_tests(
         kdbtestutils
 )
 
+target_compile_definitions(MissingTableTest PRIVATE \
-DFILES_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data" ) +
 if(NOT WIN32) #TODO enable for Windows when headers_test.sh is ported e.g. to python
     add_subdirectory(headers)
 endif()
diff --git a/autotests/MissingTableTest.cpp b/autotests/MissingTableTest.cpp
new file mode 100644
index 00000000..c94c6040
--- /dev/null
+++ b/autotests/MissingTableTest.cpp
@@ -0,0 +1,84 @@
+/* This file is part of the KDE project
+   Copyright (C) 2018 Jarosław Staniek <staniek@kde.org>
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public
+   License as published by the Free Software Foundation; either
+   version 2 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public License
+   along with this library; see the file COPYING.LIB.  If not, write to
+   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+*/
+
+#include <KDbTestUtils.h>
+#include <KDbConnectionData>
+#include <KDbConnectionOptions>
+
+class MissingTableTest : public QObject
+{
+    Q_OBJECT
+private Q_SLOTS:
+    void initTestCase();
+    void init();
+    //! Tests if the list of tables skips name for which physical table is missing.
+    //! The missingTableTest.kexi file has "persons" table deleted.
+    void testListTables();
+    void cleanupTestCase();
+    void cleanup();
+
+private:
+    //! Opens database needed for tests
+    bool openDatabase(const QString &path);
+
+    KDbTestUtils m_utils;
+};
+
+void MissingTableTest::initTestCase()
+{
+}
+
+void MissingTableTest::init()
+{
+    QString dir(QFile::decodeName(FILES_DATA_DIR));
+    QVERIFY(openDatabase(dir + "/missingTableTest.kexi"));
+}
+
+
+bool MissingTableTest::openDatabase(const QString &path)
+{
+    KDbConnectionOptions options;
+    options.setReadOnly(true);
+    return m_utils.testConnectAndUse(path, options);
+}
+
+void MissingTableTest::testListTables()
+{
+    const bool alsoSystemTables = true;
+    bool ok;
+    QStringList foundTableNames = m_utils.connection->tableNames(alsoSystemTables, \
&ok); +    QVERIFY(ok);
+    std::sort(foundTableNames.begin(), foundTableNames.end());
+    const QStringList expectedTables(
+        { "cars", "kexi__db", "kexi__fields", "kexi__objectdata", "kexi__objects" \
}); +    QCOMPARE(foundTableNames, expectedTables);
+}
+
+void MissingTableTest::cleanup()
+{
+    QVERIFY(m_utils.testDisconnect());
+}
+
+void MissingTableTest::cleanupTestCase()
+{
+}
+
+QTEST_GUILESS_MAIN(MissingTableTest)
+
+#include "MissingTableTest.moc"
diff --git a/autotests/data/missingTableTest.kexi \
b/autotests/data/missingTableTest.kexi new file mode 100644
index 00000000..628414b5
Binary files /dev/null and b/autotests/data/missingTableTest.kexi differ


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic