}
/// Pretends to open socket. Only records a call to this function.
+ /// This function returns fake socket descriptor (always the same).
+ /// Note that the returned value has been selected to be unique
+ /// (because real values are rather less than 255). Values greater
+ /// than 255 are not recommended because they cause warnings to be
+ /// reported by Valgrind when invoking close() on them.
virtual int openSocket(const Iface&,
const isc::asiolink::IOAddress&,
const uint16_t,
const bool,
const bool) {
open_socket_called_ = true;
- return (1024);
+ return (255);
}
/// Does nothing
// Check that openSocket function was called.
EXPECT_TRUE(custom_packet_filter->open_socket_called_);
- // This function always returns fake socket descriptor equal to 1024.
- EXPECT_EQ(1024, socket1);
+ // This function always returns fake socket descriptor equal to 255.
+ EXPECT_EQ(255, socket1);
// Replacing current packet filter object while there are IPv4
// sockets open is not allowed!
/// its index.
class PktFilterInetTest : public ::testing::Test {
public:
- PktFilterInetTest() {
+
+ /// @brief Constructor
+ ///
+ /// This constructor initializes socket_ member to the value of 0.
+ /// Explcit initialization is performed here because some of the
+ /// tests do not initialize this value. In such cases, destructor
+ /// could invoke close() on uninitialized socket descriptor which
+ /// would result in errors being reported by Valgrind. Note that
+ /// by initializing the class member to a valid socket descriptor
+ /// value (non-negative) we avoid Valgrind warning about trying to
+ /// close the invalid socket descriptor.
+ PktFilterInetTest()
+ : socket_(0) {
// Initialize ifname_ and ifindex_.
loInit();
}
+ /// @brief Destructor
+ ///
+ /// Closes open socket (if any).
~PktFilterInetTest() {
// Cleanup after each test. This guarantees
// that the socket does not hang after a test.
/// its index.
class PktFilterLPFTest : public ::testing::Test {
public:
- PktFilterLPFTest() {
+
+ /// @brief Constructor
+ ///
+ /// This constructor initializes socket_ member to the value of 0.
+ /// Explcit initialization is performed here because some of the
+ /// tests do not initialize this value. In such cases, destructor
+ /// could invoke close() on uninitialized socket descriptor which
+ /// would result in errors being reported by Valgrind. Note that
+ /// by initializing the class member to a valid socket descriptor
+ /// value (non-negative) we avoid Valgrind warning about trying to
+ /// close the invalid socket descriptor.
+ PktFilterLPFTest()
+ : socket_(0) {
// Initialize ifname_ and ifindex_.
loInit();
}
+ /// @brief Destructor
+ ///
+ /// Closes open socket (if any).
~PktFilterLPFTest() {
// Cleanup after each test. This guarantees
// that the socket does not hang after a test.
HWAddrPtr local_hw_addr(new HWAddr(src_hw_addr, 6, 1));
ASSERT_NO_THROW(pkt->setLocalHWAddr(local_hw_addr));
- // Set invalid length (7) of the hw address.
- HWAddrPtr remote_hw_addr(new HWAddr(&std::vector<uint8_t>(1, 7)[0], 7, 1));
+ // Set invalid length (7) of the hw address. Fill it with
+ // values of 1.
+ std::vector<uint8_t> invalid_length_addr(7, 1);
+ HWAddrPtr remote_hw_addr(new HWAddr(invalid_length_addr, 1));
ASSERT_NO_THROW(pkt->setRemoteHWAddr(remote_hw_addr));
// HW address is too long, so it should fail.
EXPECT_THROW(writeEthernetHeader(pkt, buf), BadValue);