Commit 54cbb54f authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[2572] adjusted getTotalSourceSize() to handle unknown source size

parent 4baf3a4d
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment