OpenVPN 3 Core Library
Loading...
Searching...
No Matches
test_addrlist.cpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2024- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12#include "test_common.hpp"
13#include "test_generators.hpp"
14
15#include <set>
16#include <vector>
17
19
20RC_GTEST_PROP(AddrList, AddMarksAddressAsExisting, ())
21{
22 openvpn::IP::AddrList address_list;
23 const auto address = *rc::genIPAddr();
24 address_list.add(address);
25 RC_ASSERT(address_list.exists(address));
26}
27
28RC_GTEST_PROP(AddrList, AddIsIdempotent, ())
29{
31 const auto addr = *rc::genIPAddr();
33 list.add(addr);
34 RC_ASSERT(list.size() == 1U);
36}
37
38RC_GTEST_PROP(AddrList, AddDistinctAddressesKeepsUniqueCount, ())
39{
40 const auto addrs = *rc::gen::container<std::vector<openvpn::IP::Addr>>(rc::genIPAddr());
41 const std::set unique_addrs(addrs.begin(), addrs.end());
43 for (const auto &addr : addrs)
44 {
45 list.add(addr);
46 }
47 RC_ASSERT(list.size() == unique_addrs.size());
48}
49
50RC_GTEST_PROP(AddrList, ExistsMatchesMembership, ())
51{
52 const auto addrs = *rc::gen::container<std::vector<openvpn::IP::Addr>>(rc::genIPAddr());
53 const std::set unique_addrs(addrs.begin(), addrs.end());
55 for (const auto &addr : addrs)
56 {
57 list.add(addr);
58 }
59 const auto probe = *rc::gen::oneOf(rc::gen::elementOf(unique_addrs), rc::genIPAddr());
60 const bool expected = unique_addrs.contains(probe);
62}
bool exists(const Addr &a) const
Definition addrlist.hpp:34
void add(const Addr &a)
Definition addrlist.hpp:28
auto genIPAddr() -> Gen< openvpn::IP::Addr >
RC_ASSERT(address_list.exists(address))
const auto addr
const std::set unique_addrs(addrs.begin(), addrs.end())
const bool expected
openvpn::IP::AddrList list
const auto address
const auto probe