Bitcoin Core 32.99.0
P2P Digital Currency
Loading...
Searching...
No Matches
util_check_tests.cpp
Go to the documentation of this file.
1// Copyright (c) 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 <util/check.h>
6
7#include <boost/test/unit_test.hpp>
8#include <test/util/common.h>
9
11
12namespace {
14{
16}
17} // namespace
18
20{
21 Assume(true);
22 Assert(true);
23 CHECK_NONFATAL(true);
24}
25
27{
28 // Disable aborts for easier testing here
30
31 if constexpr (G_ABORT_ON_FAILED_ASSUME) {
32 BOOST_CHECK_EXCEPTION(Assume(false), NonFatalCheckError, HasReason{"Internal bug detected: `false` check failed"});
33 } else {
35 }
36 BOOST_CHECK_EXCEPTION(CHECK_NONFATAL(false), NonFatalCheckError, HasReason{"Internal bug detected: `false` check failed"});
37 void* this_should_be_nonnull{nullptr};
38 BOOST_CHECK_EXCEPTION(Assert(this_should_be_nonnull != nullptr), NonFatalCheckError, HasReason{"Internal bug detected: `this_should_be_nonnull != nullptr` check failed"});
39}
40
42{
43 // Disable aborts for easier testing here
45
46 BOOST_CHECK_EXCEPTION(TriggerNonFatalUnreachable(), NonFatalCheckError, HasReason{"Internal bug detected: unreachable"});
47}
48
#define CHECK_NONFATAL(condition)
Identity function.
Definition check.h:115
#define NONFATAL_UNREACHABLE()
NONFATAL_UNREACHABLE() is a macro that is used to mark unreachable code.
Definition check.h:139
#define Assert(val)
Identity function.
Definition check.h:119
constexpr bool G_ABORT_ON_FAILED_ASSUME
Definition check.h:28
#define Assume(val)
Assume is the identity function.
Definition check.h:131
BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
Definition common.h:19
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EXCEPTION(HTTPHeaders{}.Read(reader), std::runtime_error, HasReason{"Empty HTTP header name"})
#define BOOST_CHECK_NO_THROW(stmt)
Definition object.cpp:27
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:82
BOOST_AUTO_TEST_CASE(check_pass)