Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: base/win/registry_unittest.cc

Issue 6090006: Regkey functions return error code instead of bool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/win/registry.h" 5 #include "base/win/registry.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 7
8 namespace base { 8 namespace base {
9 namespace win { 9 namespace win {
10 10
11 namespace { 11 namespace {
12 12
13 const wchar_t kRootKey[] = L"Base_Registry_Unittest"; 13 const wchar_t kRootKey[] = L"Base_Registry_Unittest";
14 14
15 class RegistryTest : public testing::Test { 15 class RegistryTest : public testing::Test {
16 public: 16 public:
17 RegistryTest() {} 17 RegistryTest() {}
18 18
19 protected: 19 protected:
20 virtual void SetUp() { 20 virtual void SetUp() {
21 // Create a temporary key. 21 // Create a temporary key.
22 RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); 22 RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS);
23 key.DeleteKey(kRootKey); 23 key.DeleteKey(kRootKey);
24 ASSERT_FALSE(key.Open(HKEY_CURRENT_USER, kRootKey, KEY_READ)); 24 ASSERT_NE(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, kRootKey, KEY_READ));
25 ASSERT_TRUE(key.Create(HKEY_CURRENT_USER, kRootKey, KEY_READ)); 25 ASSERT_EQ(ERROR_SUCCESS, key.Create(HKEY_CURRENT_USER, kRootKey, KEY_READ));
26 } 26 }
27 27
28 virtual void TearDown() { 28 virtual void TearDown() {
29 // Clean up the temporary key. 29 // Clean up the temporary key.
30 RegKey key(HKEY_CURRENT_USER, L"", KEY_SET_VALUE); 30 RegKey key(HKEY_CURRENT_USER, L"", KEY_SET_VALUE);
31 ASSERT_TRUE(key.DeleteKey(kRootKey)); 31 ASSERT_EQ(ERROR_SUCCESS, key.DeleteKey(kRootKey));
32 } 32 }
33 33
34 private: 34 private:
35 DISALLOW_COPY_AND_ASSIGN(RegistryTest); 35 DISALLOW_COPY_AND_ASSIGN(RegistryTest);
36 }; 36 };
37 37
38 TEST_F(RegistryTest, ValueTest) { 38 TEST_F(RegistryTest, ValueTest) {
39 RegKey key; 39 RegKey key;
40 40
41 std::wstring foo_key(kRootKey); 41 std::wstring foo_key(kRootKey);
42 foo_key += L"\\Foo"; 42 foo_key += L"\\Foo";
43 ASSERT_TRUE(key.Create(HKEY_CURRENT_USER, foo_key.c_str(), KEY_READ)); 43 ASSERT_EQ(ERROR_SUCCESS, key.Create(HKEY_CURRENT_USER, foo_key.c_str(),
44 KEY_READ));
44 45
45 { 46 {
46 ASSERT_TRUE(key.Open(HKEY_CURRENT_USER, foo_key.c_str(), 47 ASSERT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, foo_key.c_str(),
47 KEY_READ | KEY_SET_VALUE)); 48 KEY_READ | KEY_SET_VALUE));
48 49
49 const wchar_t* kName = L"Bar"; 50 const wchar_t* kName = L"Bar";
50 const wchar_t* kValue = L"bar"; 51 const wchar_t* kValue = L"bar";
51 EXPECT_TRUE(key.WriteValue(kName, kValue)); 52 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kName, kValue));
52 EXPECT_TRUE(key.ValueExists(kName)); 53 EXPECT_TRUE(key.ValueExists(kName));
53 std::wstring out_value; 54 std::wstring out_value;
54 EXPECT_TRUE(key.ReadValue(kName, &out_value)); 55 ASSERT_EQ(ERROR_SUCCESS, key.ReadValue(kName, &out_value));
55 EXPECT_NE(out_value, L""); 56 EXPECT_NE(out_value, L"");
56 EXPECT_STREQ(out_value.c_str(), kValue); 57 EXPECT_STREQ(out_value.c_str(), kValue);
57 EXPECT_EQ(1U, key.ValueCount()); 58 EXPECT_EQ(1U, key.ValueCount());
58 EXPECT_TRUE(key.DeleteValue(kName)); 59 ASSERT_EQ(ERROR_SUCCESS, key.DeleteValue(kName));
59 } 60 }
60 } 61 }
61 62
62 } // namespace 63 } // namespace
63 64
64 } // namespace win 65 } // namespace win
65 } // namespace base 66 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698