• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The PDFium Authors
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 DownloadHintsImpl;
16 class FileAccessWrapper;
17 class FileAvailImpl;
18 
19 class FakeFileAccess {
20  public:
21   explicit FakeFileAccess(FPDF_FILEACCESS* file_access);
22   ~FakeFileAccess();
23 
24   FPDF_FILEACCESS* GetFileAccess() const;
25   FX_FILEAVAIL* GetFileAvail() const;
26   FX_DOWNLOADHINTS* GetDownloadHints() const;
27 
28   FPDF_BOOL IsDataAvail(size_t offset, size_t size) const;
29   void AddSegment(size_t offset, size_t size);
30 
31   unsigned long GetFileSize();
32 
33   int GetBlock(unsigned long position, unsigned char* pBuf, unsigned long size);
34   void SetRequestedDataAvailable();
35   void SetWholeFileAvailable();
36 
37  private:
38   UnownedPtr<FPDF_FILEACCESS> file_access_;
39   std::unique_ptr<FileAccessWrapper> file_access_wrapper_;
40   std::unique_ptr<FileAvailImpl> file_avail_;
41   std::unique_ptr<DownloadHintsImpl> download_hints_;
42   RangeSet available_data_;
43   RangeSet requested_data_;
44 };
45 
46 #endif  // TESTING_FAKE_FILE_ACCESS_H_
47