1#include "test.h"
2
3#include <gtest/gtest.h>
4
5#include <base/system.h>
6
7static const int32_t INT_DATA[] = {0, 1, -1, 32, 64, 256, -512, 12345, -123456, 1234567, 12345678, 123456789, 2147483647, (-2147483647 - 1)};
8static const uint32_t UINT_DATA[] = {0u, 1u, 2u, 32u, 64u, 256u, 512u, 12345u, 123456u, 1234567u, 12345678u, 123456789u, 2147483647u, 2147483648u, 4294967295u};
9
10TEST(BytePacking, RoundtripInt)
11{
12 for(auto i : INT_DATA)
13 {
14 unsigned char aPacked[sizeof(int32_t)];
15 uint_to_bytes_be(bytes: aPacked, value: i);
16 EXPECT_EQ(bytes_be_to_uint(aPacked), i);
17 }
18}
19
20TEST(BytePacking, RoundtripUnsigned)
21{
22 for(auto u : UINT_DATA)
23 {
24 unsigned char aPacked[sizeof(uint32_t)];
25 uint_to_bytes_be(bytes: aPacked, value: u);
26 EXPECT_EQ(bytes_be_to_uint(aPacked), u);
27 }
28}
29