• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  (C) Copyright Andy Tompkins 2007. 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
8 // https://www.boost.org/LICENSE_1_0.txt)
9 
10 // Purpose to test serializing uuids with narrow 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_oarchive.hpp>
21 #include <boost/archive/text_iarchive.hpp>
22 
23 #include <boost/archive/xml_oarchive.hpp>
24 #include <boost/archive/xml_iarchive.hpp>
25 
26 #include <boost/archive/binary_oarchive.hpp>
27 #include <boost/archive/binary_iarchive.hpp>
28 
29 template <class OArchiveType, class IArchiveType, class OStringStreamType, class IStringStreamType>
test_archive()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     //cout << "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 
main(int,char * [])61 int main( int /* argc */, char* /* argv */[] )
62 {
63     using namespace std;
64     using namespace boost::archive;
65 
66     test_archive<text_oarchive, text_iarchive, ostringstream, istringstream>();
67     test_archive<xml_oarchive, xml_iarchive, ostringstream, istringstream>();
68     test_archive<binary_oarchive, binary_iarchive, ostringstream, istringstream>();
69 
70     return boost::report_errors();
71 }
72