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 TEST_F(FlashCacheTest, FlashEntryCreate) { | |
18 base::Thread cache_thread("CacheThread"); | |
19 ASSERT_TRUE(cache_thread.StartWithOptions( | |
20 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | |
21 | |
22 const std::string key = "foo.com"; | |
23 disk_cache::FlashEntryImpl* entry = | |
24 new disk_cache::FlashEntryImpl(key, | |
25 log_store_.get(), | |
26 cache_thread.message_loop_proxy()); | |
27 entry->AddRef(); | |
rvargas (doing something else)
2013/04/05 18:15:41
why?
agayev
2013/04/05 22:26:45
If I put it inside scoped_refptr, there are 2 Rele
rvargas (doing something else)
2013/04/06 01:25:23
I miss'd this was a direct new, ok.
| |
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())); | |
rvargas (doing something else)
2013/04/05 18:15:41
nit: indent under first arg
agayev
2013/04/05 22:26:45
Done.
| |
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 |