From 3f658fa2b4bd80619fcf89e1e87ae12b48effb7a Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Mon, 28 Feb 2022 18:41:14 -0600 Subject: Fix and run Burn 64-bit unit tests. --- src/burn/test/BurnUnitTest/TestRegistryFixture.cpp | 208 ++++++++++++++------- 1 file changed, 138 insertions(+), 70 deletions(-) (limited to 'src/burn/test/BurnUnitTest/TestRegistryFixture.cpp') diff --git a/src/burn/test/BurnUnitTest/TestRegistryFixture.cpp b/src/burn/test/BurnUnitTest/TestRegistryFixture.cpp index 3e78c6f5..1f3d7680 100644 --- a/src/burn/test/BurnUnitTest/TestRegistryFixture.cpp +++ b/src/burn/test/BurnUnitTest/TestRegistryFixture.cpp @@ -4,50 +4,108 @@ #define TEST_REGISTRY_FIXTURE_ROOT_PATH L"SOFTWARE\\WiX_Burn_UnitTest" #define TEST_REGISTRY_FIXTURE_HKLM_PATH TEST_REGISTRY_FIXTURE_ROOT_PATH L"\\HKLM" +#define TEST_REGISTRY_FIXTURE_HKLM32_PATH TEST_REGISTRY_FIXTURE_ROOT_PATH L"\\Wow6432Node\\HKLM" #define TEST_REGISTRY_FIXTURE_HKCU_PATH TEST_REGISTRY_FIXTURE_ROOT_PATH L"\\HKCU" +#define TEST_REGISTRY_FIXTURE_HKCU32_PATH TEST_REGISTRY_FIXTURE_ROOT_PATH L"\\Wow6432Node\\HKCU" -static LSTATUS APIENTRY TestRegistryFixture_RegCreateKeyExW( +static REG_KEY_BITNESS GetDesiredBitness( + __in REGSAM samDesired + ) +{ + REG_KEY_BITNESS desiredBitness = REG_KEY_DEFAULT; + + switch (KEY_WOW64_RES & samDesired) + { + case KEY_WOW64_32KEY: + desiredBitness = REG_KEY_32BIT; + break; + case KEY_WOW64_64KEY: + desiredBitness = REG_KEY_64BIT; + break; + default: +#if defined(_WIN64) + desiredBitness = REG_KEY_64BIT; +#else + desiredBitness = REG_KEY_32BIT; +#endif + break; + } + + return desiredBitness; +} + +static LSTATUS GetRootKey( __in HKEY hKey, - __in LPCWSTR lpSubKey, - __reserved DWORD Reserved, - __in_opt LPWSTR lpClass, - __in DWORD dwOptions, __in REGSAM samDesired, - __in_opt CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes, - __out PHKEY phkResult, - __out_opt LPDWORD lpdwDisposition - ) + __in ACCESS_MASK accessDesired, + __inout HKEY* phkRoot) { LSTATUS ls = ERROR_SUCCESS; LPCWSTR wzRoot = NULL; - HKEY hkRoot = NULL; if (HKEY_LOCAL_MACHINE == hKey) { - wzRoot = TEST_REGISTRY_FIXTURE_HKLM_PATH; + if (REG_KEY_32BIT == GetDesiredBitness(samDesired)) + { + wzRoot = TEST_REGISTRY_FIXTURE_HKLM32_PATH; + } + else + { + wzRoot = TEST_REGISTRY_FIXTURE_HKLM_PATH; + } } else if (HKEY_CURRENT_USER == hKey) { - wzRoot = TEST_REGISTRY_FIXTURE_HKCU_PATH; + if (REG_KEY_32BIT == GetDesiredBitness(samDesired)) + { + wzRoot = TEST_REGISTRY_FIXTURE_HKCU32_PATH; + } + else + { + wzRoot = TEST_REGISTRY_FIXTURE_HKCU_PATH; + } + } + + if (wzRoot) + { + ls = ::RegOpenKeyExW(HKEY_CURRENT_USER, wzRoot, 0, KEY_WRITE | accessDesired, phkRoot); } else { - hkRoot = hKey; + *phkRoot = hKey; } - if (wzRoot) + return ls; +} + +static LSTATUS APIENTRY TestRegistryFixture_RegCreateKeyExW( + __in HKEY hKey, + __in LPCWSTR lpSubKey, + __reserved DWORD Reserved, + __in_opt LPWSTR lpClass, + __in DWORD dwOptions, + __in REGSAM samDesired, + __in_opt CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes, + __out PHKEY phkResult, + __out_opt LPDWORD lpdwDisposition + ) +{ + LSTATUS ls = ERROR_SUCCESS; + HKEY hkRoot = NULL; + + ls = GetRootKey(hKey, samDesired, 0, &hkRoot); + if (ERROR_SUCCESS != ls) { - ls = ::RegOpenKeyExW(HKEY_CURRENT_USER, wzRoot, 0, KEY_WRITE, &hkRoot); - if (ERROR_SUCCESS != ls) - { - ExitFunction(); - } + ExitFunction(); } ls = ::RegCreateKeyExW(hkRoot, lpSubKey, Reserved, lpClass, dwOptions, samDesired, lpSecurityAttributes, phkResult, lpdwDisposition); LExit: - ReleaseRegKey(hkRoot); + if (hkRoot != hKey) + { + ReleaseRegKey(hkRoot); + } return ls; } @@ -61,35 +119,21 @@ static LSTATUS APIENTRY TestRegistryFixture_RegOpenKeyExW( ) { LSTATUS ls = ERROR_SUCCESS; - LPCWSTR wzRoot = NULL; HKEY hkRoot = NULL; - if (HKEY_LOCAL_MACHINE == hKey) - { - wzRoot = TEST_REGISTRY_FIXTURE_HKLM_PATH; - } - else if (HKEY_CURRENT_USER == hKey) - { - wzRoot = TEST_REGISTRY_FIXTURE_HKCU_PATH; - } - else - { - hkRoot = hKey; - } - - if (wzRoot) + ls = GetRootKey(hKey, samDesired, 0, &hkRoot); + if (ERROR_SUCCESS != ls) { - ls = ::RegOpenKeyExW(HKEY_CURRENT_USER, wzRoot, 0, KEY_WRITE, &hkRoot); - if (ERROR_SUCCESS != ls) - { - ExitFunction(); - } + ExitFunction(); } ls = ::RegOpenKeyExW(hkRoot, lpSubKey, ulOptions, samDesired, phkResult); LExit: - ReleaseRegKey(hkRoot); + if (hkRoot != hKey) + { + ReleaseRegKey(hkRoot); + } return ls; } @@ -102,35 +146,21 @@ static LSTATUS APIENTRY TestRegistryFixture_RegDeleteKeyExW( ) { LSTATUS ls = ERROR_SUCCESS; - LPCWSTR wzRoot = NULL; HKEY hkRoot = NULL; - if (HKEY_LOCAL_MACHINE == hKey) + ls = GetRootKey(hKey, samDesired, samDesired, &hkRoot); + if (ERROR_SUCCESS != ls) { - wzRoot = TEST_REGISTRY_FIXTURE_HKLM_PATH; - } - else if (HKEY_CURRENT_USER == hKey) - { - wzRoot = TEST_REGISTRY_FIXTURE_HKCU_PATH; - } - else - { - hkRoot = hKey; - } - - if (wzRoot) - { - ls = ::RegOpenKeyExW(HKEY_CURRENT_USER, wzRoot, 0, KEY_WRITE | samDesired, &hkRoot); - if (ERROR_SUCCESS != ls) - { - ExitFunction(); - } + ExitFunction(); } ls = ::RegDeleteKeyExW(hkRoot, lpSubKey, samDesired, Reserved); LExit: - ReleaseRegKey(hkRoot); + if (hkRoot != hKey) + { + ReleaseRegKey(hkRoot); + } return ls; } @@ -146,8 +176,6 @@ namespace WixBuildTools TestRegistryFixture::TestRegistryFixture() { this->rootPath = gcnew String(TEST_REGISTRY_FIXTURE_ROOT_PATH); - this->hkcuPath = gcnew String(TEST_REGISTRY_FIXTURE_HKCU_PATH); - this->hklmPath = gcnew String(TEST_REGISTRY_FIXTURE_HKLM_PATH); } TestRegistryFixture::~TestRegistryFixture() @@ -160,8 +188,10 @@ namespace WixBuildTools // set mock API's RegFunctionOverride(TestRegistryFixture_RegCreateKeyExW, TestRegistryFixture_RegOpenKeyExW, TestRegistryFixture_RegDeleteKeyExW, NULL, NULL, NULL, NULL, NULL, NULL); - Registry::CurrentUser->CreateSubKey(this->hkcuPath); - Registry::CurrentUser->CreateSubKey(this->hklmPath); + Registry::CurrentUser->CreateSubKey(TEST_REGISTRY_FIXTURE_HKCU_PATH); + Registry::CurrentUser->CreateSubKey(TEST_REGISTRY_FIXTURE_HKCU32_PATH); + Registry::CurrentUser->CreateSubKey(TEST_REGISTRY_FIXTURE_HKLM_PATH); + Registry::CurrentUser->CreateSubKey(TEST_REGISTRY_FIXTURE_HKLM32_PATH); } void TestRegistryFixture::TearDown() @@ -171,14 +201,52 @@ namespace WixBuildTools RegFunctionOverride(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); } - String^ TestRegistryFixture::GetDirectHkcuPath(... array^ paths) + String^ TestRegistryFixture::GetDirectHkcuPath(REG_KEY_BITNESS bitness, ... array^ paths) { - return Path::Combine(Registry::CurrentUser->Name, this->hkcuPath, Path::Combine(paths)); + String^ hkcuPath; + + switch (bitness) + { + case REG_KEY_32BIT: + hkcuPath = TEST_REGISTRY_FIXTURE_HKCU32_PATH; + break; + case REG_KEY_64BIT: + hkcuPath = TEST_REGISTRY_FIXTURE_HKCU_PATH; + break; + default: +#if defined(_WIN64) + hkcuPath = TEST_REGISTRY_FIXTURE_HKCU_PATH; +#else + hkcuPath = TEST_REGISTRY_FIXTURE_HKCU32_PATH; +#endif + break; + } + + return Path::Combine(Registry::CurrentUser->Name, hkcuPath, Path::Combine(paths)); } - String^ TestRegistryFixture::GetDirectHklmPath(... array^ paths) + String^ TestRegistryFixture::GetDirectHklmPath(REG_KEY_BITNESS bitness, ... array^ paths) { - return Path::Combine(Registry::CurrentUser->Name, this->hklmPath, Path::Combine(paths)); + String^ hklmPath; + + switch (bitness) + { + case REG_KEY_32BIT: + hklmPath = TEST_REGISTRY_FIXTURE_HKLM32_PATH; + break; + case REG_KEY_64BIT: + hklmPath = TEST_REGISTRY_FIXTURE_HKLM_PATH; + break; + default: +#if defined(_WIN64) + hklmPath = TEST_REGISTRY_FIXTURE_HKLM_PATH; +#else + hklmPath = TEST_REGISTRY_FIXTURE_HKLM32_PATH; +#endif + break; + } + + return Path::Combine(Registry::CurrentUser->Name, hklmPath, Path::Combine(paths)); } } } -- cgit v1.2.3-55-g6feb