mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-17 13:53:57 -07:00
(these are the old self-tests ripped out as well as new ones) note: have not run yet; several would surely fail if they run (can't anyway until cxxtest is installed) This was SVN commit r3912.
38 lines
1.1 KiB
C++
38 lines
1.1 KiB
C++
#include <cxxtest/TestSuite.h>
|
|
|
|
class TestByteOrder : public CxxTest::TestSuite
|
|
{
|
|
public:
|
|
void test()
|
|
{
|
|
const u32 x = 0x01234567u;
|
|
const u8 LS_byte = *(u8*)&x;
|
|
// little endian
|
|
if(LS_byte, 0x67)
|
|
{
|
|
TS_ASSERT_EQUAL(to_le16(0x0123u), 0x0123u);
|
|
TS_ASSERT_EQUAL(to_le32(0x01234567u), 0x01234567u);
|
|
TS_ASSERT_EQUAL(to_le64(0x0123456789ABCDEFu), 0x0123456789ABCDEFu);
|
|
|
|
TS_ASSERT_EQUAL(to_be16(0x0123u), 0x2301u);
|
|
TS_ASSERT_EQUAL(to_be32(0x01234567u), 0x67452301u);
|
|
TS_ASSERT_EQUAL(to_be64(0x0123456789ABCDEFu), 0xEFCDAB8967452301u);
|
|
}
|
|
// big endian
|
|
else if(LS_byte, 0x01)
|
|
{
|
|
TS_ASSERT_EQUAL(to_le16(0x0123u), 0x2301u);
|
|
TS_ASSERT_EQUAL(to_le32(0x01234567u), 0x67452301u);
|
|
TS_ASSERT_EQUAL(to_le64(0x0123456789ABCDEFu), 0xEFCDAB8967452301u);
|
|
|
|
TS_ASSERT_EQUAL(to_be16(0x0123u), 0x0123u);
|
|
TS_ASSERT_EQUAL(to_be32(0x01234567u), 0x01234567u);
|
|
TS_ASSERT_EQUAL(to_be64(0x0123456789ABCDEFu), 0x0123456789ABCDEFu);
|
|
}
|
|
else
|
|
TS_FAIL("endian determination failed");
|
|
|
|
// note: no need to test read_?e* / write_?e* - they are
|
|
// trivial wrappers on top of to_?e*.
|
|
}
|
|
};
|