BIND 10 trac2369, updated. ccb0973459b702152f79ea23841269a379580850 [2369] Constify variables in various places

BIND 10 source code commits bind10-changes at lists.isc.org
Sun Nov 4 17:00:48 UTC 2012


The branch, trac2369 has been updated
       via  ccb0973459b702152f79ea23841269a379580850 (commit)
       via  4d7d67838cb15ce75ceab0664e7b25e4b58d658a (commit)
       via  ed1a2ad7dfa4d0c87e9ab3fa446acdbc29f6cc24 (commit)
       via  9f5232047b3a68299192a7885068430af6f8859b (commit)
      from  80b227af0bf08ac9e7bdf645b11e8593b717add3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit ccb0973459b702152f79ea23841269a379580850
Author: Mukund Sivaraman <muks at isc.org>
Date:   Sun Nov 4 22:30:16 2012 +0530

    [2369] Constify variables in various places

commit 4d7d67838cb15ce75ceab0664e7b25e4b58d658a
Author: Mukund Sivaraman <muks at isc.org>
Date:   Sun Nov 4 21:49:56 2012 +0530

    [2369] Read data from the test file to check the InputSource

commit ed1a2ad7dfa4d0c87e9ab3fa446acdbc29f6cc24
Author: Mukund Sivaraman <muks at isc.org>
Date:   Sun Nov 4 21:40:33 2012 +0530

    [2369] Use the more specialized std::ifstream instead of std::fstream

commit 9f5232047b3a68299192a7885068430af6f8859b
Author: Mukund Sivaraman <muks at isc.org>
Date:   Sun Nov 4 21:28:54 2012 +0530

    [2369] Rename non-existent filename in test

-----------------------------------------------------------------------

Summary of changes:
 src/lib/dns/master_lexer_inputsource.cc            |    8 +++---
 src/lib/dns/master_lexer_inputsource.h             |    2 +-
 .../dns/tests/master_lexer_inputsource_unittest.cc |   29 ++++++++------------
 3 files changed, 17 insertions(+), 22 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/dns/master_lexer_inputsource.cc b/src/lib/dns/master_lexer_inputsource.cc
index f38d6c3..ffaf53e 100644
--- a/src/lib/dns/master_lexer_inputsource.cc
+++ b/src/lib/dns/master_lexer_inputsource.cc
@@ -21,7 +21,7 @@ namespace master_lexer_internal {
 namespace { // unnamed namespace
 
 std::string
-createStreamName(std::istream& input_stream) {
+createStreamName(const std::istream& input_stream) {
      std::stringstream ss;
      ss << "stream-" << &input_stream;
      return (ss.str());
@@ -46,7 +46,7 @@ InputSource::InputSource(const char* filename) :
     name_(filename),
     input_(file_stream_)
 {
-    file_stream_.open(filename, std::fstream::in);
+    file_stream_.open(filename);
     if (file_stream_.fail()) {
         isc_throw(OpenError,
                   "Error opening the input source file: " << filename);
@@ -70,7 +70,7 @@ InputSource::getChar() {
             return (END_OF_STREAM);
         }
         // We are not yet at EOF. Read from the stream.
-        int c = input_.get();
+        const int c = input_.get();
         // Have we reached EOF now? If so, set at_eof_ and return early,
         // but don't modify buffer_pos_ (which should still be equal to
         // the size of buffer_).
@@ -87,7 +87,7 @@ InputSource::getChar() {
         buffer_.push_back(c);
     }
 
-    int c = buffer_[buffer_pos_++];
+    const int c = buffer_[buffer_pos_++];
     if (c == '\n') {
         line_++;
     }
diff --git a/src/lib/dns/master_lexer_inputsource.h b/src/lib/dns/master_lexer_inputsource.h
index b7eee5f..136e809 100644
--- a/src/lib/dns/master_lexer_inputsource.h
+++ b/src/lib/dns/master_lexer_inputsource.h
@@ -135,7 +135,7 @@ private:
     size_t buffer_pos_;
 
     const std::string name_;
-    std::fstream file_stream_;
+    std::ifstream file_stream_;
     std::istream& input_;
 };
 
diff --git a/src/lib/dns/tests/master_lexer_inputsource_unittest.cc b/src/lib/dns/tests/master_lexer_inputsource_unittest.cc
index 8e0cf62..9bb6aab 100644
--- a/src/lib/dns/tests/master_lexer_inputsource_unittest.cc
+++ b/src/lib/dns/tests/master_lexer_inputsource_unittest.cc
@@ -61,14 +61,15 @@ TEST_F(InputSourceTest, getName) {
 
 TEST_F(InputSourceTest, nonExistentFile) {
     EXPECT_THROW({
-        InputSource source(TEST_DATA_SRCDIR "/videokilledtheradiostar");
+        InputSource source(TEST_DATA_SRCDIR "/does-not-exist");
     }, InputSource::OpenError);
 }
 
 // getChar() should return characters from the input stream in
 // sequence. ungetChar() should skip backwards.
 void
-checkGetAndUngetChar(InputSource& source, const char* str, size_t str_length)
+checkGetAndUngetChar(InputSource& source,
+                     const char* str, const size_t str_length)
 {
     for (size_t i = 0; i < str_length; i++) {
         EXPECT_EQ(str[i], source.getChar());
@@ -101,7 +102,7 @@ checkGetAndUngetChar(InputSource& source, const char* str, size_t str_length)
     source.ungetChar();
 
     for (size_t i = 0; i < str_length; i++) {
-        size_t index = str_length - 1 - i;
+        const size_t index = str_length - 1 - i;
         // Skip one character.
         source.ungetChar();
         EXPECT_EQ(str[index], source.getChar());
@@ -118,16 +119,13 @@ TEST_F(InputSourceTest, stream) {
 }
 
 TEST_F(InputSourceTest, file) {
-    const char* str =
-        ";; a simple (incomplete) zone file\n"
-        "\n"
-        "example.com. 3600 IN TXT \"test data\"\n"
-        "www.example.com. 60 IN A 192.0.2.1\n"
-        "www.example.com. 60 IN A 192.0.2.2\n";
-    size_t str_length = strlen(str);
+    std::ifstream fs(TEST_DATA_SRCDIR "/masterload.txt");
+    const std::string str((std::istreambuf_iterator<char>(fs)),
+                          std::istreambuf_iterator<char>());
+    fs.close();
 
     InputSource source(TEST_DATA_SRCDIR "/masterload.txt");
-    checkGetAndUngetChar(source, str, str_length);
+    checkGetAndUngetChar(source, str.c_str(), str.size());
 }
 
 // ungetAll() should skip back to the place where the InputSource
@@ -194,8 +192,7 @@ TEST_F(InputSourceTest, compactDuring) {
         source_.getChar();
     }
     EXPECT_FALSE(source_.atEOF());
-    size_t line = source_.getCurrentLine();
-    EXPECT_EQ(2, line);
+    EXPECT_EQ(2, source_.getCurrentLine());
 
     // Now, unget a couple of characters. This should cause the
     // buffer_pos_ to be not equal to the size of the buffer.
@@ -302,8 +299,7 @@ TEST_F(InputSourceTest, saveLine) {
         source_.getChar();
     }
     EXPECT_FALSE(source_.atEOF());
-    size_t line = source_.getCurrentLine();
-    EXPECT_EQ(2, line);
+    EXPECT_EQ(2, source_.getCurrentLine());
 
     // Now, save the line.
     source_.saveLine();
@@ -312,11 +308,10 @@ TEST_F(InputSourceTest, saveLine) {
     while (!source_.atEOF()) {
         source_.getChar();
     }
-    line = source_.getCurrentLine();
 
     // Now, we are at EOF.
     EXPECT_TRUE(source_.atEOF());
-    EXPECT_EQ(4, line);
+    EXPECT_EQ(4, source_.getCurrentLine());
 
     // Now, ungetAll() and check where it goes back.
     source_.ungetAll();



More information about the bind10-changes mailing list