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 <boost/cstdint.hpp>
00021 #include <boost/integer_traits.hpp>
00022 #include "torc/common/EncapsulatedInteger.hpp"
00023
00024 namespace torc {
00025 namespace common {
00026
00027 BOOST_AUTO_TEST_SUITE(common)
00028
00029
00030 BOOST_AUTO_TEST_CASE(EncapsulatedIntegerSizeUnitTest) {
00031
00032
00033
00034 BOOST_REQUIRE_EQUAL((size_t) 1, sizeof(boost::int8_t));
00035 BOOST_REQUIRE_EQUAL((size_t) 1, sizeof(boost::uint8_t));
00036 BOOST_REQUIRE_EQUAL((size_t) 2, sizeof(boost::int16_t));
00037 BOOST_REQUIRE_EQUAL((size_t) 2, sizeof(boost::uint16_t));
00038 BOOST_REQUIRE_EQUAL((size_t) 4, sizeof(boost::int32_t));
00039 BOOST_REQUIRE_EQUAL((size_t) 4, sizeof(boost::uint32_t));
00040 BOOST_REQUIRE_EQUAL((size_t) 8, sizeof(boost::int64_t));
00041 BOOST_REQUIRE_EQUAL((size_t) 8, sizeof(boost::uint64_t));
00042
00043
00044
00045
00046 BOOST_WARN_EQUAL((size_t) 1, sizeof(char));
00047 BOOST_WARN_EQUAL((size_t) 2, sizeof(short));
00048 BOOST_WARN_EQUAL((size_t) 4, sizeof(int));
00049 BOOST_WARN_EQUAL((size_t) 8, sizeof(long));
00050 BOOST_WARN_EQUAL((size_t) 8, sizeof(long long));
00051 }
00052
00053
00054 #define STANDARD_ENCAPSULATED_INTEGER_BLOCK(TYPE) \
00055 { \
00056 typedef TYPE type; \
00057 typedef EncapsulatedInteger<type> EInt; \
00058 \
00059 \
00060 \
00061 \
00062 \
00063 EInt eint1 = boost::integer_traits<TYPE>::const_min; \
00064 EInt eint2 = eint1; \
00065 EInt eint3, eint4, eint5; \
00066 (void) eint2; \
00067 \
00068 \
00069 \
00070 \
00071 eint3 = eint1; \
00072 eint4 = boost::integer_traits<TYPE>::const_max; \
00073 \
00074 \
00075 \
00076 type int1 = eint3; \
00077 type int2 = eint4; \
00078 \
00079 \
00080 \
00081 \
00082 \
00083 BOOST_CHECK_EQUAL(boost::integer_traits<TYPE>::const_min, int1); \
00084 BOOST_CHECK_EQUAL(boost::integer_traits<TYPE>::const_max, int2); \
00085 BOOST_CHECK_EQUAL(boost::integer_traits<TYPE>::const_min, eint3); \
00086 BOOST_CHECK_EQUAL(boost::integer_traits<TYPE>::const_max, eint4); \
00087 }
00088
00089
00090 BOOST_AUTO_TEST_CASE(EncapsulatedIntegerLimitsUnitTest) {
00091
00092 STANDARD_ENCAPSULATED_INTEGER_BLOCK(boost::uint8_t);
00093
00094 STANDARD_ENCAPSULATED_INTEGER_BLOCK(boost::int8_t);
00095
00096 STANDARD_ENCAPSULATED_INTEGER_BLOCK(boost::uint16_t);
00097
00098 STANDARD_ENCAPSULATED_INTEGER_BLOCK(boost::int16_t);
00099
00100 STANDARD_ENCAPSULATED_INTEGER_BLOCK(boost::uint32_t);
00101
00102 STANDARD_ENCAPSULATED_INTEGER_BLOCK(boost::int32_t);
00103
00104 STANDARD_ENCAPSULATED_INTEGER_BLOCK(boost::uint64_t);
00105
00106 STANDARD_ENCAPSULATED_INTEGER_BLOCK(boost::int64_t);
00107 }
00108
00109 BOOST_AUTO_TEST_SUITE_END()
00110
00111 }
00112 }