Page Speed Optimization Libraries  1.5.27.2
net/instaweb/util/public/file_system_test.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00018 
00019 #ifndef NET_INSTAWEB_UTIL_PUBLIC_FILE_SYSTEM_TEST_H_
00020 #define NET_INSTAWEB_UTIL_PUBLIC_FILE_SYSTEM_TEST_H_
00021 
00022 #include "net/instaweb/util/public/basictypes.h"
00023 #include "net/instaweb/util/public/google_message_handler.h"
00024 #include "net/instaweb/util/public/gtest.h"
00025 #include "net/instaweb/util/public/string.h"
00026 #include "net/instaweb/util/public/string_util.h"
00027 
00028 namespace net_instaweb {
00029 
00030 class FileSystem;
00031 class Timer;
00032 
00036 class FileSystemTest : public testing::Test {
00037  protected:
00038   FileSystemTest();
00039   virtual ~FileSystemTest();
00040 
00041   void CheckDoesNotExist(const GoogleString& filename);
00042 
00043   void CheckRead(const GoogleString& filename,
00044                  const GoogleString& expected_contents);
00045 
00046   void CheckInputFileRead(const GoogleString& filename,
00047                           const GoogleString& expected_contents);
00048 
00052   virtual void DeleteRecursively(const StringPiece& filename) = 0;
00053 
00055   virtual FileSystem* file_system() = 0;
00056 
00058   virtual Timer* timer() = 0;
00059 
00061   const GoogleString& test_tmpdir() { return test_tmpdir_; }
00062 
00063   GoogleString WriteNewFile(const StringPiece& suffix,
00064                             const GoogleString& content);
00065 
00070   virtual int FileSize(StringPiece contents) const = 0;
00071 
00072   int FileContentSize(StringPiece contents) const {
00073     return contents.size();
00074   }
00075 
00078   int FileBlockSize(StringPiece contents, int64 default_file_size) const {
00079     return ((contents.size() + kBlockSize - 1) / kBlockSize) * kBlockSize +
00080         default_file_size;
00081   }
00082 
00086   virtual int DefaultDirSize() const = 0;
00087 
00091   void TestWriteRead();
00092   void TestTemp();
00093   void TestAppend();
00094   void TestRename();
00095   void TestRemove();
00096   void TestExists();
00097   void TestCreateFileInDir();
00098   void TestMakeDir();
00099   void TestRemoveDir();
00100   void TestIsDir();
00101   void TestRecursivelyMakeDir();
00102   void TestRecursivelyMakeDir_NoPermission();
00103   void TestRecursivelyMakeDir_FileInPath();
00104   void TestListContents();
00105   void TestAtime();
00106   void TestMtime();
00107   void TestDirInfo();
00108   void TestLock();
00109   void TestLockTimeout();
00110 
00111   GoogleMessageHandler handler_;
00112   GoogleString test_tmpdir_;
00113 
00114  private:
00116   static const int kBlockSize = 4096;
00117 
00118   DISALLOW_COPY_AND_ASSIGN(FileSystemTest);
00119 };
00120 
00121 }  
00122 
00123 #endif  ///< NET_INSTAWEB_UTIL_PUBLIC_FILE_SYSTEM_TEST_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines