1 // Copyright (c) 2010 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 #include "base/registry.h"
6 #include "testing/gtest/include/gtest/gtest.h"
10 const wchar_t kRootKey
[] = L
"Base_Registry_Unittest";
12 class RegistryTest
: public testing::Test
{
17 virtual void SetUp() {
18 // Create a temporary key.
19 RegKey
key(HKEY_CURRENT_USER
, L
"", KEY_ALL_ACCESS
);
20 key
.DeleteKey(kRootKey
);
21 ASSERT_FALSE(key
.Open(HKEY_CURRENT_USER
, kRootKey
, KEY_READ
));
22 ASSERT_TRUE(key
.Create(HKEY_CURRENT_USER
, kRootKey
, KEY_READ
));
25 virtual void TearDown() {
26 // Clean up the temporary key.
27 RegKey
key(HKEY_CURRENT_USER
, L
"", KEY_SET_VALUE
);
28 ASSERT_TRUE(key
.DeleteKey(kRootKey
));
32 DISALLOW_COPY_AND_ASSIGN(RegistryTest
);
35 TEST_F(RegistryTest
, ValueTest
) {
38 std::wstring
foo_key(kRootKey
);
40 ASSERT_TRUE(key
.Create(HKEY_CURRENT_USER
, foo_key
.c_str(), KEY_READ
));
43 ASSERT_TRUE(key
.Open(HKEY_CURRENT_USER
, foo_key
.c_str(),
44 KEY_READ
| KEY_SET_VALUE
));
46 const wchar_t* kName
= L
"Bar";
47 EXPECT_TRUE(key
.WriteValue(kName
, L
"bar"));
48 EXPECT_TRUE(key
.ValueExists(kName
));
49 EXPECT_TRUE(key
.DeleteValue(kName
));