diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2022-06-03 17:48:57 -0500 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2022-06-07 19:44:36 -0500 |
| commit | 648f370f7966b2738c1446601057d888bbd2c70f (patch) | |
| tree | 9022566b1016f94127dfb7e84c9b4dfa057993cd /src/burn/test/BurnUnitTest/CacheTest.cpp | |
| parent | 6b0f2d978504da82070523eb6adb0b59f9812e93 (diff) | |
| download | wix-648f370f7966b2738c1446601057d888bbd2c70f.tar.gz wix-648f370f7966b2738c1446601057d888bbd2c70f.tar.bz2 wix-648f370f7966b2738c1446601057d888bbd2c70f.zip | |
Make PathGetSystemPath return an array of paths ordered by preference.
Diffstat (limited to 'src/burn/test/BurnUnitTest/CacheTest.cpp')
| -rw-r--r-- | src/burn/test/BurnUnitTest/CacheTest.cpp | 95 |
1 files changed, 93 insertions, 2 deletions
diff --git a/src/burn/test/BurnUnitTest/CacheTest.cpp b/src/burn/test/BurnUnitTest/CacheTest.cpp index 6979ec1a..eb0b31ab 100644 --- a/src/burn/test/BurnUnitTest/CacheTest.cpp +++ b/src/burn/test/BurnUnitTest/CacheTest.cpp | |||
| @@ -37,11 +37,100 @@ namespace Bootstrapper | |||
| 37 | using namespace System::IO; | 37 | using namespace System::IO; |
| 38 | using namespace Xunit; | 38 | using namespace Xunit; |
| 39 | 39 | ||
| 40 | public ref class CacheTest : BurnUnitTest | 40 | public ref class CacheTest : BurnUnitTest, IClassFixture<TestRegistryFixture^> |
| 41 | { | 41 | { |
| 42 | private: | ||
| 43 | TestRegistryFixture^ testRegistry; | ||
| 42 | public: | 44 | public: |
| 43 | CacheTest(BurnTestFixture^ fixture) : BurnUnitTest(fixture) | 45 | CacheTest(BurnTestFixture^ fixture, TestRegistryFixture^ registryFixture) : BurnUnitTest(fixture) |
| 44 | { | 46 | { |
| 47 | this->testRegistry = registryFixture; | ||
| 48 | } | ||
| 49 | |||
| 50 | [Fact] | ||
| 51 | void CacheElevatedTempFallbacksTest() | ||
| 52 | { | ||
| 53 | HRESULT hr = S_OK; | ||
| 54 | BURN_CACHE cache = { }; | ||
| 55 | BURN_ENGINE_COMMAND internalCommand = { }; | ||
| 56 | HKEY hkSystemEnvironment = NULL; | ||
| 57 | HKEY hkBurnPolicy = NULL; | ||
| 58 | |||
| 59 | internalCommand.fInitiallyElevated = TRUE; | ||
| 60 | |||
| 61 | try | ||
| 62 | { | ||
| 63 | this->testRegistry->SetUp(); | ||
| 64 | |||
| 65 | // No registry keys, so should fallback to %windir%\TEMP. | ||
| 66 | hr = CacheInitialize(&cache, &internalCommand); | ||
| 67 | NativeAssert::Succeeded(hr, "Failed to initialize cache."); | ||
| 68 | Assert::NotEqual<DWORD>(0, cache.cPotentialBaseWorkingFolders); | ||
| 69 | VerifyBaseWorkingFolder(L"%windir%\\TEMP\\", cache.rgsczPotentialBaseWorkingFolders[0]); | ||
| 70 | CacheUninitialize(&cache); | ||
| 71 | |||
| 72 | hr = RegCreate(HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Control\\Session Manager\\Environment", GENERIC_WRITE, &hkSystemEnvironment); | ||
| 73 | NativeAssert::Succeeded(hr, "Failed to create system environment key."); | ||
| 74 | |||
| 75 | // Third fallback is system-level %TEMP%. | ||
| 76 | hr = RegWriteExpandString(hkSystemEnvironment, L"TEMP", L"A:\\TEST\\TEMP"); | ||
| 77 | NativeAssert::Succeeded(hr, "Failed to write TEMP system environment value."); | ||
| 78 | |||
| 79 | hr = CacheInitialize(&cache, &internalCommand); | ||
| 80 | NativeAssert::Succeeded(hr, "Failed to initialize cache."); | ||
| 81 | Assert::NotEqual<DWORD>(0, cache.cPotentialBaseWorkingFolders); | ||
| 82 | VerifyBaseWorkingFolder(L"A:\\TEST\\TEMP\\", cache.rgsczPotentialBaseWorkingFolders[0]); | ||
| 83 | CacheUninitialize(&cache); | ||
| 84 | |||
| 85 | // Second fallback is system-level %TMP%. | ||
| 86 | hr = RegWriteExpandString(hkSystemEnvironment, L"TMP", L"B:\\TEST\\TMP\\"); | ||
| 87 | NativeAssert::Succeeded(hr, "Failed to write TEMP system environment value."); | ||
| 88 | |||
| 89 | hr = CacheInitialize(&cache, &internalCommand); | ||
| 90 | NativeAssert::Succeeded(hr, "Failed to initialize cache."); | ||
| 91 | Assert::NotEqual<DWORD>(0, cache.cPotentialBaseWorkingFolders); | ||
| 92 | VerifyBaseWorkingFolder(L"B:\\TEST\\TMP\\", cache.rgsczPotentialBaseWorkingFolders[0]); | ||
| 93 | CacheUninitialize(&cache); | ||
| 94 | |||
| 95 | hr = RegCreate(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Policies\\WiX\\Burn", GENERIC_WRITE, &hkBurnPolicy); | ||
| 96 | NativeAssert::Succeeded(hr, "Failed to create Burn policy key."); | ||
| 97 | |||
| 98 | // Default source is Burn policy. | ||
| 99 | hr = RegWriteExpandString(hkBurnPolicy, L"EngineWorkingDirectory", L"D:\\TEST\\POLICY\\"); | ||
| 100 | NativeAssert::Succeeded(hr, "Failed to write EngineWorkingDirectory Burn policy value."); | ||
| 101 | |||
| 102 | hr = CacheInitialize(&cache, &internalCommand); | ||
| 103 | NativeAssert::Succeeded(hr, "Failed to initialize cache."); | ||
| 104 | Assert::NotEqual<DWORD>(0, cache.cPotentialBaseWorkingFolders); | ||
| 105 | VerifyBaseWorkingFolder(L"D:\\TEST\\POLICY\\", cache.rgsczPotentialBaseWorkingFolders[0]); | ||
| 106 | CacheUninitialize(&cache); | ||
| 107 | |||
| 108 | // Command line parameter overrides everything else. | ||
| 109 | hr = StrAllocString(&internalCommand.sczEngineWorkingDirectory, L"E:\\TEST\\COMMANDLINE\\", 0); | ||
| 110 | NativeAssert::Succeeded(hr, "Failed to copy command line working directory."); | ||
| 111 | |||
| 112 | hr = CacheInitialize(&cache, &internalCommand); | ||
| 113 | NativeAssert::Succeeded(hr, "Failed to initialize cache."); | ||
| 114 | Assert::NotEqual<DWORD>(0, cache.cPotentialBaseWorkingFolders); | ||
| 115 | VerifyBaseWorkingFolder(L"E:\\TEST\\COMMANDLINE\\", cache.rgsczPotentialBaseWorkingFolders[0]); | ||
| 116 | CacheUninitialize(&cache); | ||
| 117 | } | ||
| 118 | finally | ||
| 119 | { | ||
| 120 | ReleaseRegKey(hkBurnPolicy); | ||
| 121 | ReleaseRegKey(hkSystemEnvironment); | ||
| 122 | ReleaseStr(internalCommand.sczEngineWorkingDirectory); | ||
| 123 | |||
| 124 | CacheUninitialize(&cache); | ||
| 125 | |||
| 126 | this->testRegistry->TearDown(); | ||
| 127 | } | ||
| 128 | } | ||
| 129 | |||
| 130 | void VerifyBaseWorkingFolder(LPCWSTR wzExpectedUnexpanded, LPCWSTR wzActual) | ||
| 131 | { | ||
| 132 | String^ expected = Environment::ExpandEnvironmentVariables(gcnew String(wzExpectedUnexpanded)); | ||
| 133 | WixAssert::StringEqual(expected, gcnew String(wzActual), true); | ||
| 45 | } | 134 | } |
| 46 | 135 | ||
| 47 | [Fact] | 136 | [Fact] |
| @@ -93,6 +182,8 @@ namespace Bootstrapper | |||
| 93 | File::SetAttributes(filePath, FileAttributes::Normal); | 182 | File::SetAttributes(filePath, FileAttributes::Normal); |
| 94 | File::Delete(filePath); | 183 | File::Delete(filePath); |
| 95 | } | 184 | } |
| 185 | |||
| 186 | CacheUninitialize(&cache); | ||
| 96 | } | 187 | } |
| 97 | } | 188 | } |
| 98 | }; | 189 | }; |
