Chromium Code Reviews| Index: net/disk_cache/flash/flash_entry_unittest.cc |
| diff --git a/net/disk_cache/flash/flash_entry_unittest.cc b/net/disk_cache/flash/flash_entry_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0ff4bfef9b10d71669338d7b5caa72d2942f4ada |
| --- /dev/null |
| +++ b/net/disk_cache/flash/flash_entry_unittest.cc |
| @@ -0,0 +1,47 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "base/string_util.h" |
| +#include "base/threading/thread.h" |
| +#include "base/threading/thread_restrictions.h" |
| +#include "net/base/io_buffer.h" |
| +#include "net/base/net_errors.h" |
| +#include "net/disk_cache/disk_cache_test_util.h" |
| +#include "net/disk_cache/flash/flash_cache_test_base.h" |
| +#include "net/disk_cache/flash/flash_entry_impl.h" |
| +#include "net/disk_cache/flash/format.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +TEST_F(FlashCacheTest, FlashEntryCreate) { |
| + base::Thread cache_thread("CacheThread"); |
| + ASSERT_TRUE(cache_thread.StartWithOptions( |
| + base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
| + |
| + const std::string key = "foo.com"; |
| + disk_cache::FlashEntryImpl* entry = |
| + new disk_cache::FlashEntryImpl(key, |
| + log_store_.get(), |
| + cache_thread.message_loop_proxy()); |
| + 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.
|
| + EXPECT_EQ(net::OK, entry->Init(net::CompletionCallback())); |
| + EXPECT_EQ(key, entry->GetKey()); |
| + EXPECT_EQ(0, entry->GetDataSize(0)); |
| + EXPECT_EQ(0, entry->GetDataSize(1)); |
| + EXPECT_EQ(0, entry->GetDataSize(2)); |
| + |
| + const int kSize1 = 100; |
| + scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize1)); |
| + CacheTestFillBuffer(buffer1->data(), kSize1, false); |
| + EXPECT_EQ(0, entry->ReadData( |
| + 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.
|
| + base::strlcpy(buffer1->data(), "the data", kSize1); |
| + EXPECT_EQ(kSize1, entry->WriteData( |
| + 0, 0, buffer1, kSize1, net::CompletionCallback(), false)); |
| + memset(buffer1->data(), 0, kSize1); |
| + EXPECT_EQ(kSize1, entry->ReadData( |
| + 0, 0, buffer1, kSize1, net::CompletionCallback())); |
| + EXPECT_STREQ("the data", buffer1->data()); |
| + entry->Close(); |
| +} |