Browse Source

[2369] Check as much as possible that line numbers are decremented correctly

Mukund Sivaraman 12 years ago
parent
commit
7fb91131cd
1 changed files with 23 additions and 0 deletions
  1. 23 0
      src/lib/dns/tests/inputsource_unittest.cc

+ 23 - 0
src/lib/dns/tests/inputsource_unittest.cc

@@ -144,6 +144,29 @@ TEST_F(InputSourceTest, lines) {
     // Now we are back to where we started.
     // Now we are back to where we started.
     EXPECT_EQ(1, source_.getCurrentLine());
     EXPECT_EQ(1, source_.getCurrentLine());
     EXPECT_FALSE(source_.atEOF());
     EXPECT_FALSE(source_.atEOF());
+
+    // Now check that line numbers are decremented properly (as much as
+    // possible using the available API).
+    while (!source_.atEOF()) {
+        source_.getChar();
+    }
+    line = source_.getCurrentLine();
+
+    // Now, we are at EOF.
+    EXPECT_TRUE(source_.atEOF());
+    EXPECT_EQ(4, line);
+
+    EXPECT_THROW({
+        while (true) {
+            source_.ungetChar();
+            EXPECT_TRUE(((line == source_.getCurrentLine()) ||
+                         ((line - 1) == source_.getCurrentLine())));
+            line = source_.getCurrentLine();
+        }
+    }, isc::OutOfRange);
+
+    // Now we are back to where we started.
+    EXPECT_EQ(1, source_.getCurrentLine());
 }
 }
 
 
 } // end namespace
 } // end namespace