Changeset View
Changeset View
Standalone View
Standalone View
autotests/MissingTableTest.cpp
- This file was added.
1 | /* This file is part of the KDE project | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2018 Jarosław Staniek <staniek@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Library General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2 of the License, or (at your option) any later version. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | Library General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Library General Public License | ||||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
17 | * Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #include <KDbTestUtils.h> | ||||
21 | #include <KDbConnectionData> | ||||
22 | #include <KDbConnectionOptions> | ||||
23 | | ||||
24 | class MissingTableTest : public QObject | ||||
25 | { | ||||
26 | Q_OBJECT | ||||
27 | private Q_SLOTS: | ||||
28 | void initTestCase(); | ||||
29 | void init(); | ||||
30 | //! Tests if the list of tables skips name for which physical table is missing. | ||||
31 | //! The missingTableTest.kexi file has "persons" table deleted. | ||||
32 | void testListTables(); | ||||
33 | void cleanupTestCase(); | ||||
34 | void cleanup(); | ||||
35 | | ||||
36 | private: | ||||
37 | //! Opens database needed for tests | ||||
38 | bool openDatabase(const QString &path); | ||||
39 | | ||||
40 | KDbTestUtils m_utils; | ||||
41 | }; | ||||
42 | | ||||
43 | void MissingTableTest::initTestCase() | ||||
44 | { | ||||
45 | } | ||||
46 | | ||||
47 | void MissingTableTest::init() | ||||
48 | { | ||||
49 | QString dir(QFile::decodeName(FILES_DATA_DIR)); | ||||
50 | QVERIFY(openDatabase(dir + "/missingTableTest.kexi")); | ||||
51 | } | ||||
52 | | ||||
53 | | ||||
54 | bool MissingTableTest::openDatabase(const QString &path) | ||||
55 | { | ||||
56 | KDbConnectionOptions options; | ||||
57 | options.setReadOnly(true); | ||||
58 | return m_utils.testConnectAndUse(path, options); | ||||
59 | } | ||||
60 | | ||||
61 | void MissingTableTest::testListTables() | ||||
62 | { | ||||
63 | const bool alsoSystemTables = true; | ||||
64 | bool ok; | ||||
65 | QStringList foundTableNames = m_utils.connection->tableNames(alsoSystemTables, &ok); | ||||
66 | QVERIFY(ok); | ||||
67 | | ||||
68 | // call again with ok == nullptr | ||||
69 | QCOMPARE(foundTableNames, m_utils.connection->tableNames(alsoSystemTables)); | ||||
70 | | ||||
71 | // make sure missing table is not present | ||||
72 | std::sort(foundTableNames.begin(), foundTableNames.end()); | ||||
73 | const QStringList expectedTables( | ||||
74 | { "cars", "kexi__db", "kexi__fields", "kexi__objectdata", "kexi__objects" }); | ||||
75 | QCOMPARE(foundTableNames, expectedTables); | ||||
76 | } | ||||
77 | | ||||
78 | void MissingTableTest::cleanup() | ||||
79 | { | ||||
80 | QVERIFY(m_utils.testDisconnect()); | ||||
81 | } | ||||
82 | | ||||
83 | void MissingTableTest::cleanupTestCase() | ||||
84 | { | ||||
85 | } | ||||
86 | | ||||
87 | QTEST_GUILESS_MAIN(MissingTableTest) | ||||
88 | | ||||
89 | #include "MissingTableTest.moc" |