diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2016-10-04 14:34:33 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> | 2016-10-04 21:21:20 +0000 |
commit | 6c8f32388bc7c7228887560151cde8e6d96cc546 (patch) | |
tree | 8640c52d678bfad07651d06df6234ab08751ecfc /tests/auto/corelib/io/qsettings/tst_qsettings.cpp | |
parent | 0fcd842cecfc15b5153b89b95e9c67b894daf3a6 (diff) |
tst_QSettings: Detect if Apple platforms support writing to SystemScope
A fair amount of tests are skipped if we can't write to the system scope,
eg on iOS. Without this detection they will fail.
Change-Id: I8257f1f24e69dae88925c20d2bff851e81701405
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Diffstat (limited to 'tests/auto/corelib/io/qsettings/tst_qsettings.cpp')
-rw-r--r-- | tests/auto/corelib/io/qsettings/tst_qsettings.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index dcbeb9b927..26bbb16de3 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -54,6 +54,10 @@ #include <unistd.h> #endif +#if defined(Q_OS_DARWIN) +#include <CoreFoundation/CoreFoundation.h> +#endif + Q_DECLARE_METATYPE(QSettings::Format) #ifndef QSETTINGS_P_H_VERSION @@ -72,7 +76,19 @@ static inline bool canWriteNativeSystemSettings() else qErrnoWarning(result, "RegOpenKeyEx failed"); return result == ERROR_SUCCESS; -#else // Q_OS_WIN && !Q_OS_WINRT +#elif defined(Q_OS_DARWIN) + CFStringRef key = CFSTR("canWriteNativeSystemSettings"); + #define ANY_APP_USER_AND_HOST kCFPreferencesAnyApplication, kCFPreferencesAnyUser, kCFPreferencesAnyHost + CFPreferencesSetValue(key, CFSTR("true"), ANY_APP_USER_AND_HOST); + if (CFPreferencesSynchronize(ANY_APP_USER_AND_HOST)) { + // Cleanup + CFPreferencesSetValue(key, 0, ANY_APP_USER_AND_HOST); + CFPreferencesSynchronize(ANY_APP_USER_AND_HOST); + return true; + } else { + return false; + } +#else return true; #endif } |