aboutsummaryrefslogtreecommitdiff
path: root/autotests/kconfigtest.cpp
AgeCommit message (Collapse)Author
2022-05-04KConfigGroup: fix writePathEntry/readPathEntry roundtrip for symlinksDavid Faure
If $HOME isn't canonical (e.g. on FreeBSD it's /home/user while the canonical path is /usr/home/user), replacing the canonical version of $HOME with $HOME means that we'll read back a different value than we wrote in. It might seem "equivalent" but it leads to surprises like KRecentDocuments showing duplicates because /usr/home/user became /home/user in the KConfig roundtrip (but not in the XBEL roundtrip). This commit loses the replacement of /usr/home/user with $HOME on FreeBSD, but I think an exact roundtrip is what we expect, rather than stuff being modified under our feet. The alternative would be to canonicalize everything in KRecentDocuments but users don't want to see the /usr in front, I assume (so we would have to use a cache of canonicalized path, for the removal of duplicates, awful performance wise).
2022-01-02Exclude deleted groups from groupList()Igor Kushnir
This commit is an alternative to the earlier incorrect and reverted b3dc879e8b108c26c929bfbe551bcdf77f140e94. That commit contained several mistakes and an algorithmic complexity increase: 1) the added conditions were inverted: should have been `hasNonDeletedEntries` (without `!`); 2) KConfigPrivate::groupList() passed group instead of key.mGroup to hasNonDeletedEntries(); 3) The complexity of hasNonDeletedEntries() is O(entryMap.size()). Calls to this function were added into loops that iterated entryMap.size() times. So the overall complexity of groupList() increased from linear to quadratic. This fix collects `mGroup`s of non-deleted key entries instead of `mGroup`s of group entries. The number of key entries can be much greater than the number of group entries, so this fix hurts performance. But at least the algorithmic complexity of groupList() stays linear. Future commits can optimize the loops and make them almost as fast or even faster than before this fix. The `!key.mKey.isNull() && !entryMapIt->bDeleted` checks added in this commit are consistent with the check in KConfigPrivate::hasNonDeletedEntries(). KConfig::hasGroupImpl() forwards its argument to hasNonDeletedEntries() with the following comment: // No need to look for the actual group entry anymore, or for subgroups: // a group exists if it contains any non-deleted entry. BUG: 384039 FIXED-IN: 5.90
2021-12-16WIP: Change the build system to enable building with Qt 6Ahmad Samir
This was built with: -DQT_MAJOR_VERSION=6 \ -DEXCLUDE_DEPRECATED_BEFORE_AND_AT=5.90.0 \ -DKF_DISABLE_DEPRECATED_BEFORE_AND_AT=0x055a00 Move the include(KDEInstallDirs) call before the first find_package(Qt*, the former is what auto-detects the Qt version, and defaults to 5. This is needed to be able to build against Qt5 by default. All unit tests still pass.
2021-10-13Enforce KAuthorized enums being not 0Alexander Lohnau
This will output a warning if an invalid value is requested. The goal is to avoid implicit conversion which might result in a zero-int value.
2021-10-13Create enum to to authorize common keysAlexander Lohnau
By using an enum we have a central place to provide docs for the most common actions/restrictions. Also consumers can pass in type-safe enum values instead of potentially undocumented strings that might contain typos. Also it is better documents is a value is supposed to be authorized using KAuthorized::authorize or KAuthorized::authorizeAction, in the case of "shell_access" this was mixed up from time to time. Considering that we do not want the parameter for the methods to become too long I have deliberately decided against using `enum class`. Also we don't have and usecases for the binary operators in combination with the newly added enums. Task: https://phabricator.kde.org/T11948
2021-10-11Create utility method for moving entries from one group to anotherAlexander Lohnau
This will become especially useful when moving state data from the config file to a dedicated state data file. Task: https://phabricator.kde.org/T12549
2021-08-28GIT_SILENT: we can use std::as_const directlyLaurent Montel
2021-08-13clang-tidy: one declaration per line; braces around statementsAhmad Samir
clang-tidy checks: readability-isolate-declaration and readability-braces-around-statements KF task: https://phabricator.kde.org/T14729 GIT_SILENT
2021-08-03KConfig: fix deletion of an entry that is also in kdeglobalsDavid Faure
This is the case where we expected to see Key[$d] in the config file, and it was somehow broken. When saving, the key was omitted, so when reloading the kdeglobals key was present again. Detected when trying to write a unittest for a different patch... I had to reshuffle the unittest a bit because testThreads calls testSimple which didn't expect that the "[AAA]" group would actually be deleted now.
2021-07-13Fix typos found by codespellChristophe Giboudeaux
GIT_SILENT
2021-06-21kconfigtest: save/restore XDG_CONFIG_DIRSDavid Faure
No impact on the rest of the test, but I was wondering if it might break anything, better restore it just in case.
2021-05-25Revert "fix deleted group is in listGroups"Nate Graham
This reverts commit b3dc879e8b108c26c929bfbe551bcdf77f140e94. This change breaks plasmashell startup and possible other apps as well. Reverting so the root cause can be investigated without time pressure.
2021-05-25fix deleted group is in listGroupsLieven Hey
calling deleteGroup only deletes all entries but the group does still exists in listGroups this is somewhat irritating since calling exists on that group will return false with this patch the group does no longer exists in listGroup
2021-02-22Run clang-format on all cpp/h filesAhmad Samir
NO_CHANGELOG
2021-02-06Fix build on windows on the CI, againAhmad Samir
It's a QByteArray not a QString. GIT_SILENT
2021-02-06Fix windows build on the CIAhmad Samir
I didn't consider the '#ifdef Q_OS_WIN' code paths (since that compiles just fine locally). GIT_SILENT
2021-02-06Minor code optimisationsAhmad Samir
- Use a global var for a QString that's used many times - Break up long-all-cap variable names, it makes it harder to read (and I've fixed one typo in one of those ALLCAPS) - Fix some clazy warnings, make global QString objects in unit tests static (so that the compiler doesn't create symbols for them, it doesn't matter in a unit test but KF code acts as a reference sometimes that others copy from, tip from dfaure) - Add TODO note about changing kconfig_compiler to generate C++ code that uses multi-arg QString::arg(QString, QString, QString) instead of QString::arg().arg() - More const; more QString::at() instead of operator[] where appropriate - Use a ternary where it makes the code more readable (and uses less lines :)) NO_CHANGELOG
2021-02-06kconfigtest: less implicit cast from ASCIIAhmad Samir
NO_CHANGELOG
2021-02-06Preincerment/predecrement operator where the post ones aren't neededAhmad Samir
NO_CHANGELOG
2021-02-06General code cleanupAhmad Samir
Fix some clazy warnings, and some other minor code optimisations. NO_CHANGELOG
2021-01-26KConfig: preserve the milliseconds component of QDateTimeDavid Faure
I stored a file's lastModified() into KConfig, to compare with it again on next start, and the loss of milliseconds made the code think the timestamps didn't match, even when they did.
2021-01-17Adapt to Qt6 text codec changesNicolas Fella
In Qt6 QTextCodec/QTextStream::setCodec is replaced with QTextStream::setEncoding(QStringConverter::Encoding) Also UTF-8 is the new default for QTextStream.
2020-12-13Don't include QtTest as it includes all QtCore includesLaurent Montel
2020-12-03Remove redundant comment, foreach is long goneAhmad Samir
GIT_SILENT
2020-04-17Add force save behavior to KEntryMapBenjamin Port
Summary: Fix the following bug, if an entry is set on HOME/.config/kdeglobals and on a specific config file like kcmfonts When you hit restore defaults button and apply, value will be not wrote on the specific file, but then the value is the one from kdeglobals This patch ensure we write the key to the specific configuration file on those case with an empty value. KConfig will take default value automatically Test Plan: Added a test to ensure flag is working Tested using some KCM to ensure all is working fine Reviewers: ervin, dfaure, meven, crossi, hchain Reviewed By: ervin, dfaure, meven Subscribers: kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D28128
2020-03-22KConfig: Convert to SPDX license statementsAndreas Cord-Landwehr
Summary: Convert license headers to SPDX statements and add license files as required by REUSE specification. Reviewers: cgiboudeaux Reviewed By: cgiboudeaux Subscribers: ognarb, cgiboudeaux, kde-frameworks-devel Tags: #frameworks Maniphest Tasks: T11550 Differential Revision: https://phabricator.kde.org/D27601
2020-01-23Port endl to "\n" as it's qt namespaced. Use directlyLaurent Montel
std::cout/std::cerr Summary: Port endl to "\n" as it's qt namespaced Test Plan: autotest ok Reviewers: dfaure Reviewed By: dfaure Subscribers: kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D26860
2019-12-04Make sure to execute test with english langLaurent Montel
2019-10-18Use ECMGenerateExportHeader to manage deprecated API betterFriedrich W. H. Kossebau
Summary: Allows * projects linking to KConfigCore/Gui to hide deprecated API up to a given version or silence deprecation warnings after a given version, using * -DKCONFIGCORE_DISABLE_DEPRECATED_BEFORE_AND_AT * -DKCONFIGCORE_NO_DEPRECATED * -DKCONFIGCORE_DEPRECATED_WARNINGS_SINCE * -DKCONFIGCORE_NO_DEPRECATED_WARNINGS * -DKCONFIGGUI_DISABLE_DEPRECATED_BEFORE_AND_AT * -DKCONFIGGUI_NO_DEPRECATED * -DKCONFIGGUI_DEPRECATED_WARNINGS_SINCE * -DKCONFIGGUI_NO_DEPRECATED_WARNINGS or * -DKF_DISABLE_DEPRECATED_BEFORE_AND_AT * -DKF_NO_DEPRECATED * -DKF_DEPRECATED_WARNINGS_SINCE * -DKF_NO_DEPRECATED_WARNINGS * to build KConfigCore/Gui optionally with deprecated API excluded from the build, using "EXCLUDE_DEPRECATED_BEFORE_AND_AT" cmake argument. Test Plan: Builds with EXCLUDE_DEPRECATED_BEFORE_AND_AT set to 0, 4.0.0, 5.0.0, 5.11.0, 5.24.0, 5.39.0, 5.42.0, CURRENT. Reviewers: #frameworks, mlaurent Reviewed By: mlaurent Subscribers: mlaurent, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D24496
2019-09-17[KConfig] port away from deprecated methods in Qt 5.14David Faure
Summary: In kconf_update, the ctime usage used to be about metadata change time (buff.st_ctime, before it got ported to the misnamed created()). I ported it to birthTime, because I think date of birth is a more useful way to identify a file than date of permission change which doesn't really matter to us. But in practice, I can't help but wonder if mtime alone wouldn't be enough. For the QStringLiteral("%%1").arg(i) bit, I tested it in tst_qstring, the first % is left untouched. Test Plan: make && ctest Reviewers: mdawson, arichardson, vkrause Reviewed By: vkrause Subscribers: pino, arojas, mlaurent, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D23815
2019-08-07Security: remove support for $(...) in config keys with [$e] marker.David Faure
Summary: It is very unclear at this point what a valid use case for this feature would possibly be. The old documentation only mentions $(hostname) as an example, which can be done with $HOSTNAME instead. Note that $(...) is still supported in Exec lines of desktop files, this does not require [$e] anyway (and actually works better without it, otherwise the $ signs need to be doubled to obey kconfig $e escaping rules...). Test Plan: ctest passes; various testcases with $(...) in desktop files, directory files, and config files, no longer execute commands. Reviewers: mdawson, aacid, broulik, davidedmundson, kossebau, apol, sitter, security-team Reviewed By: mdawson, davidedmundson Subscribers: ZaWertun, rikmills, fvogt, ngraham, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D22979
2019-04-01Add Notify capability to revertToDefaultKai Uwe Broulik
This enables KConfigWatcher to detect those changes, too. Differential Revision: https://phabricator.kde.org/D20039
2019-03-03[Kconfig] Compile without foreachLaurent Montel
Summary: compile without foreach Test Plan: Unittest Ok as previously Reviewers: dfaure Reviewed By: dfaure Subscribers: kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D19326
2019-02-20Write valid UTF8 characters without escaping.Jos van den Oever
Summary: commit 6a18528 introduced escaping of bytes >= 127 to ensure that KConfig files are valid UTF8. The simplistic approach with a cutoff results in many escaped bytes where it is not required. Especially non-western configuration files would have many escapes. This commit fixes that by only escaping bytes that are not valid UTF8. BUG: 403557 FIXED-IN: 5.56 Test Plan: ninja && ninja test Reviewers: dfaure, arichardson, apol, #frameworks, thiago Subscribers: rapiteanu, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D19107
2018-12-28Fix build without D-BusVolker Krause
2018-12-19Deduplicate reference valueJos van den Oever
2018-12-19Remove unneeded qWarningJos van den Oever
2018-12-18Escape bytes that are larger than or equal to 127 in config filesJos van den Oever
Summary: UserBase tells me that KDE configuration files are encoded in UTF-8. https://userbase.kde.org/KDE_System_Administration/Configuration_Files In practice some *rc files have bytes outside that encoding. In my home directory I found two files that are not valid UTF-8. I searched with find ~/.config/ -name '*rc' -exec file {} + which gives these exceptions: akonadiconsolerc: Non-ISO extended-ASCII text, with very long lines kmail2rc: Non-ISO extended-ASCII text, with very long lines In kmail2rc, the offending fields are [AttachmentView]/State [CollectionFolderView]/HeaderState Both are QByteArray values saved from QHeaderView::saveState(). In the instance I found, the offending bytes were 0x81 and 0x84. akonadiconsolerc had way more of these values. All seem related to saving widget state and hence probably QByteArrays. The written QByteArray values look very strange. The bytes in the non-printable ASCII range are written as \xXX but the values above 127 are written literally. The encoding is done by KConfigIniBackend::stringToPrintable. It does not currently escape bytes that are larger than or equal to 127. Reviewers: dfaure, arichardson, apol Reviewed By: apol Subscribers: apol, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D17651
2018-10-10Set explicit arg type in QCOMPAREDavid Edmundson
2018-10-10Add mechanism to notify other clients of config changes over DBusDavid Edmundson
Summary: Intention is not to create a registry like system, but to replace KDElibs4Support::KGlobalSettings and to replace other system settingss -> some app communication in a more generic way. writeEntry gains an additional flag Notify which if set, will notify clients of what has actually changed when we sync. Rationale to put this into KConfig was so that we could have everything batched and sychronised to the file sync and to get the fine detailed exposure of what has actually changed which we don't get with a file watcher. Default behaviour remains identical without any broadcast messages. As it is a new dependency it is purely optional and anything referencing DBus is not in the public API. Our deployment on platforms without DBus tend to be standalone applications anyway. Test Plan: Attached unit test Reviewers: broulik, dfaure Reviewed By: broulik, dfaure Subscribers: dfaure, broulik, zzag, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D13034
2018-09-28 Fix issue when reading path listsAleix Pol
Summary: They were not being split properly. Test Plan: Tests pass, including the new one. Reviewers: #frameworks, dfaure Reviewed By: dfaure Subscribers: dfaure, anthonyfieroni, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D14162
2018-08-08Fix cleanup of kconfigtest kdeglobalsDavid Edmundson
Summary: We expand the path of kdeglobals to ~/.qttest/kconfigtests/../kdeglobals which works during the test, but this cleanup is run both on startup and after removing ~/.qttest/kconfigtests at which point the expansion fails. Test Plan: Ran test, looked at qttest dir. It had cleaned up Reviewers: broulik Reviewed By: broulik Subscribers: kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D13032
2018-03-11Remove not necessary QtCore and coLaurent Montel
2017-12-02KConfig: fix autotest on CI with trailing slash in HOME.David Faure
Summary: The CI has $HOME=/home/jenkins/ with a trailing slash, which leads to FAIL! : KConfigTest::testPath() Compared values are not the same Actual (sc3.readPathEntry("homepath", QString())): "/home/jenkins//foo" Expected (HOMEPATH): "/home/jenkins/foo" QDir::homePath() is too clean for our purposes, use $HOME on Unix. Test Plan: kconfigtest now passes with HOME=/home/dfaure/
2017-12-02Repair broken test after commit ee2b394599.David Faure
QStringLiteral is latin1, not utf8.
2017-11-30Fix some clazy warningMontel Laurent
2016-09-27Marm test QSKIP when running as root.Evgeniy Sadovnik
The test checks that saving a read-only config file fails. But because root can write into read-only files, the test is failing when running by root. Check for uid when running the test and make it XFAIL if we are running as root. REVIEW: 128916
2016-03-28Add support for get QStandardPaths locations.Sandro Knauß
Inside desktop files we want to reach also data, cache and config home to create files inside these directories. REVIEW: 127462 CHANGELOG: Add support for get QStandardPaths locations inside desktop files.
2015-11-09In KConfigTest::testEntryMap, convert QByteArray with nulls using a char *Matthew Dawson
Due to https://codereview.qt-project.org/#/c/106473/, Qt 5.6 keeps null characters in QByteArray -> QString conversions, which breaks this test as one QByteArray contains nulls. Instead, convert the QByteArray to const char * first, so QString stops at the first null. The actual behaviour of KConfig is unchanged, as internally the conversion always went through a const char *, which avoids creating QStrings with null characters. REVIEW: 126001
2015-08-19unittest fix: compare floats/doubles rather than ↵David Faure
strings-made-from-floats/doubles. Qt 5.5 writes out "123.567001" for 123.567f. No matter, what we want is the roundtrip float-string-float to work, and it does.