Commit b2fe684c authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[2371] renamed open/close() {push,pop}Source() as suggested in review.

parent d0a51e7f
......@@ -47,22 +47,24 @@ MasterLexer::~MasterLexer() {
}
void
MasterLexer::open(const char* filename) {
MasterLexer::pushSource(const char* filename) {
if (filename == NULL) {
isc_throw(InvalidParameter, "NULL filename for MasterLexer::open");
isc_throw(InvalidParameter,
"NULL filename for MasterLexer::pushSource");
}
impl_->sources_.push_back(InputSourcePtr(new InputSource(filename)));
}
void
MasterLexer::open(std::istream& input) {
MasterLexer::pushSource(std::istream& input) {
impl_->sources_.push_back(InputSourcePtr(new InputSource(input)));
}
void
MasterLexer::close() {
MasterLexer::popSource() {
if (impl_->sources_.empty()) {
isc_throw(InvalidOperation, "MasterLexer::close on an empty source");
isc_throw(InvalidOperation,
"MasterLexer::popSource on an empty source");
}
impl_->sources_.pop_back();
}
......
......@@ -35,8 +35,8 @@ namespace dns {
///
/// In order to support the $INCLUDE notation, this class is designed to be
/// able to operate on multiple files or input streams in the nested way.
/// The \c open() and \c close() methods correspond to the push and pop
/// operations.
/// The \c pushSource() and \c popSource() methods correspond to the push
/// and pop operations.
///
/// While this class is public, it is less likely to be used by normal
/// applications; it's mainly expected to be used within this library,
......@@ -58,14 +58,14 @@ public:
/// \brief Open a file and make it the current input source of MasterLexer.
///
/// The opened file can be explicitly closed by the \c close() method;
/// if \c close() is not called within the lifetime of the \c MasterLexer,
/// it will be closed in the destructor.
/// The opened file can be explicitly closed by the \c popSource() method;
/// if \c popSource() is not called within the lifetime of the
/// \c MasterLexer, it will be closed in the destructor.
///
/// \throw InvalidParameter filename is NULL
/// \throw some_other The specified cannot be opened
/// \param filename A non NULL string specifying a master file
void open(const char* filename);
void pushSource(const char* filename);
/// \brief Make the given stream the current input source of MasterLexer.
///
......@@ -73,29 +73,30 @@ public:
/// caller's responsibility to keep it valid as long as it's used in
/// \c MasterLexer or to release any resource for the stream after that.
/// The caller can explicitly tell \c MasterLexer to stop using the
/// stream by calling the \c close() method.
/// stream by calling the \c popSource() method.
///
/// \param input An input stream object that produces textual
/// representation of DNS RRs.
void open(std::istream& input);
void pushSource(std::istream& input);
/// \brief Close the most recently opened input source (file or stream).
/// \brief Stop using the most recently opened input source (file or
/// stream).
///
/// If it's a file, the opened file will be literally closed.
/// If it's a file, the previously opened file will be closed internally.
/// If it's a stream, \c MasterLexer will simply stop using
/// the stream; the caller can assume it will be never used in
/// \c MasterLexer thereafter.
///
/// This method must not be called when there is no opened source for
/// This method must not be called when there is no source pushed for
/// \c MasterLexer. This method is otherwise exception free.
///
/// \throw isc::InvalidOperation Called with no opened source.
void close();
/// \throw isc::InvalidOperation Called with no pushed source.
void popSource();
/// \brief Return the name of the current input source name.
///
/// If it's a file, it will be the C string given at the corresponding
/// \c open() call, that is, its filename. If it's a stream, it will
/// \c pushSource() call, that is, its filename. If it's a stream, it will
/// be formatted as \c "stream-%p" where \c %p is hex representation
/// of the address of the stream object.
///
......
......@@ -54,7 +54,7 @@ TEST_F(MasterLexerTest, preOpen) {
}
TEST_F(MasterLexerTest, openStream) {
lexer.open(ss);
lexer.pushSource(ss);
EXPECT_EQ(expected_stream_name, lexer.getSourceName());
// From the point of view of this test, we only have to check (though
......@@ -63,44 +63,44 @@ TEST_F(MasterLexerTest, openStream) {
EXPECT_EQ(1, lexer.getSourceLine());
// By closing it the stack will be empty again.
lexer.close();
lexer.popSource();
checkEmptySource(lexer);
}
TEST_F(MasterLexerTest, openFile) {
// We use zone file (-like) data, but in this test that actually doesn't
// matter.
lexer.open(TEST_DATA_SRCDIR "/masterload.txt");
lexer.pushSource(TEST_DATA_SRCDIR "/masterload.txt");
EXPECT_EQ(TEST_DATA_SRCDIR "/masterload.txt", lexer.getSourceName());
EXPECT_EQ(1, lexer.getSourceLine());
lexer.close();
lexer.popSource();
checkEmptySource(lexer);
}
TEST_F(MasterLexerTest, openBadFileName) {
EXPECT_THROW(lexer.open(NULL), isc::InvalidParameter);
EXPECT_THROW(lexer.pushSource(NULL), isc::InvalidParameter);
}
TEST_F(MasterLexerTest, nestedOpen) {
lexer.open(ss);
lexer.pushSource(ss);
EXPECT_EQ(expected_stream_name, lexer.getSourceName());
// We can open another source without closing the previous one.
lexer.open(TEST_DATA_SRCDIR "/masterload.txt");
lexer.pushSource(TEST_DATA_SRCDIR "/masterload.txt");
EXPECT_EQ(TEST_DATA_SRCDIR "/masterload.txt", lexer.getSourceName());
// Close works on the "topmost" (last-opened) source
lexer.close();
lexer.popSource();
EXPECT_EQ(expected_stream_name, lexer.getSourceName());
lexer.close();
lexer.popSource();
EXPECT_TRUE(lexer.getSourceName().empty());
}
TEST_F(MasterLexerTest, invalidClose) {
// close() cannot be called if the sources stack is empty.
EXPECT_THROW(lexer.close(), isc::InvalidOperation);
// 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