diff options
author | Ryan Harrison <rharrison@chromium.org> | 2018-08-10 18:55:46 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-08-10 18:55:46 +0000 |
commit | 70cca3663a0ea6c290b55c290ba5eb1f1c9db572 (patch) | |
tree | 795a8448eb76b90320d46aca1808e6d64a6b3ae5 /core | |
parent | 6655d95a8586c1f272d5d418bb63514abbe1d695 (diff) | |
download | pdfium-70cca3663a0ea6c290b55c290ba5eb1f1c9db572.tar.xz |
Add proxy for syscall time
This CL adds a proxy, FXSYS_time, for the time syscall, so that a
testing mechanism can be implemented. Specically there is now a flag
for pdfium_test, --time=, that allows setting the time since the epoch
that will be returned. This plumbed all the way down into the proxy
and allows for stable results for tests that depend on getting the
current time.
There are other places in the code base that will need to be patched
like this, that will be dealt with in follow on CLs.
BUG=pdfium:1104
Change-Id: I2de185f8d47abe46704dd579c13a54948b7f81e0
Reviewed-on: https://pdfium-review.googlesource.com/39750
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/fxcrt/fx_extension.cpp | 14 | ||||
-rw-r--r-- | core/fxcrt/fx_extension.h | 3 |
2 files changed, 17 insertions, 0 deletions
diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp index c754a85508..8320b45db4 100644 --- a/core/fxcrt/fx_extension.cpp +++ b/core/fxcrt/fx_extension.cpp @@ -11,6 +11,9 @@ #include <limits> #include "third_party/base/compiler_specific.h" +#include "third_party/base/ptr_util.h" + +time_t (*time_func)() = []() -> time_t { return time(nullptr); }; float FXSYS_wcstof(const wchar_t* pwsStr, int32_t iLength, int32_t* pUsedLen) { ASSERT(pwsStr); @@ -167,3 +170,14 @@ size_t FXSYS_ToUTF16BE(uint32_t unicode, char* buf) { FXSYS_IntToFourHexChars(0xDC00 + unicode % 0x400, buf + 4); return 8; } + +void FXSYS_SetTimeFunction(time_t (*func)()) { + time_func = func ? func : []() -> time_t { return time(nullptr); }; +} + +time_t FXSYS_time(time_t* tloc) { + time_t ret_val = time_func(); + if (tloc) + *tloc = ret_val; + return ret_val; +} diff --git a/core/fxcrt/fx_extension.h b/core/fxcrt/fx_extension.h index dcdd64e1fc..6a49ee1116 100644 --- a/core/fxcrt/fx_extension.h +++ b/core/fxcrt/fx_extension.h @@ -109,4 +109,7 @@ bool FXSYS_SafeLT(const T& lhs, const T& rhs) { return lhs < rhs; } +void FXSYS_SetTimeFunction(time_t (*func)()); +time_t FXSYS_time(time_t* tloc); + #endif // CORE_FXCRT_FX_EXTENSION_H_ |