From 64261c0871043ef44a0a9c855d78428e773dfa94 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Fri, 3 Jul 2015 10:55:08 +0200 Subject: 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 --- tests/auto/corelib/io/qsettings/tst_qsettings.cpp | 47 +++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'tests/auto/corelib') 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() { { -- cgit v1.2.3