Browse Source

[2384] Test border cases

Michal 'vorner' Vaner 12 years ago
parent
commit
0acf96a895
2 changed files with 12 additions and 2 deletions
  1. 2 2
      src/lib/dns/rrttl.cc
  2. 10 0
      src/lib/dns/tests/rrttl_unittest.cc

+ 2 - 2
src/lib/dns/rrttl.cc

@@ -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);
             }

+ 10 - 0
src/lib/dns/tests/rrttl_unittest.cc

@@ -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.