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>
This commit is contained in:
Tor Arne Vestbø 2016-10-04 14:34:33 +02:00 committed by Tor Arne Vestbø
parent 0fcd842cec
commit 6c8f32388b

View File

@ -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
}