diff options
author | JINMEI Tatuya <jinmei@isc.org> | 2012-11-30 07:30:56 +0100 |
---|---|---|
committer | JINMEI Tatuya <jinmei@isc.org> | 2012-12-01 04:41:13 +0100 |
commit | b9f1eefe7e7040db4841e75a38b6a9cd1511eb59 (patch) | |
tree | bc1220e669f2bdaa952e7d541f4072ca27f1e8be /src | |
parent | [2382] ungetToken EOL/EOF in the backend factories. (diff) | |
download | kea-b9f1eefe7e7040db4841e75a38b6a9cd1511eb59.tar.xz kea-b9f1eefe7e7040db4841e75a38b6a9cd1511eb59.zip |
[2382] Consume to end of line / file in createRdata().
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/dns/rdata.cc | 21 | ||||
-rw-r--r-- | src/lib/dns/tests/rdata_unittest.cc | 24 | ||||
-rw-r--r-- | src/lib/dns/tests/rdata_unittest.h | 2 |
3 files changed, 37 insertions, 10 deletions
diff --git a/src/lib/dns/rdata.cc b/src/lib/dns/rdata.cc index ddb4b77258..cc7c582743 100644 --- a/src/lib/dns/rdata.cc +++ b/src/lib/dns/rdata.cc @@ -30,6 +30,7 @@ #include <util/buffer.h> #include <dns/name.h> #include <dns/messagerenderer.h> +#include <dns/master_lexer.h> #include <dns/rdata.h> #include <dns/rrparamregistry.h> #include <dns/rrtype.h> @@ -87,17 +88,17 @@ createRdata(const RRType& rrtype, const RRClass& rrclass, MasterLoader::Options options, MasterLoaderCallbacks& callbacks) { - RdataPtr ret; - - try { - ret = RRParamRegistry::getRegistry().createRdata(rrtype, rrclass, - lexer, origin, - options, callbacks); - } catch (...) { - // ret is NULL here. - } + const RdataPtr rdata = RRParamRegistry::getRegistry().createRdata( + rrtype, rrclass, lexer, origin, options, callbacks); + + // Consume to end of line / file. + // If not at end of line initially set error code. + // Call callback via fromtext_error once if there was an error. + const MasterToken& token = lexer.getNextToken(); + assert(token.getType() == MasterToken::END_OF_LINE || + token.getType() == MasterToken::END_OF_FILE); - return (ret); + return (rdata); } int diff --git a/src/lib/dns/tests/rdata_unittest.cc b/src/lib/dns/tests/rdata_unittest.cc index bc91f7ad0d..08d9628d19 100644 --- a/src/lib/dns/tests/rdata_unittest.cc +++ b/src/lib/dns/tests/rdata_unittest.cc @@ -82,6 +82,30 @@ createRdataUsingLexer(const RRType& rrtype, const RRClass& rrclass, } // end of namespace isc::dns::rdata::test +// Test class/type-independent behavior of createRdata(). +TEST_F(RdataTest, createRdataWithLexer) { + const generic::NS ns_rdata("ns.example.com."); + const in::AAAA aaaa_rdata("2001:db8::1"); + + stringstream ss; + ss << ns_rdata.toText() << "\n"; // valid case + ss << aaaa_rdata.toText() << " extra-token\n"; // extra token + lexer.pushSource(ss); + + const MasterLoaderCallbacks::IssueCallback callback + (boost::bind(&test::dummyCallback, _1, _2, _3)); + MasterLoaderCallbacks callbacks(callback, callback); + ConstRdataPtr rdata = createRdata(RRType::NS(), RRClass::IN(), lexer, NULL, + MasterLoader::MANY_ERRORS, callbacks); + EXPECT_EQ(0, ns_rdata.compare(*rdata)); + +#ifdef notyet + rdata = createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL, + MasterLoader::MANY_ERRORS, callbacks); + EXPECT_EQ(0, aaaa_rdata.compare(*rdata)); +#endif +} + } } } diff --git a/src/lib/dns/tests/rdata_unittest.h b/src/lib/dns/tests/rdata_unittest.h index 3efb5d8346..af19311794 100644 --- a/src/lib/dns/tests/rdata_unittest.h +++ b/src/lib/dns/tests/rdata_unittest.h @@ -20,6 +20,7 @@ #include <dns/rrclass.h> #include <dns/rrtype.h> #include <dns/rdata.h> +#include <dns/master_lexer.h> #include <gtest/gtest.h> @@ -40,6 +41,7 @@ protected: /// This is an RDATA object of some "unknown" RR type so that it can be /// used to test the compare() method against a well-known RR type. RdataPtr rdata_nomatch; + MasterLexer lexer; }; namespace test { |