OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome_elf/nt_registry/nt_registry.h" |
| 6 |
| 7 #include <windows.h> |
| 8 #include <rpc.h> |
| 9 #include <stddef.h> |
| 10 |
| 11 #include "base/test/test_reg_util_win.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace { |
| 15 |
| 16 //------------------------------------------------------------------------------ |
| 17 // WOW64 redirection tests |
| 18 // |
| 19 // - Only HKCU will be tested on the auto (try) bots. |
| 20 // HKLM will be kept separate (and manual) for local testing only. |
| 21 // |
| 22 // NOTE: Currently no real WOW64 context testing, as building x86 projects |
| 23 // during x64 builds is not currently supported for performance reasons. |
| 24 // https://cs.chromium.org/chromium/src/build/toolchain/win/BUILD.gn?sq%3Dpackag
e:chromium&l=314 |
| 25 //------------------------------------------------------------------------------ |
| 26 |
| 27 // Utility function for the WOW64 redirection test suites. |
| 28 // Note: Testing redirection through ADVAPI32 here as well, to get notice if |
| 29 // expected behaviour changes! |
| 30 // If |redirected_path| == nullptr, no redirection is expected in any case. |
| 31 void DoRedirectTest(nt::ROOT_KEY nt_root_key, |
| 32 const wchar_t* path, |
| 33 const wchar_t* redirected_path OPTIONAL) { |
| 34 HANDLE handle = INVALID_HANDLE_VALUE; |
| 35 HKEY key_handle = nullptr; |
| 36 constexpr ACCESS_MASK kAccess = KEY_WRITE | DELETE; |
| 37 const HKEY root_key = |
| 38 (nt_root_key == nt::HKCU) ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; |
| 39 |
| 40 // Make sure clean before starting. |
| 41 nt::DeleteRegKey(nt_root_key, nt::NONE, path); |
| 42 if (redirected_path) |
| 43 nt::DeleteRegKey(nt_root_key, nt::NONE, redirected_path); |
| 44 |
| 45 //---------------------------------------------------------------------------- |
| 46 // No redirection through ADVAPI32 on straight x86 or x64. |
| 47 ASSERT_EQ(ERROR_SUCCESS, |
| 48 RegCreateKeyExW(root_key, path, 0, nullptr, REG_OPTION_NON_VOLATILE, |
| 49 kAccess, nullptr, &key_handle, nullptr)); |
| 50 ASSERT_EQ(ERROR_SUCCESS, RegCloseKey(key_handle)); |
| 51 ASSERT_TRUE(nt::OpenRegKey(nt_root_key, path, kAccess, &handle, nullptr)); |
| 52 ASSERT_TRUE(nt::DeleteRegKey(handle)); |
| 53 nt::CloseRegKey(handle); |
| 54 |
| 55 #ifdef _WIN64 |
| 56 //---------------------------------------------------------------------------- |
| 57 // Try forcing WOW64 redirection on x64 through ADVAPI32. |
| 58 ASSERT_EQ(ERROR_SUCCESS, |
| 59 RegCreateKeyExW(root_key, path, 0, nullptr, REG_OPTION_NON_VOLATILE, |
| 60 kAccess | KEY_WOW64_32KEY, nullptr, &key_handle, |
| 61 nullptr)); |
| 62 ASSERT_EQ(ERROR_SUCCESS, RegCloseKey(key_handle)); |
| 63 // Check path: |
| 64 if (nt::OpenRegKey(nt_root_key, path, kAccess, &handle, nullptr)) { |
| 65 if (redirected_path) |
| 66 ADD_FAILURE(); |
| 67 ASSERT_TRUE(nt::DeleteRegKey(handle)); |
| 68 nt::CloseRegKey(handle); |
| 69 } else if (!redirected_path) { |
| 70 // Should have succeeded. |
| 71 ADD_FAILURE(); |
| 72 } |
| 73 if (redirected_path) { |
| 74 // Check redirected path: |
| 75 if (nt::OpenRegKey(nt_root_key, redirected_path, kAccess, &handle, |
| 76 nullptr)) { |
| 77 if (!redirected_path) |
| 78 ADD_FAILURE(); |
| 79 ASSERT_TRUE(nt::DeleteRegKey(handle)); |
| 80 nt::CloseRegKey(handle); |
| 81 } else { |
| 82 // Should have succeeded. |
| 83 ADD_FAILURE(); |
| 84 } |
| 85 } |
| 86 |
| 87 //---------------------------------------------------------------------------- |
| 88 // Try forcing WOW64 redirection on x64 through NTDLL. |
| 89 ASSERT_TRUE( |
| 90 nt::CreateRegKey(nt_root_key, path, kAccess | KEY_WOW64_32KEY, nullptr)); |
| 91 // Check path: |
| 92 if (nt::OpenRegKey(nt_root_key, path, kAccess, &handle, nullptr)) { |
| 93 if (redirected_path) |
| 94 ADD_FAILURE(); |
| 95 ASSERT_TRUE(nt::DeleteRegKey(handle)); |
| 96 nt::CloseRegKey(handle); |
| 97 } else if (!redirected_path) { |
| 98 // Should have succeeded. |
| 99 ADD_FAILURE(); |
| 100 } |
| 101 if (redirected_path) { |
| 102 // Check redirected path: |
| 103 if (nt::OpenRegKey(nt_root_key, redirected_path, kAccess, &handle, |
| 104 nullptr)) { |
| 105 if (!redirected_path) |
| 106 ADD_FAILURE(); |
| 107 ASSERT_TRUE(nt::DeleteRegKey(handle)); |
| 108 nt::CloseRegKey(handle); |
| 109 } else { |
| 110 // Should have succeeded. |
| 111 ADD_FAILURE(); |
| 112 } |
| 113 } |
| 114 #endif // _WIN64 |
| 115 } |
| 116 |
| 117 // These test reg paths match |kClassesSubtree| in nt_registry.cc. |
| 118 constexpr const wchar_t* kClassesRedirects[] = { |
| 119 L"SOFTWARE\\Classes\\CLSID\\chrome_testing", |
| 120 L"SOFTWARE\\Classes\\WOW6432Node\\CLSID\\chrome_testing", |
| 121 L"SOFTWARE\\Classes\\DirectShow\\chrome_testing", |
| 122 L"SOFTWARE\\Classes\\WOW6432Node\\DirectShow\\chrome_testing", |
| 123 L"SOFTWARE\\Classes\\Interface\\chrome_testing", |
| 124 L"SOFTWARE\\Classes\\WOW6432Node\\Interface\\chrome_testing", |
| 125 L"SOFTWARE\\Classes\\Media Type\\chrome_testing", |
| 126 L"SOFTWARE\\Classes\\WOW6432Node\\Media Type\\chrome_testing", |
| 127 L"SOFTWARE\\Classes\\MediaFoundation\\chrome_testing", |
| 128 L"SOFTWARE\\Classes\\WOW6432Node\\MediaFoundation\\chrome_testing"}; |
| 129 |
| 130 static_assert((_countof(kClassesRedirects) & 0x01) == 0, |
| 131 "Must have an even number of kClassesRedirects."); |
| 132 |
| 133 // This test does NOT use NtRegistryTest class. It requires Windows WOW64 |
| 134 // redirection to take place, which would not happen with a testing redirection |
| 135 // layer. |
| 136 TEST(NtRegistryTestRedirection, Wow64RedirectionHKCU) { |
| 137 // Using two elements for each loop. |
| 138 for (size_t index = 0; index < _countof(kClassesRedirects); index += 2) { |
| 139 DoRedirectTest(nt::HKCU, kClassesRedirects[index], |
| 140 kClassesRedirects[index + 1]); |
| 141 } |
| 142 } |
| 143 |
| 144 // These test reg paths match |kHklmSoftwareSubtree| in nt_registry.cc. |
| 145 constexpr const wchar_t* kHKLMNoRedirects[] = { |
| 146 L"SOFTWARE\\Classes\\chrome_testing", L"SOFTWARE\\Clients\\chrome_testing", |
| 147 L"SOFTWARE\\Microsoft\\COM3\\chrome_testing", |
| 148 L"SOFTWARE\\Microsoft\\Cryptography\\Calais\\Current\\chrome_testing", |
| 149 L"SOFTWARE\\Microsoft\\Cryptography\\Calais\\Readers\\chrome_testing", |
| 150 L"SOFTWARE\\Microsoft\\Cryptography\\Services\\chrome_testing", |
| 151 L"SOFTWARE\\Microsoft\\CTF\\SystemShared\\chrome_testing", |
| 152 L"SOFTWARE\\Microsoft\\CTF\\TIP\\chrome_testing", |
| 153 L"SOFTWARE\\Microsoft\\DFS\\chrome_testing", |
| 154 L"SOFTWARE\\Microsoft\\Driver Signing\\chrome_testing", |
| 155 L"SOFTWARE\\Microsoft\\EnterpriseCertificates\\chrome_testing", |
| 156 L"SOFTWARE\\Microsoft\\EventSystem\\chrome_testing", |
| 157 L"SOFTWARE\\Microsoft\\MSMQ\\chrome_testing", |
| 158 L"SOFTWARE\\Microsoft\\Non-Driver Signing\\chrome_testing", |
| 159 L"SOFTWARE\\Microsoft\\Notepad\\DefaultFonts\\chrome_testing", |
| 160 L"SOFTWARE\\Microsoft\\OLE\\chrome_testing", |
| 161 L"SOFTWARE\\Microsoft\\RAS\\chrome_testing", |
| 162 L"SOFTWARE\\Microsoft\\RPC\\chrome_testing", |
| 163 L"SOFTWARE\\Microsoft\\SOFTWARE\\Microsoft\\Shared " |
| 164 L"Tools\\MSInfo\\chrome_testing", |
| 165 L"SOFTWARE\\Microsoft\\SystemCertificates\\chrome_testing", |
| 166 L"SOFTWARE\\Microsoft\\TermServLicensing\\chrome_testing", |
| 167 L"SOFTWARE\\Microsoft\\Transaction Server\\chrome_testing", |
| 168 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App " |
| 169 L"Paths\\chrome_testing", |
| 170 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Control " |
| 171 L"Panel\\Cursors\\Schemes\\chrome_testing", |
| 172 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\AutoplayHandlers" |
| 173 L"\\chrome_testing", |
| 174 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\DriveIcons" |
| 175 L"\\chrome_testing", |
| 176 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\KindMap" |
| 177 L"\\chrome_testing", |
| 178 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Group " |
| 179 L"Policy\\chrome_testing", |
| 180 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\chrome_testing", |
| 181 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\PreviewHandlers" |
| 182 L"\\chrome_testing", |
| 183 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\chrome_testing", |
| 184 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Telephony\\Locations" |
| 185 L"\\chrome_testing", |
| 186 L"SOFTWARE\\Microsoft\\Windows " |
| 187 L"NT\\CurrentVersion\\Console\\chrome_testing", |
| 188 L"SOFTWARE\\Microsoft\\Windows " |
| 189 L"NT\\CurrentVersion\\FontDpi\\chrome_testing", |
| 190 L"SOFTWARE\\Microsoft\\Windows " |
| 191 L"NT\\CurrentVersion\\FontLink\\chrome_testing", |
| 192 L"SOFTWARE\\Microsoft\\Windows " |
| 193 L"NT\\CurrentVersion\\FontMapper\\chrome_testing", |
| 194 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\\chrome_testing", |
| 195 L"SOFTWARE\\Microsoft\\Windows " |
| 196 L"NT\\CurrentVersion\\FontSubstitutes\\chrome_testing", |
| 197 L"SOFTWARE\\Microsoft\\Windows " |
| 198 L"NT\\CurrentVersion\\Gre_initialize\\chrome_testing", |
| 199 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution " |
| 200 L"Options\\chrome_testing", |
| 201 L"SOFTWARE\\Microsoft\\Windows " |
| 202 L"NT\\CurrentVersion\\LanguagePack\\chrome_testing", |
| 203 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards" |
| 204 L"\\chrome_testing", |
| 205 L"SOFTWARE\\Microsoft\\Windows " |
| 206 L"NT\\CurrentVersion\\Perflib\\chrome_testing", |
| 207 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Ports\\chrome_testing", |
| 208 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print\\chrome_testing", |
| 209 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList" |
| 210 L"\\chrome_testing", |
| 211 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time " |
| 212 L"Zones\\chrome_testing", |
| 213 L"SOFTWARE\\Policies\\chrome_testing", |
| 214 L"SOFTWARE\\RegisteredApplications\\chrome_testing"}; |
| 215 |
| 216 // Run from administrator command prompt! |
| 217 // Note: Disabled for automated testing (HKLM protection). Local testing |
| 218 // only. |
| 219 // |
| 220 // This test does NOT use NtRegistryTest class. It requires Windows WOW64 |
| 221 // redirection to take place, which would not happen with a testing redirection |
| 222 // layer. |
| 223 TEST(NtRegistryTestRedirection, DISABLED_Wow64RedirectionHKLM) { |
| 224 // 1) SOFTWARE is redirected. |
| 225 DoRedirectTest(nt::HKLM, L"SOFTWARE\\chrome_testing", |
| 226 L"SOFTWARE\\WOW6432Node\\chrome_testing"); |
| 227 |
| 228 // 2) Except some subkeys are not. |
| 229 for (size_t index = 0; index < _countof(kHKLMNoRedirects); ++index) { |
| 230 DoRedirectTest(nt::HKLM, kHKLMNoRedirects[index], nullptr); |
| 231 } |
| 232 |
| 233 // 3) But then some Classes subkeys are redirected. |
| 234 // Using two elements for each loop. |
| 235 for (size_t index = 0; index < _countof(kClassesRedirects); index += 2) { |
| 236 DoRedirectTest(nt::HKLM, kClassesRedirects[index], |
| 237 kClassesRedirects[index + 1]); |
| 238 } |
| 239 |
| 240 // 4) And just make sure other Classes subkeys are shared. |
| 241 DoRedirectTest(nt::HKLM, L"SOFTWARE\\Classes\\chrome_testing", nullptr); |
| 242 } |
| 243 |
| 244 TEST(NtRegistryTestMisc, SanitizeSubkeyPaths) { |
| 245 std::wstring new_path = L""; |
| 246 EXPECT_TRUE(nt::SetTestingOverride(nt::HKCU, new_path)); |
| 247 std::wstring sani_path = nt::GetTestingOverride(nt::HKCU); |
| 248 EXPECT_STREQ(L"", sani_path.c_str()); |
| 249 |
| 250 new_path = L"boo"; |
| 251 EXPECT_TRUE(nt::SetTestingOverride(nt::HKCU, new_path)); |
| 252 sani_path = nt::GetTestingOverride(nt::HKCU); |
| 253 EXPECT_STREQ(L"boo", sani_path.c_str()); |
| 254 |
| 255 new_path = L"\\boo"; |
| 256 EXPECT_TRUE(nt::SetTestingOverride(nt::HKCU, new_path)); |
| 257 sani_path = nt::GetTestingOverride(nt::HKCU); |
| 258 EXPECT_STREQ(L"boo", sani_path.c_str()); |
| 259 |
| 260 new_path = L"boo\\"; |
| 261 EXPECT_TRUE(nt::SetTestingOverride(nt::HKCU, new_path)); |
| 262 sani_path = nt::GetTestingOverride(nt::HKCU); |
| 263 EXPECT_STREQ(L"boo", sani_path.c_str()); |
| 264 |
| 265 new_path = L"\\\\\\"; |
| 266 EXPECT_TRUE(nt::SetTestingOverride(nt::HKCU, new_path)); |
| 267 sani_path = nt::GetTestingOverride(nt::HKCU); |
| 268 EXPECT_STREQ(L"", sani_path.c_str()); |
| 269 |
| 270 new_path = L"boo\\\\\\ya"; |
| 271 EXPECT_TRUE(nt::SetTestingOverride(nt::HKCU, new_path)); |
| 272 sani_path = nt::GetTestingOverride(nt::HKCU); |
| 273 EXPECT_STREQ(L"boo\\ya", sani_path.c_str()); |
| 274 |
| 275 new_path = L"\\\\\\boo\\ya\\\\"; |
| 276 EXPECT_TRUE(nt::SetTestingOverride(nt::HKCU, new_path)); |
| 277 sani_path = nt::GetTestingOverride(nt::HKCU); |
| 278 EXPECT_STREQ(L"boo\\ya", sani_path.c_str()); |
| 279 |
| 280 // Be sure to leave the environment clean. |
| 281 new_path.clear(); |
| 282 EXPECT_TRUE(nt::SetTestingOverride(nt::HKCU, new_path)); |
| 283 sani_path = nt::GetTestingOverride(nt::HKCU); |
| 284 EXPECT_STREQ(L"", sani_path.c_str()); |
| 285 } |
| 286 |
| 287 //------------------------------------------------------------------------------ |
| 288 // NtRegistryTest class |
| 289 // |
| 290 // Only use this class for tests that need testing registry redirection. |
| 291 //------------------------------------------------------------------------------ |
| 292 |
| 293 class NtRegistryTest : public testing::Test { |
| 294 protected: |
| 295 void SetUp() override { |
| 296 base::string16 temp; |
| 297 override_manager_.OverrideRegistry(HKEY_CURRENT_USER, &temp); |
| 298 ASSERT_TRUE(nt::SetTestingOverride(nt::HKCU, temp)); |
| 299 override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE, &temp); |
| 300 ASSERT_TRUE(nt::SetTestingOverride(nt::HKLM, temp)); |
| 301 } |
| 302 |
| 303 void TearDown() override { |
| 304 base::string16 temp; |
| 305 ASSERT_TRUE(nt::SetTestingOverride(nt::HKCU, temp)); |
| 306 ASSERT_TRUE(nt::SetTestingOverride(nt::HKLM, temp)); |
| 307 } |
| 308 |
| 309 private: |
| 310 registry_util::RegistryOverrideManager override_manager_; |
| 311 }; |
| 312 |
| 313 //------------------------------------------------------------------------------ |
| 314 // NT registry API tests |
| 315 //------------------------------------------------------------------------------ |
| 316 |
| 317 TEST_F(NtRegistryTest, API_DWORD) { |
| 318 HANDLE key_handle; |
| 319 const wchar_t* dword_val_name = L"DwordTestValue"; |
| 320 DWORD dword_val = 1234; |
| 321 |
| 322 // Create a subkey to play under. |
| 323 ASSERT_TRUE(nt::CreateRegKey(nt::HKCU, L"NTRegistry\\dword", KEY_ALL_ACCESS, |
| 324 &key_handle)); |
| 325 ASSERT_NE(key_handle, INVALID_HANDLE_VALUE); |
| 326 ASSERT_NE(key_handle, nullptr); |
| 327 |
| 328 DWORD get_dword = 0; |
| 329 EXPECT_FALSE(nt::QueryRegValueDWORD(key_handle, dword_val_name, &get_dword)); |
| 330 |
| 331 // Set |
| 332 EXPECT_TRUE(nt::SetRegValueDWORD(key_handle, dword_val_name, dword_val)); |
| 333 |
| 334 // Get |
| 335 EXPECT_TRUE(nt::QueryRegValueDWORD(key_handle, dword_val_name, &get_dword)); |
| 336 EXPECT_TRUE(get_dword == dword_val); |
| 337 |
| 338 // Clean up |
| 339 EXPECT_TRUE(nt::DeleteRegKey(key_handle)); |
| 340 nt::CloseRegKey(key_handle); |
| 341 } |
| 342 |
| 343 TEST_F(NtRegistryTest, API_SZ) { |
| 344 HANDLE key_handle; |
| 345 const wchar_t* sz_val_name = L"SzTestValue"; |
| 346 std::wstring sz_val = L"blah de blah de blahhhhh."; |
| 347 const wchar_t* sz_val_name2 = L"SzTestValueEmpty"; |
| 348 std::wstring sz_val2 = L""; |
| 349 |
| 350 // Create a subkey to play under. |
| 351 ASSERT_TRUE(nt::CreateRegKey(nt::HKCU, L"NTRegistry\\sz", KEY_ALL_ACCESS, |
| 352 &key_handle)); |
| 353 ASSERT_NE(key_handle, INVALID_HANDLE_VALUE); |
| 354 ASSERT_NE(key_handle, nullptr); |
| 355 |
| 356 std::wstring get_sz; |
| 357 EXPECT_FALSE(nt::QueryRegValueSZ(key_handle, sz_val_name, &get_sz)); |
| 358 |
| 359 // Set |
| 360 EXPECT_TRUE(nt::SetRegValueSZ(key_handle, sz_val_name, sz_val)); |
| 361 EXPECT_TRUE(nt::SetRegValueSZ(key_handle, sz_val_name2, sz_val2)); |
| 362 |
| 363 // Get |
| 364 EXPECT_TRUE(nt::QueryRegValueSZ(key_handle, sz_val_name, &get_sz)); |
| 365 EXPECT_TRUE(get_sz.compare(sz_val) == 0); |
| 366 EXPECT_TRUE(nt::QueryRegValueSZ(key_handle, sz_val_name2, &get_sz)); |
| 367 EXPECT_TRUE(get_sz.compare(sz_val2) == 0); |
| 368 |
| 369 // Clean up |
| 370 EXPECT_TRUE(nt::DeleteRegKey(key_handle)); |
| 371 nt::CloseRegKey(key_handle); |
| 372 } |
| 373 |
| 374 TEST_F(NtRegistryTest, API_MULTISZ) { |
| 375 HANDLE key_handle; |
| 376 const wchar_t* multisz_val_name = L"SzmultiTestValue"; |
| 377 std::vector<std::wstring> multisz_val; |
| 378 std::wstring multi1 = L"one"; |
| 379 std::wstring multi2 = L"two"; |
| 380 std::wstring multi3 = L"three"; |
| 381 const wchar_t* multisz_val_name2 = L"SzmultiTestValueBad"; |
| 382 std::wstring multi_empty = L""; |
| 383 |
| 384 // Create a subkey to play under. |
| 385 ASSERT_TRUE(nt::CreateRegKey(nt::HKCU, L"NTRegistry\\multisz", KEY_ALL_ACCESS, |
| 386 &key_handle)); |
| 387 ASSERT_NE(key_handle, INVALID_HANDLE_VALUE); |
| 388 ASSERT_NE(key_handle, nullptr); |
| 389 |
| 390 multisz_val.push_back(multi1); |
| 391 multisz_val.push_back(multi2); |
| 392 multisz_val.push_back(multi3); |
| 393 // Set |
| 394 EXPECT_TRUE( |
| 395 nt::SetRegValueMULTISZ(key_handle, multisz_val_name, multisz_val)); |
| 396 multisz_val.clear(); |
| 397 multisz_val.push_back(multi_empty); |
| 398 // Set |
| 399 EXPECT_TRUE( |
| 400 nt::SetRegValueMULTISZ(key_handle, multisz_val_name2, multisz_val)); |
| 401 multisz_val.clear(); |
| 402 |
| 403 // Get |
| 404 EXPECT_TRUE( |
| 405 nt::QueryRegValueMULTISZ(key_handle, multisz_val_name, &multisz_val)); |
| 406 if (multisz_val.size() == 3) { |
| 407 EXPECT_TRUE(multi1.compare(multisz_val.at(0)) == 0); |
| 408 EXPECT_TRUE(multi2.compare(multisz_val.at(1)) == 0); |
| 409 EXPECT_TRUE(multi3.compare(multisz_val.at(2)) == 0); |
| 410 } else { |
| 411 EXPECT_TRUE(false); |
| 412 } |
| 413 multisz_val.clear(); |
| 414 |
| 415 // Get |
| 416 EXPECT_TRUE( |
| 417 nt::QueryRegValueMULTISZ(key_handle, multisz_val_name2, &multisz_val)); |
| 418 if (multisz_val.size() == 1) { |
| 419 EXPECT_TRUE(multi_empty.compare(multisz_val.at(0)) == 0); |
| 420 } else { |
| 421 EXPECT_TRUE(false); |
| 422 } |
| 423 multisz_val.clear(); |
| 424 |
| 425 // Clean up |
| 426 EXPECT_TRUE(nt::DeleteRegKey(key_handle)); |
| 427 nt::CloseRegKey(key_handle); |
| 428 } |
| 429 |
| 430 TEST_F(NtRegistryTest, CreateRegKeyRecursion) { |
| 431 HANDLE key_handle; |
| 432 const wchar_t* sz_new_key_1 = L"test1\\new\\subkey"; |
| 433 const wchar_t* sz_new_key_2 = L"test2\\new\\subkey\\blah\\"; |
| 434 const wchar_t* sz_new_key_3 = L"\\test3\\new\\subkey\\\\blah2"; |
| 435 |
| 436 // Tests for CreateRegKey recursion. |
| 437 ASSERT_TRUE( |
| 438 nt::CreateRegKey(nt::HKCU, sz_new_key_1, KEY_ALL_ACCESS, nullptr)); |
| 439 EXPECT_TRUE(nt::OpenRegKey(nt::HKCU, sz_new_key_1, KEY_ALL_ACCESS, |
| 440 &key_handle, nullptr)); |
| 441 EXPECT_TRUE(nt::DeleteRegKey(key_handle)); |
| 442 nt::CloseRegKey(key_handle); |
| 443 |
| 444 ASSERT_TRUE( |
| 445 nt::CreateRegKey(nt::HKCU, sz_new_key_2, KEY_ALL_ACCESS, nullptr)); |
| 446 EXPECT_TRUE(nt::OpenRegKey(nt::HKCU, sz_new_key_2, KEY_ALL_ACCESS, |
| 447 &key_handle, nullptr)); |
| 448 EXPECT_TRUE(nt::DeleteRegKey(key_handle)); |
| 449 nt::CloseRegKey(key_handle); |
| 450 |
| 451 ASSERT_TRUE( |
| 452 nt::CreateRegKey(nt::HKCU, sz_new_key_3, KEY_ALL_ACCESS, nullptr)); |
| 453 EXPECT_TRUE(nt::OpenRegKey(nt::HKCU, L"test3\\new\\subkey\\blah2", |
| 454 KEY_ALL_ACCESS, &key_handle, nullptr)); |
| 455 EXPECT_TRUE(nt::DeleteRegKey(key_handle)); |
| 456 nt::CloseRegKey(key_handle); |
| 457 |
| 458 // Subkey path can be null. |
| 459 ASSERT_TRUE(nt::CreateRegKey(nt::HKCU, nullptr, KEY_ALL_ACCESS, &key_handle)); |
| 460 ASSERT_NE(key_handle, INVALID_HANDLE_VALUE); |
| 461 ASSERT_NE(key_handle, nullptr); |
| 462 nt::CloseRegKey(key_handle); |
| 463 } |
| 464 |
| 465 } // namespace |
OLD | NEW |