summaryrefslogtreecommitdiff
path: root/core/fxcrt/fx_system_unittest.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-04-24 15:55:11 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-04-24 23:23:34 +0000
commit9ff306d958e178843b292044ce208cda86adc825 (patch)
treec3043b4242fe89ce299ca4a653fd23ebbf965518 /core/fxcrt/fx_system_unittest.cpp
parent64ee2c3fe2a21d0471595ae486d7e55e2eadfb57 (diff)
downloadpdfium-9ff306d958e178843b292044ce208cda86adc825.tar.xz
Add FXSYS_wcsftime() to avoid termination on win.
Bug: 712725 Change-Id: I3384385176410964a87b12c2587f68247ea80cc9 Reviewed-on: https://pdfium-review.googlesource.com/4454 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcrt/fx_system_unittest.cpp')
-rw-r--r--core/fxcrt/fx_system_unittest.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/core/fxcrt/fx_system_unittest.cpp b/core/fxcrt/fx_system_unittest.cpp
index def0043bab..5a7660d256 100644
--- a/core/fxcrt/fx_system_unittest.cpp
+++ b/core/fxcrt/fx_system_unittest.cpp
@@ -160,3 +160,40 @@ TEST(fxcrt, FXSYS_i64toa) {
}
#endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
+
+TEST(fxcrt, FXSYS_wcsftime) {
+ struct tm good_time = {};
+ good_time.tm_year = 74; // 1900-based.
+ good_time.tm_mon = 7; // 0-based.
+ good_time.tm_mday = 9; // 1-based.
+ good_time.tm_hour = 11;
+ good_time.tm_min = 59;
+ good_time.tm_sec = 59;
+
+ wchar_t buf[100] = {};
+ EXPECT_EQ(19u, FXSYS_wcsftime(buf, FX_ArraySize(buf), L"%Y-%m-%dT%H:%M:%S",
+ &good_time));
+ EXPECT_EQ(std::wstring(L"1974-08-09T11:59:59"), buf);
+
+ // Ensure wcsftime handles bad years, etc. without crashing.
+ struct tm bad_time = {};
+ bad_time.tm_year = -1;
+ bad_time.tm_mon = -1;
+ bad_time.tm_mday = -1;
+ bad_time.tm_hour = -1;
+ bad_time.tm_min = -1;
+ bad_time.tm_sec = -1;
+
+ FXSYS_wcsftime(buf, FX_ArraySize(buf), L"%y-%m-%dT%H:%M:%S", &bad_time);
+
+ // Ensure wcsftime handles bad-ish day without crashing (Feb 30).
+ struct tm feb_time = {};
+ feb_time.tm_year = 115; // 1900-based.
+ feb_time.tm_mon = 1; // 0-based.
+ feb_time.tm_mday = 30; // 1-based.
+ feb_time.tm_hour = 12;
+ feb_time.tm_min = 00;
+ feb_time.tm_sec = 00;
+
+ FXSYS_wcsftime(buf, FX_ArraySize(buf), L"%y-%m-%dT%H:%M:%S", &feb_time);
+}