1 #include <boost/config.hpp>
2 #include <boost/network/utils/base64/encode.hpp>
3 #include <boost/network/utils/base64/encode-io.hpp>
4 #include "utils/base64-standalone.hpp"
5 // Since we're having issues with libc++ on OS X we're excluding this in the
6 // meantime if we're using libc++
7 #ifndef _LIBCPP_VERSION
8 #include "utils/base64-stateless.hpp"
9 #include "utils/base64-stateful_buffer.hpp"
10 #endif
11 #include "utils/base64-stateful_iterator.hpp"
12 #include "utils/base64-stateful_transform.hpp"
13 #include <iostream>
14 #include <iterator>
15 #include <string>
16 #include <vector>
17 #include <sstream>
18 #include <cstdlib>
19 
20 // the main entry point does nothing; the tests are run by constructors
21 // of testing classes, which are executed by global variables
main(int argc,char const * argv[])22 int main(int argc, char const* argv[]) { return 0; }
23 
24 using namespace boost::network::utils;
25 
26 // macros to build names of test classes ans gobal runner variables
27 #define stringify_internal(x) #x
28 #define stringify(x) stringify_internal(x)
29 #define concatenate_internal(x, y) x##y
30 #define concatenate(x, y) concatenate_internal(x, y)
31 
32 #ifdef NDEBUG
33 // testing block sizes (im MB) which let the tests run approximately
34 // 5s on my machine in the optimized mode
35 #define single_block_size 160
36 #define multiple_block_size 320
37 #define multiple_block_count 1280
38 #else
39 // testing block sizes (im MB) which let the tests run approximately
40 // 5s on my machine in the not optimized mode
41 #define single_block_size 16
42 #define multiple_block_size 64
43 #define multiple_block_count 256
44 #endif
45 
46 // the class name of a test suite; base64 has to be defined as a namespace
47 // name with an alternative implementation of the base64 encoding interface
48 #define test_name concatenate(base64, _test)
49 
50 // the code which actually performs the encoding; base64 has to be defined
51 // as a namespace name - see above
52 #define encode_single_block std::string result = base64::encode<char>(buffer)
53 #define encode_multiple_blocks                                          \
54   std::string result;                                                   \
55   std::back_insert_iterator<std::string> result_encoder(result);        \
56   base64::state<unsigned char> rest;                                    \
57   for (unsigned block_index = 0; block_index < buffers.size();          \
58        ++block_index) {                                                 \
59     std::vector<unsigned char> const& buffer = buffers[block_index];    \
60     base64::encode(buffer.begin(), buffer.end(), result_encoder, rest); \
61   }                                                                     \
62   base64::encode_rest(result_encoder, rest)
63 
64 // testing the code from experimental/base64-stateless.hpp
65 // NOTE(dberris): Only do this if we're NOT using libc++.
66 #ifndef _LIBCPP_VERSION
67 #define base64 base64_stateless
68 #include "utils_base64_experiment.ipp"
69 #undef base64
70 
71 // enable the second test case, which encodes the input buffer chunk by chunk
72 // and remembers the encoding state to be able to continue
73 #define base64_with_state
74 
75 // testing the code from experimental/base64-stateful_buffer.hpp
76 #define base64 base64_stateful_buffer
77 #include "utils_base64_experiment.ipp"
78 #undef base64
79 #endif  // _LIBCPP_VERSION
80 
81 // testing the code from experimental/base64-stateful_transform.hpp
82 #define base64 base64_stateful_transform
83 #include "utils_base64_experiment.ipp"
84 #undef base64
85 
86 // testing the code from experimental/base64-stateful_iterator.hpp
87 #define base64 base64_stateful_iterator
88 #include "utils_base64_experiment.ipp"
89 #undef base64
90 
91 // testing the code from experimental/base64-standalone.hpp,
92 // which has become the code in boost/network/utils/base64/encode.hpp
93 #define base64 base64_standalone
94 #include "utils_base64_experiment.ipp"
95 #undef base64
96 
97 // redefine the testing code to use the iostream implementation from
98 // boost/network/utils/base64/encode-io.hpp which depends on the
99 // interface from boost/network/utils/base64/encode.hpp
100 #undef test_name
101 #undef encode_single_block
102 #undef encode_multiple_blocks
103 #define test_name concatenate(concatenate(base64, _standalone_io), _test)
104 #define encode_single_block \
105   std::stringstream result; \
106   result << base64::io::encode(buffer) << base64::io::encode_rest<unsigned char>
107 #define encode_multiple_blocks                                       \
108   std::stringstream result;                                          \
109   for (unsigned block_index = 0; block_index < buffers.size();       \
110        ++block_index) {                                              \
111     std::vector<unsigned char> const& buffer = buffers[block_index]; \
112     result << base64::io::encode(buffer.begin(), buffer.end());      \
113   }                                                                  \
114   result << base64::io::encode_rest<unsigned char>
115 
116 // testing the iostream implementation with the code from
117 // boost/network/utils/base64/encode.hpp
118 #define base64 base64
119 #include "utils_base64_experiment.ipp"
120 #undef base64
121