testgreg_year.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* Copyright (c) 2002,2003 CrystalClear Software, Inc.
  2. * Use, modification and distribution is subject to the
  3. * Boost Software License, Version 1.0. (See accompanying
  4. * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  5. * Author: Jeff Garland
  6. */
  7. #include "boost/date_time/gregorian/greg_year.hpp"
  8. #include "../testfrmwk.hpp"
  9. #include <iostream>
  10. #include <sstream>
  11. void test_yearlimit(int yr, bool allowed)
  12. {
  13. std::stringstream sdesc;
  14. sdesc << "should" << (allowed ? "" : " not") << " be able to make a year " << yr;
  15. try {
  16. boost::gregorian::greg_year chkyr(yr);
  17. check(sdesc.str(), allowed);
  18. if (allowed) {
  19. check_equal("year operator ==", chkyr, yr);
  20. }
  21. }
  22. catch (std::out_of_range&) { check(sdesc.str(), !allowed); }
  23. }
  24. int
  25. main()
  26. {
  27. // trac-13159 better limit testing
  28. test_yearlimit( 0, false);
  29. test_yearlimit( 1399, false);
  30. test_yearlimit( 1400, true);
  31. test_yearlimit( 1401, true);
  32. test_yearlimit( 9999, true);
  33. test_yearlimit(10000, false);
  34. test_yearlimit(10001, false);
  35. check("traits min year", (boost::gregorian::greg_year::min)() == 1400);
  36. check("traits max year", (boost::gregorian::greg_year::max)() == 9999);
  37. return printTestStats();
  38. }