diff options
author | mmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-28 00:59:06 +0000 |
---|---|---|
committer | mmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-28 00:59:06 +0000 |
commit | 4d5e036157b6fa024f0a7e0659c0559bbfc8dfcb (patch) | |
tree | 6604c15b12a8452c9ee2374d776ebb5877495591 /net/disk_cache | |
parent | 1e1402c1e5399edaa536ca41d6d8ec1c0735539c (diff) | |
download | chromium_src-4d5e036157b6fa024f0a7e0659c0559bbfc8dfcb.zip chromium_src-4d5e036157b6fa024f0a7e0659c0559bbfc8dfcb.tar.gz chromium_src-4d5e036157b6fa024f0a7e0659c0559bbfc8dfcb.tar.bz2 |
Run some disk cache unit tests on the Mac
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1475 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r-- | net/disk_cache/addr_unittest.cc | 7 | ||||
-rw-r--r-- | net/disk_cache/backend_unittest.cc | 14 | ||||
-rw-r--r-- | net/disk_cache/block_files_unittest.cc | 5 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_perftest.cc | 5 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_base.cc | 16 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_base.h | 20 | ||||
-rw-r--r-- | net/disk_cache/entry_unittest.cc | 2 | ||||
-rw-r--r-- | net/disk_cache/mapped_file_unittest.cc | 5 | ||||
-rw-r--r-- | net/disk_cache/storage_block_unittest.cc | 7 |
9 files changed, 47 insertions, 34 deletions
diff --git a/net/disk_cache/addr_unittest.cc b/net/disk_cache/addr_unittest.cc index 2fb86fd..febd5c9 100644 --- a/net/disk_cache/addr_unittest.cc +++ b/net/disk_cache/addr_unittest.cc @@ -3,11 +3,12 @@ // found in the LICENSE file. #include "net/disk_cache/addr.h" +#include "net/disk_cache/disk_cache_test_base.h" #include "testing/gtest/include/gtest/gtest.h" namespace disk_cache { -TEST(DiskCacheTest, CacheAddr_Size) { +TEST_F(DiskCacheTest, CacheAddr_Size) { Addr addr1(0); EXPECT_FALSE(addr1.is_initialized()); @@ -15,7 +16,7 @@ TEST(DiskCacheTest, CacheAddr_Size) { EXPECT_EQ(sizeof(uint32), sizeof(addr1)); } -TEST(DiskCacheTest, CacheAddr_ValidValues) { +TEST_F(DiskCacheTest, CacheAddr_ValidValues) { Addr addr2(BLOCK_1K, 3, 5, 25); EXPECT_EQ(BLOCK_1K, addr2.file_type()); EXPECT_EQ(3, addr2.num_blocks()); @@ -24,7 +25,7 @@ TEST(DiskCacheTest, CacheAddr_ValidValues) { EXPECT_EQ(1024, addr2.BlockSize()); } -TEST(DiskCacheTest, CacheAddr_InvalidValues) { +TEST_F(DiskCacheTest, CacheAddr_InvalidValues) { Addr addr3(BLOCK_4K, 0x44, 0x41508, 0x952536); EXPECT_EQ(BLOCK_4K, addr3.file_type()); EXPECT_EQ(4, addr3.num_blocks()); diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc index bf4140a..0cfcaf5 100644 --- a/net/disk_cache/backend_unittest.cc +++ b/net/disk_cache/backend_unittest.cc @@ -78,7 +78,7 @@ int TestTransaction(const std::wstring& name, int num_entries, bool load) { } // namespace // Tests that can run with different types of caches. -class DiskCacheBackendTest : public DiskCacheTestBase { +class DiskCacheBackendTest : public DiskCacheTestWithCache { protected: void BackendBasics(); void BackendSetSize(); @@ -719,7 +719,7 @@ TEST_F(DiskCacheBackendTest, MemoryOnlyDoomBetween) { BackendDoomBetween(); } -TEST(DiskCacheTest, Backend_RecoverInsert) { +TEST_F(DiskCacheTest, Backend_RecoverInsert) { // Tests with an empty cache. EXPECT_EQ(0, TestTransaction(L"insert_empty1", 0, false)); EXPECT_EQ(0, TestTransaction(L"insert_empty2", 0, false)); @@ -735,7 +735,7 @@ TEST(DiskCacheTest, Backend_RecoverInsert) { EXPECT_EQ(0, TestTransaction(L"insert_load2", 100, true)); } -TEST(DiskCacheTest, Backend_RecoverRemove) { +TEST_F(DiskCacheTest, Backend_RecoverRemove) { // Removing the only element. EXPECT_EQ(0, TestTransaction(L"remove_one1", 0, false)); EXPECT_EQ(0, TestTransaction(L"remove_one2", 0, false)); @@ -764,7 +764,7 @@ TEST(DiskCacheTest, Backend_RecoverRemove) { } // Tests dealing with cache files that cannot be recovered. -TEST(DiskCacheTest, Backend_DeleteOld) { +TEST_F(DiskCacheTest, Backend_DeleteOld) { ASSERT_TRUE(CopyTestCache(L"wrong_version")); std::wstring path = GetCachePath(); scoped_ptr<disk_cache::Backend> cache; @@ -781,7 +781,7 @@ TEST(DiskCacheTest, Backend_DeleteOld) { } // We want to be able to deal with messed up entries on disk. -TEST(DiskCacheTest, Backend_InvalidEntry) { +TEST_F(DiskCacheTest, Backend_InvalidEntry) { ASSERT_TRUE(CopyTestCache(L"bad_entry")); std::wstring path = GetCachePath(); disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0); @@ -797,7 +797,7 @@ TEST(DiskCacheTest, Backend_InvalidEntry) { } // We want to be able to deal with messed up entries on disk. -TEST(DiskCacheTest, Backend_InvalidRankings) { +TEST_F(DiskCacheTest, Backend_InvalidRankings) { ASSERT_TRUE(CopyTestCache(L"bad_rankings")); std::wstring path = GetCachePath(); disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0); @@ -907,7 +907,7 @@ TEST_F(DiskCacheBackendTest, DisableFailure2) { BackendDisable2(); } -TEST(DiskCacheTest, Backend_UsageStats) { +TEST_F(DiskCacheTest, Backend_UsageStats) { MessageLoopHelper helper; std::wstring path = GetCachePath(); diff --git a/net/disk_cache/block_files_unittest.cc b/net/disk_cache/block_files_unittest.cc index fe35527..59ca1d0 100644 --- a/net/disk_cache/block_files_unittest.cc +++ b/net/disk_cache/block_files_unittest.cc @@ -4,10 +4,11 @@ #include "net/disk_cache/block_files.h" #include "net/disk_cache/disk_cache.h" +#include "net/disk_cache/disk_cache_test_base.h" #include "net/disk_cache/disk_cache_test_util.h" #include "testing/gtest/include/gtest/gtest.h" -TEST(DiskCacheTest, BlockFiles_Grow) { +TEST_F(DiskCacheTest, BlockFiles_Grow) { std::wstring path = GetCachePath(); ASSERT_TRUE(DeleteCache(path.c_str())); @@ -22,7 +23,7 @@ TEST(DiskCacheTest, BlockFiles_Grow) { } // Handling of block files not properly closed. -TEST(DiskCacheTest, BlockFiles_Recover) { +TEST_F(DiskCacheTest, BlockFiles_Recover) { std::wstring path = GetCachePath(); ASSERT_TRUE(DeleteCache(path.c_str())); diff --git a/net/disk_cache/disk_cache_perftest.cc b/net/disk_cache/disk_cache_perftest.cc index e902ff0..25db013 100644 --- a/net/disk_cache/disk_cache_perftest.cc +++ b/net/disk_cache/disk_cache_perftest.cc @@ -7,6 +7,7 @@ #include "base/timer.h" #include "net/base/net_errors.h" #include "net/disk_cache/disk_cache.h" +#include "net/disk_cache/disk_cache_test_base.h" #include "net/disk_cache/disk_cache_test_util.h" #include "net/disk_cache/hash.h" #include "testing/gtest/include/gtest/gtest.h" @@ -163,7 +164,7 @@ int TimeRead(int num_entries, disk_cache::Backend* cache, } // namespace -TEST(DiskCacheTest, Hash) { +TEST_F(DiskCacheTest, Hash) { int seed = static_cast<int>(Time::Now().ToInternalValue()); srand(seed); @@ -175,7 +176,7 @@ TEST(DiskCacheTest, Hash) { timer.Done(); } -TEST(DiskCacheTest, CacheBackendPerformance) { +TEST_F(DiskCacheTest, CacheBackendPerformance) { MessageLoopForIO message_loop; std::wstring path = GetCachePath(); diff --git a/net/disk_cache/disk_cache_test_base.cc b/net/disk_cache/disk_cache_test_base.cc index ebf4637..417792f 100644 --- a/net/disk_cache/disk_cache_test_base.cc +++ b/net/disk_cache/disk_cache_test_base.cc @@ -8,7 +8,7 @@ #include "net/disk_cache/disk_cache_test_util.h" #include "net/disk_cache/mem_backend_impl.h" -void DiskCacheTestBase::SetMaxSize(int size) { +void DiskCacheTestWithCache::SetMaxSize(int size) { size_ = size; if (cache_impl_) EXPECT_TRUE(cache_impl_->SetMaxSize(size)); @@ -17,7 +17,7 @@ void DiskCacheTestBase::SetMaxSize(int size) { EXPECT_TRUE(mem_cache_->SetMaxSize(size)); } -void DiskCacheTestBase::InitCache() { +void DiskCacheTestWithCache::InitCache() { if (mask_) implementation_ = true; @@ -31,7 +31,7 @@ void DiskCacheTestBase::InitCache() { ASSERT_EQ(0, cache_->GetEntryCount()); } -void DiskCacheTestBase::InitMemoryCache() { +void DiskCacheTestWithCache::InitMemoryCache() { if (!implementation_) { cache_ = disk_cache::CreateInMemoryCacheBackend(size_); return; @@ -47,7 +47,7 @@ void DiskCacheTestBase::InitMemoryCache() { ASSERT_TRUE(mem_cache_->Init()); } -void DiskCacheTestBase::InitDiskCache() { +void DiskCacheTestWithCache::InitDiskCache() { std::wstring path = GetCachePath(); if (first_cleanup_) ASSERT_TRUE(DeleteCache(path.c_str())); @@ -72,17 +72,19 @@ void DiskCacheTestBase::InitDiskCache() { } -void DiskCacheTestBase::TearDown() { +void DiskCacheTestWithCache::TearDown() { delete cache_; if (!memory_only_) { std::wstring path = GetCachePath(); EXPECT_TRUE(CheckCacheIntegrity(path)); } + + PlatformTest::TearDown(); } // We are expected to leak memory when simulating crashes. -void DiskCacheTestBase::SimulateCrash() { +void DiskCacheTestWithCache::SimulateCrash() { ASSERT_TRUE(implementation_ && !memory_only_); cache_impl_->ClearRefCountForTest(); @@ -102,7 +104,7 @@ void DiskCacheTestBase::SimulateCrash() { ASSERT_TRUE(cache_impl_->Init()); } -void DiskCacheTestBase::SetTestMode() { +void DiskCacheTestWithCache::SetTestMode() { ASSERT_TRUE(implementation_ && !memory_only_); cache_impl_->SetUnitTestMode(); } diff --git a/net/disk_cache/disk_cache_test_base.h b/net/disk_cache/disk_cache_test_base.h index 04eb1c5..ca56be1f 100644 --- a/net/disk_cache/disk_cache_test_base.h +++ b/net/disk_cache/disk_cache_test_base.h @@ -2,24 +2,31 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H__ -#define NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H__ +#ifndef NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ +#define NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ #include "base/basictypes.h" +#include "base/platform_test.h" #include "testing/gtest/include/gtest/gtest.h" +// These tests can use the path service, which uses autoreleased objects on the +// Mac, so this needs to be a PlatformTest. Even tests that do not require a +// cache (and that do not need to be a DiskCacheTestWithCache) are susceptible +// to this problem; all such tests should use TEST_F(DiskCacheTest, ...). +typedef PlatformTest DiskCacheTest; + namespace disk_cache { class Backend; class BackendImpl; class MemBackendImpl; -} +} // namespace disk_cache // Provides basic support for cache related tests. -class DiskCacheTestBase : public testing::Test { +class DiskCacheTestWithCache : public DiskCacheTest { protected: - DiskCacheTestBase() + DiskCacheTestWithCache() : cache_(NULL), cache_impl_(NULL), mem_cache_(NULL), mask_(0), size_(0), memory_only_(false), implementation_(false), force_creation_(false), first_cleanup_(true) {} @@ -71,5 +78,4 @@ class DiskCacheTestBase : public testing::Test { void InitDiskCache(); }; -#endif // NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H__ - +#endif // NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc index 8d71c44..7e0ba8a 100644 --- a/net/disk_cache/entry_unittest.cc +++ b/net/disk_cache/entry_unittest.cc @@ -16,7 +16,7 @@ extern volatile int g_cache_tests_received; extern volatile bool g_cache_tests_error; // Tests that can run with different types of caches. -class DiskCacheEntryTest : public DiskCacheTestBase { +class DiskCacheEntryTest : public DiskCacheTestWithCache { protected: void InternalSyncIO(); void InternalAsyncIO(); diff --git a/net/disk_cache/mapped_file_unittest.cc b/net/disk_cache/mapped_file_unittest.cc index 138f3cb..fe090e5 100644 --- a/net/disk_cache/mapped_file_unittest.cc +++ b/net/disk_cache/mapped_file_unittest.cc @@ -4,6 +4,7 @@ #include "base/file_util.h" #include "base/string_util.h" +#include "net/disk_cache/disk_cache_test_base.h" #include "net/disk_cache/disk_cache_test_util.h" #include "net/disk_cache/mapped_file.h" #include "testing/gtest/include/gtest/gtest.h" @@ -66,7 +67,7 @@ void WaitForCallbacks(int expected) { } // namespace -TEST(DiskCacheTest, MappedFile_SyncIO) { +TEST_F(DiskCacheTest, MappedFile_SyncIO) { std::wstring filename = GetCachePath(); file_util::AppendToPath(&filename, L"a_test"); scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); @@ -82,7 +83,7 @@ TEST(DiskCacheTest, MappedFile_SyncIO) { EXPECT_STREQ(buffer1, buffer2); } -TEST(DiskCacheTest, MappedFile_AsyncIO) { +TEST_F(DiskCacheTest, MappedFile_AsyncIO) { std::wstring filename = GetCachePath(); file_util::AppendToPath(&filename, L"a_test"); scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); diff --git a/net/disk_cache/storage_block_unittest.cc b/net/disk_cache/storage_block_unittest.cc index fb89d36..4f172e0 100644 --- a/net/disk_cache/storage_block_unittest.cc +++ b/net/disk_cache/storage_block_unittest.cc @@ -5,10 +5,11 @@ #include "base/file_util.h" #include "net/disk_cache/storage_block.h" #include "net/disk_cache/storage_block-inl.h" +#include "net/disk_cache/disk_cache_test_base.h" #include "net/disk_cache/disk_cache_test_util.h" #include "testing/gtest/include/gtest/gtest.h" -TEST(DiskCacheTest, StorageBlock_LoadStore) { +TEST_F(DiskCacheTest, StorageBlock_LoadStore) { std::wstring filename = GetCachePath(); file_util::AppendToPath(&filename, L"a_test"); scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); @@ -29,7 +30,7 @@ TEST(DiskCacheTest, StorageBlock_LoadStore) { EXPECT_EQ(0xa0010002, entry1.Data()->rankings_node); } -TEST(DiskCacheTest, StorageBlock_SetData) { +TEST_F(DiskCacheTest, StorageBlock_SetData) { std::wstring filename = GetCachePath(); file_util::AppendToPath(&filename, L"a_test"); scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); @@ -50,7 +51,7 @@ TEST(DiskCacheTest, StorageBlock_SetData) { EXPECT_TRUE(entry2.Data() == entry1.Data()); } -TEST(DiskCacheTest, StorageBlock_SetModified) { +TEST_F(DiskCacheTest, StorageBlock_SetModified) { std::wstring filename = GetCachePath(); file_util::AppendToPath(&filename, L"a_test"); scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); |