libcruft-util/test/hton.cpp

31 lines
643 B
C++
Raw Normal View History

#include <cruft/util/endian.hpp>
2011-06-21 23:36:51 +10:00
#include <cruft/util/tap.hpp>
#include <cruft/util/platform.hpp>
2011-06-21 23:36:51 +10:00
#include <cstdlib>
#if defined(PLATFORM_WIN32)
#include <winsock2.h>
#else
#include <arpa/inet.h>
#include <netinet/in.h>
#endif
2011-06-21 23:36:51 +10:00
2015-04-13 18:06:08 +10:00
int
2015-07-13 16:29:01 +10:00
main (void)
{
cruft::TAP::logger tap;
2011-06-21 23:36:51 +10:00
uint16_t val16 = 0x1358;
uint32_t val32 = 0x12345678;
2011-06-21 23:36:51 +10:00
tap.expect_eq (htons (val16), cruft::hton (val16), "htons");
tap.expect_eq (htonl (val32), cruft::hton (val32), "htonl");
2011-06-21 23:36:51 +10:00
tap.expect_eq (ntohs (val16), cruft::hton (val16), "ntohs");
tap.expect_eq (ntohl (val32), cruft::hton (val32), "ntohl");
2011-06-21 23:36:51 +10:00
2015-07-13 16:29:01 +10:00
return tap.status ();
2011-06-21 23:36:51 +10:00
}