scummvm/test/common/endian.h
Johannes Schickel daa8fca001 TEST: Fix uint64 endian related test code.
This does not fix the actual implementation issues which are present right
now!
2015-01-04 21:09:32 +01:00

49 lines
1.3 KiB
C++

#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);
}
};