diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index 98dacff6..c95ded93 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -1,57 +1,60 @@ remove_definitions( -DQT_NO_KEYWORDS -DQT_NO_SIGNALS_SLOTS_KEYWORDS -DQT_NO_CAST_FROM_ASCII -DQT_USE_QSTRINGBUILDER ) set(FILES_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) set(KDB_LOCAL_PLUGINS_DIR ${PROJECT_BINARY_DIR}/plugins) add_definitions( -DFILES_OUTPUT_DIR=\"${FILES_OUTPUT_DIR}\" # make plugins work without installing them: -DKDB_LOCAL_PLUGINS_DIR=\"${KDB_LOCAL_PLUGINS_DIR}\" # nonstandard path for sqlite3 extensions, they would work too if we placed them # in ${KDB_LOCAL_PLUGINS_DIR}/sqlite3 but we want to test the "extraSqliteExtensionPaths" # connection option in ConnectionTest::testCreateDb(): -DSQLITE_LOCAL_ICU_EXTENSION_PATH=\"${KDB_LOCAL_PLUGINS_DIR}/sqlite3\" -DYYTOKENTYPE # this removes access to yytokentype enum as we should access KDb::Token instead ) include(ECMAddTests) find_package(Qt5Test) set_package_properties(Qt5Test PROPERTIES DESCRIPTION "Qt5Test library" URL "https://www.qt.io" TYPE RECOMMENDED PURPOSE "Required by tests") # A helper library for db-related tests add_library(kdbtestutils SHARED KDbTestUtils.cpp ) target_link_libraries(kdbtestutils PUBLIC KDb Qt5::Test ) generate_export_header(kdbtestutils) # Tests ecm_add_tests( ConnectionOptionsTest.cpp ConnectionTest.cpp DateTimeTest.cpp DriverTest.cpp ExpressionsTest.cpp + MissingTableTest.cpp QuerySchemaTest.cpp KDbTest.cpp LINK_LIBRARIES 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() add_subdirectory(tools) add_subdirectory(parser) 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 + + 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 +#include +#include + +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