From: JINMEI Tatuya Date: Tue, 30 Oct 2012 00:26:11 +0000 (-0700) Subject: [2371] supported open(filename) method X-Git-Tag: trac2487_base~1^2~21^2~30^2~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b237d10894d0eebe0affdc13bf781cc7f7a15b05;p=thirdparty%2Fkea.git [2371] supported open(filename) method --- diff --git a/src/lib/dns/master_lexer.cc b/src/lib/dns/master_lexer.cc index 1d8b3c2a4f..7041c57803 100644 --- a/src/lib/dns/master_lexer.cc +++ b/src/lib/dns/master_lexer.cc @@ -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))); diff --git a/src/lib/dns/master_lexer.h b/src/lib/dns/master_lexer.h index f07528e8c6..8dc51594b0 100644 --- a/src/lib/dns/master_lexer.h +++ b/src/lib/dns/master_lexer.h @@ -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; diff --git a/src/lib/dns/tests/Makefile.am b/src/lib/dns/tests/Makefile.am index 99d877f96a..931896c6af 100644 --- a/src/lib/dns/tests/Makefile.am +++ b/src/lib/dns/tests/Makefile.am @@ -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) diff --git a/src/lib/dns/tests/master_lexer_unittest.cc b/src/lib/dns/tests/master_lexer_unittest.cc index 8994c786e3..93162b154e 100644 --- a/src/lib/dns/tests/master_lexer_unittest.cc +++ b/src/lib/dns/tests/master_lexer_unittest.cc @@ -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()); +} + }