From 4d31ec78f80d6add09dc80404470cfae7f2b13c7 Mon Sep 17 00:00:00 2001 From: David Redondo Date: Fri, 28 Jan 2022 10:58:14 +0100 Subject: Don't use saveShortcut for setting up tests It will trigger side effects like triggering the dbus signal which depending on the timing may be delivered only in the next test case causing an unexpected change signal emission. --- autotests/CMakeLists.txt | 12 +++++++++++- autotests/kstandardshortcutwatchertest.cpp | 8 ++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index 725d789f..95a1200a 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -57,11 +57,21 @@ ecm_add_tests( kconfigloadertest.cpp kconfigskeletontest.cpp kstandardshortcuttest.cpp - kstandardshortcutwatchertest.cpp NAME_PREFIX kconfiggui- LINK_LIBRARIES KF5::ConfigGui Qt${QT_MAJOR_VERSION}::Test ) +ecm_add_test( + kstandardshortcutwatchertest.cpp + # add sources instead of linking so we can use the unexported initialize() + ../src/gui/kstandardshortcut.cpp + ../src/gui/kstandardshortcutwatcher.cpp + LINK_LIBRARIES KF5::ConfigCore Qt${QT_MAJOR_VERSION}::Gui Qt${QT_MAJOR_VERSION}::Test + TEST_NAME kstandardshortcutwatchertest + NAME_PREFIX kconfiggui- +) +target_include_directories(kstandardshortcutwatchertest PRIVATE "$") + # 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) diff --git a/autotests/kstandardshortcutwatchertest.cpp b/autotests/kstandardshortcutwatchertest.cpp index f20fc635..64d55d5c 100644 --- a/autotests/kstandardshortcutwatchertest.cpp +++ b/autotests/kstandardshortcutwatchertest.cpp @@ -7,6 +7,7 @@ #include "kstandardshortcutwatcher.h" #include "kconfiggroup.h" #include "ksharedconfig.h" +#include "kstandardshortcut_p.h" #include #include @@ -35,7 +36,10 @@ void KStandardShortcutWatcherTest::initTestCase() void KStandardShortcutWatcherTest::init() { - KStandardShortcut::saveShortcut(KStandardShortcut::Open, KStandardShortcut::hardcodedDefaultShortcut(KStandardShortcut::Open)); + KConfigGroup group(KSharedConfig::openConfig(), "Shortcuts"); + group.writeEntry("Open", QKeySequence::listToString(KStandardShortcut::hardcodedDefaultShortcut(KStandardShortcut::Open)), KConfig::Global); + group.sync(); + KStandardShortcut::initialize(KStandardShortcut::Open); } void KStandardShortcutWatcherTest::testSignal() @@ -54,7 +58,7 @@ void KStandardShortcutWatcherTest::testDataUpdated() // Writing manually to forego automatic update in saveShortcut() KConfigGroup group(KSharedConfig::openConfig(), "Shortcuts"); group.writeEntry("Open", QKeySequence::listToString(newShortcut), KConfig::Global | KConfig::Notify); - group.config()->sync(); + group.sync(); QTRY_COMPARE(signalSpy.count(), 1); QCOMPARE(KStandardShortcut::open(), newShortcut); } -- cgit v1.2.1