File: testgreg_day.cpp

package info (click to toggle)
boost 1.34.1-14
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 116,412 kB
  • ctags: 259,566
  • sloc: cpp: 642,395; xml: 56,450; python: 17,612; ansic: 14,520; sh: 2,265; yacc: 858; perl: 481; makefile: 478; lex: 94; sql: 74; csh: 6
file content (91 lines) | stat: -rw-r--r-- 2,546 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* Copyright (c) 2002,2003 CrystalClear Software, Inc.
 * Use, modification and distribution is subject to the 
 * Boost Software License, Version 1.0. (See accompanying
 * file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
 * Author: Jeff Garland 
 */

#include "boost/date_time/gregorian/greg_day.hpp"
#include "boost/date_time/gregorian/greg_weekday.hpp"
#include "boost/date_time/gregorian/greg_day_of_year.hpp"
#include "boost/date_time/testfrmwk.hpp"
#include <iostream>


void 
test_day() 
{
  using namespace boost::gregorian;
  greg_day d1(1);
  check("Basic test", d1 == 1);
  try {
    greg_day bad(0);
    check("Bad day creation", false); //oh oh, fail
    //unreachable
    std::cout << "Shouldn't reach here: " << bad << std::endl;
  }
  catch(std::exception &) {
    check("Bad day creation", true); //good
    
  }
  try {
    greg_day bad(32);
    check("Bad day creation2", false); //oh oh, fail
    //unreachable
    std::cout << "Shouldn't reach here: " << bad << std::endl;
  }
  catch(std::exception&) {
    check("Bad day creation2", true); //good
    
  }
  check("traits min day", (greg_day::min)() == 1);
  check("traits max day", (greg_day::max)() == 31);

  greg_weekday sunday(0);
  greg_weekday monday(1);

  check("Weekday 0 short name == Sun", 
        sunday.as_short_string() == std::string("Sun"));
  check("Weekday 1 short name == Mon", 
        monday.as_short_string() == std::string("Mon"));
  check("Weekday 2 short name == Tue", 
        greg_weekday(2).as_short_string() == std::string("Tue"));
  check("Weekday 3 short name == Wed", 
        greg_weekday(3).as_short_string() == std::string("Wed"));
  check("Weekday 4 short name == Thu", 
        greg_weekday(4).as_short_string() == std::string("Thu"));
  check("Weekday 5 short name == Fri", 
        greg_weekday(5).as_short_string() == std::string("Fri"));
  check("Weekday 6 short name == Sat", 
        greg_weekday(6).as_short_string() == std::string("Sat"));
  try {
    greg_weekday bad(7);
    check("Bad weekday creation", false); //oh oh, fail
    //unreachable
    std::cout << "Shouldn't reach here: " << bad << std::endl;
  }
  catch(bad_weekday&) {
    check("Bad weekday creation", true); //good
    
  }

   try {
     greg_day_of_year_rep bad(367);
     check("Bad day of year", false); //oh oh, fail
    //unreachable
    std::cout << "Shouldn't reach here: " << bad << std::endl;

   }
   catch(bad_day_of_year&) {
     check("Bad day of year", true); //good
  }
  
}

int
main() 
{
  test_day();
  return printTestStats();
}