1 #include "document_utils.h"
2
3 #include <android-base/file.h>
4 #include <android-base/logging.h>
5
6 #include <algorithm>
7 #include <memory>
8 #include <string>
9
10 #include "../document.h"
11 #include "../file.h"
12 #include "../linux_fileops.h"
13 #include "../page.h"
14
15 using pdfClient::LinuxFileOps;
16
17 namespace pdfClient {
18 namespace testing {
19
GetTestDataDir()20 std::string GetTestDataDir() {
21 return android::base::GetExecutableDirectory();
22 }
23
GetTempFile(std::string filename)24 std::string GetTempFile(std::string filename) {
25 return GetTestDataDir() + "/" + filename;
26 }
27
CreateTestFilePath(const std::string file_name,const std::string resources_path)28 std::string CreateTestFilePath(const std::string file_name, const std::string resources_path) {
29 return GetTestDataDir() + "/" + resources_path + "/" + file_name;
30 }
31
LoadDocument(std::string_view path,const char * password)32 std::unique_ptr<pdfClient::Document> LoadDocument(std::string_view path, const char* password) {
33 LinuxFileOps::FDCloser in(open(path.data(), O_RDONLY));
34 CHECK_GT(in.get(), 0);
35
36 std::unique_ptr<pdfClient::Document> doc;
37 CHECK_EQ(pdfClient::LOADED,
38 pdfClient::Document::Load(std::make_unique<pdfClient::FileReader>(std::move(in)),
39 password,
40 /* closeFdOnFailure= */ true, &doc))
41 << "could not load " << path << " with password " << (password ? password : "nullptr");
42 return doc;
43 }
44
45 } // namespace testing
46 } // namespace pdfClient
47