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 
test_yearlimit(int yr,bool allowed)13 void 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(sdesc.str(), allowed);
21         if (allowed) {
22             check_equal("year operator ==", chkyr, yr);
23         }
24     }
25     catch (std::out_of_range&) { check(sdesc.str(), !allowed); }
26 }
27 
28 int
main()29 main()
30 {
31   // trac-13159 better limit testing
32   test_yearlimit(    0, false);
33   test_yearlimit( 1399, false);
34   test_yearlimit( 1400,  true);
35   test_yearlimit( 1401,  true);
36   test_yearlimit( 9999,  true);
37   test_yearlimit(10000, false);
38   test_yearlimit(10001, false);
39 
40   check("traits min year", (boost::gregorian::greg_year::min)() == 1400);
41   check("traits max year", (boost::gregorian::greg_year::max)() == 9999);
42 
43   return printTestStats();
44 }
45 
46