1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright (C) 2022-2024 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Kea Hooks Basic
// Commercial End User License Agreement v2.0. See COPYING file in the premium/
// directory.

/// @file This file contains tests which verify lease query connections.

#include <config.h>

#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <testutils/log_utils.h>
#include <lease_query_connection.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <lease_query_log.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <gtest/gtest.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

using namespace std;
using namespace isc;
using namespace isc::asiolink;
using namespace isc::dhcp;
using namespace isc::lease_query;
using namespace isc::tcp;
using namespace isc::util;

namespace {

/// @brief Test timeout (ms).
const long IDLE_TIMEOUT = 10000;

/// @brief Test derivation of LeaseQueryConnection.
class TestLeaseQueryConnection : public LeaseQueryConnection {
public:

    /// @brief Constructor.
    TestLeaseQueryConnection(const IOServicePtr& io_service,
                             TcpConnectionPool& connection_pool,
                             const long idle_timeout,
                             const uint16_t family,
                             const size_t max_concurrent_queries = 20,
                             const size_t read_max = 32768)
        : LeaseQueryConnection(io_service,
                               TcpConnectionAcceptorPtr(),
                               TlsContextPtr(),
                               connection_pool,
                               0,
                               0,
                               idle_timeout,
                               family,
                               max_concurrent_queries,
                               read_max) {
    }

    /// @brief Destructor.
    virtual ~TestLeaseQueryConnection() {
    }

    /// @brief Redefine sendNextResponse to do nothing.
    virtual void sendNextResponse() {
    }

    /// @brief Make the list of in-process queries visible.
    using LeaseQueryConnection::running_queries_;

    /// @brief Make the queue of queries waiting to enter processing visible.
    using LeaseQueryConnection::pending_queries_;

    /// @brief Make the list of responses waiting to be sent visible.
    using LeaseQueryConnection::responses_;

    /// @brief Make the mutex used to lock during responses access visible.
    using LeaseQueryConnection::responses_mutex_;
};

/// @brief Type of pointers to TestLeaseQueryConnection.
typedef boost::shared_ptr<TestLeaseQueryConnection> TestLeaseQueryConnectionPtr;

/// @brief Type of weak pointers to TestLeaseQueryConnection.
typedef boost::weak_ptr<TestLeaseQueryConnection> TestLeaseQueryConnectionWPtr;

/// @brief Test fixture class for lease query connections.
class LeaseQueryConnectionTest : public test::LogContentTest {
public:
    /// @brief Path name of server's duid file.
    static const string duid_file_;

    /// @brief Constructor.
    LeaseQueryConnectionTest() {
        CfgMgr::instance().clear();
        io_service_.reset(new IOService());
    }

    /// @brief Destructor.
    ~LeaseQueryConnectionTest() {
        // Check logs.
        EXPECT_TRUE(checkFile());

        LeaseMgrFactory::destroy();
        CfgMgr::instance().clear();
        io_service_.reset();
        static_cast<void>(remove(duid_file_.c_str()));
    }

    /// @brief I/O service.
    IOServicePtr io_service_;

    /// @brief Lease query connection pool.
    TcpConnectionPool connection_pool_;
};

/// @brief Path name for server-id generation.
const string LeaseQueryConnectionTest::duid_file_ =
    string(TEST_DATA_BUILDDIR) + string("/lq6-duid");

/// @brief Verify construction (v4).
TEST_F(LeaseQueryConnectionTest, constructor4) {<--- syntax error
    TestLeaseQueryConnectionPtr conn;
    ASSERT_NO_THROW(conn.reset(new TestLeaseQueryConnection(io_service_,
                                                            connection_pool_,
                                                            IDLE_TIMEOUT,
                                                            AF_INET)));
    ASSERT_TRUE(conn);
    string log1 = "DHCPSRV_CFGMGR_CFG_DHCP_DDNS Setting DHCP-DDNS";
    log1 += " configuration to: DHCP-DDNS updates disabled";
    addString(log1);
}

/// @brief Verify construction (v6).
TEST_F(LeaseQueryConnectionTest, constructor6) {
    TestLeaseQueryConnectionPtr conn;
    ASSERT_NO_THROW(conn.reset(new TestLeaseQueryConnection(io_service_,
                                                            connection_pool_,
                                                            IDLE_TIMEOUT,
                                                            AF_INET6)));
    ASSERT_TRUE(conn);
    string log1 = "DHCPSRV_CFGMGR_CFG_DHCP_DDNS Setting DHCP-DDNS";
    log1 += " configuration to: DHCP-DDNS updates disabled";
    addString(log1);
}

} // end of anonymous namespace