]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // (C) Copyright Andy Tompkins 2008. Permission to copy, use, modify, sell and |
2 | // distribute this software is granted provided this copyright notice appears | |
3 | // in all copies. This software is provided "as is" without express or implied | |
4 | // warranty, and with no claim as to its suitability for any purpose. | |
5 | ||
6 | // Distributed under the Boost Software License, Version 1.0. (See | |
7 | // accompanying file LICENSE_1_0.txt or copy at | |
92f5a8d4 | 8 | // https://www.boost.org/LICENSE_1_0.txt) |
7c673cae FG |
9 | |
10 | // Purpose to test serializing uuids with wide stream archives | |
11 | ||
12 | #include <boost/detail/lightweight_test.hpp> | |
13 | #include <sstream> | |
14 | #include <iostream> | |
15 | ||
16 | #include <boost/uuid/uuid.hpp> | |
17 | #include <boost/uuid/uuid_serialize.hpp> | |
18 | #include <boost/uuid/uuid_io.hpp> | |
19 | ||
20 | #include <boost/archive/text_woarchive.hpp> | |
21 | #include <boost/archive/text_wiarchive.hpp> | |
22 | ||
23 | #include <boost/archive/xml_woarchive.hpp> | |
24 | #include <boost/archive/xml_wiarchive.hpp> | |
25 | ||
26 | #include <boost/archive/binary_woarchive.hpp> | |
27 | #include <boost/archive/binary_wiarchive.hpp> | |
28 | ||
29 | template <class OArchiveType, class IArchiveType, class OStringStreamType, class IStringStreamType> | |
30 | void test_archive() | |
31 | { | |
32 | using namespace std; | |
33 | using namespace boost::uuids; | |
34 | ||
35 | OStringStreamType o_stream; | |
36 | ||
37 | uuid u1 = {{0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef}}; | |
38 | ||
39 | uuid u2; | |
40 | ||
41 | // save | |
42 | { | |
43 | OArchiveType oa(o_stream); | |
44 | ||
45 | oa << BOOST_SERIALIZATION_NVP(u1); | |
46 | } | |
47 | ||
48 | //wcout << "stream:" << o_stream.str() << "\n\n"; | |
49 | ||
50 | // load | |
51 | { | |
52 | IStringStreamType i_stream(o_stream.str()); | |
53 | IArchiveType ia(i_stream); | |
54 | ||
55 | ia >> BOOST_SERIALIZATION_NVP(u2); | |
56 | } | |
57 | ||
58 | BOOST_TEST_EQ(u1, u2); | |
59 | } | |
60 | ||
61 | int test_main( int /* argc */, char* /* argv */[] ) | |
62 | { | |
63 | using namespace std; | |
64 | using namespace boost::archive; | |
65 | ||
66 | test_archive<text_woarchive, text_wiarchive, wostringstream, wistringstream>(); | |
67 | test_archive<xml_woarchive, xml_wiarchive, wostringstream, wistringstream>(); | |
68 | test_archive<binary_woarchive, binary_wiarchive, wostringstream, wistringstream>(); | |
69 | ||
70 | return boost::report_errors(); | |
71 | } |