Chromium Code Reviews| Index: chrome/installer/util/registry_test_data.h |
| diff --git a/chrome/installer/util/registry_test_data.h b/chrome/installer/util/registry_test_data.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4af18618d0f4e0a7683af623af001eb87108cd3e |
| --- /dev/null |
| +++ b/chrome/installer/util/registry_test_data.h |
| @@ -0,0 +1,58 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_INSTALLER_UTIL_REGISTRY_TEST_DATA_H_ |
| +#define CHROME_INSTALLER_UTIL_REGISTRY_TEST_DATA_H_ |
| + |
|
erikwright (departed)
2011/09/16 18:41:45
#pragma once
grt (UTC plus 2)
2011/09/16 20:44:46
Done.
|
| +#include <windows.h> |
| + |
| +#include <string> |
| + |
| +#include "base/basictypes.h" |
| + |
| +// A helper class for use by unit tests that need some registry space and data. |
| +// BEWARE: Instances of this class irrevocably and recursively delete keys and |
| +// values from the registry. Carefully read the comments for Initialize and |
| +// Reset before use. |
| +class RegistryTestData { |
| + public: |
| + RegistryTestData(); |
| + // Invokes Reset() on its way out. |
| + ~RegistryTestData(); |
| + |
| + // Resets this instance, deletes the key rooted at |base_path|, and then |
| + // populates |base_path| with: |
| + // \EmptyKey |
| + // \NonEmptyKey (default value = "|base_path|\NonEmptyKey") |
| + // \NonEmptyKey\Subkey ("SomeValue" = DWORD 1) |
| + bool Initialize(HKEY root_key, const wchar_t* base_path); |
| + |
| + // Deletes the key rooted at base_path and clears all state. |
| + void Reset(); |
| + |
| + // Fires Google Test expectations in the hopes that |path| contains the same |
| + // data as originally placed in |non_empty_key| by Initialize(). |
| + void ExpectMatchesNonEmptyKey(HKEY root_key, const wchar_t* path); |
| + |
| + HKEY root_key() const { return root_key_; } |
| + const std::wstring& base_path() const { return base_path_; } |
| + const std::wstring& empty_key_path() const { return empty_key_path_; } |
| + const std::wstring& non_empty_key_path() const { return non_empty_key_path_; } |
| + |
| + // Fires Google Test expectations in the hopes that |path| is an empty key |
| + // (exists but has no values or subkeys). |
| + static void ExpectEmptyKey(HKEY root_key, const wchar_t* path); |
| + |
| + private: |
| + static bool DeleteKey(HKEY root_key, const wchar_t* path); |
| + |
| + HKEY root_key_; |
| + std::wstring base_path_; |
| + std::wstring empty_key_path_; |
| + std::wstring non_empty_key_path_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(RegistryTestData); |
| +}; |
| + |
| +#endif // CHROME_INSTALLER_UTIL_REGISTRY_TEST_DATA_H_ |