diff options
author | Jacob Hoover <jacob.hoover@greenheck.com> | 2021-06-11 17:05:06 -0500 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2021-07-18 14:41:21 -0500 |
commit | f3c96bcab560cb09355e9366eac3f4195479d95d (patch) | |
tree | 1585c1f2af7e3582e14663c29c033702e910d12f /src/burn/test/BurnUnitTest/RegistrationTest.cpp | |
parent | 5b2b06c9bffb4e6f17409cec41bc0b4b8dab4c90 (diff) | |
download | wix-f3c96bcab560cb09355e9366eac3f4195479d95d.tar.gz wix-f3c96bcab560cb09355e9366eac3f4195479d95d.tar.bz2 wix-f3c96bcab560cb09355e9366eac3f4195479d95d.zip |
Allow access to persisted variables from related bundles.
Implements #3704
Diffstat (limited to 'src/burn/test/BurnUnitTest/RegistrationTest.cpp')
-rw-r--r-- | src/burn/test/BurnUnitTest/RegistrationTest.cpp | 178 |
1 files changed, 169 insertions, 9 deletions
diff --git a/src/burn/test/BurnUnitTest/RegistrationTest.cpp b/src/burn/test/BurnUnitTest/RegistrationTest.cpp index 96bdb2bf..298d4631 100644 --- a/src/burn/test/BurnUnitTest/RegistrationTest.cpp +++ b/src/burn/test/BurnUnitTest/RegistrationTest.cpp | |||
@@ -8,9 +8,12 @@ | |||
8 | #define HKCU_PATH L"SOFTWARE\\WiX_Burn_UnitTest\\HKCU" | 8 | #define HKCU_PATH L"SOFTWARE\\WiX_Burn_UnitTest\\HKCU" |
9 | #define REGISTRY_UNINSTALL_KEY L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall" | 9 | #define REGISTRY_UNINSTALL_KEY L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall" |
10 | #define REGISTRY_RUN_KEY L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce" | 10 | #define REGISTRY_RUN_KEY L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce" |
11 | #define TEST_BUNDLE_ID L"{D54F896D-1952-43e6-9C67-B5652240618C}" | ||
12 | #define TEST_BUNDLE_UPGRADE_CODE L"{89FDAE1F-8CC1-48B9-B930-3945E0D3E7F0}" | ||
11 | 13 | ||
12 | #define TEST_UNINSTALL_KEY L"HKEY_CURRENT_USER\\" HKCU_PATH L"\\" REGISTRY_UNINSTALL_KEY L"\\{D54F896D-1952-43e6-9C67-B5652240618C}" | 14 | #define TEST_UNINSTALL_KEY L"HKEY_CURRENT_USER\\" HKCU_PATH L"\\" REGISTRY_UNINSTALL_KEY L"\\{D54F896D-1952-43e6-9C67-B5652240618C}" |
13 | #define TEST_RUN_KEY L"HKEY_CURRENT_USER\\" HKCU_PATH L"\\" REGISTRY_RUN_KEY | 15 | #define TEST_RUN_KEY L"HKEY_CURRENT_USER\\" HKCU_PATH L"\\" REGISTRY_RUN_KEY |
16 | #define TEST_VARIABLE_KEY L"HKEY_CURRENT_USER\\" HKCU_PATH L"\\" REGISTRY_UNINSTALL_KEY L"\\{D54F896D-1952-43e6-9C67-B5652240618C}\\variables" | ||
14 | 17 | ||
15 | 18 | ||
16 | static LSTATUS APIENTRY RegistrationTest_RegCreateKeyExW( | 19 | static LSTATUS APIENTRY RegistrationTest_RegCreateKeyExW( |
@@ -496,30 +499,153 @@ namespace Bootstrapper | |||
496 | } | 499 | } |
497 | } | 500 | } |
498 | 501 | ||
499 | [Fact(Skip = "Currently fails")] | 502 | [Fact] |
500 | void ResumeTest() | 503 | void DUtilButilTest() |
501 | { | 504 | { |
502 | HRESULT hr = S_OK; | 505 | HRESULT hr = S_OK; |
503 | IXMLDOMElement* pixeBundle = NULL; | 506 | IXMLDOMElement* pixeBundle = NULL; |
504 | LPWSTR sczCurrentProcess = NULL; | 507 | LPWSTR sczCurrentProcess = NULL; |
508 | LPWSTR sczValue = NULL; | ||
509 | LPWSTR sczRelatedBundleId = NULL; | ||
510 | DWORD dwRelatedBundleIndex = 0; | ||
505 | BURN_VARIABLES variables = { }; | 511 | BURN_VARIABLES variables = { }; |
506 | BURN_USER_EXPERIENCE userExperience = { }; | 512 | BURN_USER_EXPERIENCE userExperience = { }; |
507 | BOOTSTRAPPER_COMMAND command = { }; | 513 | BOOTSTRAPPER_COMMAND command = { }; |
508 | BURN_REGISTRATION registration = { }; | 514 | BURN_REGISTRATION registration = { }; |
509 | BURN_LOGGING logging = { }; | 515 | BURN_LOGGING logging = { }; |
510 | BURN_PACKAGES packages = { }; | 516 | BURN_PACKAGES packages = { }; |
511 | BYTE rgbData[256] = { }; | ||
512 | BOOTSTRAPPER_RESUME_TYPE resumeType = BOOTSTRAPPER_RESUME_TYPE_NONE; | ||
513 | BYTE* pbBuffer = NULL; | 517 | BYTE* pbBuffer = NULL; |
514 | SIZE_T cbBuffer = 0; | 518 | SIZE_T cbBuffer = 0; |
519 | |||
515 | String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}")); | 520 | String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}")); |
516 | try | 521 | try |
517 | { | 522 | { |
518 | for (DWORD i = 0; i < 256; ++i) | 523 | // set mock API's |
524 | RegFunctionOverride(RegistrationTest_RegCreateKeyExW, RegistrationTest_RegOpenKeyExW, RegistrationTest_RegDeleteKeyExW, NULL, NULL, NULL, NULL, NULL, NULL); | ||
525 | |||
526 | Registry::CurrentUser->CreateSubKey(gcnew String(HKCU_PATH)); | ||
527 | |||
528 | logging.sczPath = L"BurnUnitTest.txt"; | ||
529 | |||
530 | LPCWSTR wzDocument = | ||
531 | L"<Bundle>" | ||
532 | L" <UX>" | ||
533 | L" <Payload Id='ux.dll' FilePath='ux.dll' Packaging='embedded' SourcePath='ux.dll' Hash='000000000000' />" | ||
534 | L" </UX>" | ||
535 | L" <RelatedBundle Id='" TEST_BUNDLE_UPGRADE_CODE "' Action='Upgrade' />" | ||
536 | L" <Registration Id='" TEST_BUNDLE_ID "' Tag='foo' ProviderKey='" TEST_BUNDLE_ID "' Version='1.0.0.0' ExecutableName='setup.exe' PerMachine='no'>" | ||
537 | L" <Arp Register='yes' Publisher='WiX Toolset' DisplayName='RegisterBasicTest' DisplayVersion='1.0.0.0' />" | ||
538 | L" </Registration>" | ||
539 | L" <Variable Id='MyBurnVariable1' Type='numeric' Value='0' Hidden='no' Persisted='yes' />" | ||
540 | L" <Variable Id='MyBurnVariable2' Type='string' Value='foo' Hidden='no' Persisted='yes' />" | ||
541 | L" <Variable Id='MyBurnVariable3' Type='version' Value='v1.1-alpha' Hidden='no' Persisted='yes' />" | ||
542 | L" <Variable Id='MyBurnVariable4' Type='string' Value='foo' Hidden='no' Persisted='no' />" | ||
543 | L" <CommandLine Variables='upperCase' />" | ||
544 | L"</Bundle>"; | ||
545 | |||
546 | // load XML document | ||
547 | LoadBundleXmlHelper(wzDocument, &pixeBundle); | ||
548 | |||
549 | hr = VariableInitialize(&variables); | ||
550 | TestThrowOnFailure(hr, L"Failed to initialize variables."); | ||
551 | |||
552 | hr = VariablesParseFromXml(&variables, pixeBundle); | ||
553 | TestThrowOnFailure(hr, L"Failed to parse variables from XML."); | ||
554 | |||
555 | hr = UserExperienceParseFromXml(&userExperience, pixeBundle); | ||
556 | TestThrowOnFailure(hr, L"Failed to parse UX from XML."); | ||
557 | |||
558 | hr = RegistrationParseFromXml(®istration, pixeBundle); | ||
559 | TestThrowOnFailure(hr, L"Failed to parse registration from XML."); | ||
560 | |||
561 | hr = PlanSetResumeCommand(®istration, BOOTSTRAPPER_ACTION_INSTALL, &command, &logging); | ||
562 | TestThrowOnFailure(hr, L"Failed to set registration resume command."); | ||
563 | |||
564 | hr = PathForCurrentProcess(&sczCurrentProcess, NULL); | ||
565 | TestThrowOnFailure(hr, L"Failed to get current process path."); | ||
566 | |||
567 | // begin session | ||
568 | hr = RegistrationSessionBegin(sczCurrentProcess, ®istration, &variables, BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_REGISTRATION, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, 0, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS); | ||
569 | TestThrowOnFailure(hr, L"Failed to register bundle."); | ||
570 | |||
571 | VariableSetNumericHelper(&variables, L"MyBurnVariable1", 42); | ||
572 | VariableSetStringHelper(&variables, L"MyBurnVariable2", L"bar", FALSE); | ||
573 | VariableSetVersionHelper(&variables, L"MyBurnVariable3", L"v1.0-beta"); | ||
574 | |||
575 | hr = VariableSerialize(&variables, TRUE, &pbBuffer, &cbBuffer); | ||
576 | TestThrowOnFailure(hr, "Failed to serialize variables."); | ||
577 | |||
578 | if (!Directory::Exists(cacheDirectory)) | ||
519 | { | 579 | { |
520 | rgbData[i] = (BYTE)i; | 580 | Directory::CreateDirectory(cacheDirectory); |
521 | } | 581 | } |
522 | 582 | ||
583 | hr = RegistrationSaveState(®istration, pbBuffer, cbBuffer); | ||
584 | TestThrowOnFailure(hr, L"Failed to save state."); | ||
585 | |||
586 | ReleaseNullBuffer(pbBuffer); | ||
587 | cbBuffer = 0; | ||
588 | // Verify the variables exist | ||
589 | Assert::Equal<String^>(gcnew String(L"42"), (String^)Registry::GetValue(gcnew String(TEST_VARIABLE_KEY), gcnew String(L"MyBurnVariable1"), nullptr)); | ||
590 | Assert::Equal<String^>(gcnew String(L"bar"), (String^)Registry::GetValue(gcnew String(TEST_VARIABLE_KEY), gcnew String(L"MyBurnVariable2"), nullptr)); | ||
591 | Assert::Equal<String^>(gcnew String(L"1.0-beta"), (String^)Registry::GetValue(gcnew String(TEST_VARIABLE_KEY), gcnew String(L"MyBurnVariable3"), nullptr)); | ||
592 | Assert::Empty((System::Collections::IEnumerable ^)Registry::GetValue(gcnew String(TEST_VARIABLE_KEY), gcnew String(L"WixBundleForcedRestartPackage"), nullptr)); | ||
593 | |||
594 | hr = StrAlloc(&sczRelatedBundleId, MAX_GUID_CHARS + 1); | ||
595 | |||
596 | // Verify we can find ourself via the UpgradeCode | ||
597 | hr = BundleEnumRelatedBundle(TEST_BUNDLE_UPGRADE_CODE, BUNDLE_INSTALL_CONTEXT_USER, &dwRelatedBundleIndex, sczRelatedBundleId); | ||
598 | TestThrowOnFailure(hr, L"Failed to enumerate related bundle."); | ||
599 | Assert::Equal<String^>(gcnew String(TEST_BUNDLE_ID), gcnew String(sczRelatedBundleId)); | ||
600 | |||
601 | // Verify we can read the bundle variables via the API | ||
602 | hr = BundleGetBundleVariable(TEST_BUNDLE_ID, L"MyBurnVariable1", &sczValue); | ||
603 | TestThrowOnFailure(hr, L"Failed to read MyBurnVariable1."); | ||
604 | Assert::Equal<String^>(gcnew String(L"42"), gcnew String(sczValue)); | ||
605 | |||
606 | // end session | ||
607 | hr = RegistrationSessionEnd(®istration, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_NONE); | ||
608 | TestThrowOnFailure(hr, L"Failed to unregister bundle."); | ||
609 | } | ||
610 | finally | ||
611 | { | ||
612 | ReleaseStr(sczRelatedBundleId); | ||
613 | ReleaseStr(sczCurrentProcess); | ||
614 | ReleaseObject(pixeBundle); | ||
615 | UserExperienceUninitialize(&userExperience); | ||
616 | RegistrationUninitialize(®istration); | ||
617 | VariablesUninitialize(&variables); | ||
618 | |||
619 | Registry::CurrentUser->DeleteSubKeyTree(gcnew String(ROOT_PATH)); | ||
620 | if (Directory::Exists(cacheDirectory)) | ||
621 | { | ||
622 | Directory::Delete(cacheDirectory, true); | ||
623 | } | ||
624 | |||
625 | RegFunctionOverride(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); | ||
626 | } | ||
627 | } | ||
628 | |||
629 | [Fact]//(Skip = "Currently fails")] | ||
630 | void ResumeTest() | ||
631 | { | ||
632 | HRESULT hr = S_OK; | ||
633 | IXMLDOMElement* pixeBundle = NULL; | ||
634 | LPWSTR sczCurrentProcess = NULL; | ||
635 | LPWSTR sczValue = NULL; | ||
636 | BURN_VARIABLES variables = { }; | ||
637 | BURN_USER_EXPERIENCE userExperience = { }; | ||
638 | BOOTSTRAPPER_COMMAND command = { }; | ||
639 | BURN_REGISTRATION registration = { }; | ||
640 | BURN_LOGGING logging = { }; | ||
641 | BURN_PACKAGES packages = { }; | ||
642 | BOOTSTRAPPER_RESUME_TYPE resumeType = BOOTSTRAPPER_RESUME_TYPE_NONE; | ||
643 | BYTE* pbBuffer = NULL; | ||
644 | SIZE_T cbBuffer = 0; | ||
645 | SIZE_T piBuffer = 0; | ||
646 | String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}")); | ||
647 | try | ||
648 | { | ||
523 | // set mock API's | 649 | // set mock API's |
524 | RegFunctionOverride(RegistrationTest_RegCreateKeyExW, RegistrationTest_RegOpenKeyExW, RegistrationTest_RegDeleteKeyExW, NULL, NULL, NULL, NULL, NULL, NULL); | 650 | RegFunctionOverride(RegistrationTest_RegCreateKeyExW, RegistrationTest_RegOpenKeyExW, RegistrationTest_RegDeleteKeyExW, NULL, NULL, NULL, NULL, NULL, NULL); |
525 | 651 | ||
@@ -535,6 +661,10 @@ namespace Bootstrapper | |||
535 | L" <Registration Id='{D54F896D-1952-43e6-9C67-B5652240618C}' UpgradeCode='{D54F896D-1952-43e6-9C67-B5652240618C}' Tag='foo' ProviderKey='foo' Version='1.0.0.0' ExecutableName='setup.exe' PerMachine='no'>" | 661 | L" <Registration Id='{D54F896D-1952-43e6-9C67-B5652240618C}' UpgradeCode='{D54F896D-1952-43e6-9C67-B5652240618C}' Tag='foo' ProviderKey='foo' Version='1.0.0.0' ExecutableName='setup.exe' PerMachine='no'>" |
536 | L" <Arp Register='yes' Publisher='WiX Toolset' DisplayName='RegisterBasicTest' DisplayVersion='1.0.0.0' />" | 662 | L" <Arp Register='yes' Publisher='WiX Toolset' DisplayName='RegisterBasicTest' DisplayVersion='1.0.0.0' />" |
537 | L" </Registration>" | 663 | L" </Registration>" |
664 | L" <Variable Id='MyBurnVariable1' Type='numeric' Value='0' Hidden='no' Persisted='yes' />" | ||
665 | L" <Variable Id='MyBurnVariable2' Type='string' Value='foo' Hidden='no' Persisted='yes' />" | ||
666 | L" <Variable Id='MyBurnVariable3' Type='version' Value='v1.1-alpha' Hidden='no' Persisted='yes' />" | ||
667 | L" <CommandLine Variables='upperCase' />" | ||
538 | L"</Bundle>"; | 668 | L"</Bundle>"; |
539 | 669 | ||
540 | // load XML document | 670 | // load XML document |
@@ -543,6 +673,9 @@ namespace Bootstrapper | |||
543 | hr = VariableInitialize(&variables); | 673 | hr = VariableInitialize(&variables); |
544 | TestThrowOnFailure(hr, L"Failed to initialize variables."); | 674 | TestThrowOnFailure(hr, L"Failed to initialize variables."); |
545 | 675 | ||
676 | hr = VariablesParseFromXml(&variables, pixeBundle); | ||
677 | TestThrowOnFailure(hr, L"Failed to parse variables from XML."); | ||
678 | |||
546 | hr = UserExperienceParseFromXml(&userExperience, pixeBundle); | 679 | hr = UserExperienceParseFromXml(&userExperience, pixeBundle); |
547 | TestThrowOnFailure(hr, L"Failed to parse UX from XML."); | 680 | TestThrowOnFailure(hr, L"Failed to parse UX from XML."); |
548 | 681 | ||
@@ -565,9 +698,33 @@ namespace Bootstrapper | |||
565 | hr = RegistrationSessionBegin(sczCurrentProcess, ®istration, &variables, BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_REGISTRATION, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, 0, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS); | 698 | hr = RegistrationSessionBegin(sczCurrentProcess, ®istration, &variables, BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_REGISTRATION, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, 0, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS); |
566 | TestThrowOnFailure(hr, L"Failed to register bundle."); | 699 | TestThrowOnFailure(hr, L"Failed to register bundle."); |
567 | 700 | ||
568 | hr = RegistrationSaveState(®istration, rgbData, sizeof(rgbData)); | 701 | VariableSetNumericHelper(&variables, L"MyBurnVariable1", 42); |
702 | VariableSetStringHelper(&variables, L"MyBurnVariable2", L"bar", FALSE); | ||
703 | VariableSetVersionHelper(&variables, L"MyBurnVariable3", L"v1.0-beta"); | ||
704 | |||
705 | hr = VariableSerialize(&variables, TRUE, &pbBuffer, &cbBuffer); | ||
706 | TestThrowOnFailure(hr, "Failed to serialize variables."); | ||
707 | |||
708 | if (!Directory::Exists(cacheDirectory)) | ||
709 | { | ||
710 | Directory::CreateDirectory(cacheDirectory); | ||
711 | } | ||
712 | |||
713 | hr = RegistrationSaveState(®istration, pbBuffer, cbBuffer); | ||
569 | TestThrowOnFailure(hr, L"Failed to save state."); | 714 | TestThrowOnFailure(hr, L"Failed to save state."); |
570 | 715 | ||
716 | ReleaseNullBuffer(pbBuffer); | ||
717 | cbBuffer = 0; | ||
718 | // Verify the variables exist | ||
719 | Assert::Equal<String^>(gcnew String(L"42"), (String^)Registry::GetValue(gcnew String(TEST_VARIABLE_KEY), gcnew String(L"MyBurnVariable1"), nullptr)); | ||
720 | Assert::Equal<String^>(gcnew String(L"bar"), (String^)Registry::GetValue(gcnew String(TEST_VARIABLE_KEY), gcnew String(L"MyBurnVariable2"), nullptr)); | ||
721 | Assert::Equal<String^>(gcnew String(L"1.0-beta"), (String^)Registry::GetValue(gcnew String(TEST_VARIABLE_KEY), gcnew String(L"MyBurnVariable3"), nullptr)); | ||
722 | Assert::Empty((System::Collections::IEnumerable^)Registry::GetValue(gcnew String(TEST_VARIABLE_KEY), gcnew String(L"WixBundleForcedRestartPackage"), nullptr)); | ||
723 | |||
724 | hr = BundleGetBundleVariable(TEST_BUNDLE_ID, L"MyBurnVariable1", &sczValue); | ||
725 | TestThrowOnFailure(hr, L"Failed to read MyBurnVariable1."); | ||
726 | Assert::Equal<String^>(gcnew String(L"42"), gcnew String(sczValue)); | ||
727 | |||
571 | // read interrupted resume type | 728 | // read interrupted resume type |
572 | hr = RegistrationDetectResumeType(®istration, &resumeType); | 729 | hr = RegistrationDetectResumeType(®istration, &resumeType); |
573 | TestThrowOnFailure(hr, L"Failed to read interrupted resume type."); | 730 | TestThrowOnFailure(hr, L"Failed to read interrupted resume type."); |
@@ -591,8 +748,11 @@ namespace Bootstrapper | |||
591 | hr = RegistrationLoadState(®istration, &pbBuffer, &cbBuffer); | 748 | hr = RegistrationLoadState(®istration, &pbBuffer, &cbBuffer); |
592 | TestThrowOnFailure(hr, L"Failed to load state."); | 749 | TestThrowOnFailure(hr, L"Failed to load state."); |
593 | 750 | ||
594 | Assert::Equal((SIZE_T)sizeof(rgbData), cbBuffer); | 751 | hr = VariableDeserialize(&variables, TRUE, pbBuffer, cbBuffer, &piBuffer); |
595 | Assert::True(0 == memcmp(pbBuffer, rgbData, sizeof(rgbData))); | 752 | TestThrowOnFailure(hr, L"Failed to deserialize variables."); |
753 | |||
754 | //Assert::Equal((SIZE_T)sizeof(rgbData), cbBuffer); | ||
755 | //Assert::True(0 == memcmp(pbBuffer, rgbData, sizeof(rgbData))); | ||
596 | 756 | ||
597 | // write active resume mode | 757 | // write active resume mode |
598 | hr = RegistrationSessionResume(®istration, &variables, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS); | 758 | hr = RegistrationSessionResume(®istration, &variables, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS); |