diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index c1ae1de..a07636d 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -1,65 +1,70 @@ remove_definitions(-DQT_NO_CAST_FROM_ASCII) include(ECMAddTests) find_package(Qt5Test ${REQUIRED_QT_VERSION} CONFIG QUIET) find_package(Qt5Concurrent ${REQUIRED_QT_VERSION} CONFIG QUIET) if(NOT Qt5Test_FOUND) message(STATUS "Qt5Test not found, autotests will not be built.") return() endif() if(NOT Qt5Concurrent_FOUND) message(STATUS "Qt5Concurrent not found, autotests will not be built.") return() endif() # compile KEntryMap into the test since it's not exported set(kentrymaptest_SRCS kentrymaptest.cpp ../src/core/kconfigdata.cpp) ecm_add_test(${kentrymaptest_SRCS} TEST_NAME kentrymaptest LINK_LIBRARIES Qt5::Test ) target_include_directories(kentrymaptest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src/core) # compile KConfigUtils into the test since it's not exported set(test_kconfigutils_SRCS test_kconfigutils ../src/kconf_update/kconfigutils.cpp) ecm_add_test(${test_kconfigutils_SRCS} TEST_NAME test_kconfigutils LINK_LIBRARIES KF5::ConfigCore Qt5::Test ) target_include_directories(test_kconfigutils PRIVATE ../src/kconf_update) qt5_add_resources(sharedconfigresources sharedconfigresources.qrc) ecm_add_test(ksharedconfigtest ${sharedconfigresources} TEST_NAME kconfigcore-ksharedconfigtest LINK_LIBRARIES KF5::ConfigCore Qt5::Test Qt5::Concurrent) # test for fallback to :/kconfig/xxxx config resource qt5_add_resources(fallbackconfigresources fallbackconfigresources.qrc) ecm_add_test(fallbackconfigresourcestest ${fallbackconfigresources} TEST_NAME kconfigcore-fallbackconfigresourcestest LINK_LIBRARIES KF5::ConfigCore Qt5::Test Qt5::Concurrent) ecm_add_tests( kconfignokdehometest.cpp kconfigtest.cpp kdesktopfiletest.cpp test_kconf_update.cpp ksharedconfig_in_global_object NAME_PREFIX kconfigcore- LINK_LIBRARIES KF5::ConfigCore Qt5::Test Qt5::Concurrent ) target_include_directories(test_kconf_update PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../src/kconf_update) ecm_add_tests( kconfigguitest.cpp kconfigloadertest.cpp kconfigskeletontest.cpp kstandardshortcuttest.cpp NAME_PREFIX kconfiggui- LINK_LIBRARIES KF5::ConfigGui Qt5::Test ) +# These tests do a global cleanup of ~/.qttest, so they can't run in parallel +set_tests_properties(kconfigcore-kconfigtest PROPERTIES RUN_SERIAL TRUE) +set_tests_properties(kconfigcore-kconfignokdehometest PROPERTIES RUN_SERIAL TRUE) +set_tests_properties(kconfiggui-kconfigguitest PROPERTIES RUN_SERIAL TRUE) + add_subdirectory(kconfig_compiler) diff --git a/autotests/kconfigskeletontest.cpp b/autotests/kconfigskeletontest.cpp index 898366c..0036a7e 100644 --- a/autotests/kconfigskeletontest.cpp +++ b/autotests/kconfigskeletontest.cpp @@ -1,149 +1,154 @@ /* This file is part of the KDE libraries Copyright (C) 2006 Olivier Goffart 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 "kconfigskeletontest.h" #include #include #include QTEST_MAIN(KConfigSkeletonTest) #define DEFAULT_SETTING1 false #define DEFAULT_SETTING2 QColor(1,2,3) #define DEFAULT_SETTING3 QFont("helvetica",12) #define DEFAULT_SETTING4 QString("Hello World") #define WRITE_SETTING1 true #define WRITE_SETTING2 QColor(3,2,1) #define WRITE_SETTING3 QFont("helvetica",14) #define WRITE_SETTING4 QString("KDE") +void KConfigSkeletonTest::initTestCase() +{ + QStandardPaths::setTestModeEnabled(true); +} + void KConfigSkeletonTest::init() { QFile::remove(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/kconfigskeletontestrc"); s = new KConfigSkeleton("kconfigskeletontestrc"); s->setCurrentGroup("MyGroup"); itemBool = s->addItemBool("MySetting1", mMyBool, DEFAULT_SETTING1); s->addItemColor("MySetting2", mMyColor, DEFAULT_SETTING2); s->setCurrentGroup("MyOtherGroup"); s->addItemFont("MySetting3", mMyFont, DEFAULT_SETTING3); s->addItemString("MySetting4", mMyString, DEFAULT_SETTING4); QCOMPARE(mMyBool, DEFAULT_SETTING1); QCOMPARE(mMyColor, DEFAULT_SETTING2); QCOMPARE(mMyFont, DEFAULT_SETTING3); QCOMPARE(mMyString, DEFAULT_SETTING4); } void KConfigSkeletonTest::cleanup() { delete s; } void KConfigSkeletonTest::testSimple() { mMyBool = WRITE_SETTING1; mMyColor = WRITE_SETTING2; mMyFont = WRITE_SETTING3; mMyString = WRITE_SETTING4; s->save(); mMyBool = false; mMyColor = QColor(); mMyString.clear(); mMyFont = QFont(); s->read(); QCOMPARE(mMyBool, WRITE_SETTING1); QCOMPARE(mMyColor, WRITE_SETTING2); QCOMPARE(mMyFont, WRITE_SETTING3); QCOMPARE(mMyString, WRITE_SETTING4); } void KConfigSkeletonTest::testRemoveItem() { QVERIFY(s->findItem("MySetting1")); s->removeItem("MySetting1"); QVERIFY(!s->findItem("MySetting1")); } void KConfigSkeletonTest::testClear() { QVERIFY(s->findItem("MySetting2")); QVERIFY(s->findItem("MySetting3")); QVERIFY(s->findItem("MySetting4")); s->clearItems(); QVERIFY(!s->findItem("MySetting2")); QVERIFY(!s->findItem("MySetting3")); QVERIFY(!s->findItem("MySetting4")); } void KConfigSkeletonTest::testDefaults() { mMyBool = WRITE_SETTING1; mMyColor = WRITE_SETTING2; mMyFont = WRITE_SETTING3; mMyString = WRITE_SETTING4; s->save(); s->setDefaults(); QCOMPARE(mMyBool, DEFAULT_SETTING1); QCOMPARE(mMyColor, DEFAULT_SETTING2); QCOMPARE(mMyFont, DEFAULT_SETTING3); QCOMPARE(mMyString, DEFAULT_SETTING4); s->save(); } void KConfigSkeletonTest::testKConfigDirty() { itemBool->setValue(true); itemBool->writeConfig(s->sharedConfig().data()); QVERIFY(s->sharedConfig()->isDirty()); s->save(); QVERIFY(!s->sharedConfig()->isDirty()); itemBool->setValue(false); itemBool->writeConfig(s->sharedConfig().data()); QVERIFY(s->sharedConfig()->isDirty()); s->save(); QVERIFY(!s->sharedConfig()->isDirty()); } void KConfigSkeletonTest::testSaveRead() { itemBool->setValue(true); s->save(); itemBool->setValue(false); s->save(); mMyBool = true; s->read(); QCOMPARE(mMyBool, false); } diff --git a/autotests/kconfigskeletontest.h b/autotests/kconfigskeletontest.h index 5cdcc9d..a5c63c9 100644 --- a/autotests/kconfigskeletontest.h +++ b/autotests/kconfigskeletontest.h @@ -1,49 +1,50 @@ /* This file is part of the KDE libraries Copyright (C) 2006 Olivier Goffart 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. */ #ifndef KCONFIGSKELETONTEST_H #define KCONFIGSKELETONTEST_H #include class KConfigSkeletonTest : public QObject { Q_OBJECT public: private Q_SLOTS: + void initTestCase(); void init(); void cleanup(); void testSimple(); void testDefaults(); void testRemoveItem(); void testClear(); void testKConfigDirty(); void testSaveRead(); private: KConfigSkeleton *s; KConfigSkeleton::ItemBool *itemBool; bool mMyBool; QColor mMyColor; QFont mMyFont; QString mMyString; }; #endif