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