40 using namespace tfc::Base64;
48 #include <boost/iostreams/concepts.hpp>
49 #include <boost/iostreams/categories.hpp>
50 #include <boost/iostreams/operations.hpp>
51 #include <boost/iostreams/invert.hpp>
52 #include <boost/iostreams/device/file_descriptor.hpp>
53 #include <boost/iostreams/filtering_stream.hpp>
59 namespace io = boost::iostreams;
61 class CodificadorBase64 :
public io::multichar_output_filter {
63 template<
typename TDesti>
64 streamsize write(TDesti& dest,
const char * buf, streamsize
mida) {
65 const string codificat =
codifica(
string(buf, mida));
66 return dest.write(codificat.c_str(), codificat.length());
75 namespace tfc {
namespace Fixtures {
80 0x21, 0xd4, 0xb5, 0x84, 0x67, 0x7f, 0x96, 0x18, 0xa, 0x0, 0x15, 0x3f, 0xcd,
81 0x3f, 0x7f, 0x58, 0x27, 0x96, 0xd2, 0x8d, 0x63, 0xab, 0x17, 0x4, 0x25, 0xec,
82 0x9c, 0xeb, 0x5, 0x5e, 0xa3, 0xf6, 0xa8, 0x00 };
86 : text_llarg(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
87 "In in urna ligula. Nunc condimentum pretium urna eu pharetra. "
88 "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
89 "Donec auctor felis sed ipsum tristique fermentum. "
90 "Vivamus id luctus justo. Phasellus enim neque, ultricies sed "
91 "varius at, vehicula aliquam elit. Sed molestie condimentum "
92 "erat, at commodo tortor consectetur eu. Donec lacinia lorem "
93 "vel arcu dictum commodo eget at libero. Cras rutrum quam "
94 "quis tortor tincidunt at convallis turpis euismod.")
97 const char *
final = principi + 40;
98 cadena_binaria.assign(principi,
final);
111 BOOST_CHECK_EQUAL(
codifica(
"Sense pad"),
"U2Vuc2UgcGFk" );
112 BOOST_CHECK_EQUAL(
descodifica(
"U2Vuc2UgcGFk"),
"Sense pad" );
117 BOOST_CHECK_EQUAL(
codifica(
"PAD=1"),
"UEFEPTE=" );
118 BOOST_CHECK_EQUAL(
descodifica(
"UEFEPTE="),
"PAD=1" );
123 BOOST_CHECK_EQUAL(
codifica(
"padding: 2"),
"cGFkZGluZzogMg==" );
124 BOOST_CHECK_EQUAL(
descodifica(
"cGFkZGluZzogMg=="),
"padding: 2" );
125 BOOST_CHECK_EQUAL(
codifica(
"abcdefghijkml"),
"YWJjZGVmZ2hpamttbA==" );
145 namespace io = boost::iostreams;
148 cerr <<
"Fitxer temporal: " << nom << endl;
153 io::filtering_ostream out;
154 out.push(CodificadorBase64());
158 BOOST_AUTO_TEST_SUITE_END()