summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
Diffstat (limited to 'samples')
-rw-r--r--samples/pdfium_test.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc
index 14a62a4bc4..b7538a8c6f 100644
--- a/samples/pdfium_test.cc
+++ b/samples/pdfium_test.cc
@@ -115,6 +115,7 @@ struct Options {
std::string font_directory;
int first_page = 0; // First 0-based page number to renderer.
int last_page = 0; // Last 0-based page number to renderer.
+ time_t time = -1;
};
Optional<std::string> ExpandDirectoryPath(const std::string& path) {
@@ -424,6 +425,17 @@ bool ParseCommandLine(const std::vector<std::string>& args,
}
} else if (cur_arg == "--md5") {
options->md5 = true;
+ } else if (cur_arg.size() > 7 && cur_arg.compare(0, 7, "--time=") == 0) {
+ if (options->time > -1) {
+ fprintf(stderr, "Duplicate --time argument\n");
+ return false;
+ }
+ const std::string time_string = cur_arg.substr(7);
+ std::stringstream(time_string) >> options->time;
+ if (options->time < 0) {
+ fprintf(stderr, "Invalid --time argument, must be non-negative\n");
+ return false;
+ }
} else if (cur_arg.size() >= 2 && cur_arg[0] == '-' && cur_arg[1] == '-') {
fprintf(stderr, "Unrecognized argument %s\n", cur_arg.c_str());
return false;
@@ -834,6 +846,7 @@ constexpr char kUsageString[] =
" --skp - write page images <pdf-name>.<page-number>.skp\n"
#endif
" --md5 - write output image paths and their md5 hashes to stdout.\n"
+ " --time=<number> - Seconds since the epoch to set system time.\n"
"";
} // namespace
@@ -889,6 +902,13 @@ int main(int argc, const char* argv[]) {
FSDK_SetUnSpObjProcessHandler(&unsupported_info);
+ if (options.time > -1) {
+ // This must be a static var to avoid explicit capture, so the lambda can be
+ // converted to a function ptr.
+ static time_t time_ret = options.time;
+ FSDK_SetTimeFunction([]() -> time_t { return time_ret; });
+ }
+
for (const std::string& filename : files) {
size_t file_length = 0;
std::unique_ptr<char, pdfium::FreeDeleter> file_contents =