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

source code of boost/libs/date_time/test/posix_time/testtime_wstream.cpp