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

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

Issue 616173003: Allow Registry Iterator functions to use a specified WOW64 mode when iterating. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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 <cstring> 7 #include <cstring>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 KEY_READ)); 134 KEY_READ));
135 ASSERT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, foo_key.c_str(), 135 ASSERT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, foo_key.c_str(),
136 KEY_READ | KEY_SET_VALUE)); 136 KEY_READ | KEY_SET_VALUE));
137 ASSERT_TRUE(key.Valid()); 137 ASSERT_TRUE(key.Valid());
138 138
139 // Create a test value that is larger than MAX_PATH. 139 // Create a test value that is larger than MAX_PATH.
140 std::wstring data(MAX_PATH * 2, L'a'); 140 std::wstring data(MAX_PATH * 2, L'a');
141 141
142 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(data.c_str(), data.c_str())); 142 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(data.c_str(), data.c_str()));
143 143
144 RegistryValueIterator iterator(HKEY_CURRENT_USER, foo_key.c_str()); 144 RegistryValueIterator iterator(HKEY_CURRENT_USER, foo_key.c_str(), 0);
145 ASSERT_TRUE(iterator.Valid()); 145 ASSERT_TRUE(iterator.Valid());
146 EXPECT_STREQ(data.c_str(), iterator.Name()); 146 EXPECT_STREQ(data.c_str(), iterator.Name());
147 EXPECT_STREQ(data.c_str(), iterator.Value()); 147 EXPECT_STREQ(data.c_str(), iterator.Value());
148 // ValueSize() is in bytes, including NUL. 148 // ValueSize() is in bytes, including NUL.
149 EXPECT_EQ((MAX_PATH * 2 + 1) * sizeof(wchar_t), iterator.ValueSize()); 149 EXPECT_EQ((MAX_PATH * 2 + 1) * sizeof(wchar_t), iterator.ValueSize());
150 ++iterator; 150 ++iterator;
151 EXPECT_FALSE(iterator.Valid()); 151 EXPECT_FALSE(iterator.Valid());
152 } 152 }
153 153
154 TEST_F(RegistryTest, TruncatedCharTest) { 154 TEST_F(RegistryTest, TruncatedCharTest) {
155 RegKey key; 155 RegKey key;
156 std::wstring foo_key(kRootKey); 156 std::wstring foo_key(kRootKey);
157 foo_key += L"\\Foo"; 157 foo_key += L"\\Foo";
158 ASSERT_EQ(ERROR_SUCCESS, key.Create(HKEY_CURRENT_USER, foo_key.c_str(), 158 ASSERT_EQ(ERROR_SUCCESS, key.Create(HKEY_CURRENT_USER, foo_key.c_str(),
159 KEY_READ)); 159 KEY_READ));
160 ASSERT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, foo_key.c_str(), 160 ASSERT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, foo_key.c_str(),
161 KEY_READ | KEY_SET_VALUE)); 161 KEY_READ | KEY_SET_VALUE));
162 ASSERT_TRUE(key.Valid()); 162 ASSERT_TRUE(key.Valid());
163 163
164 const wchar_t kName[] = L"name"; 164 const wchar_t kName[] = L"name";
165 // kData size is not a multiple of sizeof(wchar_t). 165 // kData size is not a multiple of sizeof(wchar_t).
166 const uint8 kData[] = { 1, 2, 3, 4, 5 }; 166 const uint8 kData[] = { 1, 2, 3, 4, 5 };
167 EXPECT_EQ(5, arraysize(kData)); 167 EXPECT_EQ(5, arraysize(kData));
168 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kName, kData, 168 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(kName, kData,
169 arraysize(kData), REG_BINARY)); 169 arraysize(kData), REG_BINARY));
170 170
171 RegistryValueIterator iterator(HKEY_CURRENT_USER, foo_key.c_str()); 171 RegistryValueIterator iterator(HKEY_CURRENT_USER, foo_key.c_str(), 0);
172 ASSERT_TRUE(iterator.Valid()); 172 ASSERT_TRUE(iterator.Valid());
173 EXPECT_STREQ(kName, iterator.Name()); 173 EXPECT_STREQ(kName, iterator.Name());
174 // ValueSize() is in bytes. 174 // ValueSize() is in bytes.
175 ASSERT_EQ(arraysize(kData), iterator.ValueSize()); 175 ASSERT_EQ(arraysize(kData), iterator.ValueSize());
176 // Value() is NUL terminated. 176 // Value() is NUL terminated.
177 int end = (iterator.ValueSize() + sizeof(wchar_t) - 1) / sizeof(wchar_t); 177 int end = (iterator.ValueSize() + sizeof(wchar_t) - 1) / sizeof(wchar_t);
178 EXPECT_NE(L'\0', iterator.Value()[end-1]); 178 EXPECT_NE(L'\0', iterator.Value()[end-1]);
179 EXPECT_EQ(L'\0', iterator.Value()[end]); 179 EXPECT_EQ(L'\0', iterator.Value()[end]);
180 EXPECT_EQ(0, std::memcmp(kData, iterator.Value(), arraysize(kData))); 180 EXPECT_EQ(0, std::memcmp(kData, iterator.Value(), arraysize(kData)));
181 ++iterator; 181 ++iterator;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 key.Open(HKEY_CURRENT_USER, foo_key.c_str(), KEY_READ)); 346 key.Open(HKEY_CURRENT_USER, foo_key.c_str(), KEY_READ));
347 347
348 ASSERT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, kRootKey, KEY_WRITE)); 348 ASSERT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, kRootKey, KEY_WRITE));
349 ASSERT_EQ(ERROR_SUCCESS, key.DeleteKey(L"foo")); 349 ASSERT_EQ(ERROR_SUCCESS, key.DeleteKey(L"foo"));
350 } 350 }
351 351
352 } // namespace 352 } // namespace
353 353
354 } // namespace win 354 } // namespace win
355 } // namespace base 355 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698