From: JINMEI Tatuya Date: Thu, 15 Nov 2012 22:00:40 +0000 (-0800) Subject: [2375] some style matters: mostly about constness, and folded a long line. X-Git-Tag: bind10-1.0.0-beta-release~84^2~3^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6b846ec5edfc4833503d266a72b8d7c2ed7b29ce;p=thirdparty%2Fkea.git [2375] some style matters: mostly about constness, and folded a long line. Conflicts (from cherry-pick): src/lib/dns/tests/master_lexer_unittest.cc --- diff --git a/src/lib/dns/master_lexer.cc b/src/lib/dns/master_lexer.cc index 17cdda8eeb..3be0793af1 100644 --- a/src/lib/dns/master_lexer.cc +++ b/src/lib/dns/master_lexer.cc @@ -445,7 +445,7 @@ namespace { class FakeState : public State { public: FakeState(const State* next, size_t eat_chars, - MasterLexer::Token* token, + const MasterLexer::Token* token, int paren_change, const bool* set_eol, const boost::function& callback) : next_(next), @@ -475,7 +475,7 @@ public: private: const State* const next_; size_t eat_chars_; - MasterLexer::Token* const token_; + const MasterLexer::Token* const token_; const int paren_change_; const bool* const set_eol_; const boost::function callback_; @@ -485,7 +485,7 @@ private: State* State::getFakeState(const State* next, size_t eat_chars, - MasterLexer::Token* token, + const MasterLexer::Token* token, int paren_change, const bool* set_eol, const boost::function& callback) { diff --git a/src/lib/dns/master_lexer_state.h b/src/lib/dns/master_lexer_state.h index fd041b17cc..67695040e2 100644 --- a/src/lib/dns/master_lexer_state.h +++ b/src/lib/dns/master_lexer_state.h @@ -125,7 +125,7 @@ public: /// /// The caller is responsible for deleting the State. static State* getFakeState(const State* next, size_t eat_chars, - MasterLexer::Token* token = NULL, + const MasterLexer::Token* token = NULL, int paren_change = 0, const bool* set_eol = NULL, const boost::function state(State::getFakeState(NULL, 3, &token)); + const MasterLexer::Token token(MasterLexer::Token::END_OF_LINE); + scoped_ptr state(State::getFakeState(NULL, 3, &token)); lexer.pushFakeStart(state.get()); // Push some source inside. ss << "12345"; lexer.pushSource(ss); // Get the token. - MasterLexer::Token generated(lexer.getNextToken()); + const MasterLexer::Token generated(lexer.getNextToken()); // It is the same token (well, on a different address) // We can't compare directly, so compare types. EXPECT_EQ(token.getType(), generated.getType()); @@ -221,17 +221,17 @@ TEST_F(MasterLexerTest, simpleGetToken) { // survive and be returned. TEST_F(MasterLexerTest, chainGetToken) { // Build the states - MasterLexer::Token t1(MasterLexer::Token::END_OF_LINE); - MasterLexer::Token t2(MasterLexer::Token::INITIAL_WS); - scoped_ptr s2(State::getFakeState(NULL, 1, &t2)); - scoped_ptr s1(State::getFakeState(s2.get(), 2, &t1)); + const MasterLexer::Token t1(MasterLexer::Token::END_OF_LINE); + const MasterLexer::Token t2(MasterLexer::Token::INITIAL_WS); + scoped_ptr s2(State::getFakeState(NULL, 1, &t2)); + scoped_ptr s1(State::getFakeState(s2.get(), 2, &t1)); lexer.pushFakeStart(s1.get()); // Put something into the source ss << "12345"; lexer.pushSource(ss); // Get the token. - MasterLexer::Token generated(lexer.getNextToken()); + const MasterLexer::Token generated(lexer.getNextToken()); // It is the same token as the second one (well, on a different address) // We can't compare directly, so compare types. EXPECT_EQ(t2.getType(), generated.getType()); @@ -315,19 +315,21 @@ TEST_F(MasterLexerTest, ungetSimple) { const bool true_value = true, false_value = false; // Make sure we change the state to non-default, so we return to previous // not default state. - MasterLexer::Token t0(MasterLexer::Token::INITIAL_WS); - scoped_ptr s0(State::getFakeState(NULL, 1, &t0, 1, &true_value)); + const MasterLexer::Token t0(MasterLexer::Token::INITIAL_WS); + scoped_ptr s0(State::getFakeState(NULL, 1, &t0, 1, + &true_value)); lexer.pushFakeStart(s0.get()); EXPECT_EQ(MasterLexer::Token::INITIAL_WS, lexer.getNextToken().getType()); // Prepare the token to get and return const std::string expected = "234"; - MasterLexer::Token token(MasterLexer::Token::END_OF_LINE); + const MasterLexer::Token token(MasterLexer::Token::END_OF_LINE); // Change the internal state with it too. So we can check it is retured. - scoped_ptr state(State::getFakeState(NULL, 3, &token, 1, - &false_value, - boost::bind(&checkInput, - expected, _1))); + scoped_ptr state(State::getFakeState(NULL, 3, &token, 1, + &false_value, + boost::bind(&checkInput, + expected, + _1))); lexer.pushFakeStart(state.get()); // Check the internal state before getting the token @@ -344,6 +346,7 @@ TEST_F(MasterLexerTest, ungetSimple) { lexer.ungetToken(); EXPECT_EQ(1, state->getParenCount(lexer)); EXPECT_TRUE(state->wasLastEOL(lexer)); + // By calling getToken again, we verify even the source got back to // original (as the second fake state checks it gets "234"). We must // push it as a fake start again so it is picked.