1
1
forked from 0ad/0ad
0ad/source/lib/tests/test_byte_order.h
janwas 9542ecdd7e # boatload of fixes to get self-tests to compile+mostly run
refs #117

stub_impl_hack: defines a function otherwise provided by main.cpp

remove old self_test.h contents (e.g. TEST); superceded by cxxtestgen
TS_ASSERT etc.
only include self_test from a test (otherwise, cxxtest include dir won't
be set)
cxxtest won't run tests named only "test"; add more descriptive name

FIXES uncovered by self tests
lib: infinite loop in log2
lockfree: incorrect params

This was SVN commit r3979.
2006-06-08 19:03:43 +00:00

41 lines
1.2 KiB
C++

#include "lib/self_test.h"
#include "lib/byte_order.h"
class TestByteOrder : public CxxTest::TestSuite
{
public:
void test_conversion()
{
const u32 x = 0x01234567u;
const u8 LS_byte = *(u8*)&x;
// little endian
if(LS_byte == 0x67)
{
TS_ASSERT_EQUALS(to_le16(0x0123u), 0x0123u);
TS_ASSERT_EQUALS(to_le32(0x01234567u), 0x01234567u);
TS_ASSERT_EQUALS(to_le64(0x0123456789ABCDEFull), 0x0123456789ABCDEFull);
TS_ASSERT_EQUALS(to_be16(0x0123u), 0x2301u);
TS_ASSERT_EQUALS(to_be32(0x01234567u), 0x67452301u);
TS_ASSERT_EQUALS(to_be64(0x0123456789ABCDEFull), 0xEFCDAB8967452301ull);
}
// big endian
else if(LS_byte == 0x01)
{
TS_ASSERT_EQUALS(to_le16(0x0123u), 0x2301u);
TS_ASSERT_EQUALS(to_le32(0x01234567u), 0x67452301u);
TS_ASSERT_EQUALS(to_le64(0x0123456789ABCDEFull), 0xEFCDAB8967452301ull);
TS_ASSERT_EQUALS(to_be16(0x0123u), 0x0123u);
TS_ASSERT_EQUALS(to_be32(0x01234567u), 0x01234567u);
TS_ASSERT_EQUALS(to_be64(0x0123456789ABCDEFull), 0x0123456789ABCDEFull);
}
else
TS_FAIL("endian determination failed");
// note: no need to test read_?e* / write_?e* - they are
// trivial wrappers on top of to_?e*.
}
};