OLD | NEW |
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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "net/base/io_buffer.h" | 6 #include "net/base/io_buffer.h" |
7 #include "net/disk_cache/disk_cache_test_util.h" | 7 #include "net/disk_cache/disk_cache_test_util.h" |
8 #include "net/disk_cache/flash/flash_cache_test_base.h" | 8 #include "net/disk_cache/flash/flash_cache_test_base.h" |
9 #include "net/disk_cache/flash/format.h" | 9 #include "net/disk_cache/flash/format.h" |
| 10 #include "net/disk_cache/flash/log_store.h" |
10 #include "net/disk_cache/flash/log_store_entry.h" | 11 #include "net/disk_cache/flash/log_store_entry.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 | 13 |
13 using disk_cache::LogStoreEntry; | 14 using disk_cache::LogStoreEntry; |
14 | 15 |
15 // Tests the behavior of a LogStoreEntry with empty streams. | 16 // Tests the behavior of a LogStoreEntry with empty streams. |
16 TEST_F(FlashCacheTest, LogStoreEntryEmpty) { | 17 TEST_F(FlashCacheTest, LogStoreEntryEmpty) { |
17 scoped_ptr<LogStoreEntry> entry(new LogStoreEntry(log_store_.get())); | 18 disk_cache::LogStore log_store(path_, kStorageSize); |
| 19 ASSERT_TRUE(log_store.Init()); |
| 20 |
| 21 scoped_ptr<LogStoreEntry> entry(new LogStoreEntry(&log_store)); |
18 EXPECT_TRUE(entry->Init()); | 22 EXPECT_TRUE(entry->Init()); |
19 EXPECT_TRUE(entry->Close()); | 23 EXPECT_TRUE(entry->Close()); |
20 | 24 |
21 entry.reset(new LogStoreEntry(log_store_.get(), entry->id())); | 25 entry.reset(new LogStoreEntry(&log_store, entry->id())); |
22 EXPECT_TRUE(entry->Init()); | 26 EXPECT_TRUE(entry->Init()); |
23 | 27 |
24 for (int i = 0; i < disk_cache::kFlashLogStoreEntryNumStreams; ++i) { | 28 for (int i = 0; i < disk_cache::kFlashLogStoreEntryNumStreams; ++i) { |
25 const int kSize = 1024; | 29 const int kSize = 1024; |
26 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); | 30 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); |
27 EXPECT_EQ(0, entry->GetDataSize(i)); | 31 EXPECT_EQ(0, entry->GetDataSize(i)); |
28 EXPECT_EQ(0, entry->ReadData(i, 0, buf, kSize)); | 32 EXPECT_EQ(0, entry->ReadData(i, 0, buf, kSize)); |
29 } | 33 } |
30 EXPECT_TRUE(entry->Close()); | 34 EXPECT_TRUE(entry->Close()); |
| 35 ASSERT_TRUE(log_store.Close()); |
31 } | 36 } |
32 | 37 |
33 TEST_F(FlashCacheTest, LogStoreEntryWriteRead) { | 38 TEST_F(FlashCacheTest, LogStoreEntryWriteRead) { |
34 scoped_ptr<LogStoreEntry> entry(new LogStoreEntry(log_store_.get())); | 39 disk_cache::LogStore log_store(path_, kStorageSize); |
| 40 ASSERT_TRUE(log_store.Init()); |
| 41 |
| 42 scoped_ptr<LogStoreEntry> entry(new LogStoreEntry(&log_store)); |
35 EXPECT_TRUE(entry->Init()); | 43 EXPECT_TRUE(entry->Init()); |
36 | 44 |
37 int sizes[disk_cache::kFlashLogStoreEntryNumStreams] = {333, 444, 555, 666}; | 45 int sizes[disk_cache::kFlashLogStoreEntryNumStreams] = {333, 444, 555, 666}; |
38 scoped_refptr<net::IOBuffer> buffers[ | 46 scoped_refptr<net::IOBuffer> buffers[ |
39 disk_cache::kFlashLogStoreEntryNumStreams]; | 47 disk_cache::kFlashLogStoreEntryNumStreams]; |
40 | 48 |
41 for (int i = 0; i < disk_cache::kFlashLogStoreEntryNumStreams; ++i) { | 49 for (int i = 0; i < disk_cache::kFlashLogStoreEntryNumStreams; ++i) { |
42 buffers[i] = new net::IOBuffer(sizes[i]); | 50 buffers[i] = new net::IOBuffer(sizes[i]); |
43 CacheTestFillBuffer(buffers[i]->data(), sizes[i], false); | 51 CacheTestFillBuffer(buffers[i]->data(), sizes[i], false); |
44 EXPECT_EQ(sizes[i], entry->WriteData(i, 0, buffers[i], sizes[i])); | 52 EXPECT_EQ(sizes[i], entry->WriteData(i, 0, buffers[i], sizes[i])); |
45 } | 53 } |
46 EXPECT_TRUE(entry->Close()); | 54 EXPECT_TRUE(entry->Close()); |
47 | 55 |
48 int32 id = entry->id(); | 56 int32 id = entry->id(); |
49 entry.reset(new LogStoreEntry(log_store_.get(), id)); | 57 entry.reset(new LogStoreEntry(&log_store, id)); |
50 EXPECT_TRUE(entry->Init()); | 58 EXPECT_TRUE(entry->Init()); |
51 | 59 |
52 for (int i = 0; i < disk_cache::kFlashLogStoreEntryNumStreams; ++i) { | 60 for (int i = 0; i < disk_cache::kFlashLogStoreEntryNumStreams; ++i) { |
53 EXPECT_EQ(sizes[i], entry->GetDataSize(i)); | 61 EXPECT_EQ(sizes[i], entry->GetDataSize(i)); |
54 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(sizes[i])); | 62 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(sizes[i])); |
55 EXPECT_EQ(sizes[i], entry->ReadData(i, 0, buffer, sizes[i])); | 63 EXPECT_EQ(sizes[i], entry->ReadData(i, 0, buffer, sizes[i])); |
56 EXPECT_EQ(0, memcmp(buffers[i]->data(), buffer->data(), sizes[i])); | 64 EXPECT_EQ(0, memcmp(buffers[i]->data(), buffer->data(), sizes[i])); |
57 } | 65 } |
58 EXPECT_TRUE(entry->Close()); | 66 EXPECT_TRUE(entry->Close()); |
59 EXPECT_EQ(id, entry->id()); | 67 EXPECT_EQ(id, entry->id()); |
| 68 ASSERT_TRUE(log_store.Close()); |
60 } | 69 } |
OLD | NEW |