From: Francis Dupont Date: Thu, 16 Jul 2015 11:08:20 +0000 (+0200) Subject: [3944] Added unit tests for boost time utils X-Git-Tag: trac4006_base~17^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d306c7d7c3b14410d3c5c375c5f72c582e895e1b;p=thirdparty%2Fkea.git [3944] Added unit tests for boost time utils --- diff --git a/src/lib/util/tests/Makefile.am b/src/lib/util/tests/Makefile.am index 9d727cb88a..a7ded73d35 100644 --- a/src/lib/util/tests/Makefile.am +++ b/src/lib/util/tests/Makefile.am @@ -28,6 +28,7 @@ TESTS += run_unittests run_unittests_SOURCES = run_unittests.cc run_unittests_SOURCES += base32hex_unittest.cc run_unittests_SOURCES += base64_unittest.cc +run_unittests_SOURCES += boost_time_utils_unittest.cc run_unittests_SOURCES += buffer_unittest.cc run_unittests_SOURCES += csv_file_unittest.cc run_unittests_SOURCES += fd_share_tests.cc diff --git a/src/lib/util/tests/boost_time_utils_unittest.cc b/src/lib/util/tests/boost_time_utils_unittest.cc new file mode 100644 index 0000000000..bf4d4a9e63 --- /dev/null +++ b/src/lib/util/tests/boost_time_utils_unittest.cc @@ -0,0 +1,46 @@ +// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include + +#include + +#include + +#include + +using namespace std; +using namespace isc::util; +using namespace boost::posix_time; +using namespace boost::gregorian; + +/// Check the ptimeToText() function returns a numeric month. +/// Note durationToText() is called by ptimeToText() so is tested too. + +// The Posix time epoch is 1970 +TEST(BoostTimeUtilsTest, epoch) { + time_t tepoch = 0; + ptime pepoch = from_time_t(tepoch); + string sepoch = ptimeToText(pepoch); + EXPECT_TRUE(strncmp(sepoch.c_str(), "1970-01-01 00:00:00.000", 23) == 0); +} + +// The 2015 Bastille day +TEST(BoostTimeUtilsTest, bastilleDay) { + time_duration tdbast = + hours(12) + minutes(13) + seconds(14) + milliseconds(500); + ptime pbast(date(2015, Jul, 14), tdbast); + string sbast = ptimeToText(pbast); + EXPECT_TRUE(strncmp(sbast.c_str(), "2015-07-14 12:13:14.500", 23) == 0); +}