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

Side by Side Diff: net/disk_cache/blockfile/index_table_v3_unittest.cc

Issue 1894733002: Change scoped_ptr to std::unique_ptr in //net/disk_cache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 | « net/disk_cache/blockfile/index_table_v3.cc ('k') | net/disk_cache/blockfile/mapped_file.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "net/disk_cache/blockfile/index_table_v3.h" 5 #include "net/disk_cache/blockfile/index_table_v3.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // |num_entries| is the capacity of the main table. The extra table is half 56 // |num_entries| is the capacity of the main table. The extra table is half
57 // the size of the main table. 57 // the size of the main table.
58 explicit TestCacheTables(int num_entries); 58 explicit TestCacheTables(int num_entries);
59 ~TestCacheTables() {} 59 ~TestCacheTables() {}
60 60
61 void GetInitData(IndexTableInitData* result); 61 void GetInitData(IndexTableInitData* result);
62 void CopyFrom(const TestCacheTables& other); 62 void CopyFrom(const TestCacheTables& other);
63 base::Time start_time() const { return start_time_; } 63 base::Time start_time() const { return start_time_; }
64 64
65 private: 65 private:
66 scoped_ptr<uint64_t[]> main_bitmap_; 66 std::unique_ptr<uint64_t[]> main_bitmap_;
67 scoped_ptr<disk_cache::IndexBucket[]> main_table_; 67 std::unique_ptr<disk_cache::IndexBucket[]> main_table_;
68 scoped_ptr<disk_cache::IndexBucket[]> extra_table_; 68 std::unique_ptr<disk_cache::IndexBucket[]> extra_table_;
69 base::Time start_time_; 69 base::Time start_time_;
70 int num_bitmap_bytes_; 70 int num_bitmap_bytes_;
71 71
72 DISALLOW_COPY_AND_ASSIGN(TestCacheTables); 72 DISALLOW_COPY_AND_ASSIGN(TestCacheTables);
73 }; 73 };
74 74
75 TestCacheTables::TestCacheTables(int num_entries) { 75 TestCacheTables::TestCacheTables(int num_entries) {
76 DCHECK_GE(num_entries, 1024); 76 DCHECK_GE(num_entries, 1024);
77 DCHECK_EQ(num_entries, num_entries / 1024 * 1024); 77 DCHECK_EQ(num_entries, num_entries / 1024 * 1024);
78 main_table_.reset(new disk_cache::IndexBucket[num_entries]); 78 main_table_.reset(new disk_cache::IndexBucket[num_entries]);
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 ASSERT_EQ(3u, iterator.cells.size()); 573 ASSERT_EQ(3u, iterator.cells.size());
574 EXPECT_EQ(entries[41].hash, iterator.cells[0].hash); 574 EXPECT_EQ(entries[41].hash, iterator.cells[0].hash);
575 EXPECT_EQ(entries[42].hash, iterator.cells[1].hash); 575 EXPECT_EQ(entries[42].hash, iterator.cells[1].hash);
576 EXPECT_EQ(entries[43].hash, iterator.cells[2].hash); 576 EXPECT_EQ(entries[43].hash, iterator.cells[2].hash);
577 } 577 }
578 578
579 // Tests doubling of the table. 579 // Tests doubling of the table.
580 TEST(DiskCacheIndexTable, Doubling) { 580 TEST(DiskCacheIndexTable, Doubling) {
581 IndexTable index(NULL); 581 IndexTable index(NULL);
582 int size = 1024; 582 int size = 1024;
583 scoped_ptr<TestCacheTables> cache(new TestCacheTables(size)); 583 std::unique_ptr<TestCacheTables> cache(new TestCacheTables(size));
584 int entry_id = 0; 584 int entry_id = 0;
585 disk_cache::CellList entries; 585 disk_cache::CellList entries;
586 586
587 // Go from 1024 to 256k cells. 587 // Go from 1024 to 256k cells.
588 for (int resizes = 0; resizes <= 8; resizes++) { 588 for (int resizes = 0; resizes <= 8; resizes++) {
589 scoped_ptr<TestCacheTables> old_cache(std::move(cache)); 589 std::unique_ptr<TestCacheTables> old_cache(std::move(cache));
590 cache.reset(new TestCacheTables(size)); 590 cache.reset(new TestCacheTables(size));
591 cache.get()->CopyFrom(*old_cache.get()); 591 cache.get()->CopyFrom(*old_cache.get());
592 592
593 IndexTableInitData init_data; 593 IndexTableInitData init_data;
594 cache.get()->GetInitData(&init_data); 594 cache.get()->GetInitData(&init_data);
595 index.Init(&init_data); 595 index.Init(&init_data);
596 596
597 // Write some entries. 597 // Write some entries.
598 for (int i = 0; i < 250; i++, entry_id++) { 598 for (int i = 0; i < 250; i++, entry_id++) {
599 SCOPED_TRACE(entry_id); 599 SCOPED_TRACE(entry_id);
(...skipping 14 matching lines...) Expand all
614 disk_cache::EntrySet found_entries = index.LookupEntries(entries[i].hash); 614 disk_cache::EntrySet found_entries = index.LookupEntries(entries[i].hash);
615 ASSERT_EQ(1u, found_entries.cells.size()); 615 ASSERT_EQ(1u, found_entries.cells.size());
616 EXPECT_TRUE(found_entries.cells[0].IsValid()); 616 EXPECT_TRUE(found_entries.cells[0].IsValid());
617 } 617 }
618 } 618 }
619 619
620 // Tests bucket chaining when growing the index. 620 // Tests bucket chaining when growing the index.
621 TEST(DiskCacheIndexTable, BucketChains) { 621 TEST(DiskCacheIndexTable, BucketChains) {
622 IndexTable index(NULL); 622 IndexTable index(NULL);
623 int size = 1024; 623 int size = 1024;
624 scoped_ptr<TestCacheTables> cache(new TestCacheTables(size)); 624 std::unique_ptr<TestCacheTables> cache(new TestCacheTables(size));
625 disk_cache::CellList entries; 625 disk_cache::CellList entries;
626 626
627 IndexTableInitData init_data; 627 IndexTableInitData init_data;
628 cache.get()->GetInitData(&init_data); 628 cache.get()->GetInitData(&init_data);
629 index.Init(&init_data); 629 index.Init(&init_data);
630 630
631 // Write some entries. 631 // Write some entries.
632 for (int i = 0; i < 8; i++) { 632 for (int i = 0; i < 8; i++) {
633 SCOPED_TRACE(i); 633 SCOPED_TRACE(i);
634 uint32_t hash = i * 256; 634 uint32_t hash = i * 256;
635 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 7 + 1); 635 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 7 + 1);
636 EntryCell entry = index.CreateEntryCell(hash, addr); 636 EntryCell entry = index.CreateEntryCell(hash, addr);
637 EXPECT_TRUE(entry.IsValid()); 637 EXPECT_TRUE(entry.IsValid());
638 638
639 disk_cache::CellInfo info = { hash, addr }; 639 disk_cache::CellInfo info = { hash, addr };
640 entries.push_back(info); 640 entries.push_back(info);
641 } 641 }
642 642
643 // Double the size. 643 // Double the size.
644 scoped_ptr<TestCacheTables> old_cache(std::move(cache)); 644 std::unique_ptr<TestCacheTables> old_cache(std::move(cache));
645 cache.reset(new TestCacheTables(size * 2)); 645 cache.reset(new TestCacheTables(size * 2));
646 cache.get()->CopyFrom(*old_cache.get()); 646 cache.get()->CopyFrom(*old_cache.get());
647 647
648 cache.get()->GetInitData(&init_data); 648 cache.get()->GetInitData(&init_data);
649 index.Init(&init_data); 649 index.Init(&init_data);
650 650
651 // Write more entries, starting with the upper half of the table. 651 // Write more entries, starting with the upper half of the table.
652 for (int i = 9; i < 11; i++) { 652 for (int i = 9; i < 11; i++) {
653 SCOPED_TRACE(i); 653 SCOPED_TRACE(i);
654 uint32_t hash = i * 256; 654 uint32_t hash = i * 256;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 702
703 uint32_t hash = 0; 703 uint32_t hash = 0;
704 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, 6); 704 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, 6);
705 EntryCell entry = index.CreateEntryCell(hash, addr); 705 EntryCell entry = index.CreateEntryCell(hash, addr);
706 EXPECT_TRUE(entry.IsValid()); 706 EXPECT_TRUE(entry.IsValid());
707 707
708 index.OnBackupTimer(); 708 index.OnBackupTimer();
709 int expected = (1024 + 512) / 8 + sizeof(disk_cache::IndexHeaderV3); 709 int expected = (1024 + 512) / 8 + sizeof(disk_cache::IndexHeaderV3);
710 EXPECT_EQ(expected, backend.buffer_len()); 710 EXPECT_EQ(expected, backend.buffer_len());
711 } 711 }
OLDNEW
« no previous file with comments | « net/disk_cache/blockfile/index_table_v3.cc ('k') | net/disk_cache/blockfile/mapped_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698