File: Endianness.cpp

package info (click to toggle)
openrct2 0.4.3%2Bds-1
  • links: PTS, VCS
  • area: contrib
  • in suites: bookworm
  • size: 67,880 kB
  • sloc: cpp: 549,527; ansic: 1,322; sh: 441; python: 269; xml: 180; php: 34; makefile: 19
file content (43 lines) | stat: -rw-r--r-- 901 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "openrct2/core/Endianness.h"

#include <gtest/gtest.h>

TEST(SwapBETest, ForUInt8_DoesNothing)
{
    uint8_t before = 0x12;
    uint8_t after = ByteSwapBE(before);
    ASSERT_EQ(before, after);
}

TEST(SwapBETest, ForUInt16_SwapsBytes)
{
    uint16_t before = 0x1234;
    uint16_t after = ByteSwapBE(before);
    ASSERT_EQ(0x3412u, after);
}

TEST(SwapBETest, ForUInt32_SwapsBytes)
{
    uint32_t before = 0x12345678;
    uint32_t after = ByteSwapBE(before);
    ASSERT_EQ(0x78563412u, after);
}

TEST(SwapBETest, ForUInt64_SwapsBytes)
{
    uint64_t before = 0x1234567887654321;
    uint64_t after = ByteSwapBE(before);
    ASSERT_EQ(0x2143658778563412u, after);
}

TEST(SwapBETest, ForCustomBlittableType_SwapsBytes)
{
    struct MyStruct
    {
        uint16_t value;
    };

    MyStruct before = { 0x1234 };
    MyStruct after = ByteSwapBE(before);
    ASSERT_EQ(0x3412, after.value);
}