BIND 10 trac2369, updated. 51e26dc96b447d4f60b6aa2c428bfcfe6e6a4d04 [2369] Add InputSource::compact() method
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Oct 31 05:23:47 UTC 2012
The branch, trac2369 has been updated
via 51e26dc96b447d4f60b6aa2c428bfcfe6e6a4d04 (commit)
from 9843e33b58ce12f13fc34fe27c7ef0e4042bd506 (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 51e26dc96b447d4f60b6aa2c428bfcfe6e6a4d04
Author: Mukund Sivaraman <muks at isc.org>
Date: Wed Oct 31 10:53:31 2012 +0530
[2369] Add InputSource::compact() method
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/inputsource.cc | 11 ++++
src/lib/dns/inputsource.h | 5 ++
src/lib/dns/tests/inputsource_unittest.cc | 90 +++++++++++++++++++++++++++++
3 files changed, 106 insertions(+)
-----------------------------------------------------------------------
diff --git a/src/lib/dns/inputsource.cc b/src/lib/dns/inputsource.cc
index 1da98b0..b5b1e08 100644
--- a/src/lib/dns/inputsource.cc
+++ b/src/lib/dns/inputsource.cc
@@ -102,6 +102,17 @@ InputSource::ungetAll() {
at_eof_ = false;
}
+void
+InputSource::compact() {
+ if (buffer_pos_ == buffer_.size()) {
+ buffer_.clear();
+ } else {
+ buffer_.erase(buffer_.begin() + buffer_pos_);
+ }
+
+ buffer_pos_ = 0;
+}
+
} // namespace master_lexer_internal
} // namespace dns
} // namespace isc
diff --git a/src/lib/dns/inputsource.h b/src/lib/dns/inputsource.h
index d45fa28..ba2f77d 100644
--- a/src/lib/dns/inputsource.h
+++ b/src/lib/dns/inputsource.h
@@ -92,6 +92,11 @@ public:
/// it sets the current line number to the line number saved then.
void ungetAll();
+ /// Removes buffered content before the current location in the
+ /// \c InputSource. It's not possible to \c ungetChar() after this,
+ /// unless we read more data using \c getChar().
+ void compact();
+
private:
bool at_eof_;
size_t line_;
diff --git a/src/lib/dns/tests/inputsource_unittest.cc b/src/lib/dns/tests/inputsource_unittest.cc
index 097aded..e2c386b 100644
--- a/src/lib/dns/tests/inputsource_unittest.cc
+++ b/src/lib/dns/tests/inputsource_unittest.cc
@@ -123,6 +123,96 @@ TEST_F(InputSourceTest, ungetAll) {
EXPECT_FALSE(source_.atEOF());
}
+TEST_F(InputSourceTest, compact) {
+ // Compact at the start
+ source_.compact();
+
+ // Ungetting here must throw.
+ EXPECT_THROW(source_.ungetChar(), InputSource::UngetError);
+
+ for (size_t i = 0; i < str_length_; i++) {
+ EXPECT_EQ(str_[i], source_.getChar());
+ EXPECT_FALSE(source_.atEOF());
+ }
+
+ // At this point, we still have not reached EOF.
+ EXPECT_FALSE(source_.atEOF());
+
+ // This should cause EOF to be set.
+ EXPECT_EQ(-1, source_.getChar());
+
+ // Now, EOF should be set.
+ EXPECT_TRUE(source_.atEOF());
+ EXPECT_EQ(4, source_.getCurrentLine());
+
+ // Compact again
+ source_.compact();
+
+ // We are still at EOF.
+ EXPECT_TRUE(source_.atEOF());
+ EXPECT_EQ(4, source_.getCurrentLine());
+
+ // Skip the EOF.
+ source_.ungetChar();
+
+ // Ungetting here must throw.
+ EXPECT_THROW(source_.ungetChar(), InputSource::UngetError);
+
+ EXPECT_EQ(-1, source_.getChar());
+ EXPECT_TRUE(source_.atEOF());
+}
+
+TEST_F(InputSourceTest, compactDuring) {
+ // First, skip to line 2.
+ while (!source_.atEOF() &&
+ (source_.getCurrentLine() != 2)) {
+ source_.getChar();
+ }
+ EXPECT_FALSE(source_.atEOF());
+ size_t line = source_.getCurrentLine();
+ EXPECT_EQ(2, line);
+
+ source_.saveLine();
+ source_.compact();
+
+ // Ungetting here must throw.
+ EXPECT_THROW(source_.ungetChar(), InputSource::UngetError);
+
+ for (size_t i = 15; i < str_length_; i++) {
+ EXPECT_EQ(str_[i], source_.getChar());
+ EXPECT_FALSE(source_.atEOF());
+ }
+
+ // At this point, we still have not reached EOF.
+ EXPECT_FALSE(source_.atEOF());
+
+ // This should cause EOF to be set.
+ EXPECT_EQ(-1, source_.getChar());
+
+ // Now, EOF should be set.
+ EXPECT_TRUE(source_.atEOF());
+
+ // Now, ungetAll() and check where it goes back.
+ source_.ungetAll();
+
+ // Ungetting here must throw.
+ EXPECT_THROW(source_.ungetChar(), InputSource::UngetError);
+
+ for (size_t i = 15; i < str_length_; i++) {
+ EXPECT_EQ(str_[i], source_.getChar());
+ EXPECT_FALSE(source_.atEOF());
+ }
+
+ // At this point, we still have not reached EOF.
+ EXPECT_FALSE(source_.atEOF());
+
+ // This should cause EOF to be set.
+ EXPECT_EQ(-1, source_.getChar());
+
+ // Now, EOF should be set.
+ EXPECT_TRUE(source_.atEOF());
+}
+
// Test line counters.
TEST_F(InputSourceTest, lines) {
size_t line = 1;
More information about the bind10-changes
mailing list