aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-04-25 17:36:19 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2016-04-25 17:36:19 +0300
commit9dfb45148670f712f6d3cf7f5000a4b4e393d83d (patch)
treecd70f5183172c45821b04d256e7f875525578692 /tests
parent7d75dc6b474c33c8b20407aa37a33932cbf35620 (diff)
Fix timestamp from_string() compilation error appeared when compiled with clang++ and libc++0.3.0
Diffstat (limited to 'tests')
-rw-r--r--tests/timestamp/driver.cxx76
1 files changed, 53 insertions, 23 deletions
diff --git a/tests/timestamp/driver.cxx b/tests/timestamp/driver.cxx
index 0c0f2ef..4c366fc 100644
--- a/tests/timestamp/driver.cxx
+++ b/tests/timestamp/driver.cxx
@@ -4,10 +4,12 @@
#include <time.h> // tzset()
+#include <chrono>
#include <locale>
#include <clocale>
#include <cassert>
#include <sstream>
+#include <iomanip>
#include <iostream>
#include <system_error>
@@ -20,9 +22,9 @@ using namespace butl;
// same format string, ensure the output matches the input.
//
static bool
-parse (const char* in, const char* fmt, bool local, const char* out)
+parse (const char* in, const char* fmt, bool local, string out)
{
- if (out == nullptr)
+ if (out.empty ())
out = in;
try
@@ -43,7 +45,7 @@ parse (const char* in, const char* fmt, bool local, const char* out)
}
static bool
-parse (const char* in, const char* fmt, const char* out = nullptr)
+parse (const char* in, const char* fmt, const string& out = "")
{
return parse (in, fmt, true, out) && parse (in, fmt, false, out);
}
@@ -62,6 +64,20 @@ fail (const char* in, const char* fmt)
}
}
+// Convert nanoseconds to string according to the butl::duration period.
+//
+static string
+ns (unsigned long long t)
+{
+ duration d (chrono::duration_cast<duration> (chrono::nanoseconds (t)));
+ chrono::nanoseconds n (chrono::duration_cast<chrono::nanoseconds> (d));
+
+ ostringstream o;
+ o.fill ('0');
+ o << setw (9) << n.count ();
+ return o.str ();
+}
+
int
main ()
{
@@ -110,37 +126,51 @@ main ()
assert (parse ("Feb 11 19:31:10 2016 GMT", "%b %d %H:%M:%S%[.N] %Y"));
assert (parse ("2016-02-11 19:31:10 GMT", "%Y-%m-%d %H:%M:%S%[.N]"));
- assert (parse (
- "Feb 21 19:31:10.384902285 2016 GMT", "%b %d %H:%M:%S%[.N] %Y"));
- assert (parse (
- "2016-02-21 19:31:10.384902285 GMT", "%Y-%m-%d %H:%M:%S%[.N]"));
+ assert (parse ("Feb 21 19:31:10.384902285 2016 GMT",
+ "%b %d %H:%M:%S%[.N] %Y",
+ "Feb 21 19:31:10." + ns (384902285) + " 2016 GMT"));
- assert (parse (
- "Feb 21 19:31:10 .384902285 2016 GMT", "%b %d %H:%M:%S %[.N] %Y"));
- assert (parse (
- "2016-02-21 19:31:10 .384902285 GMT", "%Y-%m-%d %H:%M:%S %[.N]"));
+ assert (parse ("2016-02-21 19:31:10.384902285 GMT",
+ "%Y-%m-%d %H:%M:%S%[.N]",
+ "2016-02-21 19:31:10." + ns (384902285) + " GMT"));
+
+ assert (parse ("Feb 21 19:31:10 .384902285 2016 GMT",
+ "%b %d %H:%M:%S %[.N] %Y",
+ "Feb 21 19:31:10 ." + ns (384902285) + " 2016 GMT"));
+
+ assert (parse ("2016-02-21 19:31:10 .384902285 GMT",
+ "%Y-%m-%d %H:%M:%S %[.N]",
+ "2016-02-21 19:31:10 ." + ns (384902285) + " GMT"));
assert (parse (
"2016-02-21 19:31:10 .384902285 GMT",
"%Y-%m-%d %H:%M:%S %[.N]",
- "2016-02-21 19:31:10 .384902285 GMT"));
+ "2016-02-21 19:31:10 ." + ns (384902285) + " GMT"));
assert (parse (
"2016-02-21 19:31:10 .384902285 GMT",
"%Y-%m-%d %H:%M:%S %[.N]",
- "2016-02-21 19:31:10 .384902285 GMT"));
+ "2016-02-21 19:31:10 ." + ns (384902285) + " GMT"));
- assert (parse (
- "Feb 21 19:31:10 .384902285NS 2016 GMT", "%b %d %H:%M:%S %[.N]NS %Y"));
- assert (parse (
- "2016-02-21 19:31:10 .384902285NS GMT", "%Y-%m-%d %H:%M:%S %[.N]NS"));
+ assert (parse ("Feb 21 19:31:10 .384902285NS 2016 GMT",
+ "%b %d %H:%M:%S %[.N]NS %Y",
+ "Feb 21 19:31:10 ." + ns (384902285) + "NS 2016 GMT"));
- assert (parse (
- ".384902285 Feb 21 19:31:10 2016", "%[.N] %b %d %H:%M:%S %Y"));
- assert (parse (
- ".384902285 2016-02-21 19:31:10", "%[.N] %Y-%m-%d %H:%M:%S"));
- assert (parse (
- ".3849022852016-02-21 19:31:10", "%[.N]%Y-%m-%d %H:%M:%S"));
+ assert (parse ("2016-02-21 19:31:10 .384902285NS GMT",
+ "%Y-%m-%d %H:%M:%S %[.N]NS",
+ "2016-02-21 19:31:10 ." + ns (384902285) + "NS GMT"));
+
+ assert (parse (".384902285 Feb 21 19:31:10 2016",
+ "%[.N] %b %d %H:%M:%S %Y",
+ "." + ns (384902285) + " Feb 21 19:31:10 2016"));
+
+ assert (parse (".384902285 2016-02-21 19:31:10",
+ "%[.N] %Y-%m-%d %H:%M:%S",
+ "." + ns (384902285) + " 2016-02-21 19:31:10"));
+
+ assert (parse (".3849022852016-02-21 19:31:10",
+ "%[.N]%Y-%m-%d %H:%M:%S",
+ "." + ns (384902285) + "2016-02-21 19:31:10"));
/*
setlocale (LC_ALL, "de_DE.utf-8");