File indexing completed on 2022-10-04 15:18:58

0001 /* This file is part of the KDE project
0002    Copyright (C) 2018 Jarosław Staniek <staniek@kde.org>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include <KDbTestUtils.h>
0021 #include <KDbConnectionData>
0022 #include <KDbConnectionOptions>
0023 
0024 class MissingTableTest : public QObject
0025 {
0026     Q_OBJECT
0027 private Q_SLOTS:
0028     void initTestCase();
0029     void init();
0030     //! Tests if the list of tables skips name for which physical table is missing.
0031     //! The missingTableTest.kexi file has "persons" table deleted.
0032     void testListTables();
0033     void cleanupTestCase();
0034     void cleanup();
0035 
0036 private:
0037     //! Opens database needed for tests
0038     bool openDatabase(const QString &path);
0039 
0040     KDbTestUtils m_utils;
0041 };
0042 
0043 void MissingTableTest::initTestCase()
0044 {
0045 }
0046 
0047 void MissingTableTest::init()
0048 {
0049     QString dir(QFile::decodeName(FILES_DATA_DIR));
0050     QVERIFY(openDatabase(dir + "/missingTableTest.kexi"));
0051 }
0052 
0053 
0054 bool MissingTableTest::openDatabase(const QString &path)
0055 {
0056     KDbConnectionOptions options;
0057     options.setReadOnly(true);
0058     return m_utils.testConnectAndUse(path, options);
0059 }
0060 
0061 void MissingTableTest::testListTables()
0062 {
0063     const bool alsoSystemTables = true;
0064     bool ok;
0065     QStringList foundTableNames = m_utils.connection()->tableNames(alsoSystemTables, &ok);
0066     QVERIFY(ok);
0067 
0068     // call again with ok == nullptr
0069     QCOMPARE(foundTableNames, m_utils.connection()->tableNames(alsoSystemTables));
0070 
0071     // make sure missing table is not present
0072     std::sort(foundTableNames.begin(), foundTableNames.end());
0073     const QStringList expectedTables(
0074         { "cars", "kexi__db", "kexi__fields", "kexi__objectdata", "kexi__objects" });
0075     QCOMPARE(foundTableNames, expectedTables);
0076 }
0077 
0078 void MissingTableTest::cleanup()
0079 {
0080     QVERIFY(m_utils.testDisconnect());
0081 }
0082 
0083 void MissingTableTest::cleanupTestCase()
0084 {
0085 }
0086 
0087 QTEST_GUILESS_MAIN(MissingTableTest)
0088 
0089 #include "MissingTableTest.moc"