OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/memory/scoped_ptr.h" | |
6 #include "net/base/io_buffer.h" | |
7 #include "net/disk_cache/disk_cache_test_util.h" | |
8 #include "net/disk_cache/flash/cache_entry.h" | |
9 #include "net/disk_cache/flash/flash_cache_test_base.h" | |
10 #include "net/disk_cache/flash/format.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 using disk_cache::CacheEntry; | |
14 | |
15 TEST_F(FlashCacheTest, CacheEntryEmpty) { | |
rvargas (doing something else)
2012/12/05 00:21:01
nit: could you add a one liner stating what this i
agayev
2012/12/05 16:53:19
Done.
| |
16 scoped_ptr<CacheEntry> entry(new CacheEntry(log_structured_store_.get())); | |
17 EXPECT_TRUE(entry->Init()); | |
18 EXPECT_TRUE(entry->Close()); | |
19 | |
20 entry.reset(new CacheEntry(log_structured_store_.get(), entry->id())); | |
21 EXPECT_TRUE(entry->Init()); | |
22 | |
23 for (int i = 0; i < disk_cache::kFlashCacheEntryNumStreams; ++i) { | |
24 EXPECT_EQ(0, entry->GetDataSize(i)); | |
25 EXPECT_EQ(0, entry->ReadData(i, 0, NULL, 1024)); | |
rvargas (doing something else)
2012/12/05 00:21:01
There could be multiple reasons for this to return
agayev
2012/12/05 16:53:19
I want to test that reading from an entry with emp
| |
26 } | |
27 EXPECT_TRUE(entry->Close()); | |
28 } | |
29 | |
30 TEST_F(FlashCacheTest, CacheEntryWriteRead) { | |
31 scoped_ptr<CacheEntry> entry(new CacheEntry(log_structured_store_.get())); | |
32 EXPECT_TRUE(entry->Init()); | |
33 | |
34 int sizes[disk_cache::kFlashCacheEntryNumStreams] = {333, 444, 555, 666}; | |
35 scoped_refptr<net::IOBuffer> buffers[disk_cache::kFlashCacheEntryNumStreams]; | |
36 | |
37 for (int i = 0; i < disk_cache::kFlashCacheEntryNumStreams; ++i) { | |
38 buffers[i] = new net::IOBuffer(sizes[i]); | |
39 CacheTestFillBuffer(buffers[i]->data(), sizes[i], false); | |
40 EXPECT_EQ(sizes[i], entry->WriteData(i, 0, buffers[i], sizes[i])); | |
41 } | |
42 EXPECT_TRUE(entry->Close()); | |
43 | |
44 int32 id = entry->id(); | |
45 entry.reset(new CacheEntry(log_structured_store_.get(), id)); | |
46 EXPECT_TRUE(entry->Init()); | |
47 | |
48 for (int i = 0; i < disk_cache::kFlashCacheEntryNumStreams; ++i) { | |
49 EXPECT_EQ(sizes[i], entry->GetDataSize(i)); | |
50 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(sizes[i])); | |
51 EXPECT_EQ(sizes[i], entry->ReadData(i, 0, buffer, sizes[i])); | |
52 EXPECT_EQ(0, memcmp(buffers[i]->data(), buffer->data(), sizes[i])); | |
53 } | |
54 EXPECT_TRUE(entry->Close()); | |
55 EXPECT_EQ(id, entry->id()); | |
56 } | |
OLD | NEW |