BIND 10 trac2375, updated. e70ed476bb19a8201e5ba09cbf63998e916afe20 [2375] Add a test a token is actually produced
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Nov 13 18:06:59 UTC 2012
The branch, trac2375 has been updated
via e70ed476bb19a8201e5ba09cbf63998e916afe20 (commit)
from 70f1f22868ecc0b092c503dde1550223652c3f82 (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 e70ed476bb19a8201e5ba09cbf63998e916afe20
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Tue Nov 13 19:04:16 2012 +0100
[2375] Add a test a token is actually produced
This is a debug test. It checks the state machine produced a token.
There are no tests for this test, since such condition would be a
programmer error, not something expected.
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/master_lexer.cc | 11 +++++++++--
src/lib/dns/master_lexer.h | 4 +++-
src/lib/dns/tests/master_lexer_token_unittest.cc | 7 +++++--
3 files changed, 17 insertions(+), 5 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dns/master_lexer.cc b/src/lib/dns/master_lexer.cc
index 47e1b5f..e5cadcc 100644
--- a/src/lib/dns/master_lexer.cc
+++ b/src/lib/dns/master_lexer.cc
@@ -125,6 +125,9 @@ MasterLexer::getSourceLine() const {
MasterLexer::Token
MasterLexer::getNextToken(Options options) {
+ // Reset the token now. This is to check a token was actually produced.
+ // This is debugging aid.
+ impl_->token_ = Token(Token::NO_TOKEN_PRODUCED);
if (impl_->source_ == NULL) {
isc_throw(isc::InvalidOperation, "No source to read tokens from");
}
@@ -132,7 +135,10 @@ MasterLexer::getNextToken(Options options) {
state = state->handle(*this)) {
// Do nothing here. All is handled in the for cycle header itself.
}
- // TODO load the token
+ // Make sure a token was produced. Since this Can Not Happen, we assert
+ // here instead of throwing.
+ assert(impl_->token_.getType() != Token::ERROR ||
+ impl_->token_.getErrorCode() != Token::NO_TOKEN_PRODUCED);
return (impl_->token_);
}
@@ -151,7 +157,8 @@ const char* const error_text[] = {
"lexer not started", // NOT_STARTED
"unbalanced parentheses", // UNBALANCED_PAREN
"unexpected end of input", // UNEXPECTED_END
- "unbalanced quotes" // UNBALANCED_QUOTES
+ "unbalanced quotes", // UNBALANCED_QUOTES
+ "no token produced"
};
const size_t error_text_max_count = sizeof(error_text) / sizeof(error_text[0]);
}
diff --git a/src/lib/dns/master_lexer.h b/src/lib/dns/master_lexer.h
index 97d048a..4e99455 100644
--- a/src/lib/dns/master_lexer.h
+++ b/src/lib/dns/master_lexer.h
@@ -249,8 +249,10 @@ public:
NOT_STARTED, ///< The lexer is just initialized and has no token
UNBALANCED_PAREN, ///< Unbalanced parentheses detected
UNEXPECTED_END, ///< The lexer reaches the end of line or file
- /// unexpectedly
+ /// unexpectedly
UNBALANCED_QUOTES, ///< Unbalanced quotations detected
+ NO_TOKEN_PRODUCED, ///< No token was produced. This means programmer
+ /// error and should never get out of the lexer.
MAX_ERROR_CODE ///< Max integer corresponding to valid error codes.
/// (excluding this one). Mainly for internal use.
};
diff --git a/src/lib/dns/tests/master_lexer_token_unittest.cc b/src/lib/dns/tests/master_lexer_token_unittest.cc
index a63b9ca..8d0a291 100644
--- a/src/lib/dns/tests/master_lexer_token_unittest.cc
+++ b/src/lib/dns/tests/master_lexer_token_unittest.cc
@@ -135,15 +135,18 @@ TEST_F(MasterLexerTokenTest, errors) {
EXPECT_EQ("unbalanced quotes",
MasterLexer::Token(MasterLexer::Token::UNBALANCED_QUOTES).
getErrorText());
+ EXPECT_EQ("no token produced",
+ MasterLexer::Token(MasterLexer::Token::NO_TOKEN_PRODUCED).
+ getErrorText());
// getErrorCode/Text() isn't allowed for non number types
EXPECT_THROW(token_num.getErrorCode(), isc::InvalidOperation);
EXPECT_THROW(token_num.getErrorText(), isc::InvalidOperation);
- // Only the pre-defined error code is accepted. Hardcoding '4' (max code
+ // Only the pre-defined error code is accepted. Hardcoding '5' (max code
// + 1) is intentional; it'd be actually better if we notice it when we
// update the enum list (which shouldn't happen too often).
- EXPECT_THROW(MasterLexer::Token(MasterLexer::Token::ErrorCode(4)),
+ EXPECT_THROW(MasterLexer::Token(MasterLexer::Token::ErrorCode(5)),
isc::InvalidParameter);
// Check the coexistence of "from number" and "from error-code"
More information about the bind10-changes
mailing list