Bitcoin Core 30.99.0
P2P Digital Currency
ipc_tests.cpp
Go to the documentation of this file.
1// Copyright (c) 2023-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <ipc/process.h>
6#include <ipc/test/ipc_test.h>
7
8#include <test/util/common.h>
10#include <boost/test/unit_test.hpp>
11
14{
17 IpcSocketTest(m_args.GetDataDirNet());
18}
19
20// Test address parsing.
21BOOST_AUTO_TEST_CASE(parse_address_test)
22{
23 std::unique_ptr<ipc::Process> process{ipc::MakeProcess()};
24 fs::path datadir{"/var/empty/notexist"};
25 auto check_notexist{[](const std::system_error& e) { return e.code() == std::errc::no_such_file_or_directory; }};
26 auto check_address{[&](std::string address, std::string expect_address, std::string expect_error) {
27 if (expect_error.empty()) {
28 BOOST_CHECK_EXCEPTION(process->connect(datadir, "test_bitcoin", address), std::system_error, check_notexist);
29 } else {
30 BOOST_CHECK_EXCEPTION(process->connect(datadir, "test_bitcoin", address), std::invalid_argument, HasReason(expect_error));
31 }
32 BOOST_CHECK_EQUAL(address, expect_address);
33 }};
34 check_address("unix", "unix:/var/empty/notexist/test_bitcoin.sock", "");
35 check_address("unix:", "unix:/var/empty/notexist/test_bitcoin.sock", "");
36 check_address("unix:path.sock", "unix:/var/empty/notexist/path.sock", "");
37 check_address("unix:0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.sock",
38 "unix:/var/empty/notexist/0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.sock",
39 "Unix address path \"/var/empty/notexist/0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.sock\" exceeded maximum socket path length");
40 check_address("invalid", "invalid", "Unrecognized address 'invalid'");
41}
42
BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
Definition: common.h:18
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
void IpcSocketTest(const fs::path &datadir)
Test ipc::Process bind() and connect() methods connecting over a unix socket.
Definition: ipc_test.cpp:140
void IpcPipeTest()
Unit test that tests execution of IPC calls without actually creating a separate process.
Definition: ipc_test.cpp:60
void IpcSocketPairTest()
Test ipc::Protocol connect() and serve() methods connecting over a socketpair.
Definition: ipc_test.cpp:120
BOOST_AUTO_TEST_CASE(ipc_tests)
Definition: ipc_tests.cpp:13
std::unique_ptr< Process > MakeProcess()
Constructor for Process interface.
Definition: process.cpp:156
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:17
Basic testing setup.
Definition: setup_common.h:64