| OLD | NEW |
| 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" |
| 6 |
| 5 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> |
| 6 | 9 |
| 7 #include "base/logging.h" | 10 #include "base/logging.h" |
| 8 #include "base/macros.h" | 11 #include "base/macros.h" |
| 9 #include "net/disk_cache/blockfile/addr.h" | 12 #include "net/disk_cache/blockfile/addr.h" |
| 10 #include "net/disk_cache/blockfile/disk_format_v3.h" | 13 #include "net/disk_cache/blockfile/disk_format_v3.h" |
| 11 #include "net/disk_cache/blockfile/index_table_v3.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 15 |
| 14 using disk_cache::EntryCell; | 16 using disk_cache::EntryCell; |
| 15 using disk_cache::IndexCell; | 17 using disk_cache::IndexCell; |
| 16 using disk_cache::IndexTable; | 18 using disk_cache::IndexTable; |
| 17 using disk_cache::IndexTableInitData; | 19 using disk_cache::IndexTableInitData; |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 21 int GetChecksum(const IndexCell& source) { | 23 int GetChecksum(const IndexCell& source) { |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 // Tests doubling of the table. | 579 // Tests doubling of the table. |
| 578 TEST(DiskCacheIndexTable, Doubling) { | 580 TEST(DiskCacheIndexTable, Doubling) { |
| 579 IndexTable index(NULL); | 581 IndexTable index(NULL); |
| 580 int size = 1024; | 582 int size = 1024; |
| 581 scoped_ptr<TestCacheTables> cache(new TestCacheTables(size)); | 583 scoped_ptr<TestCacheTables> cache(new TestCacheTables(size)); |
| 582 int entry_id = 0; | 584 int entry_id = 0; |
| 583 disk_cache::CellList entries; | 585 disk_cache::CellList entries; |
| 584 | 586 |
| 585 // Go from 1024 to 256k cells. | 587 // Go from 1024 to 256k cells. |
| 586 for (int resizes = 0; resizes <= 8; resizes++) { | 588 for (int resizes = 0; resizes <= 8; resizes++) { |
| 587 scoped_ptr<TestCacheTables> old_cache(cache.Pass()); | 589 scoped_ptr<TestCacheTables> old_cache(std::move(cache)); |
| 588 cache.reset(new TestCacheTables(size)); | 590 cache.reset(new TestCacheTables(size)); |
| 589 cache.get()->CopyFrom(*old_cache.get()); | 591 cache.get()->CopyFrom(*old_cache.get()); |
| 590 | 592 |
| 591 IndexTableInitData init_data; | 593 IndexTableInitData init_data; |
| 592 cache.get()->GetInitData(&init_data); | 594 cache.get()->GetInitData(&init_data); |
| 593 index.Init(&init_data); | 595 index.Init(&init_data); |
| 594 | 596 |
| 595 // Write some entries. | 597 // Write some entries. |
| 596 for (int i = 0; i < 250; i++, entry_id++) { | 598 for (int i = 0; i < 250; i++, entry_id++) { |
| 597 SCOPED_TRACE(entry_id); | 599 SCOPED_TRACE(entry_id); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 uint32_t hash = i * 256; | 634 uint32_t hash = i * 256; |
| 633 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); |
| 634 EntryCell entry = index.CreateEntryCell(hash, addr); | 636 EntryCell entry = index.CreateEntryCell(hash, addr); |
| 635 EXPECT_TRUE(entry.IsValid()); | 637 EXPECT_TRUE(entry.IsValid()); |
| 636 | 638 |
| 637 disk_cache::CellInfo info = { hash, addr }; | 639 disk_cache::CellInfo info = { hash, addr }; |
| 638 entries.push_back(info); | 640 entries.push_back(info); |
| 639 } | 641 } |
| 640 | 642 |
| 641 // Double the size. | 643 // Double the size. |
| 642 scoped_ptr<TestCacheTables> old_cache(cache.Pass()); | 644 scoped_ptr<TestCacheTables> old_cache(std::move(cache)); |
| 643 cache.reset(new TestCacheTables(size * 2)); | 645 cache.reset(new TestCacheTables(size * 2)); |
| 644 cache.get()->CopyFrom(*old_cache.get()); | 646 cache.get()->CopyFrom(*old_cache.get()); |
| 645 | 647 |
| 646 cache.get()->GetInitData(&init_data); | 648 cache.get()->GetInitData(&init_data); |
| 647 index.Init(&init_data); | 649 index.Init(&init_data); |
| 648 | 650 |
| 649 // Write more entries, starting with the upper half of the table. | 651 // Write more entries, starting with the upper half of the table. |
| 650 for (int i = 9; i < 11; i++) { | 652 for (int i = 9; i < 11; i++) { |
| 651 SCOPED_TRACE(i); | 653 SCOPED_TRACE(i); |
| 652 uint32_t hash = i * 256; | 654 uint32_t hash = i * 256; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 | 702 |
| 701 uint32_t hash = 0; | 703 uint32_t hash = 0; |
| 702 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, 6); | 704 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, 6); |
| 703 EntryCell entry = index.CreateEntryCell(hash, addr); | 705 EntryCell entry = index.CreateEntryCell(hash, addr); |
| 704 EXPECT_TRUE(entry.IsValid()); | 706 EXPECT_TRUE(entry.IsValid()); |
| 705 | 707 |
| 706 index.OnBackupTimer(); | 708 index.OnBackupTimer(); |
| 707 int expected = (1024 + 512) / 8 + sizeof(disk_cache::IndexHeaderV3); | 709 int expected = (1024 + 512) / 8 + sizeof(disk_cache::IndexHeaderV3); |
| 708 EXPECT_EQ(expected, backend.buffer_len()); | 710 EXPECT_EQ(expected, backend.buffer_len()); |
| 709 } | 711 } |
| OLD | NEW |