From 790656e31f441404fa57944ca1a69890052a7828 Mon Sep 17 00:00:00 2001 From: "hclam@chromium.org" Date: Wed, 2 Sep 2009 20:13:57 +0000 Subject: Fixing bugs in sparse cache when dealing with GetAvailableRange queries not aligned TEST=net_unittests --gtest_filter=DiskCacheEntryTest.PartialSparseEntry In handling GetAvailableRange() queries, if the start offset is not aligned to 1KB, there was some strange behaviors: 1. The start offset found is smaller than the input offset 2. Number of continus bytes doesn't take into account offset in a block. This patch will fix the above problems. Review URL: http://codereview.chromium.org/186002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25225 0039d316-1c4b-4281-b951-d872f2087c98 --- net/disk_cache/entry_unittest.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'net/disk_cache/entry_unittest.cc') diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc index f65f593..dbd4f82 100644 --- a/net/disk_cache/entry_unittest.cc +++ b/net/disk_cache/entry_unittest.cc @@ -1256,6 +1256,21 @@ void DiskCacheEntryTest::PartialSparseEntry() { EXPECT_EQ(3616, entry->GetAvailableRange(20 * 1024, 10000, &start)); EXPECT_EQ(20 * 1024, start); + // 1. Query before a filled 1KB block. + // 2. Query within a filled 1KB block. + // 3. Query beyond a filled 1KB block. + if (memory_only_) { + EXPECT_EQ(3496, entry->GetAvailableRange(19400, kSize, &start)); + EXPECT_EQ(20000, start); + } else { + EXPECT_EQ(3016, entry->GetAvailableRange(19400, kSize, &start)); + EXPECT_EQ(20480, start); + } + EXPECT_EQ(1523, entry->GetAvailableRange(3073, kSize, &start)); + EXPECT_EQ(3073, start); + EXPECT_EQ(0, entry->GetAvailableRange(4600, kSize, &start)); + 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(7 * 1024 + 500, entry->GetAvailableRange(1024, 10000, &start)); -- cgit v1.1