all: Refactoring work with time using boost::chrono
Now the library has two clocks: time::steady_clock and
time::system_clock, following (boost|std)::chrono. In addition to
standard now() method, the library contains several helpers to convert
to/from UnixTimestamp (microsecond resolution) and IsoString (optional
microsecond resolution). The IsoString conversions use
boost::posix_time routines, since boost::chrono supports extended IO
support only starting boost version 1.52 (Boost Chrono V2).
This commit breaks compatibility with previous API. All time-related
Data/Interest calls must explicitly use time units to specify
FreshnessPeriod/InterestLifetime.
Brief usage/conversion guide:
- creation of time units does not support double/float types. If
necessary to create time unit from double, ``ndn::duration<double>`` (for
seconds) needs to be used instead. In some cases, this would also
require ``ndn::duration_cast``, if the target is not ``ndn::nanoseconds``.
- ndn::getNow, ndn::ndn_getNowMilliseconds, ndn::time::now are all
removed in favor of the now() method in a specific clock:
* time::system_clock::now();
* time::steady_clock::now();
- When necessary to convert system_clock::TimePoint to unix timestamp,
``time::toUnixTimestamp`` can be used. This method return number of
milliseconds since UNIX epoch as ``ndn::time::milliseconds`` type.
Use count() method to obtain number as an integral value.
Change-Id: Icd688bc6766e008d60c3d2888173627874526e47
Refs: #1152
diff --git a/tests/security/test-encode-decode-certificate.cpp b/tests/security/test-encode-decode-certificate.cpp
index 409e757..3b8cc83 100644
--- a/tests/security/test-encode-decode-certificate.cpp
+++ b/tests/security/test-encode-decode-certificate.cpp
@@ -83,8 +83,8 @@
const std::string CERT_INFO = "Certificate name:\n"
" /\n"
"Validity:\n"
- " NotBefore: 20131226T232254.000000\n"
- " NotAfter: 20131226T232254.000000\n"
+ " NotBefore: 20131226T232254\n"
+ " NotAfter: 20131226T232254\n"
"Subject Description:\n"
" 2.5.4.41: TEST NAME\n"
"Public key bits:\n"
@@ -98,8 +98,8 @@
ndn::Certificate c;
// validity
- c.setNotBefore(1388100174000); // 12/26/2013 @ 11:22pm
- c.setNotAfter(1388100174000); // 12/26/2013 @ 11:22pm
+ c.setNotBefore(time::fromUnixTimestamp(time::milliseconds(1388100174000))); // 12/26/2013 @ 11:22pm
+ c.setNotAfter(time::fromUnixTimestamp(time::milliseconds(1388100174000))); // 12/26/2013 @ 11:22pm
// subject
c.addSubjectDescription(CertificateSubjectDescription("2.5.4.41", "TEST NAME"));
@@ -131,19 +131,19 @@
// p.Load(source);
BOOST_REQUIRE_NO_THROW(c.encode());
-
+
// ofstream of("cert.out");
// of.write((const char*)c.getContent().value(), c.getContent().value_size());
// const Block &wire = i.wireEncode();
BOOST_REQUIRE_EQUAL_COLLECTIONS(CERT, CERT+sizeof(CERT),
- c.getContent().value_begin(), c.getContent().value_end());
+ c.getContent().value_begin(), c.getContent().value_end());
std::ostringstream os;
os << c << std::endl;
std::string info(os.str());
- BOOST_REQUIRE_EQUAL_COLLECTIONS(CERT_INFO.begin(), CERT_INFO.end(),
- info.begin(), info.end());
+
+ BOOST_CHECK_EQUAL(CERT_INFO, info);
}
const unsigned char REAL_CERT[] = {
@@ -153,8 +153,8 @@
const std::string REAL_CERT_INFO = "Certificate name:\n"
" /tmp\n"
"Validity:\n"
-" NotBefore: 20131101T171122.000000\n"
-" NotAfter: 20141101T171122.000000\n"
+" NotBefore: 20131101T171122\n"
+" NotAfter: 20141101T171122\n"
"Subject Description:\n"
" 2.5.4.41: NDN Testbed Root\n"
"Public key bits:\n"
@@ -176,8 +176,7 @@
std::ostringstream os;
os << c << std::endl;
std::string info(os.str());
- BOOST_REQUIRE_EQUAL_COLLECTIONS(REAL_CERT_INFO.begin(), REAL_CERT_INFO.end(),
- info.begin(), info.end());
+ BOOST_CHECK_EQUAL(REAL_CERT_INFO, info);
}
BOOST_AUTO_TEST_SUITE_END()