2 * Copyright 2014 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <folly/Bits.h>
19 #include <gtest/gtest.h>
21 using namespace folly;
26 uint16_t v16 = 0x1234;
27 uint16_t v16s = 0x3412;
28 uint32_t v32 = 0x12345678;
29 uint32_t v32s = 0x78563412;
30 uint64_t v64 = 0x123456789abcdef0ULL;
31 uint64_t v64s = 0xf0debc9a78563412ULL;
33 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
36 EXPECT_EQ(v##sz, Endian::little(v##sz)); \
37 EXPECT_EQ(v##sz, Endian::little##sz(v##sz)); \
38 EXPECT_EQ(v##sz##s, Endian::big(v##sz)); \
39 EXPECT_EQ(v##sz##s, Endian::big##sz(v##sz));
41 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
44 EXPECT_EQ(v##sz##s, Endian::little(v##sz)); \
45 EXPECT_EQ(v##sz##s, Endian::little##sz(v##sz)); \
46 EXPECT_EQ(v##sz, Endian::big(v##sz)); \
47 EXPECT_EQ(v##sz, Endian::big##sz(v##sz));
50 # error Your machine uses a weird endianness!
51 #endif /* __BYTE_ORDER__ */
54 EXPECT_EQ(v##sz##s, Endian::swap(v##sz)); \
55 EXPECT_EQ(v##sz##s, Endian::swap##sz(v##sz)); \