initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1 | // Copyright 2008, Google Inc. |
| 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright |
| 9 | // notice, this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above |
| 11 | // copyright notice, this list of conditions and the following disclaimer |
| 12 | // in the documentation and/or other materials provided with the |
| 13 | // distribution. |
| 14 | // * Neither the name of Google Inc. nor the names of its |
| 15 | // contributors may be used to endorse or promote products derived from |
| 16 | // this software without specific prior written permission. |
| 17 | // |
| 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | |
| 30 | #ifndef NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H__ |
| 31 | #define NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H__ |
| 32 | |
| 33 | #include "base/basictypes.h" |
| 34 | #include "testing/gtest/include/gtest/gtest.h" |
| 35 | |
| 36 | namespace disk_cache { |
| 37 | |
| 38 | class Backend; |
| 39 | class BackendImpl; |
| 40 | class MemBackendImpl; |
| 41 | |
| 42 | } |
| 43 | |
| 44 | // Provides basic support for cache related tests. |
| 45 | class DiskCacheTestBase : public testing::Test { |
| 46 | protected: |
| 47 | DiskCacheTestBase() |
| 48 | : cache_(NULL), cache_impl_(NULL), mem_cache_(NULL), mask_(0), size_(0), |
[email protected] | a9da16d | 2008-07-30 21:41:54 | [diff] [blame^] | 49 | memory_only_(false), implementation_(false), force_creation_(false), |
| 50 | first_cleanup_(true) {} |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 51 | |
| 52 | void InitCache(); |
| 53 | virtual void TearDown(); |
| 54 | void SimulateCrash(); |
[email protected] | a9da16d | 2008-07-30 21:41:54 | [diff] [blame^] | 55 | void SetTestMode(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 56 | |
| 57 | void SetMemoryOnlyMode() { |
| 58 | memory_only_ = true; |
| 59 | } |
| 60 | |
| 61 | // Use the implementation directly instead of the factory provided object. |
| 62 | void SetDirectMode() { |
| 63 | implementation_ = true; |
| 64 | } |
| 65 | |
| 66 | void SetMask(uint32 mask) { |
| 67 | mask_ = mask; |
| 68 | } |
| 69 | |
| 70 | void SetMaxSize(int size); |
| 71 | |
| 72 | // Deletes and re-creates the files on initialization errors. |
| 73 | void SetForceCreation() { |
| 74 | force_creation_ = true; |
| 75 | } |
| 76 | |
[email protected] | a9da16d | 2008-07-30 21:41:54 | [diff] [blame^] | 77 | void DisableFirstCleanup() { |
| 78 | first_cleanup_ = false; |
| 79 | } |
| 80 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 81 | // cache_ will always have a valid object, regardless of how the cache was |
| 82 | // initialized. The implementation pointers can be NULL. |
| 83 | disk_cache::Backend* cache_; |
| 84 | disk_cache::BackendImpl* cache_impl_; |
| 85 | disk_cache::MemBackendImpl* mem_cache_; |
| 86 | |
| 87 | uint32 mask_; |
| 88 | int size_; |
| 89 | bool memory_only_; |
| 90 | bool implementation_; |
| 91 | bool force_creation_; |
[email protected] | a9da16d | 2008-07-30 21:41:54 | [diff] [blame^] | 92 | bool first_cleanup_; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 93 | |
| 94 | private: |
| 95 | void InitMemoryCache(); |
| 96 | void InitDiskCache(); |
| 97 | }; |
| 98 | |
| 99 | #endif // NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H__ |