Android: Get rid of extra dup()s on launching child processes
[chromium-blink-merge.git] / chrome / installer / util / registry_test_data.h
blob4af18618d0f4e0a7683af623af001eb87108cd3e
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_
8 #include <windows.h>
10 #include <string>
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
17 // Reset before use.
18 class RegistryTestData {
19 public:
20 RegistryTestData();
21 // Invokes Reset() on its way out.
22 ~RegistryTestData();
24 // Resets this instance, deletes the key rooted at |base_path|, and then
25 // populates |base_path| with:
26 // \EmptyKey
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.
32 void Reset();
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);
47 private:
48 static bool DeleteKey(HKEY root_key, const wchar_t* path);
50 HKEY root_key_;
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_