mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-03 15:35:17 +00:00
[2467] Removed "raw" pointers from b10-dhcp4/6 tests
This commit is contained in:
@@ -25,7 +25,10 @@
|
|||||||
#include <dhcp/option_int.h>
|
#include <dhcp/option_int.h>
|
||||||
#include <dhcpsrv/subnet.h>
|
#include <dhcpsrv/subnet.h>
|
||||||
#include <dhcpsrv/cfgmgr.h>
|
#include <dhcpsrv/cfgmgr.h>
|
||||||
|
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
|
#include <boost/scoped_ptr.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -47,7 +50,7 @@ public:
|
|||||||
// Open port 0 means to not do anything at all. We don't want to
|
// Open port 0 means to not do anything at all. We don't want to
|
||||||
// deal with sockets here, just check if configuration handling
|
// deal with sockets here, just check if configuration handling
|
||||||
// is sane.
|
// is sane.
|
||||||
srv_ = new Dhcpv4Srv(0);
|
srv_.reset(new Dhcpv4Srv(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks if global parameter of name have expected_value
|
// Checks if global parameter of name have expected_value
|
||||||
@@ -73,7 +76,6 @@ public:
|
|||||||
|
|
||||||
~Dhcp4ParserTest() {
|
~Dhcp4ParserTest() {
|
||||||
resetConfiguration();
|
resetConfiguration();
|
||||||
delete srv_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Create the simple configuration with single option.
|
/// @brief Create the simple configuration with single option.
|
||||||
@@ -278,7 +280,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Dhcpv4Srv* srv_;
|
boost::scoped_ptr<Dhcpv4Srv> srv_;
|
||||||
|
|
||||||
int rcode_;
|
int rcode_;
|
||||||
ConstElementPtr comment_;
|
ConstElementPtr comment_;
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
|
// Copyright (C) 2012-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
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <dhcp/dhcp4.h>
|
#include <dhcp/dhcp4.h>
|
||||||
#include <dhcp4/ctrl_dhcp4_srv.h>
|
#include <dhcp4/ctrl_dhcp4_srv.h>
|
||||||
|
|
||||||
|
#include <boost/scoped_ptr.hpp>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@@ -36,7 +37,7 @@ using namespace isc::config;
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class NakedControlledDhcpv4Srv: public ControlledDhcpv4Srv {
|
class NakedControlledDhcpv4Srv: public ControlledDhcpv4Srv {
|
||||||
// "naked" DHCPv4 server, exposes internal fields
|
// "Naked" DHCPv4 server, exposes internal fields
|
||||||
public:
|
public:
|
||||||
NakedControlledDhcpv4Srv():ControlledDhcpv4Srv(DHCP4_SERVER_PORT + 10000) { }
|
NakedControlledDhcpv4Srv():ControlledDhcpv4Srv(DHCP4_SERVER_PORT + 10000) { }
|
||||||
};
|
};
|
||||||
@@ -52,21 +53,21 @@ public:
|
|||||||
|
|
||||||
TEST_F(CtrlDhcpv4SrvTest, commands) {
|
TEST_F(CtrlDhcpv4SrvTest, commands) {
|
||||||
|
|
||||||
ControlledDhcpv4Srv* srv = NULL;
|
boost::scoped_ptr<ControlledDhcpv4Srv> srv;
|
||||||
ASSERT_NO_THROW({
|
ASSERT_NO_THROW(
|
||||||
srv = new ControlledDhcpv4Srv(DHCP4_SERVER_PORT + 10000);
|
srv.reset(new ControlledDhcpv4Srv(DHCP4_SERVER_PORT + 10000))
|
||||||
});
|
);
|
||||||
|
|
||||||
// use empty parameters list
|
// Use empty parameters list
|
||||||
ElementPtr params(new isc::data::MapElement());
|
ElementPtr params(new isc::data::MapElement());
|
||||||
int rcode = -1;
|
int rcode = -1;
|
||||||
|
|
||||||
// case 1: send bogus command
|
// Case 1: send bogus command
|
||||||
ConstElementPtr result = ControlledDhcpv4Srv::execDhcpv4ServerCommand("blah", params);
|
ConstElementPtr result = ControlledDhcpv4Srv::execDhcpv4ServerCommand("blah", params);
|
||||||
ConstElementPtr comment = parseAnswer(rcode, result);
|
ConstElementPtr comment = parseAnswer(rcode, result);
|
||||||
EXPECT_EQ(1, rcode); // expect failure (no such command as blah)
|
EXPECT_EQ(1, rcode); // expect failure (no such command as blah)
|
||||||
|
|
||||||
// case 2: send shutdown command without any parameters
|
// Case 2: send shutdown command without any parameters
|
||||||
result = ControlledDhcpv4Srv::execDhcpv4ServerCommand("shutdown", params);
|
result = ControlledDhcpv4Srv::execDhcpv4ServerCommand("shutdown", params);
|
||||||
comment = parseAnswer(rcode, result);
|
comment = parseAnswer(rcode, result);
|
||||||
EXPECT_EQ(0, rcode); // expect success
|
EXPECT_EQ(0, rcode); // expect success
|
||||||
@@ -75,13 +76,10 @@ TEST_F(CtrlDhcpv4SrvTest, commands) {
|
|||||||
ConstElementPtr x(new isc::data::IntElement(pid));
|
ConstElementPtr x(new isc::data::IntElement(pid));
|
||||||
params->set("pid", x);
|
params->set("pid", x);
|
||||||
|
|
||||||
// case 3: send shutdown command with 1 parameter: pid
|
// Case 3: send shutdown command with 1 parameter: pid
|
||||||
result = ControlledDhcpv4Srv::execDhcpv4ServerCommand("shutdown", params);
|
result = ControlledDhcpv4Srv::execDhcpv4ServerCommand("shutdown", params);
|
||||||
comment = parseAnswer(rcode, result);
|
comment = parseAnswer(rcode, result);
|
||||||
EXPECT_EQ(0, rcode); // expect success
|
EXPECT_EQ(0, rcode); // expect success
|
||||||
|
|
||||||
|
|
||||||
delete srv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end of anonymous namespace
|
} // End of anonymous namespace
|
||||||
|
@@ -29,6 +29,8 @@
|
|||||||
#include <dhcpsrv/utils.h>
|
#include <dhcpsrv/utils.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <boost/scoped_ptr.hpp>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -367,26 +369,18 @@ public:
|
|||||||
TEST_F(Dhcpv4SrvTest, basic) {
|
TEST_F(Dhcpv4SrvTest, basic) {
|
||||||
|
|
||||||
// Check that the base class can be instantiated
|
// Check that the base class can be instantiated
|
||||||
Dhcpv4Srv* srv = NULL;
|
boost::scoped_ptr<Dhcpv4Srv> srv;
|
||||||
ASSERT_NO_THROW({
|
ASSERT_NO_THROW(srv.reset(new Dhcpv4Srv(DHCP4_SERVER_PORT + 10000)));
|
||||||
srv = new Dhcpv4Srv(DHCP4_SERVER_PORT + 10000);
|
srv.reset();
|
||||||
});
|
|
||||||
delete srv;
|
|
||||||
|
|
||||||
// Check that the derived class can be instantiated
|
// Check that the derived class can be instantiated
|
||||||
NakedDhcpv4Srv* naked_srv = NULL;
|
boost::scoped_ptr<NakedDhcpv4Srv> naked_srv;
|
||||||
ASSERT_NO_THROW({
|
ASSERT_NO_THROW(
|
||||||
naked_srv = new NakedDhcpv4Srv(DHCP4_SERVER_PORT + 10000);
|
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);
|
|
||||||
});
|
|
||||||
EXPECT_TRUE(naked_srv->getServerID());
|
EXPECT_TRUE(naked_srv->getServerID());
|
||||||
|
|
||||||
delete naked_srv;
|
ASSERT_NO_THROW(naked_srv.reset(new NakedDhcpv4Srv(0)));
|
||||||
|
EXPECT_TRUE(naked_srv->getServerID());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verifies that received DISCOVER can be processed correctly,
|
// Verifies that received DISCOVER can be processed correctly,
|
||||||
@@ -398,7 +392,7 @@ TEST_F(Dhcpv4SrvTest, basic) {
|
|||||||
// engine. See DiscoverBasic, DiscoverHint, DiscoverNoClientId
|
// engine. See DiscoverBasic, DiscoverHint, DiscoverNoClientId
|
||||||
// and DiscoverInvalidHint.
|
// and DiscoverInvalidHint.
|
||||||
TEST_F(Dhcpv4SrvTest, processDiscover) {
|
TEST_F(Dhcpv4SrvTest, processDiscover) {
|
||||||
NakedDhcpv4Srv* srv = new NakedDhcpv4Srv(0);
|
boost::scoped_ptr<NakedDhcpv4Srv> srv(new NakedDhcpv4Srv(0));
|
||||||
vector<uint8_t> mac(6);
|
vector<uint8_t> mac(6);
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
mac[i] = 255 - i;
|
mac[i] = 255 - i;
|
||||||
@@ -492,8 +486,6 @@ TEST_F(Dhcpv4SrvTest, processDiscover) {
|
|||||||
|
|
||||||
// Check that the requested options are returned.
|
// Check that the requested options are returned.
|
||||||
optionsCheck(offer);
|
optionsCheck(offer);
|
||||||
|
|
||||||
delete srv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verifies that received REQUEST can be processed correctly,
|
// Verifies that received REQUEST can be processed correctly,
|
||||||
@@ -504,10 +496,10 @@ TEST_F(Dhcpv4SrvTest, processDiscover) {
|
|||||||
// are other tests that verify correctness of the allocation
|
// are other tests that verify correctness of the allocation
|
||||||
// engine. See RequestBasic.
|
// engine. See RequestBasic.
|
||||||
TEST_F(Dhcpv4SrvTest, processRequest) {
|
TEST_F(Dhcpv4SrvTest, processRequest) {
|
||||||
NakedDhcpv4Srv* srv = new NakedDhcpv4Srv(0);
|
boost::scoped_ptr<NakedDhcpv4Srv> srv(new NakedDhcpv4Srv(0));
|
||||||
vector<uint8_t> mac(6);
|
vector<uint8_t> mac(6);
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
mac[i] = i*10;
|
mac[i] = i * 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::shared_ptr<Pkt4> req(new Pkt4(DHCPREQUEST, 1234));
|
boost::shared_ptr<Pkt4> req(new Pkt4(DHCPREQUEST, 1234));
|
||||||
@@ -592,53 +584,36 @@ TEST_F(Dhcpv4SrvTest, processRequest) {
|
|||||||
|
|
||||||
// Check that the requested options are returned.
|
// Check that the requested options are returned.
|
||||||
optionsCheck(ack);
|
optionsCheck(ack);
|
||||||
|
|
||||||
delete srv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Dhcpv4SrvTest, processRelease) {
|
TEST_F(Dhcpv4SrvTest, processRelease) {
|
||||||
NakedDhcpv4Srv* srv = new NakedDhcpv4Srv();
|
NakedDhcpv4Srv srv;
|
||||||
|
|
||||||
boost::shared_ptr<Pkt4> pkt(new Pkt4(DHCPRELEASE, 1234));
|
boost::shared_ptr<Pkt4> pkt(new Pkt4(DHCPRELEASE, 1234));
|
||||||
|
|
||||||
// Should not throw
|
// Should not throw
|
||||||
EXPECT_NO_THROW(
|
EXPECT_NO_THROW(srv.processRelease(pkt));
|
||||||
srv->processRelease(pkt);
|
|
||||||
);
|
|
||||||
|
|
||||||
delete srv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Dhcpv4SrvTest, processDecline) {
|
TEST_F(Dhcpv4SrvTest, processDecline) {
|
||||||
NakedDhcpv4Srv* srv = new NakedDhcpv4Srv();
|
NakedDhcpv4Srv srv;
|
||||||
|
|
||||||
boost::shared_ptr<Pkt4> pkt(new Pkt4(DHCPDECLINE, 1234));
|
boost::shared_ptr<Pkt4> pkt(new Pkt4(DHCPDECLINE, 1234));
|
||||||
|
|
||||||
// Should not throw
|
// Should not throw
|
||||||
EXPECT_NO_THROW(
|
EXPECT_NO_THROW(srv.processDecline(pkt));
|
||||||
srv->processDecline(pkt);
|
|
||||||
);
|
|
||||||
|
|
||||||
delete srv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Dhcpv4SrvTest, processInform) {
|
TEST_F(Dhcpv4SrvTest, processInform) {
|
||||||
NakedDhcpv4Srv* srv = new NakedDhcpv4Srv();
|
NakedDhcpv4Srv srv;
|
||||||
|
|
||||||
boost::shared_ptr<Pkt4> pkt(new Pkt4(DHCPINFORM, 1234));
|
boost::shared_ptr<Pkt4> pkt(new Pkt4(DHCPINFORM, 1234));
|
||||||
|
|
||||||
// Should not throw
|
// Should not throw
|
||||||
EXPECT_NO_THROW(
|
EXPECT_NO_THROW(srv.processInform(pkt));
|
||||||
srv->processInform(pkt);
|
|
||||||
);
|
|
||||||
|
|
||||||
// Should return something
|
// Should return something
|
||||||
EXPECT_TRUE(srv->processInform(pkt));
|
EXPECT_TRUE(srv.processInform(pkt));
|
||||||
|
|
||||||
// @todo Implement more reasonable tests before starting
|
// @todo Implement more reasonable tests before starting
|
||||||
// work on processSomething() method.
|
// work on processSomething() method.
|
||||||
|
|
||||||
delete srv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Dhcpv4SrvTest, serverReceivedPacketName) {
|
TEST_F(Dhcpv4SrvTest, serverReceivedPacketName) {
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
|
// Copyright (C) 2012-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
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <dhcp6/ctrl_dhcp6_srv.h>
|
#include <dhcp6/ctrl_dhcp6_srv.h>
|
||||||
#include <config/ccsession.h>
|
#include <config/ccsession.h>
|
||||||
|
|
||||||
|
#include <boost/scoped_ptr.hpp>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -52,12 +53,12 @@ public:
|
|||||||
|
|
||||||
TEST_F(CtrlDhcpv6SrvTest, commands) {
|
TEST_F(CtrlDhcpv6SrvTest, commands) {
|
||||||
|
|
||||||
ControlledDhcpv6Srv* srv = NULL;
|
boost::scoped_ptr<ControlledDhcpv6Srv> srv;
|
||||||
ASSERT_NO_THROW({
|
ASSERT_NO_THROW(
|
||||||
srv = new ControlledDhcpv6Srv(DHCP6_SERVER_PORT + 10000);
|
srv.reset(new ControlledDhcpv6Srv(DHCP6_SERVER_PORT + 10000))
|
||||||
});
|
);
|
||||||
|
|
||||||
// use empty parameters list
|
// Use empty parameters list
|
||||||
ElementPtr params(new isc::data::MapElement());
|
ElementPtr params(new isc::data::MapElement());
|
||||||
int rcode = -1;
|
int rcode = -1;
|
||||||
|
|
||||||
@@ -78,10 +79,7 @@ TEST_F(CtrlDhcpv6SrvTest, commands) {
|
|||||||
// case 3: send shutdown command with 1 parameter: pid
|
// case 3: send shutdown command with 1 parameter: pid
|
||||||
result = ControlledDhcpv6Srv::execDhcpv6ServerCommand("shutdown", params);
|
result = ControlledDhcpv6Srv::execDhcpv6ServerCommand("shutdown", params);
|
||||||
comment = parseAnswer(rcode, result);
|
comment = parseAnswer(rcode, result);
|
||||||
EXPECT_EQ(0, rcode); // expect success
|
EXPECT_EQ(0, rcode); // Expect success
|
||||||
|
|
||||||
|
|
||||||
delete srv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end of anonymous namespace
|
} // end of anonymous namespace
|
||||||
|
Reference in New Issue
Block a user