32 #include <boost/lexical_cast.hpp> 33 #include <boost/property_tree/json_parser.hpp> 34 #include <boost/foreach.hpp> 63 char input_letter[] =
"AB";
65 std::cout <<
"Input AB " << input_letter << std::endl;
66 CPPUNIT_ASSERT(strncmp(input_letter,
"BA", 2 ) == 0);
68 char input_num[] =
"12";
70 std::cout <<
"Input 12" << input_num << std::endl;
71 CPPUNIT_ASSERT(strncmp(input_num,
"21", 2 ) == 0);
73 char input_symb[] =
"!@";
75 std::cout <<
"Input !@ " << input_symb << std::endl;
76 CPPUNIT_ASSERT(strncmp(input_symb,
"@!", 2 ) == 0);
82 char input_letter[] =
"ABCD";
84 std::cout <<
"Input ABCD=" << input_letter << std::endl;
85 CPPUNIT_ASSERT(strncmp(input_letter,
"DCBA", 4 ) == 0);
87 char input_num[] =
"1234";
89 std::cout <<
"Input 1234=" << input_num << std::endl;
90 CPPUNIT_ASSERT(strncmp(input_num,
"4321", 4 ) == 0);
92 char input_symb[] =
"!@#$";
94 std::cout <<
"Input !@#$= " << input_symb << std::endl;
95 CPPUNIT_ASSERT(strncmp(input_symb,
"$#@!", 4 ) == 0);
100 char input_letter[] =
"ABCDabcdefghij";
101 int len = strlen(input_letter);
103 std::cout <<
" Input ABCDabcdefghij " << input_letter << std::endl;
104 CPPUNIT_ASSERT_MESSAGE(
"SwapBytes of n bytes (ABCDabcdefghij) is not working!", strncmp(input_letter,
"jihgfedcbaDCBA", len ) == 0);
106 char input_num[] =
"12345678";
108 std::cout <<
" Input 12345678 " << input_num << std::endl;
109 CPPUNIT_ASSERT(strncmp(input_num,
"87654321", 8 ) == 0);
111 char input_symb[] =
"!@#$%&*(";
113 std::cout <<
" Input !@#$%&*( " << input_symb << std::endl;
114 CPPUNIT_ASSERT(strncmp(input_symb,
"(*&%$#@!", 8 ) == 0);
119 char input_letter[] =
"ABCDabcd";
121 std::cout <<
" Input ABCDabcd " << input_letter << std::endl;
122 CPPUNIT_ASSERT(strncmp(input_letter,
"dcbaDCBA", 8 ) == 0);
124 char input_num[] =
"12345678";
126 std::cout <<
" Input 12345678 " << input_num << std::endl;
127 CPPUNIT_ASSERT(strncmp(input_num,
"87654321", 8 ) == 0);
129 char input_symb[] =
"!@#$%&*(";
131 std::cout <<
" Input !@#$%&*( " << input_symb << std::endl;
132 CPPUNIT_ASSERT(strncmp(input_symb,
"(*&%$#@!", 8 ) == 0);
139 boost::int16_t i16min = -32768;
140 boost::int16_t i16min_swap2 = -32768;
141 boost::int16_t i16max = 32767;
142 boost::int16_t i16max_swap2 = 32767;
143 boost::int16_t i16med = 32767/2;
144 boost::int16_t i16med_swap2 = 32767/2;
148 std::cout <<
" Input min " << i16min << std::endl;
151 std::cout <<
" Input swap " << i16min << std::endl;
153 std::cout <<
" Swap again " << i16min << std::endl;
155 CPPUNIT_ASSERT(i16min == i16min_swap2);
157 std::cout <<
" Input max " << i16max << std::endl;
160 std::cout <<
" Input swap " << i16max << std::endl;
162 std::cout <<
" Swap again " << i16max << std::endl;
163 CPPUNIT_ASSERT(i16max == i16max_swap2);
165 std::cout <<
" Input med " << i16med << std::endl;
168 std::cout <<
" Input swap " << i16med << std::endl;
170 std::cout <<
"Swap again " << i16med << std::endl;
171 CPPUNIT_ASSERT(i16med == i16med_swap2);
178 boost::int32_t i32min = -2147483647;
180 boost::int32_t i32min_swap2 = -2147483647;
181 boost::int32_t i32max = 2147483683;
182 boost::int32_t i32max_swap2 = 2147483683;
183 boost::int32_t i32med = 2147483683/2;
184 boost::int32_t i32med_swap2 = 2147483683/2;
187 CPPUNIT_ASSERT(
sizeof(i32min) == 4);
191 CPPUNIT_ASSERT(i32min == i32min_swap2);
195 CPPUNIT_ASSERT(i32max == i32max_swap2);
199 CPPUNIT_ASSERT(i32med == i32med_swap2);
206 boost::uint32_t ui32max = 4294967295;
207 boost::uint32_t ui32max_swap2 = 4294967295;
208 boost::uint32_t ui32med = 4294967295/2;
209 boost::uint32_t ui32med_swap2 = 4294967295/2;
212 CPPUNIT_ASSERT(
sizeof(ui32max) == 4);
216 CPPUNIT_ASSERT(ui32max == ui32max_swap2);
220 CPPUNIT_ASSERT(ui32med == ui32med_swap2);
228 float fl_swap2 = 10.25f ;
231 CPPUNIT_ASSERT(fl == fl_swap2);
233 float fl1 = 4.2038954e-045f ;
234 float fl1_swap2 = 4.2038954e-045f;
237 CPPUNIT_ASSERT(fl1 == fl1_swap2);
239 float fl2 = 1.99999976f ;
240 float fl2_swap2 = 1.99999976f;
243 CPPUNIT_ASSERT(fl2 == fl2_swap2);
245 float fl3 = +1.4012985e-045f ;
246 float fl3_swap2 = +1.4012985e-045f;
249 CPPUNIT_ASSERT(fl3 == fl3_swap2);
251 float fl5 = (float)0xFFFFFFFD ;
252 float fl5_swap2 = (float)0xFFFFFFFD ;
255 CPPUNIT_ASSERT(fl5 == fl5_swap2);
257 float fl6 = (float)(-3) ;
258 float fl6_swap2 = (float)(-3) ;
261 CPPUNIT_ASSERT(fl6 == fl6_swap2);
286 float f;
float f_orig;
287 for (
int i = 1000000000; i > 0; i--)
290 f = (float)(i / 100000.0);
291 f_orig = (float)(i / 100000.0 );
294 CPPUNIT_ASSERT(f == f_orig);
302 double d = 3.1415926535897932384626433832795 ;
303 double dorig = 3.1415926535897932384626433832795 ;
304 CPPUNIT_ASSERT(
sizeof(d) == 8) ;
306 std::cout.precision(52);
311 CPPUNIT_ASSERT(d == dorig) ;
314 double d_52 = 300300300300 +0.0000000000000002220446049250313080847263336181640625 ;
315 double dorig_52 = 300300300300 + 0.0000000000000002220446049250313080847263336181640625 ;
318 CPPUNIT_ASSERT(d_52 == dorig_52) ;
324 for (
int i = 52; i > 0; i--)
327 p_orig = pow(base,-i) ;
333 CPPUNIT_ASSERT(p == p_orig);
void tcSwapBytes()
Test Case: Swap an array of n-bytes.
Utility functions to swap bytes: double, int and unsigned int.
void tcSwapBytes_float()
Test Case: Swap 4 bytes (float).
void Swap8Bytes(char *v)
It swaps an array of eight bytes in local.
void tcSwap2Bytes()
Test Case: Swap an array of 2 bytes -sizeof(<type>)== 2.
void Swap2Bytes(T &v)
It swaps two bytes in local.
Test suite for ByteSwapUtils.
void Swap4Bytes(T &v)
It swaps four bytes in local.
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
Test suite for ByteSwapUtils.
void tcSwapBytes_buint32()
Test Case: Swap 4 bytes (boost::uint32).
void tcSwap4Bytes()
Test Case: Swap an array of 4 bytes.
CPPUNIT_TEST_SUITE_REGISTRATION(TsByteSwapUtils)
void tcSwapBytes_bint16()
Test Case: Swap 2 bytes (boost::int16).
This file contains include headers for the TerraLib Common Runtime module.
void tcSwapBytes_bint32()
Test Case: Swap 4 bytes (boost::int32).
void tcSwap8Bytes()
Test Case: Swap an array of 8-bytesr.
void tcSwapBytes_double()
Test Case: Swap 8 bytes (double).
void SwapBytes(T &v)
It swaps the bytes in local.