boost_time_utils_unittest.cc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #include <config.h>
  7. #include <util/boost_time_utils.h>
  8. #include <string.h>
  9. #include <gtest/gtest.h>
  10. using namespace std;
  11. using namespace isc::util;
  12. using namespace boost::posix_time;
  13. using namespace boost::gregorian;
  14. /// Check the ptimeToText() function returns a numeric month.
  15. /// Note durationToText() is called by ptimeToText() so is tested too.
  16. // The Posix time epoch is 1970
  17. TEST(BoostTimeUtilsTest, epoch) {
  18. time_t tepoch = 0;
  19. ptime pepoch = from_time_t(tepoch);
  20. string sepoch = ptimeToText(pepoch);
  21. EXPECT_EQ("1970-01-01 00:00:00.000", sepoch.substr(0, 23));
  22. }
  23. // The 2015 Bastille day
  24. TEST(BoostTimeUtilsTest, bastilleDay) {
  25. time_duration tdbast =
  26. hours(12) + minutes(13) + seconds(14) + milliseconds(500);
  27. ptime pbast(date(2015, Jul, 14), tdbast);
  28. string sbast = ptimeToText(pbast);
  29. EXPECT_EQ("2015-07-14 12:13:14.500", sbast.substr(0, 23));
  30. }