summaryrefslogtreecommitdiffstats
path: root/net/disk_cache/entry_unittest.cc
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-23 18:47:25 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-23 18:47:25 +0000
commite1fcf1482fd306b7e404ed037106801840deda76 (patch)
treed5d26cf73f30a254aecca16dfba4f6f5e9bdba4c /net/disk_cache/entry_unittest.cc
parent8e3e066579460f88a19e2e6e091c396f3bd851c3 (diff)
downloadchromium_src-e1fcf1482fd306b7e404ed037106801840deda76.zip
chromium_src-e1fcf1482fd306b7e404ed037106801840deda76.tar.gz
chromium_src-e1fcf1482fd306b7e404ed037106801840deda76.tar.bz2
Disk cache: Extend the internal buffering performed by each entry
to cover external files. We now keep a variable-size buffer and use it even after we know that the data is not going to be stored by a block-file. The backend keeps track of the total memory used by all entries and prevents that value from going over a max value that depends on the total memory available. This CL removes the tests that were checking the synchronous operation of sparse IO because that model is no longer supported by the public API, and this CL would add complexity to them (they fail due to thread safety concerns). BUG=6626 TEST=net_unittests Review URL: http://codereview.chromium.org/3167020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57082 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/entry_unittest.cc')
-rw-r--r--net/disk_cache/entry_unittest.cc751
1 files changed, 456 insertions, 295 deletions
diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc
index 859cabb..1ff033c 100644
--- a/net/disk_cache/entry_unittest.cc
+++ b/net/disk_cache/entry_unittest.cc
@@ -36,27 +36,31 @@ class DiskCacheEntryTest : public DiskCacheTestWithCache {
void InvalidData();
void DoomNormalEntry();
void DoomedEntry();
- void BasicSparseIO(bool async);
- void HugeSparseIO(bool async);
+ void BasicSparseIO();
+ void HugeSparseIO();
void GetAvailableRange();
void CouldBeSparse();
void DoomSparseEntry();
void PartialSparseEntry();
};
+// We need to support synchronous IO even though it is not a supported operation
+// from the point of view of the disk cache's public interface, because we use
+// it internally, not just by a few tests, but as part of the implementation
+// (see sparse_control.cc, for example).
void DiskCacheEntryTest::InternalSyncIO() {
- disk_cache::Entry *entry1 = NULL;
- ASSERT_EQ(net::OK, CreateEntry("the first key", &entry1));
- ASSERT_TRUE(NULL != entry1);
+ disk_cache::Entry* entry = NULL;
+ ASSERT_EQ(net::OK, CreateEntry("the first key", &entry));
+ ASSERT_TRUE(NULL != entry);
const int kSize1 = 10;
scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1);
CacheTestFillBuffer(buffer1->data(), kSize1, false);
- EXPECT_EQ(0, entry1->ReadData(0, 0, buffer1, kSize1, NULL));
+ EXPECT_EQ(0, entry->ReadData(0, 0, buffer1, kSize1, NULL));
base::strlcpy(buffer1->data(), "the data", kSize1);
- EXPECT_EQ(10, entry1->WriteData(0, 0, buffer1, kSize1, NULL, false));
+ EXPECT_EQ(10, entry->WriteData(0, 0, buffer1, kSize1, NULL, false));
memset(buffer1->data(), 0, kSize1);
- EXPECT_EQ(10, entry1->ReadData(0, 0, buffer1, kSize1, NULL));
+ EXPECT_EQ(10, entry->ReadData(0, 0, buffer1, kSize1, NULL));
EXPECT_STREQ("the data", buffer1->data());
const int kSize2 = 5000;
@@ -66,22 +70,26 @@ void DiskCacheEntryTest::InternalSyncIO() {
memset(buffer3->data(), 0, kSize3);
CacheTestFillBuffer(buffer2->data(), kSize2, false);
base::strlcpy(buffer2->data(), "The really big data goes here", kSize2);
- EXPECT_EQ(5000, entry1->WriteData(1, 1500, buffer2, kSize2, NULL, false));
+ EXPECT_EQ(5000, entry->WriteData(1, 1500, buffer2, kSize2, NULL, false));
memset(buffer2->data(), 0, kSize2);
- EXPECT_EQ(4989, entry1->ReadData(1, 1511, buffer2, kSize2, NULL));
+ EXPECT_EQ(4989, entry->ReadData(1, 1511, buffer2, kSize2, NULL));
EXPECT_STREQ("big data goes here", buffer2->data());
- EXPECT_EQ(5000, entry1->ReadData(1, 0, buffer2, kSize2, NULL));
+ EXPECT_EQ(5000, entry->ReadData(1, 0, buffer2, kSize2, NULL));
EXPECT_EQ(0, memcmp(buffer2->data(), buffer3->data(), 1500));
- EXPECT_EQ(1500, entry1->ReadData(1, 5000, buffer2, kSize2, NULL));
+ EXPECT_EQ(1500, entry->ReadData(1, 5000, buffer2, kSize2, NULL));
- EXPECT_EQ(0, entry1->ReadData(1, 6500, buffer2, kSize2, NULL));
- EXPECT_EQ(6500, entry1->ReadData(1, 0, buffer3, kSize3, NULL));
- EXPECT_EQ(8192, entry1->WriteData(1, 0, buffer3, 8192, NULL, false));
- EXPECT_EQ(8192, entry1->ReadData(1, 0, buffer3, kSize3, NULL));
- EXPECT_EQ(8192, entry1->GetDataSize(1));
+ EXPECT_EQ(0, entry->ReadData(1, 6500, buffer2, kSize2, NULL));
+ EXPECT_EQ(6500, entry->ReadData(1, 0, buffer3, kSize3, NULL));
+ EXPECT_EQ(8192, entry->WriteData(1, 0, buffer3, 8192, NULL, false));
+ EXPECT_EQ(8192, entry->ReadData(1, 0, buffer3, kSize3, NULL));
+ EXPECT_EQ(8192, entry->GetDataSize(1));
- entry1->Doom();
- entry1->Close();
+ // We need to delete the memory buffer on this thread.
+ EXPECT_EQ(0, entry->WriteData(0, 0, NULL, 0, NULL, true));
+ EXPECT_EQ(0, entry->WriteData(1, 0, NULL, 0, NULL, true));
+
+ entry->Doom();
+ entry->Close();
FlushQueueForTest();
EXPECT_EQ(0, cache_->GetEntryCount());
}
@@ -99,19 +107,19 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyInternalSyncIO) {
}
void DiskCacheEntryTest::InternalAsyncIO() {
- disk_cache::Entry *entry1 = NULL;
- ASSERT_EQ(net::OK, CreateEntry("the first key", &entry1));
- ASSERT_TRUE(NULL != entry1);
+ disk_cache::Entry* entry = NULL;
+ ASSERT_EQ(net::OK, CreateEntry("the first key", &entry));
+ ASSERT_TRUE(NULL != entry);
// Avoid using internal buffers for the test. We have to write something to
// the entry and close it so that we flush the internal buffer to disk. After
// that, IO operations will be really hitting the disk. We don't care about
// the content, so just extending the entry is enough (all extensions zero-
// fill any holes).
- EXPECT_EQ(0, entry1->WriteData(0, 15 * 1024, NULL, 0, NULL, false));
- EXPECT_EQ(0, entry1->WriteData(1, 15 * 1024, NULL, 0, NULL, false));
- entry1->Close();
- ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1));
+ EXPECT_EQ(0, WriteData(entry, 0, 15 * 1024, NULL, 0, false));
+ EXPECT_EQ(0, WriteData(entry, 1, 15 * 1024, NULL, 0, false));
+ entry->Close();
+ ASSERT_EQ(net::OK, OpenEntry("the first key", &entry));
// Let's verify that each IO goes to the right callback object.
CallbackTest callback1(false);
@@ -143,17 +151,17 @@ void DiskCacheEntryTest::InternalAsyncIO() {
CacheTestFillBuffer(buffer2->data(), kSize2, false);
CacheTestFillBuffer(buffer3->data(), kSize3, false);
- EXPECT_EQ(0, entry1->ReadData(0, 15 * 1024, buffer1, kSize1, &callback1));
+ EXPECT_EQ(0, entry->ReadData(0, 15 * 1024, buffer1, kSize1, &callback1));
base::strlcpy(buffer1->data(), "the data", kSize1);
int expected = 0;
- int ret = entry1->WriteData(0, 0, buffer1, kSize1, &callback2, false);
+ int ret = entry->WriteData(0, 0, buffer1, kSize1, &callback2, false);
EXPECT_TRUE(10 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
memset(buffer2->data(), 0, kSize2);
- ret = entry1->ReadData(0, 0, buffer2, kSize1, &callback3);
+ ret = entry->ReadData(0, 0, buffer2, kSize1, &callback3);
EXPECT_TRUE(10 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
@@ -162,21 +170,21 @@ void DiskCacheEntryTest::InternalAsyncIO() {
EXPECT_STREQ("the data", buffer2->data());
base::strlcpy(buffer2->data(), "The really big data goes here", kSize2);
- ret = entry1->WriteData(1, 1500, buffer2, kSize2, &callback4, true);
+ ret = entry->WriteData(1, 1500, buffer2, kSize2, &callback4, true);
EXPECT_TRUE(5000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
memset(buffer3->data(), 0, kSize3);
- ret = entry1->ReadData(1, 1511, buffer3, kSize2, &callback5);
+ ret = entry->ReadData(1, 1511, buffer3, kSize2, &callback5);
EXPECT_TRUE(4989 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
EXPECT_STREQ("big data goes here", buffer3->data());
- ret = entry1->ReadData(1, 0, buffer2, kSize2, &callback6);
+ ret = entry->ReadData(1, 0, buffer2, kSize2, &callback6);
EXPECT_TRUE(5000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
@@ -185,35 +193,35 @@ void DiskCacheEntryTest::InternalAsyncIO() {
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
EXPECT_EQ(0, memcmp(buffer2->data(), buffer3->data(), 1500));
- ret = entry1->ReadData(1, 5000, buffer2, kSize2, &callback7);
+ ret = entry->ReadData(1, 5000, buffer2, kSize2, &callback7);
EXPECT_TRUE(1500 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
- ret = entry1->ReadData(1, 0, buffer3, kSize3, &callback9);
+ ret = entry->ReadData(1, 0, buffer3, kSize3, &callback9);
EXPECT_TRUE(6500 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
- ret = entry1->WriteData(1, 0, buffer3, 8192, &callback10, true);
+ ret = entry->WriteData(1, 0, buffer3, 8192, &callback10, true);
EXPECT_TRUE(8192 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
- ret = entry1->ReadData(1, 0, buffer3, kSize3, &callback11);
+ ret = entry->ReadData(1, 0, buffer3, kSize3, &callback11);
EXPECT_TRUE(8192 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
- EXPECT_EQ(8192, entry1->GetDataSize(1));
+ EXPECT_EQ(8192, entry->GetDataSize(1));
- ret = entry1->ReadData(0, 0, buffer1, kSize1, &callback12);
+ ret = entry->ReadData(0, 0, buffer1, kSize1, &callback12);
EXPECT_TRUE(10 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
- ret = entry1->ReadData(1, 0, buffer2, kSize2, &callback13);
+ ret = entry->ReadData(1, 0, buffer2, kSize2, &callback13);
EXPECT_TRUE(5000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
@@ -223,8 +231,8 @@ void DiskCacheEntryTest::InternalAsyncIO() {
EXPECT_FALSE(g_cache_tests_error);
EXPECT_EQ(expected, g_cache_tests_received);
- entry1->Doom();
- entry1->Close();
+ entry->Doom();
+ entry->Close();
FlushQueueForTest();
EXPECT_EQ(0, cache_->GetEntryCount());
}
@@ -242,8 +250,8 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyInternalAsyncIO) {
}
void DiskCacheEntryTest::ExternalSyncIO() {
- disk_cache::Entry *entry1;
- ASSERT_EQ(net::OK, CreateEntry("the first key", &entry1));
+ disk_cache::Entry* entry;
+ ASSERT_EQ(net::OK, CreateEntry("the first key", &entry));
const int kSize1 = 17000;
const int kSize2 = 25000;
@@ -252,27 +260,31 @@ void DiskCacheEntryTest::ExternalSyncIO() {
CacheTestFillBuffer(buffer1->data(), kSize1, false);
CacheTestFillBuffer(buffer2->data(), kSize2, false);
base::strlcpy(buffer1->data(), "the data", kSize1);
- EXPECT_EQ(17000, entry1->WriteData(0, 0, buffer1, kSize1, NULL, false));
+ EXPECT_EQ(17000, entry->WriteData(0, 0, buffer1, kSize1, NULL, false));
memset(buffer1->data(), 0, kSize1);
- EXPECT_EQ(17000, entry1->ReadData(0, 0, buffer1, kSize1, NULL));
+ EXPECT_EQ(17000, entry->ReadData(0, 0, buffer1, kSize1, NULL));
EXPECT_STREQ("the data", buffer1->data());
base::strlcpy(buffer2->data(), "The really big data goes here", kSize2);
- EXPECT_EQ(25000, entry1->WriteData(1, 10000, buffer2, kSize2, NULL, false));
+ EXPECT_EQ(25000, entry->WriteData(1, 10000, buffer2, kSize2, NULL, false));
memset(buffer2->data(), 0, kSize2);
- EXPECT_EQ(24989, entry1->ReadData(1, 10011, buffer2, kSize2, NULL));
+ EXPECT_EQ(24989, entry->ReadData(1, 10011, buffer2, kSize2, NULL));
EXPECT_STREQ("big data goes here", buffer2->data());
- EXPECT_EQ(25000, entry1->ReadData(1, 0, buffer2, kSize2, NULL));
+ EXPECT_EQ(25000, entry->ReadData(1, 0, buffer2, kSize2, NULL));
EXPECT_EQ(0, memcmp(buffer2->data(), buffer2->data(), 10000));
- EXPECT_EQ(5000, entry1->ReadData(1, 30000, buffer2, kSize2, NULL));
+ EXPECT_EQ(5000, entry->ReadData(1, 30000, buffer2, kSize2, NULL));
- EXPECT_EQ(0, entry1->ReadData(1, 35000, buffer2, kSize2, NULL));
- EXPECT_EQ(17000, entry1->ReadData(1, 0, buffer1, kSize1, NULL));
- EXPECT_EQ(17000, entry1->WriteData(1, 20000, buffer1, kSize1, NULL, false));
- EXPECT_EQ(37000, entry1->GetDataSize(1));
+ EXPECT_EQ(0, entry->ReadData(1, 35000, buffer2, kSize2, NULL));
+ EXPECT_EQ(17000, entry->ReadData(1, 0, buffer1, kSize1, NULL));
+ EXPECT_EQ(17000, entry->WriteData(1, 20000, buffer1, kSize1, NULL, false));
+ EXPECT_EQ(37000, entry->GetDataSize(1));
- entry1->Doom();
- entry1->Close();
+ // We need to delete the memory buffer on this thread.
+ EXPECT_EQ(0, entry->WriteData(0, 0, NULL, 0, NULL, true));
+ EXPECT_EQ(0, entry->WriteData(1, 0, NULL, 0, NULL, true));
+
+ entry->Doom();
+ entry->Close();
FlushQueueForTest();
EXPECT_EQ(0, cache_->GetEntryCount());
}
@@ -290,8 +302,8 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyExternalSyncIO) {
}
void DiskCacheEntryTest::ExternalAsyncIO() {
- disk_cache::Entry *entry1;
- ASSERT_EQ(net::OK, CreateEntry("the first key", &entry1));
+ disk_cache::Entry* entry;
+ ASSERT_EQ(net::OK, CreateEntry("the first key", &entry));
// Let's verify that each IO goes to the right callback object.
CallbackTest callback1(false);
@@ -320,7 +332,7 @@ void DiskCacheEntryTest::ExternalAsyncIO() {
CacheTestFillBuffer(buffer2->data(), kSize2, false);
CacheTestFillBuffer(buffer3->data(), kSize3, false);
base::strlcpy(buffer1->data(), "the data", kSize1);
- int ret = entry1->WriteData(0, 0, buffer1, kSize1, &callback1, false);
+ int ret = entry->WriteData(0, 0, buffer1, kSize1, &callback1, false);
EXPECT_TRUE(17000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
@@ -328,7 +340,7 @@ void DiskCacheEntryTest::ExternalAsyncIO() {
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
memset(buffer2->data(), 0, kSize1);
- ret = entry1->ReadData(0, 0, buffer2, kSize1, &callback2);
+ ret = entry->ReadData(0, 0, buffer2, kSize1, &callback2);
EXPECT_TRUE(17000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
@@ -337,7 +349,7 @@ void DiskCacheEntryTest::ExternalAsyncIO() {
EXPECT_STREQ("the data", buffer1->data());
base::strlcpy(buffer2->data(), "The really big data goes here", kSize2);
- ret = entry1->WriteData(1, 10000, buffer2, kSize2, &callback3, false);
+ ret = entry->WriteData(1, 10000, buffer2, kSize2, &callback3, false);
EXPECT_TRUE(25000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
@@ -345,43 +357,43 @@ void DiskCacheEntryTest::ExternalAsyncIO() {
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
memset(buffer3->data(), 0, kSize3);
- ret = entry1->ReadData(1, 10011, buffer3, kSize3, &callback4);
+ ret = entry->ReadData(1, 10011, buffer3, kSize3, &callback4);
EXPECT_TRUE(24989 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
EXPECT_STREQ("big data goes here", buffer3->data());
- ret = entry1->ReadData(1, 0, buffer2, kSize2, &callback5);
+ ret = entry->ReadData(1, 0, buffer2, kSize2, &callback5);
EXPECT_TRUE(25000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
EXPECT_EQ(0, memcmp(buffer2->data(), buffer2->data(), 10000));
- ret = entry1->ReadData(1, 30000, buffer2, kSize2, &callback6);
+ ret = entry->ReadData(1, 30000, buffer2, kSize2, &callback6);
EXPECT_TRUE(5000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
- EXPECT_EQ(0, entry1->ReadData(1, 35000, buffer2, kSize2, &callback7));
- ret = entry1->ReadData(1, 0, buffer1, kSize1, &callback8);
+ EXPECT_EQ(0, entry->ReadData(1, 35000, buffer2, kSize2, &callback7));
+ ret = entry->ReadData(1, 0, buffer1, kSize1, &callback8);
EXPECT_TRUE(17000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
- ret = entry1->WriteData(1, 20000, buffer1, kSize1, &callback9, false);
+ ret = entry->WriteData(1, 20000, buffer1, kSize1, &callback9, false);
EXPECT_TRUE(17000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
- EXPECT_EQ(37000, entry1->GetDataSize(1));
+ EXPECT_EQ(37000, entry->GetDataSize(1));
EXPECT_FALSE(g_cache_tests_error);
EXPECT_EQ(expected, g_cache_tests_received);
- entry1->Doom();
- entry1->Close();
+ entry->Doom();
+ entry->Close();
FlushQueueForTest();
EXPECT_EQ(0, cache_->GetEntryCount());
}
@@ -399,7 +411,7 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyExternalAsyncIO) {
}
void DiskCacheEntryTest::StreamAccess() {
- disk_cache::Entry *entry = NULL;
+ disk_cache::Entry* entry = NULL;
ASSERT_EQ(net::OK, CreateEntry("the first key", &entry));
ASSERT_TRUE(NULL != entry);
@@ -410,15 +422,14 @@ void DiskCacheEntryTest::StreamAccess() {
const int kNumStreams = 3;
for (int i = 0; i < kNumStreams; i++) {
CacheTestFillBuffer(buffer1->data(), kBufferSize, false);
- EXPECT_EQ(kBufferSize, entry->WriteData(i, 0, buffer1, kBufferSize, NULL,
- false));
+ EXPECT_EQ(kBufferSize, WriteData(entry, i, 0, buffer1, kBufferSize, false));
memset(buffer2->data(), 0, kBufferSize);
- EXPECT_EQ(kBufferSize, entry->ReadData(i, 0, buffer2, kBufferSize, NULL));
+ EXPECT_EQ(kBufferSize, ReadData(entry, i, 0, buffer2, kBufferSize));
EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kBufferSize));
}
EXPECT_EQ(net::ERR_INVALID_ARGUMENT,
- entry->ReadData(kNumStreams, 0, buffer1, kBufferSize, NULL));
+ ReadData(entry, kNumStreams, 0, buffer1, kBufferSize));
entry->Close();
}
@@ -434,11 +445,11 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyStreamAccess) {
}
void DiskCacheEntryTest::GetKey() {
- std::string key1("the first key");
- disk_cache::Entry *entry1;
- ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
- EXPECT_EQ(key1, entry1->GetKey()) << "short key";
- entry1->Close();
+ std::string key("the first key");
+ disk_cache::Entry* entry;
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
+ EXPECT_EQ(key, entry->GetKey()) << "short key";
+ entry->Close();
int seed = static_cast<int>(Time::Now().ToInternalValue());
srand(seed);
@@ -447,25 +458,25 @@ void DiskCacheEntryTest::GetKey() {
CacheTestFillBuffer(key_buffer, 3000, true);
key_buffer[1000] = '\0';
- key1 = key_buffer;
- ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
- EXPECT_TRUE(key1 == entry1->GetKey()) << "1000 bytes key";
- entry1->Close();
+ key = key_buffer;
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
+ EXPECT_TRUE(key == entry->GetKey()) << "1000 bytes key";
+ entry->Close();
key_buffer[1000] = 'p';
key_buffer[3000] = '\0';
- key1 = key_buffer;
- ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
- EXPECT_TRUE(key1 == entry1->GetKey()) << "medium size key";
- entry1->Close();
+ key = key_buffer;
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
+ EXPECT_TRUE(key == entry->GetKey()) << "medium size key";
+ entry->Close();
CacheTestFillBuffer(key_buffer, sizeof(key_buffer), true);
key_buffer[19999] = '\0';
- key1 = key_buffer;
- ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
- EXPECT_TRUE(key1 == entry1->GetKey()) << "long key";
- entry1->Close();
+ key = key_buffer;
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
+ EXPECT_TRUE(key == entry->GetKey()) << "long key";
+ entry->Close();
}
TEST_F(DiskCacheEntryTest, GetKey) {
@@ -481,8 +492,8 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyGetKey) {
void DiskCacheEntryTest::GrowData() {
std::string key1("the first key");
- disk_cache::Entry *entry1, *entry2;
- ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
+ disk_cache::Entry* entry;
+ ASSERT_EQ(net::OK, CreateEntry(key1, &entry));
const int kSize = 20000;
scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize);
@@ -491,44 +502,58 @@ void DiskCacheEntryTest::GrowData() {
memset(buffer2->data(), 0, kSize);
base::strlcpy(buffer1->data(), "the data", kSize);
- EXPECT_EQ(10, entry1->WriteData(0, 0, buffer1, 10, NULL, false));
- EXPECT_EQ(10, entry1->ReadData(0, 0, buffer2, 10, NULL));
+ EXPECT_EQ(10, WriteData(entry, 0, 0, buffer1, 10, false));
+ EXPECT_EQ(10, ReadData(entry, 0, 0, buffer2, 10));
EXPECT_STREQ("the data", buffer2->data());
- EXPECT_EQ(10, entry1->GetDataSize(0));
+ EXPECT_EQ(10, entry->GetDataSize(0));
- EXPECT_EQ(2000, entry1->WriteData(0, 0, buffer1, 2000, NULL, false));
- EXPECT_EQ(2000, entry1->GetDataSize(0));
- EXPECT_EQ(2000, entry1->ReadData(0, 0, buffer2, 2000, NULL));
+ EXPECT_EQ(2000, WriteData(entry, 0, 0, buffer1, 2000, false));
+ EXPECT_EQ(2000, entry->GetDataSize(0));
+ EXPECT_EQ(2000, ReadData(entry, 0, 0, buffer2, 2000));
EXPECT_TRUE(!memcmp(buffer1->data(), buffer2->data(), 2000));
- EXPECT_EQ(20000, entry1->WriteData(0, 0, buffer1, kSize, NULL, false));
- EXPECT_EQ(20000, entry1->GetDataSize(0));
- EXPECT_EQ(20000, entry1->ReadData(0, 0, buffer2, kSize, NULL));
+ EXPECT_EQ(20000, WriteData(entry, 0, 0, buffer1, kSize, false));
+ EXPECT_EQ(20000, entry->GetDataSize(0));
+ EXPECT_EQ(20000, ReadData(entry, 0, 0, buffer2, kSize));
EXPECT_TRUE(!memcmp(buffer1->data(), buffer2->data(), kSize));
- entry1->Close();
+ entry->Close();
memset(buffer2->data(), 0, kSize);
- ASSERT_EQ(net::OK, CreateEntry("Second key", &entry2));
- EXPECT_EQ(10, entry2->WriteData(0, 0, buffer1, 10, NULL, false));
- EXPECT_EQ(10, entry2->GetDataSize(0));
- entry2->Close();
+ std::string key2("Second key");
+ ASSERT_EQ(net::OK, CreateEntry(key2, &entry));
+ EXPECT_EQ(10, WriteData(entry, 0, 0, buffer1, 10, false));
+ EXPECT_EQ(10, entry->GetDataSize(0));
+ entry->Close();
// Go from an internal address to a bigger block size.
- ASSERT_EQ(net::OK, OpenEntry("Second key", &entry2));
- EXPECT_EQ(2000, entry2->WriteData(0, 0, buffer1, 2000, NULL, false));
- EXPECT_EQ(2000, entry2->GetDataSize(0));
- EXPECT_EQ(2000, entry2->ReadData(0, 0, buffer2, 2000, NULL));
+ ASSERT_EQ(net::OK, OpenEntry(key2, &entry));
+ EXPECT_EQ(2000, WriteData(entry, 0, 0, buffer1, 2000, false));
+ EXPECT_EQ(2000, entry->GetDataSize(0));
+ EXPECT_EQ(2000, ReadData(entry, 0, 0, buffer2, 2000));
EXPECT_TRUE(!memcmp(buffer1->data(), buffer2->data(), 2000));
- entry2->Close();
+ entry->Close();
memset(buffer2->data(), 0, kSize);
// Go from an internal address to an external one.
- ASSERT_EQ(net::OK, OpenEntry("Second key", &entry2));
- EXPECT_EQ(20000, entry2->WriteData(0, 0, buffer1, kSize, NULL, false));
- EXPECT_EQ(20000, entry2->GetDataSize(0));
- EXPECT_EQ(20000, entry2->ReadData(0, 0, buffer2, kSize, NULL));
+ ASSERT_EQ(net::OK, OpenEntry(key2, &entry));
+ EXPECT_EQ(20000, WriteData(entry, 0, 0, buffer1, kSize, false));
+ EXPECT_EQ(20000, entry->GetDataSize(0));
+ EXPECT_EQ(20000, ReadData(entry, 0, 0, buffer2, kSize));
EXPECT_TRUE(!memcmp(buffer1->data(), buffer2->data(), kSize));
- entry2->Close();
+ entry->Close();
+
+ // Double check the size from disk.
+ ASSERT_EQ(net::OK, OpenEntry(key2, &entry));
+ EXPECT_EQ(20000, entry->GetDataSize(0));
+
+ // Now extend the entry without actual data.
+ EXPECT_EQ(0, WriteData(entry, 0, 45500, buffer1, 0, false));
+ entry->Close();
+
+ // And check again from disk.
+ ASSERT_EQ(net::OK, OpenEntry(key2, &entry));
+ EXPECT_EQ(45500, entry->GetDataSize(0));
+ entry->Close();
}
TEST_F(DiskCacheEntryTest, GrowData) {
@@ -543,9 +568,9 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyGrowData) {
}
void DiskCacheEntryTest::TruncateData() {
- std::string key1("the first key");
- disk_cache::Entry *entry1;
- ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
+ std::string key("the first key");
+ disk_cache::Entry* entry;
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
const int kSize1 = 20000;
const int kSize2 = 20000;
@@ -556,50 +581,50 @@ void DiskCacheEntryTest::TruncateData() {
memset(buffer2->data(), 0, kSize2);
// Simple truncation:
- EXPECT_EQ(200, entry1->WriteData(0, 0, buffer1, 200, NULL, false));
- EXPECT_EQ(200, entry1->GetDataSize(0));
- EXPECT_EQ(100, entry1->WriteData(0, 0, buffer1, 100, NULL, false));
- EXPECT_EQ(200, entry1->GetDataSize(0));
- EXPECT_EQ(100, entry1->WriteData(0, 0, buffer1, 100, NULL, true));
- EXPECT_EQ(100, entry1->GetDataSize(0));
- EXPECT_EQ(0, entry1->WriteData(0, 50, buffer1, 0, NULL, true));
- EXPECT_EQ(50, entry1->GetDataSize(0));
- EXPECT_EQ(0, entry1->WriteData(0, 0, buffer1, 0, NULL, true));
- EXPECT_EQ(0, entry1->GetDataSize(0));
- entry1->Close();
- ASSERT_EQ(net::OK, OpenEntry(key1, &entry1));
+ EXPECT_EQ(200, entry->WriteData(0, 0, buffer1, 200, NULL, false));
+ EXPECT_EQ(200, entry->GetDataSize(0));
+ EXPECT_EQ(100, entry->WriteData(0, 0, buffer1, 100, NULL, false));
+ EXPECT_EQ(200, entry->GetDataSize(0));
+ EXPECT_EQ(100, entry->WriteData(0, 0, buffer1, 100, NULL, true));
+ EXPECT_EQ(100, entry->GetDataSize(0));
+ EXPECT_EQ(0, entry->WriteData(0, 50, buffer1, 0, NULL, true));
+ EXPECT_EQ(50, entry->GetDataSize(0));
+ EXPECT_EQ(0, entry->WriteData(0, 0, buffer1, 0, NULL, true));
+ EXPECT_EQ(0, entry->GetDataSize(0));
+ entry->Close();
+ ASSERT_EQ(net::OK, OpenEntry(key, &entry));
// Go to an external file.
- EXPECT_EQ(20000, entry1->WriteData(0, 0, buffer1, 20000, NULL, true));
- EXPECT_EQ(20000, entry1->GetDataSize(0));
- EXPECT_EQ(20000, entry1->ReadData(0, 0, buffer2, 20000, NULL));
+ EXPECT_EQ(20000, entry->WriteData(0, 0, buffer1, 20000, NULL, true));
+ EXPECT_EQ(20000, entry->GetDataSize(0));
+ EXPECT_EQ(20000, entry->ReadData(0, 0, buffer2, 20000, NULL));
EXPECT_TRUE(!memcmp(buffer1->data(), buffer2->data(), 20000));
memset(buffer2->data(), 0, kSize2);
// External file truncation
- EXPECT_EQ(18000, entry1->WriteData(0, 0, buffer1, 18000, NULL, false));
- EXPECT_EQ(20000, entry1->GetDataSize(0));
- EXPECT_EQ(18000, entry1->WriteData(0, 0, buffer1, 18000, NULL, true));
- EXPECT_EQ(18000, entry1->GetDataSize(0));
- EXPECT_EQ(0, entry1->WriteData(0, 17500, buffer1, 0, NULL, true));
- EXPECT_EQ(17500, entry1->GetDataSize(0));
+ EXPECT_EQ(18000, entry->WriteData(0, 0, buffer1, 18000, NULL, false));
+ EXPECT_EQ(20000, entry->GetDataSize(0));
+ EXPECT_EQ(18000, entry->WriteData(0, 0, buffer1, 18000, NULL, true));
+ EXPECT_EQ(18000, entry->GetDataSize(0));
+ EXPECT_EQ(0, entry->WriteData(0, 17500, buffer1, 0, NULL, true));
+ EXPECT_EQ(17500, entry->GetDataSize(0));
// And back to an internal block.
- EXPECT_EQ(600, entry1->WriteData(0, 1000, buffer1, 600, NULL, true));
- EXPECT_EQ(1600, entry1->GetDataSize(0));
- EXPECT_EQ(600, entry1->ReadData(0, 1000, buffer2, 600, NULL));
+ EXPECT_EQ(600, entry->WriteData(0, 1000, buffer1, 600, NULL, true));
+ EXPECT_EQ(1600, entry->GetDataSize(0));
+ EXPECT_EQ(600, entry->ReadData(0, 1000, buffer2, 600, NULL));
EXPECT_TRUE(!memcmp(buffer1->data(), buffer2->data(), 600));
- EXPECT_EQ(1000, entry1->ReadData(0, 0, buffer2, 1000, NULL));
+ EXPECT_EQ(1000, entry->ReadData(0, 0, buffer2, 1000, NULL));
EXPECT_TRUE(!memcmp(buffer1->data(), buffer2->data(), 1000)) <<
"Preserves previous data";
// Go from external file to zero length.
- EXPECT_EQ(20000, entry1->WriteData(0, 0, buffer1, 20000, NULL, true));
- EXPECT_EQ(20000, entry1->GetDataSize(0));
- EXPECT_EQ(0, entry1->WriteData(0, 0, buffer1, 0, NULL, true));
- EXPECT_EQ(0, entry1->GetDataSize(0));
+ EXPECT_EQ(20000, entry->WriteData(0, 0, buffer1, 20000, NULL, true));
+ EXPECT_EQ(20000, entry->GetDataSize(0));
+ EXPECT_EQ(0, entry->WriteData(0, 0, buffer1, 0, NULL, true));
+ EXPECT_EQ(0, entry->GetDataSize(0));
- entry1->Close();
+ entry->Close();
}
TEST_F(DiskCacheEntryTest, TruncateData) {
@@ -619,19 +644,41 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyTruncateData) {
}
void DiskCacheEntryTest::ZeroLengthIO() {
- std::string key1("the first key");
- disk_cache::Entry *entry1;
- ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
+ std::string key("the first key");
+ disk_cache::Entry* entry;
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
- EXPECT_EQ(0, entry1->ReadData(0, 0, NULL, 0, NULL));
- EXPECT_EQ(0, entry1->WriteData(0, 0, NULL, 0, NULL, false));
+ EXPECT_EQ(0, ReadData(entry, 0, 0, NULL, 0));
+ EXPECT_EQ(0, WriteData(entry, 0, 0, NULL, 0, false));
// This write should extend the entry.
- EXPECT_EQ(0, entry1->WriteData(0, 1000, NULL, 0, NULL, false));
- EXPECT_EQ(0, entry1->ReadData(0, 500, NULL, 0, NULL));
- EXPECT_EQ(0, entry1->ReadData(0, 2000, NULL, 0, NULL));
- EXPECT_EQ(1000, entry1->GetDataSize(0));
- entry1->Close();
+ EXPECT_EQ(0, WriteData(entry, 0, 1000, NULL, 0, false));
+ EXPECT_EQ(0, ReadData(entry, 0, 500, NULL, 0));
+ EXPECT_EQ(0, ReadData(entry, 0, 2000, NULL, 0));
+ EXPECT_EQ(1000, entry->GetDataSize(0));
+
+ EXPECT_EQ(0, WriteData(entry, 0, 100000, NULL, 0, true));
+ EXPECT_EQ(0, ReadData(entry, 0, 50000, NULL, 0));
+ EXPECT_EQ(100000, entry->GetDataSize(0));
+
+ // Lets verify the actual content.
+ const int kSize = 20;
+ const char zeros[kSize] = {};
+ scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize);
+
+ CacheTestFillBuffer(buffer->data(), kSize, false);
+ EXPECT_EQ(kSize, ReadData(entry, 0, 500, buffer, kSize));
+ EXPECT_TRUE(!memcmp(buffer->data(), zeros, kSize));
+
+ CacheTestFillBuffer(buffer->data(), kSize, false);
+ EXPECT_EQ(kSize, ReadData(entry, 0, 5000, buffer, kSize));
+ EXPECT_TRUE(!memcmp(buffer->data(), zeros, kSize));
+
+ CacheTestFillBuffer(buffer->data(), kSize, false);
+ EXPECT_EQ(kSize, ReadData(entry, 0, 50000, buffer, kSize));
+ EXPECT_TRUE(!memcmp(buffer->data(), zeros, kSize));
+
+ entry->Close();
}
TEST_F(DiskCacheEntryTest, ZeroLengthIO) {
@@ -645,11 +692,155 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyZeroLengthIO) {
ZeroLengthIO();
}
+// Tests that we handle the content correctly when buffering.
+TEST_F(DiskCacheEntryTest, Buffering) {
+ InitCache();
+ std::string key("the first key");
+ disk_cache::Entry* entry;
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
+
+ const int kSize = 200;
+ scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize);
+ scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize);
+ CacheTestFillBuffer(buffer1->data(), kSize, true);
+ CacheTestFillBuffer(buffer2->data(), kSize, true);
+
+ EXPECT_EQ(kSize, WriteData(entry, 1, 0, buffer1, kSize, false));
+ entry->Close();
+
+ // Write a little more and read what we wrote before.
+ ASSERT_EQ(net::OK, OpenEntry(key, &entry));
+ EXPECT_EQ(kSize, WriteData(entry, 1, 5000, buffer1, kSize, false));
+ EXPECT_EQ(kSize, ReadData(entry, 1, 0, buffer2, kSize));
+ EXPECT_TRUE(!memcmp(buffer2->data(), buffer1->data(), kSize));
+
+ // Now go to an external file.
+ EXPECT_EQ(kSize, WriteData(entry, 1, 18000, buffer1, kSize, false));
+ entry->Close();
+
+ // Write something else and verify old data.
+ ASSERT_EQ(net::OK, OpenEntry(key, &entry));
+ EXPECT_EQ(kSize, WriteData(entry, 1, 10000, buffer1, kSize, false));
+ CacheTestFillBuffer(buffer2->data(), kSize, true);
+ EXPECT_EQ(kSize, ReadData(entry, 1, 5000, buffer2, kSize));
+ EXPECT_TRUE(!memcmp(buffer2->data(), buffer1->data(), kSize));
+ CacheTestFillBuffer(buffer2->data(), kSize, true);
+ EXPECT_EQ(kSize, ReadData(entry, 1, 0, buffer2, kSize));
+ EXPECT_TRUE(!memcmp(buffer2->data(), buffer1->data(), kSize));
+ CacheTestFillBuffer(buffer2->data(), kSize, true);
+ EXPECT_EQ(kSize, ReadData(entry, 1, 18000, buffer2, kSize));
+ EXPECT_TRUE(!memcmp(buffer2->data(), buffer1->data(), kSize));
+
+ // Extend the file some more.
+ EXPECT_EQ(kSize, WriteData(entry, 1, 23000, buffer1, kSize, false));
+ entry->Close();
+
+ // And now make sure that we can deal with data in both places (ram/disk).
+ ASSERT_EQ(net::OK, OpenEntry(key, &entry));
+ EXPECT_EQ(kSize, WriteData(entry, 1, 17000, buffer1, kSize, false));
+
+ // We should not overwrite the data at 18000 with this.
+ EXPECT_EQ(kSize, WriteData(entry, 1, 19000, buffer1, kSize, false));
+ CacheTestFillBuffer(buffer2->data(), kSize, true);
+ EXPECT_EQ(kSize, ReadData(entry, 1, 18000, buffer2, kSize));
+ EXPECT_TRUE(!memcmp(buffer2->data(), buffer1->data(), kSize));
+ CacheTestFillBuffer(buffer2->data(), kSize, true);
+ EXPECT_EQ(kSize, ReadData(entry, 1, 17000, buffer2, kSize));
+ EXPECT_TRUE(!memcmp(buffer2->data(), buffer1->data(), kSize));
+
+ EXPECT_EQ(kSize, WriteData(entry, 1, 22900, buffer1, kSize, false));
+ CacheTestFillBuffer(buffer2->data(), kSize, true);
+ EXPECT_EQ(100, ReadData(entry, 1, 23000, buffer2, kSize));
+ EXPECT_TRUE(!memcmp(buffer2->data(), buffer1->data() + 100, 100));
+
+ CacheTestFillBuffer(buffer2->data(), kSize, true);
+ EXPECT_EQ(100, ReadData(entry, 1, 23100, buffer2, kSize));
+ EXPECT_TRUE(!memcmp(buffer2->data(), buffer1->data() + 100, 100));
+
+ entry->Close();
+}
+
+// Some extra tests to make sure that buffering works properly when changing
+// the entry size.
+TEST_F(DiskCacheEntryTest, SizeChanges) {
+ InitCache();
+ std::string key("the first key");
+ disk_cache::Entry* entry;
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
+
+ const int kSize = 200;
+ const char zeros[kSize] = {};
+ scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize);
+ scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize);
+ CacheTestFillBuffer(buffer1->data(), kSize, true);
+ CacheTestFillBuffer(buffer2->data(), kSize, true);
+
+ EXPECT_EQ(kSize, WriteData(entry, 1, 0, buffer1, kSize, true));
+ EXPECT_EQ(kSize, WriteData(entry, 1, 17000, buffer1, kSize, true));
+ EXPECT_EQ(kSize, WriteData(entry, 1, 23000, buffer1, kSize, true));
+ entry->Close();
+
+ // Extend the file and read between the old size and the new write.
+ ASSERT_EQ(net::OK, OpenEntry(key, &entry));
+ EXPECT_EQ(23000 + kSize, entry->GetDataSize(1));
+ EXPECT_EQ(kSize, WriteData(entry, 1, 25000, buffer1, kSize, true));
+ EXPECT_EQ(25000 + kSize, entry->GetDataSize(1));
+ EXPECT_EQ(kSize, ReadData(entry, 1, 24000, buffer2, kSize));
+ EXPECT_TRUE(!memcmp(buffer2->data(), zeros, kSize));
+
+ // Read at the end of the old file size.
+ EXPECT_EQ(35, ReadData(entry, 1, 23000 + kSize - 35, buffer2, kSize));
+ EXPECT_TRUE(!memcmp(buffer2->data(), buffer1->data() + kSize - 35, 35));
+
+ // Read slightly before the last write.
+ CacheTestFillBuffer(buffer2->data(), kSize, true);
+ EXPECT_EQ(kSize, ReadData(entry, 1, 24900, buffer2, kSize));
+ EXPECT_TRUE(!memcmp(buffer2->data(), zeros, 100));
+ EXPECT_TRUE(!memcmp(buffer2->data() + 100, buffer1->data(), kSize - 100));
+
+ // Extend the entry a little more.
+ EXPECT_EQ(kSize, WriteData(entry, 1, 26000, buffer1, kSize, true));
+ EXPECT_EQ(26000 + kSize, entry->GetDataSize(1));
+ CacheTestFillBuffer(buffer2->data(), kSize, true);
+ EXPECT_EQ(kSize, ReadData(entry, 1, 25900, buffer2, kSize));
+ EXPECT_TRUE(!memcmp(buffer2->data(), zeros, 100));
+ EXPECT_TRUE(!memcmp(buffer2->data() + 100, buffer1->data(), kSize - 100));
+
+ // And now reduce the size.
+ EXPECT_EQ(kSize, WriteData(entry, 1, 25000, buffer1, kSize, true));
+ EXPECT_EQ(25000 + kSize, entry->GetDataSize(1));
+ EXPECT_EQ(28, ReadData(entry, 1, 25000 + kSize - 28, buffer2, kSize));
+ EXPECT_TRUE(!memcmp(buffer2->data(), buffer1->data() + kSize - 28, 28));
+
+ // Reduce the size with a buffer that is not extending the size.
+ EXPECT_EQ(kSize, WriteData(entry, 1, 24000, buffer1, kSize, false));
+ EXPECT_EQ(25000 + kSize, entry->GetDataSize(1));
+ EXPECT_EQ(kSize, WriteData(entry, 1, 24500, buffer1, kSize, true));
+ EXPECT_EQ(24500 + kSize, entry->GetDataSize(1));
+ EXPECT_EQ(kSize, ReadData(entry, 1, 23900, buffer2, kSize));
+ EXPECT_TRUE(!memcmp(buffer2->data(), zeros, 100));
+ EXPECT_TRUE(!memcmp(buffer2->data() + 100, buffer1->data(), kSize - 100));
+
+ // And now reduce the size below the old size.
+ EXPECT_EQ(kSize, WriteData(entry, 1, 19000, buffer1, kSize, true));
+ EXPECT_EQ(19000 + kSize, entry->GetDataSize(1));
+ EXPECT_EQ(kSize, ReadData(entry, 1, 18900, buffer2, kSize));
+ EXPECT_TRUE(!memcmp(buffer2->data(), zeros, 100));
+ EXPECT_TRUE(!memcmp(buffer2->data() + 100, buffer1->data(), kSize - 100));
+
+ // Verify that the actual file is truncated.
+ entry->Close();
+ ASSERT_EQ(net::OK, OpenEntry(key, &entry));
+ EXPECT_EQ(19000 + kSize, entry->GetDataSize(1));
+
+ entry->Close();
+}
+
// Write more than the total cache capacity but to a single entry. |size| is the
// amount of bytes to write each time.
void DiskCacheEntryTest::ReuseEntry(int size) {
std::string key1("the first key");
- disk_cache::Entry *entry;
+ disk_cache::Entry* entry;
ASSERT_EQ(net::OK, CreateEntry(key1, &entry));
entry->Close();
@@ -660,8 +851,8 @@ void DiskCacheEntryTest::ReuseEntry(int size) {
CacheTestFillBuffer(buffer->data(), size, false);
for (int i = 0; i < 15; i++) {
- EXPECT_EQ(0, entry->WriteData(0, 0, buffer, 0, NULL, true));
- EXPECT_EQ(size, entry->WriteData(0, 0, buffer, size, NULL, false));
+ EXPECT_EQ(0, WriteData(entry, 0, 0, buffer, 0, true));
+ EXPECT_EQ(size, WriteData(entry, 0, 0, buffer, size, false));
entry->Close();
ASSERT_EQ(net::OK, OpenEntry(key2, &entry));
}
@@ -703,9 +894,9 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyReuseInternalEntry) {
// Reading somewhere that was not written should return zeros.
void DiskCacheEntryTest::InvalidData() {
- std::string key1("the first key");
- disk_cache::Entry *entry1;
- ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
+ std::string key("the first key");
+ disk_cache::Entry* entry;
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
const int kSize1 = 20000;
const int kSize2 = 20000;
@@ -718,52 +909,52 @@ void DiskCacheEntryTest::InvalidData() {
memset(buffer2->data(), 0, kSize2);
// Simple data grow:
- EXPECT_EQ(200, entry1->WriteData(0, 400, buffer1, 200, NULL, false));
- EXPECT_EQ(600, entry1->GetDataSize(0));
- EXPECT_EQ(100, entry1->ReadData(0, 300, buffer3, 100, NULL));
+ EXPECT_EQ(200, WriteData(entry, 0, 400, buffer1, 200, false));
+ EXPECT_EQ(600, entry->GetDataSize(0));
+ EXPECT_EQ(100, ReadData(entry, 0, 300, buffer3, 100));
EXPECT_TRUE(!memcmp(buffer3->data(), buffer2->data(), 100));
- entry1->Close();
- ASSERT_EQ(net::OK, OpenEntry(key1, &entry1));
+ entry->Close();
+ ASSERT_EQ(net::OK, OpenEntry(key, &entry));
// The entry is now on disk. Load it and extend it.
- EXPECT_EQ(200, entry1->WriteData(0, 800, buffer1, 200, NULL, false));
- EXPECT_EQ(1000, entry1->GetDataSize(0));
- EXPECT_EQ(100, entry1->ReadData(0, 700, buffer3, 100, NULL));
+ EXPECT_EQ(200, WriteData(entry, 0, 800, buffer1, 200, false));
+ EXPECT_EQ(1000, entry->GetDataSize(0));
+ EXPECT_EQ(100, ReadData(entry, 0, 700, buffer3, 100));
EXPECT_TRUE(!memcmp(buffer3->data(), buffer2->data(), 100));
- entry1->Close();
- ASSERT_EQ(net::OK, OpenEntry(key1, &entry1));
+ entry->Close();
+ ASSERT_EQ(net::OK, OpenEntry(key, &entry));
// This time using truncate.
- EXPECT_EQ(200, entry1->WriteData(0, 1800, buffer1, 200, NULL, true));
- EXPECT_EQ(2000, entry1->GetDataSize(0));
- EXPECT_EQ(100, entry1->ReadData(0, 1500, buffer3, 100, NULL));
+ EXPECT_EQ(200, WriteData(entry, 0, 1800, buffer1, 200, true));
+ EXPECT_EQ(2000, entry->GetDataSize(0));
+ EXPECT_EQ(100, ReadData(entry, 0, 1500, buffer3, 100));
EXPECT_TRUE(!memcmp(buffer3->data(), buffer2->data(), 100));
// Go to an external file.
- EXPECT_EQ(200, entry1->WriteData(0, 19800, buffer1, 200, NULL, false));
- EXPECT_EQ(20000, entry1->GetDataSize(0));
- EXPECT_EQ(4000, entry1->ReadData(0, 14000, buffer3, 4000, NULL));
+ EXPECT_EQ(200, WriteData(entry, 0, 19800, buffer1, 200, false));
+ EXPECT_EQ(20000, entry->GetDataSize(0));
+ EXPECT_EQ(4000, ReadData(entry, 0, 14000, buffer3, 4000));
EXPECT_TRUE(!memcmp(buffer3->data(), buffer2->data(), 4000));
// And back to an internal block.
- EXPECT_EQ(600, entry1->WriteData(0, 1000, buffer1, 600, NULL, true));
- EXPECT_EQ(1600, entry1->GetDataSize(0));
- EXPECT_EQ(600, entry1->ReadData(0, 1000, buffer3, 600, NULL));
+ EXPECT_EQ(600, WriteData(entry, 0, 1000, buffer1, 600, true));
+ EXPECT_EQ(1600, entry->GetDataSize(0));
+ EXPECT_EQ(600, ReadData(entry, 0, 1000, buffer3, 600));
EXPECT_TRUE(!memcmp(buffer3->data(), buffer1->data(), 600));
// Extend it again.
- EXPECT_EQ(600, entry1->WriteData(0, 2000, buffer1, 600, NULL, false));
- EXPECT_EQ(2600, entry1->GetDataSize(0));
- EXPECT_EQ(200, entry1->ReadData(0, 1800, buffer3, 200, NULL));
+ EXPECT_EQ(600, WriteData(entry, 0, 2000, buffer1, 600, false));
+ EXPECT_EQ(2600, entry->GetDataSize(0));
+ EXPECT_EQ(200, ReadData(entry, 0, 1800, buffer3, 200));
EXPECT_TRUE(!memcmp(buffer3->data(), buffer2->data(), 200));
// And again (with truncation flag).
- EXPECT_EQ(600, entry1->WriteData(0, 3000, buffer1, 600, NULL, true));
- EXPECT_EQ(3600, entry1->GetDataSize(0));
- EXPECT_EQ(200, entry1->ReadData(0, 2800, buffer3, 200, NULL));
+ EXPECT_EQ(600, WriteData(entry, 0, 3000, buffer1, 600, true));
+ EXPECT_EQ(3600, entry->GetDataSize(0));
+ EXPECT_EQ(200, ReadData(entry, 0, 2800, buffer3, 200));
EXPECT_TRUE(!memcmp(buffer3->data(), buffer2->data(), 200));
- entry1->Close();
+ entry->Close();
}
TEST_F(DiskCacheEntryTest, InvalidData) {
@@ -778,23 +969,23 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyInvalidData) {
}
void DiskCacheEntryTest::DoomNormalEntry() {
- std::string key1("the first key");
- disk_cache::Entry *entry1;
- ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
- entry1->Doom();
- entry1->Close();
+ std::string key("the first key");
+ disk_cache::Entry* entry;
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
+ entry->Doom();
+ entry->Close();
const int kSize = 20000;
scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize);
CacheTestFillBuffer(buffer->data(), kSize, true);
buffer->data()[19999] = '\0';
- key1 = buffer->data();
- ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
- EXPECT_EQ(20000, entry1->WriteData(0, 0, buffer, kSize, NULL, false));
- EXPECT_EQ(20000, entry1->WriteData(1, 0, buffer, kSize, NULL, false));
- entry1->Doom();
- entry1->Close();
+ key = buffer->data();
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
+ EXPECT_EQ(20000, WriteData(entry, 0, 0, buffer, kSize, false));
+ EXPECT_EQ(20000, WriteData(entry, 1, 0, buffer, kSize, false));
+ entry->Doom();
+ entry->Close();
FlushQueueForTest();
EXPECT_EQ(0, cache_->GetEntryCount());
@@ -815,7 +1006,7 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyDoomEntry) {
// Verify that basic operations work as expected with doomed entries.
void DiskCacheEntryTest::DoomedEntry() {
std::string key("the first key");
- disk_cache::Entry *entry;
+ disk_cache::Entry* entry;
ASSERT_EQ(net::OK, CreateEntry(key, &entry));
entry->Doom();
@@ -831,8 +1022,8 @@ void DiskCacheEntryTest::DoomedEntry() {
CacheTestFillBuffer(buffer1->data(), kSize1, false);
memset(buffer2->data(), 0, kSize2);
- EXPECT_EQ(2000, entry->WriteData(0, 0, buffer1, 2000, NULL, false));
- EXPECT_EQ(2000, entry->ReadData(0, 0, buffer2, 2000, NULL));
+ EXPECT_EQ(2000, WriteData(entry, 0, 0, buffer1, 2000, false));
+ EXPECT_EQ(2000, ReadData(entry, 0, 0, buffer2, 2000));
EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize1));
EXPECT_EQ(key, entry->GetKey());
EXPECT_TRUE(initial < entry->GetLastModified());
@@ -892,23 +1083,18 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyEnumerationWithSparseEntries) {
// Writes |buf_1| to offset and reads it back as |buf_2|.
void VerifySparseIO(disk_cache::Entry* entry, int64 offset,
- net::IOBuffer* buf_1, int size, bool async,
- net::IOBuffer* buf_2) {
- TestCompletionCallback callback;
- TestCompletionCallback* cb = async ? &callback : NULL;
+ net::IOBuffer* buf_1, int size, net::IOBuffer* buf_2) {
+ TestCompletionCallback cb;
memset(buf_2->data(), 0, size);
- int ret = entry->ReadSparseData(offset, buf_2, size, cb);
- ret = callback.GetResult(ret);
- EXPECT_EQ(0, ret);
+ int ret = entry->ReadSparseData(offset, buf_2, size, &cb);
+ EXPECT_EQ(0, cb.GetResult(ret));
- ret = entry->WriteSparseData(offset, buf_1, size, cb);
- ret = callback.GetResult(ret);
- EXPECT_EQ(size, ret);
+ ret = entry->WriteSparseData(offset, buf_1, size, &cb);
+ EXPECT_EQ(size, cb.GetResult(ret));
- ret = entry->ReadSparseData(offset, buf_2, size, cb);
- ret = callback.GetResult(ret);
- EXPECT_EQ(size, ret);
+ ret = entry->ReadSparseData(offset, buf_2, size, &cb);
+ EXPECT_EQ(size, cb.GetResult(ret));
EXPECT_EQ(0, memcmp(buf_1->data(), buf_2->data(), size));
}
@@ -916,20 +1102,18 @@ void VerifySparseIO(disk_cache::Entry* entry, int64 offset,
// Reads |size| bytes from |entry| at |offset| and verifies that they are the
// same as the content of the provided |buffer|.
void VerifyContentSparseIO(disk_cache::Entry* entry, int64 offset, char* buffer,
- int size, bool async) {
- TestCompletionCallback callback;
- TestCompletionCallback* cb = async ? &callback : NULL;
+ int size) {
+ TestCompletionCallback cb;
scoped_refptr<net::IOBuffer> buf_1 = new net::IOBuffer(size);
memset(buf_1->data(), 0, size);
- int ret = entry->ReadSparseData(offset, buf_1, size, cb);
- ret = callback.GetResult(ret);
- EXPECT_EQ(size, ret);
+ int ret = entry->ReadSparseData(offset, buf_1, size, &cb);
+ EXPECT_EQ(size, cb.GetResult(ret));
EXPECT_EQ(0, memcmp(buf_1->data(), buffer, size));
}
-void DiskCacheEntryTest::BasicSparseIO(bool async) {
+void DiskCacheEntryTest::BasicSparseIO() {
std::string key("the first key");
disk_cache::Entry* entry;
ASSERT_EQ(net::OK, CreateEntry(key, &entry));
@@ -940,47 +1124,36 @@ void DiskCacheEntryTest::BasicSparseIO(bool async) {
CacheTestFillBuffer(buf_1->data(), kSize, false);
// Write at offset 0.
- VerifySparseIO(entry, 0, buf_1, kSize, async, buf_2);
+ VerifySparseIO(entry, 0, buf_1, kSize, buf_2);
// Write at offset 0x400000 (4 MB).
- VerifySparseIO(entry, 0x400000, buf_1, kSize, async, buf_2);
+ VerifySparseIO(entry, 0x400000, buf_1, kSize, buf_2);
// Write at offset 0x800000000 (32 GB).
- VerifySparseIO(entry, 0x800000000LL, buf_1, kSize, async, buf_2);
+ VerifySparseIO(entry, 0x800000000LL, buf_1, kSize, buf_2);
entry->Close();
// Check everything again.
ASSERT_EQ(net::OK, OpenEntry(key, &entry));
- VerifyContentSparseIO(entry, 0, buf_1->data(), kSize, async);
- VerifyContentSparseIO(entry, 0x400000, buf_1->data(), kSize, async);
- VerifyContentSparseIO(entry, 0x800000000LL, buf_1->data(), kSize, async);
+ VerifyContentSparseIO(entry, 0, buf_1->data(), kSize);
+ VerifyContentSparseIO(entry, 0x400000, buf_1->data(), kSize);
+ VerifyContentSparseIO(entry, 0x800000000LL, buf_1->data(), kSize);
entry->Close();
}
-TEST_F(DiskCacheEntryTest, BasicSparseSyncIO) {
+TEST_F(DiskCacheEntryTest, BasicSparseIO) {
InitCache();
- BasicSparseIO(false);
+ BasicSparseIO();
}
-TEST_F(DiskCacheEntryTest, MemoryOnlyBasicSparseSyncIO) {
+TEST_F(DiskCacheEntryTest, MemoryOnlyBasicSparseIO) {
SetMemoryOnlyMode();
InitCache();
- BasicSparseIO(false);
+ BasicSparseIO();
}
-TEST_F(DiskCacheEntryTest, BasicSparseAsyncIO) {
- InitCache();
- BasicSparseIO(true);
-}
-
-TEST_F(DiskCacheEntryTest, MemoryOnlyBasicSparseAsyncIO) {
- SetMemoryOnlyMode();
- InitCache();
- BasicSparseIO(true);
-}
-
-void DiskCacheEntryTest::HugeSparseIO(bool async) {
+void DiskCacheEntryTest::HugeSparseIO() {
std::string key("the first key");
disk_cache::Entry* entry;
ASSERT_EQ(net::OK, CreateEntry(key, &entry));
@@ -992,35 +1165,24 @@ void DiskCacheEntryTest::HugeSparseIO(bool async) {
CacheTestFillBuffer(buf_1->data(), kSize, false);
// Write at offset 0x20F0000 (33 MB - 64 KB).
- VerifySparseIO(entry, 0x20F0000, buf_1, kSize, async, buf_2);
+ VerifySparseIO(entry, 0x20F0000, buf_1, kSize, buf_2);
entry->Close();
// Check it again.
ASSERT_EQ(net::OK, OpenEntry(key, &entry));
- VerifyContentSparseIO(entry, 0x20F0000, buf_1->data(), kSize, async);
+ VerifyContentSparseIO(entry, 0x20F0000, buf_1->data(), kSize);
entry->Close();
}
-TEST_F(DiskCacheEntryTest, HugeSparseSyncIO) {
- InitCache();
- HugeSparseIO(false);
-}
-
-TEST_F(DiskCacheEntryTest, MemoryOnlyHugeSparseSyncIO) {
- SetMemoryOnlyMode();
- InitCache();
- HugeSparseIO(false);
-}
-
-TEST_F(DiskCacheEntryTest, HugeSparseAsyncIO) {
+TEST_F(DiskCacheEntryTest, HugeSparseIO) {
InitCache();
- HugeSparseIO(true);
+ HugeSparseIO();
}
-TEST_F(DiskCacheEntryTest, MemoryOnlyHugeSparseAsyncIO) {
+TEST_F(DiskCacheEntryTest, MemoryOnlyHugeSparseIO) {
SetMemoryOnlyMode();
InitCache();
- HugeSparseIO(true);
+ HugeSparseIO();
}
void DiskCacheEntryTest::GetAvailableRange() {
@@ -1033,8 +1195,8 @@ void DiskCacheEntryTest::GetAvailableRange() {
CacheTestFillBuffer(buf->data(), kSize, false);
// Write at offset 0x20F0000 (33 MB - 64 KB), and 0x20F4400 (33 MB - 47 KB).
- EXPECT_EQ(kSize, entry->WriteSparseData(0x20F0000, buf, kSize, NULL));
- EXPECT_EQ(kSize, entry->WriteSparseData(0x20F4400, buf, kSize, NULL));
+ EXPECT_EQ(kSize, WriteSparseData(entry, 0x20F0000, buf, kSize));
+ EXPECT_EQ(kSize, WriteSparseData(entry, 0x20F4400, buf, kSize));
// We stop at the first empty block.
int64 start;
@@ -1095,7 +1257,7 @@ void DiskCacheEntryTest::CouldBeSparse() {
CacheTestFillBuffer(buf->data(), kSize, false);
// Write at offset 0x20F0000 (33 MB - 64 KB).
- EXPECT_EQ(kSize, entry->WriteSparseData(0x20F0000, buf, kSize, NULL));
+ EXPECT_EQ(kSize, WriteSparseData(entry, 0x20F0000, buf, kSize));
EXPECT_TRUE(entry->CouldBeSparse());
entry->Close();
@@ -1109,9 +1271,9 @@ void DiskCacheEntryTest::CouldBeSparse() {
ASSERT_EQ(net::OK, CreateEntry(key, &entry));
EXPECT_FALSE(entry->CouldBeSparse());
- EXPECT_EQ(kSize, entry->WriteData(0, 0, buf, kSize, NULL, false));
- EXPECT_EQ(kSize, entry->WriteData(1, 0, buf, kSize, NULL, false));
- EXPECT_EQ(kSize, entry->WriteData(2, 0, buf, kSize, NULL, false));
+ EXPECT_EQ(kSize, WriteData(entry, 0, 0, buf, kSize, false));
+ EXPECT_EQ(kSize, WriteData(entry, 1, 0, buf, kSize, false));
+ EXPECT_EQ(kSize, WriteData(entry, 2, 0, buf, kSize, false));
EXPECT_FALSE(entry->CouldBeSparse());
entry->Close();
@@ -1149,16 +1311,16 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyMisalignedSparseIO) {
for (int i = 0; i < kSize; i += 1024) {
scoped_refptr<net::WrappedIOBuffer> buf_3 =
new net::WrappedIOBuffer(buf_1->data() + i);
- VerifySparseIO(entry, i, buf_3, 1024, false, buf_2);
- VerifySparseIO(entry, 9000 + i, buf_3, 1024, false, buf_2);
+ VerifySparseIO(entry, i, buf_3, 1024, buf_2);
+ VerifySparseIO(entry, 9000 + i, buf_3, 1024, buf_2);
}
// Make sure we have data written.
- VerifyContentSparseIO(entry, 0, buf_1->data(), kSize, false);
- VerifyContentSparseIO(entry, 9000, buf_1->data(), kSize, false);
+ VerifyContentSparseIO(entry, 0, buf_1->data(), kSize);
+ VerifyContentSparseIO(entry, 9000, buf_1->data(), kSize);
// This tests a large write that spans 3 entries from a misaligned offset.
- VerifySparseIO(entry, 20481, buf_1, 8192, false, buf_2);
+ VerifySparseIO(entry, 20481, buf_1, 8192, buf_2);
entry->Close();
}
@@ -1352,10 +1514,9 @@ void DiskCacheEntryTest::PartialSparseEntry() {
// The first write is just to extend the entry. The third write occupies
// a 1KB block partially, it may not be written internally depending on the
// implementation.
- EXPECT_EQ(kSize, entry->WriteSparseData(20000, buf1, kSize, NULL));
- EXPECT_EQ(kSize, entry->WriteSparseData(500, buf1, kSize, NULL));
- EXPECT_EQ(kSmallSize,
- entry->WriteSparseData(1080321, buf1, kSmallSize, NULL));
+ EXPECT_EQ(kSize, WriteSparseData(entry, 20000, buf1, kSize));
+ EXPECT_EQ(kSize, WriteSparseData(entry, 500, buf1, kSize));
+ EXPECT_EQ(kSmallSize, WriteSparseData(entry, 1080321, buf1, kSmallSize));
entry->Close();
ASSERT_EQ(net::OK, OpenEntry(key, &entry));
@@ -1363,14 +1524,14 @@ void DiskCacheEntryTest::PartialSparseEntry() {
memset(buf2->data(), 0, kSize);
EXPECT_EQ(0, entry->ReadSparseData(8000, buf2, kSize, NULL));
- EXPECT_EQ(500, entry->ReadSparseData(kSize, buf2, kSize, NULL));
+ EXPECT_EQ(500, ReadSparseData(entry, kSize, buf2, kSize));
EXPECT_EQ(0, memcmp(buf2->data(), buf1->data() + kSize - 500, 500));
- EXPECT_EQ(0, entry->ReadSparseData(0, buf2, kSize, NULL));
+ EXPECT_EQ(0, ReadSparseData(entry, 0, buf2, kSize));
// This read should not change anything.
- EXPECT_EQ(96, entry->ReadSparseData(24000, buf2, kSize, NULL));
- EXPECT_EQ(500, entry->ReadSparseData(kSize, buf2, kSize, NULL));
- EXPECT_EQ(0, entry->ReadSparseData(499, buf2, kSize, NULL));
+ EXPECT_EQ(96, ReadSparseData(entry, 24000, buf2, kSize));
+ EXPECT_EQ(500, ReadSparseData(entry, kSize, buf2, kSize));
+ EXPECT_EQ(0, ReadSparseData(entry, 99, buf2, kSize));
int rv;
int64 start;
@@ -1411,11 +1572,11 @@ void DiskCacheEntryTest::PartialSparseEntry() {
EXPECT_EQ(4600, start);
// Now make another write and verify that there is no hole in between.
- EXPECT_EQ(kSize, entry->WriteSparseData(500 + kSize, buf1, kSize, NULL));
+ EXPECT_EQ(kSize, WriteSparseData(entry, 500 + kSize, buf1, kSize));
rv = entry->GetAvailableRange(1024, 10000, &start, &cb);
EXPECT_EQ(7 * 1024 + 500, cb.GetResult(rv));
EXPECT_EQ(1024, start);
- EXPECT_EQ(kSize, entry->ReadSparseData(kSize, buf2, kSize, NULL));
+ EXPECT_EQ(kSize, ReadSparseData(entry, kSize, buf2, kSize));
EXPECT_EQ(0, memcmp(buf2->data(), buf1->data() + kSize - 500, 500));
EXPECT_EQ(0, memcmp(buf2->data() + 500, buf1->data(), kSize - 500));
@@ -1445,9 +1606,9 @@ TEST_F(DiskCacheEntryTest, CleanupSparseEntry) {
CacheTestFillBuffer(buf1->data(), kSize, false);
const int k1Meg = 1024 * 1024;
- EXPECT_EQ(kSize, entry->WriteSparseData(8192, buf1, kSize, NULL));
- EXPECT_EQ(kSize, entry->WriteSparseData(k1Meg + 8192, buf1, kSize, NULL));
- EXPECT_EQ(kSize, entry->WriteSparseData(2 * k1Meg + 8192, buf1, kSize, NULL));
+ EXPECT_EQ(kSize, WriteSparseData(entry, 8192, buf1, kSize));
+ EXPECT_EQ(kSize, WriteSparseData(entry, k1Meg + 8192, buf1, kSize));
+ EXPECT_EQ(kSize, WriteSparseData(entry, 2 * k1Meg + 8192, buf1, kSize));
entry->Close();
EXPECT_EQ(4, cache_->GetEntryCount());
@@ -1464,7 +1625,7 @@ TEST_F(DiskCacheEntryTest, CleanupSparseEntry) {
for (int i = 0; i < 2; i++) {
ASSERT_EQ(net::OK, OpenEntry(child_key[i], &entry));
// Overwrite the header's magic and signature.
- EXPECT_EQ(12, entry->WriteData(2, 0, buf1, 12, NULL, false));
+ EXPECT_EQ(12, WriteData(entry, 2, 0, buf1, 12, false));
entry->Close();
}
@@ -1472,12 +1633,12 @@ TEST_F(DiskCacheEntryTest, CleanupSparseEntry) {
ASSERT_EQ(net::OK, OpenEntry(key, &entry));
// Two children should be gone. One while reading and one while writing.
- EXPECT_EQ(0, entry->ReadSparseData(2 * k1Meg + 8192, buf1, kSize, NULL));
- EXPECT_EQ(kSize, entry->WriteSparseData(k1Meg + 16384, buf1, kSize, NULL));
- EXPECT_EQ(0, entry->ReadSparseData(k1Meg + 8192, buf1, kSize, NULL));
+ EXPECT_EQ(0, ReadSparseData(entry, 2 * k1Meg + 8192, buf1, kSize));
+ EXPECT_EQ(kSize, WriteSparseData(entry, k1Meg + 16384, buf1, kSize));
+ EXPECT_EQ(0, ReadSparseData(entry, k1Meg + 8192, buf1, kSize));
// We never touched this one.
- EXPECT_EQ(kSize, entry->ReadSparseData(8192, buf1, kSize, NULL));
+ EXPECT_EQ(kSize, ReadSparseData(entry, 8192, buf1, kSize));
entry->Close();
// We re-created one of the corrupt children.