ts_TimeStamp.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00022 //----------------------------------------------------------------------
00023 #include <icl_core/TimeStamp.h>
00024 
00025 using icl_core::TimeStamp;
00026 
00027 namespace icl_core {
00028 
00029 std::ostream& operator << (std::ostream& os, const TimeStamp& t)
00030 {
00031   return os << t.formatIso8601BasicUTC();
00032 }
00033 
00034 }
00035 
00036 #include <boost/test/unit_test.hpp>
00037 
00038 BOOST_AUTO_TEST_SUITE(ts_TimeStamp)
00039 
00040 BOOST_AUTO_TEST_CASE(CheckISO8601RoundTrip)
00041 {
00042   {
00043     TimeStamp t1(0, 0);
00044     TimeStamp t2 = TimeStamp::fromIso8601BasicUTC(t1.formatIso8601BasicUTC());
00045     BOOST_CHECK_EQUAL(t1, t2);
00046   }
00047   {
00048     TimeStamp t1(1000000000, 123456789);
00049     TimeStamp t2 = TimeStamp::fromIso8601BasicUTC(t1.formatIso8601BasicUTC());
00050     BOOST_CHECK_EQUAL(t1, t2);
00051   }
00052   {
00053     TimeStamp t1(2000000000, 12345);
00054     TimeStamp t2 = TimeStamp::fromIso8601BasicUTC(t1.formatIso8601BasicUTC());
00055     BOOST_CHECK_EQUAL(t1, t2);
00056   }
00057   {
00058     TimeStamp t1(2147483647, 999999999);
00059     TimeStamp t2 = TimeStamp::fromIso8601BasicUTC(t1.formatIso8601BasicUTC());
00060     BOOST_CHECK_EQUAL(t1, t2);
00061   }
00062   // Test some random values.
00063   for (uint64_t secs = 1; secs < 2000000000; secs += 72836471)
00064   {
00065     {
00066       TimeStamp t1(secs, 0);
00067       TimeStamp t2 = TimeStamp::fromIso8601BasicUTC(t1.formatIso8601BasicUTC());
00068       BOOST_CHECK_EQUAL(t1, t2);
00069     }
00070     {
00071       TimeStamp t1(secs, 999999999);
00072       TimeStamp t2 = TimeStamp::fromIso8601BasicUTC(t1.formatIso8601BasicUTC());
00073       BOOST_CHECK_EQUAL(t1, t2);
00074     }
00075   }
00076 }
00077 
00078 BOOST_AUTO_TEST_CASE(CheckISO8601UTCConversion)
00079 {
00080   {
00081     std::string s = "19700101T000000,000000000";
00082     TimeStamp t1 = TimeStamp::fromIso8601BasicUTC(s);
00083     TimeStamp t2(0, 0);
00084     BOOST_CHECK_EQUAL(t1, t2);
00085   }
00086   {
00087     std::string s = "20040916T235959,25";
00088     TimeStamp t1 = TimeStamp::fromIso8601BasicUTC(s);
00089     TimeStamp t2(1095379199, 250000000);
00090     BOOST_CHECK_EQUAL(t1, t2);
00091   }
00092   {
00093     std::string s = "20130709T125530,123456789";
00094     TimeStamp t1 = TimeStamp::fromIso8601BasicUTC(s);
00095     TimeStamp t2(1373374530, 123456789);
00096     BOOST_CHECK_EQUAL(t1, t2);
00097   }
00098   {
00099     // 32-bit signed timestamp maximum.
00100     std::string s = "20380119T031407,999999999";
00101     TimeStamp t1 = TimeStamp::fromIso8601BasicUTC(s);
00102     TimeStamp t2(2147483647, 999999999);
00103     BOOST_CHECK_EQUAL(t1, t2);
00104   }
00105 }
00106 
00107 BOOST_AUTO_TEST_SUITE_END()


fzi_icl_core
Author(s):
autogenerated on Tue Aug 8 2017 02:28:04