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);
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);