summaryrefslogtreecommitdiff
path: root/testing/fake_file_access.h
diff options
context:
space:
mode:
authorArtem Strygin <art-snake@yandex-team.ru>2017-09-28 18:46:03 +0300
committerChromium commit bot <commit-bot@chromium.org>2017-09-28 15:59:08 +0000
commit0e60b9ef2b79de52ef62101abae2af7292e879b7 (patch)
tree9f71519f2a364ee6702219a44de7fdb1def18cc7 /testing/fake_file_access.h
parent1ca7173cd85adcd58766fc89f95c3dc163efa17a (diff)
downloadpdfium-0e60b9ef2b79de52ef62101abae2af7292e879b7.tar.xz
Implement FakeFileAccess.
Update embedder tests to simulate unavailable data and download requests. Change-Id: I634fa89d2a0c859243e849752936da87568909f4 Reviewed-on: https://pdfium-review.googlesource.com/11890 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'testing/fake_file_access.h')
-rw-r--r--testing/fake_file_access.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/testing/fake_file_access.h b/testing/fake_file_access.h
new file mode 100644
index 0000000000..1328b16392
--- /dev/null
+++ b/testing/fake_file_access.h
@@ -0,0 +1,42 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TESTING_FAKE_FILE_ACCESS_H_
+#define TESTING_FAKE_FILE_ACCESS_H_
+
+#include <memory>
+
+#include "core/fxcrt/unowned_ptr.h"
+#include "public/fpdf_dataavail.h"
+#include "public/fpdfview.h"
+#include "testing/range_set.h"
+
+class FakeFileAccess {
+ public:
+ explicit FakeFileAccess(FPDF_FILEACCESS* file_access);
+ ~FakeFileAccess();
+
+ FPDF_FILEACCESS* GetFileAccess() const { return file_access_wrapper_.get(); }
+ FX_FILEAVAIL* GetFileAvail() const { return file_avail_.get(); }
+ FX_DOWNLOADHINTS* GetDownloadHints() const { return download_hints_.get(); }
+
+ FPDF_BOOL IsDataAvail(size_t offset, size_t size) const;
+ void AddSegment(size_t offset, size_t size);
+
+ unsigned long GetFileSize();
+
+ int GetBlock(unsigned long position, unsigned char* pBuf, unsigned long size);
+ void SetRequestedDataAvailable();
+ void SetWholeFileAvailable();
+
+ private:
+ fxcrt::UnownedPtr<FPDF_FILEACCESS> file_access_;
+ std::unique_ptr<FPDF_FILEACCESS> file_access_wrapper_;
+ std::unique_ptr<FX_FILEAVAIL> file_avail_;
+ std::unique_ptr<FX_DOWNLOADHINTS> download_hints_;
+ RangeSet available_data_;
+ RangeSet requested_data_;
+};
+
+#endif // TESTING_FAKE_FILE_ACCESS_H_