EXPECT_EQ(expected_sigcount, actual_rrset.getRRsigDataCount());
}
+ // The following two are trivial wrapper to create a shared pointer
+ // version of TreeNodeRRset object in order to work around dubious
+ // behavior of some C++ compiler: they reject getting a const reference to
+ // a temporary non-copyable object.
+ boost::shared_ptr<TreeNodeRRset>
+ createRRset(const RRClass& rrclass, const ZoneNode* node,
+ const RdataSet* rdataset, bool dnssec_ok)
+ {
+ return (boost::shared_ptr<TreeNodeRRset>(
+ new TreeNodeRRset(rrclass, node, rdataset, dnssec_ok)));
+ }
+
+ boost::shared_ptr<TreeNodeRRset>
+ createRRset(const Name& realname, const RRClass& rrclass, const ZoneNode* node,
+ const RdataSet* rdataset, bool dnssec_ok)
+ {
+ return (boost::shared_ptr<TreeNodeRRset>(
+ new TreeNodeRRset(realname, rrclass, node, rdataset,
+ dnssec_ok)));
+ }
+
TEST_F(TreeNodeRRsetTest, create) {
// Constructed with RRSIG, and it should be visible.
- checkBasicFields(TreeNodeRRset(rrclass_, www_node_, a_rdataset_, true),
+ checkBasicFields(*createRRset(rrclass_, www_node_, a_rdataset_, true),
- www_name_, rrclass_, RRType::A(), 2, 1);
+ www_name_, rrclass_, RRType::A(), 3600, 2, 1);
// Constructed with RRSIG, and it should be invisible.
- checkBasicFields(TreeNodeRRset(rrclass_, www_node_, a_rdataset_, false),
+ checkBasicFields(*createRRset(rrclass_, www_node_, a_rdataset_, false),
- www_name_, rrclass_, RRType::A(), 2, 0);
+ www_name_, rrclass_, RRType::A(), 3600, 2, 0);
// Constructed without RRSIG, and it would be visible (but of course won't)
- checkBasicFields(TreeNodeRRset(rrclass_, origin_node_, ns_rdataset_, true),
+ checkBasicFields(*createRRset(rrclass_, origin_node_, ns_rdataset_, true),
- origin_name_, rrclass_, RRType::NS(), 1, 0);
+ origin_name_, rrclass_, RRType::NS(), 3600, 1, 0);
// Constructed without RRSIG, and it should be visible
- checkBasicFields(TreeNodeRRset(rrclass_, origin_node_, ns_rdataset_,
- false),
+ checkBasicFields(*createRRset(rrclass_, origin_node_, ns_rdataset_, false),
- origin_name_, rrclass_, RRType::NS(), 1, 0);
+ origin_name_, rrclass_, RRType::NS(), 3600, 1, 0);
// RRSIG-only case (note the RRset's type is covered type)
- checkBasicFields(TreeNodeRRset(rrclass_, www_node_, rrsig_only_rdataset_,
- true),
+ checkBasicFields(*createRRset(rrclass_, www_node_, rrsig_only_rdataset_,
+ true),
- www_name_, rrclass_, RRType::TXT(), 0, 1);
+ www_name_, rrclass_, RRType::TXT(), 3600, 0, 1);
// RRSIG-only case (note the RRset's type is covered type), but it's
// invisible
- checkBasicFields(TreeNodeRRset(rrclass_, www_node_, rrsig_only_rdataset_,
- false),
+ checkBasicFields(*createRRset(rrclass_, www_node_, rrsig_only_rdataset_,
+ false),
- www_name_, rrclass_, RRType::TXT(), 0, 0);
+ www_name_, rrclass_, RRType::TXT(), 3600, 0, 0);
// Wildcard substitution
- checkBasicFields(TreeNodeRRset(match_name_, rrclass_,
- wildcard_node_, wildcard_rdataset_,
- true),
+ checkBasicFields(*createRRset(match_name_, rrclass_,
+ wildcard_node_, wildcard_rdataset_,
+ true),
- match_name_, rrclass_, RRType::A(), 2, 1);
+ match_name_, rrclass_, RRType::A(), 3600, 2, 1);
}
- // Templated if and when we support OutputBuffer version of toWire().
- // Right now, we take a minimalist approach, only implementing testing the
- // renderer version.
+ // The following two templated functions are helper to encapsulate the
+ // concept truncation and handle MessageRenderer and OutputBuffer transparently
+ // in templated test cases.
+ template <typename OutputType>
+ void
+ setOutputLengthLimit(OutputType& output, size_t len_limit) {
+ output.setLengthLimit(len_limit);
+ }
+ template <>
+ void
+ setOutputLengthLimit<OutputBuffer>(OutputBuffer&, size_t) {
+ }
+
+ template <typename OutputType>
+ bool
+ isOutputTruncated(OutputType& output) {
+ return (output.isTruncated());
+ }
+ template <>
+ bool
+ isOutputTruncated<OutputBuffer>(OutputBuffer&) {
+ return (false);
+ }
+
+ // Templated so we so can support OutputBuffer version of toWire().
+ // We use the above helper templated functions for some renderer only methods.
+ // We test two sets of cases: normal rendering case and case when truncation
+ // is expected. The latter is effectively for MessageRenderer only.
+ // If len_limit == 0, we consider it the normal case; otherwise it's for
+ // truncation. prepended_name isn't used for the truncation case.
template <typename OutputType>
void
checkToWireResult(OutputType& expected_output, OutputType& actual_output,
// Different kind of different RRset class
EXPECT_FALSE(rrset.isSameKind(*aaaa_rrset_));
}
- EXPECT_THROW(rrset.getTTL(), isc::Unexpected);
+
+ TEST_F(TreeNodeRRsetTest, unexpectedMethods) {
+ // Note: buffer version of toWire() is checked in the toWire test.
+
+ TreeNodeRRset rrset(rrclass_, www_node_, a_rdataset_, true);
+
+ EXPECT_THROW(rrset.setTTL(RRTTL(0)), isc::Unexpected);
+ EXPECT_THROW(rrset.setName(Name("example")), isc::Unexpected);
+ EXPECT_THROW(rrset.addRdata(createRdata(RRType::A(), rrclass_, "0.0.0.0")),
+ isc::Unexpected);
+ EXPECT_THROW(rrset.getRRsig(), isc::Unexpected);
+ RdataPtr sig_rdata = createRdata(
+ RRType::RRSIG(), rrclass_,
+ "A 5 2 3600 20120814220826 20120715220826 5300 example.com. FAKE");
+ EXPECT_THROW(rrset.addRRsig(sig_rdata), isc::Unexpected);
+ EXPECT_THROW(rrset.addRRsig(*a_rrsig_rrset_), isc::Unexpected);
+ EXPECT_THROW(rrset.addRRsig(a_rrsig_rrset_), isc::Unexpected);
+ EXPECT_THROW(rrset.addRRsig(RRsetPtr()), isc::Unexpected);
+ EXPECT_THROW(rrset.removeRRsig(), isc::Unexpected);
+ }
}