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