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

Side by Side Diff: net/disk_cache/backend_unittest.cc

Issue 17019: Try to consistently use arraysize() with strlcpy(). (Closed)
Patch Set: Created 11 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
« no previous file with comments | « base/file_util_posix.cc ('k') | net/disk_cache/entry_unittest.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/basictypes.h"
5 #include "base/file_util.h" 6 #include "base/file_util.h"
6 #include "base/path_service.h" 7 #include "base/path_service.h"
7 #include "base/platform_thread.h" 8 #include "base/platform_thread.h"
8 #include "base/string_util.h" 9 #include "base/string_util.h"
9 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
10 #include "net/disk_cache/backend_impl.h" 11 #include "net/disk_cache/backend_impl.h"
11 #include "net/disk_cache/disk_cache_test_base.h" 12 #include "net/disk_cache/disk_cache_test_base.h"
12 #include "net/disk_cache/disk_cache_test_util.h" 13 #include "net/disk_cache/disk_cache_test_util.h"
13 #include "net/disk_cache/mapped_file.h" 14 #include "net/disk_cache/mapped_file.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 const char* kName1 = "the first key"; 156 const char* kName1 = "the first key";
156 const char* kName2 = "the first Key"; 157 const char* kName2 = "the first Key";
157 disk_cache::Entry *entry1, *entry2; 158 disk_cache::Entry *entry1, *entry2;
158 ASSERT_TRUE(cache_->CreateEntry(kName1, &entry1)); 159 ASSERT_TRUE(cache_->CreateEntry(kName1, &entry1));
159 160
160 ASSERT_TRUE(cache_->CreateEntry(kName2, &entry2)); 161 ASSERT_TRUE(cache_->CreateEntry(kName2, &entry2));
161 EXPECT_TRUE(entry1 != entry2) << "Case sensitive"; 162 EXPECT_TRUE(entry1 != entry2) << "Case sensitive";
162 entry2->Close(); 163 entry2->Close();
163 164
164 char buffer[30]; 165 char buffer[30];
165 base::strlcpy(buffer, kName1, sizeof(buffer)); 166 base::strlcpy(buffer, kName1, arraysize(buffer));
166 ASSERT_TRUE(cache_->OpenEntry(buffer, &entry2)); 167 ASSERT_TRUE(cache_->OpenEntry(buffer, &entry2));
167 EXPECT_TRUE(entry1 == entry2); 168 EXPECT_TRUE(entry1 == entry2);
168 entry2->Close(); 169 entry2->Close();
169 170
170 base::strlcpy(buffer + 1, kName1, sizeof(buffer) - 1); 171 base::strlcpy(buffer + 1, kName1, arraysize(buffer) - 1);
171 ASSERT_TRUE(cache_->OpenEntry(buffer + 1, &entry2)); 172 ASSERT_TRUE(cache_->OpenEntry(buffer + 1, &entry2));
172 EXPECT_TRUE(entry1 == entry2); 173 EXPECT_TRUE(entry1 == entry2);
173 entry2->Close(); 174 entry2->Close();
174 175
175 base::strlcpy(buffer + 3, kName1, sizeof(buffer) - 3); 176 base::strlcpy(buffer + 3, kName1, arraysize(buffer) - 3);
176 ASSERT_TRUE(cache_->OpenEntry(buffer + 3, &entry2)); 177 ASSERT_TRUE(cache_->OpenEntry(buffer + 3, &entry2));
177 EXPECT_TRUE(entry1 == entry2); 178 EXPECT_TRUE(entry1 == entry2);
178 entry2->Close(); 179 entry2->Close();
179 180
180 // Now verify long keys. 181 // Now verify long keys.
181 char buffer2[20000]; 182 char buffer2[20000];
182 memset(buffer2, 's', sizeof(buffer2)); 183 memset(buffer2, 's', sizeof(buffer2));
183 buffer2[1023] = '\0'; 184 buffer2[1023] = '\0';
184 ASSERT_TRUE(cache_->CreateEntry(buffer2, &entry2)) << "key on block file"; 185 ASSERT_TRUE(cache_->CreateEntry(buffer2, &entry2)) << "key on block file";
185 entry2->Close(); 186 entry2->Close();
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 InitCache(); 970 InitCache();
970 BackendDoomAll(); 971 BackendDoomAll();
971 } 972 }
972 973
973 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAll) { 974 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAll) {
974 SetMemoryOnlyMode(); 975 SetMemoryOnlyMode();
975 InitCache(); 976 InitCache();
976 BackendDoomAll(); 977 BackendDoomAll();
977 } 978 }
978 979
OLDNEW
« no previous file with comments | « base/file_util_posix.cc ('k') | net/disk_cache/entry_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698