]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/karma/binary3.cpp
d666307eb175e2d2dc257a780b4111868fd166dd
1 // Copyright (c) 2001-2011 Hartmut Kaiser
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #include <boost/config/warning_disable.hpp>
7 #include <boost/detail/lightweight_test.hpp>
9 #include <boost/spirit/include/karma_binary.hpp>
10 #include <boost/spirit/include/karma_generate.hpp>
12 #include <boost/spirit/include/phoenix_core.hpp>
13 #include <boost/spirit/include/phoenix_operator.hpp>
15 #include <boost/predef/other/endian.h>
19 using namespace spirit_test
;
21 ///////////////////////////////////////////////////////////////////////////////
25 using namespace boost::spirit
;
26 using namespace boost::phoenix
;
28 { // test optional attributes
30 #if BOOST_ENDIAN_LITTLE_BYTE
31 boost::optional
<boost::uint8_t> v8 (0x01);
32 BOOST_TEST(binary_test("\x01", 1, byte_
, v8
));
33 boost::optional
<boost::uint16_t> v16 (0x0201);
34 BOOST_TEST(binary_test("\x01\x02", 2, word
, v16
));
35 boost::optional
<boost::uint32_t> v32 (0x04030201);
36 BOOST_TEST(binary_test("\x01\x02\x03\x04", 4, dword
, v32
));
37 #ifdef BOOST_HAS_LONG_LONG
38 boost::optional
<boost::uint64_t> v64 (0x0807060504030201LL
);
39 BOOST_TEST(binary_test("\x01\x02\x03\x04\x05\x06\x07\x08", 8, qword
, v64
));
41 boost::optional
<float> vf(1.0f
);
42 BOOST_TEST(binary_test("\x00\x00\x80\x3f", 4, bin_float
, vf
));
43 boost::optional
<double> vd(1.0);
44 BOOST_TEST(binary_test("\x00\x00\x00\x00\x00\x00\xf0\x3f", 8,
47 #else // BOOST_ENDIAN_LITTLE_BYTE
49 boost::optional
<boost::uint8_t> v8 (0x01);
50 BOOST_TEST(binary_test("\x01", 1, byte_
, v8
));
51 boost::optional
<boost::uint16_t> v16 (0x0102);
52 BOOST_TEST(binary_test("\x01\x02", 2, word
, v16
));
53 boost::optional
<boost::uint32_t> v32 (0x01020304);
54 BOOST_TEST(binary_test("\x01\x02\x03\x04", 4, dword
, v32
));
55 #ifdef BOOST_HAS_LONG_LONG
56 boost::optional
<boost::uint64_t> v64 (0x0102030405060708LL
);
57 BOOST_TEST(binary_test("\x01\x02\x03\x04\x05\x06\x07\x08", 8, qword
, v64
));
59 boost::optional
<float> vf(1.0f
);
60 BOOST_TEST(binary_test("\x3f\x80\x00\x00", 4, bin_float
, vf
));
61 boost::optional
<double> vd(1.0);
62 BOOST_TEST(binary_test("\x3f\xf0\x00\x00\x00\x00\x00\x00", 8,
68 // we support Phoenix attributes only starting with V2.2
69 #if SPIRIT_VERSION >= 0x2020
70 { // test Phoenix expression attributes, only supported if
71 // karma_phoenix_attributes.hpp is included
72 namespace phoenix
= boost::phoenix
;
74 #if BOOST_ENDIAN_LITTLE_BYTE
75 BOOST_TEST(binary_test("\x01", 1, byte_
, phoenix::val(0x01)));
76 BOOST_TEST(binary_test("\x01\x02", 2, word
, phoenix::val(0x0201)));
77 BOOST_TEST(binary_test("\x01\x02\x03\x04", 4, dword
,
78 phoenix::val(0x04030201)));
80 boost::uint8_t v8 (0x01);
81 BOOST_TEST(binary_test("\x01", 1, byte_
, phoenix::ref(v8
)));
82 BOOST_TEST(binary_test("\x02", 1, byte_
, ++phoenix::ref(v8
)));
84 boost::uint16_t v16 (0x0201);
85 BOOST_TEST(binary_test("\x01\x02", 2, word
, phoenix::ref(v16
)));
86 BOOST_TEST(binary_test("\x02\x02", 2, word
, ++phoenix::ref(v16
)));
88 boost::uint32_t v32 (0x04030201);
89 BOOST_TEST(binary_test("\x01\x02\x03\x04", 4, dword
, phoenix::ref(v32
)));
90 BOOST_TEST(binary_test("\x02\x02\x03\x04", 4, dword
, ++phoenix::ref(v32
)));
92 #ifdef BOOST_HAS_LONG_LONG
93 BOOST_TEST(binary_test("\x01\x02\x03\x04\x05\x06\x07\x08", 8, qword
,
94 phoenix::val(0x0807060504030201LL
)));
96 boost::uint64_t v64 (0x0807060504030201LL
);
97 BOOST_TEST(binary_test("\x01\x02\x03\x04\x05\x06\x07\x08", 8, qword
,
99 BOOST_TEST(binary_test("\x02\x02\x03\x04\x05\x06\x07\x08", 8, qword
,
100 ++phoenix::ref(v64
)));
102 BOOST_TEST(binary_test("\x00\x00\x80\x3f", 4, bin_float
,
103 phoenix::val(1.0f
)));
105 BOOST_TEST(binary_test("\x00\x00\x80\x3f", 4, bin_float
,
107 BOOST_TEST(binary_test("\x00\x00\x00\x40", 4, bin_float
,
108 ++phoenix::ref(vf
)));
110 BOOST_TEST(binary_test("\x00\x00\x00\x00\x00\x00\xf0\x3f", 8,
111 bin_double
, phoenix::val(1.0)));
113 BOOST_TEST(binary_test("\x00\x00\x00\x00\x00\x00\xf0\x3f", 8,
114 bin_double
, phoenix::ref(vd
)));
115 BOOST_TEST(binary_test("\x00\x00\x00\x00\x00\x00\x00\x40", 8,
116 bin_double
, ++phoenix::ref(vd
)));
118 #else // BOOST_ENDIAN_LITTLE_BYTE
120 BOOST_TEST(binary_test("\x01", 1, byte_
, phoenix::val(0x01)));
121 BOOST_TEST(binary_test("\x01\x02", 2, word
, phoenix::val(0x0102)));
122 BOOST_TEST(binary_test("\x01\x02\x03\x04", 4, dword
,
123 phoenix::val(0x01020304)));
125 boost::uint8_t v8 (0x01);
126 BOOST_TEST(binary_test("\x01", 1, byte_
, phoenix::ref(v8
)));
127 BOOST_TEST(binary_test("\x02", 1, byte_
, ++phoenix::ref(v8
)));
129 boost::uint16_t v16 (0x0102);
130 BOOST_TEST(binary_test("\x01\x02", 2, word
, phoenix::ref(v16
)));
131 BOOST_TEST(binary_test("\x01\x03", 2, word
, ++phoenix::ref(v16
)));
133 boost::uint32_t v32 (0x01020304);
134 BOOST_TEST(binary_test("\x01\x02\x03\x04", 4, dword
, phoenix::ref(v32
)));
135 BOOST_TEST(binary_test("\x01\x02\x03\x05", 4, dword
, ++phoenix::ref(v32
)));
137 #ifdef BOOST_HAS_LONG_LONG
138 BOOST_TEST(binary_test("\x01\x02\x03\x04\x05\x06\x07\x08", 8, qword
,
139 phoenix::val(0x0102030405060708LL
)));
141 boost::uint64_t v64 (0x0102030405060708LL
);
142 BOOST_TEST(binary_test("\x01\x02\x03\x04\x05\x06\x07\x08", 8, qword
,
144 BOOST_TEST(binary_test("\x01\x02\x03\x04\x05\x06\x07\x09", 8, qword
,
145 ++phoenix::ref(v64
)));
147 BOOST_TEST(binary_test("\x3f\x80\x00\x00", 4, bin_float
,
148 phoenix::val(1.0f
)));
150 BOOST_TEST(binary_test("\x3f\x80\x00\x00", 4, bin_float
,
152 BOOST_TEST(binary_test("\x40\x00\x00\x00", 4, bin_float
,
153 ++phoenix::ref(vf
)));
155 BOOST_TEST(binary_test("\x3f\xf0\x00\x00\x00\x00\x00\x00", 8,
156 bin_double
, phoenix::val(1.0)));
158 BOOST_TEST(binary_test("\x3f\xf0\x00\x00\x00\x00\x00\x00", 8,
159 bin_double
, phoenix::ref(vd
)));
160 BOOST_TEST(binary_test("\x40\x00\x00\x00\x00\x00\x00\x00", 8,
161 bin_double
, ++phoenix::ref(vd
)));
167 return boost::report_errors();