Bitcoin Core 28.99.0
P2P Digital Currency
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
10
11#include <boost/test/unit_test.hpp>
12
14
16{
17 node::Warnings warnings;
18 // On pre-release builds, a warning is generated automatically
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
Manages warning messages within a node.
Definition: warnings.h:40
bool Unset(warning_type id) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Unset a warning message.
Definition: warnings.cpp:36
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(warnings)
#define BOOST_CHECK(expr)
Definition: object.cpp:17
Basic testing setup.
Definition: setup_common.h:63
bilingual_str _(ConstevalStringLiteral str)
Translation function.
Definition: translation.h:80