diff options
author | Patrick Scott <phanna@android.com> | 2010-02-04 10:37:17 -0500 |
---|---|---|
committer | Patrick Scott <phanna@android.com> | 2010-02-04 10:39:42 -0500 |
commit | c7f5f8508d98d5952d42ed7648c2a8f30a4da156 (patch) | |
tree | dd51dbfbf6670daa61279b3a19e7b1835b301dbf /net/disk_cache/disk_cache_test_base.cc | |
parent | 139d8152182f9093f03d9089822b688e49fa7667 (diff) | |
download | external_chromium-c7f5f8508d98d5952d42ed7648c2a8f30a4da156.zip external_chromium-c7f5f8508d98d5952d42ed7648c2a8f30a4da156.tar.gz external_chromium-c7f5f8508d98d5952d42ed7648c2a8f30a4da156.tar.bz2 |
Initial source checkin.
The source files were determined by building net_unittests in chromium's source
tree. Some of the obvious libraries were left out (v8, gmock, gtest).
The Android.mk file has all the sources (minus unittests and tools) that were
used during net_unittests compilation. Nothing builds yet because of STL but
that is the next task. The .cpp files will most likely not compile anyways
because of the LOCAL_CPP_EXTENSION mod. I will have to break this into multiple
projects to get around that limitation.
Diffstat (limited to 'net/disk_cache/disk_cache_test_base.cc')
-rw-r--r-- | net/disk_cache/disk_cache_test_base.cc | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/net/disk_cache/disk_cache_test_base.cc b/net/disk_cache/disk_cache_test_base.cc new file mode 100644 index 0000000..21352a2 --- /dev/null +++ b/net/disk_cache/disk_cache_test_base.cc @@ -0,0 +1,113 @@ +// Copyright (c) 2006-2008 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 "net/disk_cache/disk_cache_test_base.h" + +#include "net/disk_cache/backend_impl.h" +#include "net/disk_cache/disk_cache_test_util.h" +#include "net/disk_cache/mem_backend_impl.h" + +void DiskCacheTest::TearDown() { + MessageLoop::current()->RunAllPending(); +} + +void DiskCacheTestWithCache::SetMaxSize(int size) { + size_ = size; + if (cache_impl_) + EXPECT_TRUE(cache_impl_->SetMaxSize(size)); + + if (mem_cache_) + EXPECT_TRUE(mem_cache_->SetMaxSize(size)); +} + +void DiskCacheTestWithCache::InitCache() { + if (mask_ || new_eviction_) + implementation_ = true; + + if (memory_only_) + InitMemoryCache(); + else + InitDiskCache(); + + ASSERT_TRUE(NULL != cache_); + if (first_cleanup_) + ASSERT_EQ(0, cache_->GetEntryCount()); +} + +void DiskCacheTestWithCache::InitMemoryCache() { + if (!implementation_) { + cache_ = disk_cache::CreateInMemoryCacheBackend(size_); + return; + } + + mem_cache_ = new disk_cache::MemBackendImpl(); + cache_ = mem_cache_; + ASSERT_TRUE(NULL != cache_); + + if (size_) + EXPECT_TRUE(mem_cache_->SetMaxSize(size_)); + + ASSERT_TRUE(mem_cache_->Init()); +} + +void DiskCacheTestWithCache::InitDiskCache() { + FilePath path = GetCacheFilePath(); + if (first_cleanup_) + ASSERT_TRUE(DeleteCache(path)); + + if (implementation_) + return InitDiskCacheImpl(path); + + cache_ = disk_cache::BackendImpl::CreateBackend(path, force_creation_, size_, + net::DISK_CACHE, + disk_cache::kNoRandom); +} + +void DiskCacheTestWithCache::InitDiskCacheImpl(const FilePath& path) { + if (mask_) + cache_impl_ = new disk_cache::BackendImpl(path, mask_); + else + cache_impl_ = new disk_cache::BackendImpl(path); + + cache_ = cache_impl_; + ASSERT_TRUE(NULL != cache_); + + if (size_) + EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); + + if (new_eviction_) + cache_impl_->SetNewEviction(); + + cache_impl_->SetFlags(disk_cache::kNoRandom); + ASSERT_TRUE(cache_impl_->Init()); +} + +void DiskCacheTestWithCache::TearDown() { + MessageLoop::current()->RunAllPending(); + delete cache_; + + if (!memory_only_ && integrity_) { + FilePath path = GetCacheFilePath(); + EXPECT_TRUE(CheckCacheIntegrity(path, new_eviction_)); + } + + PlatformTest::TearDown(); +} + +// We are expected to leak memory when simulating crashes. +void DiskCacheTestWithCache::SimulateCrash() { + ASSERT_TRUE(implementation_ && !memory_only_); + cache_impl_->ClearRefCountForTest(); + + delete cache_impl_; + FilePath path = GetCacheFilePath(); + EXPECT_TRUE(CheckCacheIntegrity(path, new_eviction_)); + + InitDiskCacheImpl(path); +} + +void DiskCacheTestWithCache::SetTestMode() { + ASSERT_TRUE(implementation_ && !memory_only_); + cache_impl_->SetUnitTestMode(); +} |