1 /*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #include <byteswap.h>
18
19 #include <gtest/gtest.h>
20
21 static constexpr uint16_t le16 = 0x1234;
22 static constexpr uint32_t le32 = 0x12345678;
23 static constexpr uint64_t le64 = 0x123456789abcdef0;
24
25 static constexpr uint16_t be16 = 0x3412;
26 static constexpr uint32_t be32 = 0x78563412;
27 static constexpr uint64_t be64 = 0xf0debc9a78563412;
28
TEST(byteswap,bswap_16)29 TEST(byteswap, bswap_16) {
30 EXPECT_EQ(le16, bswap_16(be16));
31 EXPECT_EQ(be16, bswap_16(le16));
32 }
33
TEST(byteswap,bswap_32)34 TEST(byteswap, bswap_32) {
35 EXPECT_EQ(le32, bswap_32(be32));
36 EXPECT_EQ(be32, bswap_32(le32));
37 }
38
TEST(byteswap,bswap_64)39 TEST(byteswap, bswap_64) {
40 EXPECT_EQ(le64, bswap_64(be64));
41 EXPECT_EQ(be64, bswap_64(le64));
42 }
43
44