#include "tap.hpp" #include "endian.hpp" #include /////////////////////////////////////////////////////////////////////////////// int main (void) { cruft::TAP::logger tap; { uint32_t a = 0x12345678, b = 0x78563412; tap.expect_eq (a, cruft::bswap (b), "u32 byteswap"); } { static std::uint8_t const bytes[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }; tap.expect_eq (cruft::readle (bytes), 0xefcdab8967452301, "readle"); } { static constexpr u32 A = 0x11223344; static constexpr u32 B = 0x44332211; f32 const a_f = cruft::cast::bit (A); f32 const b_f = cruft::bswap (a_f); u32 const b_u = cruft::cast::bit (b_f); tap.expect_eq (b_u, B, "f32 bswap"); } { static constexpr u64 A = 0x1122334455667788; static constexpr u64 B = 0x8877665544332211; f64 const a_f = cruft::cast::bit (A); f64 const b_f = cruft::bswap (a_f); u64 const b_u = cruft::cast::bit (b_f); tap.expect_eq (b_u, B, "u64 bswap"); } return tap.status (); }