summaryrefslogtreecommitdiffstats
path: root/src/lib/asiolink/tests/tcp_endpoint_unittest.cc
blob: bd250ec6a3a1b9257b54b205f324782cd7467aac (plain)
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
// Copyright (C) 2011, 2015  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
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

#include <config.h>

#include <string>

#include <gtest/gtest.h>

#include <boost/asio.hpp>
#include <asiolink/io_address.h>
#include <asiolink/tcp_endpoint.h>

using namespace isc::asiolink;
using namespace std;

// This test checks that the endpoint can manage its own internal
// boost::asio::ip::tcp::endpoint object.

TEST(TCPEndpointTest, v4Address) {
    const string test_address("192.0.2.1");
    const unsigned short test_port = 5301;

    IOAddress address(test_address);
    TCPEndpoint endpoint(address, test_port);

    EXPECT_TRUE(address == endpoint.getAddress());
    EXPECT_EQ(test_port, endpoint.getPort());
    EXPECT_EQ(static_cast<short>(IPPROTO_TCP), endpoint.getProtocol());
    EXPECT_EQ(AF_INET, endpoint.getFamily());
}

TEST(TCPEndpointTest, v6Address) {
    const string test_address("2001:db8::1235");
    const unsigned short test_port = 5302;

    IOAddress address(test_address);
    TCPEndpoint endpoint(address, test_port);

    EXPECT_TRUE(address == endpoint.getAddress());
    EXPECT_EQ(test_port, endpoint.getPort());
    EXPECT_EQ(static_cast<short>(IPPROTO_TCP), endpoint.getProtocol());
    EXPECT_EQ(AF_INET6, endpoint.getFamily());
}