Commit 0acf96a8 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[2384] Test border cases

parent 8ac89e17
......@@ -104,8 +104,8 @@ RRTTL::RRTTL(const std::string& ttlstr) {
// Any valid uint32_t number must have at most 10 digits. If it
// has more, it could wrap around the int64_t silently (at least
// in theory, some compilers seem to throw from lexical_cast).
if (unit - pos > 10 || value <= 0 || val <= 0 ||
val >= 0xffffffff) {
if (unit - pos > 10 || value < 0 || val < 0 ||
val > 0xffffffff) {
isc_throw(InvalidRRTTL, "Part of TTL out of range: " <<
ttlstr);
}
......
......@@ -74,6 +74,11 @@ TEST_F(RRTTLTest, getValue) {
}
TEST_F(RRTTLTest, fromText) {
// Border cases
EXPECT_EQ(0, RRTTL("0").getValue());
EXPECT_EQ(4294967295, RRTTL("4294967295").getValue());
// Invalid cases
EXPECT_THROW(RRTTL("0xdeadbeef"), InvalidRRTTL); // must be decimal
EXPECT_THROW(RRTTL("-1"), InvalidRRTTL); // must be positive
EXPECT_THROW(RRTTL("1.1"), InvalidRRTTL); // must be integer
......@@ -101,6 +106,11 @@ TEST_F(RRTTLTest, fromTextUnit) {
checkUnit(24 * 60 * 60, 'D');
checkUnit(7 * 24 * 60 * 60, 'W');
// Some border cases
EXPECT_EQ(4294967295, RRTTL("4294967295S").getValue());
EXPECT_EQ(0, RRTTL("0W0D0H0M0S").getValue());
EXPECT_EQ(4294967295, RRTTL("1193046H1695S").getValue());
// Now some compound ones. We allow any order (it would be much work to
// check the order anyway). The last part can be without unit, in which
// case it is considered seconds.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment