diff options
Diffstat (limited to 'src/burn/test/BurnUnitTest')
-rw-r--r-- | src/burn/test/BurnUnitTest/CacheTest.cpp | 95 | ||||
-rw-r--r-- | src/burn/test/BurnUnitTest/precomp.h | 2 |
2 files changed, 95 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 | }; |
diff --git a/src/burn/test/BurnUnitTest/precomp.h b/src/burn/test/BurnUnitTest/precomp.h index 11e54284..92c8c4c0 100644 --- a/src/burn/test/BurnUnitTest/precomp.h +++ b/src/burn/test/BurnUnitTest/precomp.h | |||
@@ -19,9 +19,11 @@ | |||
19 | #include <buffutil.h> | 19 | #include <buffutil.h> |
20 | #include <dirutil.h> | 20 | #include <dirutil.h> |
21 | #include <fileutil.h> | 21 | #include <fileutil.h> |
22 | #include <guidutil.h> | ||
22 | #include <logutil.h> | 23 | #include <logutil.h> |
23 | #include <memutil.h> | 24 | #include <memutil.h> |
24 | #include <pathutil.h> | 25 | #include <pathutil.h> |
26 | #include <polcutil.h> | ||
25 | #include <regutil.h> | 27 | #include <regutil.h> |
26 | #include <resrutil.h> | 28 | #include <resrutil.h> |
27 | #include <shelutil.h> | 29 | #include <shelutil.h> |