You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
567 lines
17 KiB
C++
567 lines
17 KiB
C++
4 years ago
|
/***************************************************************************
|
||
|
* Copyright (C) 2018 by gempa GmbH *
|
||
|
* *
|
||
|
* All Rights Reserved. *
|
||
|
* *
|
||
|
* NOTICE: All information contained herein is, and remains *
|
||
|
* the property of gempa GmbH and its suppliers, if any. The intellectual *
|
||
|
* and technical concepts contained herein are proprietary to gempa GmbH *
|
||
|
* and its suppliers. *
|
||
|
* Dissemination of this information or reproduction of this material *
|
||
|
* is strictly forbidden unless prior written permission is obtained *
|
||
|
* from gempa GmbH. *
|
||
|
* *
|
||
|
* Author: Tracey Werner, Enrico Ellguth *
|
||
|
* Email: tracey.werner@gempa.de, enrico.ellguth@gempa.de *
|
||
|
***************************************************************************/
|
||
|
|
||
|
|
||
|
#define SEISCOMP_TEST_MODULE gempa
|
||
|
#include <seiscomp3/unittest/unittests.h>
|
||
|
#include <gempa/caps/datetime.h>
|
||
|
|
||
|
#include <string>
|
||
|
|
||
|
|
||
|
namespace gc = Gempa::CAPS;
|
||
|
namespace bu = boost::unit_test;
|
||
|
|
||
|
|
||
|
|
||
|
bool isClose(gc::TimeSpan time, long sec, long micro, int offset = 1) {
|
||
|
long microSeconds = time.microseconds();
|
||
|
|
||
|
long secDiff = time.seconds() - sec;
|
||
|
if ( secDiff > 0 )
|
||
|
microSeconds += secDiff * 1000000;
|
||
|
else if ( secDiff < 0 )
|
||
|
micro += abs(secDiff) * 1000000;
|
||
|
|
||
|
if ( abs(microSeconds - micro) <= offset )
|
||
|
return true;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
BOOST_AUTO_TEST_SUITE(gempa_common_caps_datetime)
|
||
|
|
||
|
|
||
|
BOOST_AUTO_TEST_CASE(construction) {
|
||
|
|
||
|
bu::unit_test_log.set_threshold_level(bu::log_warnings);
|
||
|
bu::unit_test_log.set_threshold_level(bu::log_messages);
|
||
|
|
||
|
struct timeval tvPositive;
|
||
|
tvPositive.tv_sec = 60000;
|
||
|
tvPositive.tv_usec = 123456;
|
||
|
gc::TimeSpan k(tvPositive);
|
||
|
BOOST_CHECK(k.seconds() == tvPositive.tv_sec);
|
||
|
BOOST_CHECK(k.microseconds() == tvPositive.tv_usec);
|
||
|
|
||
|
struct timeval tvNegativeUsec;
|
||
|
tvNegativeUsec.tv_sec = 300;
|
||
|
tvNegativeUsec.tv_usec = -13456;
|
||
|
gc::TimeSpan ki(tvNegativeUsec);
|
||
|
BOOST_CHECK_EQUAL(ki.seconds() , tvNegativeUsec.tv_sec);
|
||
|
BOOST_CHECK_EQUAL(ki.microseconds() , tvNegativeUsec.tv_usec);
|
||
|
|
||
|
struct timeval tvNegativeSec;
|
||
|
tvNegativeSec.tv_sec = -300;
|
||
|
tvNegativeSec.tv_usec = 13456;
|
||
|
|
||
|
gc::TimeSpan kj(tvNegativeSec);
|
||
|
BOOST_CHECK_EQUAL(kj.seconds() , tvNegativeSec.tv_sec);
|
||
|
BOOST_CHECK_EQUAL(kj.microseconds() , tvNegativeSec.tv_usec);
|
||
|
|
||
|
struct timeval tvNegative;
|
||
|
tvNegative.tv_sec = -3000;
|
||
|
tvNegative.tv_usec = -123456;
|
||
|
gc::TimeSpan kk(tvNegative);
|
||
|
BOOST_CHECK_EQUAL(kk.seconds() , tvNegative.tv_sec);
|
||
|
BOOST_CHECK_EQUAL(kk.microseconds() , tvNegative.tv_usec);
|
||
|
|
||
|
struct timeval tvNull;
|
||
|
gc::TimeSpan kl(tvNull);
|
||
|
BOOST_CHECK_EQUAL(kl.seconds() , tvNull.tv_sec);
|
||
|
BOOST_CHECK_EQUAL(kl.microseconds() , tvNull.tv_usec);
|
||
|
|
||
|
// copy
|
||
|
gc::TimeSpan copyPositive(gc::TimeSpan(79743.123456));
|
||
|
BOOST_CHECK(copyPositive.seconds() == 79743);
|
||
|
BOOST_CHECK(copyPositive.microseconds() == 123456);
|
||
|
|
||
|
gc::TimeSpan copyNegative(gc::TimeSpan(-98765.123456));
|
||
|
long sec = -98765;
|
||
|
long micro = -123456;
|
||
|
BOOST_CHECK(isClose(copyNegative, sec, micro,20) == true);
|
||
|
|
||
|
gc::TimeSpan copyNegativeTest(gc::TimeSpan(-98765.000070));
|
||
|
sec = -98765 ;
|
||
|
micro = 70;
|
||
|
BOOST_CHECK_EQUAL(isClose(copyNegativeTest,sec, micro,500), true);
|
||
|
|
||
|
// long
|
||
|
gc::TimeSpan longPositive(765432, 456789);
|
||
|
BOOST_CHECK(longPositive.seconds() == 765432);
|
||
|
BOOST_CHECK(longPositive.microseconds() == 456789);
|
||
|
|
||
|
gc::TimeSpan longNegativeUsec(200, -732);
|
||
|
BOOST_CHECK_EQUAL(longNegativeUsec.seconds(), 200);
|
||
|
BOOST_CHECK_EQUAL(longNegativeUsec.microseconds(), -732);
|
||
|
|
||
|
gc::TimeSpan longNegativeSec(-800, 73265);
|
||
|
BOOST_CHECK_EQUAL(longNegativeSec.seconds(), -800);
|
||
|
BOOST_CHECK_EQUAL(longNegativeSec.microseconds(), 73265);
|
||
|
|
||
|
gc::TimeSpan longNegative(-500, -732650);
|
||
|
BOOST_CHECK_EQUAL(longNegative.seconds(), -500);
|
||
|
BOOST_CHECK_EQUAL(longNegative.microseconds(), -732650);
|
||
|
|
||
|
// double
|
||
|
double number = 123456.98765;
|
||
|
gc::TimeSpan doublePositive(number);
|
||
|
BOOST_CHECK_EQUAL(doublePositive.seconds(), 123456);
|
||
|
BOOST_CHECK_EQUAL(doublePositive.microseconds(), 987650);
|
||
|
|
||
|
number = -98765.123470;
|
||
|
gc::TimeSpan doubleNegative(number);
|
||
|
BOOST_CHECK_EQUAL(doubleNegative.seconds(), -98765);
|
||
|
BOOST_CHECK_CLOSE((double)doubleNegative.microseconds(), -123470, 0.01);
|
||
|
|
||
|
number = -98765.000080;
|
||
|
gc::TimeSpan doubleNegativeTest(number);
|
||
|
sec = -98765;
|
||
|
micro = 80;
|
||
|
BOOST_CHECK_EQUAL(isClose(doubleNegativeTest,sec, micro,500), true);
|
||
|
|
||
|
// pointer
|
||
|
timeval n;
|
||
|
n.tv_sec = 123;
|
||
|
n.tv_usec = 123456;
|
||
|
|
||
|
gc::TimeSpan pointerPositive(&n);
|
||
|
BOOST_CHECK_EQUAL(pointerPositive.seconds(), 123);
|
||
|
BOOST_CHECK_EQUAL(pointerPositive.microseconds(), 123456);
|
||
|
|
||
|
n.tv_sec = -123;
|
||
|
n.tv_usec = 123456;
|
||
|
|
||
|
gc::TimeSpan pointerNegativeSec(&n);
|
||
|
BOOST_CHECK_EQUAL(pointerNegativeSec.seconds(), -123);
|
||
|
BOOST_CHECK_EQUAL(pointerNegativeSec.microseconds(), 123456);
|
||
|
|
||
|
n.tv_sec = 123;
|
||
|
n.tv_usec = -123456;
|
||
|
|
||
|
gc::TimeSpan pointerNegativeUsec(&n);
|
||
|
BOOST_CHECK_EQUAL(pointerNegativeUsec.seconds(), 123);
|
||
|
BOOST_CHECK_EQUAL(pointerNegativeUsec.microseconds(), -123456);
|
||
|
|
||
|
n.tv_sec = -123;
|
||
|
n.tv_usec = -123456;
|
||
|
|
||
|
gc::TimeSpan pointerNegative(&n);
|
||
|
BOOST_CHECK_EQUAL(pointerNegative.seconds(), -123);
|
||
|
BOOST_CHECK_EQUAL(pointerNegative.microseconds(), -123456);
|
||
|
|
||
|
timeval *nullPointer = NULL;
|
||
|
gc::TimeSpan pointerNull(nullPointer);
|
||
|
BOOST_CHECK_EQUAL(pointerNull.seconds(), 0);
|
||
|
BOOST_CHECK_EQUAL(pointerNull.microseconds(), 0);
|
||
|
}
|
||
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
BOOST_AUTO_TEST_CASE(addition) {
|
||
|
gc::TimeSpan k = 5, l = 7;
|
||
|
BOOST_CHECK(k + l == gc::TimeSpan(12));
|
||
|
|
||
|
gc::TimeSpan m = 320.5, n = 60.2;
|
||
|
BOOST_CHECK(m + n == gc::TimeSpan(380.7));
|
||
|
|
||
|
gc::TimeSpan g = 55, d = -50;
|
||
|
BOOST_CHECK(d + g == gc::TimeSpan(5));
|
||
|
|
||
|
gc::TimeSpan t = -80.0053, s = -70.0044;
|
||
|
gc::TimeSpan result = t + s;
|
||
|
long sec = t.seconds() + s.seconds();
|
||
|
long micro = t.microseconds() + s.microseconds();
|
||
|
BOOST_CHECK_EQUAL(isClose(result, sec,micro),true);
|
||
|
|
||
|
gc::TimeSpan u = -5.035, v = -60.044;
|
||
|
result = u + v;
|
||
|
sec = u.seconds() + v.seconds();
|
||
|
micro = u.microseconds() + v.microseconds();
|
||
|
BOOST_CHECK_EQUAL(isClose(result,sec, micro), true);
|
||
|
|
||
|
gc::TimeSpan w = -5.0885, x = -6.01111;
|
||
|
result = w + x;
|
||
|
sec = w.seconds() + x.seconds();
|
||
|
micro = w.microseconds() + x.microseconds();
|
||
|
BOOST_CHECK_EQUAL(isClose(result,sec, micro), true);
|
||
|
}
|
||
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
BOOST_AUTO_TEST_CASE(subtraction) {
|
||
|
gc::TimeSpan k = 5, l = 6;
|
||
|
BOOST_CHECK(k - l == gc::TimeSpan(-1));
|
||
|
|
||
|
gc::TimeSpan t = 58, i = 68.05;
|
||
|
gc::TimeSpan result = t - i;
|
||
|
long sec = t.seconds() - i.seconds();
|
||
|
long micro = t.microseconds() - i.microseconds();
|
||
|
BOOST_CHECK_EQUAL(isClose(result,sec, micro), true);
|
||
|
|
||
|
gc::TimeSpan e(30,4);
|
||
|
gc::TimeSpan o(45,3);
|
||
|
result = e - o;
|
||
|
sec = e.seconds() - o.seconds();
|
||
|
micro = e.microseconds() - o.microseconds();
|
||
|
BOOST_CHECK_EQUAL(isClose(result,sec, micro), true);
|
||
|
|
||
|
gc::TimeSpan f = 30.00004, g = -45.00003;
|
||
|
result = f - g;
|
||
|
sec = f.seconds() - g.seconds();
|
||
|
micro = f.microseconds() - g.microseconds();
|
||
|
BOOST_CHECK_EQUAL(isClose(result,sec, micro), true);
|
||
|
}
|
||
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
BOOST_AUTO_TEST_CASE(setSec) {
|
||
|
gc::TimeSpan h, k, l;
|
||
|
BOOST_CHECK_EQUAL(h.set(4), gc::TimeSpan(4));
|
||
|
BOOST_CHECK_EQUAL(k.set(2), gc::TimeSpan(2));
|
||
|
BOOST_CHECK_EQUAL(l.set(1), gc::TimeSpan(1));
|
||
|
BOOST_CHECK_EQUAL(l.set(-10), gc::TimeSpan(-10));
|
||
|
BOOST_CHECK_EQUAL(k.set(-9876), gc::TimeSpan(-9876));
|
||
|
BOOST_CHECK_EQUAL(l.set(0), gc::TimeSpan(0.));
|
||
|
}
|
||
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
BOOST_AUTO_TEST_CASE(setMicro) {
|
||
|
gc::TimeSpan h, k, l, ts;
|
||
|
BOOST_CHECK_EQUAL(h.setUSecs(9), gc::TimeSpan(0.000009));
|
||
|
BOOST_CHECK_EQUAL(k.setUSecs(2), gc::TimeSpan(0.0000020));
|
||
|
BOOST_CHECK_EQUAL(l.setUSecs(3), gc::TimeSpan(0.000003));
|
||
|
BOOST_CHECK_EQUAL(ts.setUSecs(4), gc::TimeSpan(0.000004));
|
||
|
BOOST_CHECK_EQUAL(l.setUSecs(0), gc::TimeSpan(0.0));
|
||
|
BOOST_CHECK_EQUAL(h.setUSecs(2000000), gc::TimeSpan(2.00));
|
||
|
BOOST_CHECK_EQUAL(k.setUSecs(-3000000), gc::TimeSpan(-3.0));
|
||
|
|
||
|
bu::unit_test_log.set_threshold_level(bu::log_warnings);
|
||
|
|
||
|
gc::TimeSpan test = l.setUSecs(-7262);
|
||
|
BOOST_WARN_EQUAL(test.microseconds(), -7262);
|
||
|
|
||
|
gc::TimeSpan test2 = l.setUSecs(-98744);
|
||
|
BOOST_WARN_EQUAL(test2.microseconds(), -98744);
|
||
|
|
||
|
gc::TimeSpan test3 = l.setUSecs(-98);
|
||
|
BOOST_WARN_EQUAL(isClose(test3,0, -98), true);
|
||
|
}
|
||
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
BOOST_AUTO_TEST_CASE(secAndMicro) {
|
||
|
gc::TimeSpan ts(2.000002);
|
||
|
BOOST_CHECK(ts.seconds() == 2 && ts.microseconds() == 2);
|
||
|
|
||
|
gc::TimeSpan h(4.000009);
|
||
|
BOOST_CHECK(h.seconds() == 4 && h.microseconds() == 9);
|
||
|
|
||
|
gc::TimeSpan t(0.000004);
|
||
|
BOOST_CHECK(t.seconds() == 0 && t.microseconds() == 4);
|
||
|
|
||
|
gc::TimeSpan k(0.000000);
|
||
|
BOOST_CHECK(k.seconds() == 0 && k.microseconds() == 0);
|
||
|
|
||
|
gc::TimeSpan m(-8.123456);
|
||
|
long sec = -8;
|
||
|
long micro = -123456;
|
||
|
BOOST_WARN_EQUAL(isClose(m,sec, micro,20), true);
|
||
|
}
|
||
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
BOOST_AUTO_TEST_CASE(absolute) {
|
||
|
gc::TimeSpan k(-2.567);
|
||
|
gc::TimeSpan result = k.abs();
|
||
|
long sec = result.seconds();
|
||
|
long micro = result.microseconds();
|
||
|
BOOST_CHECK_EQUAL(isClose(result,2, 567000,20), true);
|
||
|
|
||
|
gc::TimeSpan m(-2, -5);
|
||
|
gc::TimeSpan n(2, 5);
|
||
|
BOOST_CHECK_EQUAL(m.abs(), n.abs());
|
||
|
BOOST_CHECK_EQUAL(m.abs(), n);
|
||
|
|
||
|
gc::TimeSpan i(600, -700000);
|
||
|
result = i.abs();
|
||
|
BOOST_CHECK_EQUAL(result.seconds(), 600);
|
||
|
BOOST_CHECK_EQUAL(result.microseconds(),700000);
|
||
|
|
||
|
gc::TimeSpan r(200, -5);
|
||
|
gc::TimeSpan s(200.000005);
|
||
|
gc::TimeSpan absR = r.abs();
|
||
|
BOOST_CHECK_EQUAL(r.abs(), s.abs());
|
||
|
BOOST_CHECK_EQUAL(absR.seconds(), s.seconds());
|
||
|
BOOST_CHECK_EQUAL(absR.microseconds(), s.microseconds());
|
||
|
|
||
|
gc::TimeSpan l = (double)-1.000678;
|
||
|
result = l.abs();
|
||
|
sec = 1;
|
||
|
micro = 678;
|
||
|
BOOST_CHECK_EQUAL(isClose(result,sec, micro), true);
|
||
|
|
||
|
gc::TimeSpan h = -4;
|
||
|
BOOST_CHECK_EQUAL(h.abs(), gc::TimeSpan(4));
|
||
|
|
||
|
gc::TimeSpan ts;
|
||
|
BOOST_CHECK_EQUAL(ts.abs(), gc::TimeSpan(0.0));
|
||
|
}
|
||
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
BOOST_AUTO_TEST_CASE(length) {
|
||
|
gc::TimeSpan k = 2.000002;
|
||
|
BOOST_CHECK(k.length() == 2.000002);
|
||
|
|
||
|
gc::TimeSpan l = 1.000003;
|
||
|
BOOST_CHECK(l.length() == 1.000003);
|
||
|
|
||
|
gc::TimeSpan h = 4.000009;
|
||
|
BOOST_CHECK(h.length() == 4.000009);
|
||
|
}
|
||
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
BOOST_AUTO_TEST_CASE(notEqual) {
|
||
|
gc::TimeSpan k = 2.000002, l = 1.000003;
|
||
|
BOOST_CHECK(k != l);
|
||
|
|
||
|
gc::TimeSpan ts, t = 0.000007;
|
||
|
BOOST_CHECK(ts != t);
|
||
|
|
||
|
gc::TimeSpan h = 4.000009, j = 2845687.000004;
|
||
|
BOOST_CHECK(h != j);
|
||
|
}
|
||
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
BOOST_AUTO_TEST_CASE(assign) {
|
||
|
gc::TimeSpan k = 2.000002;
|
||
|
BOOST_CHECK(k == gc::TimeSpan(2.000002));
|
||
|
|
||
|
gc::TimeSpan t;
|
||
|
BOOST_CHECK(t == gc::TimeSpan(0.0));
|
||
|
|
||
|
gc::TimeSpan h = 4.000009;
|
||
|
BOOST_CHECK(h == gc::TimeSpan(4.000009));
|
||
|
|
||
|
gc::TimeSpan ts = 0.000004;
|
||
|
BOOST_CHECK(ts == gc::TimeSpan(0.000004));
|
||
|
}
|
||
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
BOOST_AUTO_TEST_CASE(plus) {
|
||
|
gc::TimeSpan k = 2.000002, l = 1.000003;
|
||
|
BOOST_CHECK_EQUAL(k += l, gc::TimeSpan(3.000005));
|
||
|
|
||
|
gc::TimeSpan h = 4.000009, t;
|
||
|
BOOST_CHECK_EQUAL(t += h, gc::TimeSpan(4.000009));
|
||
|
|
||
|
gc::TimeSpan ts = 0.000004, j = 80005.000004;
|
||
|
BOOST_CHECK_EQUAL(ts += j, gc::TimeSpan(80005.000008));
|
||
|
}
|
||
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
BOOST_AUTO_TEST_CASE(minus) {
|
||
|
gc::TimeSpan k = 2.000002, l = 1.000003;
|
||
|
BOOST_CHECK_EQUAL(k -= l, gc::TimeSpan(0.999999));
|
||
|
|
||
|
gc::TimeSpan t, j = 6897.098772;
|
||
|
BOOST_CHECK_EQUAL(j -= t, gc::TimeSpan(6897.098772));
|
||
|
|
||
|
gc::TimeSpan h = 4.000009, ts = 0.000004;
|
||
|
BOOST_CHECK_EQUAL(h -= ts, gc::TimeSpan(4.000005));
|
||
|
}
|
||
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
BOOST_AUTO_TEST_CASE(lower) {
|
||
|
gc::TimeSpan k = 2.000002, t;
|
||
|
BOOST_CHECK_EQUAL(t < k, true);
|
||
|
|
||
|
gc::TimeSpan h = 4.000009, j = 2.897665;
|
||
|
BOOST_CHECK_EQUAL(j < h, true);
|
||
|
|
||
|
gc::TimeSpan ts = 0.000004, z = 7893648.987645;
|
||
|
BOOST_CHECK_EQUAL(z < ts, false);
|
||
|
}
|
||
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
BOOST_AUTO_TEST_CASE(greater) {
|
||
|
gc::TimeSpan k = 2.000002, t;
|
||
|
BOOST_CHECK_EQUAL(k > t, true);
|
||
|
|
||
|
gc::TimeSpan h = 4.000009, j = 3.909888;
|
||
|
BOOST_CHECK_EQUAL(h > j, true);
|
||
|
|
||
|
gc::TimeSpan ts = 0.000004, g = 0.000001;
|
||
|
BOOST_CHECK_EQUAL(g > ts, false);
|
||
|
}
|
||
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
BOOST_AUTO_TEST_CASE(lowerEqual) {
|
||
|
gc::TimeSpan k = 2.000002;
|
||
|
BOOST_CHECK_EQUAL(k <= gc::TimeSpan(2.000002), true);
|
||
|
|
||
|
gc::TimeSpan t;
|
||
|
BOOST_CHECK_EQUAL(t <= gc::TimeSpan(2), true);
|
||
|
|
||
|
gc::TimeSpan h = 4.000009;
|
||
|
BOOST_CHECK_EQUAL(h <= gc::TimeSpan(2), false);
|
||
|
}
|
||
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
BOOST_AUTO_TEST_CASE(greaterEqual) {
|
||
|
gc::TimeSpan h = 4.000009;
|
||
|
BOOST_CHECK_EQUAL(h >= gc::TimeSpan(2), true);
|
||
|
|
||
|
gc::TimeSpan ts = 0.000004;
|
||
|
BOOST_CHECK_EQUAL(ts >= gc::TimeSpan(0.000001), true);
|
||
|
|
||
|
gc::TimeSpan k = 2.000002;
|
||
|
BOOST_CHECK_EQUAL(k >= gc::TimeSpan(2.000002), true);
|
||
|
}
|
||
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
BOOST_AUTO_TEST_CASE(inDouble) {
|
||
|
gc::TimeSpan k = 6.000003;
|
||
|
double kd = k.operator double();
|
||
|
BOOST_CHECK_EQUAL(kd, 6.000003);
|
||
|
|
||
|
gc::TimeSpan t = 0.000008;
|
||
|
double td = t.operator double();
|
||
|
BOOST_CHECK_EQUAL(td, 0.000008);
|
||
|
|
||
|
gc::TimeSpan ts = 2.000004;
|
||
|
double tsd = ts.operator double();
|
||
|
BOOST_CHECK_EQUAL(tsd, 2.000004);
|
||
|
}
|
||
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
BOOST_AUTO_TEST_CASE(toTimeval) {
|
||
|
const timeval tv = gc::Time(6.000003);
|
||
|
gc::TimeSpan k = 6.000003;
|
||
|
timeval kv = k.operator const timeval &();
|
||
|
BOOST_CHECK_EQUAL(kv.tv_sec, tv.tv_sec);
|
||
|
BOOST_CHECK_EQUAL(kv.tv_usec, tv.tv_usec);
|
||
|
|
||
|
const timeval ti = gc::Time(0.000008);
|
||
|
gc::TimeSpan t = 0.000008;
|
||
|
timeval tvi = t.operator const timeval &();
|
||
|
BOOST_CHECK_EQUAL(tvi.tv_sec, ti.tv_sec);
|
||
|
BOOST_CHECK_EQUAL(tvi.tv_usec, ti.tv_usec);
|
||
|
|
||
|
const timeval tl = gc::Time(2.000004);
|
||
|
gc::TimeSpan ts = 2.000004;
|
||
|
timeval tsv = ts.operator const timeval &();
|
||
|
BOOST_CHECK_EQUAL(tsv.tv_sec, tl.tv_sec);
|
||
|
BOOST_CHECK_EQUAL(tsv.tv_usec, tl.tv_usec);
|
||
|
}
|
||
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
BOOST_AUTO_TEST_CASE(fromString) {
|
||
|
gc::Time time = gc::Time::FromString("2019-01-01 10:01:59", "%F %T");
|
||
|
|
||
|
BOOST_CHECK(time.valid());
|
||
|
|
||
|
int year, month, day, hour, min, sec;
|
||
|
BOOST_CHECK(time.get(&year, &month, &day, &hour, &min, &sec));
|
||
|
BOOST_CHECK_EQUAL(year, 2019);
|
||
|
BOOST_CHECK_EQUAL(month, 1);
|
||
|
BOOST_CHECK_EQUAL(day, 1);
|
||
|
BOOST_CHECK_EQUAL(hour, 10);
|
||
|
BOOST_CHECK_EQUAL(min, 01);
|
||
|
BOOST_CHECK_EQUAL(sec, 59);
|
||
|
|
||
|
// Buffer overflow test
|
||
|
std::string str;
|
||
|
str.resize(1024);
|
||
|
time = gc::Time::FromString(str.c_str(), "%F %T");
|
||
|
BOOST_CHECK(!time.valid());
|
||
|
}
|
||
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
BOOST_AUTO_TEST_SUITE_END()
|