template<typename T> bool rfc1982LessThan(T a, T b)
{
- return ((signed)(a - b)) < 0;
+ typedef typename std::make_signed<T>::type signed_t;
+ return static_cast<signed_t>(a - b) < 0;
}
// fills container with ranges, so {posbegin,posend}
BOOST_CHECK_EQUAL(SimpleMatch("abc*").match(std::string("abc")), true);
}
+template<typename T> bool rfc1982check(T x, T y) {
+ return rfc1982LessThan(x, y);
+}
+
+BOOST_AUTO_TEST_CASE(test_rfc1982LessThan) {
+ // The test cases from rfc1982 section 5.2
+ BOOST_CHECK(rfc1982check<uint8_t>(0, 1));
+ BOOST_CHECK(rfc1982check<uint8_t>(0, 44));
+ BOOST_CHECK(rfc1982check<uint8_t>(0, 100));
+ BOOST_CHECK(rfc1982check<uint8_t>(44, 100));
+ BOOST_CHECK(rfc1982check<uint8_t>(100, 200));
+ BOOST_CHECK(rfc1982check<uint8_t>(200, 255));
+ BOOST_CHECK(rfc1982check<uint8_t>(255, 0));
+ BOOST_CHECK(rfc1982check<uint8_t>(255, 100));
+ BOOST_CHECK(rfc1982check<uint8_t>(200, 0));
+ BOOST_CHECK(rfc1982check<uint8_t>(200, 44));
+
+ BOOST_CHECK(rfc1982check<uint32_t>(0, 1));
+ BOOST_CHECK(rfc1982check<uint32_t>(UINT32_MAX-10, 1));
+ BOOST_CHECK(rfc1982check<uint32_t>(UINT32_MAX/2, UINT32_MAX-10));
+
+ BOOST_CHECK(rfc1982check<uint64_t>(0, 1));
+ BOOST_CHECK(rfc1982check<uint64_t>(UINT64_MAX-10, 1));
+ BOOST_CHECK(rfc1982check<uint64_t>(UINT64_MAX/2, UINT64_MAX-10));
+}
+
BOOST_AUTO_TEST_SUITE_END()