1 // binary_stream_test.cpp ------------------------------------------------------------//
3 // Copyright Beman Dawes 2009
5 // Distributed under the Boost Software License, Version 1.0.
6 // See http://www.boost.org/LICENSE_1_0.txt
8 #include <boost/binary_stream.hpp>
13 using namespace boost
;
20 void verify( bool x
, const char * file
, int line
)
24 cout
<< file
<< "(" << line
<< ") : error: predicate is false\n" << endl
;
29 #define BOOST_VERIFY(predicate) verify( predicate, __FILE__, __LINE__ )
34 std::stringstream
ss( std::ios_base::in
| std::ios_base::out
| std::ios_base::binary
);
36 short short_1(0x0102), short_2
;
39 BOOST_VERIFY( short_1
== short_2
);
41 unsigned short ushort_1(0x0102), ushort_2
;
44 BOOST_VERIFY( ushort_1
== ushort_2
);
46 int int_1(0x01020304), int_2
;
49 BOOST_VERIFY( int_1
== int_2
);
51 unsigned int uint_1(0x01020304), uint_2
;
54 BOOST_VERIFY( uint_1
== uint_2
);
56 long long_1(0x01020304L
), long_2
;
59 BOOST_VERIFY( long_1
== long_2
);
61 unsigned long ulong_1(0x01020304UL
), ulong_2
;
64 BOOST_VERIFY( ulong_1
== ulong_2
);
66 long long long_long_1(0x0102030405060708LL
), long_long_2
;
69 BOOST_VERIFY( long_long_1
== long_long_2
);
71 unsigned long long ulong_long_1(0x0102030405060708ULL
), ulong_long_2
;
74 BOOST_VERIFY( ulong_long_1
== ulong_long_2
);
76 float float_1(1.2F
), float_2
;
79 BOOST_VERIFY( float_1
== float_2
);
81 double double_1(1.2), double_2
;
84 BOOST_VERIFY( double_1
== double_2
);
86 long double long_double_1(1.2), long_double_2
;
89 BOOST_VERIFY( long_double_1
== long_double_2
);
91 char char_1(0x01), char_2
;
94 BOOST_VERIFY( char_1
== char_2
);
96 signed char schar_1(0x01), schar_2
;
99 BOOST_VERIFY( schar_1
== schar_2
);
101 unsigned char uchar_1(0x01), uchar_2
;
104 BOOST_VERIFY( uchar_1
== uchar_2
);
106 wchar_t wchar_t_1(L
'1'), wchar_t_2
;
109 BOOST_VERIFY( wchar_t_1
== wchar_t_2
);
111 string
string_1("foobar"), string_2
;
112 ss
<= string_1
.c_str();
114 BOOST_VERIFY( string_1
== string_2
);
117 BOOST_VERIFY( string_1
== string_2
);
119 cout
<< errors
<< " error(s) detected\n";