Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
test
node_warnings_tests.cpp
Go to the documentation of this file.
1
// Copyright (c) 2024-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
6
#include <
node/warnings.h
>
7
#include <
util/translation.h
>
8
9
#include <
test/util/setup_common.h
>
10
11
#include <boost/test/unit_test.hpp>
12
13
BOOST_FIXTURE_TEST_SUITE
(node_warnings_tests,
BasicTestingSetup
)
14
15
BOOST_AUTO_TEST_CASE
(warnings)
16
{
17
node::Warnings
warnings;
18
// On pre-release builds, a warning is generated automatically
19
warnings.
Unset
(
node::Warning::PRE_RELEASE_TEST_BUILD
);
20
21
// For these tests, we don't care what the exact warnings are, so
22
// just refer to them as warning_1 and warning_2
23
const
auto
warning_1{
node::Warning::CLOCK_OUT_OF_SYNC
};
24
const
auto
warning_2{
node::Warning::FATAL_INTERNAL_ERROR
};
25
26
// Ensure we start without any warnings
27
BOOST_CHECK
(warnings.GetMessages().size() == 0);
28
// Add two warnings
29
BOOST_CHECK
(warnings.Set(warning_1,
_
(
"warning 1"
)));
30
BOOST_CHECK
(warnings.Set(warning_2,
_
(
"warning 2"
)));
31
// Unset the second one
32
BOOST_CHECK
(warnings.Unset(warning_2));
33
// Since it's already been unset, this should return false
34
BOOST_CHECK
(!warnings.Unset(warning_2));
35
// We should now be able to set w2 again
36
BOOST_CHECK
(warnings.Set(warning_2,
_
(
"warning 2 - revision 1"
)));
37
// Setting w2 again should return false since it's already set
38
BOOST_CHECK
(!warnings.Set(warning_2,
_
(
"warning 2 - revision 2"
)));
39
40
// Verify messages are correct
41
const
auto
messages{warnings.GetMessages()};
42
BOOST_CHECK
(messages.size() == 2);
43
BOOST_CHECK
(messages[0].original ==
"warning 1"
);
44
BOOST_CHECK
(messages[1].original ==
"warning 2 - revision 1"
);
45
46
// Clearing all warnings should also clear all messages
47
BOOST_CHECK
(warnings.Unset(warning_1));
48
BOOST_CHECK
(warnings.Unset(warning_2));
49
BOOST_CHECK
(warnings.GetMessages().size() == 0);
50
}
51
52
BOOST_AUTO_TEST_SUITE_END
()
node::Warnings
Manages warning messages within a node.
Definition
warnings.h:40
node::Warnings::Unset
bool Unset(warning_type id) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Unset a warning message.
Definition
warnings.cpp:36
BOOST_FIXTURE_TEST_SUITE
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(ipc_tests)
Definition
ipc_tests.cpp:13
node::Warning::CLOCK_OUT_OF_SYNC
@ CLOCK_OUT_OF_SYNC
Definition
warnings.h:24
node::Warning::FATAL_INTERNAL_ERROR
@ FATAL_INTERNAL_ERROR
Definition
warnings.h:26
node::Warning::PRE_RELEASE_TEST_BUILD
@ PRE_RELEASE_TEST_BUILD
Definition
warnings.h:25
BOOST_CHECK
#define BOOST_CHECK(expr)
Definition
object.cpp:16
setup_common.h
BasicTestingSetup
Basic testing setup.
Definition
setup_common.h:64
translation.h
_
consteval auto _(util::TranslatedLiteral str)
Definition
translation.h:79
warnings.h
Generated on
for Bitcoin Core by
1.17.0