/ src / crc32c / src / crc32c_read_le_unittest.cc
crc32c_read_le_unittest.cc
 1  // Copyright 2017 The CRC32C Authors. All rights reserved.
 2  // Use of this source code is governed by a BSD-style license that can be
 3  // found in the LICENSE file. See the AUTHORS file for names of contributors.
 4  
 5  #include "./crc32c_read_le.h"
 6  
 7  #include <cstddef>
 8  #include <cstdint>
 9  
10  #include "gtest/gtest.h"
11  
12  #include "./crc32c_round_up.h"
13  
14  namespace crc32c {
15  
16  TEST(Crc32CReadLETest, ReadUint32LE) {
17    // little-endian 0x12345678
18    alignas(4) uint8_t bytes[] = {0x78, 0x56, 0x34, 0x12};
19  
20    ASSERT_EQ(RoundUp<4>(bytes), bytes) << "Stack array is not aligned";
21    EXPECT_EQ(static_cast<uint32_t>(0x12345678), ReadUint32LE(bytes));
22  }
23  
24  TEST(Crc32CReadLETest, ReadUint64LE) {
25    // little-endian 0x123456789ABCDEF0
26    alignas(8) uint8_t bytes[] = {0xF0, 0xDE, 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12};
27  
28    ASSERT_EQ(RoundUp<8>(bytes), bytes) << "Stack array is not aligned";
29    EXPECT_EQ(static_cast<uint64_t>(0x123456789ABCDEF0), ReadUint64LE(bytes));
30  }
31  
32  }  // namespace crc32c