Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
file_system_test_base.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef PAGESPEED_KERNEL_BASE_FILE_SYSTEM_TEST_BASE_H_
20 #define PAGESPEED_KERNEL_BASE_FILE_SYSTEM_TEST_BASE_H_
21 
28 
29 namespace net_instaweb {
30 
31 class Timer;
32 
34 
38 class FileSystemTest : public testing::Test {
39  protected:
41  virtual ~FileSystemTest();
42 
43  void CheckDoesNotExist(const GoogleString& filename);
44 
45  void CheckRead(const GoogleString& filename,
46  const GoogleString& expected_contents);
47 
48  void CheckInputFileRead(const GoogleString& filename,
49  const GoogleString& expected_contents);
50 
54  virtual void DeleteRecursively(const StringPiece& filename) = 0;
55 
57  virtual FileSystem* file_system() = 0;
58 
60  virtual Timer* timer() = 0;
61 
63  const GoogleString& test_tmpdir() { return test_tmpdir_; }
64 
65  GoogleString WriteNewFile(const StringPiece& suffix,
66  const GoogleString& content);
67 
72  virtual int FileSize(StringPiece contents) const = 0;
73 
74  int FileContentSize(StringPiece contents) const {
75  return contents.size();
76  }
77 
80  int FileBlockSize(StringPiece contents, int64 default_file_size) const {
81  return ((contents.size() + kBlockSize - 1) / kBlockSize) * kBlockSize +
82  default_file_size;
83  }
84 
88  virtual int DefaultDirSize() const = 0;
89 
93  void TestWriteRead();
94  void TestTemp();
95  void TestAppend();
96  void TestRename();
97  void TestRemove();
98  void TestExists();
99  void TestCreateFileInDir();
100  void TestMakeDir();
101  void TestRemoveDir();
102  void TestIsDir();
103  void TestRecursivelyMakeDir();
104  void TestRecursivelyMakeDir_NoPermission();
105  void TestRecursivelyMakeDir_FileInPath();
106  void TestListContents();
107  void TestAtime();
108  void TestMtime();
109  void TestDirInfo();
110  void TestLock();
111  void TestLockTimeout();
112  void TestLockBumping();
113 
114  GoogleMessageHandler handler_;
115  GoogleString test_tmpdir_;
116 
117  private:
119  static const int kBlockSize = 4096;
120 
121 
122 };
123 
125  public:
126  CountingProgressNotifier() : count_(0) {}
127  void Notify() override { count_++; }
128  int get_count() { return count_; }
129 
130  private:
131  int count_;
132 };
133 
134 }
135 
136 #endif
Definition: file_system.h:126
virtual Timer * timer()=0
Pointer to a timer to use in tests.
virtual int DefaultDirSize() const =0
const GoogleString & test_tmpdir()
Provide a temporary directory for tests to put files in.
Definition: file_system_test_base.h:63
virtual FileSystem * file_system()=0
Provide a pointer to your favorite filesystem implementation.
virtual int FileSize(StringPiece contents) const =0
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
int FileBlockSize(StringPiece contents, int64 default_file_size) const
Definition: file_system_test_base.h:80
Definition: file_system_test_base.h:124
Definition: file_system.h:76
Definition: file_system_test_base.h:38
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
virtual void DeleteRecursively(const StringPiece &filename)=0
Definition: google_message_handler.h:35