00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <boost/test/unit_test.hpp>
00020 #include "torc/common/Endian.hpp"
00021
00022 namespace torc {
00023 namespace common {
00024
00025 using torc::common::htonll;
00026 using torc::common::ntohll;
00027
00028 BOOST_AUTO_TEST_SUITE(common)
00029
00030
00031 BOOST_AUTO_TEST_CASE(EndianUnitTest) {
00032
00033
00034
00035
00036 boost::uint16_t uint16_h_expected = 0x0123;
00037 boost::uint16_t uint16_n_expected = 0x2301;
00038 boost::uint16_t uint16_n_actual = htons(uint16_h_expected);
00039 boost::uint16_t uint16_h_actual = ntohs(uint16_n_expected);
00040 BOOST_CHECK_EQUAL(uint16_h_expected, uint16_h_actual);
00041 BOOST_CHECK_EQUAL(uint16_n_expected, uint16_n_actual);
00042
00043
00044
00045
00046
00047 boost::uint32_t uint32_h_expected = 0x01234567;
00048 boost::uint32_t uint32_n_expected = 0x67452301;
00049 boost::uint32_t uint32_n_actual = htonl(uint32_h_expected);
00050 boost::uint32_t uint32_h_actual = ntohl(uint32_n_expected);
00051 BOOST_CHECK_EQUAL(uint32_h_expected, uint32_h_actual);
00052 BOOST_CHECK_EQUAL(uint32_n_expected, uint32_n_actual);
00053
00054
00055
00056
00057
00058 boost::uint64_t uint64_h_expected = 0x0123456789abcdefll;
00059 boost::uint64_t uint64_n_expected = 0xefcdab8967452301ll;
00060 boost::uint64_t uint64_n_actual = htonll(uint64_h_expected);
00061 boost::uint64_t uint64_h_actual = ntohll(uint64_n_expected);
00062 BOOST_CHECK_EQUAL(uint64_h_expected, uint64_h_actual);
00063 BOOST_CHECK_EQUAL(uint64_n_expected, uint64_n_actual);
00064 }
00065
00066 BOOST_AUTO_TEST_SUITE_END()
00067
00068 }
00069 }