Factor out TestRegistryFixture so other tests can mock regutil API's.
Sean Hall committed
Feb 28, 2022 at 18:38 UTC
7e61f48f6be0849cb0c0da796ec77603c14532e5
6 files changed
+352
-256
src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj
+2
@@ -57,6 +57,7 @@
57
</ClCompile>
58
<ClCompile Include="RegistrationTest.cpp" />
59
<ClCompile Include="SearchTest.cpp" />
60
+ <ClCompile Include="TestRegistryFixture.cpp" />
61
<ClCompile Include="VariableHelpers.cpp" />
62
<ClCompile Include="VariableTest.cpp" />
63
<ClCompile Include="VariantTest.cpp" />
@@ -67,6 +68,7 @@
68
<ClInclude Include="BurnUnitTest.h" />
69
<ClInclude Include="ManifestHelpers.h" />
70
<ClInclude Include="precomp.h" />
71
+ <ClInclude Include="TestRegistryFixture.h" />
72
<ClInclude Include="VariableHelpers.h" />
73
</ItemGroup>
74
src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj.filters
+11
-5
@@ -42,6 +42,9 @@
42
<ClCompile Include="SearchTest.cpp">
43
<Filter>Source Files</Filter>
44
</ClCompile>
45
+ <ClCompile Include="TestRegistryFixture.cpp">
46
+ <Filter>Source Files</Filter>
47
+ </ClCompile>
48
<ClCompile Include="VariableHelpers.cpp">
49
<Filter>Source Files</Filter>
50
</ClCompile>
@@ -56,19 +59,22 @@
59
<ClInclude Include="BurnTestException.h">
60
<Filter>Header Files</Filter>
61
</ClInclude>
59
- <ClInclude Include="ManifestHelpers.h">
62
+ <ClInclude Include="BurnTestFixture.h">
63
<Filter>Header Files</Filter>
64
</ClInclude>
62
- <ClInclude Include="precomp.h">
65
+ <ClInclude Include="BurnUnitTest.h">
66
<Filter>Header Files</Filter>
67
</ClInclude>
65
- <ClInclude Include="VariableHelpers.h">
68
+ <ClInclude Include="ManifestHelpers.h">
69
<Filter>Header Files</Filter>
70
</ClInclude>
68
- <ClInclude Include="BurnUnitTest.h">
71
+ <ClInclude Include="precomp.h">
72
<Filter>Header Files</Filter>
73
</ClInclude>
71
- <ClInclude Include="BurnTestFixture.h">
74
+ <ClInclude Include="TestRegistryFixture.h">
75
+ <Filter>Header Files</Filter>
76
+ </ClInclude>
77
+ <ClInclude Include="VariableHelpers.h">
78
<Filter>Header Files</Filter>
79
</ClInclude>
80
</ItemGroup>
src/burn/test/BurnUnitTest/RegistrationTest.cpp
+124
-251
@@ -3,43 +3,11 @@
3
#include "precomp.h"
4
5
6
-#define ROOT_PATH L"SOFTWARE\\WiX_Burn_UnitTest"
7
-#define HKLM_PATH ROOT_PATH L"\\HKLM"
8
-#define HKCU_PATH ROOT_PATH L"\\HKCU"
6
#define REGISTRY_UNINSTALL_KEY L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
7
#define REGISTRY_RUN_KEY L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce"
8
#define TEST_BUNDLE_ID L"{D54F896D-1952-43E6-9C67-B5652240618C}"
9
#define TEST_BUNDLE_UPGRADE_CODE L"{89FDAE1F-8CC1-48B9-B930-3945E0D3E7F0}"
10
14
-#define TEST_UNINSTALL_KEY L"HKEY_CURRENT_USER\\" HKCU_PATH L"\\" REGISTRY_UNINSTALL_KEY L"\\" TEST_BUNDLE_ID
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"\\" TEST_BUNDLE_ID L"\\variables"
17
-
18
-
19
-static LSTATUS APIENTRY RegistrationTest_RegCreateKeyExW(
20
- __in HKEY hKey,
21
- __in LPCWSTR lpSubKey,
22
- __reserved DWORD Reserved,
23
- __in_opt LPWSTR lpClass,
24
- __in DWORD dwOptions,
25
- __in REGSAM samDesired,
26
- __in_opt CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes,
27
- __out PHKEY phkResult,
28
- __out_opt LPDWORD lpdwDisposition
29
- );
30
-static LSTATUS APIENTRY RegistrationTest_RegOpenKeyExW(
31
- __in HKEY hKey,
32
- __in_opt LPCWSTR lpSubKey,
33
- __reserved DWORD ulOptions,
34
- __in REGSAM samDesired,
35
- __out PHKEY phkResult
36
- );
37
-static LSTATUS APIENTRY RegistrationTest_RegDeleteKeyExW(
38
- __in HKEY hKey,
39
- __in LPCWSTR lpSubKey,
40
- __in REGSAM samDesired,
41
- __reserved DWORD Reserved
42
- );
11
12
namespace Microsoft
13
{
@@ -55,12 +23,23 @@ namespace Bootstrapper
23
using namespace System;
24
using namespace System::IO;
25
using namespace Xunit;
26
+ using namespace WixBuildTools::TestSupport;
27
59
- public ref class RegistrationTest : BurnUnitTest
28
+ public ref class RegistrationTest : BurnUnitTest, IClassFixture<TestRegistryFixture^>
29
{
30
+ private:
31
+ TestRegistryFixture^ testRegistry;
32
+ String^ testRunKeyPath;
33
+ String^ testUninstallKeyPath;
34
+ String^ testVariableKeyPath;
35
public:
62
- RegistrationTest(BurnTestFixture^ fixture) : BurnUnitTest(fixture)
36
+ RegistrationTest(BurnTestFixture^ fixture, TestRegistryFixture^ registryFixture) : BurnUnitTest(fixture)
37
{
38
+ this->testRegistry = registryFixture;
39
+
40
+ this->testRunKeyPath = this->testRegistry->GetDirectHkcuPath(gcnew String(REGISTRY_RUN_KEY));
41
+ this->testUninstallKeyPath = this->testRegistry->GetDirectHkcuPath(gcnew String(REGISTRY_UNINSTALL_KEY), gcnew String(TEST_BUNDLE_ID));
42
+ this->testVariableKeyPath = Path::Combine(this->testUninstallKeyPath, gcnew String(L"variables"));
43
}
44
45
[Fact]
@@ -79,14 +58,12 @@ namespace Bootstrapper
58
BURN_CACHE cache = { };
59
BURN_ENGINE_COMMAND internalCommand = { };
60
String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(TEST_BUNDLE_ID));
61
+ String^ cacheExePath = Path::Combine(cacheDirectory, gcnew String(L"setup.exe"));
62
DWORD dwRegistrationOptions = BURN_REGISTRATION_ACTION_OPERATIONS_CACHE_BUNDLE;
63
64
try
65
{
86
- // set mock API's
87
- RegFunctionOverride(RegistrationTest_RegCreateKeyExW, RegistrationTest_RegOpenKeyExW, RegistrationTest_RegDeleteKeyExW, NULL, NULL, NULL, NULL, NULL, NULL);
88
-
89
- Registry::CurrentUser->CreateSubKey(gcnew String(HKCU_PATH));
66
+ this->testRegistry->SetUp();
67
68
logging.sczPath = L"BurnUnitTest.txt";
69
@@ -133,8 +110,8 @@ namespace Bootstrapper
110
Assert::True(Directory::Exists(cacheDirectory));
111
Assert::True(File::Exists(Path::Combine(cacheDirectory, gcnew String(L"setup.exe"))));
112
136
- Assert::Equal(Int32(BURN_RESUME_MODE_ACTIVE), (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
137
- Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.clean.room /burn.runonce"), (String^)(Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr)));
113
+ this->ValidateUninstallKeyResume(Int32(BURN_RESUME_MODE_ACTIVE));
114
+ this->ValidateRunOnceKeyEntry(cacheExePath);
115
116
// end session
117
hr = RegistrationSessionEnd(®istration, &cache, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BOOTSTRAPPER_REGISTRATION_TYPE_NONE);
@@ -143,8 +120,8 @@ namespace Bootstrapper
120
// verify that registration was removed
121
Assert::False(Directory::Exists(cacheDirectory));
122
146
- Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
147
- Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
123
+ this->ValidateUninstallKeyNull(L"Resume");
124
+ this->ValidateRunOnceKeyString(TEST_BUNDLE_ID, nullptr);
125
}
126
finally
127
{
@@ -154,13 +131,12 @@ namespace Bootstrapper
131
RegistrationUninitialize(®istration);
132
VariablesUninitialize(&variables);
133
157
- Registry::CurrentUser->DeleteSubKeyTree(gcnew String(ROOT_PATH));
134
if (Directory::Exists(cacheDirectory))
135
{
136
Directory::Delete(cacheDirectory, true);
137
}
138
163
- RegFunctionOverride(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
139
+ this->testRegistry->TearDown();
140
}
141
}
142
@@ -180,13 +156,11 @@ namespace Bootstrapper
156
BURN_CACHE cache = { };
157
BURN_ENGINE_COMMAND internalCommand = { };
158
String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(TEST_BUNDLE_ID));
159
+ String^ cacheExePath = Path::Combine(cacheDirectory, gcnew String(L"setup.exe"));
160
DWORD dwRegistrationOptions = 0;
161
try
162
{
186
- // set mock API's
187
- RegFunctionOverride(RegistrationTest_RegCreateKeyExW, RegistrationTest_RegOpenKeyExW, RegistrationTest_RegDeleteKeyExW, NULL, NULL, NULL, NULL, NULL, NULL);
188
-
189
- Registry::CurrentUser->CreateSubKey(gcnew String(HKCU_PATH));
163
+ this->testRegistry->SetUp();
164
165
logging.sczPath = L"BurnUnitTest.txt";
166
@@ -234,18 +208,18 @@ namespace Bootstrapper
208
TestThrowOnFailure(hr, L"Failed to register bundle.");
209
210
// verify that registration was created
237
- Assert::Equal<String^>(gcnew String(L"Product1 Installation"), (String^)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"DisplayName"), nullptr));
238
- Assert::Equal(Int32(BURN_RESUME_MODE_ACTIVE), (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
239
- Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.clean.room /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
211
+ this->ValidateUninstallKeyDisplayName(L"Product1 Installation");
212
+ this->ValidateUninstallKeyResume(Int32(BURN_RESUME_MODE_ACTIVE));
213
+ this->ValidateRunOnceKeyEntry(cacheExePath);
214
215
// complete registration
216
hr = RegistrationSessionEnd(®istration, &cache, &variables, &packages, BURN_RESUME_MODE_ARP, BOOTSTRAPPER_APPLY_RESTART_NONE, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
217
TestThrowOnFailure(hr, L"Failed to unregister bundle.");
218
219
// verify that registration was updated
246
- Assert::Equal(Int32(BURN_RESUME_MODE_ARP), (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
247
- Assert::Equal(1, (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Installed"), nullptr));
248
- Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
220
+ this->ValidateUninstallKeyResume(Int32(BURN_RESUME_MODE_ARP));
221
+ this->ValidateUninstallKeyInstalled(1);
222
+ this->ValidateRunOnceKeyString(TEST_BUNDLE_ID, nullptr);
223
224
//
225
// uninstall
@@ -256,18 +230,18 @@ namespace Bootstrapper
230
TestThrowOnFailure(hr, L"Failed to register bundle.");
231
232
// verify that registration was updated
259
- Assert::Equal(Int32(BURN_RESUME_MODE_ACTIVE), (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
260
- Assert::Equal(1, (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Installed"), nullptr));
261
- Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.clean.room /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
233
+ this->ValidateUninstallKeyResume(Int32(BURN_RESUME_MODE_ACTIVE));
234
+ this->ValidateUninstallKeyInstalled(1);
235
+ this->ValidateRunOnceKeyEntry(cacheExePath);
236
237
// delete registration
238
hr = RegistrationSessionEnd(®istration, &cache, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BOOTSTRAPPER_REGISTRATION_TYPE_NONE);
239
TestThrowOnFailure(hr, L"Failed to unregister bundle.");
240
241
// verify that registration was removed
268
- Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
269
- Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Installed"), nullptr));
270
- Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
242
+ this->ValidateUninstallKeyNull(L"Resume");
243
+ this->ValidateUninstallKeyNull(L"Installed");
244
+ this->ValidateRunOnceKeyString(TEST_BUNDLE_ID, nullptr);
245
}
246
finally
247
{
@@ -277,13 +251,12 @@ namespace Bootstrapper
251
RegistrationUninitialize(®istration);
252
VariablesUninitialize(&variables);
253
280
- Registry::CurrentUser->DeleteSubKeyTree(gcnew String(ROOT_PATH));
254
if (Directory::Exists(cacheDirectory))
255
{
256
Directory::Delete(cacheDirectory, true);
257
}
258
286
- RegFunctionOverride(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
259
+ this->testRegistry->TearDown();
260
}
261
}
262
@@ -303,13 +276,11 @@ namespace Bootstrapper
276
BURN_CACHE cache = { };
277
BURN_ENGINE_COMMAND internalCommand = { };
278
String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(TEST_BUNDLE_ID));
279
+ String^ cacheExePath = Path::Combine(cacheDirectory, gcnew String(L"setup.exe"));
280
DWORD dwRegistrationOptions = 0;
281
try
282
{
309
- // set mock API's
310
- RegFunctionOverride(RegistrationTest_RegCreateKeyExW, RegistrationTest_RegOpenKeyExW, RegistrationTest_RegDeleteKeyExW, NULL, NULL, NULL, NULL, NULL, NULL);
311
-
312
- Registry::CurrentUser->CreateSubKey(gcnew String(HKCU_PATH));
283
+ this->testRegistry->SetUp();
284
285
logging.sczPath = L"BurnUnitTest.txt";
286
@@ -357,15 +328,15 @@ namespace Bootstrapper
328
TestThrowOnFailure(hr, L"Failed to register bundle.");
329
330
// verify that registration was created
360
- Assert::Equal(Int32(BURN_RESUME_MODE_ACTIVE), (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
361
- Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.clean.room /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
331
+ this->ValidateUninstallKeyResume(Int32(BURN_RESUME_MODE_ACTIVE));
332
+ this->ValidateRunOnceKeyEntry(cacheExePath);
333
334
// complete registration
335
hr = RegistrationSessionEnd(®istration, &cache, &variables, &packages, BURN_RESUME_MODE_ARP, BOOTSTRAPPER_APPLY_RESTART_REQUIRED, BOOTSTRAPPER_REGISTRATION_TYPE_FULL);
336
TestThrowOnFailure(hr, L"Failed to unregister bundle.");
337
338
// verify that registration variables were updated
368
- Assert::Equal<String^>(gcnew String(L"Product1"), (String^)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"DisplayName"), nullptr));
339
+ this->ValidateUninstallKeyDisplayName(L"Product1");
340
registration.fInstalled = TRUE;
341
342
hr = RegistrationSetVariables(®istration, &variables);
@@ -385,9 +356,9 @@ namespace Bootstrapper
356
TestThrowOnFailure(hr, L"Failed to unregister bundle.");
357
358
// verify that registration was removed
388
- Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
389
- Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Installed"), nullptr));
390
- Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
359
+ this->ValidateUninstallKeyNull(L"Resume");
360
+ this->ValidateUninstallKeyNull(L"Installed");
361
+ this->ValidateRunOnceKeyString(TEST_BUNDLE_ID, nullptr);
362
}
363
finally
364
{
@@ -397,13 +368,12 @@ namespace Bootstrapper
368
RegistrationUninitialize(®istration);
369
VariablesUninitialize(&variables);
370
400
- Registry::CurrentUser->DeleteSubKeyTree(gcnew String(ROOT_PATH));
371
if (Directory::Exists(cacheDirectory))
372
{
373
Directory::Delete(cacheDirectory, true);
374
}
375
406
- RegFunctionOverride(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
376
+ this->testRegistry->TearDown();
377
}
378
}
379
@@ -423,13 +393,11 @@ namespace Bootstrapper
393
BURN_CACHE cache = { };
394
BURN_ENGINE_COMMAND internalCommand = { };
395
String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(TEST_BUNDLE_ID));
396
+ String^ cacheExePath = Path::Combine(cacheDirectory, gcnew String(L"setup.exe"));
397
DWORD dwRegistrationOptions = 0;
398
try
399
{
429
- // set mock API's
430
- RegFunctionOverride(RegistrationTest_RegCreateKeyExW, RegistrationTest_RegOpenKeyExW, RegistrationTest_RegDeleteKeyExW, NULL, NULL, NULL, NULL, NULL, NULL);
431
-
432
- Registry::CurrentUser->CreateSubKey(gcnew String(HKCU_PATH));
400
+ this->testRegistry->SetUp();
401
402
logging.sczPath = L"BurnUnitTest.txt";
403
@@ -479,29 +447,29 @@ namespace Bootstrapper
447
TestThrowOnFailure(hr, L"Failed to register bundle.");
448
449
// verify that registration was created
482
- Assert::Equal(Int32(BURN_RESUME_MODE_ACTIVE), (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
483
- Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.clean.room /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
450
+ this->ValidateUninstallKeyResume(Int32(BURN_RESUME_MODE_ACTIVE));
451
+ this->ValidateRunOnceKeyEntry(cacheExePath);
452
453
// finish registration
454
hr = RegistrationSessionEnd(®istration, &cache, &variables, &packages, BURN_RESUME_MODE_ARP, BOOTSTRAPPER_APPLY_RESTART_NONE, BOOTSTRAPPER_REGISTRATION_TYPE_FULL);
455
TestThrowOnFailure(hr, L"Failed to register bundle.");
456
457
// verify that registration was updated
490
- Assert::Equal(Int32(BURN_RESUME_MODE_ARP), (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
491
- Assert::Equal(1, (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Installed"), nullptr));
492
- Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
493
-
494
- Assert::Equal<String^>(gcnew String(L"DisplayName1"), (String^)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"DisplayName"), nullptr));
495
- Assert::Equal<String^>(gcnew String(L"1.2.3.4"), (String^)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"DisplayVersion"), nullptr));
496
- Assert::Equal<String^>(gcnew String(L"Publisher1"), (String^)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Publisher"), nullptr));
497
- Assert::Equal<String^>(gcnew String(L"http://www.microsoft.com/help"), (String^)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"HelpLink"), nullptr));
498
- Assert::Equal<String^>(gcnew String(L"555-555-5555"), (String^)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"HelpTelephone"), nullptr));
499
- Assert::Equal<String^>(gcnew String(L"http://www.microsoft.com/about"), (String^)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"URLInfoAbout"), nullptr));
500
- Assert::Equal<String^>(gcnew String(L"http://www.microsoft.com/update"), (String^)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"URLUpdateInfo"), nullptr));
501
- Assert::Equal<String^>(gcnew String(L"Comments1"), (String^)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Comments"), nullptr));
502
- Assert::Equal<String^>(gcnew String(L"Contact1"), (String^)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Contact"), nullptr));
503
- Assert::Equal(1, (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"NoModify"), nullptr));
504
- Assert::Equal(1, (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"NoRemove"), nullptr));
458
+ this->ValidateUninstallKeyResume(Int32(BURN_RESUME_MODE_ARP));
459
+ this->ValidateUninstallKeyInstalled(1);
460
+ this->ValidateRunOnceKeyString(TEST_BUNDLE_ID, nullptr);
461
+
462
+ this->ValidateUninstallKeyDisplayName(L"DisplayName1");
463
+ this->ValidateUninstallKeyString(L"DisplayVersion", L"1.2.3.4");
464
+ this->ValidateUninstallKeyString(L"Publisher", L"Publisher1");
465
+ this->ValidateUninstallKeyString(L"HelpLink", L"http://www.microsoft.com/help");
466
+ this->ValidateUninstallKeyString(L"HelpTelephone", L"555-555-5555");
467
+ this->ValidateUninstallKeyString(L"URLInfoAbout", L"http://www.microsoft.com/about");
468
+ this->ValidateUninstallKeyString(L"URLUpdateInfo", L"http://www.microsoft.com/update");
469
+ this->ValidateUninstallKeyString(L"Comments", L"Comments1");
470
+ this->ValidateUninstallKeyString(L"Contact", L"Contact1");
471
+ this->ValidateUninstallKeyNumber(L"NoModify", 1);
472
+ this->ValidateUninstallKeyNumber(L"NoRemove", 1);
473
474
//
475
// uninstall
@@ -512,17 +480,17 @@ namespace Bootstrapper
480
TestThrowOnFailure(hr, L"Failed to register bundle.");
481
482
// verify that registration was updated
515
- Assert::Equal(Int32(BURN_RESUME_MODE_ACTIVE), (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
516
- Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.clean.room /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
483
+ this->ValidateUninstallKeyResume(Int32(BURN_RESUME_MODE_ACTIVE));
484
+ this->ValidateRunOnceKeyEntry(cacheExePath);
485
486
// delete registration
487
hr = RegistrationSessionEnd(®istration, &cache, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BOOTSTRAPPER_REGISTRATION_TYPE_NONE);
488
TestThrowOnFailure(hr, L"Failed to unregister bundle.");
489
490
// verify that registration was removed
523
- Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
524
- Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Installed"), nullptr));
525
- Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
491
+ this->ValidateUninstallKeyNull(L"Resume");
492
+ this->ValidateUninstallKeyNull(L"Installed");
493
+ this->ValidateRunOnceKeyString(TEST_BUNDLE_ID, nullptr);
494
}
495
finally
496
{
@@ -532,13 +500,12 @@ namespace Bootstrapper
500
RegistrationUninitialize(®istration);
501
VariablesUninitialize(&variables);
502
535
- Registry::CurrentUser->DeleteSubKeyTree(gcnew String(ROOT_PATH));
503
if (Directory::Exists(cacheDirectory))
504
{
505
Directory::Delete(cacheDirectory, true);
506
}
540
-
541
- RegFunctionOverride(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
507
+
508
+ this->testRegistry->TearDown();
509
}
510
}
511
@@ -567,10 +534,7 @@ namespace Bootstrapper
534
String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(TEST_BUNDLE_ID));
535
try
536
{
570
- // set mock API's
571
- RegFunctionOverride(RegistrationTest_RegCreateKeyExW, RegistrationTest_RegOpenKeyExW, RegistrationTest_RegDeleteKeyExW, NULL, NULL, NULL, NULL, NULL, NULL);
572
-
573
- Registry::CurrentUser->CreateSubKey(gcnew String(HKCU_PATH));
537
+ this->testRegistry->SetUp();
538
539
logging.sczPath = L"BurnUnitTest.txt";
540
@@ -641,10 +605,10 @@ namespace Bootstrapper
605
cbBuffer = 0;
606
607
// Verify the variables exist
644
- Assert::Equal<String^>(gcnew String(L"42"), (String^)Registry::GetValue(gcnew String(TEST_VARIABLE_KEY), gcnew String(L"MyBurnVariable1"), nullptr));
645
- Assert::Equal<String^>(gcnew String(L"bar"), (String^)Registry::GetValue(gcnew String(TEST_VARIABLE_KEY), gcnew String(L"MyBurnVariable2"), nullptr));
646
- Assert::Equal<String^>(gcnew String(L"1.0-beta"), (String^)Registry::GetValue(gcnew String(TEST_VARIABLE_KEY), gcnew String(L"MyBurnVariable3"), nullptr));
647
- Assert::Empty((System::Collections::IEnumerable ^)Registry::GetValue(gcnew String(TEST_VARIABLE_KEY), gcnew String(L"WixBundleForcedRestartPackage"), nullptr));
608
+ this->ValidateVariableKey(L"MyBurnVariable1", gcnew String(L"42"));
609
+ this->ValidateVariableKey(L"MyBurnVariable2", gcnew String(L"bar"));
610
+ this->ValidateVariableKey(L"MyBurnVariable3", gcnew String(L"1.0-beta"));
611
+ this->ValidateVariableKeyEmpty(L"WixBundleForcedRestartPackage");
612
613
hr = StrAlloc(&sczRelatedBundleId, MAX_GUID_CHARS + 1);
614
NativeAssert::Succeeded(hr, "Failed to allocate buffer for related bundle id.");
@@ -674,13 +638,12 @@ namespace Bootstrapper
638
RegistrationUninitialize(®istration);
639
VariablesUninitialize(&variables);
640
677
- Registry::CurrentUser->DeleteSubKeyTree(gcnew String(ROOT_PATH));
641
if (Directory::Exists(cacheDirectory))
642
{
643
Directory::Delete(cacheDirectory, true);
644
}
645
683
- RegFunctionOverride(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
646
+ this->testRegistry->TearDown();
647
}
648
}
649
@@ -705,13 +668,11 @@ namespace Bootstrapper
668
SIZE_T cbBuffer = 0;
669
SIZE_T piBuffer = 0;
670
String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(TEST_BUNDLE_ID));
671
+ String^ cacheExePath = Path::Combine(cacheDirectory, gcnew String(L"setup.exe"));
672
DWORD dwRegistrationOptions = 0;
673
try
674
{
711
- // set mock API's
712
- RegFunctionOverride(RegistrationTest_RegCreateKeyExW, RegistrationTest_RegOpenKeyExW, RegistrationTest_RegDeleteKeyExW, NULL, NULL, NULL, NULL, NULL, NULL);
713
-
714
- Registry::CurrentUser->CreateSubKey(gcnew String(HKCU_PATH));
675
+ this->testRegistry->SetUp();
676
677
logging.sczPath = L"BurnUnitTest.txt";
678
@@ -786,10 +747,10 @@ namespace Bootstrapper
747
cbBuffer = 0;
748
749
// Verify the variables exist
789
- Assert::Equal<String^>(gcnew String(L"42"), (String^)Registry::GetValue(gcnew String(TEST_VARIABLE_KEY), gcnew String(L"MyBurnVariable1"), nullptr));
790
- Assert::Equal<String^>(gcnew String(L"bar"), (String^)Registry::GetValue(gcnew String(TEST_VARIABLE_KEY), gcnew String(L"MyBurnVariable2"), nullptr));
791
- Assert::Equal<String^>(gcnew String(L"1.0-beta"), (String^)Registry::GetValue(gcnew String(TEST_VARIABLE_KEY), gcnew String(L"MyBurnVariable3"), nullptr));
792
- Assert::Empty((System::Collections::IEnumerable^)Registry::GetValue(gcnew String(TEST_VARIABLE_KEY), gcnew String(L"WixBundleForcedRestartPackage"), nullptr));
750
+ this->ValidateVariableKey(L"MyBurnVariable1", gcnew String(L"42"));
751
+ this->ValidateVariableKey(L"MyBurnVariable2", gcnew String(L"bar"));
752
+ this->ValidateVariableKey(L"MyBurnVariable3", gcnew String(L"1.0-beta"));
753
+ this->ValidateVariableKeyEmpty(L"WixBundleForcedRestartPackage");
754
755
hr = BundleGetBundleVariable(TEST_BUNDLE_ID, L"MyBurnVariable1", &sczValue);
756
TestThrowOnFailure(hr, L"Failed to read MyBurnVariable1.");
@@ -807,7 +768,7 @@ namespace Bootstrapper
768
TestThrowOnFailure(hr, L"Failed to suspend session.");
769
770
// verify that run key was removed
810
- Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
771
+ this->ValidateRunOnceKeyString(TEST_BUNDLE_ID, nullptr);
772
773
// read suspend resume type
774
hr = RegistrationDetectResumeType(®istration, &resumeType);
@@ -827,7 +788,7 @@ namespace Bootstrapper
788
TestThrowOnFailure(hr, L"Failed to write active resume mode.");
789
790
// verify that run key was put back
830
- Assert::NotEqual((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
791
+ this->ValidateRunOnceKeyEntry(cacheExePath);
792
793
// end session
794
hr = RegistrationSessionEnd(®istration, &cache, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BOOTSTRAPPER_REGISTRATION_TYPE_NONE);
@@ -847,155 +808,67 @@ namespace Bootstrapper
808
RegistrationUninitialize(®istration);
809
VariablesUninitialize(&variables);
810
850
- Registry::CurrentUser->DeleteSubKeyTree(gcnew String(ROOT_PATH));
811
if (Directory::Exists(cacheDirectory))
812
{
813
Directory::Delete(cacheDirectory, true);
814
}
815
856
- RegFunctionOverride(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
816
+ this->testRegistry->TearDown();
817
}
818
}
819
860
- //BOOTSTRAPPER_RESUME_TYPE_NONE,
861
- //BOOTSTRAPPER_RESUME_TYPE_INVALID, // resume information is present but invalid
862
- //BOOTSTRAPPER_RESUME_TYPE_UNEXPECTED, // relaunched after an unexpected interruption
863
- //BOOTSTRAPPER_RESUME_TYPE_REBOOT, // relaunched after reboot
864
- //BOOTSTRAPPER_RESUME_TYPE_SUSPEND, // relaunched after suspend
865
- //BOOTSTRAPPER_RESUME_TYPE_ARP, // launched from ARP
866
- };
867
-}
868
-}
869
-}
870
-}
871
-}
872
-
873
-
874
-static LSTATUS APIENTRY RegistrationTest_RegCreateKeyExW(
875
- __in HKEY hKey,
876
- __in LPCWSTR lpSubKey,
877
- __reserved DWORD Reserved,
878
- __in_opt LPWSTR lpClass,
879
- __in DWORD dwOptions,
880
- __in REGSAM samDesired,
881
- __in_opt CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes,
882
- __out PHKEY phkResult,
883
- __out_opt LPDWORD lpdwDisposition
884
- )
885
-{
886
- LSTATUS ls = ERROR_SUCCESS;
887
- LPCWSTR wzRoot = NULL;
888
- HKEY hkRoot = NULL;
889
-
890
- if (HKEY_LOCAL_MACHINE == hKey)
891
- {
892
- wzRoot = HKLM_PATH;
893
- }
894
- else if (HKEY_CURRENT_USER == hKey)
895
- {
896
- wzRoot = HKCU_PATH;
897
- }
898
- else
899
- {
900
- hkRoot = hKey;
901
- }
902
-
903
- if (wzRoot)
904
- {
905
- ls = ::RegOpenKeyExW(HKEY_CURRENT_USER, wzRoot, 0, KEY_WRITE, &hkRoot);
906
- if (ERROR_SUCCESS != ls)
820
+ void ValidateRunOnceKeyString(LPCWSTR valueName, String^ expected)
821
{
908
- ExitFunction();
822
+ WixAssert::StringEqual(expected, (String^)Registry::GetValue(this->testRunKeyPath, gcnew String(valueName), nullptr), false);
823
}
910
- }
824
912
- ls = ::RegCreateKeyExW(hkRoot, lpSubKey, Reserved, lpClass, dwOptions, samDesired, lpSecurityAttributes, phkResult, lpdwDisposition);
913
-
914
-LExit:
915
- ReleaseRegKey(hkRoot);
916
-
917
- return ls;
918
-}
919
-
920
-static LSTATUS APIENTRY RegistrationTest_RegOpenKeyExW(
921
- __in HKEY hKey,
922
- __in_opt LPCWSTR lpSubKey,
923
- __reserved DWORD ulOptions,
924
- __in REGSAM samDesired,
925
- __out PHKEY phkResult
926
- )
927
-{
928
- LSTATUS ls = ERROR_SUCCESS;
929
- LPCWSTR wzRoot = NULL;
930
- HKEY hkRoot = NULL;
931
-
932
- if (HKEY_LOCAL_MACHINE == hKey)
933
- {
934
- wzRoot = HKLM_PATH;
935
- }
936
- else if (HKEY_CURRENT_USER == hKey)
937
- {
938
- wzRoot = HKCU_PATH;
939
- }
940
- else
941
- {
942
- hkRoot = hKey;
943
- }
944
-
945
- if (wzRoot)
946
- {
947
- ls = ::RegOpenKeyExW(HKEY_CURRENT_USER, wzRoot, 0, KEY_WRITE, &hkRoot);
948
- if (ERROR_SUCCESS != ls)
825
+ void ValidateRunOnceKeyEntry(String^ exePath)
826
{
950
- ExitFunction();
827
+ this->ValidateRunOnceKeyString(TEST_BUNDLE_ID, String::Concat(L"\"", exePath, L"\" /burn.clean.room /burn.runonce"));
828
}
952
- }
829
954
- ls = ::RegOpenKeyExW(hkRoot, lpSubKey, ulOptions, samDesired, phkResult);
955
-
956
-LExit:
957
- ReleaseRegKey(hkRoot);
830
+ void ValidateUninstallKeyNull(LPCWSTR valueName)
831
+ {
832
+ Assert::Null(Registry::GetValue(this->testUninstallKeyPath, gcnew String(valueName), nullptr));
833
+ }
834
959
- return ls;
960
-}
835
+ void ValidateUninstallKeyNumber(LPCWSTR valueName, Int32 expected)
836
+ {
837
+ Assert::Equal(expected, (Int32)Registry::GetValue(this->testUninstallKeyPath, gcnew String(valueName), nullptr));
838
+ }
839
962
-static LSTATUS APIENTRY RegistrationTest_RegDeleteKeyExW(
963
- __in HKEY hKey,
964
- __in LPCWSTR lpSubKey,
965
- __in REGSAM samDesired,
966
- __reserved DWORD Reserved
967
- )
968
-{
969
- LSTATUS ls = ERROR_SUCCESS;
970
- LPCWSTR wzRoot = NULL;
971
- HKEY hkRoot = NULL;
840
+ void ValidateUninstallKeyString(LPCWSTR valueName, String^ expected)
841
+ {
842
+ WixAssert::StringEqual(expected, (String^)Registry::GetValue(this->testUninstallKeyPath, gcnew String(valueName), nullptr), false);
843
+ }
844
973
- if (HKEY_LOCAL_MACHINE == hKey)
974
- {
975
- wzRoot = HKLM_PATH;
976
- }
977
- else if (HKEY_CURRENT_USER == hKey)
978
- {
979
- wzRoot = HKCU_PATH;
980
- }
981
- else
982
- {
983
- hkRoot = hKey;
984
- }
845
+ void ValidateUninstallKeyDisplayName(String^ expected)
846
+ {
847
+ this->ValidateUninstallKeyString(L"DisplayName", expected);
848
+ }
849
986
- if (wzRoot)
987
- {
988
- ls = ::RegOpenKeyExW(HKEY_CURRENT_USER, wzRoot, 0, KEY_WRITE | samDesired, &hkRoot);
989
- if (ERROR_SUCCESS != ls)
850
+ void ValidateUninstallKeyInstalled(Int32 expected)
851
{
991
- ExitFunction();
852
+ this->ValidateUninstallKeyNumber(L"Installed", expected);
853
}
993
- }
854
995
- ls = ::RegDeleteKeyExW(hkRoot, lpSubKey, samDesired, Reserved);
855
+ void ValidateUninstallKeyResume(Int32 expected)
856
+ {
857
+ this->ValidateUninstallKeyNumber(L"Resume", expected);
858
+ }
859
997
-LExit:
998
- ReleaseRegKey(hkRoot);
860
+ void ValidateVariableKey(LPCWSTR valueName, String^ expected)
861
+ {
862
+ WixAssert::StringEqual(expected, (String^)Registry::GetValue(this->testVariableKeyPath, gcnew String(valueName), nullptr), false);
863
+ }
864
1000
- return ls;
865
+ void ValidateVariableKeyEmpty(LPCWSTR valueName)
866
+ {
867
+ Assert::Empty((System::Collections::IEnumerable^)Registry::GetValue(this->testVariableKeyPath, gcnew String(valueName), nullptr));
868
+ }
869
+ };
870
+}
871
+}
872
+}
873
+}
874
}
src/burn/test/BurnUnitTest/TestRegistryFixture.cpp
new
+184
@@ -0,0 +1,184 @@
1
+// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
+
3
+#include "precomp.h"
4
+
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"
7
+#define TEST_REGISTRY_FIXTURE_HKCU_PATH TEST_REGISTRY_FIXTURE_ROOT_PATH L"\\HKCU"
8
+
9
+static LSTATUS APIENTRY TestRegistryFixture_RegCreateKeyExW(
10
+ __in HKEY hKey,
11
+ __in LPCWSTR lpSubKey,
12
+ __reserved DWORD Reserved,
13
+ __in_opt LPWSTR lpClass,
14
+ __in DWORD dwOptions,
15
+ __in REGSAM samDesired,
16
+ __in_opt CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes,
17
+ __out PHKEY phkResult,
18
+ __out_opt LPDWORD lpdwDisposition
19
+ )
20
+{
21
+ LSTATUS ls = ERROR_SUCCESS;
22
+ LPCWSTR wzRoot = NULL;
23
+ HKEY hkRoot = NULL;
24
+
25
+ if (HKEY_LOCAL_MACHINE == hKey)
26
+ {
27
+ wzRoot = TEST_REGISTRY_FIXTURE_HKLM_PATH;
28
+ }
29
+ else if (HKEY_CURRENT_USER == hKey)
30
+ {
31
+ wzRoot = TEST_REGISTRY_FIXTURE_HKCU_PATH;
32
+ }
33
+ else
34
+ {
35
+ hkRoot = hKey;
36
+ }
37
+
38
+ if (wzRoot)
39
+ {
40
+ ls = ::RegOpenKeyExW(HKEY_CURRENT_USER, wzRoot, 0, KEY_WRITE, &hkRoot);
41
+ if (ERROR_SUCCESS != ls)
42
+ {
43
+ ExitFunction();
44
+ }
45
+ }
46
+
47
+ ls = ::RegCreateKeyExW(hkRoot, lpSubKey, Reserved, lpClass, dwOptions, samDesired, lpSecurityAttributes, phkResult, lpdwDisposition);
48
+
49
+LExit:
50
+ ReleaseRegKey(hkRoot);
51
+
52
+ return ls;
53
+}
54
+
55
+static LSTATUS APIENTRY TestRegistryFixture_RegOpenKeyExW(
56
+ __in HKEY hKey,
57
+ __in_opt LPCWSTR lpSubKey,
58
+ __reserved DWORD ulOptions,
59
+ __in REGSAM samDesired,
60
+ __out PHKEY phkResult
61
+ )
62
+{
63
+ LSTATUS ls = ERROR_SUCCESS;
64
+ LPCWSTR wzRoot = NULL;
65
+ HKEY hkRoot = NULL;
66
+
67
+ if (HKEY_LOCAL_MACHINE == hKey)
68
+ {
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
+ {
82
+ ls = ::RegOpenKeyExW(HKEY_CURRENT_USER, wzRoot, 0, KEY_WRITE, &hkRoot);
83
+ if (ERROR_SUCCESS != ls)
84
+ {
85
+ ExitFunction();
86
+ }
87
+ }
88
+
89
+ ls = ::RegOpenKeyExW(hkRoot, lpSubKey, ulOptions, samDesired, phkResult);
90
+
91
+LExit:
92
+ ReleaseRegKey(hkRoot);
93
+
94
+ return ls;
95
+}
96
+
97
+static LSTATUS APIENTRY TestRegistryFixture_RegDeleteKeyExW(
98
+ __in HKEY hKey,
99
+ __in LPCWSTR lpSubKey,
100
+ __in REGSAM samDesired,
101
+ __reserved DWORD Reserved
102
+ )
103
+{
104
+ LSTATUS ls = ERROR_SUCCESS;
105
+ LPCWSTR wzRoot = NULL;
106
+ HKEY hkRoot = NULL;
107
+
108
+ if (HKEY_LOCAL_MACHINE == hKey)
109
+ {
110
+ wzRoot = TEST_REGISTRY_FIXTURE_HKLM_PATH;
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
+ }
129
+
130
+ ls = ::RegDeleteKeyExW(hkRoot, lpSubKey, samDesired, Reserved);
131
+
132
+LExit:
133
+ ReleaseRegKey(hkRoot);
134
+
135
+ return ls;
136
+}
137
+
138
+namespace WixBuildTools
139
+{
140
+ namespace TestSupport
141
+ {
142
+ using namespace System;
143
+ using namespace System::IO;
144
+ using namespace Microsoft::Win32;
145
+
146
+ TestRegistryFixture::TestRegistryFixture()
147
+ {
148
+ 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
+ }
152
+
153
+ TestRegistryFixture::~TestRegistryFixture()
154
+ {
155
+ this->TearDown();
156
+ }
157
+
158
+ void TestRegistryFixture::SetUp()
159
+ {
160
+ // set mock API's
161
+ RegFunctionOverride(TestRegistryFixture_RegCreateKeyExW, TestRegistryFixture_RegOpenKeyExW, TestRegistryFixture_RegDeleteKeyExW, NULL, NULL, NULL, NULL, NULL, NULL);
162
+
163
+ Registry::CurrentUser->CreateSubKey(this->hkcuPath);
164
+ Registry::CurrentUser->CreateSubKey(this->hklmPath);
165
+ }
166
+
167
+ void TestRegistryFixture::TearDown()
168
+ {
169
+ Registry::CurrentUser->DeleteSubKeyTree(this->rootPath, false);
170
+
171
+ RegFunctionOverride(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
172
+ }
173
+
174
+ String^ TestRegistryFixture::GetDirectHkcuPath(... array<String^>^ paths)
175
+ {
176
+ return Path::Combine(Registry::CurrentUser->Name, this->hkcuPath, Path::Combine(paths));
177
+ }
178
+
179
+ String^ TestRegistryFixture::GetDirectHklmPath(... array<String^>^ paths)
180
+ {
181
+ return Path::Combine(Registry::CurrentUser->Name, this->hklmPath, Path::Combine(paths));
182
+ }
183
+ }
184
+}
src/burn/test/BurnUnitTest/TestRegistryFixture.h
new
+30
@@ -0,0 +1,30 @@
1
+#pragma once
2
+// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
3
+
4
+namespace WixBuildTools
5
+{
6
+namespace TestSupport
7
+{
8
+ using namespace System;
9
+
10
+ public ref class TestRegistryFixture : IDisposable
11
+ {
12
+ private:
13
+ String^ rootPath;
14
+ String^ hkcuPath;
15
+ String^ hklmPath;
16
+ public:
17
+ TestRegistryFixture();
18
+
19
+ ~TestRegistryFixture();
20
+
21
+ void SetUp();
22
+
23
+ void TearDown();
24
+
25
+ String^ GetDirectHkcuPath(... array<String^>^ paths);
26
+
27
+ String^ GetDirectHklmPath(... array<String^>^ paths);
28
+ };
29
+}
30
+}
src/burn/test/BurnUnitTest/precomp.h
+1
@@ -78,3 +78,4 @@
78
#include "BurnUnitTest.h"
79
#include "VariableHelpers.h"
80
#include "ManifestHelpers.h"
81
+#include "TestRegistryFixture.h"