1 // Copyright 2017 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef TESTING_FAKE_FILE_ACCESS_H_ 6 #define TESTING_FAKE_FILE_ACCESS_H_ 7 8 #include <memory> 9 10 #include "core/fxcrt/unowned_ptr.h" 11 #include "public/fpdf_dataavail.h" 12 #include "public/fpdfview.h" 13 #include "testing/range_set.h" 14 15 class FakeFileAccess { 16 public: 17 explicit FakeFileAccess(FPDF_FILEACCESS* file_access); 18 ~FakeFileAccess(); 19 GetFileAccess()20 FPDF_FILEACCESS* GetFileAccess() const { return file_access_wrapper_.get(); } GetFileAvail()21 FX_FILEAVAIL* GetFileAvail() const { return file_avail_.get(); } GetDownloadHints()22 FX_DOWNLOADHINTS* GetDownloadHints() const { return download_hints_.get(); } 23 24 FPDF_BOOL IsDataAvail(size_t offset, size_t size) const; 25 void AddSegment(size_t offset, size_t size); 26 27 unsigned long GetFileSize(); 28 29 int GetBlock(unsigned long position, unsigned char* pBuf, unsigned long size); 30 void SetRequestedDataAvailable(); 31 void SetWholeFileAvailable(); 32 33 private: 34 UnownedPtr<FPDF_FILEACCESS> file_access_; 35 std::unique_ptr<FPDF_FILEACCESS> file_access_wrapper_; 36 std::unique_ptr<FX_FILEAVAIL> file_avail_; 37 std::unique_ptr<FX_DOWNLOADHINTS> download_hints_; 38 RangeSet available_data_; 39 RangeSet requested_data_; 40 }; 41 42 #endif // TESTING_FAKE_FILE_ACCESS_H_ 43