| OLD | NEW |
| 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/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "net/disk_cache/storage_block.h" | 6 #include "net/disk_cache/storage_block.h" |
| 7 #include "net/disk_cache/storage_block-inl.h" | 7 #include "net/disk_cache/storage_block-inl.h" |
| 8 #include "net/disk_cache/disk_cache_test_base.h" | 8 #include "net/disk_cache/disk_cache_test_base.h" |
| 9 #include "net/disk_cache/disk_cache_test_util.h" | 9 #include "net/disk_cache/disk_cache_test_util.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 TEST_F(DiskCacheTest, StorageBlock_LoadStore) { | 12 TEST_F(DiskCacheTest, StorageBlock_LoadStore) { |
| 13 ScopedTestCache test_cache; | 13 FilePath filename = GetCacheFilePath().AppendASCII("a_test"); |
| 14 FilePath filename = test_cache.path().AppendASCII("a_test"); | |
| 15 | |
| 16 scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); | 14 scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); |
| 17 ASSERT_TRUE(CreateCacheTestFile(filename)); | 15 ASSERT_TRUE(CreateCacheTestFile(filename)); |
| 18 ASSERT_TRUE(file->Init(filename, 8192)); | 16 ASSERT_TRUE(file->Init(filename, 8192)); |
| 19 | 17 |
| 20 disk_cache::CacheEntryBlock entry1(file, disk_cache::Addr(0xa0010001)); | 18 disk_cache::CacheEntryBlock entry1(file, disk_cache::Addr(0xa0010001)); |
| 21 memset(entry1.Data(), 0, sizeof(disk_cache::EntryStore)); | 19 memset(entry1.Data(), 0, sizeof(disk_cache::EntryStore)); |
| 22 entry1.Data()->hash = 0xaa5555aa; | 20 entry1.Data()->hash = 0xaa5555aa; |
| 23 entry1.Data()->rankings_node = 0xa0010002; | 21 entry1.Data()->rankings_node = 0xa0010002; |
| 24 | 22 |
| 25 EXPECT_TRUE(entry1.Store()); | 23 EXPECT_TRUE(entry1.Store()); |
| 26 entry1.Data()->hash = 0x88118811; | 24 entry1.Data()->hash = 0x88118811; |
| 27 entry1.Data()->rankings_node = 0xa0040009; | 25 entry1.Data()->rankings_node = 0xa0040009; |
| 28 | 26 |
| 29 EXPECT_TRUE(entry1.Load()); | 27 EXPECT_TRUE(entry1.Load()); |
| 30 EXPECT_EQ(0xaa5555aa, entry1.Data()->hash); | 28 EXPECT_EQ(0xaa5555aa, entry1.Data()->hash); |
| 31 EXPECT_EQ(0xa0010002, entry1.Data()->rankings_node); | 29 EXPECT_EQ(0xa0010002, entry1.Data()->rankings_node); |
| 32 } | 30 } |
| 33 | 31 |
| 34 TEST_F(DiskCacheTest, StorageBlock_SetData) { | 32 TEST_F(DiskCacheTest, StorageBlock_SetData) { |
| 35 ScopedTestCache test_cache; | 33 FilePath filename = GetCacheFilePath().AppendASCII("a_test"); |
| 36 FilePath filename = test_cache.path().AppendASCII("a_test"); | |
| 37 | |
| 38 scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); | 34 scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); |
| 39 ASSERT_TRUE(CreateCacheTestFile(filename)); | 35 ASSERT_TRUE(CreateCacheTestFile(filename)); |
| 40 ASSERT_TRUE(file->Init(filename, 8192)); | 36 ASSERT_TRUE(file->Init(filename, 8192)); |
| 41 | 37 |
| 42 disk_cache::CacheEntryBlock entry1(file, disk_cache::Addr(0xa0010001)); | 38 disk_cache::CacheEntryBlock entry1(file, disk_cache::Addr(0xa0010001)); |
| 43 entry1.Data()->hash = 0xaa5555aa; | 39 entry1.Data()->hash = 0xaa5555aa; |
| 44 | 40 |
| 45 disk_cache::CacheEntryBlock entry2(file, disk_cache::Addr(0xa0010002)); | 41 disk_cache::CacheEntryBlock entry2(file, disk_cache::Addr(0xa0010002)); |
| 46 EXPECT_TRUE(entry2.Load()); | 42 EXPECT_TRUE(entry2.Load()); |
| 47 EXPECT_TRUE(entry2.Data() != NULL); | 43 EXPECT_TRUE(entry2.Data() != NULL); |
| 48 EXPECT_TRUE(0 == entry2.Data()->hash); | 44 EXPECT_TRUE(0 == entry2.Data()->hash); |
| 49 | 45 |
| 50 EXPECT_TRUE(entry2.Data() != entry1.Data()); | 46 EXPECT_TRUE(entry2.Data() != entry1.Data()); |
| 51 entry2.SetData(entry1.Data()); | 47 entry2.SetData(entry1.Data()); |
| 52 EXPECT_EQ(0xaa5555aa, entry2.Data()->hash); | 48 EXPECT_EQ(0xaa5555aa, entry2.Data()->hash); |
| 53 EXPECT_TRUE(entry2.Data() == entry1.Data()); | 49 EXPECT_TRUE(entry2.Data() == entry1.Data()); |
| 54 } | 50 } |
| 55 | 51 |
| 56 TEST_F(DiskCacheTest, StorageBlock_SetModified) { | 52 TEST_F(DiskCacheTest, StorageBlock_SetModified) { |
| 57 ScopedTestCache test_cache; | 53 FilePath filename = GetCacheFilePath().AppendASCII("a_test"); |
| 58 FilePath filename = test_cache.path().AppendASCII("a_test"); | |
| 59 | |
| 60 scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); | 54 scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); |
| 61 ASSERT_TRUE(CreateCacheTestFile(filename)); | 55 ASSERT_TRUE(CreateCacheTestFile(filename)); |
| 62 ASSERT_TRUE(file->Init(filename, 8192)); | 56 ASSERT_TRUE(file->Init(filename, 8192)); |
| 63 | 57 |
| 64 disk_cache::CacheEntryBlock* entry1 = | 58 disk_cache::CacheEntryBlock* entry1 = |
| 65 new disk_cache::CacheEntryBlock(file, disk_cache::Addr(0xa0010003)); | 59 new disk_cache::CacheEntryBlock(file, disk_cache::Addr(0xa0010003)); |
| 66 EXPECT_TRUE(entry1->Load()); | 60 EXPECT_TRUE(entry1->Load()); |
| 67 EXPECT_TRUE(0 == entry1->Data()->hash); | 61 EXPECT_TRUE(0 == entry1->Data()->hash); |
| 68 entry1->Data()->hash = 0x45687912; | 62 entry1->Data()->hash = 0x45687912; |
| 69 entry1->set_modified(); | 63 entry1->set_modified(); |
| 70 delete entry1; | 64 delete entry1; |
| 71 | 65 |
| 72 disk_cache::CacheEntryBlock entry2(file, disk_cache::Addr(0xa0010003)); | 66 disk_cache::CacheEntryBlock entry2(file, disk_cache::Addr(0xa0010003)); |
| 73 EXPECT_TRUE(entry2.Load()); | 67 EXPECT_TRUE(entry2.Load()); |
| 74 EXPECT_TRUE(0x45687912 == entry2.Data()->hash); | 68 EXPECT_TRUE(0x45687912 == entry2.Data()->hash); |
| 75 } | 69 } |
| OLD | NEW |