summaryrefslogtreecommitdiff
path: root/core/fxcrt
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-10-22 19:34:53 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-22 19:34:53 +0000
commit706e187ed8be44eb50bdf7024674930a4e10fa45 (patch)
tree9157a2c483b35d8e2ac11f655c29322594ad8d0b /core/fxcrt
parent2f62d36bfac781428f3896b443177e033be4c554 (diff)
downloadpdfium-706e187ed8be44eb50bdf7024674930a4e10fa45.tar.xz
Fix timezone inconsistency in document methods test.
We do this by adding an override that forces GM time on everyone when run from the test harness. Generalize presubmit warnings so that the new function passes. De-duplicate lambda capture in place of static function. Change-Id: I15b34bea558baf1763476b36f0bca76614984107 Reviewed-on: https://pdfium-review.googlesource.com/c/44390 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcrt')
-rw-r--r--core/fxcrt/fx_extension.cpp27
-rw-r--r--core/fxcrt/fx_extension.h7
2 files changed, 31 insertions, 3 deletions
diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp
index 8e78e4d789..443e301630 100644
--- a/core/fxcrt/fx_extension.cpp
+++ b/core/fxcrt/fx_extension.cpp
@@ -12,7 +12,20 @@
#include "third_party/base/compiler_specific.h"
-time_t (*time_func)() = []() -> time_t { return time(nullptr); };
+namespace {
+
+time_t DefaultTimeFunction() {
+ return time(nullptr);
+}
+
+struct tm* DefaultLocaltimeFunction(const time_t* tp) {
+ return localtime(tp);
+}
+
+time_t (*g_time_func)() = DefaultTimeFunction;
+struct tm* (*g_localtime_func)(const time_t*) = DefaultLocaltimeFunction;
+
+} // namespace
float FXSYS_wcstof(const wchar_t* pwsStr, int32_t iLength, int32_t* pUsedLen) {
ASSERT(pwsStr);
@@ -171,12 +184,20 @@ size_t FXSYS_ToUTF16BE(uint32_t unicode, char* buf) {
}
void FXSYS_SetTimeFunction(time_t (*func)()) {
- time_func = func ? func : []() -> time_t { return time(nullptr); };
+ g_time_func = func ? func : DefaultTimeFunction;
+}
+
+void FXSYS_SetLocaltimeFunction(struct tm* (*func)(const time_t*)) {
+ g_localtime_func = func ? func : DefaultLocaltimeFunction;
}
time_t FXSYS_time(time_t* tloc) {
- time_t ret_val = time_func();
+ time_t ret_val = g_time_func();
if (tloc)
*tloc = ret_val;
return ret_val;
}
+
+struct tm* FXSYS_localtime(const time_t* tp) {
+ return g_localtime_func(tp);
+}
diff --git a/core/fxcrt/fx_extension.h b/core/fxcrt/fx_extension.h
index c1cd188c81..38f9fd5993 100644
--- a/core/fxcrt/fx_extension.h
+++ b/core/fxcrt/fx_extension.h
@@ -7,6 +7,8 @@
#ifndef CORE_FXCRT_FX_EXTENSION_H_
#define CORE_FXCRT_FX_EXTENSION_H_
+#include <time.h>
+
#include <cctype>
#include <cmath>
#include <cwctype>
@@ -106,7 +108,12 @@ bool FXSYS_SafeLT(const T& lhs, const T& rhs) {
return lhs < rhs;
}
+// Override time/localtime functions for test consistency.
void FXSYS_SetTimeFunction(time_t (*func)());
+void FXSYS_SetLocaltimeFunction(struct tm* (*func)(const time_t*));
+
+// Replacements for time/localtime that respect overrides.
time_t FXSYS_time(time_t* tloc);
+struct tm* FXSYS_localtime(const time_t* tp);
#endif // CORE_FXCRT_FX_EXTENSION_H_