Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: net/disk_cache/disk_cache_test_util.h

Issue 48003: Make sure that net_perftest doesn't leave temporary files. (Closed)
Patch Set: Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/disk_cache/disk_cache_perftest.cc ('k') | net/disk_cache/disk_cache_test_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/file_path.h"
10 #include "base/message_loop.h" 11 #include "base/message_loop.h"
11 #include "base/task.h" 12 #include "base/task.h"
12 13
13 // Re-creates a given test file inside the cache test folder. 14 // Re-creates a given test file inside the cache test folder.
14 bool CreateCacheTestFile(const wchar_t* name); 15 bool CreateCacheTestFile(const wchar_t* name);
15 16
16 // Deletes all file son the cache. 17 // Deletes all file son the cache.
17 bool DeleteCache(const wchar_t* path); 18 bool DeleteCache(const wchar_t* path);
18 19
19 // Gets the path to the cache test folder. 20 // Gets the path to the cache test folder.
20 std::wstring GetCachePath(); 21 std::wstring GetCachePath();
21 22
22 // Fills buffer with random values (may contain nulls unless no_nulls is true). 23 // Fills buffer with random values (may contain nulls unless no_nulls is true).
23 void CacheTestFillBuffer(char* buffer, size_t len, bool no_nulls); 24 void CacheTestFillBuffer(char* buffer, size_t len, bool no_nulls);
24 25
25 // Deletes all files matching a pattern. 26 // Deletes all files matching a pattern.
26 // Do not call this function with "*" as search_name. 27 // Do not call this function with "*" as search_name.
27 bool DeleteFiles(const wchar_t* path, const wchar_t* search_name); 28 bool DeleteFiles(const wchar_t* path, const wchar_t* search_name);
28 29
29 // Generates a random key of up to 200 bytes. 30 // Generates a random key of up to 200 bytes.
30 std::string GenerateKey(bool same_length); 31 std::string GenerateKey(bool same_length);
31 32
32 // Returns true if the cache is not corrupt. 33 // Returns true if the cache is not corrupt.
33 bool CheckCacheIntegrity(const std::wstring& path); 34 bool CheckCacheIntegrity(const std::wstring& path);
34 35
36 // Helper class which ensures that the cache dir returned by GetCachePath exists
37 // and is clear in ctor and that the directory gets deleted in dtor.
38 class ScopedTestCache {
39 public:
40 ScopedTestCache();
41 ~ScopedTestCache();
42
43 FilePath path() const { return FilePath::FromWStringHack(path_); }
44 std::wstring path_wstring() const { return path_; }
45
46 private:
47 const std::wstring path_; // Path to the cache test folder.
48
49 DISALLOW_COPY_AND_ASSIGN(ScopedTestCache);
50 };
51
35 // ----------------------------------------------------------------------- 52 // -----------------------------------------------------------------------
36 53
37 // Simple callback to process IO completions from the cache. 54 // Simple callback to process IO completions from the cache.
38 class CallbackTest : public CallbackRunner< Tuple1<int> > { 55 class CallbackTest : public CallbackRunner< Tuple1<int> > {
39 public: 56 public:
40 explicit CallbackTest(int id) : id_(id), reuse_(0) {} 57 explicit CallbackTest(int id) : id_(id), reuse_(0) {}
41 explicit CallbackTest(int id, bool reuse) : id_(id), reuse_(reuse ? 0 : 1) {} 58 explicit CallbackTest(int id, bool reuse) : id_(id), reuse_(reuse ? 0 : 1) {}
42 ~CallbackTest() {} 59 ~CallbackTest() {}
43 60
44 virtual void RunWithParams(const Tuple1<int>& params); 61 virtual void RunWithParams(const Tuple1<int>& params);
(...skipping 29 matching lines...) Expand all
74 base::RepeatingTimer<MessageLoopHelper> timer_; 91 base::RepeatingTimer<MessageLoopHelper> timer_;
75 int num_callbacks_; 92 int num_callbacks_;
76 int num_iterations_; 93 int num_iterations_;
77 int last_; 94 int last_;
78 bool completed_; 95 bool completed_;
79 96
80 DISALLOW_COPY_AND_ASSIGN(MessageLoopHelper); 97 DISALLOW_COPY_AND_ASSIGN(MessageLoopHelper);
81 }; 98 };
82 99
83 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_ 100 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_
OLDNEW
« no previous file with comments | « net/disk_cache/disk_cache_perftest.cc ('k') | net/disk_cache/disk_cache_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698