diff options
Diffstat (limited to 'src/test/BurnUnitTest/RegistrationTest.cpp')
| -rw-r--r-- | src/test/BurnUnitTest/RegistrationTest.cpp | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/src/test/BurnUnitTest/RegistrationTest.cpp b/src/test/BurnUnitTest/RegistrationTest.cpp index 1687385b..883a1258 100644 --- a/src/test/BurnUnitTest/RegistrationTest.cpp +++ b/src/test/BurnUnitTest/RegistrationTest.cpp | |||
| @@ -73,6 +73,7 @@ namespace Bootstrapper | |||
| 73 | BURN_LOGGING logging = { }; | 73 | BURN_LOGGING logging = { }; |
| 74 | BURN_PACKAGES packages = { }; | 74 | BURN_PACKAGES packages = { }; |
| 75 | String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}")); | 75 | String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}")); |
| 76 | |||
| 76 | try | 77 | try |
| 77 | { | 78 | { |
| 78 | // set mock API's | 79 | // set mock API's |
| @@ -261,6 +262,115 @@ namespace Bootstrapper | |||
| 261 | } | 262 | } |
| 262 | 263 | ||
| 263 | [Fact] | 264 | [Fact] |
| 265 | void RegisterVariablesTest() | ||
| 266 | { | ||
| 267 | HRESULT hr = S_OK; | ||
| 268 | IXMLDOMElement* pixeBundle = NULL; | ||
| 269 | LPWSTR sczCurrentProcess = NULL; | ||
| 270 | BURN_VARIABLES variables = { }; | ||
| 271 | BURN_USER_EXPERIENCE userExperience = { }; | ||
| 272 | BOOTSTRAPPER_COMMAND command = { }; | ||
| 273 | BURN_REGISTRATION registration = { }; | ||
| 274 | BURN_LOGGING logging = { }; | ||
| 275 | BURN_PACKAGES packages = { }; | ||
| 276 | String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}")); | ||
| 277 | try | ||
| 278 | { | ||
| 279 | // set mock API's | ||
| 280 | RegFunctionOverride(RegistrationTest_RegCreateKeyExW, RegistrationTest_RegOpenKeyExW, RegistrationTest_RegDeleteKeyExW, NULL, NULL, NULL, NULL, NULL, NULL); | ||
| 281 | |||
| 282 | Registry::CurrentUser->CreateSubKey(gcnew String(HKCU_PATH)); | ||
| 283 | |||
| 284 | logging.sczPath = L"BurnUnitTest.txt"; | ||
| 285 | |||
| 286 | LPCWSTR wzDocument = | ||
| 287 | L"<Bundle>" | ||
| 288 | L" <UX>" | ||
| 289 | L" <Payload Id='ux.dll' FilePath='ux.dll' Packaging='embedded' SourcePath='ux.dll' Hash='000000000000' />" | ||
| 290 | L" </UX>" | ||
| 291 | L" <Registration Id='{D54F896D-1952-43e6-9C67-B5652240618C}' UpgradeCode='{D54F896D-1952-43e6-9C67-B5652240618C}' Tag='foo' ProviderKey='bar' Version='1.0.0.0' ExecutableName='setup.exe' PerMachine='no'>" | ||
| 292 | L" <Arp Register='yes' Publisher='WiX Toolset' DisplayName='Product1' DisplayVersion='1.0.0.0' />" | ||
| 293 | L" </Registration>" | ||
| 294 | L"</Bundle>"; | ||
| 295 | |||
| 296 | // load XML document | ||
| 297 | LoadBundleXmlHelper(wzDocument, &pixeBundle); | ||
| 298 | |||
| 299 | hr = VariableInitialize(&variables); | ||
| 300 | TestThrowOnFailure(hr, L"Failed to initialize variables."); | ||
| 301 | |||
| 302 | hr = UserExperienceParseFromXml(&userExperience, pixeBundle); | ||
| 303 | TestThrowOnFailure(hr, L"Failed to parse UX from XML."); | ||
| 304 | |||
| 305 | hr = RegistrationParseFromXml(®istration, pixeBundle); | ||
| 306 | TestThrowOnFailure(hr, L"Failed to parse registration from XML."); | ||
| 307 | |||
| 308 | hr = PlanSetResumeCommand(®istration, BOOTSTRAPPER_ACTION_INSTALL, &command, &logging); | ||
| 309 | TestThrowOnFailure(hr, L"Failed to set registration resume command."); | ||
| 310 | |||
| 311 | hr = PathForCurrentProcess(&sczCurrentProcess, NULL); | ||
| 312 | TestThrowOnFailure(hr, L"Failed to get current process path."); | ||
| 313 | |||
| 314 | // | ||
| 315 | // install | ||
| 316 | // | ||
| 317 | |||
| 318 | // write registration | ||
| 319 | hr = RegistrationSessionBegin(sczCurrentProcess, ®istration, &variables, &userExperience, BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_REGISTRATION, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, 0); | ||
| 320 | TestThrowOnFailure(hr, L"Failed to register bundle."); | ||
| 321 | |||
| 322 | // verify that registration was created | ||
| 323 | Assert::Equal(Int32(BURN_RESUME_MODE_ACTIVE), (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr)); | ||
| 324 | Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr)); | ||
| 325 | |||
| 326 | // complete registration | ||
| 327 | hr = RegistrationSessionEnd(®istration, &packages, BURN_RESUME_MODE_ARP, BOOTSTRAPPER_APPLY_RESTART_REQUIRED, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER); | ||
| 328 | TestThrowOnFailure(hr, L"Failed to unregister bundle."); | ||
| 329 | |||
| 330 | // verify that registration variables were updated | ||
| 331 | registration.fInstalled = TRUE; | ||
| 332 | |||
| 333 | hr = RegistrationSetVariables(®istration, &variables); | ||
| 334 | TestThrowOnFailure(hr, L"Failed to set registration variables."); | ||
| 335 | |||
| 336 | Assert::Equal(1ll, VariableGetNumericHelper(&variables, BURN_BUNDLE_INSTALLED)); | ||
| 337 | Assert::Equal(1ll, VariableGetNumericHelper(&variables, BURN_REBOOT_PENDING)); | ||
| 338 | Assert::Equal<String^>(gcnew String(L"foo"), VariableGetStringHelper(&variables, BURN_BUNDLE_TAG)); | ||
| 339 | Assert::Equal<String^>(gcnew String(L"bar"), VariableGetStringHelper(&variables, BURN_BUNDLE_PROVIDER_KEY)); | ||
| 340 | Assert::Equal<String^>(gcnew String(L"1.0.0.0"), VariableGetVersionHelper(&variables, BURN_BUNDLE_VERSION)); | ||
| 341 | |||
| 342 | // | ||
| 343 | // uninstall | ||
| 344 | // | ||
| 345 | |||
| 346 | // delete registration | ||
| 347 | hr = RegistrationSessionEnd(®istration, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER); | ||
| 348 | TestThrowOnFailure(hr, L"Failed to unregister bundle."); | ||
| 349 | |||
| 350 | // verify that registration was removed | ||
| 351 | Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr)); | ||
| 352 | Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Installed"), nullptr)); | ||
| 353 | Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr)); | ||
| 354 | } | ||
| 355 | finally | ||
| 356 | { | ||
| 357 | ReleaseStr(sczCurrentProcess); | ||
| 358 | ReleaseObject(pixeBundle); | ||
| 359 | UserExperienceUninitialize(&userExperience); | ||
| 360 | RegistrationUninitialize(®istration); | ||
| 361 | VariablesUninitialize(&variables); | ||
| 362 | |||
| 363 | Registry::CurrentUser->DeleteSubKeyTree(gcnew String(ROOT_PATH)); | ||
| 364 | if (Directory::Exists(cacheDirectory)) | ||
| 365 | { | ||
| 366 | Directory::Delete(cacheDirectory, true); | ||
| 367 | } | ||
| 368 | |||
| 369 | RegFunctionOverride(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); | ||
| 370 | } | ||
| 371 | } | ||
| 372 | |||
| 373 | [Fact] | ||
| 264 | void RegisterArpFullTest() | 374 | void RegisterArpFullTest() |
| 265 | { | 375 | { |
| 266 | HRESULT hr = S_OK; | 376 | HRESULT hr = S_OK; |
