diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-30 21:41:54 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-30 21:41:54 +0000 |
commit | a9da16d0e7aa10ad2f4ee3290edc361b862e6314 (patch) | |
tree | a5ecba94190bd01ae479f7274d450296ad241f11 /net/disk_cache/backend_unittest.cc | |
parent | 01e9c8a645db02edb5b0c8b33ff091f55b47dbd5 (diff) | |
download | chromium_src-a9da16d0e7aa10ad2f4ee3290edc361b862e6314.zip chromium_src-a9da16d0e7aa10ad2f4ee3290edc361b862e6314.tar.gz chromium_src-a9da16d0e7aa10ad2f4ee3290edc361b862e6314.tar.bz2 |
Add unit tests to the disk cache to verify that a failure during cache reinitialization is handled properly.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/backend_unittest.cc')
-rw-r--r-- | net/disk_cache/backend_unittest.cc | 100 |
1 files changed, 65 insertions, 35 deletions
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc index 0514758..cbdc450 100644 --- a/net/disk_cache/backend_unittest.cc +++ b/net/disk_cache/backend_unittest.cc @@ -111,6 +111,9 @@ class DiskCacheBackendTest : public DiskCacheTestBase { void BackendDoomRecent(); void BackendDoomBetween(); void BackendDoomAll(); + void BackendInvalidRankings(); + void BackendDisable(); + void BackendDisable2(); }; void DiskCacheBackendTest::BackendBasics() { @@ -809,71 +812,98 @@ TEST(DiskCacheTest, Backend_InvalidRankings) { } // If the LRU is corrupt, we delete the cache. -TEST(DiskCacheTest, Backend_InvalidRankings2) { - ASSERT_TRUE(CopyTestCache(L"bad_rankings")); - std::wstring path = GetCachePath(); - disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0); - ASSERT_TRUE(NULL != cache); - +void DiskCacheBackendTest::BackendInvalidRankings() { disk_cache::Entry* entry; void* iter = NULL; - ASSERT_TRUE(cache->OpenNextEntry(&iter, &entry)); + ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry)); entry->Close(); - EXPECT_EQ(2, cache->GetEntryCount()); + EXPECT_EQ(2, cache_->GetEntryCount()); - EXPECT_FALSE(cache->OpenNextEntry(&iter, &entry)); - EXPECT_EQ(0, cache->GetEntryCount()); + EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry)); + EXPECT_EQ(0, cache_->GetEntryCount()); +} - delete cache; - EXPECT_TRUE(CheckCacheIntegrity(path)); +TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { + ASSERT_TRUE(CopyTestCache(L"bad_rankings")); + DisableFirstCleanup(); + SetDirectMode(); + InitCache(); + BackendInvalidRankings(); } -// If the LRU is corrupt and we have open entries, we disable the cache. -TEST(DiskCacheTest, Backend_Disable) { +TEST_F(DiskCacheBackendTest, InvalidRankingsFailure) { ASSERT_TRUE(CopyTestCache(L"bad_rankings")); - std::wstring path = GetCachePath(); - disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0); - ASSERT_TRUE(NULL != cache); + DisableFirstCleanup(); + SetDirectMode(); + InitCache(); + SetTestMode(); // Fail cache reinitialization. + BackendInvalidRankings(); +} +// If the LRU is corrupt and we have open entries, we disable the cache. +void DiskCacheBackendTest::BackendDisable() { disk_cache::Entry *entry1, *entry2; void* iter = NULL; - ASSERT_TRUE(cache->OpenNextEntry(&iter, &entry1)); + ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry1)); - EXPECT_FALSE(cache->OpenNextEntry(&iter, &entry2)); - EXPECT_EQ(2, cache->GetEntryCount()); - EXPECT_FALSE(cache->CreateEntry("Something new", &entry2)); + EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry2)); + EXPECT_EQ(2, cache_->GetEntryCount()); + EXPECT_FALSE(cache_->CreateEntry("Something new", &entry2)); entry1->Close(); - EXPECT_EQ(0, cache->GetEntryCount()); + EXPECT_EQ(0, cache_->GetEntryCount()); +} - delete cache; - EXPECT_TRUE(CheckCacheIntegrity(path)); +TEST_F(DiskCacheBackendTest, DisableSuccess) { + ASSERT_TRUE(CopyTestCache(L"bad_rankings")); + DisableFirstCleanup(); + SetDirectMode(); + InitCache(); + BackendDisable(); } -// This is another type of corruption on the LRU; disable the cache. -TEST(DiskCacheTest, Backend_Disable2) { - ASSERT_TRUE(CopyTestCache(L"list_loop")); - std::wstring path = GetCachePath(); - disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0); - ASSERT_TRUE(NULL != cache); +TEST_F(DiskCacheBackendTest, DisableFailure) { + ASSERT_TRUE(CopyTestCache(L"bad_rankings")); + DisableFirstCleanup(); + SetDirectMode(); + InitCache(); + SetTestMode(); // Fail cache reinitialization. + BackendDisable(); +} - EXPECT_EQ(8, cache->GetEntryCount()); +// This is another type of corruption on the LRU; disable the cache. +void DiskCacheBackendTest::BackendDisable2() { + EXPECT_EQ(8, cache_->GetEntryCount()); disk_cache::Entry* entry; void* iter = NULL; int count = 0; - while (cache->OpenNextEntry(&iter, &entry)) { + while (cache_->OpenNextEntry(&iter, &entry)) { ASSERT_TRUE(NULL != entry); entry->Close(); count++; ASSERT_LT(count, 9); }; - EXPECT_EQ(0, cache->GetEntryCount()); + EXPECT_EQ(0, cache_->GetEntryCount()); +} - delete cache; - EXPECT_TRUE(CheckCacheIntegrity(path)); +TEST_F(DiskCacheBackendTest, DisableSuccess2) { + ASSERT_TRUE(CopyTestCache(L"list_loop")); + DisableFirstCleanup(); + SetDirectMode(); + InitCache(); + BackendDisable2(); +} + +TEST_F(DiskCacheBackendTest, DisableFailure2) { + ASSERT_TRUE(CopyTestCache(L"list_loop")); + DisableFirstCleanup(); + SetDirectMode(); + InitCache(); + SetTestMode(); // Fail cache reinitialization. + BackendDisable2(); } TEST(DiskCacheTest, Backend_UsageStats) { |