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/burn.cmd | 3 +- src/burn/burn_t.proj | 1 + src/burn/test/BurnUnitTest/RegistrationTest.cpp | 4 +- src/burn/test/BurnUnitTest/TestRegistryFixture.cpp | 208 ++++++++++++++------- src/burn/test/BurnUnitTest/TestRegistryFixture.h | 6 +- src/burn/test/BurnUnitTest/VariableTest.cpp | 8 + 6 files changed, 153 insertions(+), 77 deletions(-) (limited to 'src/burn') diff --git a/src/burn/burn.cmd b/src/burn/burn.cmd index bd872bad..60640b08 100644 --- a/src/burn/burn.cmd +++ b/src/burn/burn.cmd @@ -15,7 +15,8 @@ nuget restore || exit /b msbuild burn_t.proj -p:Configuration=%_C% -nologo -m -warnaserror -bl:%_L%\burn_build.binlog || exit /b -msbuild test\BurnUnitTest -t:Test -p:Configuration=%_C% -nologo -p:CppCliTestResultsFile="%_L%\TestResults\BurnUnitTest.xunit2.xml" || exit /b +msbuild test\BurnUnitTest -t:Test -p:Configuration=%_C% -p:Platform=Win32 -nologo -p:CppCliTestResultsFile="%_L%\TestResults\BurnUnitTest32.xunit2.xml" || exit /b +msbuild test\BurnUnitTest -t:Test -p:Configuration=%_C% -p:Platform=x64 -nologo -p:CppCliTestResultsFile="%_L%\TestResults\BurnUnitTest64.xunit2.xml" || exit /b @popd @endlocal diff --git a/src/burn/burn_t.proj b/src/burn/burn_t.proj index ffc0c780..d7902fe1 100644 --- a/src/burn/burn_t.proj +++ b/src/burn/burn_t.proj @@ -1,6 +1,7 @@ + diff --git a/src/burn/test/BurnUnitTest/RegistrationTest.cpp b/src/burn/test/BurnUnitTest/RegistrationTest.cpp index f3645893..6a10961d 100644 --- a/src/burn/test/BurnUnitTest/RegistrationTest.cpp +++ b/src/burn/test/BurnUnitTest/RegistrationTest.cpp @@ -37,8 +37,8 @@ namespace Bootstrapper { this->testRegistry = registryFixture; - this->testRunKeyPath = this->testRegistry->GetDirectHkcuPath(gcnew String(REGISTRY_RUN_KEY)); - this->testUninstallKeyPath = this->testRegistry->GetDirectHkcuPath(gcnew String(REGISTRY_UNINSTALL_KEY), gcnew String(TEST_BUNDLE_ID)); + this->testRunKeyPath = this->testRegistry->GetDirectHkcuPath(REG_KEY_DEFAULT, gcnew String(REGISTRY_RUN_KEY)); + this->testUninstallKeyPath = this->testRegistry->GetDirectHkcuPath(REG_KEY_DEFAULT, gcnew String(REGISTRY_UNINSTALL_KEY), gcnew String(TEST_BUNDLE_ID)); this->testVariableKeyPath = Path::Combine(this->testUninstallKeyPath, gcnew String(L"variables")); } 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)); } } } diff --git a/src/burn/test/BurnUnitTest/TestRegistryFixture.h b/src/burn/test/BurnUnitTest/TestRegistryFixture.h index 283efe42..2f283f3e 100644 --- a/src/burn/test/BurnUnitTest/TestRegistryFixture.h +++ b/src/burn/test/BurnUnitTest/TestRegistryFixture.h @@ -11,8 +11,6 @@ namespace TestSupport { private: String^ rootPath; - String^ hkcuPath; - String^ hklmPath; public: TestRegistryFixture(); @@ -22,9 +20,9 @@ namespace TestSupport void TearDown(); - String^ GetDirectHkcuPath(... array^ paths); + String^ GetDirectHkcuPath(REG_KEY_BITNESS bitness, ... array^ paths); - String^ GetDirectHklmPath(... array^ paths); + String^ GetDirectHklmPath(REG_KEY_BITNESS bitness, ... array^ paths); }; } } diff --git a/src/burn/test/BurnUnitTest/VariableTest.cpp b/src/burn/test/BurnUnitTest/VariableTest.cpp index 2ae829dc..53105e69 100644 --- a/src/burn/test/BurnUnitTest/VariableTest.cpp +++ b/src/burn/test/BurnUnitTest/VariableTest.cpp @@ -497,7 +497,11 @@ namespace Bootstrapper Assert::Equal(Environment::GetFolderPath(Environment::SpecialFolder::ApplicationData) + "\\", VariableGetStringHelper(&variables, L"AppDataFolder")); Assert::Equal(Environment::GetFolderPath(Environment::SpecialFolder::CommonApplicationData) + "\\", VariableGetStringHelper(&variables, L"CommonAppDataFolder")); +#if defined(_WIN64) + Assert::Equal(Environment::GetFolderPath(Environment::SpecialFolder::ProgramFiles) + "\\", VariableGetStringHelper(&variables, L"ProgramFiles64Folder")); +#else Assert::Equal(Environment::GetFolderPath(Environment::SpecialFolder::ProgramFiles) + "\\", VariableGetStringHelper(&variables, L"ProgramFilesFolder")); +#endif Assert::Equal(Environment::GetFolderPath(Environment::SpecialFolder::DesktopDirectory) + "\\", VariableGetStringHelper(&variables, L"DesktopFolder")); Assert::Equal(Environment::GetFolderPath(Environment::SpecialFolder::Favorites) + "\\", VariableGetStringHelper(&variables, L"FavoritesFolder")); VariableGetStringHelper(&variables, L"FontsFolder"); @@ -514,7 +518,11 @@ namespace Bootstrapper Assert::Equal(System::IO::Path::GetTempPath(), System::IO::Path::GetFullPath(VariableGetStringHelper(&variables, L"TempFolder"))); VariableGetStringHelper(&variables, L"AdminToolsFolder"); +#if defined(_WIN64) + Assert::Equal(Environment::GetFolderPath(Environment::SpecialFolder::CommonProgramFiles) + "\\", VariableGetStringHelper(&variables, L"CommonFiles64Folder")); +#else Assert::Equal(Environment::GetFolderPath(Environment::SpecialFolder::CommonProgramFiles) + "\\", VariableGetStringHelper(&variables, L"CommonFilesFolder")); +#endif Assert::Equal(Environment::GetFolderPath(Environment::SpecialFolder::MyPictures) + "\\", VariableGetStringHelper(&variables, L"MyPicturesFolder")); Assert::Equal(Environment::GetFolderPath(Environment::SpecialFolder::Templates) + "\\", VariableGetStringHelper(&variables, L"TemplateFolder")); -- cgit v1.2.3-55-g6feb