From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- .../serialization/test/test_iterators_base64.cpp | 105 +++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 src/boost/libs/serialization/test/test_iterators_base64.cpp (limited to 'src/boost/libs/serialization/test/test_iterators_base64.cpp') diff --git a/src/boost/libs/serialization/test/test_iterators_base64.cpp b/src/boost/libs/serialization/test/test_iterators_base64.cpp new file mode 100644 index 000000000..1f772c6d7 --- /dev/null +++ b/src/boost/libs/serialization/test/test_iterators_base64.cpp @@ -0,0 +1,105 @@ +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// test_iterators.cpp + +// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#include + +#if (defined _MSC_VER) && (_MSC_VER == 1200) +# pragma warning (disable : 4786) // too long name, harmless warning +#endif + +#include +#include // size_t + +#include +#ifdef BOOST_NO_STDC_NAMESPACE +namespace std{ + using ::rand; + using ::size_t; +} +#endif + +#include +#include +#include +#include +#include + +#include "test_tools.hpp" + +#include + +template +void test_base64(unsigned int size){ + CharType rawdata[150]; + CharType * rptr; + for(rptr = rawdata + size; rptr-- > rawdata;) + *rptr = static_cast(std::rand()& 0xff); + + // convert to base64 + typedef std::list text_base64_type; + text_base64_type text_base64; + + typedef + boost::archive::iterators::insert_linebreaks< + boost::archive::iterators::base64_from_binary< + boost::archive::iterators::transform_width< + CharType * + ,6 + ,sizeof(CharType) * 8 + > + > + ,76 + > + translate_out; + + std::copy( + translate_out(static_cast(rawdata)), + translate_out(rawdata + size), + std::back_inserter(text_base64) + ); + + // convert from base64 to binary and compare with the original + typedef + boost::archive::iterators::transform_width< + boost::archive::iterators::binary_from_base64< + boost::archive::iterators::remove_whitespace< + typename text_base64_type::iterator + > + >, + sizeof(CharType) * 8, + 6 + > translate_in; + + BOOST_CHECK( + std::equal( + rawdata, + rawdata + size, + translate_in(text_base64.begin()) + ) + ); + +} + +int +test_main( int /*argc*/, char* /*argv*/[] ) +{ + test_base64(1); + test_base64(2); + test_base64(3); + test_base64(4); + test_base64(150); + #ifndef BOOST_NO_CWCHAR + test_base64(1); + test_base64(2); + test_base64(3); + test_base64(4); + test_base64(150); + #endif + return EXIT_SUCCESS; +} -- cgit v1.2.3