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
44
45
46
47
48
|
#include <cxxtest/TestSuite.h>
#include "common/endian.h"
class EndianTestSuite : public CxxTest::TestSuite
{
public:
void test_MKTAG() {
const char *str_tag = "ABCD";
uint32 tag = READ_BE_UINT32(str_tag);
TS_ASSERT_EQUALS(MKTAG('A','B','C','D'), tag);
}
void test_READ_BE_UINT64() {
const byte data[8] = {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF};
uint64 value = READ_BE_UINT64(data);
TS_ASSERT_EQUALS(value, 0x123456789ABCDEFFULL);
}
void test_READ_LE_UINT64() {
const byte data[8] = {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF};
uint64 value = READ_LE_UINT64(data);
TS_ASSERT_EQUALS(value, 0xFFDEBC9A78563412ULL);
}
void test_READ_BE_UINT32() {
const char data[4] = { 0x12, 0x34, 0x56, 0x78 };
uint32 value = READ_BE_UINT32(data);
TS_ASSERT_EQUALS(value, 0x12345678UL);
}
void test_READ_LE_UINT32() {
const char data[4] = { 0x12, 0x34, 0x56, 0x78 };
uint32 value = READ_LE_UINT32(data);
TS_ASSERT_EQUALS(value, 0x78563412UL);
}
void test_READ_BE_UINT16() {
const char data[4] = { 0x12, 0x34, 0x56, 0x78 };
uint32 value = READ_BE_UINT16(data);
TS_ASSERT_EQUALS(value, 0x1234UL);
}
void test_READ_LE_UINT16() {
const char data[4] = { 0x12, 0x34, 0x56, 0x78 };
uint32 value = READ_LE_UINT16(data);
TS_ASSERT_EQUALS(value, 0x3412UL);
}
};
|