BIND 10 trac2375, updated. 9dbf3b1de0f8897483b2ee17ee113a3e8b95b3cc [2375] A fake state class
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Nov 13 12:37:53 UTC 2012
The branch, trac2375 has been updated
discards 2183a9d5b46c20ed8c481f505b57494d3142e654 (commit)
discards 89a6e668f647c323849e78449f00efad1ca624c4 (commit)
discards 8a5338e994c6509c38fb024f1212e629b334c9b4 (commit)
discards 6d1bc86b2cb43819564cf936290f514b6d4e42bf (commit)
via 9dbf3b1de0f8897483b2ee17ee113a3e8b95b3cc (commit)
via a3f9d7df5b616de6773f509d3f5f2c5fc5f32d14 (commit)
via 15d6d71ed052c0dc5d6be39a8afe484014887b31 (commit)
via a3dde49a8210f65d1f37c9dee5638dc62ed92dd3 (commit)
via 6a2d1a5cbdeb2603982abbf148012e0879bba4ee (commit)
via 9fb295c549978ba217384643beb60b25b52ff35a (commit)
via a49d071d0040474aa3fb23cb0e79c92f51f54f71 (commit)
via 626a7de9ad0d9cc7324e024b41f55ef636ee7957 (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (2183a9d5b46c20ed8c481f505b57494d3142e654)
\
N -- N -- N (9dbf3b1de0f8897483b2ee17ee113a3e8b95b3cc)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
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 9dbf3b1de0f8897483b2ee17ee113a3e8b95b3cc
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Mon Nov 12 19:24:21 2012 +0100
[2375] A fake state class
It is for tests, but in the main code for technical reasons.
commit a3f9d7df5b616de6773f509d3f5f2c5fc5f32d14
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Mon Nov 12 18:14:46 2012 +0100
[2375] getNextToken() and ungetNextToken() interface.
With doxygen description of what it should do and empty method bodies,
so the tests in following commits will at least compile.
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/master_lexer.cc | 12 ++++--
src/lib/dns/master_lexer.h | 12 ++++--
src/lib/dns/master_lexer_state.h | 2 +-
src/lib/dns/tests/master_lexer_state_unittest.cc | 46 +++++++++++++++-------
4 files changed, 48 insertions(+), 24 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dns/master_lexer.cc b/src/lib/dns/master_lexer.cc
index 507c3b1..e99485a 100644
--- a/src/lib/dns/master_lexer.cc
+++ b/src/lib/dns/master_lexer.cc
@@ -159,7 +159,7 @@ MasterLexer::Token::getErrorText() const {
namespace master_lexer_internal {
// Below we implement state classes for state transitions of MasterLexer.
// Note that these need to be defined here so that they can refer to
-// the details of of MasterLexerImpl.
+// the details of MasterLexerImpl.
typedef MasterLexer::Token Token; // convenience shortcut
@@ -178,6 +178,7 @@ State::getParenCount(const MasterLexer& lexer) const {
return (lexer.impl_->paren_count_);
}
+namespace {
class CRLF : public State {
public:
CRLF() {}
@@ -211,7 +212,6 @@ public:
}
};
-namespace {
// We use a common instance of a each state in a singleton-like way to save
// construction overhead. They are not singletons in its strict sense as
// we don't prohibit direct construction of these objects. But that doesn't
@@ -228,9 +228,13 @@ State::getInstance(ID state_id) {
return (CRLF_STATE);
case String:
return (STRING_STATE);
- default:
- isc_throw(isc::NotImplemented, "Unknown state ID");
}
+
+ // This is a bug of the caller, and this method is only expected to be
+ // used by tests, so we just forcefully make it fail by asserting the
+ // condition.
+ assert(false);
+ return (STRING_STATE); // a dummy return, to silence some compilers.
}
const State*
diff --git a/src/lib/dns/master_lexer.h b/src/lib/dns/master_lexer.h
index 54beb0f..31b9f8e 100644
--- a/src/lib/dns/master_lexer.h
+++ b/src/lib/dns/master_lexer.h
@@ -50,11 +50,15 @@ class MasterLexer {
public:
class Token; // we define it separately for better readability
+ /// \brief Options for getNextToken.
+ ///
+ /// A compound option, indicating multiple options are set, can be
+ /// specified using the logical OR operator (operator|()).
enum Options {
- NONE = 0, //< No option
- INITIAL_WS = 1, ///< recognize begin-of-line spaces
- QSTRING = INITIAL_WS << 1, ///< recognize quoted string
- NUMBER = QSTRING << 1 ///< recognize numeric text as integer
+ NONE = 0, //< No option
+ INITIAL_WS = 1, ///< recognize begin-of-line spaces
+ QSTRING = 2, ///< recognize quoted string
+ NUMBER = 4 ///< recognize numeric text as integer
};
/// \brief The constructor.
diff --git a/src/lib/dns/master_lexer_state.h b/src/lib/dns/master_lexer_state.h
index a76d8ec..fc6b262 100644
--- a/src/lib/dns/master_lexer_state.h
+++ b/src/lib/dns/master_lexer_state.h
@@ -37,7 +37,7 @@ namespace master_lexer_internal {
/// context, and updates it as necessary; each \c State derived class is
/// completely stateless.
///
-/// The initial transition takes place a static method of the base class,
+/// The initial transition takes place in a static method of the base class,
/// \c start(). This is mainly for implementation convenience; we need to
/// pass options given to \c MasterLexer::getNextToken() for the initial
/// state, so it makes more sense to separate the interface for the transition
diff --git a/src/lib/dns/tests/master_lexer_state_unittest.cc b/src/lib/dns/tests/master_lexer_state_unittest.cc
index f6d99a9..bcee7fd 100644
--- a/src/lib/dns/tests/master_lexer_state_unittest.cc
+++ b/src/lib/dns/tests/master_lexer_state_unittest.cc
@@ -34,9 +34,7 @@ protected:
s_string(State::getInstance(State::String)),
options(MasterLexer::NONE),
orig_options(options)
- {
- lexer.pushSource(ss);
- }
+ {}
// Specify INITIAL_WS as common initial options.
const MasterLexer::Options common_options;
@@ -61,12 +59,15 @@ eofCheck(const State& state, MasterLexer& lexer) {
TEST_F(MasterLexerStateTest, startAndEnd) {
// A simple case: the input is empty, so we begin with start and
// are immediately done.
+ lexer.pushSource(ss);
EXPECT_EQ(s_null, State::start(lexer, common_options));
eofCheck(s_crlf, lexer);
}
TEST_F(MasterLexerStateTest, startToEOL) {
ss << "\n";
+ lexer.pushSource(ss);
+
EXPECT_EQ(s_null, State::start(lexer, common_options));
EXPECT_TRUE(s_crlf.wasLastEOL(lexer));
EXPECT_EQ(Token::END_OF_LINE, s_crlf.getToken(lexer).getType());
@@ -77,12 +78,15 @@ TEST_F(MasterLexerStateTest, startToEOL) {
}
TEST_F(MasterLexerStateTest, space) {
+ // repeat '\t\n' twice (see below), then space after EOL
+ ss << " \t\n\t\n ";
+ lexer.pushSource(ss);
+
// by default space characters and tabs will be ignored. We check this
// twice; at the second iteration, it's a white space at the beginning
// of line, but since we don't specify INITIAL_WS option, it's treated as
// normal space and ignored.
for (size_t i = 0; i < 2; ++i) {
- ss << " \t\n";
EXPECT_EQ(s_null, State::start(lexer, MasterLexer::NONE));
EXPECT_TRUE(s_crlf.wasLastEOL(lexer));
EXPECT_EQ(Token::END_OF_LINE, s_crlf.getToken(lexer).getType());
@@ -90,7 +94,6 @@ TEST_F(MasterLexerStateTest, space) {
// Now we specify the INITIAL_WS option. It will be recognized and the
// corresponding token will be returned.
- ss << " ";
EXPECT_EQ(s_null, State::start(lexer, MasterLexer::INITIAL_WS));
EXPECT_FALSE(s_crlf.wasLastEOL(lexer));
EXPECT_EQ(Token::INITIAL_WS, s_crlf.getToken(lexer).getType());
@@ -98,6 +101,7 @@ TEST_F(MasterLexerStateTest, space) {
TEST_F(MasterLexerStateTest, parentheses) {
ss << "\n(\na\n )\n "; // 1st \n is to check if 'was EOL' is set to false
+ lexer.pushSource(ss);
EXPECT_EQ(s_null, State::start(lexer, common_options)); // handle \n
@@ -127,6 +131,8 @@ TEST_F(MasterLexerStateTest, parentheses) {
TEST_F(MasterLexerStateTest, nestedParentheses) {
// This is an unusual, but allowed (in this implementation) case.
ss << "(a(b)\n c)\n ";
+ lexer.pushSource(ss);
+
EXPECT_EQ(&s_string, State::start(lexer, common_options)); // consume '('
s_string.handle(lexer); // consume 'a'
EXPECT_EQ(&s_string, State::start(lexer, common_options)); // consume '('
@@ -155,6 +161,8 @@ TEST_F(MasterLexerStateTest, unbalancedParentheses) {
// Only closing paren is provided. We prepend a \n to check if it's
// correctly canceled after detecting the error.
ss << "\n)";
+ ss << "(a";
+ lexer.pushSource(ss);
EXPECT_EQ(s_null, State::start(lexer, common_options)); // consume '\n'
EXPECT_TRUE(s_crlf.wasLastEOL(lexer)); // this \n was remembered
@@ -169,7 +177,6 @@ TEST_F(MasterLexerStateTest, unbalancedParentheses) {
EXPECT_FALSE(s_crlf.wasLastEOL(lexer));
// Reach EOF with a dangling open parenthesis.
- ss << "(a";
EXPECT_EQ(&s_string, State::start(lexer, common_options)); // consume '('
s_string.handle(lexer); // consume 'a'
EXPECT_EQ(1, s_crlf.getParenCount(lexer));
@@ -184,11 +191,14 @@ TEST_F(MasterLexerStateTest, startToComment) {
// the rest of the line, and recognize the new line. Note that the
// second ';' is simply ignored.
ss << " ;a;\n";
+ ss << ";a;"; // Likewise, but the comment ends with EOF.
+ lexer.pushSource(ss);
+
+ // Comment ending with EOL
EXPECT_EQ(s_null, State::start(lexer, common_options));
EXPECT_EQ(Token::END_OF_LINE, s_crlf.getToken(lexer).getType());
- // Likewise, but the comment ends with EOF.
- ss << ";a;";
+ // Comment ending with EOF
EXPECT_EQ(s_null, State::start(lexer, common_options));
EXPECT_EQ(Token::END_OF_FILE, s_crlf.getToken(lexer).getType());
}
@@ -198,6 +208,8 @@ TEST_F(MasterLexerStateTest, commentAfterParen) {
// other tests should also ensure that it works correctly, but we
// check it explicitly.
ss << "( ;this is a comment\na)\n";
+ lexer.pushSource(ss);
+
// consume '(', skip comments, consume 'a', then consume ')'
EXPECT_EQ(&s_string, State::start(lexer, common_options));
s_string.handle(lexer);
@@ -206,30 +218,34 @@ TEST_F(MasterLexerStateTest, commentAfterParen) {
}
TEST_F(MasterLexerStateTest, crlf) {
- // A sequence of \r, \n is recognized as a single 'end-of-line'
- ss << "\r\n";
+ ss << "\r\n"; // case 1
+ ss << "\r "; // case 2
+ ss << "\r;comment\na"; // case 3
+ ss << "\r"; // case 4
+ lexer.pushSource(ss);
+
+ // 1. A sequence of \r, \n is recognized as a single 'end-of-line'
EXPECT_EQ(&s_crlf, State::start(lexer, common_options)); // recognize '\r'
EXPECT_EQ(s_null, s_crlf.handle(lexer)); // recognize '\n'
EXPECT_EQ(Token::END_OF_LINE, s_crlf.getToken(lexer).getType());
EXPECT_TRUE(s_crlf.wasLastEOL(lexer));
- // Single '\r' (not followed by \n) is recognized as a single 'end-of-line'
- ss << "\r "; // then there will be "initial WS"
+ // 2. Single '\r' (not followed by \n) is recognized as a single
+ // 'end-of-line'. then there will be "initial WS"
EXPECT_EQ(&s_crlf, State::start(lexer, common_options)); // recognize '\r'
// see ' ', "unget" it
EXPECT_EQ(s_null, s_crlf.handle(lexer));
EXPECT_EQ(s_null, State::start(lexer, common_options)); // recognize ' '
EXPECT_EQ(Token::INITIAL_WS, s_crlf.getToken(lexer).getType());
- ss << "\r;comment\na";
+ // 3. comment between \r and \n
EXPECT_EQ(&s_crlf, State::start(lexer, common_options)); // recognize '\r'
// skip comments, recognize '\n'
EXPECT_EQ(s_null, s_crlf.handle(lexer));
EXPECT_EQ(Token::END_OF_LINE, s_crlf.getToken(lexer).getType());
EXPECT_EQ(&s_string, State::start(lexer, common_options));
- // \r then EOF
- ss << "\r";
+ // 4. \r then EOF
EXPECT_EQ(&s_crlf, State::start(lexer, common_options)); // recognize '\r'
// see EOF, then "unget" it
EXPECT_EQ(s_null, s_crlf.handle(lexer));
More information about the bind10-changes
mailing list