ts_TimeStamp.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
23 #include <icl_core/TimeStamp.h>
24 
26 
27 namespace icl_core {
28 
29 std::ostream& operator << (std::ostream& os, const TimeStamp& t)
30 {
31  return os << t.formatIso8601BasicUTC();
32 }
33 
34 }
35 
36 #include <boost/test/unit_test.hpp>
37 
38 BOOST_AUTO_TEST_SUITE(ts_TimeStamp)
39 
40 BOOST_AUTO_TEST_CASE(CheckISO8601RoundTrip)
41 {
42  {
43  TimeStamp t1(0, 0);
45  BOOST_CHECK_EQUAL(t1, t2);
46  }
47  {
48  TimeStamp t1(1000000000, 123456789);
50  BOOST_CHECK_EQUAL(t1, t2);
51  }
52  {
53  TimeStamp t1(2000000000, 12345);
55  BOOST_CHECK_EQUAL(t1, t2);
56  }
57  {
58  TimeStamp t1(2147483647, 999999999);
60  BOOST_CHECK_EQUAL(t1, t2);
61  }
62  // Test some random values.
63  for (uint64_t secs = 1; secs < 2000000000; secs += 72836471)
64  {
65  {
66  TimeStamp t1(secs, 0);
68  BOOST_CHECK_EQUAL(t1, t2);
69  }
70  {
71  TimeStamp t1(secs, 999999999);
73  BOOST_CHECK_EQUAL(t1, t2);
74  }
75  }
76 }
77 
78 BOOST_AUTO_TEST_CASE(CheckISO8601UTCConversion)
79 {
80  {
81  std::string s = "19700101T000000,000000000";
83  TimeStamp t2(0, 0);
84  BOOST_CHECK_EQUAL(t1, t2);
85  }
86  {
87  std::string s = "20040916T235959,25";
89  TimeStamp t2(1095379199, 250000000);
90  BOOST_CHECK_EQUAL(t1, t2);
91  }
92  {
93  std::string s = "20130709T125530,123456789";
95  TimeStamp t2(1373374530, 123456789);
96  BOOST_CHECK_EQUAL(t1, t2);
97  }
98  {
99  // 32-bit signed timestamp maximum.
100  std::string s = "20380119T031407,999999999";
102  TimeStamp t2(2147483647, 999999999);
103  BOOST_CHECK_EQUAL(t1, t2);
104  }
105 }
106 
107 BOOST_AUTO_TEST_SUITE_END()
Represents absolute times.
Definition: TimeStamp.h:61
std::ostream & operator<<(std::ostream &os, StampedBase const &stamped)
Definition: DataHeader.cpp:27
BOOST_AUTO_TEST_CASE(CheckISO8601RoundTrip)
unsigned __int64 uint64_t
Definition: msvc_stdint.h:103
String formatIso8601BasicUTC() const
Definition: TimeStamp.cpp:249
static TimeStamp fromIso8601BasicUTC(const String &str)
Definition: TimeStamp.cpp:125
Contains TimeStamp.


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58