2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-31 14:05:33 +00:00

[2467] Miscellaneous minor changes as a result of review

This commit is contained in:
Stephen Morris
2013-04-30 13:57:22 +01:00
parent af37bfe0c4
commit 55dd08057c
6 changed files with 30 additions and 34 deletions

View File

@@ -134,8 +134,7 @@ public:
// domain-name // domain-name
OptionDefinition def("domain-name", DHO_DOMAIN_NAME, OPT_FQDN_TYPE); OptionDefinition def("domain-name", DHO_DOMAIN_NAME, OPT_FQDN_TYPE);
boost::shared_ptr<OptionCustom> OptionCustomPtr option_domain_name(new OptionCustom(def, Option::V4));
option_domain_name(new OptionCustom(def, Option::V4));
option_domain_name->writeFqdn("example.com"); option_domain_name->writeFqdn("example.com");
subnet_->addOption(option_domain_name, false, "dhcp4"); subnet_->addOption(option_domain_name, false, "dhcp4");
@@ -154,8 +153,7 @@ public:
/// @brief checks that the response matches request /// @brief checks that the response matches request
/// @param q query (client's message) /// @param q query (client's message)
/// @param a answer (server's message) /// @param a answer (server's message)
void messageCheck(const boost::shared_ptr<Pkt4>& q, void messageCheck(const Pkt4Ptr& q, const Pkt4Ptr& a) {
const boost::shared_ptr<Pkt4>& a) {
ASSERT_TRUE(q); ASSERT_TRUE(q);
ASSERT_TRUE(a); ASSERT_TRUE(a);
@@ -398,8 +396,8 @@ TEST_F(Dhcpv4SrvTest, processDiscover) {
mac[i] = 255 - i; mac[i] = 255 - i;
} }
boost::shared_ptr<Pkt4> pkt(new Pkt4(DHCPDISCOVER, 1234)); Pkt4Ptr pkt(new Pkt4(DHCPDISCOVER, 1234));
boost::shared_ptr<Pkt4> offer; Pkt4Ptr offer;
pkt->setIface("eth0"); pkt->setIface("eth0");
pkt->setIndex(17); pkt->setIndex(17);
@@ -502,8 +500,8 @@ TEST_F(Dhcpv4SrvTest, processRequest) {
mac[i] = i * 10; mac[i] = i * 10;
} }
boost::shared_ptr<Pkt4> req(new Pkt4(DHCPREQUEST, 1234)); Pkt4Ptr req(new Pkt4(DHCPREQUEST, 1234));
boost::shared_ptr<Pkt4> ack; Pkt4Ptr ack;
req->setIface("eth0"); req->setIface("eth0");
req->setIndex(17); req->setIndex(17);
@@ -588,7 +586,7 @@ TEST_F(Dhcpv4SrvTest, processRequest) {
TEST_F(Dhcpv4SrvTest, processRelease) { TEST_F(Dhcpv4SrvTest, processRelease) {
NakedDhcpv4Srv srv; NakedDhcpv4Srv srv;
boost::shared_ptr<Pkt4> pkt(new Pkt4(DHCPRELEASE, 1234)); Pkt4Ptr pkt(new Pkt4(DHCPRELEASE, 1234));
// Should not throw // Should not throw
EXPECT_NO_THROW(srv.processRelease(pkt)); EXPECT_NO_THROW(srv.processRelease(pkt));
@@ -596,7 +594,7 @@ TEST_F(Dhcpv4SrvTest, processRelease) {
TEST_F(Dhcpv4SrvTest, processDecline) { TEST_F(Dhcpv4SrvTest, processDecline) {
NakedDhcpv4Srv srv; NakedDhcpv4Srv srv;
boost::shared_ptr<Pkt4> pkt(new Pkt4(DHCPDECLINE, 1234)); Pkt4Ptr pkt(new Pkt4(DHCPDECLINE, 1234));
// Should not throw // Should not throw
EXPECT_NO_THROW(srv.processDecline(pkt)); EXPECT_NO_THROW(srv.processDecline(pkt));
@@ -604,7 +602,7 @@ TEST_F(Dhcpv4SrvTest, processDecline) {
TEST_F(Dhcpv4SrvTest, processInform) { TEST_F(Dhcpv4SrvTest, processInform) {
NakedDhcpv4Srv srv; NakedDhcpv4Srv srv;
boost::shared_ptr<Pkt4> pkt(new Pkt4(DHCPINFORM, 1234)); Pkt4Ptr pkt(new Pkt4(DHCPINFORM, 1234));
// Should not throw // Should not throw
EXPECT_NO_THROW(srv.processInform(pkt)); EXPECT_NO_THROW(srv.processInform(pkt));

View File

@@ -169,7 +169,7 @@ public:
EXPECT_EQ(0, ia->getT1()); EXPECT_EQ(0, ia->getT1());
EXPECT_EQ(0, ia->getT2()); EXPECT_EQ(0, ia->getT2());
boost::shared_ptr<OptionCustom> status = OptionCustomPtr status =
boost::dynamic_pointer_cast<OptionCustom>(ia->getOption(D6O_STATUS_CODE)); boost::dynamic_pointer_cast<OptionCustom>(ia->getOption(D6O_STATUS_CODE));
// It is ok to not include status success as this is the default behavior // It is ok to not include status success as this is the default behavior
@@ -189,7 +189,7 @@ public:
} }
void checkMsgStatusCode(const Pkt6Ptr& msg, uint16_t expected_status) { void checkMsgStatusCode(const Pkt6Ptr& msg, uint16_t expected_status) {
boost::shared_ptr<OptionCustom> status = OptionCustomPtr status =
boost::dynamic_pointer_cast<OptionCustom>(msg->getOption(D6O_STATUS_CODE)); boost::dynamic_pointer_cast<OptionCustom>(msg->getOption(D6O_STATUS_CODE));
// It is ok to not include status success as this is the default behavior // It is ok to not include status success as this is the default behavior
@@ -586,7 +586,7 @@ TEST_F(Dhcpv6SrvTest, advertiseOptions) {
sol->addOption(clientid); sol->addOption(clientid);
// Pass it to the server and get an advertise // Pass it to the server and get an advertise
boost::shared_ptr<Pkt6> adv = srv.processSolicit(sol); Pkt6Ptr adv = srv.processSolicit(sol);
// check if we get response at all // check if we get response at all
ASSERT_TRUE(adv); ASSERT_TRUE(adv);

View File

@@ -111,13 +111,13 @@ TEST_F(IfaceMgrTest, dhcp6Sniffer) {
interfaces << "eth0 fe80::21e:8cff:fe9b:7349"; interfaces << "eth0 fe80::21e:8cff:fe9b:7349";
interfaces.close(); interfaces.close();
NakedIfaceMgr* ifacemgr = new NakedIfaceMgr(); boost::scoped_ptr<NakedIfaceMgr> ifacemgr = new NakedIfaceMgr();
Pkt6* pkt = NULL; Pkt6Ptr pkt;
int cnt = 0; int cnt = 0;
cout << "---8X-----------------------------------------" << endl; cout << "---8X-----------------------------------------" << endl;
while (true) { while (true) {
pkt = ifacemgr->receive(); pkt.reset(ifacemgr->receive());
cout << "// this code is autogenerated. Do NOT edit." << endl; cout << "// this code is autogenerated. Do NOT edit." << endl;
cout << "// Received " << pkt->data_len_ << " bytes packet:" << endl; cout << "// Received " << pkt->data_len_ << " bytes packet:" << endl;
@@ -145,13 +145,11 @@ TEST_F(IfaceMgrTest, dhcp6Sniffer) {
cout << " return (pkt);" << endl; cout << " return (pkt);" << endl;
cout << "}" << endl << endl; cout << "}" << endl << endl;
delete pkt; pkt.reset();
} }
cout << "---8X-----------------------------------------" << endl; cout << "---8X-----------------------------------------" << endl;
// Never happens. Infinite loop is infinite // Never happens. Infinite loop is infinite
delete pkt;
delete ifacemgr;
} }
#endif #endif

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2011i-2013 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2011-2013 Internet Systems Consortium, Inc. ("ISC")
// //
// Permission to use, copy, modify, and/or distribute this software for any // Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above // purpose with or without fee is hereby granted, provided that the above

View File

@@ -46,7 +46,7 @@ public:
OutputBuffer outBuf_; OutputBuffer outBuf_;
}; };
// V4 is not really implemented yet. A simple test will do for now. // Basic tests for V4 functionality
TEST_F(OptionTest, v4_basic) { TEST_F(OptionTest, v4_basic) {
scoped_ptr<Option> opt; scoped_ptr<Option> opt;

View File

@@ -305,7 +305,7 @@ TEST(Pkt4Test, hwAddr) {
// type and transaction doesn't matter in this test // type and transaction doesn't matter in this test
pkt.reset(new Pkt4(DHCPOFFER, 1234)); pkt.reset(new Pkt4(DHCPOFFER, 1234));
pkt->setHWAddr(255-macLen*10, // just weird htype pkt->setHWAddr(255 - macLen * 10, // just weird htype
macLen, macLen,
mac); mac);
EXPECT_EQ(0, memcmp(expectedChaddr, &pkt->getHWAddr()->hwaddr_[0], EXPECT_EQ(0, memcmp(expectedChaddr, &pkt->getHWAddr()->hwaddr_[0],
@@ -317,7 +317,7 @@ TEST(Pkt4Test, hwAddr) {
// CHADDR starts at offset 28 in DHCP packet // CHADDR starts at offset 28 in DHCP packet
const uint8_t* ptr = const uint8_t* ptr =
static_cast<const uint8_t*>(pkt->getBuffer().getData())+28; static_cast<const uint8_t*>(pkt->getBuffer().getData()) + 28;
EXPECT_EQ(0, memcmp(ptr, expectedChaddr, Pkt4::MAX_CHADDR_LEN)); EXPECT_EQ(0, memcmp(ptr, expectedChaddr, Pkt4::MAX_CHADDR_LEN));
@@ -391,7 +391,7 @@ TEST(Pkt4Test, sname) {
// SNAME starts at offset 44 in DHCP packet // SNAME starts at offset 44 in DHCP packet
const uint8_t* ptr = const uint8_t* ptr =
static_cast<const uint8_t*>(pkt->getBuffer().getData())+44; static_cast<const uint8_t*>(pkt->getBuffer().getData()) + 44;
EXPECT_EQ(0, memcmp(ptr, sname, Pkt4::MAX_SNAME_LEN)); EXPECT_EQ(0, memcmp(ptr, sname, Pkt4::MAX_SNAME_LEN));
pkt.reset(); pkt.reset();
@@ -429,7 +429,7 @@ TEST(Pkt4Test, file) {
// FILE starts at offset 108 in DHCP packet. // FILE starts at offset 108 in DHCP packet.
const uint8_t* ptr = const uint8_t* ptr =
static_cast<const uint8_t*>(pkt->getBuffer().getData())+108; static_cast<const uint8_t*>(pkt->getBuffer().getData()) + 108;
EXPECT_EQ(0, memcmp(ptr, file, Pkt4::MAX_FILE_LEN)); EXPECT_EQ(0, memcmp(ptr, file, Pkt4::MAX_FILE_LEN));
pkt.reset(); pkt.reset();
@@ -459,9 +459,9 @@ TEST(Pkt4Test, options) {
vector<uint8_t> payload[5]; vector<uint8_t> payload[5];
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
payload[i].push_back(i*10); payload[i].push_back(i * 10);
payload[i].push_back(i*10+1); payload[i].push_back(i * 10 + 1);
payload[i].push_back(i*10+2); payload[i].push_back(i * 10 + 2);
} }
boost::shared_ptr<Option> opt1(new Option(Option::V4, 12, payload[0])); boost::shared_ptr<Option> opt1(new Option(Option::V4, 12, payload[0]));
@@ -552,35 +552,35 @@ TEST(Pkt4Test, unpackOptions) {
EXPECT_EQ(12, x->getType()); // this should be option 12 EXPECT_EQ(12, x->getType()); // this should be option 12
ASSERT_EQ(3, x->getData().size()); // it should be of length 3 ASSERT_EQ(3, x->getData().size()); // it should be of length 3
EXPECT_EQ(5, x->len()); // total option length 5 EXPECT_EQ(5, x->len()); // total option length 5
EXPECT_EQ(0, memcmp(&x->getData()[0], v4Opts+2, 3)); // data len=3 EXPECT_EQ(0, memcmp(&x->getData()[0], v4Opts + 2, 3)); // data len=3
x = pkt->getOption(14); x = pkt->getOption(14);
ASSERT_TRUE(x); // option 13 should exist ASSERT_TRUE(x); // option 13 should exist
EXPECT_EQ(14, x->getType()); // this should be option 13 EXPECT_EQ(14, x->getType()); // this should be option 13
ASSERT_EQ(3, x->getData().size()); // it should be of length 3 ASSERT_EQ(3, x->getData().size()); // it should be of length 3
EXPECT_EQ(5, x->len()); // total option length 5 EXPECT_EQ(5, x->len()); // total option length 5
EXPECT_EQ(0, memcmp(&x->getData()[0], v4Opts+7, 3)); // data len=3 EXPECT_EQ(0, memcmp(&x->getData()[0], v4Opts + 7, 3)); // data len=3
x = pkt->getOption(60); x = pkt->getOption(60);
ASSERT_TRUE(x); // option 60 should exist ASSERT_TRUE(x); // option 60 should exist
EXPECT_EQ(60, x->getType()); // this should be option 60 EXPECT_EQ(60, x->getType()); // this should be option 60
ASSERT_EQ(3, x->getData().size()); // it should be of length 3 ASSERT_EQ(3, x->getData().size()); // it should be of length 3
EXPECT_EQ(5, x->len()); // total option length 5 EXPECT_EQ(5, x->len()); // total option length 5
EXPECT_EQ(0, memcmp(&x->getData()[0], v4Opts+15, 3)); // data len=3 EXPECT_EQ(0, memcmp(&x->getData()[0], v4Opts + 15, 3)); // data len=3
x = pkt->getOption(128); x = pkt->getOption(128);
ASSERT_TRUE(x); // option 3 should exist ASSERT_TRUE(x); // option 3 should exist
EXPECT_EQ(128, x->getType()); // this should be option 254 EXPECT_EQ(128, x->getType()); // this should be option 254
ASSERT_EQ(3, x->getData().size()); // it should be of length 3 ASSERT_EQ(3, x->getData().size()); // it should be of length 3
EXPECT_EQ(5, x->len()); // total option length 5 EXPECT_EQ(5, x->len()); // total option length 5
EXPECT_EQ(0, memcmp(&x->getData()[0], v4Opts+20, 3)); // data len=3 EXPECT_EQ(0, memcmp(&x->getData()[0], v4Opts + 20, 3)); // data len=3
x = pkt->getOption(254); x = pkt->getOption(254);
ASSERT_TRUE(x); // option 3 should exist ASSERT_TRUE(x); // option 3 should exist
EXPECT_EQ(254, x->getType()); // this should be option 254 EXPECT_EQ(254, x->getType()); // this should be option 254
ASSERT_EQ(3, x->getData().size()); // it should be of length 3 ASSERT_EQ(3, x->getData().size()); // it should be of length 3
EXPECT_EQ(5, x->len()); // total option length 5 EXPECT_EQ(5, x->len()); // total option length 5
EXPECT_EQ(0, memcmp(&x->getData()[0], v4Opts+25, 3)); // data len=3 EXPECT_EQ(0, memcmp(&x->getData()[0], v4Opts + 25, 3)); // data len=3
} }
// This test verifies methods that are used for manipulating meta fields // This test verifies methods that are used for manipulating meta fields