]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/spirit/test/x3/binary.cpp
buildsys: switch source download to quincy
[ceph.git] / ceph / src / boost / libs / spirit / test / x3 / binary.cpp
CommitLineData
7c673cae
FG
1/*=============================================================================
2 Copyright (c) 2001-2011 Hartmut Kaiser
3
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6==============================================================================*/
7#include <boost/detail/lightweight_test.hpp>
8
7c673cae
FG
9#include <boost/spirit/home/x3/binary.hpp>
10#include <boost/cstdint.hpp>
92f5a8d4 11#include <boost/predef/other/endian.h>
7c673cae
FG
12#include "test.hpp"
13
14///////////////////////////////////////////////////////////////////////////////
15int main()
16{
17 using spirit_test::test_attr;
18 using spirit_test::test;
19 using spirit_test::binary_test;
20 using spirit_test::binary_test_attr;
21
22 using boost::spirit::x3::byte_;
23 using boost::spirit::x3::word;
24 using boost::spirit::x3::dword;
25 using boost::spirit::x3::big_word;
26 using boost::spirit::x3::big_dword;
27 using boost::spirit::x3::little_word;
28 using boost::spirit::x3::little_dword;
29#ifdef BOOST_HAS_LONG_LONG
30 using boost::spirit::x3::qword;
31 using boost::spirit::x3::big_qword;
32 using boost::spirit::x3::little_qword;
33#endif
34// using boost::spirit::x3::bin_float;
35// using boost::spirit::x3::big_bin_float;
36// using boost::spirit::x3::little_bin_float;
37// using boost::spirit::x3::bin_double;
38// using boost::spirit::x3::big_bin_double;
39// using boost::spirit::x3::little_bin_double;
40
41 boost::uint8_t uc;
42 boost::uint16_t us;
43 boost::uint32_t ui;
44#ifdef BOOST_HAS_LONG_LONG
45 boost::uint64_t ul;
46#endif
11fdf7f2
TL
47// float f;
48// double d;
7c673cae 49
f67539c2
TL
50 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(byte_);
51 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(word);
52 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(dword);
53 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(big_word);
54 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(big_dword);
55 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(little_word);
56 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(little_dword);
57#ifdef BOOST_HAS_LONG_LONG
58 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(qword);
59 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(big_qword);
60 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(little_qword);
61#endif
62
63// TODO: boost::endian::endian_arithmetic value constructor is not constexpr
64#if 0
65 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(byte_(1));
66 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(word(1));
67 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(dword(1));
68 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(big_word(1));
69 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(big_dword(1));
70 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(little_word(1));
71 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(little_dword(1));
72#ifdef BOOST_HAS_LONG_LONG
73 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(qword(1));
74 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(big_qword(1));
75 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(little_qword(1));
76#endif
77#endif
78
7c673cae 79 { // test native endian binaries
92f5a8d4 80#if BOOST_ENDIAN_LITTLE_BYTE
7c673cae
FG
81 BOOST_TEST(test_attr("\x01", byte_, uc) && uc == 0x01);
82 BOOST_TEST(test_attr("\x01\x02", word, us) && us == 0x0201);
83 BOOST_TEST(test_attr("\x01\x02\x03\x04", dword, ui) && ui == 0x04030201);
84#ifdef BOOST_HAS_LONG_LONG
85 BOOST_TEST(test_attr("\x01\x02\x03\x04\x05\x06\x07\x08", qword, ul) &&
86 ul == 0x0807060504030201LL);
87#endif
88// BOOST_TEST(binary_test_attr("\x00\x00\x80\x3f", 4, bin_float, f) &&
89// f == 1.0f);
90// BOOST_TEST(binary_test_attr("\x00\x00\x00\x00\x00\x00\xf0\x3f",
91// 8, bin_double, d) && f == 1.0);
92#else
93 BOOST_TEST(test_attr("\x01", byte_, uc) && uc == 0x01);
94 BOOST_TEST(test_attr("\x01\x02", word, us) && us == 0x0102);
95 BOOST_TEST(test_attr("\x01\x02\x03\x04", dword, ui) && ui == 0x01020304);
96#ifdef BOOST_HAS_LONG_LONG
97 BOOST_TEST(test_attr("\x01\x02\x03\x04\x05\x06\x07\x08", qword, ul) &&
98 ul == 0x0102030405060708LL);
99#endif
100// BOOST_TEST(binary_test_attr("\x3f\x80\x00\x00", 4, bin_float, f) &&
101// f == 1.0f);
102// BOOST_TEST(binary_test_attr("\x3f\xf0\x00\x00\x00\x00\x00\x00",
103// 8, bin_double, d) && f == 1.0);
104#endif
105 }
106
107 { // test native endian binaries
92f5a8d4 108#if BOOST_ENDIAN_LITTLE_BYTE
7c673cae
FG
109 BOOST_TEST(test("\x01", byte_(0x01)));
110 BOOST_TEST(test("\x01\x02", word(0x0201)));
111 BOOST_TEST(test("\x01\x02\x03\x04", dword(0x04030201)));
112#ifdef BOOST_HAS_LONG_LONG
113 BOOST_TEST(test("\x01\x02\x03\x04\x05\x06\x07\x08",
114 qword(0x0807060504030201LL)));
115#endif
116// BOOST_TEST(binary_test("\x00\x00\x80\x3f", 4, bin_float(1.0f)));
117// BOOST_TEST(binary_test("\x00\x00\x00\x00\x00\x00\xf0\x3f", 8,
118// bin_double(1.0)));
119#else
120 BOOST_TEST(test("\x01", byte_(0x01)));
121 BOOST_TEST(test("\x01\x02", word(0x0102)));
122 BOOST_TEST(test("\x01\x02\x03\x04", dword(0x01020304)));
123#ifdef BOOST_HAS_LONG_LONG
124 BOOST_TEST(test("\x01\x02\x03\x04\x05\x06\x07\x08",
125 qword(0x0102030405060708LL)));
126#endif
127// BOOST_TEST(binary_test("\x3f\x80\x00\x00", 4, bin_float(1.0f)));
128// BOOST_TEST(binary_test("\x3f\x80\x00\x00\x00\x00\x00\x00", 8,
129// bin_double(1.0)));
130#endif
131 }
132
133 { // test big endian binaries
134 BOOST_TEST(test_attr("\x01\x02", big_word, us) && us == 0x0102);
135 BOOST_TEST(test_attr("\x01\x02\x03\x04", big_dword, ui) && ui == 0x01020304);
136#ifdef BOOST_HAS_LONG_LONG
137 BOOST_TEST(test_attr("\x01\x02\x03\x04\x05\x06\x07\x08", big_qword, ul)
138 && ul == 0x0102030405060708LL);
139#endif
140// BOOST_TEST(binary_test_attr("\x3f\x80\x00\x00", 4, big_bin_float, f) &&
141// f == 1.0f);
142// BOOST_TEST(binary_test_attr("\x3f\xf0\x00\x00\x00\x00\x00\x00",
143// 8, big_bin_double, d) && f == 1.0);
144 }
145
146 {
147 BOOST_TEST(test("\x01\x02", big_word(0x0102)));
148 BOOST_TEST(test("\x01\x02\x03\x04", big_dword(0x01020304)));
149#ifdef BOOST_HAS_LONG_LONG
150 BOOST_TEST(test("\x01\x02\x03\x04\x05\x06\x07\x08",
151 big_qword(0x0102030405060708LL)));
152#endif
153// BOOST_TEST(binary_test("\x3f\x80\x00\x00", 4, big_bin_float(1.0f)));
154// BOOST_TEST(binary_test("\x3f\xf0\x00\x00\x00\x00\x00\x00", 8,
155// big_bin_double(1.0)));
156 }
157
158 { // test little endian binaries
159 BOOST_TEST(test_attr("\x01\x02", little_word, us) && us == 0x0201);
160 BOOST_TEST(test_attr("\x01\x02\x03\x04", little_dword, ui) && ui == 0x04030201);
161#ifdef BOOST_HAS_LONG_LONG
162 BOOST_TEST(test_attr("\x01\x02\x03\x04\x05\x06\x07\x08", little_qword, ul)
163 && ul == 0x0807060504030201LL);
164#endif
165// BOOST_TEST(binary_test_attr("\x00\x00\x80\x3f", 4,
166// little_bin_float, f) && f == 1.0f);
167// BOOST_TEST(binary_test_attr("\x00\x00\x00\x00\x00\x00\xf0\x3f",
168// 8, little_bin_double, d) && f == 1.0);
169 }
170
171 {
172 BOOST_TEST(test("\x01\x02", little_word(0x0201)));
173 BOOST_TEST(test("\x01\x02\x03\x04", little_dword(0x04030201)));
174#ifdef BOOST_HAS_LONG_LONG
175 BOOST_TEST(test("\x01\x02\x03\x04\x05\x06\x07\x08",
176 little_qword(0x0807060504030201LL)));
177#endif
178// BOOST_TEST(binary_test("\x00\x00\x80\x3f", 4, little_bin_float(1.0f)));
179// BOOST_TEST(binary_test("\x00\x00\x00\x00\x00\x00\xf0\x3f", 8,
180// little_bin_double(1.0)));
181 }
182
183 return boost::report_errors();
184}