1 // Copyright 2019 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_UTILS_FILE_UTIL_H_ 6 #define TESTING_UTILS_FILE_UTIL_H_ 7 8 #include <stdint.h> 9 10 #include <string> 11 #include <vector> 12 13 #include "public/fpdfview.h" 14 15 // Reads the entire contents of a file into a vector. Returns an empty vector on 16 // failure. Note that this function assumes reading an empty file is not a valid 17 // use case, and treats such an action as a failure. 18 std::vector<uint8_t> GetFileContents(const char* filename); 19 20 // Use an ordinary file anywhere a FPDF_FILEACCESS is required. 21 class FileAccessForTesting final : public FPDF_FILEACCESS { 22 public: 23 explicit FileAccessForTesting(const std::string& file_name); 24 25 private: 26 static int SGetBlock(void* param, 27 unsigned long pos, 28 unsigned char* pBuf, 29 unsigned long size); 30 31 int GetBlockImpl(unsigned long pos, unsigned char* pBuf, unsigned long size); 32 33 std::vector<uint8_t> file_contents_; 34 }; 35 36 #endif // TESTING_UTILS_FILE_UTIL_H_ 37