1 // deprecated_test.cpp ---------------------------------------------------------------//
2
3 // Copyright Beman Dawes 2014, 2015
4
5 // Distributed under the Boost Software License, Version 1.0.
6 // See http://www.boost.org/LICENSE_1_0.txt
7
8 // See library home page at http://www.boost.org/libs/endian
9
10 //--------------------------------------------------------------------------------------//
11
12 #include <boost/endian/detail/disable_warnings.hpp>
13
14 #define BOOST_ENDIAN_DEPRECATED_NAMES
15 #include <boost/endian/endian.hpp>
16 #include <boost/core/lightweight_test.hpp>
17 #include <boost/cstdint.hpp>
18 #include <iostream>
19 #include <sstream>
20
21 using namespace boost::endian;
22 using std::cout;
23 using std::endl;
24
25 namespace
26 {
27
28 // check_size ----------------------------------------------------------------------//
29
check_size()30 void check_size()
31 {
32 BOOST_TEST_EQ(sizeof(big8_t), 1);
33 BOOST_TEST_EQ(sizeof(big16_t), 2);
34 BOOST_TEST_EQ(sizeof(big24_t), 3);
35 BOOST_TEST_EQ(sizeof(big32_t), 4);
36 BOOST_TEST_EQ(sizeof(big40_t), 5);
37 BOOST_TEST_EQ(sizeof(big48_t), 6);
38 BOOST_TEST_EQ(sizeof(big56_t), 7);
39 BOOST_TEST_EQ(sizeof(big64_t), 8);
40
41 BOOST_TEST_EQ(sizeof(ubig8_t), 1);
42 BOOST_TEST_EQ(sizeof(ubig16_t), 2);
43 BOOST_TEST_EQ(sizeof(ubig24_t), 3);
44 BOOST_TEST_EQ(sizeof(ubig32_t), 4);
45 BOOST_TEST_EQ(sizeof(ubig40_t), 5);
46 BOOST_TEST_EQ(sizeof(ubig48_t), 6);
47 BOOST_TEST_EQ(sizeof(ubig56_t), 7);
48 BOOST_TEST_EQ(sizeof(ubig64_t), 8);
49
50 BOOST_TEST_EQ(sizeof(little8_t), 1);
51 BOOST_TEST_EQ(sizeof(little16_t), 2);
52 BOOST_TEST_EQ(sizeof(little24_t), 3);
53 BOOST_TEST_EQ(sizeof(little32_t), 4);
54 BOOST_TEST_EQ(sizeof(little40_t), 5);
55 BOOST_TEST_EQ(sizeof(little48_t), 6);
56 BOOST_TEST_EQ(sizeof(little56_t), 7);
57 BOOST_TEST_EQ(sizeof(little64_t), 8);
58
59 BOOST_TEST_EQ(sizeof(ulittle8_t), 1);
60 BOOST_TEST_EQ(sizeof(ulittle16_t), 2);
61 BOOST_TEST_EQ(sizeof(ulittle24_t), 3);
62 BOOST_TEST_EQ(sizeof(ulittle32_t), 4);
63 BOOST_TEST_EQ(sizeof(ulittle40_t), 5);
64 BOOST_TEST_EQ(sizeof(ulittle48_t), 6);
65 BOOST_TEST_EQ(sizeof(ulittle56_t), 7);
66 BOOST_TEST_EQ(sizeof(ulittle64_t), 8);
67
68 BOOST_TEST_EQ(sizeof(native8_t), 1);
69 BOOST_TEST_EQ(sizeof(native16_t), 2);
70 BOOST_TEST_EQ(sizeof(native24_t), 3);
71 BOOST_TEST_EQ(sizeof(native32_t), 4);
72 BOOST_TEST_EQ(sizeof(native40_t), 5);
73 BOOST_TEST_EQ(sizeof(native48_t), 6);
74 BOOST_TEST_EQ(sizeof(native56_t), 7);
75 BOOST_TEST_EQ(sizeof(native64_t), 8);
76
77 BOOST_TEST_EQ(sizeof(unative8_t), 1);
78 BOOST_TEST_EQ(sizeof(unative16_t), 2);
79 BOOST_TEST_EQ(sizeof(unative24_t), 3);
80 BOOST_TEST_EQ(sizeof(unative32_t), 4);
81 BOOST_TEST_EQ(sizeof(unative40_t), 5);
82 BOOST_TEST_EQ(sizeof(unative48_t), 6);
83 BOOST_TEST_EQ(sizeof(unative56_t), 7);
84 BOOST_TEST_EQ(sizeof(unative64_t), 8);
85
86 BOOST_TEST_EQ(sizeof(aligned_big16_t), 2);
87 BOOST_TEST_EQ(sizeof(aligned_big32_t), 4);
88 BOOST_TEST_EQ(sizeof(aligned_big64_t), 8);
89
90 BOOST_TEST_EQ(sizeof(aligned_ubig16_t), 2);
91 BOOST_TEST_EQ(sizeof(aligned_ubig32_t), 4);
92 BOOST_TEST_EQ(sizeof(aligned_ubig64_t), 8);
93
94 BOOST_TEST_EQ(sizeof(aligned_little16_t), 2);
95 BOOST_TEST_EQ(sizeof(aligned_little32_t), 4);
96 BOOST_TEST_EQ(sizeof(aligned_little64_t), 8);
97
98 BOOST_TEST_EQ(sizeof(aligned_ulittle16_t), 2);
99 BOOST_TEST_EQ(sizeof(aligned_ulittle32_t), 4);
100 BOOST_TEST_EQ(sizeof(aligned_ulittle64_t), 8);
101
102 # ifndef BOOST_NO_CXX11_TEMPLATE_ALIASES
103 BOOST_TEST_EQ(sizeof(endian<endianness::big, int_least16_t, 16>), 2);
104 BOOST_TEST_EQ(sizeof(endian<endianness::big,
105 int_least16_t, 16, alignment::unaligned>), 2);
106 # endif
107 } // check_size
108
109 // test_inserter_and_extractor -----------------------------------------------------//
110
test_inserter_and_extractor()111 void test_inserter_and_extractor()
112 {
113 std::cout << "test inserter and extractor..." << std::endl;
114
115 ubig64_t bu64(0x010203040506070ULL);
116 ulittle64_t lu64(0x010203040506070ULL);
117
118 boost::uint64_t x;
119
120 std::stringstream ss;
121
122 ss << bu64;
123 ss >> x;
124 BOOST_TEST_EQ(x, 0x010203040506070ULL);
125
126 ss.clear();
127 ss << lu64;
128 ss >> x;
129 BOOST_TEST_EQ(x, 0x010203040506070ULL);
130
131 ss.clear();
132 ss << 0x010203040506070ULL;
133 ubig64_t bu64z(0);
134 ss >> bu64z;
135 BOOST_TEST_EQ(bu64z, bu64);
136
137 ss.clear();
138 ss << 0x010203040506070ULL;
139 ulittle64_t lu64z(0);
140 ss >> lu64z;
141 BOOST_TEST_EQ(lu64z, lu64);
142
143 std::cout << "test inserter and extractor complete" << std::endl;
144
145 }
146
147 } // unnamed namespace
148
149 //--------------------------------------------------------------------------------------//
150
cpp_main(int,char * [])151 int cpp_main(int, char *[])
152 {
153 cout << "byte swap intrinsics: " BOOST_ENDIAN_INTRINSIC_MSG << endl;
154
155 cout << " construct big endian aligned" << endl;
156 big32_t x(1122334455);
157
158 cout << " assign to buffer from built-in integer" << endl;
159 x = 1234567890;
160
161 cout << " operator==(buffer.value(), built-in)" << endl;
162 bool b1(x == 1234567890);
163 BOOST_TEST(b1);
164
165 cout << " construct little endian unaligned" << endl;
166 little32_t x2(1122334455);
167
168 cout << " assign to buffer from built-in integer" << endl;
169 x2 = 1234567890;
170
171 cout << " operator==(buffer.value(), built-in)" << endl;
172 bool b2(x2 == 1234567890);
173 BOOST_TEST(b2);
174
175 check_size();
176 test_inserter_and_extractor();
177
178 cout << " done" << endl;
179
180 return ::boost::report_errors();
181 }
182
main(int argc,char * argv[])183 int main( int argc, char* argv[] )
184 {
185 try
186 {
187 return cpp_main( argc, argv );
188 }
189 catch( std::exception const & x )
190 {
191 BOOST_ERROR( x.what() );
192 return boost::report_errors();
193 }
194 }
195
196 #include <boost/endian/detail/disable_warnings_pop.hpp>
197