testtime_wstream.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Copyright (c) 2003-2004 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: Bart Garst
  6. * $Date$
  7. */
  8. #include <iostream>
  9. #include <sstream>
  10. #include <boost/date_time/gregorian/gregorian.hpp>
  11. #include <boost/date_time/posix_time/posix_time.hpp>
  12. #include "../testfrmwk.hpp"
  13. #include <boost/lexical_cast.hpp>
  14. using namespace boost::gregorian;
  15. using namespace boost::posix_time;
  16. using boost::lexical_cast;
  17. int main(){
  18. #if defined(BOOST_NO_STD_WSTRING) || \
  19. defined(BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS)
  20. check("No wstring/wstream support for this compiler", false);
  21. #else
  22. std::wstring res, ws;
  23. std::wstringstream wss;
  24. /* time_period was used because all the time-type objects
  25. * that have operator<< can be easily accessed from it.
  26. * Tose are: ptime, time_duration, time_period */
  27. date d1(2003,Jan,20), d2(2003,May,10);
  28. time_period tp(ptime(d1,hours(1)), ptime(d2,hours(15)));
  29. // ptime
  30. wss << tp.begin();
  31. res = L"2003-Jan-20 01:00:00";
  32. check("ptime op<<", res == wss.str());
  33. wss.str(L"");
  34. ws = to_simple_wstring(tp.begin());
  35. check("ptime to_simple_wstring", res == ws);
  36. res = L"20030120T010000";
  37. ws = to_iso_wstring(tp.begin());
  38. check("ptime to_iso_wstring", res == ws);
  39. res = L"2003-01-20T01:00:00";
  40. ws = to_iso_extended_wstring(tp.begin());
  41. check("ptime to_iso_extended_wstring", res == ws);
  42. // time_duration
  43. wss << tp.length();
  44. res = L"2654:00:00";
  45. check("time_duration", res == wss.str());
  46. wss.str(L"");
  47. ws = to_simple_wstring(tp.length());
  48. check("time_duration to_simple_wstring", res == ws);
  49. res = L"26540000";
  50. ws = to_iso_wstring(tp.length());
  51. check("time_duration to_iso_wstring", res == ws);
  52. // time_period
  53. wss << tp;
  54. #ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
  55. res = L"[2003-Jan-20 01:00:00/2003-May-10 14:59:59.999999999]";
  56. #else
  57. res = L"[2003-Jan-20 01:00:00/2003-May-10 14:59:59.999999]";
  58. #endif
  59. check("time_period", res == wss.str());
  60. wss.str(L"");
  61. ws = to_simple_wstring(tp);
  62. check("time_period to_simple_wstring", res == ws);
  63. // special values
  64. time_duration sv_td(neg_infin);
  65. date sv_d(pos_infin);
  66. ptime sv_tp(sv_d,hours(1));
  67. res = L"+infinity";
  68. wss << sv_tp;
  69. check("ptime op<< special value", res == wss.str());
  70. wss.str(L"");
  71. ws = to_simple_wstring(sv_tp);
  72. check("ptime to_simple_wstring special value", res == ws);
  73. res = L"-infinity";
  74. wss << sv_td;
  75. check("time_duration op<< special value", res == wss.str());
  76. wss.str(L"");
  77. ws = to_simple_wstring(sv_td);
  78. check("time_duration to_simple_wstring special value", res == ws);
  79. #endif
  80. return printTestStats();
  81. }