diff options
Diffstat (limited to 'src/burn/test/BurnUnitTest/TestRegistryFixture.cpp')
| -rw-r--r-- | src/burn/test/BurnUnitTest/TestRegistryFixture.cpp | 208 |
1 files changed, 138 insertions, 70 deletions
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 @@ | |||
| 4 | 4 | ||
| 5 | #define TEST_REGISTRY_FIXTURE_ROOT_PATH L"SOFTWARE\\WiX_Burn_UnitTest" | 5 | #define TEST_REGISTRY_FIXTURE_ROOT_PATH L"SOFTWARE\\WiX_Burn_UnitTest" |
| 6 | #define TEST_REGISTRY_FIXTURE_HKLM_PATH TEST_REGISTRY_FIXTURE_ROOT_PATH L"\\HKLM" | 6 | #define TEST_REGISTRY_FIXTURE_HKLM_PATH TEST_REGISTRY_FIXTURE_ROOT_PATH L"\\HKLM" |
| 7 | #define TEST_REGISTRY_FIXTURE_HKLM32_PATH TEST_REGISTRY_FIXTURE_ROOT_PATH L"\\Wow6432Node\\HKLM" | ||
| 7 | #define TEST_REGISTRY_FIXTURE_HKCU_PATH TEST_REGISTRY_FIXTURE_ROOT_PATH L"\\HKCU" | 8 | #define TEST_REGISTRY_FIXTURE_HKCU_PATH TEST_REGISTRY_FIXTURE_ROOT_PATH L"\\HKCU" |
| 9 | #define TEST_REGISTRY_FIXTURE_HKCU32_PATH TEST_REGISTRY_FIXTURE_ROOT_PATH L"\\Wow6432Node\\HKCU" | ||
| 8 | 10 | ||
| 9 | static LSTATUS APIENTRY TestRegistryFixture_RegCreateKeyExW( | 11 | static REG_KEY_BITNESS GetDesiredBitness( |
| 12 | __in REGSAM samDesired | ||
| 13 | ) | ||
| 14 | { | ||
| 15 | REG_KEY_BITNESS desiredBitness = REG_KEY_DEFAULT; | ||
| 16 | |||
| 17 | switch (KEY_WOW64_RES & samDesired) | ||
| 18 | { | ||
| 19 | case KEY_WOW64_32KEY: | ||
| 20 | desiredBitness = REG_KEY_32BIT; | ||
| 21 | break; | ||
| 22 | case KEY_WOW64_64KEY: | ||
| 23 | desiredBitness = REG_KEY_64BIT; | ||
| 24 | break; | ||
| 25 | default: | ||
| 26 | #if defined(_WIN64) | ||
| 27 | desiredBitness = REG_KEY_64BIT; | ||
| 28 | #else | ||
| 29 | desiredBitness = REG_KEY_32BIT; | ||
| 30 | #endif | ||
| 31 | break; | ||
| 32 | } | ||
| 33 | |||
| 34 | return desiredBitness; | ||
| 35 | } | ||
| 36 | |||
| 37 | static LSTATUS GetRootKey( | ||
| 10 | __in HKEY hKey, | 38 | __in HKEY hKey, |
| 11 | __in LPCWSTR lpSubKey, | ||
| 12 | __reserved DWORD Reserved, | ||
| 13 | __in_opt LPWSTR lpClass, | ||
| 14 | __in DWORD dwOptions, | ||
| 15 | __in REGSAM samDesired, | 39 | __in REGSAM samDesired, |
| 16 | __in_opt CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes, | 40 | __in ACCESS_MASK accessDesired, |
| 17 | __out PHKEY phkResult, | 41 | __inout HKEY* phkRoot) |
| 18 | __out_opt LPDWORD lpdwDisposition | ||
| 19 | ) | ||
| 20 | { | 42 | { |
| 21 | LSTATUS ls = ERROR_SUCCESS; | 43 | LSTATUS ls = ERROR_SUCCESS; |
| 22 | LPCWSTR wzRoot = NULL; | 44 | LPCWSTR wzRoot = NULL; |
| 23 | HKEY hkRoot = NULL; | ||
| 24 | 45 | ||
| 25 | if (HKEY_LOCAL_MACHINE == hKey) | 46 | if (HKEY_LOCAL_MACHINE == hKey) |
| 26 | { | 47 | { |
| 27 | wzRoot = TEST_REGISTRY_FIXTURE_HKLM_PATH; | 48 | if (REG_KEY_32BIT == GetDesiredBitness(samDesired)) |
| 49 | { | ||
| 50 | wzRoot = TEST_REGISTRY_FIXTURE_HKLM32_PATH; | ||
| 51 | } | ||
| 52 | else | ||
| 53 | { | ||
| 54 | wzRoot = TEST_REGISTRY_FIXTURE_HKLM_PATH; | ||
| 55 | } | ||
| 28 | } | 56 | } |
| 29 | else if (HKEY_CURRENT_USER == hKey) | 57 | else if (HKEY_CURRENT_USER == hKey) |
| 30 | { | 58 | { |
| 31 | wzRoot = TEST_REGISTRY_FIXTURE_HKCU_PATH; | 59 | if (REG_KEY_32BIT == GetDesiredBitness(samDesired)) |
| 60 | { | ||
| 61 | wzRoot = TEST_REGISTRY_FIXTURE_HKCU32_PATH; | ||
| 62 | } | ||
| 63 | else | ||
| 64 | { | ||
| 65 | wzRoot = TEST_REGISTRY_FIXTURE_HKCU_PATH; | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | if (wzRoot) | ||
| 70 | { | ||
| 71 | ls = ::RegOpenKeyExW(HKEY_CURRENT_USER, wzRoot, 0, KEY_WRITE | accessDesired, phkRoot); | ||
| 32 | } | 72 | } |
| 33 | else | 73 | else |
| 34 | { | 74 | { |
| 35 | hkRoot = hKey; | 75 | *phkRoot = hKey; |
| 36 | } | 76 | } |
| 37 | 77 | ||
| 38 | if (wzRoot) | 78 | return ls; |
| 79 | } | ||
| 80 | |||
| 81 | static LSTATUS APIENTRY TestRegistryFixture_RegCreateKeyExW( | ||
| 82 | __in HKEY hKey, | ||
| 83 | __in LPCWSTR lpSubKey, | ||
| 84 | __reserved DWORD Reserved, | ||
| 85 | __in_opt LPWSTR lpClass, | ||
| 86 | __in DWORD dwOptions, | ||
| 87 | __in REGSAM samDesired, | ||
| 88 | __in_opt CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes, | ||
| 89 | __out PHKEY phkResult, | ||
| 90 | __out_opt LPDWORD lpdwDisposition | ||
| 91 | ) | ||
| 92 | { | ||
| 93 | LSTATUS ls = ERROR_SUCCESS; | ||
| 94 | HKEY hkRoot = NULL; | ||
| 95 | |||
| 96 | ls = GetRootKey(hKey, samDesired, 0, &hkRoot); | ||
| 97 | if (ERROR_SUCCESS != ls) | ||
| 39 | { | 98 | { |
| 40 | ls = ::RegOpenKeyExW(HKEY_CURRENT_USER, wzRoot, 0, KEY_WRITE, &hkRoot); | 99 | ExitFunction(); |
| 41 | if (ERROR_SUCCESS != ls) | ||
| 42 | { | ||
| 43 | ExitFunction(); | ||
| 44 | } | ||
| 45 | } | 100 | } |
| 46 | 101 | ||
| 47 | ls = ::RegCreateKeyExW(hkRoot, lpSubKey, Reserved, lpClass, dwOptions, samDesired, lpSecurityAttributes, phkResult, lpdwDisposition); | 102 | ls = ::RegCreateKeyExW(hkRoot, lpSubKey, Reserved, lpClass, dwOptions, samDesired, lpSecurityAttributes, phkResult, lpdwDisposition); |
| 48 | 103 | ||
| 49 | LExit: | 104 | LExit: |
| 50 | ReleaseRegKey(hkRoot); | 105 | if (hkRoot != hKey) |
| 106 | { | ||
| 107 | ReleaseRegKey(hkRoot); | ||
| 108 | } | ||
| 51 | 109 | ||
| 52 | return ls; | 110 | return ls; |
| 53 | } | 111 | } |
| @@ -61,35 +119,21 @@ static LSTATUS APIENTRY TestRegistryFixture_RegOpenKeyExW( | |||
| 61 | ) | 119 | ) |
| 62 | { | 120 | { |
| 63 | LSTATUS ls = ERROR_SUCCESS; | 121 | LSTATUS ls = ERROR_SUCCESS; |
| 64 | LPCWSTR wzRoot = NULL; | ||
| 65 | HKEY hkRoot = NULL; | 122 | HKEY hkRoot = NULL; |
| 66 | 123 | ||
| 67 | if (HKEY_LOCAL_MACHINE == hKey) | 124 | ls = GetRootKey(hKey, samDesired, 0, &hkRoot); |
| 68 | { | 125 | if (ERROR_SUCCESS != ls) |
| 69 | wzRoot = TEST_REGISTRY_FIXTURE_HKLM_PATH; | ||
| 70 | } | ||
| 71 | else if (HKEY_CURRENT_USER == hKey) | ||
| 72 | { | ||
| 73 | wzRoot = TEST_REGISTRY_FIXTURE_HKCU_PATH; | ||
| 74 | } | ||
| 75 | else | ||
| 76 | { | ||
| 77 | hkRoot = hKey; | ||
| 78 | } | ||
| 79 | |||
| 80 | if (wzRoot) | ||
| 81 | { | 126 | { |
| 82 | ls = ::RegOpenKeyExW(HKEY_CURRENT_USER, wzRoot, 0, KEY_WRITE, &hkRoot); | 127 | ExitFunction(); |
| 83 | if (ERROR_SUCCESS != ls) | ||
| 84 | { | ||
| 85 | ExitFunction(); | ||
| 86 | } | ||
| 87 | } | 128 | } |
| 88 | 129 | ||
| 89 | ls = ::RegOpenKeyExW(hkRoot, lpSubKey, ulOptions, samDesired, phkResult); | 130 | ls = ::RegOpenKeyExW(hkRoot, lpSubKey, ulOptions, samDesired, phkResult); |
| 90 | 131 | ||
| 91 | LExit: | 132 | LExit: |
| 92 | ReleaseRegKey(hkRoot); | 133 | if (hkRoot != hKey) |
| 134 | { | ||
| 135 | ReleaseRegKey(hkRoot); | ||
| 136 | } | ||
| 93 | 137 | ||
| 94 | return ls; | 138 | return ls; |
| 95 | } | 139 | } |
| @@ -102,35 +146,21 @@ static LSTATUS APIENTRY TestRegistryFixture_RegDeleteKeyExW( | |||
| 102 | ) | 146 | ) |
| 103 | { | 147 | { |
| 104 | LSTATUS ls = ERROR_SUCCESS; | 148 | LSTATUS ls = ERROR_SUCCESS; |
| 105 | LPCWSTR wzRoot = NULL; | ||
| 106 | HKEY hkRoot = NULL; | 149 | HKEY hkRoot = NULL; |
| 107 | 150 | ||
| 108 | if (HKEY_LOCAL_MACHINE == hKey) | 151 | ls = GetRootKey(hKey, samDesired, samDesired, &hkRoot); |
| 152 | if (ERROR_SUCCESS != ls) | ||
| 109 | { | 153 | { |
| 110 | wzRoot = TEST_REGISTRY_FIXTURE_HKLM_PATH; | 154 | ExitFunction(); |
| 111 | } | ||
| 112 | else if (HKEY_CURRENT_USER == hKey) | ||
| 113 | { | ||
| 114 | wzRoot = TEST_REGISTRY_FIXTURE_HKCU_PATH; | ||
| 115 | } | ||
| 116 | else | ||
| 117 | { | ||
| 118 | hkRoot = hKey; | ||
| 119 | } | ||
| 120 | |||
| 121 | if (wzRoot) | ||
| 122 | { | ||
| 123 | ls = ::RegOpenKeyExW(HKEY_CURRENT_USER, wzRoot, 0, KEY_WRITE | samDesired, &hkRoot); | ||
| 124 | if (ERROR_SUCCESS != ls) | ||
| 125 | { | ||
| 126 | ExitFunction(); | ||
| 127 | } | ||
| 128 | } | 155 | } |
| 129 | 156 | ||
| 130 | ls = ::RegDeleteKeyExW(hkRoot, lpSubKey, samDesired, Reserved); | 157 | ls = ::RegDeleteKeyExW(hkRoot, lpSubKey, samDesired, Reserved); |
| 131 | 158 | ||
| 132 | LExit: | 159 | LExit: |
| 133 | ReleaseRegKey(hkRoot); | 160 | if (hkRoot != hKey) |
| 161 | { | ||
| 162 | ReleaseRegKey(hkRoot); | ||
| 163 | } | ||
| 134 | 164 | ||
| 135 | return ls; | 165 | return ls; |
| 136 | } | 166 | } |
| @@ -146,8 +176,6 @@ namespace WixBuildTools | |||
| 146 | TestRegistryFixture::TestRegistryFixture() | 176 | TestRegistryFixture::TestRegistryFixture() |
| 147 | { | 177 | { |
| 148 | this->rootPath = gcnew String(TEST_REGISTRY_FIXTURE_ROOT_PATH); | 178 | this->rootPath = gcnew String(TEST_REGISTRY_FIXTURE_ROOT_PATH); |
| 149 | this->hkcuPath = gcnew String(TEST_REGISTRY_FIXTURE_HKCU_PATH); | ||
| 150 | this->hklmPath = gcnew String(TEST_REGISTRY_FIXTURE_HKLM_PATH); | ||
| 151 | } | 179 | } |
| 152 | 180 | ||
| 153 | TestRegistryFixture::~TestRegistryFixture() | 181 | TestRegistryFixture::~TestRegistryFixture() |
| @@ -160,8 +188,10 @@ namespace WixBuildTools | |||
| 160 | // set mock API's | 188 | // set mock API's |
| 161 | RegFunctionOverride(TestRegistryFixture_RegCreateKeyExW, TestRegistryFixture_RegOpenKeyExW, TestRegistryFixture_RegDeleteKeyExW, NULL, NULL, NULL, NULL, NULL, NULL); | 189 | RegFunctionOverride(TestRegistryFixture_RegCreateKeyExW, TestRegistryFixture_RegOpenKeyExW, TestRegistryFixture_RegDeleteKeyExW, NULL, NULL, NULL, NULL, NULL, NULL); |
| 162 | 190 | ||
| 163 | Registry::CurrentUser->CreateSubKey(this->hkcuPath); | 191 | Registry::CurrentUser->CreateSubKey(TEST_REGISTRY_FIXTURE_HKCU_PATH); |
| 164 | Registry::CurrentUser->CreateSubKey(this->hklmPath); | 192 | Registry::CurrentUser->CreateSubKey(TEST_REGISTRY_FIXTURE_HKCU32_PATH); |
| 193 | Registry::CurrentUser->CreateSubKey(TEST_REGISTRY_FIXTURE_HKLM_PATH); | ||
| 194 | Registry::CurrentUser->CreateSubKey(TEST_REGISTRY_FIXTURE_HKLM32_PATH); | ||
| 165 | } | 195 | } |
| 166 | 196 | ||
| 167 | void TestRegistryFixture::TearDown() | 197 | void TestRegistryFixture::TearDown() |
| @@ -171,14 +201,52 @@ namespace WixBuildTools | |||
| 171 | RegFunctionOverride(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); | 201 | RegFunctionOverride(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
| 172 | } | 202 | } |
| 173 | 203 | ||
| 174 | String^ TestRegistryFixture::GetDirectHkcuPath(... array<String^>^ paths) | 204 | String^ TestRegistryFixture::GetDirectHkcuPath(REG_KEY_BITNESS bitness, ... array<String^>^ paths) |
| 175 | { | 205 | { |
| 176 | return Path::Combine(Registry::CurrentUser->Name, this->hkcuPath, Path::Combine(paths)); | 206 | String^ hkcuPath; |
| 207 | |||
| 208 | switch (bitness) | ||
| 209 | { | ||
| 210 | case REG_KEY_32BIT: | ||
| 211 | hkcuPath = TEST_REGISTRY_FIXTURE_HKCU32_PATH; | ||
| 212 | break; | ||
| 213 | case REG_KEY_64BIT: | ||
| 214 | hkcuPath = TEST_REGISTRY_FIXTURE_HKCU_PATH; | ||
| 215 | break; | ||
| 216 | default: | ||
| 217 | #if defined(_WIN64) | ||
| 218 | hkcuPath = TEST_REGISTRY_FIXTURE_HKCU_PATH; | ||
| 219 | #else | ||
| 220 | hkcuPath = TEST_REGISTRY_FIXTURE_HKCU32_PATH; | ||
| 221 | #endif | ||
| 222 | break; | ||
| 223 | } | ||
| 224 | |||
| 225 | return Path::Combine(Registry::CurrentUser->Name, hkcuPath, Path::Combine(paths)); | ||
| 177 | } | 226 | } |
| 178 | 227 | ||
| 179 | String^ TestRegistryFixture::GetDirectHklmPath(... array<String^>^ paths) | 228 | String^ TestRegistryFixture::GetDirectHklmPath(REG_KEY_BITNESS bitness, ... array<String^>^ paths) |
| 180 | { | 229 | { |
| 181 | return Path::Combine(Registry::CurrentUser->Name, this->hklmPath, Path::Combine(paths)); | 230 | String^ hklmPath; |
| 231 | |||
| 232 | switch (bitness) | ||
| 233 | { | ||
| 234 | case REG_KEY_32BIT: | ||
| 235 | hklmPath = TEST_REGISTRY_FIXTURE_HKLM32_PATH; | ||
| 236 | break; | ||
| 237 | case REG_KEY_64BIT: | ||
| 238 | hklmPath = TEST_REGISTRY_FIXTURE_HKLM_PATH; | ||
| 239 | break; | ||
| 240 | default: | ||
| 241 | #if defined(_WIN64) | ||
| 242 | hklmPath = TEST_REGISTRY_FIXTURE_HKLM_PATH; | ||
| 243 | #else | ||
| 244 | hklmPath = TEST_REGISTRY_FIXTURE_HKLM32_PATH; | ||
| 245 | #endif | ||
| 246 | break; | ||
| 247 | } | ||
| 248 | |||
| 249 | return Path::Combine(Registry::CurrentUser->Name, hklmPath, Path::Combine(paths)); | ||
| 182 | } | 250 | } |
| 183 | } | 251 | } |
| 184 | } | 252 | } |
