From: Stephen Morris Date: Wed, 8 May 2013 10:54:45 +0000 (+0100) Subject: [2467] Merge branch 'master' into trac2467 X-Git-Tag: bind10-1.2.0beta1-release~474 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=315d2846dec8b2f36df1aa8ed23feddfc621a356;p=thirdparty%2Fkea.git [2467] Merge branch 'master' into trac2467 Conflicts: src/bin/dhcp4/tests/dhcp4_srv_unittest.cc src/lib/dhcp/tests/iface_mgr_unittest.cc --- 315d2846dec8b2f36df1aa8ed23feddfc621a356 diff --cc src/bin/dhcp4/tests/dhcp4_srv_unittest.cc index 46b588ada2,18e3ee369b..cabd8b7dda --- a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc @@@ -367,21 -493,29 +493,21 @@@ public TEST_F(Dhcpv4SrvTest, basic) { // Check that the base class can be instantiated - Dhcpv4Srv* srv = NULL; - ASSERT_NO_THROW({ - srv = new Dhcpv4Srv(DHCP4_SERVER_PORT + 10000); - }); - delete srv; + boost::scoped_ptr srv; + ASSERT_NO_THROW(srv.reset(new Dhcpv4Srv(DHCP4_SERVER_PORT + 10000))); + srv.reset(); // Check that the derived class can be instantiated - NakedDhcpv4Srv* naked_srv = NULL; - ASSERT_NO_THROW({ - naked_srv = new NakedDhcpv4Srv(DHCP4_SERVER_PORT + 10000); - }); + boost::scoped_ptr naked_srv; + ASSERT_NO_THROW( + naked_srv.reset(new NakedDhcpv4Srv(DHCP4_SERVER_PORT + 10000))); EXPECT_TRUE(naked_srv->getServerID()); - delete naked_srv; - ASSERT_NO_THROW({ - naked_srv = new NakedDhcpv4Srv(0); - }); + ASSERT_NO_THROW(naked_srv.reset(new NakedDhcpv4Srv(0))); EXPECT_TRUE(naked_srv->getServerID()); - - delete naked_srv; } - // Verifies that received DISCOVER can be processed correctly, + // Verifies that DISCOVER received via relay can be processed correctly, // that the OFFER message generated in response is valid and // contains necessary options. // diff --cc src/lib/dhcp/tests/iface_mgr_unittest.cc index 4c9bdbca50,31b9300086..ede7abf2d3 --- a/src/lib/dhcp/tests/iface_mgr_unittest.cc +++ b/src/lib/dhcp/tests/iface_mgr_unittest.cc @@@ -45,15 -45,63 +46,62 @@@ char LOOPBACK[BUF_SIZE] = "lo" const uint16_t PORT1 = 10547; // V6 socket const uint16_t PORT2 = 10548; // V4 socket -// On some systems measured duration of receive6() and -// receive4() appears to be shorter than select() timeout. -// called by these functions. This may be the case -// if different ime resolutions are used by these functions. -// For such cases we set the tolerance of 0.01s. +// On some systems measured duration of receive6() and receive4() appears to be +// shorter than select() timeout. This may be the case if different time +// resolutions are used by these functions. For such cases we set the +// tolerance to 0.01s. const uint32_t TIMEOUT_TOLERANCE = 10000; + /// Mock object implementing PktFilter class. It is used by + /// IfaceMgrTest::setPacketFilter to verify that IfaceMgr::setPacketFilter + /// sets this object as a handler for opening sockets. This dummy + /// class simply records that openSocket function was called by + /// the IfaceMgr as expected. + /// + /// @todo This class currently doesn't verify that send/receive functions + /// were called. In order to test it, there is a need to supply dummy + /// function performing select() on certain sockets. The system select() + /// call will fail when dummy socket descriptor is provided and thus + /// TestPktFilter::receive will never be called. The appropriate extension + /// to IfaceMgr is planned along with implementation of other "Packet + /// Filters" such as these supporting Linux Packet Filtering and + /// Berkley Packet Filtering. + class TestPktFilter : public PktFilter { + public: + + /// Constructor + TestPktFilter() + : open_socket_called_(false) { + } + + /// Pretends to open socket. Only records a call to this function. + virtual int openSocket(const Iface&, + const isc::asiolink::IOAddress&, + const uint16_t, + const bool, + const bool) { + open_socket_called_ = true; + return (1024); + } + + /// Does nothing + virtual Pkt4Ptr receive(const Iface&, + const SocketInfo&) { + return (Pkt4Ptr()); + } + + /// Does nothing + virtual int send(uint16_t, const Pkt4Ptr&) { + return (0); + } + + /// Holds the information whether openSocket was called on this + /// object after its creation. + bool open_socket_called_; + }; class NakedIfaceMgr: public IfaceMgr { - // "naked" Interface Manager, exposes internal fields + // "Naked" Interface Manager, exposes internal fields public: NakedIfaceMgr() { } IfaceCollection & getIfacesLst() { return ifaces_; } @@@ -161,10 -212,13 +209,10 @@@ TEST_F(IfaceMgrTest, basic) } TEST_F(IfaceMgrTest, ifaceClass) { - // basic tests for Iface inner class + // Basic tests for Iface inner class - IfaceMgr::Iface iface("eth5", 7); - Iface* iface = new Iface("eth5", 7); - - EXPECT_STREQ("eth5/7", iface->getFullName().c_str()); - - delete iface; ++ Iface iface("eth5", 7); + EXPECT_STREQ("eth5/7", iface.getFullName().c_str()); } // TODO: Implement getPlainMac() test as soon as interface detection @@@ -172,13 -226,13 +220,13 @@@ TEST_F(IfaceMgrTest, getIface) { cout << "Interface checks. Please ignore socket binding errors." << endl; - NakedIfaceMgr* ifacemgr = new NakedIfaceMgr(); + scoped_ptr ifacemgr(new NakedIfaceMgr()); - // interface name, ifindex + // Interface name, ifindex - IfaceMgr::Iface iface1("lo1", 100); - IfaceMgr::Iface iface2("eth9", 101); - IfaceMgr::Iface iface3("en3", 102); - IfaceMgr::Iface iface4("e1000g4", 103); + Iface iface1("lo1", 100); + Iface iface2("eth9", 101); + Iface iface3("en3", 102); + Iface iface4("e1000g4", 103); cout << "This test assumes that there are less than 100 network interfaces" << " in the tested system and there are no lo1, eth9, en3, e1000g4" << " or wifi15 interfaces present." << endl; @@@ -198,8 -252,8 +246,8 @@@ } - // check that interface can be retrieved by ifindex + // Check that interface can be retrieved by ifindex - IfaceMgr::Iface* tmp = ifacemgr->getIface(102); + Iface* tmp = ifacemgr->getIface(102); ASSERT_TRUE(tmp != NULL); EXPECT_EQ("en3", tmp->getName()); @@@ -775,8 -868,10 +855,8 @@@ TEST_F(IfaceMgrTest, socket4) // Test the Iface structure itself TEST_F(IfaceMgrTest, iface) { - scoped_ptr iface; - EXPECT_NO_THROW(iface.reset(new IfaceMgr::Iface("eth0",1))); - Iface* iface = NULL; - EXPECT_NO_THROW( - iface = new Iface("eth0",1); - ); ++ boost::scoped_ptr iface; ++ EXPECT_NO_THROW(iface.reset(new Iface("eth0",1))); EXPECT_EQ("eth0", iface->getName()); EXPECT_EQ(1, iface->getIndex()); @@@ -845,23 -942,23 +925,23 @@@ TEST_F(IfaceMgrTest, iface_methods) TEST_F(IfaceMgrTest, socketInfo) { - // check that socketinfo for IPv4 socket is functional + // Check that socketinfo for IPv4 socket is functional - IfaceMgr::SocketInfo sock1(7, IOAddress("192.0.2.56"), DHCP4_SERVER_PORT + 7); + SocketInfo sock1(7, IOAddress("192.0.2.56"), DHCP4_SERVER_PORT + 7); EXPECT_EQ(7, sock1.sockfd_); EXPECT_EQ("192.0.2.56", sock1.addr_.toText()); EXPECT_EQ(AF_INET, sock1.family_); EXPECT_EQ(DHCP4_SERVER_PORT + 7, sock1.port_); - // check that socketinfo for IPv6 socket is functional + // Check that socketinfo for IPv6 socket is functional - IfaceMgr::SocketInfo sock2(9, IOAddress("2001:db8:1::56"), DHCP4_SERVER_PORT + 9); + SocketInfo sock2(9, IOAddress("2001:db8:1::56"), DHCP4_SERVER_PORT + 9); EXPECT_EQ(9, sock2.sockfd_); EXPECT_EQ("2001:db8:1::56", sock2.addr_.toText()); EXPECT_EQ(AF_INET6, sock2.family_); EXPECT_EQ(DHCP4_SERVER_PORT + 9, sock2.port_); - // now let's test if IfaceMgr handles socket info properly - NakedIfaceMgr* ifacemgr = new NakedIfaceMgr(); + // Now let's test if IfaceMgr handles socket info properly + scoped_ptr ifacemgr(new NakedIfaceMgr()); - IfaceMgr::Iface* loopback = ifacemgr->getIface(LOOPBACK); + Iface* loopback = ifacemgr->getIface(LOOPBACK); ASSERT_TRUE(loopback); loopback->addSocket(sock1); loopback->addSocket(sock2); @@@ -1192,9 -1287,9 +1272,9 @@@ TEST_F(IfaceMgrTest, DISABLED_detectIfa EXPECT_EQ(detected->getAddresses().size(), i->getAddresses().size()); - // now compare addresses + // Now compare addresses - const IfaceMgr::AddressCollection& addrs = detected->getAddresses(); - for (IfaceMgr::AddressCollection::const_iterator addr = addrs.begin(); + const Iface::AddressCollection& addrs = detected->getAddresses(); + for (Iface::AddressCollection::const_iterator addr = addrs.begin(); addr != addrs.end(); ++addr) { bool addr_found = false;