Browse Source

[2369] Use a const variable's value for END_OF_STREAM state

Mukund Sivaraman 12 years ago
parent
commit
5ac6e8b56c

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

@@ -63,7 +63,7 @@ InputSource::getChar() {
         // getChar(). at_eof_ will be set then. We then simply return
         // getChar(). at_eof_ will be set then. We then simply return
         // early.
         // early.
         if (at_eof_) {
         if (at_eof_) {
-            return -1;
+            return (END_OF_STREAM);
         }
         }
         // We are not yet at EOF. Read from the stream.
         // We are not yet at EOF. Read from the stream.
         int c = input_.get();
         int c = input_.get();
@@ -72,7 +72,7 @@ InputSource::getChar() {
         // the size of buffer_).
         // the size of buffer_).
         if (!input_.good()) {
         if (!input_.good()) {
             at_eof_ = true;
             at_eof_ = true;
-            return -1;
+            return (END_OF_STREAM);
         }
         }
         buffer_.push_back(c);
         buffer_.push_back(c);
     }
     }

+ 6 - 1
src/lib/dns/master_lexer_inputsource.h

@@ -79,8 +79,11 @@ public:
         {}
         {}
     };
     };
 
 
+    /// \brief Returned by getChar() when end of stream is reached.
+    static const int END_OF_STREAM;
+
     /// \brief Returns a single character from the input source. If end
     /// \brief Returns a single character from the input source. If end
-    /// of file is reached, -1 is returned.
+    /// of file is reached, \c END_OF_STREAM is returned.
     int getChar();
     int getChar();
 
 
     /// \brief Skips backward a single character in the input
     /// \brief Skips backward a single character in the input
@@ -114,6 +117,8 @@ private:
     std::istream& input_;
     std::istream& input_;
 };
 };
 
 
+const int InputSource::END_OF_STREAM = -1;
+
 } // namespace master_lexer_internal
 } // namespace master_lexer_internal
 } // namespace dns
 } // namespace dns
 } // namespace isc
 } // namespace isc

+ 6 - 6
src/lib/dns/tests/master_lexer_inputsource_unittest.cc

@@ -71,7 +71,7 @@ TEST_F(InputSourceTest, getAndUngetChar) {
     EXPECT_FALSE(source_.atEOF());
     EXPECT_FALSE(source_.atEOF());
 
 
     // This should cause EOF to be set.
     // This should cause EOF to be set.
-    EXPECT_EQ(-1, source_.getChar());
+    EXPECT_EQ(InputSource::END_OF_STREAM, source_.getChar());
 
 
     // Now, EOF should be set.
     // Now, EOF should be set.
     EXPECT_TRUE(source_.atEOF());
     EXPECT_TRUE(source_.atEOF());
@@ -84,7 +84,7 @@ TEST_F(InputSourceTest, getAndUngetChar) {
     EXPECT_FALSE(source_.atEOF());
     EXPECT_FALSE(source_.atEOF());
 
 
     // This should cause EOF to be set again.
     // This should cause EOF to be set again.
-    EXPECT_EQ(-1, source_.getChar());
+    EXPECT_EQ(InputSource::END_OF_STREAM, source_.getChar());
 
 
     // Now, EOF should be set.
     // Now, EOF should be set.
     EXPECT_TRUE(source_.atEOF());
     EXPECT_TRUE(source_.atEOF());
@@ -139,7 +139,7 @@ TEST_F(InputSourceTest, compact) {
     EXPECT_FALSE(source_.atEOF());
     EXPECT_FALSE(source_.atEOF());
 
 
     // This should cause EOF to be set.
     // This should cause EOF to be set.
-    EXPECT_EQ(-1, source_.getChar());
+    EXPECT_EQ(InputSource::END_OF_STREAM, source_.getChar());
 
 
     // Now, EOF should be set.
     // Now, EOF should be set.
     EXPECT_TRUE(source_.atEOF());
     EXPECT_TRUE(source_.atEOF());
@@ -158,7 +158,7 @@ TEST_F(InputSourceTest, compact) {
     // Ungetting here must throw.
     // Ungetting here must throw.
     EXPECT_THROW(source_.ungetChar(), InputSource::UngetBeforeBeginning);
     EXPECT_THROW(source_.ungetChar(), InputSource::UngetBeforeBeginning);
 
 
-    EXPECT_EQ(-1, source_.getChar());
+    EXPECT_EQ(InputSource::END_OF_STREAM, source_.getChar());
     EXPECT_TRUE(source_.atEOF());
     EXPECT_TRUE(source_.atEOF());
 }
 }
 
 
@@ -192,7 +192,7 @@ TEST_F(InputSourceTest, compactDuring) {
     EXPECT_FALSE(source_.atEOF());
     EXPECT_FALSE(source_.atEOF());
 
 
     // This should cause EOF to be set.
     // This should cause EOF to be set.
-    EXPECT_EQ(-1, source_.getChar());
+    EXPECT_EQ(InputSource::END_OF_STREAM, source_.getChar());
 
 
     // Now, EOF should be set.
     // Now, EOF should be set.
     EXPECT_TRUE(source_.atEOF());
     EXPECT_TRUE(source_.atEOF());
@@ -212,7 +212,7 @@ TEST_F(InputSourceTest, compactDuring) {
     EXPECT_FALSE(source_.atEOF());
     EXPECT_FALSE(source_.atEOF());
 
 
     // This should cause EOF to be set.
     // This should cause EOF to be set.
-    EXPECT_EQ(-1, source_.getChar());
+    EXPECT_EQ(InputSource::END_OF_STREAM, source_.getChar());
 
 
     // Now, EOF should be set.
     // Now, EOF should be set.
     EXPECT_TRUE(source_.atEOF());
     EXPECT_TRUE(source_.atEOF());