1 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
---|
2 | // test_iterators.cpp |
---|
3 | |
---|
4 | // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . |
---|
5 | // Use, modification and distribution is subject to the Boost Software |
---|
6 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
---|
7 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
8 | |
---|
9 | #include <algorithm> |
---|
10 | #include <list> |
---|
11 | |
---|
12 | #if (defined _MSC_VER) && (_MSC_VER == 1200) |
---|
13 | # pragma warning (disable : 4786) // too long name, harmless warning |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <cstdlib> |
---|
17 | #include <cstddef> // size_t |
---|
18 | |
---|
19 | #include <boost/config.hpp> |
---|
20 | #ifdef BOOST_NO_STDC_NAMESPACE |
---|
21 | namespace std{ |
---|
22 | using ::rand; |
---|
23 | using ::size_t; |
---|
24 | } |
---|
25 | #endif |
---|
26 | |
---|
27 | #include <boost/pfto.hpp> |
---|
28 | |
---|
29 | #include <boost/archive/iterators/binary_from_base64.hpp> |
---|
30 | #include <boost/archive/iterators/base64_from_binary.hpp> |
---|
31 | #include <boost/archive/iterators/insert_linebreaks.hpp> |
---|
32 | #include <boost/archive/iterators/remove_whitespace.hpp> |
---|
33 | #include <boost/archive/iterators/transform_width.hpp> |
---|
34 | |
---|
35 | #include <boost/test/test_tools.hpp> |
---|
36 | |
---|
37 | #include <iostream> |
---|
38 | |
---|
39 | template<typename CharType> |
---|
40 | void test_base64(){ |
---|
41 | CharType rawdata[150]; |
---|
42 | std::size_t size = sizeof(rawdata) / sizeof(CharType); |
---|
43 | CharType * rptr; |
---|
44 | for(rptr = rawdata + size; rptr-- > rawdata;) |
---|
45 | *rptr = std::rand(); |
---|
46 | |
---|
47 | // convert to base64 |
---|
48 | typedef std::list<CharType> text_base64_type; |
---|
49 | text_base64_type text_base64; |
---|
50 | |
---|
51 | typedef |
---|
52 | boost::archive::iterators::insert_linebreaks< |
---|
53 | boost::archive::iterators::base64_from_binary< |
---|
54 | boost::archive::iterators::transform_width< |
---|
55 | CharType * |
---|
56 | ,6 |
---|
57 | ,sizeof(CharType) * 8 |
---|
58 | > |
---|
59 | > |
---|
60 | ,72 |
---|
61 | > |
---|
62 | translate_out; |
---|
63 | |
---|
64 | std::copy( |
---|
65 | translate_out(BOOST_MAKE_PFTO_WRAPPER(static_cast<CharType *>(rawdata))), |
---|
66 | translate_out(BOOST_MAKE_PFTO_WRAPPER(rawdata + size)), |
---|
67 | std::back_inserter(text_base64) |
---|
68 | ); |
---|
69 | |
---|
70 | // convert from base64 to binary and compare with the original |
---|
71 | typedef |
---|
72 | boost::archive::iterators::transform_width< |
---|
73 | boost::archive::iterators::binary_from_base64< |
---|
74 | boost::archive::iterators::remove_whitespace< |
---|
75 | BOOST_DEDUCED_TYPENAME text_base64_type::iterator |
---|
76 | > |
---|
77 | >, |
---|
78 | sizeof(CharType) * 8, |
---|
79 | 6 |
---|
80 | > translate_in; |
---|
81 | |
---|
82 | BOOST_CHECK( |
---|
83 | std::equal( |
---|
84 | rawdata, |
---|
85 | rawdata + size, |
---|
86 | translate_in(BOOST_MAKE_PFTO_WRAPPER(text_base64.begin())) |
---|
87 | ) |
---|
88 | ); |
---|
89 | |
---|
90 | } |
---|
91 | |
---|
92 | int |
---|
93 | test_main( int argc, char* argv[] ) |
---|
94 | { |
---|
95 | test_base64<char>(); |
---|
96 | #ifndef BOOST_NO_CWCHAR |
---|
97 | test_base64<wchar_t>(); |
---|
98 | #endif |
---|
99 | return EXIT_SUCCESS; |
---|
100 | } |
---|