| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2011 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 #ifndef CHROME_INSTALLER_UTIL_REGISTRY_TEST_DATA_H_ |
| 6 #define CHROME_INSTALLER_UTIL_REGISTRY_TEST_DATA_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <windows.h> |
| 10 |
| 11 #include <string> |
| 12 |
| 13 #include "base/basictypes.h" |
| 14 |
| 15 // A helper class for use by unit tests that need some registry space and data. |
| 16 // BEWARE: Instances of this class irrevocably and recursively delete keys and |
| 17 // values from the registry. Carefully read the comments for Initialize and |
| 18 // Reset before use. |
| 19 class RegistryTestData { |
| 20 public: |
| 21 RegistryTestData(); |
| 22 // Invokes Reset() on its way out. |
| 23 ~RegistryTestData(); |
| 24 |
| 25 // Resets this instance, deletes the key rooted at |base_path|, and then |
| 26 // populates |base_path| with: |
| 27 // \EmptyKey |
| 28 // \NonEmptyKey (default value = "|base_path|\NonEmptyKey") |
| 29 // \NonEmptyKey\Subkey ("SomeValue" = DWORD 1) |
| 30 bool Initialize(HKEY root_key, const wchar_t* base_path); |
| 31 |
| 32 // Deletes the key rooted at base_path and clears all state. |
| 33 void Reset(); |
| 34 |
| 35 // Fires Google Test expectations in the hopes that |path| contains the same |
| 36 // data as originally placed in |non_empty_key| by Initialize(). |
| 37 void ExpectMatchesNonEmptyKey(HKEY root_key, const wchar_t* path); |
| 38 |
| 39 HKEY root_key() const { return root_key_; } |
| 40 const std::wstring& base_path() const { return base_path_; } |
| 41 const std::wstring& empty_key_path() const { return empty_key_path_; } |
| 42 const std::wstring& non_empty_key_path() const { return non_empty_key_path_; } |
| 43 |
| 44 // Fires Google Test expectations in the hopes that |path| is an empty key |
| 45 // (exists but has no values or subkeys). |
| 46 static void ExpectEmptyKey(HKEY root_key, const wchar_t* path); |
| 47 |
| 48 private: |
| 49 static bool DeleteKey(HKEY root_key, const wchar_t* path); |
| 50 |
| 51 HKEY root_key_; |
| 52 std::wstring base_path_; |
| 53 std::wstring empty_key_path_; |
| 54 std::wstring non_empty_key_path_; |
| 55 |
| 56 DISALLOW_COPY_AND_ASSIGN(RegistryTestData); |
| 57 }; |
| 58 |
| 59 #endif // CHROME_INSTALLER_UTIL_REGISTRY_TEST_DATA_H_ |
| OLD | NEW |