2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-01 14:35:29 +00:00

[trac1113] sync with master, fix doxygen and unittest

This commit is contained in:
chenzhengzhang
2011-08-11 11:00:21 +08:00
parent 5b7dee0548
commit 00686a614c
5 changed files with 100 additions and 97 deletions

View File

@@ -39,9 +39,8 @@ public:
/// \brief Return the value of the rmailbox field. /// \brief Return the value of the rmailbox field.
/// ///
/// This method normally does not throw an exception, but if resource /// \exception std::bad_alloc If resource allocation for the returned
/// allocation for the returned \c Name object fails, a corresponding /// \c Name fails.
/// standard exception will be thrown.
/// ///
/// \note /// \note
/// Unlike the case of some other RDATA classes (such as /// Unlike the case of some other RDATA classes (such as
@@ -59,9 +58,8 @@ public:
/// \brief Return the value of the emailbox field. /// \brief Return the value of the emailbox field.
/// ///
/// This method normally does not throw an exception, but if resource /// \exception std::bad_alloc If resource allocation for the returned
/// allocation for the returned \c Name object fails, a corresponding /// \c Name fails.
/// standard exception will be thrown.
Name getEmailbox() const { return (emailbox_); } Name getEmailbox() const { return (emailbox_); }
private: private:

View File

@@ -37,107 +37,80 @@ class Rdata_MINFO_Test : public RdataTest {
}; };
// minfo text // minfo text
string minfo_txt("root.example.com. emailbx.example.com."); const char* const minfo_txt = "rmailbox.example.com. emailbox.example.com.";
string minfo_txt2("rmailbx.example.com. emailbx.example.com."); const char* const too_long_label = "01234567890123456789012345678901234567"
string too_long_label("012345678901234567890123456789" "89012345678901234567890123";
"0123456789012345678901234567890123");
// root.example.com. emailbx.example.com. const generic::MINFO rdata_minfo((string(minfo_txt)));
const uint8_t uncompressed_wiredata_minfo[] = {
0x04, 0x72, 0x6f, 0x6f, 0x74, 0x07, 0x65, 0x78, 0x61, 0x6d, 0x70,
0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x07, 0x65, 0x6d, 0x61,
0x69, 0x6c, 0x62, 0x78, 0x07, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c,
0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00};
// rmailbx.example.com. emailbx.example.com.
const uint8_t uncompressed_wiredata_minfo2[] = {
0x07, 0x72, 0x6d, 0x61, 0x69, 0x6c, 0x62, 0x78, 0x07, 0x65, 0x78,
0x61, 0x6d, 0x70, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x07,
0x65, 0x6d, 0x61, 0x69, 0x6c, 0x62, 0x78, 0x07, 0x65, 0x78, 0x61,
0x6d, 0x70, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00};
// root.example.com. emailbx.example.com.
const uint8_t compressed_wiredata_minfo[] = {
0x04, 0x72, 0x6f, 0x6f, 0x74, 0x07, 0x65, 0x78, 0x61, 0x6d, 0x70,
0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x07, 0x65, 0x6d, 0x61,
0x69, 0x6c, 0x62, 0x78, 0xc0, 0x05};
// rmailbx.example.com. emailbx.example.com.
const uint8_t compressed_wiredata_minfo2[] = {
0x07, 0x72, 0x6d, 0x61, 0x69, 0x6c, 0x62, 0x78, 0x07, 0x65, 0x78,
0x61, 0x6d, 0x70, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x07,
0x65, 0x6d, 0x61, 0x69, 0x6c, 0x62, 0x78, 0xc0, 0x08};
const generic::MINFO rdata_minfo(minfo_txt);
const generic::MINFO rdata_minfo2(minfo_txt2);
TEST_F(Rdata_MINFO_Test, createFromText) { TEST_F(Rdata_MINFO_Test, createFromText) {
EXPECT_EQ(Name("root.example.com."), rdata_minfo.getRmailbox()); EXPECT_EQ(Name("rmailbox.example.com."), rdata_minfo.getRmailbox());
EXPECT_EQ(Name("emailbx.example.com."), rdata_minfo.getEmailbox()); EXPECT_EQ(Name("emailbox.example.com."), rdata_minfo.getEmailbox());
} }
TEST_F(Rdata_MINFO_Test, badText) { TEST_F(Rdata_MINFO_Test, badText) {
// incomplete text // incomplete text
EXPECT_THROW(generic::MINFO("root.example.com."), EXPECT_THROW(generic::MINFO("root.example.com."),
InvalidRdataText); InvalidRdataText);
// bad name // number of fields (must be 2) is incorrect
EXPECT_THROW(generic::MINFO("root.example.com emailbox.example.com. "
"example.com."),
InvalidRdataText);
// bad rmailbox name
EXPECT_THROW(generic::MINFO("root.example.com. emailbx.example.com." + EXPECT_THROW(generic::MINFO("root.example.com. emailbx.example.com." +
too_long_label), string(too_long_label)),
TooLongLabel);
// bad emailbox name
EXPECT_THROW(generic::MINFO("root.example.com." +
string(too_long_label) + " emailbx.example.com."),
TooLongLabel); TooLongLabel);
} }
TEST_F(Rdata_MINFO_Test, createFromWire) { TEST_F(Rdata_MINFO_Test, createFromWire) {
// compressed emailbx name // compressed emailbx name
EXPECT_EQ(0, rdata_minfo.compare( EXPECT_EQ(0, rdata_minfo.compare(
*rdataFactoryFromFile(RRType("MINFO"), RRClass("IN"), *rdataFactoryFromFile(RRType::MINFO(), RRClass::IN(),
"rdata_minfo_fromWire"))); "rdata_minfo_fromWire")));
// compressed rmailbx and emailbx name // compressed rmailbx and emailbx name
EXPECT_EQ(0, rdata_minfo.compare( EXPECT_EQ(0, rdata_minfo.compare(
*rdataFactoryFromFile(RRType("MINFO"), RRClass("IN"), *rdataFactoryFromFile(RRType("MINFO"), RRClass::IN(),
"rdata_minfo_fromWire", 30))); "rdata_minfo_fromWire", 35)));
// RDLENGTH is too short // RDLENGTH is too short
EXPECT_THROW(rdataFactoryFromFile(RRType("MINFO"), RRClass("IN"), EXPECT_THROW(rdataFactoryFromFile(RRType::MINFO(), RRClass::IN(),
"rdata_minfo_fromWire", 36), "rdata_minfo_fromWire", 41),
InvalidRdataLength); InvalidRdataLength);
// RDLENGTH is too long // RDLENGTH is too long
EXPECT_THROW(rdataFactoryFromFile(RRType("MINFO"), RRClass("IN"), EXPECT_THROW(rdataFactoryFromFile(RRType::MINFO(), RRClass::IN(),
"rdata_minfo_fromWire", 42), "rdata_minfo_fromWire", 47),
InvalidRdataLength); InvalidRdataLength);
// incomplete name. the error should be detected in the name constructor // incomplete name. the error should be detected in the name constructor
EXPECT_THROW(rdataFactoryFromFile(RRType("MINFO"), RRClass("IN"), EXPECT_THROW(rdataFactoryFromFile(RRType("MINFO"), RRClass::IN(),
"rdata_minfo_fromWire", 48), "rdata_minfo_fromWire", 53),
DNSMessageFORMERR); DNSMessageFORMERR);
} }
TEST_F(Rdata_MINFO_Test, toWireBuffer) { TEST_F(Rdata_MINFO_Test, toWireBuffer) {
obuffer.skip(2);
rdata_minfo.toWire(obuffer); rdata_minfo.toWire(obuffer);
vector<unsigned char> data;
UnitTestUtil::readWireData("rdata_minfo_toWireUncompressed.wire", data);
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData, EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
obuffer.getData(), obuffer.getLength(), static_cast<const uint8_t *>(obuffer.getData()) + 2,
uncompressed_wiredata_minfo, obuffer.getLength() - 2, &data[2], data.size() - 2);
sizeof(uncompressed_wiredata_minfo));
obuffer.clear();
rdata_minfo2.toWire(obuffer);
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
obuffer.getData(), obuffer.getLength(),
uncompressed_wiredata_minfo2,
sizeof(uncompressed_wiredata_minfo2));
} }
TEST_F(Rdata_MINFO_Test, toWireRenderer) { TEST_F(Rdata_MINFO_Test, toWireRenderer) {
obuffer.skip(2);
rdata_minfo.toWire(renderer); rdata_minfo.toWire(renderer);
vector<unsigned char> data;
UnitTestUtil::readWireData("rdata_minfo_toWire", data);
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData, EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
obuffer.getData(), obuffer.getLength(), static_cast<const uint8_t *>(obuffer.getData()) + 2,
compressed_wiredata_minfo, obuffer.getLength() - 2, &data[2], data.size() - 2);
sizeof(compressed_wiredata_minfo));
renderer.clear();
rdata_minfo2.toWire(renderer);
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
obuffer.getData(), obuffer.getLength(),
compressed_wiredata_minfo2,
sizeof(compressed_wiredata_minfo2));
} }
TEST_F(Rdata_MINFO_Test, toText) { TEST_F(Rdata_MINFO_Test, toText) {
EXPECT_EQ(minfo_txt, rdata_minfo.toText()); EXPECT_EQ(minfo_txt, rdata_minfo.toText());
EXPECT_EQ(minfo_txt2, rdata_minfo2.toText());
} }
TEST_F(Rdata_MINFO_Test, compare) { TEST_F(Rdata_MINFO_Test, compare) {
@@ -145,18 +118,18 @@ TEST_F(Rdata_MINFO_Test, compare) {
EXPECT_EQ(0, rdata_minfo.compare(rdata_minfo)); EXPECT_EQ(0, rdata_minfo.compare(rdata_minfo));
// names must be compared in case-insensitive manner // names must be compared in case-insensitive manner
EXPECT_EQ(0, rdata_minfo.compare(generic::MINFO("ROOT.example.com. " EXPECT_EQ(0, rdata_minfo.compare(generic::MINFO("RMAILBOX.example.com. "
"emailbx.EXAMPLE.com."))); "emailbox.EXAMPLE.com.")));
// another MINFO whose rmailbox name is larger than that of rdata_minfo. // another MINFO whose rmailbox name is larger than that of rdata_minfo.
const generic::MINFO large1_minfo("zzzz.example.com. " const generic::MINFO large1_minfo("zzzzzzzz.example.com. "
"emailbox.example.com."); "emailbox.example.com.");
EXPECT_GT(0, rdata_minfo.compare(large1_minfo)); EXPECT_GT(0, rdata_minfo.compare(large1_minfo));
EXPECT_LT(0, large1_minfo.compare(rdata_minfo)); EXPECT_LT(0, large1_minfo.compare(rdata_minfo));
// another MINFO whose emailbox name is larger than that of rdata_minfo. // another MINFO whose emailbox name is larger than that of rdata_minfo.
const generic::MINFO large2_minfo("root.example.com. " const generic::MINFO large2_minfo("rmailbox.example.com. "
"zzzzzzz.example.com."); "zzzzzzzzzzz.example.com.");
EXPECT_GT(0, rdata_minfo.compare(large2_minfo)); EXPECT_GT(0, rdata_minfo.compare(large2_minfo));
EXPECT_LT(0, large2_minfo.compare(rdata_minfo)); EXPECT_LT(0, large2_minfo.compare(rdata_minfo));

View File

@@ -101,7 +101,8 @@ EXTRA_DIST += rdata_rp_fromWire5.spec rdata_rp_fromWire6.spec
EXTRA_DIST += rdata_rp_toWire1.spec rdata_rp_toWire2.spec EXTRA_DIST += rdata_rp_toWire1.spec rdata_rp_toWire2.spec
EXTRA_DIST += rdata_soa_fromWire rdata_soa_toWireUncompressed.spec EXTRA_DIST += rdata_soa_fromWire rdata_soa_toWireUncompressed.spec
EXTRA_DIST += rdata_srv_fromWire EXTRA_DIST += rdata_srv_fromWire
EXTRA_DIST += rdata_minfo_fromWire EXTRA_DIST += rdata_minfo_fromWire rdata_minfo_toWireUncompressed.spec
EXTRA_DIST += rdata_minfo_toWireUncompressed.wire rdata_minfo_toWire
EXTRA_DIST += rdata_txt_fromWire1 rdata_txt_fromWire2.spec EXTRA_DIST += rdata_txt_fromWire1 rdata_txt_fromWire2.spec
EXTRA_DIST += rdata_txt_fromWire3.spec rdata_txt_fromWire4.spec EXTRA_DIST += rdata_txt_fromWire3.spec rdata_txt_fromWire4.spec
EXTRA_DIST += rdata_txt_fromWire5.spec rdata_unknown_fromWire EXTRA_DIST += rdata_txt_fromWire5.spec rdata_unknown_fromWire

View File

@@ -1,38 +1,47 @@
# #
# various kinds of MINFO RDATA stored in an input buffer # various kinds of MINFO RDATA stored in an input buffer
# #
# RDLENGHT=28 bytes # Valid compressed RDATA for "(rmailbox.example.com. emailbox.example.com.)"
# RDLENGHT=32 bytes
# 0 1 # 0 1
00 1c 00 21
# 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 20 1 2(bytes) # RMAILBOX: non compressed
04 72 6f 6f 74 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 07 65 6d # 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 20 1 2 3(bytes)
# 3 4 5 6 7 8 9 #(8) r m a i l b o x (7) e x a m p l e (3) c o m .
61 69 6c 62 78 c0 07 08 72 6d 61 69 6c 62 6f 78 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00
# EMAILBOX: compressed
# 4 5 6 7 8 9 30 1 2 3 4
#(8) e m a i l b o x ptr=11
08 65 6d 61 69 6c 62 6f 78 c0 0b
# #
# compressed name # Both RMAILBOX and EMAILBOX compressed
# RDLENGHT=04 bytes # RDLENGHT=04 bytes
#30 1 # 5 6
00 04 00 04
# 2 3 4 5(bytes) # 7 8 9 40(bytes)
c0 02 c0 14 #ptr=02 ptr=24
c0 02 c0 18
# #
# length too short # rdlength too short
# RDLENGHT=03 bytes # RDLENGHT=03 bytes
# 6 7 # 1 2
00 03 00 03
# 8 9 40 1(bytes) # 3 4 5 6(bytes)
c0 02 c0 14 #ptr=02 ptr=24
c0 02 c0 18
# #
# length too long # rdlength too long
# RDLENGHT=25 bytes # RDLENGHT=25 bytes
# 2 3 # 7 8
00 19 00 19
# 4 5 6 7(bytes) # 9 50 1 2(bytes)
c0 02 c0 14 #ptr=02 ptr=24
c0 02 c0 18
# #
# incomplete target name # incomplete RMAILBOX NAME
# RDLENGHT=19 bytes # RDLENGHT=19 bytes
# 8 9 # 3 4
00 13 00 13
#50 1 2 3 4 5 6 7 8 9 60 1 2 3 4 5 6 7 8 (bytes) # 5 6 7 8 9 60 1 2 3 4 5 6 7 8 9 60 1 2 3 (bytes)
04 72 6f 6f 74 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 07 #(8) r m a i l b o x (7) e x a m p l e (3) c
08 72 6d 61 69 6c 62 6f 78 07 65 78 61 6d 70 6c 65 03 63

View File

@@ -822,6 +822,28 @@ class RP(RR):
f.write('# MAILBOX=%s TEXT=%s\n' % (self.mailbox, self.text)) f.write('# MAILBOX=%s TEXT=%s\n' % (self.mailbox, self.text))
f.write('%s %s\n' % (mailbox_wire, text_wire)) f.write('%s %s\n' % (mailbox_wire, text_wire))
class MINFO(RR):
'''Implements rendering MINFO RDATA in the test data format.
Configurable parameters are as follows (see the description of the
same name of attribute for the default value):
- rmailbox (string): The rmailbox field.
- emailbox (string): The emailbox field.
These strings must be interpreted as a valid domain name.
'''
rmailbox = 'rmailbox.example.com'
emailbox = 'emailbox.example.com'
def dump(self, f):
rmailbox_wire = encode_name(self.rmailbox)
emailbox_wire = encode_name(self.emailbox)
if self.rdlen is None:
self.rdlen = (len(rmailbox_wire) + len(emailbox_wire)) / 2
else:
self.rdlen = int(self.rdlen)
self.dump_header(f, self.rdlen)
f.write('# RMAILBOX=%s EMAILBOX=%s\n' % (self.rmailbox, self.emailbox))
f.write('%s %s\n' % (rmailbox_wire, emailbox_wire))
class NSECBASE(RR): class NSECBASE(RR):
'''Implements rendering NSEC/NSEC3 type bitmaps commonly used for '''Implements rendering NSEC/NSEC3 type bitmaps commonly used for
these RRs. The NSEC and NSEC3 classes will be inherited from this these RRs. The NSEC and NSEC3 classes will be inherited from this