| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_ | 5 #ifndef NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_ |
| 6 #define NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_ | 6 #define NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/scoped_temp_dir.h" | |
| 15 #include "base/timer.h" | 14 #include "base/timer.h" |
| 16 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 17 | 16 |
| 18 // Re-creates a given test file inside the cache test folder. | 17 // Re-creates a given test file inside the cache test folder. |
| 19 bool CreateCacheTestFile(const FilePath& name); | 18 bool CreateCacheTestFile(const FilePath& name); |
| 20 | 19 |
| 21 // Deletes all file son the cache. | 20 // Deletes all file son the cache. |
| 22 bool DeleteCache(const FilePath& path); | 21 bool DeleteCache(const FilePath& path); |
| 23 | 22 |
| 24 // Copies a set of cache files from the data folder to the destination folder. | 23 // Copies a set of cache files from the data folder to the test folder. |
| 25 bool CopyTestCache(const std::string& name, const FilePath& destination); | 24 bool CopyTestCache(const std::string& name); |
| 25 |
| 26 // Gets the path to the cache test folder. |
| 27 FilePath GetCacheFilePath(); |
| 26 | 28 |
| 27 // Fills buffer with random values (may contain nulls unless no_nulls is true). | 29 // Fills buffer with random values (may contain nulls unless no_nulls is true). |
| 28 void CacheTestFillBuffer(char* buffer, size_t len, bool no_nulls); | 30 void CacheTestFillBuffer(char* buffer, size_t len, bool no_nulls); |
| 29 | 31 |
| 30 // Generates a random key of up to 200 bytes. | 32 // Generates a random key of up to 200 bytes. |
| 31 std::string GenerateKey(bool same_length); | 33 std::string GenerateKey(bool same_length); |
| 32 | 34 |
| 33 // Returns true if the cache is not corrupt. | 35 // Returns true if the cache is not corrupt. |
| 34 bool CheckCacheIntegrity(const FilePath& path, bool new_eviction); | 36 bool CheckCacheIntegrity(const FilePath& path, bool new_eviction); |
| 35 | 37 |
| 36 // Helper class which ensures that the cache dir returned by GetCacheFilePath | 38 // Helper class which ensures that the cache dir returned by GetCacheFilePath |
| 37 // exists and is clear in ctor and that the directory gets deleted in dtor. | 39 // exists and is clear in ctor and that the directory gets deleted in dtor. |
| 38 class ScopedTestCache { | 40 class ScopedTestCache { |
| 39 public: | 41 public: |
| 40 ScopedTestCache(); | 42 ScopedTestCache(); |
| 43 // Use a specific folder name. |
| 44 explicit ScopedTestCache(const std::string& name); |
| 41 ~ScopedTestCache(); | 45 ~ScopedTestCache(); |
| 42 | 46 |
| 43 FilePath path() const { return temp_dir_.path(); } | 47 FilePath path() const { return path_; } |
| 44 | 48 |
| 45 private: | 49 private: |
| 46 ScopedTempDir temp_dir_; | 50 const FilePath path_; // Path to the cache test folder. |
| 47 | 51 |
| 48 DISALLOW_COPY_AND_ASSIGN(ScopedTestCache); | 52 DISALLOW_COPY_AND_ASSIGN(ScopedTestCache); |
| 49 }; | 53 }; |
| 50 | 54 |
| 51 // ----------------------------------------------------------------------- | 55 // ----------------------------------------------------------------------- |
| 52 | 56 |
| 53 // Simple callback to process IO completions from the cache. It allows tests | 57 // Simple callback to process IO completions from the cache. It allows tests |
| 54 // with multiple simultaneous IO operations. | 58 // with multiple simultaneous IO operations. |
| 55 class CallbackTest : public CallbackRunner< Tuple1<int> > { | 59 class CallbackTest : public CallbackRunner< Tuple1<int> > { |
| 56 public: | 60 public: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 base::RepeatingTimer<MessageLoopHelper> timer_; | 96 base::RepeatingTimer<MessageLoopHelper> timer_; |
| 93 int num_callbacks_; | 97 int num_callbacks_; |
| 94 int num_iterations_; | 98 int num_iterations_; |
| 95 int last_; | 99 int last_; |
| 96 bool completed_; | 100 bool completed_; |
| 97 | 101 |
| 98 DISALLOW_COPY_AND_ASSIGN(MessageLoopHelper); | 102 DISALLOW_COPY_AND_ASSIGN(MessageLoopHelper); |
| 99 }; | 103 }; |
| 100 | 104 |
| 101 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_ | 105 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_ |
| OLD | NEW |