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/ref_counted.h" | |
6 #include "base/string_util.h" | |
7 #include "base/threading/thread.h" | |
8 #include "base/threading/thread_restrictions.h" | |
9 #include "net/base/io_buffer.h" | |
10 #include "net/base/net_errors.h" | |
11 #include "net/disk_cache/disk_cache_test_util.h" | |
12 #include "net/disk_cache/flash/flash_cache_test_base.h" | |
13 #include "net/disk_cache/flash/flash_entry_impl.h" | |
14 #include "net/disk_cache/flash/format.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | |
16 | |
17 using net::CompletionCallback; | |
18 | |
19 TEST_F(FlashCacheTest, FlashEntryCreate) { | |
20 base::Thread cache_thread("CacheThread"); | |
21 ASSERT_TRUE(cache_thread.StartWithOptions( | |
22 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | |
23 | |
24 const std::string key = "foo.com"; | |
25 disk_cache::FlashEntryImpl* entry = | |
26 new disk_cache::FlashEntryImpl(key, | |
27 log_store_.get(), | |
28 cache_thread.message_loop_proxy()); | |
29 entry->AddRef(); | |
30 EXPECT_EQ(net::OK, entry->Init(CompletionCallback())); | |
31 EXPECT_EQ(key, entry->GetKey()); | |
32 EXPECT_EQ(0, entry->GetDataSize(0)); | |
33 EXPECT_EQ(0, entry->GetDataSize(1)); | |
34 EXPECT_EQ(0, entry->GetDataSize(2)); | |
35 | |
36 const int kSize1 = 100; | |
37 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize1)); | |
38 CacheTestFillBuffer(buffer1->data(), kSize1, false); | |
39 EXPECT_EQ(0, entry->ReadData(0, 0, buffer1, kSize1, CompletionCallback())); | |
40 base::strlcpy(buffer1->data(), "the data", kSize1); | |
41 EXPECT_EQ(kSize1, entry->WriteData(0, 0, buffer1, kSize1, | |
42 CompletionCallback(), false)); | |
43 memset(buffer1->data(), 0, kSize1); | |
44 EXPECT_EQ(kSize1, entry->ReadData(0, 0, buffer1, kSize1, | |
45 CompletionCallback())); | |
46 EXPECT_STREQ("the data", buffer1->data()); | |
47 entry->Close(); | |
48 } | |
OLD | NEW |