summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io
diff options
context:
space:
mode:
authorSebastian Schuberth <sschuberth@gmail.com>2015-07-03 10:55:08 +0200
committerSebastian Schuberth <sschuberth@gmail.com>2015-08-27 07:08:30 +0000
commit64261c0871043ef44a0a9c855d78428e773dfa94 (patch)
tree3e2ce062166408b01cc270e63f86d38489d3954d /tests/auto/corelib/io
parentbfecc2dbc670bdb2fa514d96c89ab65cfb10a3c8 (diff)
Support accessing 32-bit Registry from 64-bit programs and vice versa
For details see "Accessing an Alternate Registry View": http://msdn.microsoft.com/en-us/library/aa384129%28VS.85%29.aspx Task-number: QTBUG-3845 Change-Id: Iecf24b15dc01830686ddd708871bc3392d95282f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/io')
-rw-r--r--tests/auto/corelib/io/qsettings/tst_qsettings.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp
index 3ed1b0aa2c..d7b126e65c 100644
--- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp
+++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp
@@ -121,6 +121,7 @@ private slots:
void testEmptyKey();
void testResourceFiles();
void testRegistryShortRootNames();
+ void testRegistry32And64Bit();
void trailingWhitespace();
#ifdef Q_OS_MAC
void fileName();
@@ -2075,6 +2076,52 @@ void tst_QSettings::testRegistryShortRootNames()
#endif
}
+void tst_QSettings::testRegistry32And64Bit()
+{
+#if !defined (Q_OS_WIN) || defined(Q_OS_WINRT)
+ QSKIP("This test is specific to the Windows registry.", SkipAll);
+#else
+
+ const QString key("HKEY_LOCAL_MACHINE\\Software");
+ const QString keyWow("HKEY_LOCAL_MACHINE\\Software\\Wow6432Node");
+
+#ifndef Q_OS_WIN64
+ // This branch is taken at compile time if targeting 32-bit; it does not
+ // necessarily mean that the OS running the test is 32-bit (it could be
+ // e.g. 64-bit).
+ QCOMPARE(QSettings(key, QSettings::NativeFormat).childGroups(),
+ QSettings(key, QSettings::Registry32Format).childGroups());
+
+ // Detect whether we are running under 64-bit Windows.
+ typedef BOOL (WINAPI *IsWow64ProcessPtr)(HANDLE hProcess, PBOOL Wow64Process);
+ IsWow64ProcessPtr IsWow64Process = (IsWow64ProcessPtr)QLibrary::resolve(
+ "kernel32.dll", "IsWow64Process");
+
+ if (IsWow64Process) {
+ BOOL IsWow64 = FALSE;
+ if (IsWow64Process(GetCurrentProcess(), &IsWow64) && IsWow64) {
+ // The 64-bit registry's "Wow6432Node" key should match the 32-bit registry.
+ // If we are not on 32-bit Windows, these should never be the same,
+ // because the 64-bit registry has a "Wow6432Node" key.
+ QCOMPARE(QSettings(keyWow, QSettings::Registry64Format).childGroups(),
+ QSettings(key, QSettings::Registry32Format).childGroups());
+ }
+ }
+#else
+ // This branch is taken at compile time if targeting 64-bit; it does not
+ // necessarily mean that the OS running the test is 64-bit (it could be
+ // e.g. 128-bit).
+ QCOMPARE(QSettings(key, QSettings::NativeFormat).childGroups(),
+ QSettings(key, QSettings::Registry64Format).childGroups());
+
+ // The 64-bit registry's "Wow6432Node" key should match the 32-bit registry.
+ QCOMPARE(QSettings(keyWow, QSettings::Registry64Format).childGroups(),
+ QSettings(key, QSettings::Registry32Format).childGroups());
+#endif
+
+#endif
+}
+
void tst_QSettings::trailingWhitespace()
{
{