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