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

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
« no previous file with comments | « base/win/registry.cc ('k') | base/win/win_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
49 ASSERT_TRUE(key.Valid());
48 50
49 const wchar_t* kName = L"Bar"; 51 const wchar_t* kStringValueName = L"StringValue";
50 const wchar_t* kValue = L"bar"; 52 const wchar_t* kDWORDValueName = L"DWORDValue";
51 EXPECT_TRUE(key.WriteValue(kName, kValue)); 53 const wchar_t* kInt64ValueName = L"Int64Value";
52 EXPECT_TRUE(key.ValueExists(kName)); 54 const wchar_t* kStringData = L"string data";
53 std::wstring out_value; 55 const DWORD kDWORDData = 0xdeadbabe;
54 EXPECT_TRUE(key.ReadValue(kName, &out_value)); 56 const int64 kInt64Data = 0xdeadbabedeadbabeLL;
55 EXPECT_NE(out_value, L""); 57
56 EXPECT_STREQ(out_value.c_str(), kValue); 58 // Test value creation
57 EXPECT_EQ(1U, key.ValueCount()); 59 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kStringValueName, kStringData));
58 EXPECT_TRUE(key.DeleteValue(kName)); 60 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kDWORDValueName, kDWORDData));
61 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kInt64ValueName, &kInt64Data,
62 sizeof(kInt64Data), REG_QWORD));
63 EXPECT_EQ(3U, key.ValueCount());
64 EXPECT_TRUE(key.ValueExists(kStringValueName));
65 EXPECT_TRUE(key.ValueExists(kDWORDValueName));
66 EXPECT_TRUE(key.ValueExists(kInt64ValueName));
67
68 // Test Read
69 std::wstring string_value;
70 DWORD dword_value = 0;
71 int64 int64_value = 0;
72 ASSERT_EQ(ERROR_SUCCESS, key.ReadValue(kStringValueName, &string_value));
73 ASSERT_EQ(ERROR_SUCCESS, key.ReadValueDW(kDWORDValueName, &dword_value));
74 ASSERT_EQ(ERROR_SUCCESS, key.ReadInt64(kInt64ValueName, &int64_value));
75 EXPECT_STREQ(kStringData, string_value.c_str());
76 EXPECT_EQ(kDWORDData, dword_value);
77 EXPECT_EQ(kInt64Data, int64_value);
78
79 // Make sure out args are not touched if ReadValue fails
80 const wchar_t* kNonExistent = L"NonExistent";
81 ASSERT_NE(ERROR_SUCCESS, key.ReadValue(kNonExistent, &string_value));
82 ASSERT_NE(ERROR_SUCCESS, key.ReadValueDW(kNonExistent, &dword_value));
83 ASSERT_NE(ERROR_SUCCESS, key.ReadInt64(kNonExistent, &int64_value));
84 EXPECT_STREQ(kStringData, string_value.c_str());
85 EXPECT_EQ(kDWORDData, dword_value);
86 EXPECT_EQ(kInt64Data, int64_value);
87
88 // Test delete
89 ASSERT_EQ(ERROR_SUCCESS, key.DeleteValue(kStringValueName));
90 ASSERT_EQ(ERROR_SUCCESS, key.DeleteValue(kDWORDValueName));
91 ASSERT_EQ(ERROR_SUCCESS, key.DeleteValue(kInt64ValueName));
92 EXPECT_EQ(0U, key.ValueCount());
93 EXPECT_FALSE(key.ValueExists(kStringValueName));
94 EXPECT_FALSE(key.ValueExists(kDWORDValueName));
95 EXPECT_FALSE(key.ValueExists(kInt64ValueName));
59 } 96 }
60 } 97 }
61 98
62 } // namespace 99 } // namespace
63 100
64 } // namespace win 101 } // namespace win
65 } // namespace base 102 } // namespace base
OLDNEW
« no previous file with comments | « base/win/registry.cc ('k') | base/win/win_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698