testgreg_day.cpp 2.5 KB

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