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
8#include "boost/date_time/gregorian/greg_year.hpp"
9#include "../testfrmwk.hpp"
10#include <iostream>
11#include <sstream>
12
13void test_yearlimit(int yr, bool allowed)
14{
15 std::stringstream sdesc;
16 sdesc << "should" << (allowed ? "" : " not") << " be able to make a year " << yr;
17
18 try {
19 boost::gregorian::greg_year chkyr(yr);
20 check(testname: sdesc.str(), testcond: allowed);
21 if (allowed) {
22 check_equal(testname: "year operator ==", left: chkyr, right: yr);
23 }
24 }
25 catch (std::out_of_range&) { check(testname: sdesc.str(), testcond: !allowed); }
26}
27
28int
29main()
30{
31 // trac-13159 better limit testing
32 test_yearlimit( yr: 0, allowed: false);
33 test_yearlimit( yr: 1399, allowed: false);
34 test_yearlimit( yr: 1400, allowed: true);
35 test_yearlimit( yr: 1401, allowed: true);
36 test_yearlimit( yr: 9999, allowed: true);
37 test_yearlimit(yr: 10000, allowed: false);
38 test_yearlimit(yr: 10001, allowed: false);
39
40 check(testname: "traits min year", testcond: (boost::gregorian::greg_year::min)() == 1400);
41 check(testname: "traits max year", testcond: (boost::gregorian::greg_year::max)() == 9999);
42
43 return printTestStats();
44}
45
46

source code of boost/libs/date_time/test/gregorian/testgreg_year.cpp