mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 21:45:37 +00:00
[2382] Consume to end of line / file in createRdata().
This commit is contained in:
@@ -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;
|
||||
const RdataPtr rdata = RRParamRegistry::getRegistry().createRdata(
|
||||
rrtype, rrclass, lexer, origin, options, callbacks);
|
||||
|
||||
try {
|
||||
ret = RRParamRegistry::getRegistry().createRdata(rrtype, rrclass,
|
||||
lexer, origin,
|
||||
options, callbacks);
|
||||
} catch (...) {
|
||||
// ret is NULL here.
|
||||
}
|
||||
// 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
|
||||
|
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user