Browse Source

[2371] supported open(filename) method

JINMEI Tatuya 12 years ago
parent
commit
b237d10894

+ 8 - 0
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); }
 
@@ -60,6 +63,11 @@ MasterLexer::~MasterLexer() {
 }
 
 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)));
 }

+ 1 - 0
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;

+ 1 - 1
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)
 

+ 8 - 0
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());
+}
+
 }