]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/date_time/test/gregorian/testgreg_serialize.cpp
1 /* Copyright (c) 2002-2005 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, Bart Garst
8 #include <boost/archive/text_oarchive.hpp>
9 #include <boost/archive/text_iarchive.hpp>
10 #include <boost/archive/xml_oarchive.hpp>
11 #include <boost/archive/xml_iarchive.hpp>
13 #include <boost/date_time/gregorian/gregorian.hpp>
14 #include <boost/date_time/gregorian/greg_serialize.hpp>
15 #include "../testfrmwk.hpp"
18 using namespace boost
;
19 using namespace gregorian
;
21 template<class archive_type
, class temporal_type
>
22 void save_to(archive_type
& ar
, const temporal_type
& tt
)
28 std::ostringstream oss
;
30 // NOTE: DATE_TIME_XML_SERIALIZE is only used in testing and is
31 // defined in the testing Jamfile
32 #if defined(DATE_TIME_XML_SERIALIZE)
33 std::cout
<< "Running xml archive tests" << std::endl
;
34 archive::xml_oarchive
oa(oss
);
36 std::cout
<< "Running text archive tests" << std::endl
;
37 archive::text_oarchive
oa(oss
);
41 date
sv_d1(not_a_date_time
);
42 date
sv_d2(pos_infin
);
44 date_duration
sv_dd(neg_infin
);
49 greg_weekday
gwd(Friday
);
50 partial_date
pd(26,Jul
);
51 nth_kday_of_month
nkd(nth_kday_of_month::second
,Tuesday
,Mar
);
52 first_kday_of_month
fkd(Saturday
,Apr
);
53 last_kday_of_month
lkd(Saturday
,Apr
);
54 first_kday_before
fkdb(Thursday
);
55 first_kday_after
fkda(Thursday
);
57 // load up the archive
59 #if defined(DATE_TIME_XML_SERIALIZE)
60 save_to(oa
, BOOST_SERIALIZATION_NVP(d
));
61 save_to(oa
, BOOST_SERIALIZATION_NVP(sv_d1
));
62 save_to(oa
, BOOST_SERIALIZATION_NVP(sv_d2
));
63 save_to(oa
, BOOST_SERIALIZATION_NVP(dd
));
64 save_to(oa
, BOOST_SERIALIZATION_NVP(sv_dd
));
65 save_to(oa
, BOOST_SERIALIZATION_NVP(dp
));
66 save_to(oa
, BOOST_SERIALIZATION_NVP(gy
));
67 save_to(oa
, BOOST_SERIALIZATION_NVP(gm
));
68 save_to(oa
, BOOST_SERIALIZATION_NVP(gd
));
69 save_to(oa
, BOOST_SERIALIZATION_NVP(gwd
));
70 save_to(oa
, BOOST_SERIALIZATION_NVP(pd
));
71 save_to(oa
, BOOST_SERIALIZATION_NVP(nkd
));
72 save_to(oa
, BOOST_SERIALIZATION_NVP(fkd
));
73 save_to(oa
, BOOST_SERIALIZATION_NVP(lkd
));
74 save_to(oa
, BOOST_SERIALIZATION_NVP(fkdb
));
75 save_to(oa
, BOOST_SERIALIZATION_NVP(fkda
));
94 }catch(archive::archive_exception
& ae
){
95 std::string
s(ae
.what());
96 check("Error writing to archive: " + s
+ "\nWritten data: \"" + oss
.str() + "\"", false);
97 return printTestStats();
100 std::istringstream
iss(oss
.str());
101 #if defined(DATE_TIME_XML_SERIALIZE)
102 archive::xml_iarchive
ia(iss
);
104 archive::text_iarchive
ia(iss
);
107 // read from the archive
108 date
d2(not_a_date_time
);
109 date
sv_d3(min_date_time
);
110 date
sv_d4(min_date_time
);
111 date_duration
dd2(not_a_date_time
);
112 date_duration
sv_dd2(0);
113 date_period
dp2(date(2000,Jan
,1),date_duration(1));
117 greg_weekday
gwd2(Monday
);
119 nth_kday_of_month
nkd2(nth_kday_of_month::first
,Monday
,Jan
);
120 first_kday_of_month
fkd2(Monday
,Jan
);
121 last_kday_of_month
lkd2(Monday
,Jan
);
122 first_kday_before
fkdb2(Monday
);
123 first_kday_after
fkda2(Monday
);
126 #if defined(DATE_TIME_XML_SERIALIZE)
127 ia
>> BOOST_SERIALIZATION_NVP(d2
);
128 ia
>> BOOST_SERIALIZATION_NVP(sv_d3
);
129 ia
>> BOOST_SERIALIZATION_NVP(sv_d4
);
130 ia
>> BOOST_SERIALIZATION_NVP(dd2
);
131 ia
>> BOOST_SERIALIZATION_NVP(sv_dd2
);
132 ia
>> BOOST_SERIALIZATION_NVP(dp2
);
133 ia
>> BOOST_SERIALIZATION_NVP(gy2
);
134 ia
>> BOOST_SERIALIZATION_NVP(gm2
);
135 ia
>> BOOST_SERIALIZATION_NVP(gd2
);
136 ia
>> BOOST_SERIALIZATION_NVP(gwd2
);
137 ia
>> BOOST_SERIALIZATION_NVP(pd2
);
138 ia
>> BOOST_SERIALIZATION_NVP(nkd2
);
139 ia
>> BOOST_SERIALIZATION_NVP(fkd2
);
140 ia
>> BOOST_SERIALIZATION_NVP(lkd2
);
141 ia
>> BOOST_SERIALIZATION_NVP(fkdb2
);
142 ia
>> BOOST_SERIALIZATION_NVP(fkda2
);
161 }catch(archive::archive_exception
& ae
){
162 std::string
s(ae
.what());
163 check("Error reading from archive: " + s
+ "\nWritten data: \"" + oss
.str() + "\"", false);
164 return printTestStats();
167 check("date", d
== d2
);
168 check("special_value date (nadt)", sv_d1
== sv_d3
);
169 check("special_value date (pos_infin)", sv_d2
== sv_d4
);
170 check("date_duration", dd
== dd2
);
171 check("special_value date_duration (neg_infin)", sv_dd
== sv_dd2
);
172 check("date_period", dp
== dp2
);
173 check("greg_year", gy
== gy2
);
174 check("greg_month", gm
== gm2
);
175 check("greg_day", gd
== gd2
);
176 check("greg_weekday", gwd
== gwd2
);
177 check("date_generator: partial_date", pd
== pd2
);
178 check("date_generator: nth_kday_of_month", nkd
.get_date(2002) == nkd2
.get_date(2002)); // no operator== for nth_kday_of_week - yet
179 check("date_generator: first_kday_of_month", fkd
.get_date(2002) == fkd2
.get_date(2002)); // no operator== for first_kday_of_week - yet
180 check("date_generator: last_kday_of_month", lkd
.get_date(2002) == lkd2
.get_date(2002)); // no operator== for last_kday_of_week - yet
181 check("date_generator: first_kday_before", fkdb
.get_date(d
) == fkdb2
.get_date(d
)); // no operator== for first_kday_before - yet
182 check("date_generator: first_kday_after", fkda
.get_date(d
) == fkda2
.get_date(d
)); // no operator== for first_kday_after - yet
184 return printTestStats();