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

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

Issue 1340683002: Remove base's implicit_cast. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: implicitcast: numericstest Created 5 years, 3 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 | « content/browser/cache_storage/cache_storage.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 const int kNumEntries = 10; 245 const int kNumEntries = 10;
246 246
247 for (int i = 0; i < kNumEntries; ++i) { 247 for (int i = 0; i < kNumEntries; ++i) {
248 std::string key = GenerateKey(true); 248 std::string key = GenerateKey(true);
249 disk_cache::Entry* entry; 249 disk_cache::Entry* entry;
250 if (CreateEntry(key, &entry) != net::OK) 250 if (CreateEntry(key, &entry) != net::OK)
251 return false; 251 return false;
252 key_pool->insert(key); 252 key_pool->insert(key);
253 entry->Close(); 253 entry->Close();
254 } 254 }
255 return key_pool->size() == implicit_cast<size_t>(cache_->GetEntryCount()); 255 return key_pool->size() == static_cast<size_t>(cache_->GetEntryCount());
256 } 256 }
257 257
258 // Performs iteration over the backend and checks that the keys of entries 258 // Performs iteration over the backend and checks that the keys of entries
259 // opened are in |keys_to_match|, then erases them. Up to |max_to_open| entries 259 // opened are in |keys_to_match|, then erases them. Up to |max_to_open| entries
260 // will be opened, if it is positive. Otherwise, iteration will continue until 260 // will be opened, if it is positive. Otherwise, iteration will continue until
261 // OpenNextEntry stops returning net::OK. 261 // OpenNextEntry stops returning net::OK.
262 bool DiskCacheBackendTest::EnumerateAndMatchKeys( 262 bool DiskCacheBackendTest::EnumerateAndMatchKeys(
263 int max_to_open, 263 int max_to_open,
264 TestIterator* iter, 264 TestIterator* iter,
265 std::set<std::string>* keys_to_match, 265 std::set<std::string>* keys_to_match,
266 size_t* count) { 266 size_t* count) {
267 disk_cache::Entry* entry; 267 disk_cache::Entry* entry;
268 268
269 if (!iter) 269 if (!iter)
270 return false; 270 return false;
271 while (iter->OpenNextEntry(&entry) == net::OK) { 271 while (iter->OpenNextEntry(&entry) == net::OK) {
272 if (!entry) 272 if (!entry)
273 return false; 273 return false;
274 EXPECT_EQ(1U, keys_to_match->erase(entry->GetKey())); 274 EXPECT_EQ(1U, keys_to_match->erase(entry->GetKey()));
275 entry->Close(); 275 entry->Close();
276 ++(*count); 276 ++(*count);
277 if (max_to_open >= 0 && implicit_cast<int>(*count) >= max_to_open) 277 if (max_to_open >= 0 && static_cast<int>(*count) >= max_to_open)
278 break; 278 break;
279 }; 279 };
280 280
281 return true; 281 return true;
282 } 282 }
283 283
284 void DiskCacheBackendTest::BackendBasics() { 284 void DiskCacheBackendTest::BackendBasics() {
285 InitCache(); 285 InitCache();
286 disk_cache::Entry *entry1 = NULL, *entry2 = NULL; 286 disk_cache::Entry *entry1 = NULL, *entry2 = NULL;
287 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1)); 287 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1));
(...skipping 3032 matching lines...) Expand 10 before | Expand all | Expand 10 after
3320 // The entry is being closed on the Simple Cache worker pool 3320 // The entry is being closed on the Simple Cache worker pool
3321 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting(); 3321 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
3322 base::RunLoop().RunUntilIdle(); 3322 base::RunLoop().RunUntilIdle();
3323 3323
3324 // Write an invalid header for stream 0 and stream 1. 3324 // Write an invalid header for stream 0 and stream 1.
3325 base::FilePath entry_file1_path = cache_path_.AppendASCII( 3325 base::FilePath entry_file1_path = cache_path_.AppendASCII(
3326 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0)); 3326 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0));
3327 3327
3328 disk_cache::SimpleFileHeader header; 3328 disk_cache::SimpleFileHeader header;
3329 header.initial_magic_number = UINT64_C(0xbadf00d); 3329 header.initial_magic_number = UINT64_C(0xbadf00d);
3330 EXPECT_EQ( 3330 EXPECT_EQ(static_cast<int>(sizeof(header)),
3331 implicit_cast<int>(sizeof(header)), 3331 base::WriteFile(entry_file1_path, reinterpret_cast<char*>(&header),
3332 base::WriteFile(entry_file1_path, reinterpret_cast<char*>(&header), 3332 sizeof(header)));
3333 sizeof(header)));
3334 ASSERT_EQ(net::ERR_FAILED, OpenEntry(key, &entry)); 3333 ASSERT_EQ(net::ERR_FAILED, OpenEntry(key, &entry));
3335 } 3334 }
3336 3335
3337 // Tests that the Simple Cache Backend fails to initialize with non-matching 3336 // Tests that the Simple Cache Backend fails to initialize with non-matching
3338 // file structure on disk. 3337 // file structure on disk.
3339 TEST_F(DiskCacheBackendTest, SimpleCacheOverBlockfileCache) { 3338 TEST_F(DiskCacheBackendTest, SimpleCacheOverBlockfileCache) {
3340 // Create a cache structure with the |BackendImpl|. 3339 // Create a cache structure with the |BackendImpl|.
3341 InitCache(); 3340 InitCache();
3342 disk_cache::Entry* entry; 3341 disk_cache::Entry* entry;
3343 const int kSize = 50; 3342 const int kSize = 50;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
3482 const int kSize = 50; 3481 const int kSize = 50;
3483 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); 3482 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
3484 CacheTestFillBuffer(buffer->data(), kSize, false); 3483 CacheTestFillBuffer(buffer->data(), kSize, false);
3485 ASSERT_EQ(kSize, 3484 ASSERT_EQ(kSize,
3486 WriteData(corrupted_entry, 0, 0, buffer.get(), kSize, false)); 3485 WriteData(corrupted_entry, 0, 0, buffer.get(), kSize, false));
3487 ASSERT_EQ(kSize, ReadData(corrupted_entry, 0, 0, buffer.get(), kSize)); 3486 ASSERT_EQ(kSize, ReadData(corrupted_entry, 0, 0, buffer.get(), kSize));
3488 corrupted_entry->Close(); 3487 corrupted_entry->Close();
3489 3488
3490 EXPECT_TRUE(disk_cache::simple_util::CreateCorruptFileForTests( 3489 EXPECT_TRUE(disk_cache::simple_util::CreateCorruptFileForTests(
3491 key, cache_path_)); 3490 key, cache_path_));
3492 EXPECT_EQ(key_pool.size() + 1, 3491 EXPECT_EQ(key_pool.size() + 1, static_cast<size_t>(cache_->GetEntryCount()));
3493 implicit_cast<size_t>(cache_->GetEntryCount()));
3494 3492
3495 // Check that enumeration returns all entries but the corrupt one. 3493 // Check that enumeration returns all entries but the corrupt one.
3496 std::set<std::string> keys_to_match(key_pool); 3494 std::set<std::string> keys_to_match(key_pool);
3497 scoped_ptr<TestIterator> iter = CreateIterator(); 3495 scoped_ptr<TestIterator> iter = CreateIterator();
3498 size_t count = 0; 3496 size_t count = 0;
3499 ASSERT_TRUE(EnumerateAndMatchKeys(-1, iter.get(), &keys_to_match, &count)); 3497 ASSERT_TRUE(EnumerateAndMatchKeys(-1, iter.get(), &keys_to_match, &count));
3500 iter.reset(); 3498 iter.reset();
3501 3499
3502 EXPECT_EQ(key_pool.size(), count); 3500 EXPECT_EQ(key_pool.size(), count);
3503 EXPECT_TRUE(keys_to_match.empty()); 3501 EXPECT_TRUE(keys_to_match.empty());
(...skipping 21 matching lines...) Expand all
3525 // after closing. 3523 // after closing.
3526 // NOTE: IF THIS TEST IS FLAKY THEN IT IS FAILING. See https://crbug.com/416940 3524 // NOTE: IF THIS TEST IS FLAKY THEN IT IS FAILING. See https://crbug.com/416940
3527 TEST_F(DiskCacheBackendTest, SimpleCacheDeleteQuickly) { 3525 TEST_F(DiskCacheBackendTest, SimpleCacheDeleteQuickly) {
3528 SetSimpleCacheMode(); 3526 SetSimpleCacheMode();
3529 for (int i = 0; i < 100; ++i) { 3527 for (int i = 0; i < 100; ++i) {
3530 InitCache(); 3528 InitCache();
3531 cache_.reset(); 3529 cache_.reset();
3532 EXPECT_TRUE(CleanupCacheDir()); 3530 EXPECT_TRUE(CleanupCacheDir());
3533 } 3531 }
3534 } 3532 }
OLDNEW
« no previous file with comments | « content/browser/cache_storage/cache_storage.cc ('k') | net/disk_cache/entry_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698