Main MRPT website > C++ reference for MRPT 1.5.6
bits_unittest.cpp
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 
10 #include <mrpt/utils/core_defs.h>
11 #include <mrpt/utils/bits.h>
12 #include <gtest/gtest.h>
13 
14 using namespace mrpt;
15 using namespace mrpt::utils;
16 using namespace std;
17 
18 // Load data from constant file and check for exact match.
20 {
21  {
22  uint8_t val = 0x88, val_r;
23  const uint8_t val_r_ok = 0x88;
24 
25  mrpt::utils::reverseBytes(val, val_r);
26  EXPECT_EQ(val_r, val_r_ok);
28  EXPECT_EQ(val, val_r_ok);
29  }
30  {
31  uint16_t val = 0x1122, val_r;
32  const uint16_t val_r_ok = 0x2211;
33 
34  mrpt::utils::reverseBytes(val, val_r);
35  EXPECT_EQ(val_r, val_r_ok);
37  EXPECT_EQ(val, val_r_ok);
38  }
39  {
40  uint32_t val = UINT32_C(0x11223344), val_r;
41  const uint32_t val_r_ok = UINT32_C(0x44332211);
42 
43  mrpt::utils::reverseBytes(val, val_r);
44  EXPECT_EQ(val_r, val_r_ok);
46  EXPECT_EQ(val, val_r_ok);
47  }
48  {
49  uint64_t val = UINT64_C( 0x1122334455667788 ), val_r;
50  const uint64_t val_r_ok = UINT64_C( 0x8877665544332211 );
51 
52  mrpt::utils::reverseBytes(val, val_r);
53  EXPECT_EQ(val_r, val_r_ok);
55  EXPECT_EQ(val, val_r_ok);
56  }
57 }
unsigned __int16 uint16_t
Definition: rptypes.h:46
void BASE_IMPEXP reverseBytesInPlace(bool &v_in_out)
Reverse the order of the bytes of a given type (useful for transforming btw little/big endian) ...
unsigned char uint8_t
Definition: rptypes.h:43
void reverseBytes(const T &v_in, T &v_out)
Reverse the order of the bytes of a given type (useful for transforming btw little/big endian) ...
void reverseBytes(const T &v_in, T &v_out)
Reverse the order of the bytes of a given type (useful for transforming btw little/big endian) ...
Definition: bits.h:162
TEST(bits, reverseBytes)
unsigned __int64 uint64_t
Definition: rptypes.h:52
GLuint GLfloat * val
Definition: glew.h:7785
unsigned __int32 uint32_t
Definition: rptypes.h:49



Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018