Bitcoin Core 28.99.0
P2P Digital Currency
ipc_tests.cpp
Go to the documentation of this file.
1// Copyright (c) 2023 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 <test/ipc_test.h>
7
9#include <boost/test/unit_test.hpp>
10
13{
16 IpcSocketTest(m_args.GetDataDirNet());
17}
18
19// Test address parsing.
20BOOST_AUTO_TEST_CASE(parse_address_test)
21{
22 std::unique_ptr<ipc::Process> process{ipc::MakeProcess()};
23 fs::path datadir{"/var/empty/notexist"};
24 auto check_notexist{[](const std::system_error& e) { return e.code() == std::errc::no_such_file_or_directory; }};
25 auto check_address{[&](std::string address, std::string expect_address, std::string expect_error) {
26 if (expect_error.empty()) {
27 BOOST_CHECK_EXCEPTION(process->connect(datadir, "test_bitcoin", address), std::system_error, check_notexist);
28 } else {
29 BOOST_CHECK_EXCEPTION(process->connect(datadir, "test_bitcoin", address), std::invalid_argument, HasReason(expect_error));
30 }
31 BOOST_CHECK_EQUAL(address, expect_address);
32 }};
33 check_address("unix", "unix:/var/empty/notexist/test_bitcoin.sock", "");
34 check_address("unix:", "unix:/var/empty/notexist/test_bitcoin.sock", "");
35 check_address("unix:path.sock", "unix:/var/empty/notexist/path.sock", "");
36 check_address("unix:0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.sock",
37 "unix:/var/empty/notexist/0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.sock",
38 "Unix address path \"/var/empty/notexist/0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.sock\" exceeded maximum socket path length");
39 check_address("invalid", "invalid", "Unrecognized address 'invalid'");
40}
41
BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
Definition: setup_common.h:295
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:33
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:150
void IpcPipeTest()
Unit test that tests execution of IPC calls without actually creating a separate process.
Definition: ipc_test.cpp:54
void IpcSocketPairTest()
Test ipc::Protocol connect() and serve() methods connecting over a socketpair.
Definition: ipc_test.cpp:130
BOOST_AUTO_TEST_CASE(ipc_tests)
Definition: ipc_tests.cpp:12
std::unique_ptr< Process > MakeProcess()
Constructor for Process interface.
Definition: process.cpp:154
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
Basic testing setup.
Definition: setup_common.h:63