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

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

Issue 1550493002: Switch to standard integer types in base/win/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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
« no previous file with comments | « base/win/registry.cc ('k') | base/win/resource_util.h » ('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) 2011 The Chromium Authors. All rights reserved. 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 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 6
7 #include <stdint.h>
8
7 #include <cstring> 9 #include <cstring>
8 #include <vector> 10 #include <vector>
9 11
10 #include "base/bind.h" 12 #include "base/bind.h"
11 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/macros.h"
12 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 16 #include "base/run_loop.h"
14 #include "base/stl_util.h" 17 #include "base/stl_util.h"
15 #include "base/win/windows_version.h" 18 #include "base/win/windows_version.h"
16 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
17 20
18 namespace base { 21 namespace base {
19 namespace win { 22 namespace win {
20 23
21 namespace { 24 namespace {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 { 82 {
80 ASSERT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, foo_key.c_str(), 83 ASSERT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, foo_key.c_str(),
81 KEY_READ | KEY_SET_VALUE)); 84 KEY_READ | KEY_SET_VALUE));
82 ASSERT_TRUE(key.Valid()); 85 ASSERT_TRUE(key.Valid());
83 86
84 const wchar_t kStringValueName[] = L"StringValue"; 87 const wchar_t kStringValueName[] = L"StringValue";
85 const wchar_t kDWORDValueName[] = L"DWORDValue"; 88 const wchar_t kDWORDValueName[] = L"DWORDValue";
86 const wchar_t kInt64ValueName[] = L"Int64Value"; 89 const wchar_t kInt64ValueName[] = L"Int64Value";
87 const wchar_t kStringData[] = L"string data"; 90 const wchar_t kStringData[] = L"string data";
88 const DWORD kDWORDData = 0xdeadbabe; 91 const DWORD kDWORDData = 0xdeadbabe;
89 const int64 kInt64Data = 0xdeadbabedeadbabeLL; 92 const int64_t kInt64Data = 0xdeadbabedeadbabeLL;
90 93
91 // Test value creation 94 // Test value creation
92 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kStringValueName, kStringData)); 95 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kStringValueName, kStringData));
93 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kDWORDValueName, kDWORDData)); 96 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kDWORDValueName, kDWORDData));
94 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kInt64ValueName, &kInt64Data, 97 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kInt64ValueName, &kInt64Data,
95 sizeof(kInt64Data), REG_QWORD)); 98 sizeof(kInt64Data), REG_QWORD));
96 EXPECT_EQ(3U, key.GetValueCount()); 99 EXPECT_EQ(3U, key.GetValueCount());
97 EXPECT_TRUE(key.HasValue(kStringValueName)); 100 EXPECT_TRUE(key.HasValue(kStringValueName));
98 EXPECT_TRUE(key.HasValue(kDWORDValueName)); 101 EXPECT_TRUE(key.HasValue(kDWORDValueName));
99 EXPECT_TRUE(key.HasValue(kInt64ValueName)); 102 EXPECT_TRUE(key.HasValue(kInt64ValueName));
100 103
101 // Test Read 104 // Test Read
102 std::wstring string_value; 105 std::wstring string_value;
103 DWORD dword_value = 0; 106 DWORD dword_value = 0;
104 int64 int64_value = 0; 107 int64_t int64_value = 0;
105 ASSERT_EQ(ERROR_SUCCESS, key.ReadValue(kStringValueName, &string_value)); 108 ASSERT_EQ(ERROR_SUCCESS, key.ReadValue(kStringValueName, &string_value));
106 ASSERT_EQ(ERROR_SUCCESS, key.ReadValueDW(kDWORDValueName, &dword_value)); 109 ASSERT_EQ(ERROR_SUCCESS, key.ReadValueDW(kDWORDValueName, &dword_value));
107 ASSERT_EQ(ERROR_SUCCESS, key.ReadInt64(kInt64ValueName, &int64_value)); 110 ASSERT_EQ(ERROR_SUCCESS, key.ReadInt64(kInt64ValueName, &int64_value));
108 EXPECT_STREQ(kStringData, string_value.c_str()); 111 EXPECT_STREQ(kStringData, string_value.c_str());
109 EXPECT_EQ(kDWORDData, dword_value); 112 EXPECT_EQ(kDWORDData, dword_value);
110 EXPECT_EQ(kInt64Data, int64_value); 113 EXPECT_EQ(kInt64Data, int64_value);
111 114
112 // Make sure out args are not touched if ReadValue fails 115 // Make sure out args are not touched if ReadValue fails
113 const wchar_t* kNonExistent = L"NonExistent"; 116 const wchar_t* kNonExistent = L"NonExistent";
114 ASSERT_NE(ERROR_SUCCESS, key.ReadValue(kNonExistent, &string_value)); 117 ASSERT_NE(ERROR_SUCCESS, key.ReadValue(kNonExistent, &string_value));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 std::wstring foo_key(kRootKey); 162 std::wstring foo_key(kRootKey);
160 foo_key += L"\\Foo"; 163 foo_key += L"\\Foo";
161 ASSERT_EQ(ERROR_SUCCESS, key.Create(HKEY_CURRENT_USER, foo_key.c_str(), 164 ASSERT_EQ(ERROR_SUCCESS, key.Create(HKEY_CURRENT_USER, foo_key.c_str(),
162 KEY_READ)); 165 KEY_READ));
163 ASSERT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, foo_key.c_str(), 166 ASSERT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, foo_key.c_str(),
164 KEY_READ | KEY_SET_VALUE)); 167 KEY_READ | KEY_SET_VALUE));
165 ASSERT_TRUE(key.Valid()); 168 ASSERT_TRUE(key.Valid());
166 169
167 const wchar_t kName[] = L"name"; 170 const wchar_t kName[] = L"name";
168 // kData size is not a multiple of sizeof(wchar_t). 171 // kData size is not a multiple of sizeof(wchar_t).
169 const uint8 kData[] = { 1, 2, 3, 4, 5 }; 172 const uint8_t kData[] = {1, 2, 3, 4, 5};
170 EXPECT_EQ(5u, arraysize(kData)); 173 EXPECT_EQ(5u, arraysize(kData));
171 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kName, kData, 174 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kName, kData,
172 arraysize(kData), REG_BINARY)); 175 arraysize(kData), REG_BINARY));
173 176
174 RegistryValueIterator iterator(HKEY_CURRENT_USER, foo_key.c_str()); 177 RegistryValueIterator iterator(HKEY_CURRENT_USER, foo_key.c_str());
175 ASSERT_TRUE(iterator.Valid()); 178 ASSERT_TRUE(iterator.Valid());
176 EXPECT_STREQ(kName, iterator.Name()); 179 EXPECT_STREQ(kName, iterator.Name());
177 // ValueSize() is in bytes. 180 // ValueSize() is in bytes.
178 ASSERT_EQ(arraysize(kData), iterator.ValueSize()); 181 ASSERT_EQ(arraysize(kData), iterator.ValueSize());
179 // Value() is NUL terminated. 182 // Value() is NUL terminated.
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 ASSERT_TRUE(key.StartWatching(Bind(&TestChangeDelegate::OnKeyChanged, 414 ASSERT_TRUE(key.StartWatching(Bind(&TestChangeDelegate::OnKeyChanged,
412 Unretained(&delegate)))); 415 Unretained(&delegate))));
413 base::RunLoop().RunUntilIdle(); 416 base::RunLoop().RunUntilIdle();
414 EXPECT_FALSE(delegate.WasCalled()); 417 EXPECT_FALSE(delegate.WasCalled());
415 } 418 }
416 419
417 } // namespace 420 } // namespace
418 421
419 } // namespace win 422 } // namespace win
420 } // namespace base 423 } // namespace base
OLDNEW
« no previous file with comments | « base/win/registry.cc ('k') | base/win/resource_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698