libcruft-util/test/hton.cpp
Danny Robson f6056153e3 rename root namespace from util to cruft
This places, at long last, the core library code into the same namespace
as the extended library code.
2018-08-05 14:42:02 +10:00

32 lines
591 B
C++

#include "endian.hpp"
#include "tap.hpp"
#include "platform.hpp"
#include <cstdlib>
#if defined(PLATFORM_WIN32)
#include <winsock2.h>
#else
#include <arpa/inet.h>
#include <netinet/in.h>
#endif
int
main (void)
{
cruft::TAP::logger tap;
uint16_t u16 = 0x1358;
uint32_t u32 = 0x12345678;
tap.expect_eq (htons (u16), cruft::hton (u16), "htons");
tap.expect_eq (htonl (u32), cruft::hton (u32), "htonl");
tap.expect_eq (ntohs (u16), cruft::hton (u16), "ntohs");
tap.expect_eq (ntohl (u32), cruft::hton (u32), "ntohl");
return tap.status ();
}