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_day.hpp"
9 #include "boost/date_time/gregorian/greg_weekday.hpp"
10 #include "boost/date_time/gregorian/greg_day_of_year.hpp"
11 #include "../testfrmwk.hpp"
12 #include <iostream>
13
14
15 void
test_day()16 test_day()
17 {
18 using namespace boost::gregorian;
19 greg_day d1(1);
20 check("Basic test", d1 == 1);
21 try {
22 greg_day bad(0);
23 check("Bad day creation", false); //oh oh, fail
24 //unreachable
25 std::cout << "Shouldn't reach here: " << bad << std::endl;
26 }
27 catch(std::exception &) {
28 check("Bad day creation", true); //good
29
30 }
31 try {
32 greg_day bad(32);
33 check("Bad day creation2", false); //oh oh, fail
34 //unreachable
35 std::cout << "Shouldn't reach here: " << bad << std::endl;
36 }
37 catch(std::exception&) {
38 check("Bad day creation2", true); //good
39
40 }
41 check("traits min day", (greg_day::min)() == 1);
42 check("traits max day", (greg_day::max)() == 31);
43
44 greg_weekday sunday(0);
45 greg_weekday monday(1);
46
47 check("Weekday 0 short name == Sun",
48 sunday.as_short_string() == std::string("Sun"));
49 check("Weekday 1 short name == Mon",
50 monday.as_short_string() == std::string("Mon"));
51 check("Weekday 2 short name == Tue",
52 greg_weekday(2).as_short_string() == std::string("Tue"));
53 check("Weekday 3 short name == Wed",
54 greg_weekday(3).as_short_string() == std::string("Wed"));
55 check("Weekday 4 short name == Thu",
56 greg_weekday(4).as_short_string() == std::string("Thu"));
57 check("Weekday 5 short name == Fri",
58 greg_weekday(5).as_short_string() == std::string("Fri"));
59 check("Weekday 6 short name == Sat",
60 greg_weekday(6).as_short_string() == std::string("Sat"));
61 try {
62 greg_weekday bad(7);
63 check("Bad weekday creation", false); //oh oh, fail
64 //unreachable
65 std::cout << "Shouldn't reach here: " << bad << std::endl;
66 }
67 catch(bad_weekday&) {
68 check("Bad weekday creation", true); //good
69
70 }
71
72 try {
73 greg_day_of_year_rep bad(367);
74 check("Bad day of year", false); //oh oh, fail
75 //unreachable
76 std::cout << "Shouldn't reach here: " << bad << std::endl;
77
78 }
79 catch(bad_day_of_year&) {
80 check("Bad day of year", true); //good
81 }
82
83 }
84
85 int
main()86 main()
87 {
88 test_day();
89 return printTestStats();
90 }
91
92