2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-31 05:55:28 +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.
///
/// This method normally does not throw an exception, but if resource
/// allocation for the returned \c Name object fails, a corresponding
/// standard exception will be thrown.
/// \exception std::bad_alloc If resource allocation for the returned
/// \c Name fails.
///
/// \note
/// Unlike the case of some other RDATA classes (such as
@@ -59,9 +58,8 @@ public:
/// \brief Return the value of the emailbox field.
///
/// This method normally does not throw an exception, but if resource
/// allocation for the returned \c Name object fails, a corresponding
/// standard exception will be thrown.
/// \exception std::bad_alloc If resource allocation for the returned
/// \c Name fails.
Name getEmailbox() const { return (emailbox_); }
private:

View File

@@ -37,107 +37,80 @@ class Rdata_MINFO_Test : public RdataTest {
};
// minfo text
string minfo_txt("root.example.com. emailbx.example.com.");
string minfo_txt2("rmailbx.example.com. emailbx.example.com.");
string too_long_label("012345678901234567890123456789"
"0123456789012345678901234567890123");
const char* const minfo_txt = "rmailbox.example.com. emailbox.example.com.";
const char* const too_long_label = "01234567890123456789012345678901234567"
"89012345678901234567890123";
// root.example.com. emailbx.example.com.
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);
const generic::MINFO rdata_minfo((string(minfo_txt)));
TEST_F(Rdata_MINFO_Test, createFromText) {
EXPECT_EQ(Name("root.example.com."), rdata_minfo.getRmailbox());
EXPECT_EQ(Name("emailbx.example.com."), rdata_minfo.getEmailbox());
EXPECT_EQ(Name("rmailbox.example.com."), rdata_minfo.getRmailbox());
EXPECT_EQ(Name("emailbox.example.com."), rdata_minfo.getEmailbox());
}
TEST_F(Rdata_MINFO_Test, badText) {
// incomplete text
EXPECT_THROW(generic::MINFO("root.example.com."),
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." +
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);
}
TEST_F(Rdata_MINFO_Test, createFromWire) {
// compressed emailbx name
EXPECT_EQ(0, rdata_minfo.compare(
*rdataFactoryFromFile(RRType("MINFO"), RRClass("IN"),
*rdataFactoryFromFile(RRType::MINFO(), RRClass::IN(),
"rdata_minfo_fromWire")));
// compressed rmailbx and emailbx name
EXPECT_EQ(0, rdata_minfo.compare(
*rdataFactoryFromFile(RRType("MINFO"), RRClass("IN"),
"rdata_minfo_fromWire", 30)));
*rdataFactoryFromFile(RRType("MINFO"), RRClass::IN(),
"rdata_minfo_fromWire", 35)));
// RDLENGTH is too short
EXPECT_THROW(rdataFactoryFromFile(RRType("MINFO"), RRClass("IN"),
"rdata_minfo_fromWire", 36),
EXPECT_THROW(rdataFactoryFromFile(RRType::MINFO(), RRClass::IN(),
"rdata_minfo_fromWire", 41),
InvalidRdataLength);
// RDLENGTH is too long
EXPECT_THROW(rdataFactoryFromFile(RRType("MINFO"), RRClass("IN"),
"rdata_minfo_fromWire", 42),
EXPECT_THROW(rdataFactoryFromFile(RRType::MINFO(), RRClass::IN(),
"rdata_minfo_fromWire", 47),
InvalidRdataLength);
// incomplete name. the error should be detected in the name constructor
EXPECT_THROW(rdataFactoryFromFile(RRType("MINFO"), RRClass("IN"),
"rdata_minfo_fromWire", 48),
EXPECT_THROW(rdataFactoryFromFile(RRType("MINFO"), RRClass::IN(),
"rdata_minfo_fromWire", 53),
DNSMessageFORMERR);
}
TEST_F(Rdata_MINFO_Test, toWireBuffer) {
obuffer.skip(2);
rdata_minfo.toWire(obuffer);
vector<unsigned char> data;
UnitTestUtil::readWireData("rdata_minfo_toWireUncompressed.wire", data);
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
obuffer.getData(), obuffer.getLength(),
uncompressed_wiredata_minfo,
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));
static_cast<const uint8_t *>(obuffer.getData()) + 2,
obuffer.getLength() - 2, &data[2], data.size() - 2);
}
TEST_F(Rdata_MINFO_Test, toWireRenderer) {
obuffer.skip(2);
rdata_minfo.toWire(renderer);
vector<unsigned char> data;
UnitTestUtil::readWireData("rdata_minfo_toWire", data);
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
obuffer.getData(), obuffer.getLength(),
compressed_wiredata_minfo,
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));
static_cast<const uint8_t *>(obuffer.getData()) + 2,
obuffer.getLength() - 2, &data[2], data.size() - 2);
}
TEST_F(Rdata_MINFO_Test, toText) {
EXPECT_EQ(minfo_txt, rdata_minfo.toText());
EXPECT_EQ(minfo_txt2, rdata_minfo2.toText());
}
TEST_F(Rdata_MINFO_Test, compare) {
@@ -145,18 +118,18 @@ TEST_F(Rdata_MINFO_Test, compare) {
EXPECT_EQ(0, rdata_minfo.compare(rdata_minfo));
// names must be compared in case-insensitive manner
EXPECT_EQ(0, rdata_minfo.compare(generic::MINFO("ROOT.example.com. "
"emailbx.EXAMPLE.com.")));
EXPECT_EQ(0, rdata_minfo.compare(generic::MINFO("RMAILBOX.example.com. "
"emailbox.EXAMPLE.com.")));
// 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.");
EXPECT_GT(0, rdata_minfo.compare(large1_minfo));
EXPECT_LT(0, large1_minfo.compare(rdata_minfo));
// another MINFO whose emailbox name is larger than that of rdata_minfo.
const generic::MINFO large2_minfo("root.example.com. "
"zzzzzzz.example.com.");
const generic::MINFO large2_minfo("rmailbox.example.com. "
"zzzzzzzzzzz.example.com.");
EXPECT_GT(0, rdata_minfo.compare(large2_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_soa_fromWire rdata_soa_toWireUncompressed.spec
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_fromWire3.spec rdata_txt_fromWire4.spec
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
#
# RDLENGHT=28 bytes
#
# Valid compressed RDATA for "(rmailbox.example.com. emailbox.example.com.)"
# RDLENGHT=32 bytes
# 0 1
00 1c
# 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 20 1 2(bytes)
04 72 6f 6f 74 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 07 65 6d
# 3 4 5 6 7 8 9
61 69 6c 62 78 c0 07
00 21
# RMAILBOX: non compressed
# 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 20 1 2 3(bytes)
#(8) r m a i l b o x (7) e x a m p l e (3) c o m .
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
#30 1
# 5 6
00 04
# 2 3 4 5(bytes)
c0 02 c0 14
# 7 8 9 40(bytes)
#ptr=02 ptr=24
c0 02 c0 18
#
# length too short
# rdlength too short
# RDLENGHT=03 bytes
# 6 7
# 1 2
00 03
# 8 9 40 1(bytes)
c0 02 c0 14
# 3 4 5 6(bytes)
#ptr=02 ptr=24
c0 02 c0 18
#
# length too long
# rdlength too long
# RDLENGHT=25 bytes
# 2 3
# 7 8
00 19
# 4 5 6 7(bytes)
c0 02 c0 14
# 9 50 1 2(bytes)
#ptr=02 ptr=24
c0 02 c0 18
#
# incomplete target name
# incomplete RMAILBOX NAME
# RDLENGHT=19 bytes
# 8 9
# 3 4
00 13
#50 1 2 3 4 5 6 7 8 9 60 1 2 3 4 5 6 7 8 (bytes)
04 72 6f 6f 74 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 07
# 5 6 7 8 9 60 1 2 3 4 5 6 7 8 9 60 1 2 3 (bytes)
#(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('%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):
'''Implements rendering NSEC/NSEC3 type bitmaps commonly used for
these RRs. The NSEC and NSEC3 classes will be inherited from this