From: JINMEI Tatuya Date: Thu, 10 Jan 2013 23:37:11 +0000 (-0800) Subject: [2572] adjusted getTotalSourceSize() to handle unknown source size X-Git-Tag: bind10-1.0.0-rc-release~95^2~11^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=54cbb54f358dd83e6c87f23ed17c5df754a28dc7;p=thirdparty%2Fkea.git [2572] adjusted getTotalSourceSize() to handle unknown source size --- diff --git a/src/lib/dns/master_lexer.cc b/src/lib/dns/master_lexer.cc index 710f349c76..518bea3731 100644 --- a/src/lib/dns/master_lexer.cc +++ b/src/lib/dns/master_lexer.cc @@ -187,6 +187,12 @@ size_t MasterLexer::getTotalSourceSize() const { size_t total_size = 0; BOOST_FOREACH(InputSourcePtr& src, impl_->sources_) { + // If the size of any pushed source is unknown, the total is also + // considered unknown. + if (src->getSize() == SOURCE_SIZE_UNKNOWN) { + return (SOURCE_SIZE_UNKNOWN); + } + total_size += src->getSize(); } return (total_size); diff --git a/src/lib/dns/tests/master_lexer_unittest.cc b/src/lib/dns/tests/master_lexer_unittest.cc index 65ca08a135..c8ab61f5f1 100644 --- a/src/lib/dns/tests/master_lexer_unittest.cc +++ b/src/lib/dns/tests/master_lexer_unittest.cc @@ -142,6 +142,24 @@ TEST_F(MasterLexerTest, nestedPush) { EXPECT_TRUE(lexer.getSourceName().empty()); } +TEST_F(MasterLexerTest, unknownSourceSize) { + // Similar to the previous case, but the size of the second source + // will be considered "unknown" (by emulating an error). + ss << "test"; + lexer.pushSource(ss); + EXPECT_EQ(4, lexer.getTotalSourceSize()); + + stringstream ss2; + ss2.setstate(std::ios_base::failbit); // this will make the size unknown + lexer.pushSource(ss2); + // Then the total size is also unknown. + EXPECT_EQ(MasterLexer::SOURCE_SIZE_UNKNOWN, lexer.getTotalSourceSize()); + + // If we pop that source, the size becomes known again. + lexer.popSource(); + EXPECT_EQ(4, lexer.getTotalSourceSize()); +} + TEST_F(MasterLexerTest, invalidPop) { // popSource() cannot be called if the sources stack is empty. EXPECT_THROW(lexer.popSource(), isc::InvalidOperation);