2017-10-12 17:36:46 +11:00
|
|
|
#include "tap.hpp"
|
|
|
|
|
|
|
|
#include "endian.hpp"
|
|
|
|
|
2018-05-03 18:32:08 +10:00
|
|
|
#include <cstdint>
|
|
|
|
|
2017-10-12 17:36:46 +11:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::TAP::logger tap;
|
2017-10-12 17:36:46 +11:00
|
|
|
|
|
|
|
{
|
|
|
|
uint32_t a = 0x12345678, b = 0x78563412;
|
2018-08-05 14:42:02 +10:00
|
|
|
tap.expect_eq (a, cruft::bswap (b), "u32 byteswap");
|
2017-10-12 17:36:46 +11:00
|
|
|
}
|
|
|
|
|
2018-05-03 18:32:08 +10:00
|
|
|
{
|
|
|
|
static std::uint8_t const bytes[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
|
2018-08-05 14:42:02 +10:00
|
|
|
tap.expect_eq (cruft::readle<std::uint64_t> (bytes), 0xefcdab8967452301, "readle<u64>");
|
2018-05-03 18:32:08 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-12 17:36:46 +11:00
|
|
|
{
|
|
|
|
// try to byte swap the pattern for 1.0f
|
|
|
|
//
|
|
|
|
// it may not be the most robust test, but it'll catch the most
|
|
|
|
// egregious errors for the time being.
|
|
|
|
union {
|
|
|
|
uint32_t u;
|
|
|
|
float f;
|
|
|
|
} data { .u = 0x0000803f /* 0x3f800000 == 1.f */ };
|
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
tap.expect_eq (cruft::bswap (data.f), 1.f, "f32 byteswap");
|
2017-10-12 17:36:46 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
return tap.status ();
|
|
|
|
}
|