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

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

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef Created 5 years 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.h ('k') | net/disk_cache/blockfile/mapped_file.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 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/basictypes.h"
8 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/macros.h"
9 #include "net/disk_cache/blockfile/addr.h" 9 #include "net/disk_cache/blockfile/addr.h"
10 #include "net/disk_cache/blockfile/disk_format_v3.h" 10 #include "net/disk_cache/blockfile/disk_format_v3.h"
11 #include "net/disk_cache/blockfile/index_table_v3.h" 11 #include "net/disk_cache/blockfile/index_table_v3.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 using disk_cache::EntryCell; 14 using disk_cache::EntryCell;
15 using disk_cache::IndexCell; 15 using disk_cache::IndexCell;
16 using disk_cache::IndexTable; 16 using disk_cache::IndexTable;
17 using disk_cache::IndexTableInitData; 17 using disk_cache::IndexTableInitData;
18 18
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // |num_entries| is the capacity of the main table. The extra table is half 54 // |num_entries| is the capacity of the main table. The extra table is half
55 // the size of the main table. 55 // the size of the main table.
56 explicit TestCacheTables(int num_entries); 56 explicit TestCacheTables(int num_entries);
57 ~TestCacheTables() {} 57 ~TestCacheTables() {}
58 58
59 void GetInitData(IndexTableInitData* result); 59 void GetInitData(IndexTableInitData* result);
60 void CopyFrom(const TestCacheTables& other); 60 void CopyFrom(const TestCacheTables& other);
61 base::Time start_time() const { return start_time_; } 61 base::Time start_time() const { return start_time_; }
62 62
63 private: 63 private:
64 scoped_ptr<uint64[]> main_bitmap_; 64 scoped_ptr<uint64_t[]> main_bitmap_;
65 scoped_ptr<disk_cache::IndexBucket[]> main_table_; 65 scoped_ptr<disk_cache::IndexBucket[]> main_table_;
66 scoped_ptr<disk_cache::IndexBucket[]> extra_table_; 66 scoped_ptr<disk_cache::IndexBucket[]> extra_table_;
67 base::Time start_time_; 67 base::Time start_time_;
68 int num_bitmap_bytes_; 68 int num_bitmap_bytes_;
69 69
70 DISALLOW_COPY_AND_ASSIGN(TestCacheTables); 70 DISALLOW_COPY_AND_ASSIGN(TestCacheTables);
71 }; 71 };
72 72
73 TestCacheTables::TestCacheTables(int num_entries) { 73 TestCacheTables::TestCacheTables(int num_entries) {
74 DCHECK_GE(num_entries, 1024); 74 DCHECK_GE(num_entries, 1024);
75 DCHECK_EQ(num_entries, num_entries / 1024 * 1024); 75 DCHECK_EQ(num_entries, num_entries / 1024 * 1024);
76 main_table_.reset(new disk_cache::IndexBucket[num_entries]); 76 main_table_.reset(new disk_cache::IndexBucket[num_entries]);
77 extra_table_.reset(new disk_cache::IndexBucket[num_entries / 2]); 77 extra_table_.reset(new disk_cache::IndexBucket[num_entries / 2]);
78 memset(main_table_.get(), 0, num_entries * sizeof(*main_table_.get())); 78 memset(main_table_.get(), 0, num_entries * sizeof(*main_table_.get()));
79 memset(extra_table_.get(), 0, num_entries / 2 * sizeof(*extra_table_.get())); 79 memset(extra_table_.get(), 0, num_entries / 2 * sizeof(*extra_table_.get()));
80 80
81 // We allow IndexBitmap smaller than a page because the code should not really 81 // We allow IndexBitmap smaller than a page because the code should not really
82 // depend on that. 82 // depend on that.
83 num_bitmap_bytes_ = (num_entries + num_entries / 2) / 8; 83 num_bitmap_bytes_ = (num_entries + num_entries / 2) / 8;
84 size_t required_size = sizeof(disk_cache::IndexHeaderV3) + num_bitmap_bytes_; 84 size_t required_size = sizeof(disk_cache::IndexHeaderV3) + num_bitmap_bytes_;
85 main_bitmap_.reset(new uint64[required_size / sizeof(uint64)]); 85 main_bitmap_.reset(new uint64_t[required_size / sizeof(uint64_t)]);
86 memset(main_bitmap_.get(), 0, required_size); 86 memset(main_bitmap_.get(), 0, required_size);
87 87
88 disk_cache::IndexHeaderV3* header = 88 disk_cache::IndexHeaderV3* header =
89 reinterpret_cast<disk_cache::IndexHeaderV3*>(main_bitmap_.get()); 89 reinterpret_cast<disk_cache::IndexHeaderV3*>(main_bitmap_.get());
90 90
91 header->magic = disk_cache::kIndexMagicV3; 91 header->magic = disk_cache::kIndexMagicV3;
92 header->version = disk_cache::kVersion3; 92 header->version = disk_cache::kVersion3;
93 header->table_len = num_entries + num_entries / 2; 93 header->table_len = num_entries + num_entries / 2;
94 header->max_bucket = num_entries / 4 - 1; 94 header->max_bucket = num_entries / 4 - 1;
95 95
(...skipping 10 matching lines...) Expand all
106 result->index_bitmap = 106 result->index_bitmap =
107 reinterpret_cast<disk_cache::IndexBitmap*>(main_bitmap_.get()); 107 reinterpret_cast<disk_cache::IndexBitmap*>(main_bitmap_.get());
108 108
109 result->main_table = main_table_.get(); 109 result->main_table = main_table_.get();
110 result->extra_table = extra_table_.get(); 110 result->extra_table = extra_table_.get();
111 111
112 result->backup_header.reset(new disk_cache::IndexHeaderV3); 112 result->backup_header.reset(new disk_cache::IndexHeaderV3);
113 memcpy(result->backup_header.get(), result->index_bitmap, 113 memcpy(result->backup_header.get(), result->index_bitmap,
114 sizeof(result->index_bitmap->header)); 114 sizeof(result->index_bitmap->header));
115 115
116 result->backup_bitmap.reset(new uint32[num_bitmap_bytes_ / sizeof(uint32)]); 116 result->backup_bitmap.reset(
117 new uint32_t[num_bitmap_bytes_ / sizeof(uint32_t)]);
117 memcpy(result->backup_bitmap.get(), result->index_bitmap->bitmap, 118 memcpy(result->backup_bitmap.get(), result->index_bitmap->bitmap,
118 num_bitmap_bytes_); 119 num_bitmap_bytes_);
119 } 120 }
120 121
121 void TestCacheTables::CopyFrom(const TestCacheTables& other) { 122 void TestCacheTables::CopyFrom(const TestCacheTables& other) {
122 disk_cache::IndexBitmap* this_bitmap = 123 disk_cache::IndexBitmap* this_bitmap =
123 reinterpret_cast<disk_cache::IndexBitmap*>(main_bitmap_.get()); 124 reinterpret_cast<disk_cache::IndexBitmap*>(main_bitmap_.get());
124 disk_cache::IndexBitmap* other_bitmap = 125 disk_cache::IndexBitmap* other_bitmap =
125 reinterpret_cast<disk_cache::IndexBitmap*>(other.main_bitmap_.get()); 126 reinterpret_cast<disk_cache::IndexBitmap*>(other.main_bitmap_.get());
126 127
(...skipping 14 matching lines...) Expand all
141 this_bitmap->header.max_bucket = other_bitmap->header.max_bucket; 142 this_bitmap->header.max_bucket = other_bitmap->header.max_bucket;
142 this_bitmap->header.create_time = other_bitmap->header.create_time; 143 this_bitmap->header.create_time = other_bitmap->header.create_time;
143 this_bitmap->header.base_time = other_bitmap->header.base_time; 144 this_bitmap->header.base_time = other_bitmap->header.base_time;
144 this_bitmap->header.flags = other_bitmap->header.flags; 145 this_bitmap->header.flags = other_bitmap->header.flags;
145 start_time_ = other.start_time_; 146 start_time_ = other.start_time_;
146 } 147 }
147 148
148 } // namespace 149 } // namespace
149 150
150 TEST(DiskCacheIndexTable, EntryCell) { 151 TEST(DiskCacheIndexTable, EntryCell) {
151 uint32 hash = 0x55aa6699; 152 uint32_t hash = 0x55aa6699;
152 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, 0x4531); 153 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, 0x4531);
153 bool small_table = true; 154 bool small_table = true;
154 int cell_num = 88; 155 int cell_num = 88;
155 int reuse = 6; 156 int reuse = 6;
156 int timestamp = 123456; 157 int timestamp = 123456;
157 disk_cache::EntryState state = disk_cache::ENTRY_MODIFIED; 158 disk_cache::EntryState state = disk_cache::ENTRY_MODIFIED;
158 disk_cache::EntryGroup group = disk_cache::ENTRY_HIGH_USE; 159 disk_cache::EntryGroup group = disk_cache::ENTRY_HIGH_USE;
159 160
160 for (int i = 0; i < 4; i++) { 161 for (int i = 0; i < 4; i++) {
161 SCOPED_TRACE(i); 162 SCOPED_TRACE(i);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 IndexTableInitData init_data; 271 IndexTableInitData init_data;
271 cache.GetInitData(&init_data); 272 cache.GetInitData(&init_data);
272 273
273 IndexTable index(NULL); 274 IndexTable index(NULL);
274 index.Init(&init_data); 275 index.Init(&init_data);
275 276
276 // Write some entries. 277 // Write some entries.
277 disk_cache::CellList entries; 278 disk_cache::CellList entries;
278 for (int i = 0; i < 250; i++) { 279 for (int i = 0; i < 250; i++) {
279 SCOPED_TRACE(i); 280 SCOPED_TRACE(i);
280 uint32 hash = i * i * 1111 + i * 11; 281 uint32_t hash = i * i * 1111 + i * 11;
281 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 13 + 1); 282 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 13 + 1);
282 EntryCell entry = index.CreateEntryCell(hash, addr); 283 EntryCell entry = index.CreateEntryCell(hash, addr);
283 EXPECT_TRUE(entry.IsValid()); 284 EXPECT_TRUE(entry.IsValid());
284 285
285 disk_cache::CellInfo info = { hash, addr }; 286 disk_cache::CellInfo info = { hash, addr };
286 entries.push_back(info); 287 entries.push_back(info);
287 } 288 }
288 289
289 // Read them back. 290 // Read them back.
290 for (size_t i = 0; i < entries.size(); i++) { 291 for (size_t i = 0; i < entries.size(); i++) {
291 SCOPED_TRACE(i); 292 SCOPED_TRACE(i);
292 uint32 hash = entries[i].hash; 293 uint32_t hash = entries[i].hash;
293 disk_cache::Addr addr = entries[i].address; 294 disk_cache::Addr addr = entries[i].address;
294 295
295 disk_cache::EntrySet found_entries = index.LookupEntries(hash); 296 disk_cache::EntrySet found_entries = index.LookupEntries(hash);
296 ASSERT_EQ(1u, found_entries.cells.size()); 297 ASSERT_EQ(1u, found_entries.cells.size());
297 EXPECT_TRUE(found_entries.cells[0].IsValid()); 298 EXPECT_TRUE(found_entries.cells[0].IsValid());
298 EXPECT_EQ(hash, found_entries.cells[0].hash()); 299 EXPECT_EQ(hash, found_entries.cells[0].hash());
299 EXPECT_EQ(addr.value(), found_entries.cells[0].GetAddress().value()); 300 EXPECT_EQ(addr.value(), found_entries.cells[0].GetAddress().value());
300 301
301 EntryCell entry = index.FindEntryCell(hash, addr); 302 EntryCell entry = index.FindEntryCell(hash, addr);
302 EXPECT_TRUE(entry.IsValid()); 303 EXPECT_TRUE(entry.IsValid());
303 EXPECT_EQ(hash, entry.hash()); 304 EXPECT_EQ(hash, entry.hash());
304 EXPECT_EQ(addr.value(), entry.GetAddress().value()); 305 EXPECT_EQ(addr.value(), entry.GetAddress().value());
305 306
306 // Delete the first 100 entries. 307 // Delete the first 100 entries.
307 if (i < 100) 308 if (i < 100)
308 index.SetSate(hash, addr, disk_cache::ENTRY_DELETED); 309 index.SetSate(hash, addr, disk_cache::ENTRY_DELETED);
309 } 310 }
310 311
311 // See what we have now. 312 // See what we have now.
312 for (size_t i = 0; i < entries.size(); i++) { 313 for (size_t i = 0; i < entries.size(); i++) {
313 SCOPED_TRACE(i); 314 SCOPED_TRACE(i);
314 uint32 hash = entries[i].hash; 315 uint32_t hash = entries[i].hash;
315 disk_cache::Addr addr = entries[i].address; 316 disk_cache::Addr addr = entries[i].address;
316 317
317 disk_cache::EntrySet found_entries = index.LookupEntries(hash); 318 disk_cache::EntrySet found_entries = index.LookupEntries(hash);
318 if (i < 100) { 319 if (i < 100) {
319 EXPECT_EQ(0u, found_entries.cells.size()); 320 EXPECT_EQ(0u, found_entries.cells.size());
320 } else { 321 } else {
321 ASSERT_EQ(1u, found_entries.cells.size()); 322 ASSERT_EQ(1u, found_entries.cells.size());
322 EXPECT_TRUE(found_entries.cells[0].IsValid()); 323 EXPECT_TRUE(found_entries.cells[0].IsValid());
323 EXPECT_EQ(hash, found_entries.cells[0].hash()); 324 EXPECT_EQ(hash, found_entries.cells[0].hash());
324 EXPECT_EQ(addr.value(), found_entries.cells[0].GetAddress().value()); 325 EXPECT_EQ(addr.value(), found_entries.cells[0].GetAddress().value());
325 } 326 }
326 } 327 }
327 } 328 }
328 329
329 // Tests handling of multiple entries with the same hash. 330 // Tests handling of multiple entries with the same hash.
330 TEST(DiskCacheIndexTable, SameHash) { 331 TEST(DiskCacheIndexTable, SameHash) {
331 TestCacheTables cache(1024); 332 TestCacheTables cache(1024);
332 IndexTableInitData init_data; 333 IndexTableInitData init_data;
333 cache.GetInitData(&init_data); 334 cache.GetInitData(&init_data);
334 335
335 IndexTable index(NULL); 336 IndexTable index(NULL);
336 index.Init(&init_data); 337 index.Init(&init_data);
337 338
338 disk_cache::CellList entries; 339 disk_cache::CellList entries;
339 uint32 hash = 0x55aa55bb; 340 uint32_t hash = 0x55aa55bb;
340 for (int i = 0; i < 6; i++) { 341 for (int i = 0; i < 6; i++) {
341 SCOPED_TRACE(i); 342 SCOPED_TRACE(i);
342 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 13 + 1); 343 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 13 + 1);
343 EntryCell entry = index.CreateEntryCell(hash, addr); 344 EntryCell entry = index.CreateEntryCell(hash, addr);
344 EXPECT_TRUE(entry.IsValid()); 345 EXPECT_TRUE(entry.IsValid());
345 346
346 disk_cache::CellInfo info = { hash, addr }; 347 disk_cache::CellInfo info = { hash, addr };
347 entries.push_back(info); 348 entries.push_back(info);
348 } 349 }
349 350
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 470
470 IndexTable index(NULL); 471 IndexTable index(NULL);
471 index.Init(&init_data); 472 index.Init(&init_data);
472 473
473 base::Time time = cache.start_time(); 474 base::Time time = cache.start_time();
474 475
475 // Write some entries. 476 // Write some entries.
476 disk_cache::CellList entries; 477 disk_cache::CellList entries;
477 for (int i = 0; i < 44; i++) { 478 for (int i = 0; i < 44; i++) {
478 SCOPED_TRACE(i); 479 SCOPED_TRACE(i);
479 uint32 hash = i; // The entries will be ordered on the table. 480 uint32_t hash = i; // The entries will be ordered on the table.
480 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 13 + 1); 481 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 13 + 1);
481 if (i < 10 || i == 40) 482 if (i < 10 || i == 40)
482 addr = disk_cache::Addr(disk_cache::BLOCK_EVICTED, 1, 6, i * 13 + 1); 483 addr = disk_cache::Addr(disk_cache::BLOCK_EVICTED, 1, 6, i * 13 + 1);
483 484
484 EntryCell entry = index.CreateEntryCell(hash, addr); 485 EntryCell entry = index.CreateEntryCell(hash, addr);
485 EXPECT_TRUE(entry.IsValid()); 486 EXPECT_TRUE(entry.IsValid());
486 487
487 disk_cache::CellInfo info = { hash, addr }; 488 disk_cache::CellInfo info = { hash, addr };
488 entries.push_back(info); 489 entries.push_back(info);
489 490
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 cache.reset(new TestCacheTables(size)); 588 cache.reset(new TestCacheTables(size));
588 cache.get()->CopyFrom(*old_cache.get()); 589 cache.get()->CopyFrom(*old_cache.get());
589 590
590 IndexTableInitData init_data; 591 IndexTableInitData init_data;
591 cache.get()->GetInitData(&init_data); 592 cache.get()->GetInitData(&init_data);
592 index.Init(&init_data); 593 index.Init(&init_data);
593 594
594 // Write some entries. 595 // Write some entries.
595 for (int i = 0; i < 250; i++, entry_id++) { 596 for (int i = 0; i < 250; i++, entry_id++) {
596 SCOPED_TRACE(entry_id); 597 SCOPED_TRACE(entry_id);
597 uint32 hash = entry_id * i * 321 + entry_id * 13; 598 uint32_t hash = entry_id * i * 321 + entry_id * 13;
598 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, entry_id * 17 + 1); 599 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, entry_id * 17 + 1);
599 EntryCell entry = index.CreateEntryCell(hash, addr); 600 EntryCell entry = index.CreateEntryCell(hash, addr);
600 EXPECT_TRUE(entry.IsValid()); 601 EXPECT_TRUE(entry.IsValid());
601 602
602 disk_cache::CellInfo info = { hash, addr }; 603 disk_cache::CellInfo info = { hash, addr };
603 entries.push_back(info); 604 entries.push_back(info);
604 } 605 }
605 size *= 2; 606 size *= 2;
606 } 607 }
607 608
(...skipping 13 matching lines...) Expand all
621 scoped_ptr<TestCacheTables> cache(new TestCacheTables(size)); 622 scoped_ptr<TestCacheTables> cache(new TestCacheTables(size));
622 disk_cache::CellList entries; 623 disk_cache::CellList entries;
623 624
624 IndexTableInitData init_data; 625 IndexTableInitData init_data;
625 cache.get()->GetInitData(&init_data); 626 cache.get()->GetInitData(&init_data);
626 index.Init(&init_data); 627 index.Init(&init_data);
627 628
628 // Write some entries. 629 // Write some entries.
629 for (int i = 0; i < 8; i++) { 630 for (int i = 0; i < 8; i++) {
630 SCOPED_TRACE(i); 631 SCOPED_TRACE(i);
631 uint32 hash = i * 256; 632 uint32_t hash = i * 256;
632 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 7 + 1); 633 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 7 + 1);
633 EntryCell entry = index.CreateEntryCell(hash, addr); 634 EntryCell entry = index.CreateEntryCell(hash, addr);
634 EXPECT_TRUE(entry.IsValid()); 635 EXPECT_TRUE(entry.IsValid());
635 636
636 disk_cache::CellInfo info = { hash, addr }; 637 disk_cache::CellInfo info = { hash, addr };
637 entries.push_back(info); 638 entries.push_back(info);
638 } 639 }
639 640
640 // Double the size. 641 // Double the size.
641 scoped_ptr<TestCacheTables> old_cache(cache.Pass()); 642 scoped_ptr<TestCacheTables> old_cache(cache.Pass());
642 cache.reset(new TestCacheTables(size * 2)); 643 cache.reset(new TestCacheTables(size * 2));
643 cache.get()->CopyFrom(*old_cache.get()); 644 cache.get()->CopyFrom(*old_cache.get());
644 645
645 cache.get()->GetInitData(&init_data); 646 cache.get()->GetInitData(&init_data);
646 index.Init(&init_data); 647 index.Init(&init_data);
647 648
648 // Write more entries, starting with the upper half of the table. 649 // Write more entries, starting with the upper half of the table.
649 for (int i = 9; i < 11; i++) { 650 for (int i = 9; i < 11; i++) {
650 SCOPED_TRACE(i); 651 SCOPED_TRACE(i);
651 uint32 hash = i * 256; 652 uint32_t hash = i * 256;
652 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 7 + 1); 653 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 7 + 1);
653 EntryCell entry = index.CreateEntryCell(hash, addr); 654 EntryCell entry = index.CreateEntryCell(hash, addr);
654 EXPECT_TRUE(entry.IsValid()); 655 EXPECT_TRUE(entry.IsValid());
655 656
656 disk_cache::CellInfo info = { hash, addr }; 657 disk_cache::CellInfo info = { hash, addr };
657 entries.push_back(info); 658 entries.push_back(info);
658 } 659 }
659 660
660 // Access all the entries. 661 // Access all the entries.
661 for (size_t i = 0; i < entries.size(); i++) { 662 for (size_t i = 0; i < entries.size(); i++) {
(...skipping 10 matching lines...) Expand all
672 IndexTableInitData init_data; 673 IndexTableInitData init_data;
673 cache.GetInitData(&init_data); 674 cache.GetInitData(&init_data);
674 MockIndexBackend backend; 675 MockIndexBackend backend;
675 676
676 IndexTable index(&backend); 677 IndexTable index(&backend);
677 index.Init(&init_data); 678 index.Init(&init_data);
678 679
679 // Write some entries. 680 // Write some entries.
680 for (int i = 0; i < 512; i++) { 681 for (int i = 0; i < 512; i++) {
681 SCOPED_TRACE(i); 682 SCOPED_TRACE(i);
682 uint32 hash = 0; 683 uint32_t hash = 0;
683 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i + 1); 684 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i + 1);
684 EntryCell entry = index.CreateEntryCell(hash, addr); 685 EntryCell entry = index.CreateEntryCell(hash, addr);
685 EXPECT_TRUE(entry.IsValid()); 686 EXPECT_TRUE(entry.IsValid());
686 } 687 }
687 688
688 EXPECT_TRUE(backend.grow_called()); 689 EXPECT_TRUE(backend.grow_called());
689 } 690 }
690 691
691 TEST(DiskCacheIndexTable, SaveIndex) { 692 TEST(DiskCacheIndexTable, SaveIndex) {
692 TestCacheTables cache(1024); 693 TestCacheTables cache(1024);
693 IndexTableInitData init_data; 694 IndexTableInitData init_data;
694 cache.GetInitData(&init_data); 695 cache.GetInitData(&init_data);
695 MockIndexBackend backend; 696 MockIndexBackend backend;
696 697
697 IndexTable index(&backend); 698 IndexTable index(&backend);
698 index.Init(&init_data); 699 index.Init(&init_data);
699 700
700 uint32 hash = 0; 701 uint32_t hash = 0;
701 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, 6); 702 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, 6);
702 EntryCell entry = index.CreateEntryCell(hash, addr); 703 EntryCell entry = index.CreateEntryCell(hash, addr);
703 EXPECT_TRUE(entry.IsValid()); 704 EXPECT_TRUE(entry.IsValid());
704 705
705 index.OnBackupTimer(); 706 index.OnBackupTimer();
706 int expected = (1024 + 512) / 8 + sizeof(disk_cache::IndexHeaderV3); 707 int expected = (1024 + 512) / 8 + sizeof(disk_cache::IndexHeaderV3);
707 EXPECT_EQ(expected, backend.buffer_len()); 708 EXPECT_EQ(expected, backend.buffer_len());
708 } 709 }
OLDNEW
« no previous file with comments | « net/disk_cache/blockfile/index_table_v3.h ('k') | net/disk_cache/blockfile/mapped_file.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698