1 | //===-- Unittests for byte ------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "src/__support/CPP/cstddef.h" |
10 | #include "test/UnitTest/Test.h" |
11 | |
12 | namespace LIBC_NAMESPACE::cpp { |
13 | |
14 | TEST(LlvmLibcByteTest, to_integer) { |
15 | const char str[] = "abc" ; |
16 | const byte *const ptr = reinterpret_cast<const byte *>(str); |
17 | ASSERT_EQ(to_integer<char>(ptr[0]), 'a'); |
18 | ASSERT_EQ(to_integer<char>(ptr[1]), 'b'); |
19 | ASSERT_EQ(to_integer<char>(ptr[2]), 'c'); |
20 | ASSERT_EQ(to_integer<char>(ptr[3]), '\0'); |
21 | } |
22 | |
23 | TEST(LlvmLibcByteTest, bitwise) { |
24 | byte b{42}; |
25 | ASSERT_EQ(b, byte{0b00101010}); |
26 | |
27 | b <<= 1; |
28 | ASSERT_EQ(b, byte{0b01010100}); |
29 | b >>= 1; |
30 | |
31 | ASSERT_EQ((b << 1), byte{0b01010100}); |
32 | ASSERT_EQ((b >> 1), byte{0b00010101}); |
33 | |
34 | b |= byte{0b11110000}; |
35 | ASSERT_EQ(b, byte{0b11111010}); |
36 | |
37 | b &= byte{0b11110000}; |
38 | ASSERT_EQ(b, byte{0b11110000}); |
39 | |
40 | b ^= byte{0b11111111}; |
41 | ASSERT_EQ(b, byte{0b00001111}); |
42 | } |
43 | |
44 | } // namespace LIBC_NAMESPACE::cpp |
45 | |