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

[2371] supported open(filename) method

parent 24e75cee
......@@ -32,11 +32,14 @@ createStreamName(std::istream& input_stream) {
return (ss.str());
}
// A fake version of InputSource until #2369 is ready. This class only
// provides some interfaces and doesn't manipulate the input source further.
class InputSource {
public:
InputSource(std::istream& input_stream) :
name_(createStreamName(input_stream))
{}
InputSource(const char* filename) : name_(filename) {}
const std::string& getName() const { return (name_); }
size_t getCurrentLine() const { return (1); }
......@@ -59,6 +62,11 @@ MasterLexer::~MasterLexer() {
delete impl_;
}
void
MasterLexer::open(const char* filename) {
impl_->sources_.push_back(InputSourcePtr(new InputSource(filename)));
}
void
MasterLexer::open(std::istream& input) {
impl_->sources_.push_back(InputSourcePtr(new InputSource(input)));
......
......@@ -31,6 +31,7 @@ public:
MasterLexer();
~MasterLexer();
void open(const char* filename);
void open(std::istream& input);
std::string getSourceName() const;
size_t getSourceLine() const;
......
......@@ -4,7 +4,7 @@ AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
AM_CPPFLAGS += $(BOOST_INCLUDES)
AM_CPPFLAGS += -I$(top_srcdir)/src/lib/dns -I$(top_builddir)/src/lib/dns
AM_CPPFLAGS += -I$(top_srcdir)/src/lib/util -I$(top_builddir)/src/lib/util
AM_CPPFLAGS += -DTEST_DATA_SRCDIR=\"$(srcdir)/testdata\"
AM_CPPFLAGS += -DTEST_DATA_SRCDIR=\"$(abs_top_srcdir)/src/lib/dns/tests/testdata\"
AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/lib/dns/tests/testdata\"
AM_CXXFLAGS = $(B10_CXXFLAGS)
......
......@@ -53,4 +53,12 @@ TEST_F(MasterLexerTest, openStream) {
EXPECT_EQ(1, lexer.getSourceLine());
}
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");
EXPECT_EQ(TEST_DATA_SRCDIR "/masterload.txt", lexer.getSourceName());
EXPECT_EQ(1, lexer.getSourceLine());
}
}
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