LCOV - code coverage report
Current view: top level - src/test - util_tests.cpp (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 99.4 % 1330 1322
Test Date: 2025-02-22 05:08:25 Functions: 100.0 % 128 128
Branches: 50.1 % 7220 3618

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2011-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 <clientversion.h>
       6                 :             : #include <common/signmessage.h> // For MessageSign(), MessageVerify(), MESSAGE_MAGIC
       7                 :             : #include <hash.h> // For Hash()
       8                 :             : #include <key.h>  // For CKey
       9                 :             : #include <script/parsing.h>
      10                 :             : #include <span.h>
      11                 :             : #include <sync.h>
      12                 :             : #include <test/util/random.h>
      13                 :             : #include <test/util/setup_common.h>
      14                 :             : #include <uint256.h>
      15                 :             : #include <util/bitdeque.h>
      16                 :             : #include <util/byte_units.h>
      17                 :             : #include <util/fs.h>
      18                 :             : #include <util/fs_helpers.h>
      19                 :             : #include <util/moneystr.h>
      20                 :             : #include <util/overflow.h>
      21                 :             : #include <util/readwritefile.h>
      22                 :             : #include <util/strencodings.h>
      23                 :             : #include <util/string.h>
      24                 :             : #include <util/time.h>
      25                 :             : #include <util/vector.h>
      26                 :             : 
      27                 :             : #include <array>
      28                 :             : #include <cmath>
      29                 :             : #include <fstream>
      30                 :             : #include <limits>
      31                 :             : #include <map>
      32                 :             : #include <optional>
      33                 :             : #include <stdint.h>
      34                 :             : #include <string.h>
      35                 :             : #include <thread>
      36                 :             : #include <univalue.h>
      37                 :             : #include <utility>
      38                 :             : #include <vector>
      39                 :             : 
      40                 :             : #include <sys/types.h>
      41                 :             : 
      42                 :             : #ifndef WIN32
      43                 :             : #include <signal.h>
      44                 :             : #include <sys/wait.h>
      45                 :             : #endif
      46                 :             : 
      47                 :             : #include <boost/test/unit_test.hpp>
      48                 :             : 
      49                 :             : using namespace std::literals;
      50                 :             : using namespace util::hex_literals;
      51                 :             : using util::ConstevalHexDigit;
      52                 :             : using util::Join;
      53                 :             : using util::RemovePrefix;
      54                 :             : using util::RemovePrefixView;
      55                 :             : using util::ReplaceAll;
      56                 :             : using util::Split;
      57                 :             : using util::SplitString;
      58                 :             : using util::TrimString;
      59                 :             : using util::TrimStringView;
      60                 :             : 
      61                 :             : static const std::string STRING_WITH_EMBEDDED_NULL_CHAR{"1"s "\0" "1"s};
      62                 :             : 
      63                 :             : /* defined in logging.cpp */
      64                 :             : namespace BCLog {
      65                 :             :     std::string LogEscapeMessage(std::string_view str);
      66                 :             : }
      67                 :             : 
      68                 :             : BOOST_FIXTURE_TEST_SUITE(util_tests, BasicTestingSetup)
      69                 :             : 
      70                 :             : namespace {
      71                 :             : class NoCopyOrMove
      72                 :             : {
      73                 :             : public:
      74                 :             :     int i;
      75                 :           2 :     explicit NoCopyOrMove(int i) : i{i} { }
      76                 :             : 
      77                 :             :     NoCopyOrMove() = delete;
      78                 :             :     NoCopyOrMove(const NoCopyOrMove&) = delete;
      79                 :             :     NoCopyOrMove(NoCopyOrMove&&) = delete;
      80                 :             :     NoCopyOrMove& operator=(const NoCopyOrMove&) = delete;
      81                 :             :     NoCopyOrMove& operator=(NoCopyOrMove&&) = delete;
      82                 :             : 
      83         [ -  + ]:           6 :     operator bool() const { return i != 0; }
      84                 :             : 
      85                 :           2 :     int get_ip1() { return i + 1; }
      86                 :           4 :     bool test()
      87                 :             :     {
      88                 :             :         // Check that Assume can be used within a lambda and still call methods
      89                 :           4 :         [&]() { Assume(get_ip1()); }();
      90                 :           4 :         return Assume(get_ip1() != 5);
      91                 :             :     }
      92                 :             : };
      93                 :             : } // namespace
      94                 :             : 
      95   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(util_check)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
      96                 :             : {
      97                 :             :     // Check that Assert can forward
      98         [ +  - ]:           2 :     const std::unique_ptr<int> p_two = Assert(std::make_unique<int>(2));
      99                 :             :     // Check that Assert works on lvalues and rvalues
     100   [ +  -  +  - ]:           2 :     const int two = *Assert(p_two);
     101         [ +  - ]:           2 :     Assert(two == 2);
     102         [ +  - ]:           2 :     Assert(true);
     103                 :             :     // Check that Assume can be used as unary expression
     104                 :           2 :     const bool result{Assume(two == 2)};
     105         [ +  - ]:           2 :     Assert(result);
     106                 :             : 
     107                 :             :     // Check that Assert doesn't require copy/move
     108                 :           2 :     NoCopyOrMove x{9};
     109         [ +  - ]:           2 :     Assert(x).i += 3;
     110         [ +  - ]:           2 :     Assert(x).test();
     111                 :             : 
     112                 :             :     // Check nested Asserts
     113   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(Assert((Assert(x).test() ? 3 : 0)), 3);
          -  +  +  -  +  
                      - ]
     114                 :             : 
     115                 :             :     // Check -Wdangling-gsl does not trigger when copying the int. (It would
     116                 :             :     // trigger on "const int&")
     117                 :           2 :     const int nine{*Assert(std::optional<int>{9})};
     118   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(9, nine);
     119                 :           2 : }
     120                 :             : 
     121   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(util_criticalsection)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     122                 :             : {
     123                 :           2 :     RecursiveMutex cs;
     124                 :             : 
     125                 :           4 :     do {
     126                 :           2 :         LOCK(cs);
     127         [ +  - ]:           2 :         break;
     128                 :             : 
     129                 :             :         BOOST_ERROR("break was swallowed!");
     130                 :           2 :     } while(0);
     131                 :             : 
     132                 :           2 :     do {
     133                 :           2 :         TRY_LOCK(cs, lockTest);
     134         [ +  - ]:           2 :         if (lockTest) {
     135   [ +  -  +  -  :           4 :             BOOST_CHECK(true); // Needed to suppress "Test case [...] did not check any assertions"
                   +  - ]
     136         [ +  - ]:           2 :             break;
     137                 :             :         }
     138                 :             : 
     139   [ #  #  #  #  :           0 :         BOOST_ERROR("break was swallowed!");
                   #  # ]
     140                 :           2 :     } while(0);
     141                 :           2 : }
     142                 :             : 
     143                 :             : constexpr char HEX_PARSE_INPUT[] = "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f";
     144                 :             : constexpr uint8_t HEX_PARSE_OUTPUT[] = {
     145                 :             :     0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, 0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7,
     146                 :             :     0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, 0xa6, 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde,
     147                 :             :     0xb6, 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, 0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12,
     148                 :             :     0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, 0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d,
     149                 :             :     0x5f
     150                 :             : };
     151                 :             : static_assert((sizeof(HEX_PARSE_INPUT) - 1) == 2 * sizeof(HEX_PARSE_OUTPUT));
     152   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(parse_hex)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     153                 :             : {
     154                 :           2 :     std::vector<unsigned char> result;
     155                 :             : 
     156                 :             :     // Basic test vector
     157         [ +  - ]:           2 :     std::vector<unsigned char> expected(std::begin(HEX_PARSE_OUTPUT), std::end(HEX_PARSE_OUTPUT));
     158                 :           2 :     constexpr std::array<std::byte, 65> hex_literal_array{operator""_hex<util::detail::Hex(HEX_PARSE_INPUT)>()};
     159                 :           2 :     auto hex_literal_span{MakeUCharSpan(hex_literal_array)};
     160   [ +  -  +  -  :           4 :     BOOST_CHECK_EQUAL_COLLECTIONS(hex_literal_span.begin(), hex_literal_span.end(), expected.begin(), expected.end());
             +  -  +  - ]
     161                 :             : 
     162         [ +  - ]:           2 :     const std::vector<std::byte> hex_literal_vector{operator""_hex_v<util::detail::Hex(HEX_PARSE_INPUT)>()};
     163                 :           2 :     hex_literal_span = MakeUCharSpan(hex_literal_vector);
     164   [ +  -  +  -  :           4 :     BOOST_CHECK_EQUAL_COLLECTIONS(hex_literal_span.begin(), hex_literal_span.end(), expected.begin(), expected.end());
             +  -  +  - ]
     165                 :             : 
     166                 :           2 :     constexpr std::array<uint8_t, 65> hex_literal_array_uint8{operator""_hex_u8<util::detail::Hex(HEX_PARSE_INPUT)>()};
     167   [ +  -  +  -  :           4 :     BOOST_CHECK_EQUAL_COLLECTIONS(hex_literal_array_uint8.begin(), hex_literal_array_uint8.end(), expected.begin(), expected.end());
             +  -  +  - ]
     168                 :             : 
     169         [ +  - ]:           4 :     result = operator""_hex_v_u8<util::detail::Hex(HEX_PARSE_INPUT)>();
     170   [ +  -  +  -  :           4 :     BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
             +  -  +  - ]
     171                 :             : 
     172         [ +  - ]:           4 :     result = ParseHex(HEX_PARSE_INPUT);
     173   [ +  -  +  -  :           4 :     BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
             +  -  +  - ]
     174                 :             : 
     175         [ +  - ]:           4 :     result = TryParseHex<uint8_t>(HEX_PARSE_INPUT).value();
     176   [ +  -  +  -  :           4 :     BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
             +  -  +  - ]
     177                 :             : 
     178                 :             :     // Spaces between bytes must be supported
     179         [ +  - ]:           2 :     expected = {0x12, 0x34, 0x56, 0x78};
     180         [ +  - ]:           4 :     result = ParseHex("12 34 56 78");
     181   [ +  -  +  -  :           4 :     BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
             +  -  +  - ]
     182         [ +  - ]:           4 :     result = TryParseHex<uint8_t>("12 34 56 78").value();
     183   [ +  -  +  -  :           4 :     BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
             +  -  +  - ]
     184                 :             : 
     185                 :             :     // Leading space must be supported (used in BerkeleyEnvironment::Salvage)
     186         [ +  - ]:           2 :     expected = {0x89, 0x34, 0x56, 0x78};
     187         [ +  - ]:           4 :     result = ParseHex(" 89 34 56 78");
     188   [ +  -  +  -  :           4 :     BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
             +  -  +  - ]
     189         [ +  - ]:           4 :     result = TryParseHex<uint8_t>(" 89 34 56 78").value();
     190   [ +  -  +  -  :           4 :     BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
             +  -  +  - ]
     191                 :             : 
     192                 :             :     // Mixed case and spaces are supported
     193         [ +  - ]:           2 :     expected = {0xff, 0xaa};
     194         [ +  - ]:           4 :     result = ParseHex("     Ff        aA    ");
     195   [ +  -  +  -  :           4 :     BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
             +  -  +  - ]
     196         [ +  - ]:           4 :     result = TryParseHex<uint8_t>("     Ff        aA    ").value();
     197   [ +  -  +  -  :           4 :     BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
             +  -  +  - ]
     198                 :             : 
     199                 :             :     // Empty string is supported
     200                 :           2 :     static_assert(""_hex.empty());
     201                 :           2 :     static_assert(""_hex_u8.empty());
     202   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(""_hex_v.size(), 0);
                   +  - ]
     203   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(""_hex_v_u8.size(), 0);
                   +  - ]
     204   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(ParseHex("").size(), 0);
                   +  - ]
     205   [ +  -  +  -  :           4 :     BOOST_CHECK_EQUAL(TryParseHex<uint8_t>("").value().size(), 0);
                   +  - ]
     206                 :             : 
     207                 :             :     // Spaces between nibbles is treated as invalid
     208   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(ParseHex("AAF F").size(), 0);
                   +  - ]
     209   [ +  -  +  -  :           4 :     BOOST_CHECK(!TryParseHex("AAF F").has_value());
             +  -  +  - ]
     210                 :             : 
     211                 :             :     // Embedded null is treated as invalid
     212         [ +  - ]:           2 :     const std::string with_embedded_null{" 11 "s
     213                 :             :                                          " \0 "
     214                 :           2 :                                          " 22 "s};
     215   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(with_embedded_null.size(), 11);
     216   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(ParseHex(with_embedded_null).size(), 0);
                   +  - ]
     217   [ +  -  +  -  :           4 :     BOOST_CHECK(!TryParseHex(with_embedded_null).has_value());
             +  -  +  - ]
     218                 :             : 
     219                 :             :     // Non-hex is treated as invalid
     220   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(ParseHex("1234 invalid 1234").size(), 0);
                   +  - ]
     221   [ +  -  +  -  :           4 :     BOOST_CHECK(!TryParseHex("1234 invalid 1234").has_value());
             +  -  +  - ]
     222                 :             : 
     223                 :             :     // Truncated input is treated as invalid
     224   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(ParseHex("12 3").size(), 0);
                   +  - ]
     225   [ +  -  +  -  :           4 :     BOOST_CHECK(!TryParseHex("12 3").has_value());
                   +  - ]
     226                 :           2 : }
     227                 :             : 
     228   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(consteval_hex_digit)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     229                 :             : {
     230         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(ConstevalHexDigit('0'), 0);
     231         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(ConstevalHexDigit('9'), 9);
     232         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(ConstevalHexDigit('a'), 0xa);
     233         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(ConstevalHexDigit('f'), 0xf);
     234                 :           2 : }
     235                 :             : 
     236   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(util_HexStr)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     237                 :             : {
     238         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(HexStr(HEX_PARSE_OUTPUT), HEX_PARSE_INPUT);
     239         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(HexStr(Span{HEX_PARSE_OUTPUT}.last(0)), "");
     240         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(HexStr(Span{HEX_PARSE_OUTPUT}.first(0)), "");
     241                 :             : 
     242                 :           2 :     {
     243                 :           2 :         constexpr std::string_view out_exp{"04678afdb0"};
     244                 :           2 :         constexpr std::span in_s{HEX_PARSE_OUTPUT, out_exp.size() / 2};
     245                 :           2 :         const Span<const uint8_t> in_u{MakeUCharSpan(in_s)};
     246                 :           2 :         const Span<const std::byte> in_b{MakeByteSpan(in_s)};
     247                 :             : 
     248         [ +  - ]:           2 :         BOOST_CHECK_EQUAL(HexStr(in_u), out_exp);
     249         [ +  - ]:           2 :         BOOST_CHECK_EQUAL(HexStr(in_s), out_exp);
     250         [ +  - ]:           2 :         BOOST_CHECK_EQUAL(HexStr(in_b), out_exp);
     251                 :             :     }
     252                 :             : 
     253                 :           2 :     {
     254                 :           2 :         auto input = std::string();
     255         [ +  + ]:         514 :         for (size_t i=0; i<256; ++i) {
     256         [ +  - ]:         512 :             input.push_back(static_cast<char>(i));
     257                 :             :         }
     258                 :             : 
     259         [ +  - ]:           2 :         auto hex = HexStr(input);
     260   [ +  -  +  -  :           4 :         BOOST_TEST_REQUIRE(hex.size() == 512);
                   +  - ]
     261                 :           2 :         static constexpr auto hexmap = std::string_view("0123456789abcdef");
     262         [ +  + ]:         514 :         for (size_t i = 0; i < 256; ++i) {
     263         [ +  - ]:         512 :             auto upper = hexmap.find(hex[i * 2]);
     264         [ +  - ]:         512 :             auto lower = hexmap.find(hex[i * 2 + 1]);
     265   [ +  -  +  -  :        1024 :             BOOST_TEST_REQUIRE(upper != std::string_view::npos);
             +  -  +  - ]
     266   [ +  -  +  -  :        1024 :             BOOST_TEST_REQUIRE(lower != std::string_view::npos);
             +  -  +  - ]
     267   [ +  -  +  -  :        1024 :             BOOST_TEST_REQUIRE(i == upper*16 + lower);
                   +  - ]
     268                 :             :         }
     269                 :           2 :     }
     270                 :           2 : }
     271                 :             : 
     272   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(span_write_bytes)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     273                 :             : {
     274                 :           2 :     std::array mut_arr{uint8_t{0xaa}, uint8_t{0xbb}};
     275                 :           2 :     const auto mut_bytes{MakeWritableByteSpan(mut_arr)};
     276                 :           2 :     mut_bytes[1] = std::byte{0x11};
     277         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(mut_arr.at(0), 0xaa);
     278         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(mut_arr.at(1), 0x11);
     279                 :           2 : }
     280                 :             : 
     281   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(util_Join)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     282                 :             : {
     283                 :             :     // Normal version
     284   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(Join(std::vector<std::string>{}, ", "), "");
     285   [ +  -  +  +  :           6 :     BOOST_CHECK_EQUAL(Join(std::vector<std::string>{"foo"}, ", "), "foo");
          +  -  +  -  +  
          -  +  +  -  -  
                   -  - ]
     286   [ +  -  +  +  :          10 :     BOOST_CHECK_EQUAL(Join(std::vector<std::string>{"foo", "bar"}, ", "), "foo, bar");
          +  -  +  -  +  
          -  +  +  -  -  
                   -  - ]
     287                 :             : 
     288                 :             :     // Version with unary operator
     289                 :           8 :     const auto op_upper = [](const std::string& s) { return ToUpper(s); };
     290   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(Join(std::list<std::string>{}, ", ", op_upper), "");
     291   [ +  -  +  +  :           6 :     BOOST_CHECK_EQUAL(Join(std::list<std::string>{"foo"}, ", ", op_upper), "FOO");
          +  -  +  -  +  
          -  +  +  -  -  
                   -  - ]
     292   [ +  -  +  +  :          10 :     BOOST_CHECK_EQUAL(Join(std::list<std::string>{"foo", "bar"}, ", ", op_upper), "FOO, BAR");
          +  -  +  -  +  
          -  +  +  -  -  
                   -  - ]
     293                 :           2 : }
     294                 :             : 
     295   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(util_ReplaceAll)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     296                 :             : {
     297                 :           2 :     const std::string original("A test \"%s\" string '%s'.");
     298                 :          12 :     auto test_replaceall = [&original](const std::string& search, const std::string& substitute, const std::string& expected) {
     299                 :          10 :         auto test = original;
     300         [ +  - ]:          10 :         ReplaceAll(test, search, substitute);
     301   [ +  -  +  - ]:          10 :         BOOST_CHECK_EQUAL(test, expected);
     302                 :          12 :     };
     303                 :             : 
     304   [ +  -  +  -  :           4 :     test_replaceall("", "foo", original);
                   +  - ]
     305   [ +  -  +  -  :           4 :     test_replaceall(original, "foo", "foo");
                   +  - ]
     306   [ +  -  +  -  :           4 :     test_replaceall("%s", "foo", "A test \"foo\" string 'foo'.");
             +  -  +  - ]
     307   [ +  -  +  -  :           4 :     test_replaceall("\"", "foo", "A test foo%sfoo string '%s'.");
             +  -  +  - ]
     308   [ +  -  +  -  :           4 :     test_replaceall("'", "foo", "A test \"%s\" string foo%sfoo.");
             +  -  +  - ]
     309                 :           2 : }
     310                 :             : 
     311   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(util_TrimString)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     312                 :             : {
     313         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(TrimString(" foo bar "), "foo bar");
     314         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(TrimStringView("\t \n  \n \f\n\r\t\v\tfoo \n \f\n\r\t\v\tbar\t  \n \f\n\r\t\v\t\n "), "foo \n \f\n\r\t\v\tbar");
     315         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(TrimString("\t \n foo \n\tbar\t \n "), "foo \n\tbar");
     316         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(TrimStringView("\t \n foo \n\tbar\t \n ", "fobar"), "\t \n foo \n\tbar\t \n ");
     317         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(TrimString("foo bar"), "foo bar");
     318         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(TrimStringView("foo bar", "fobar"), " ");
     319   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(TrimString(std::string("\0 foo \0 ", 8)), std::string("\0 foo \0", 7));
                   +  - ]
     320   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(TrimStringView(std::string(" foo ", 5)), std::string("foo", 3));
                   +  - ]
     321   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(TrimString(std::string("\t\t\0\0\n\n", 6)), std::string("\0\0", 2));
                   +  - ]
     322   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(TrimStringView(std::string("\x05\x04\x03\x02\x01\x00", 6)), std::string("\x05\x04\x03\x02\x01\x00", 6));
                   +  - ]
     323   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(TrimString(std::string("\x05\x04\x03\x02\x01\x00", 6), std::string("\x05\x04\x03\x02\x01", 5)), std::string("\0", 1));
             +  -  +  - ]
     324   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(TrimStringView(std::string("\x05\x04\x03\x02\x01\x00", 6), std::string("\x05\x04\x03\x02\x01\x00", 6)), "");
                   +  - ]
     325                 :           2 : }
     326                 :             : 
     327   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(util_ParseISO8601DateTime)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     328                 :             : {
     329   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ParseISO8601DateTime("1969-12-31T23:59:59Z").value(), -1);
     330   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ParseISO8601DateTime("1970-01-01T00:00:00Z").value(), 0);
     331   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ParseISO8601DateTime("1970-01-01T00:00:01Z").value(), 1);
     332   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ParseISO8601DateTime("2000-01-01T00:00:01Z").value(), 946684801);
     333   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ParseISO8601DateTime("2011-09-30T23:36:17Z").value(), 1317425777);
     334   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ParseISO8601DateTime("2100-12-31T23:59:59Z").value(), 4133980799);
     335   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ParseISO8601DateTime("9999-12-31T23:59:59Z").value(), 253402300799);
     336                 :             : 
     337                 :             :     // Accept edge-cases, where the time overflows. They are not produced by
     338                 :             :     // FormatISO8601DateTime, so this can be changed in the future, if needed.
     339                 :             :     // For now, keep compatibility with the previous implementation.
     340   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ParseISO8601DateTime("2000-01-01T99:00:00Z").value(), 947041200);
     341   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ParseISO8601DateTime("2000-01-01T00:99:00Z").value(), 946690740);
     342   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ParseISO8601DateTime("2000-01-01T00:00:99Z").value(), 946684899);
     343   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ParseISO8601DateTime("2000-01-01T99:99:99Z").value(), 947047239);
     344                 :             : 
     345                 :             :     // Reject date overflows.
     346   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseISO8601DateTime("2000-99-01T00:00:00Z"));
     347   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseISO8601DateTime("2000-01-99T00:00:00Z"));
     348                 :             : 
     349                 :             :     // Reject out-of-range years
     350   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseISO8601DateTime("32768-12-31T23:59:59Z"));
     351   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseISO8601DateTime("32767-12-31T23:59:59Z"));
     352   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseISO8601DateTime("32767-12-31T00:00:00Z"));
     353   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseISO8601DateTime("999-12-31T00:00:00Z"));
     354                 :             : 
     355                 :             :     // Reject invalid format
     356                 :           2 :     const std::string valid{"2000-01-01T00:00:01Z"};
     357   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseISO8601DateTime(valid).has_value());
                   +  - ]
     358         [ +  + ]:          42 :     for (auto mut{0U}; mut < valid.size(); ++mut) {
     359         [ +  - ]:          40 :         std::string invalid{valid};
     360         [ +  - ]:          40 :         invalid[mut] = 'a';
     361   [ +  -  +  -  :          80 :         BOOST_CHECK(!ParseISO8601DateTime(invalid));
                   +  - ]
     362                 :          40 :     }
     363                 :           2 : }
     364                 :             : 
     365   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(util_FormatISO8601DateTime)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     366                 :             : {
     367         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatISO8601DateTime(971890963199), "32767-12-31T23:59:59Z");
     368         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatISO8601DateTime(971890876800), "32767-12-31T00:00:00Z");
     369                 :             : 
     370         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatISO8601DateTime(-1), "1969-12-31T23:59:59Z");
     371         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatISO8601DateTime(0), "1970-01-01T00:00:00Z");
     372         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatISO8601DateTime(1), "1970-01-01T00:00:01Z");
     373         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatISO8601DateTime(946684801), "2000-01-01T00:00:01Z");
     374         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatISO8601DateTime(1317425777), "2011-09-30T23:36:17Z");
     375         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatISO8601DateTime(4133980799), "2100-12-31T23:59:59Z");
     376         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatISO8601DateTime(253402300799), "9999-12-31T23:59:59Z");
     377                 :           2 : }
     378                 :             : 
     379   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(util_FormatISO8601Date)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     380                 :             : {
     381         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatISO8601Date(971890963199), "32767-12-31");
     382         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatISO8601Date(971890876800), "32767-12-31");
     383                 :             : 
     384         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatISO8601Date(0), "1970-01-01");
     385         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatISO8601Date(1317425777), "2011-09-30");
     386                 :           2 : }
     387                 :             : 
     388   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(util_FormatMoney)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     389                 :             : {
     390         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(0), "0.00");
     391         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney((COIN/10000)*123456789), "12345.6789");
     392         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(-COIN), "-1.00");
     393                 :             : 
     394         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(COIN*100000000), "100000000.00");
     395         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(COIN*10000000), "10000000.00");
     396         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(COIN*1000000), "1000000.00");
     397         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(COIN*100000), "100000.00");
     398         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(COIN*10000), "10000.00");
     399         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(COIN*1000), "1000.00");
     400         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(COIN*100), "100.00");
     401         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(COIN*10), "10.00");
     402         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(COIN), "1.00");
     403         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(COIN/10), "0.10");
     404         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(COIN/100), "0.01");
     405         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(COIN/1000), "0.001");
     406         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(COIN/10000), "0.0001");
     407         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(COIN/100000), "0.00001");
     408         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(COIN/1000000), "0.000001");
     409         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(COIN/10000000), "0.0000001");
     410         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(COIN/100000000), "0.00000001");
     411                 :             : 
     412         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(std::numeric_limits<CAmount>::max()), "92233720368.54775807");
     413         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(std::numeric_limits<CAmount>::max() - 1), "92233720368.54775806");
     414         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(std::numeric_limits<CAmount>::max() - 2), "92233720368.54775805");
     415         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(std::numeric_limits<CAmount>::max() - 3), "92233720368.54775804");
     416                 :             :     // ...
     417         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(std::numeric_limits<CAmount>::min() + 3), "-92233720368.54775805");
     418         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(std::numeric_limits<CAmount>::min() + 2), "-92233720368.54775806");
     419         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(std::numeric_limits<CAmount>::min() + 1), "-92233720368.54775807");
     420         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatMoney(std::numeric_limits<CAmount>::min()), "-92233720368.54775808");
     421                 :           2 : }
     422                 :             : 
     423   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(util_ParseMoney)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     424                 :             : {
     425   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("0.0").value(), 0);
     426   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney(".").value(), 0);
     427   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("0.").value(), 0);
     428   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney(".0").value(), 0);
     429   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney(".6789").value(), 6789'0000);
     430   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("12345.").value(), COIN * 12345);
     431                 :             : 
     432   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("12345.6789").value(), (COIN/10000)*123456789);
     433                 :             : 
     434   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("10000000.00").value(), COIN*10000000);
     435   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("1000000.00").value(), COIN*1000000);
     436   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("100000.00").value(), COIN*100000);
     437   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("10000.00").value(), COIN*10000);
     438   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("1000.00").value(), COIN*1000);
     439   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("100.00").value(), COIN*100);
     440   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("10.00").value(), COIN*10);
     441   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("1.00").value(), COIN);
     442   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("1").value(), COIN);
     443   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("   1").value(), COIN);
     444   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("1   ").value(), COIN);
     445   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("  1 ").value(), COIN);
     446   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("0.1").value(), COIN/10);
     447   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("0.01").value(), COIN/100);
     448   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("0.001").value(), COIN/1000);
     449   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("0.0001").value(), COIN/10000);
     450   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("0.00001").value(), COIN/100000);
     451   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("0.000001").value(), COIN/1000000);
     452   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("0.0000001").value(), COIN/10000000);
     453   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("0.00000001").value(), COIN/100000000);
     454   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney(" 0.00000001 ").value(), COIN/100000000);
     455   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney("0.00000001 ").value(), COIN/100000000);
     456   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(ParseMoney(" 0.00000001").value(), COIN/100000000);
     457                 :             : 
     458                 :             :     // Parsing amount that cannot be represented should fail
     459   [ +  -  +  -  :           4 :     BOOST_CHECK(!ParseMoney("100000000.00"));
                   +  - ]
     460   [ +  -  +  -  :           4 :     BOOST_CHECK(!ParseMoney("0.000000001"));
                   +  - ]
     461                 :             : 
     462                 :             :     // Parsing empty string should fail
     463   [ +  -  +  -  :           4 :     BOOST_CHECK(!ParseMoney(""));
                   +  - ]
     464   [ +  -  +  -  :           4 :     BOOST_CHECK(!ParseMoney(" "));
                   +  - ]
     465   [ +  -  +  -  :           4 :     BOOST_CHECK(!ParseMoney("  "));
                   +  - ]
     466                 :             : 
     467                 :             :     // Parsing two numbers should fail
     468   [ +  -  +  -  :           4 :     BOOST_CHECK(!ParseMoney(".."));
                   +  - ]
     469   [ +  -  +  -  :           4 :     BOOST_CHECK(!ParseMoney("0..0"));
                   +  - ]
     470   [ +  -  +  -  :           4 :     BOOST_CHECK(!ParseMoney("1 2"));
                   +  - ]
     471   [ +  -  +  -  :           4 :     BOOST_CHECK(!ParseMoney(" 1 2 "));
                   +  - ]
     472   [ +  -  +  -  :           4 :     BOOST_CHECK(!ParseMoney(" 1.2 3 "));
                   +  - ]
     473   [ +  -  +  -  :           4 :     BOOST_CHECK(!ParseMoney(" 1 2.3 "));
                   +  - ]
     474                 :             : 
     475                 :             :     // Embedded whitespace should fail
     476   [ +  -  +  -  :           4 :     BOOST_CHECK(!ParseMoney(" -1 .2  "));
                   +  - ]
     477   [ +  -  +  -  :           4 :     BOOST_CHECK(!ParseMoney("  1 .2  "));
                   +  - ]
     478   [ +  -  +  -  :           4 :     BOOST_CHECK(!ParseMoney(" +1 .2  "));
                   +  - ]
     479                 :             : 
     480                 :             :     // Attempted 63 bit overflow should fail
     481   [ +  -  +  -  :           4 :     BOOST_CHECK(!ParseMoney("92233720368.54775808"));
                   +  - ]
     482                 :             : 
     483                 :             :     // Parsing negative amounts must fail
     484   [ +  -  +  -  :           4 :     BOOST_CHECK(!ParseMoney("-1"));
                   +  - ]
     485                 :             : 
     486                 :             :     // Parsing strings with embedded NUL characters should fail
     487   [ +  -  +  -  :           4 :     BOOST_CHECK(!ParseMoney("\0-1"s));
                   +  - ]
     488   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseMoney(STRING_WITH_EMBEDDED_NULL_CHAR));
     489   [ +  -  +  -  :           4 :     BOOST_CHECK(!ParseMoney("1\0"s));
                   +  - ]
     490                 :           2 : }
     491                 :             : 
     492   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(util_IsHex)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     493                 :             : {
     494   [ +  -  +  - ]:           4 :     BOOST_CHECK(IsHex("00"));
     495   [ +  -  +  - ]:           4 :     BOOST_CHECK(IsHex("00112233445566778899aabbccddeeffAABBCCDDEEFF"));
     496   [ +  -  +  - ]:           4 :     BOOST_CHECK(IsHex("ff"));
     497   [ +  -  +  - ]:           4 :     BOOST_CHECK(IsHex("FF"));
     498                 :             : 
     499   [ +  -  +  - ]:           4 :     BOOST_CHECK(!IsHex(""));
     500   [ +  -  +  - ]:           4 :     BOOST_CHECK(!IsHex("0"));
     501   [ +  -  +  - ]:           4 :     BOOST_CHECK(!IsHex("a"));
     502   [ +  -  +  - ]:           4 :     BOOST_CHECK(!IsHex("eleven"));
     503   [ +  -  +  - ]:           4 :     BOOST_CHECK(!IsHex("00xx00"));
     504   [ +  -  +  - ]:           4 :     BOOST_CHECK(!IsHex("0x0000"));
     505                 :           2 : }
     506                 :             : 
     507   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(util_seed_insecure_rand)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     508                 :             : {
     509                 :           2 :     SeedRandomForTest(SeedRand::ZEROS);
     510         [ +  + ]:          20 :     for (int mod=2;mod<11;mod++)
     511                 :             :     {
     512                 :          18 :         int mask = 1;
     513                 :             :         // Really rough binomial confidence approximation.
     514                 :          18 :         int err = 30*10000./mod*sqrt((1./mod*(1-1./mod))/10000.);
     515                 :             :         //mask is 2^ceil(log2(mod))-1
     516         [ +  + ]:          50 :         while(mask<mod-1)mask=(mask<<1)+1;
     517                 :             : 
     518                 :             :         int count = 0;
     519                 :             :         //How often does it get a zero from the uniform range [0,mod)?
     520         [ +  + ]:      180018 :         for (int i = 0; i < 10000; i++) {
     521                 :      235594 :             uint32_t rval;
     522                 :      235594 :             do{
     523                 :      235594 :                 rval=m_rng.rand32()&mask;
     524         [ +  + ]:      235594 :             }while(rval>=(uint32_t)mod);
     525                 :      180000 :             count += rval==0;
     526                 :             :         }
     527         [ +  - ]:          36 :         BOOST_CHECK(count<=10000/mod+err);
     528         [ +  - ]:          36 :         BOOST_CHECK(count>=10000/mod-err);
     529                 :             :     }
     530                 :           2 : }
     531                 :             : 
     532   [ +  -  +  -  :          24 : BOOST_AUTO_TEST_CASE(util_TimingResistantEqual)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     533                 :             : {
     534   [ +  -  +  -  :           4 :     BOOST_CHECK(TimingResistantEqual(std::string(""), std::string("")));
                   +  - ]
     535   [ +  -  +  -  :           4 :     BOOST_CHECK(!TimingResistantEqual(std::string("abc"), std::string("")));
                   +  - ]
     536   [ +  -  +  -  :           4 :     BOOST_CHECK(!TimingResistantEqual(std::string(""), std::string("abc")));
                   +  - ]
     537   [ +  -  +  -  :           4 :     BOOST_CHECK(!TimingResistantEqual(std::string("a"), std::string("aa")));
                   +  - ]
     538   [ +  -  +  -  :           4 :     BOOST_CHECK(!TimingResistantEqual(std::string("aa"), std::string("a")));
                   +  - ]
     539   [ +  -  +  -  :           4 :     BOOST_CHECK(TimingResistantEqual(std::string("abc"), std::string("abc")));
                   +  - ]
     540   [ +  -  +  -  :           4 :     BOOST_CHECK(!TimingResistantEqual(std::string("abc"), std::string("aba")));
                   +  - ]
     541                 :           2 : }
     542                 :             : 
     543                 :             : /* Test strprintf formatting directives.
     544                 :             :  * Put a string before and after to ensure sanity of element sizes on stack. */
     545                 :             : #define B "check_prefix"
     546                 :             : #define E "check_postfix"
     547   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(strprintf_numbers)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     548                 :             : {
     549                 :           2 :     int64_t s64t = -9223372036854775807LL; /* signed 64 bit test value */
     550                 :           2 :     uint64_t u64t = 18446744073709551615ULL; /* unsigned 64 bit test value */
     551   [ +  -  +  - ]:           4 :     BOOST_CHECK(strprintf("%s %d %s", B, s64t, E) == B" -9223372036854775807 " E);
     552   [ +  -  +  - ]:           4 :     BOOST_CHECK(strprintf("%s %u %s", B, u64t, E) == B" 18446744073709551615 " E);
     553   [ +  -  +  - ]:           4 :     BOOST_CHECK(strprintf("%s %x %s", B, u64t, E) == B" ffffffffffffffff " E);
     554                 :             : 
     555                 :           2 :     size_t st = 12345678; /* unsigned size_t test value */
     556                 :           2 :     ssize_t sst = -12345678; /* signed size_t test value */
     557   [ +  -  +  - ]:           4 :     BOOST_CHECK(strprintf("%s %d %s", B, sst, E) == B" -12345678 " E);
     558   [ +  -  +  - ]:           4 :     BOOST_CHECK(strprintf("%s %u %s", B, st, E) == B" 12345678 " E);
     559   [ +  -  +  - ]:           4 :     BOOST_CHECK(strprintf("%s %x %s", B, st, E) == B" bc614e " E);
     560                 :             : 
     561                 :           2 :     ptrdiff_t pt = 87654321; /* positive ptrdiff_t test value */
     562                 :           2 :     ptrdiff_t spt = -87654321; /* negative ptrdiff_t test value */
     563   [ +  -  +  - ]:           4 :     BOOST_CHECK(strprintf("%s %d %s", B, spt, E) == B" -87654321 " E);
     564   [ +  -  +  - ]:           4 :     BOOST_CHECK(strprintf("%s %u %s", B, pt, E) == B" 87654321 " E);
     565   [ +  -  +  - ]:           4 :     BOOST_CHECK(strprintf("%s %x %s", B, pt, E) == B" 5397fb1 " E);
     566                 :           2 : }
     567                 :             : #undef B
     568                 :             : #undef E
     569                 :             : 
     570   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(util_time_GetTime)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     571                 :             : {
     572                 :           2 :     SetMockTime(111);
     573                 :             :     // Check that mock time does not change after a sleep
     574         [ +  + ]:           6 :     for (const auto& num_sleep : {0ms, 1ms}) {
     575                 :           4 :         UninterruptibleSleep(num_sleep);
     576         [ +  - ]:           4 :         BOOST_CHECK_EQUAL(111, GetTime()); // Deprecated time getter
     577         [ +  - ]:           4 :         BOOST_CHECK_EQUAL(111, Now<NodeSeconds>().time_since_epoch().count());
     578         [ +  - ]:           4 :         BOOST_CHECK_EQUAL(111, TicksSinceEpoch<std::chrono::seconds>(NodeClock::now()));
     579         [ +  - ]:           4 :         BOOST_CHECK_EQUAL(111, TicksSinceEpoch<SecondsDouble>(Now<NodeSeconds>()));
     580         [ +  - ]:           4 :         BOOST_CHECK_EQUAL(111, GetTime<std::chrono::seconds>().count());
     581         [ +  - ]:           4 :         BOOST_CHECK_EQUAL(111000, GetTime<std::chrono::milliseconds>().count());
     582         [ +  - ]:           4 :         BOOST_CHECK_EQUAL(111000, TicksSinceEpoch<std::chrono::milliseconds>(NodeClock::now()));
     583         [ +  - ]:           4 :         BOOST_CHECK_EQUAL(111000000, GetTime<std::chrono::microseconds>().count());
     584                 :             :     }
     585                 :             : 
     586                 :           2 :     SetMockTime(0);
     587                 :             :     // Check that steady time and system time changes after a sleep
     588                 :           2 :     const auto steady_ms_0 = Now<SteadyMilliseconds>();
     589                 :           2 :     const auto steady_0 = std::chrono::steady_clock::now();
     590                 :           2 :     const auto ms_0 = GetTime<std::chrono::milliseconds>();
     591                 :           2 :     const auto us_0 = GetTime<std::chrono::microseconds>();
     592                 :           2 :     UninterruptibleSleep(1ms);
     593         [ +  - ]:           4 :     BOOST_CHECK(steady_ms_0 < Now<SteadyMilliseconds>());
     594         [ +  - ]:           4 :     BOOST_CHECK(steady_0 + 1ms <= std::chrono::steady_clock::now());
     595         [ +  - ]:           4 :     BOOST_CHECK(ms_0 < GetTime<std::chrono::milliseconds>());
     596         [ +  - ]:           4 :     BOOST_CHECK(us_0 < GetTime<std::chrono::microseconds>());
     597                 :           2 : }
     598                 :             : 
     599   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(test_IsDigit)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     600                 :             : {
     601         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(IsDigit('0'), true);
     602         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(IsDigit('1'), true);
     603         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(IsDigit('8'), true);
     604         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(IsDigit('9'), true);
     605                 :             : 
     606         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(IsDigit('0' - 1), false);
     607         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(IsDigit('9' + 1), false);
     608         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(IsDigit(0), false);
     609         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(IsDigit(1), false);
     610         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(IsDigit(8), false);
     611         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(IsDigit(9), false);
     612                 :           2 : }
     613                 :             : 
     614                 :             : /* Check for overflow */
     615                 :             : template <typename T>
     616                 :           4 : static void TestAddMatrixOverflow()
     617                 :             : {
     618                 :           4 :     constexpr T MAXI{std::numeric_limits<T>::max()};
     619         [ +  - ]:           8 :     BOOST_CHECK(!CheckedAdd(T{1}, MAXI));
     620         [ +  - ]:           8 :     BOOST_CHECK(!CheckedAdd(MAXI, MAXI));
     621         [ +  - ]:           4 :     BOOST_CHECK_EQUAL(MAXI, SaturatingAdd(T{1}, MAXI));
     622         [ +  - ]:           4 :     BOOST_CHECK_EQUAL(MAXI, SaturatingAdd(MAXI, MAXI));
     623                 :             : 
     624   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(0, CheckedAdd(T{0}, T{0}).value());
     625   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(MAXI, CheckedAdd(T{0}, MAXI).value());
     626   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(MAXI, CheckedAdd(T{1}, MAXI - 1).value());
     627   [ +  -  +  - ]:           4 :     BOOST_CHECK_EQUAL(MAXI - 1, CheckedAdd(T{1}, MAXI - 2).value());
     628         [ +  - ]:           4 :     BOOST_CHECK_EQUAL(0, SaturatingAdd(T{0}, T{0}));
     629         [ +  - ]:           4 :     BOOST_CHECK_EQUAL(MAXI, SaturatingAdd(T{0}, MAXI));
     630         [ +  - ]:           4 :     BOOST_CHECK_EQUAL(MAXI, SaturatingAdd(T{1}, MAXI - 1));
     631         [ +  - ]:           4 :     BOOST_CHECK_EQUAL(MAXI - 1, SaturatingAdd(T{1}, MAXI - 2));
     632                 :           4 : }
     633                 :             : 
     634                 :             : /* Check for overflow or underflow */
     635                 :             : template <typename T>
     636                 :           2 : static void TestAddMatrix()
     637                 :             : {
     638                 :           2 :     TestAddMatrixOverflow<T>();
     639                 :           2 :     constexpr T MINI{std::numeric_limits<T>::min()};
     640                 :           2 :     constexpr T MAXI{std::numeric_limits<T>::max()};
     641         [ +  - ]:           4 :     BOOST_CHECK(!CheckedAdd(T{-1}, MINI));
     642         [ +  - ]:           4 :     BOOST_CHECK(!CheckedAdd(MINI, MINI));
     643         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(MINI, SaturatingAdd(T{-1}, MINI));
     644         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(MINI, SaturatingAdd(MINI, MINI));
     645                 :             : 
     646   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(MINI, CheckedAdd(T{0}, MINI).value());
     647   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(MINI, CheckedAdd(T{-1}, MINI + 1).value());
     648   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(-1, CheckedAdd(MINI, MAXI).value());
     649   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(MINI + 1, CheckedAdd(T{-1}, MINI + 2).value());
     650         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(MINI, SaturatingAdd(T{0}, MINI));
     651         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(MINI, SaturatingAdd(T{-1}, MINI + 1));
     652         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(MINI + 1, SaturatingAdd(T{-1}, MINI + 2));
     653         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(-1, SaturatingAdd(MINI, MAXI));
     654                 :           2 : }
     655                 :             : 
     656   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(util_overflow)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     657                 :             : {
     658                 :           2 :     TestAddMatrixOverflow<unsigned>();
     659                 :           2 :     TestAddMatrix<signed>();
     660                 :           2 : }
     661                 :             : 
     662   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(test_ParseInt32)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     663                 :             : {
     664                 :           2 :     int32_t n;
     665                 :             :     // Valid values
     666   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseInt32("1234", nullptr));
     667   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseInt32("0", &n) && n == 0);
             -  +  +  - ]
     668   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseInt32("1234", &n) && n == 1234);
             -  +  +  - ]
     669   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseInt32("01234", &n) && n == 1234); // no octal
             -  +  +  - ]
     670   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseInt32("2147483647", &n) && n == 2147483647);
             -  +  +  - ]
     671   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseInt32("-2147483648", &n) && n == (-2147483647 - 1)); // (-2147483647 - 1) equals INT_MIN
             -  +  +  - ]
     672   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseInt32("-1234", &n) && n == -1234);
             -  +  +  - ]
     673   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseInt32("00000000000000001234", &n) && n == 1234);
             -  +  +  - ]
     674   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseInt32("-00000000000000001234", &n) && n == -1234);
             -  +  +  - ]
     675   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseInt32("00000000000000000000", &n) && n == 0);
             -  +  +  - ]
     676   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseInt32("-00000000000000000000", &n) && n == 0);
             -  +  +  - ]
     677                 :             :     // Invalid values
     678   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt32("", &n));
     679   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt32(" 1", &n)); // no padding inside
     680   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt32("1 ", &n));
     681   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt32("++1", &n));
     682   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt32("+-1", &n));
     683   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt32("-+1", &n));
     684   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt32("--1", &n));
     685   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt32("1a", &n));
     686   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt32("aap", &n));
     687   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt32("0x1", &n)); // no hex
     688   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt32(STRING_WITH_EMBEDDED_NULL_CHAR, &n));
     689                 :             :     // Overflow and underflow
     690   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt32("-2147483649", nullptr));
     691   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt32("2147483648", nullptr));
     692   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt32("-32482348723847471234", nullptr));
     693   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt32("32482348723847471234", nullptr));
     694                 :           2 : }
     695                 :             : 
     696                 :             : template <typename T>
     697                 :          16 : static void RunToIntegralTests()
     698                 :             : {
     699         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>(STRING_WITH_EMBEDDED_NULL_CHAR));
     700         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>(" 1"));
     701         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>("1 "));
     702         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>("1a"));
     703         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>("1.1"));
     704         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>("1.9"));
     705         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>("+01.9"));
     706         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>("-"));
     707         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>("+"));
     708         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>(" -1"));
     709         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>("-1 "));
     710         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>(" -1 "));
     711         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>("+1"));
     712         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>(" +1"));
     713         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>(" +1 "));
     714         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>("+-1"));
     715         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>("-+1"));
     716         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>("++1"));
     717         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>("--1"));
     718         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>(""));
     719         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>("aap"));
     720         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>("0x1"));
     721         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>("-32482348723847471234"));
     722         [ +  - ]:          32 :     BOOST_CHECK(!ToIntegral<T>("32482348723847471234"));
     723                 :          16 : }
     724                 :             : 
     725   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(test_ToIntegral)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     726                 :             : {
     727   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<int32_t>("1234").value(), 1'234);
     728   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<int32_t>("0").value(), 0);
     729   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<int32_t>("01234").value(), 1'234);
     730   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<int32_t>("00000000000000001234").value(), 1'234);
     731   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<int32_t>("-00000000000000001234").value(), -1'234);
     732   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<int32_t>("00000000000000000000").value(), 0);
     733   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<int32_t>("-00000000000000000000").value(), 0);
     734   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<int32_t>("-1234").value(), -1'234);
     735   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<int32_t>("-1").value(), -1);
     736                 :             : 
     737                 :           2 :     RunToIntegralTests<uint64_t>();
     738                 :           2 :     RunToIntegralTests<int64_t>();
     739                 :           2 :     RunToIntegralTests<uint32_t>();
     740                 :           2 :     RunToIntegralTests<int32_t>();
     741                 :           2 :     RunToIntegralTests<uint16_t>();
     742                 :           2 :     RunToIntegralTests<int16_t>();
     743                 :           2 :     RunToIntegralTests<uint8_t>();
     744                 :           2 :     RunToIntegralTests<int8_t>();
     745                 :             : 
     746         [ +  - ]:           4 :     BOOST_CHECK(!ToIntegral<int64_t>("-9223372036854775809"));
     747   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<int64_t>("-9223372036854775808").value(), -9'223'372'036'854'775'807LL - 1LL);
     748   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<int64_t>("9223372036854775807").value(), 9'223'372'036'854'775'807);
     749         [ +  - ]:           4 :     BOOST_CHECK(!ToIntegral<int64_t>("9223372036854775808"));
     750                 :             : 
     751         [ +  - ]:           4 :     BOOST_CHECK(!ToIntegral<uint64_t>("-1"));
     752   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<uint64_t>("0").value(), 0U);
     753   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<uint64_t>("18446744073709551615").value(), 18'446'744'073'709'551'615ULL);
     754         [ +  - ]:           4 :     BOOST_CHECK(!ToIntegral<uint64_t>("18446744073709551616"));
     755                 :             : 
     756         [ +  - ]:           4 :     BOOST_CHECK(!ToIntegral<int32_t>("-2147483649"));
     757   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<int32_t>("-2147483648").value(), -2'147'483'648LL);
     758   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<int32_t>("2147483647").value(), 2'147'483'647);
     759         [ +  - ]:           4 :     BOOST_CHECK(!ToIntegral<int32_t>("2147483648"));
     760                 :             : 
     761         [ +  - ]:           4 :     BOOST_CHECK(!ToIntegral<uint32_t>("-1"));
     762   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<uint32_t>("0").value(), 0U);
     763   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<uint32_t>("4294967295").value(), 4'294'967'295U);
     764         [ +  - ]:           4 :     BOOST_CHECK(!ToIntegral<uint32_t>("4294967296"));
     765                 :             : 
     766         [ +  - ]:           4 :     BOOST_CHECK(!ToIntegral<int16_t>("-32769"));
     767   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<int16_t>("-32768").value(), -32'768);
     768   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<int16_t>("32767").value(), 32'767);
     769         [ +  - ]:           4 :     BOOST_CHECK(!ToIntegral<int16_t>("32768"));
     770                 :             : 
     771         [ +  - ]:           4 :     BOOST_CHECK(!ToIntegral<uint16_t>("-1"));
     772   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<uint16_t>("0").value(), 0U);
     773   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<uint16_t>("65535").value(), 65'535U);
     774         [ +  - ]:           4 :     BOOST_CHECK(!ToIntegral<uint16_t>("65536"));
     775                 :             : 
     776         [ +  - ]:           4 :     BOOST_CHECK(!ToIntegral<int8_t>("-129"));
     777   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<int8_t>("-128").value(), -128);
     778   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<int8_t>("127").value(), 127);
     779         [ +  - ]:           4 :     BOOST_CHECK(!ToIntegral<int8_t>("128"));
     780                 :             : 
     781         [ +  - ]:           4 :     BOOST_CHECK(!ToIntegral<uint8_t>("-1"));
     782   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<uint8_t>("0").value(), 0U);
     783   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(ToIntegral<uint8_t>("255").value(), 255U);
     784         [ +  - ]:           4 :     BOOST_CHECK(!ToIntegral<uint8_t>("256"));
     785                 :           2 : }
     786                 :             : 
     787                 :          16 : int64_t atoi64_legacy(const std::string& str)
     788                 :             : {
     789                 :          16 :     return strtoll(str.c_str(), nullptr, 10);
     790                 :             : }
     791                 :             : 
     792   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(test_LocaleIndependentAtoi)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     793                 :             : {
     794         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("1234"), 1'234);
     795         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("0"), 0);
     796         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("01234"), 1'234);
     797         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("-1234"), -1'234);
     798         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(" 1"), 1);
     799         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("1 "), 1);
     800         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("1a"), 1);
     801         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("1.1"), 1);
     802         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("1.9"), 1);
     803         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("+01.9"), 1);
     804         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("-1"), -1);
     805         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(" -1"), -1);
     806         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("-1 "), -1);
     807         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(" -1 "), -1);
     808         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("+1"), 1);
     809         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(" +1"), 1);
     810         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(" +1 "), 1);
     811                 :             : 
     812         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("+-1"), 0);
     813         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("-+1"), 0);
     814         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("++1"), 0);
     815         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("--1"), 0);
     816         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(""), 0);
     817         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("aap"), 0);
     818         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("0x1"), 0);
     819         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("-32482348723847471234"), -2'147'483'647 - 1);
     820         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("32482348723847471234"), 2'147'483'647);
     821                 :             : 
     822         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int64_t>("-9223372036854775809"), -9'223'372'036'854'775'807LL - 1LL);
     823         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int64_t>("-9223372036854775808"), -9'223'372'036'854'775'807LL - 1LL);
     824         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int64_t>("9223372036854775807"), 9'223'372'036'854'775'807);
     825         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int64_t>("9223372036854775808"), 9'223'372'036'854'775'807);
     826                 :             : 
     827                 :           2 :     std::map<std::string, int64_t> atoi64_test_pairs = {
     828         [ +  - ]:           2 :         {"-9223372036854775809", std::numeric_limits<int64_t>::min()},
     829                 :           2 :         {"-9223372036854775808", -9'223'372'036'854'775'807LL - 1LL},
     830                 :           2 :         {"9223372036854775807", 9'223'372'036'854'775'807},
     831                 :           2 :         {"9223372036854775808", std::numeric_limits<int64_t>::max()},
     832                 :           2 :         {"+-", 0},
     833                 :           2 :         {"0x1", 0},
     834                 :           2 :         {"ox1", 0},
     835                 :           2 :         {"", 0},
     836   [ +  +  -  - ]:          18 :     };
     837                 :             : 
     838         [ +  + ]:          18 :     for (const auto& pair : atoi64_test_pairs) {
     839   [ +  -  +  -  :          16 :         BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int64_t>(pair.first), pair.second);
                   +  - ]
     840                 :             :     }
     841                 :             : 
     842                 :             :     // Ensure legacy compatibility with previous versions of Bitcoin Core's atoi64
     843         [ +  + ]:          18 :     for (const auto& pair : atoi64_test_pairs) {
     844   [ +  -  +  -  :          16 :         BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int64_t>(pair.first), atoi64_legacy(pair.first));
                   +  - ]
     845                 :             :     }
     846                 :             : 
     847   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint64_t>("-1"), 0U);
                   +  - ]
     848   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint64_t>("0"), 0U);
                   +  - ]
     849   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint64_t>("18446744073709551615"), 18'446'744'073'709'551'615ULL);
                   +  - ]
     850   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint64_t>("18446744073709551616"), 18'446'744'073'709'551'615ULL);
                   +  - ]
     851                 :             : 
     852   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("-2147483649"), -2'147'483'648LL);
                   +  - ]
     853   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("-2147483648"), -2'147'483'648LL);
                   +  - ]
     854   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("2147483647"), 2'147'483'647);
                   +  - ]
     855   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("2147483648"), 2'147'483'647);
                   +  - ]
     856                 :             : 
     857   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint32_t>("-1"), 0U);
                   +  - ]
     858   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint32_t>("0"), 0U);
                   +  - ]
     859   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint32_t>("4294967295"), 4'294'967'295U);
                   +  - ]
     860   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint32_t>("4294967296"), 4'294'967'295U);
                   +  - ]
     861                 :             : 
     862   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int16_t>("-32769"), -32'768);
                   +  - ]
     863   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int16_t>("-32768"), -32'768);
                   +  - ]
     864   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int16_t>("32767"), 32'767);
                   +  - ]
     865   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int16_t>("32768"), 32'767);
                   +  - ]
     866                 :             : 
     867   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint16_t>("-1"), 0U);
                   +  - ]
     868   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint16_t>("0"), 0U);
                   +  - ]
     869   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint16_t>("65535"), 65'535U);
                   +  - ]
     870   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint16_t>("65536"), 65'535U);
                   +  - ]
     871                 :             : 
     872   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int8_t>("-129"), -128);
                   +  - ]
     873   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int8_t>("-128"), -128);
                   +  - ]
     874   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int8_t>("127"), 127);
                   +  - ]
     875   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int8_t>("128"), 127);
                   +  - ]
     876                 :             : 
     877   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint8_t>("-1"), 0U);
                   +  - ]
     878   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint8_t>("0"), 0U);
                   +  - ]
     879   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint8_t>("255"), 255U);
                   +  - ]
     880   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint8_t>("256"), 255U);
                   +  - ]
     881   [ +  -  +  -  :           4 : }
          +  -  +  -  +  
          -  +  -  +  -  
             -  +  -  - ]
     882                 :             : 
     883   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(test_ParseInt64)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     884                 :             : {
     885                 :           2 :     int64_t n;
     886                 :             :     // Valid values
     887   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseInt64("1234", nullptr));
     888   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseInt64("0", &n) && n == 0LL);
             -  +  +  - ]
     889   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseInt64("1234", &n) && n == 1234LL);
             -  +  +  - ]
     890   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseInt64("01234", &n) && n == 1234LL); // no octal
             -  +  +  - ]
     891   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseInt64("2147483647", &n) && n == 2147483647LL);
             -  +  +  - ]
     892   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseInt64("-2147483648", &n) && n == -2147483648LL);
             -  +  +  - ]
     893   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseInt64("9223372036854775807", &n) && n == int64_t{9223372036854775807});
             -  +  +  - ]
     894   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseInt64("-9223372036854775808", &n) && n == int64_t{-9223372036854775807-1});
             -  +  +  - ]
     895   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseInt64("-1234", &n) && n == -1234LL);
             -  +  +  - ]
     896                 :             :     // Invalid values
     897   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt64("", &n));
     898   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt64(" 1", &n)); // no padding inside
     899   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt64("1 ", &n));
     900   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt64("1a", &n));
     901   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt64("aap", &n));
     902   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt64("0x1", &n)); // no hex
     903   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt64(STRING_WITH_EMBEDDED_NULL_CHAR, &n));
     904                 :             :     // Overflow and underflow
     905   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt64("-9223372036854775809", nullptr));
     906   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt64("9223372036854775808", nullptr));
     907   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt64("-32482348723847471234", nullptr));
     908   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseInt64("32482348723847471234", nullptr));
     909                 :           2 : }
     910                 :             : 
     911   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(test_ParseUInt8)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     912                 :             : {
     913                 :           2 :     uint8_t n;
     914                 :             :     // Valid values
     915   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseUInt8("255", nullptr));
     916   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt8("0", &n) && n == 0);
             -  +  +  - ]
     917   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt8("255", &n) && n == 255);
             -  +  +  - ]
     918   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt8("0255", &n) && n == 255); // no octal
             -  +  +  - ]
     919   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt8("255", &n) && n == static_cast<uint8_t>(255));
             -  +  +  - ]
     920   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt8("+255", &n) && n == 255);
             -  +  +  - ]
     921   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt8("00000000000000000012", &n) && n == 12);
             -  +  +  - ]
     922   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt8("00000000000000000000", &n) && n == 0);
             -  +  +  - ]
     923                 :             :     // Invalid values
     924   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt8("-00000000000000000000", &n));
     925   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt8("", &n));
     926   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt8(" 1", &n)); // no padding inside
     927   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt8(" -1", &n));
     928   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt8("++1", &n));
     929   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt8("+-1", &n));
     930   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt8("-+1", &n));
     931   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt8("--1", &n));
     932   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt8("-1", &n));
     933   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt8("1 ", &n));
     934   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt8("1a", &n));
     935   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt8("aap", &n));
     936   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt8("0x1", &n)); // no hex
     937   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt8(STRING_WITH_EMBEDDED_NULL_CHAR, &n));
     938                 :             :     // Overflow and underflow
     939   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt8("-255", &n));
     940   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt8("256", &n));
     941   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt8("-123", &n));
     942   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt8("-123", nullptr));
     943   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt8("256", nullptr));
     944                 :           2 : }
     945                 :             : 
     946   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(test_ParseUInt16)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     947                 :             : {
     948                 :           2 :     uint16_t n;
     949                 :             :     // Valid values
     950   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseUInt16("1234", nullptr));
     951   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt16("0", &n) && n == 0);
             -  +  +  - ]
     952   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt16("1234", &n) && n == 1234);
             -  +  +  - ]
     953   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt16("01234", &n) && n == 1234); // no octal
             -  +  +  - ]
     954   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt16("65535", &n) && n == static_cast<uint16_t>(65535));
             -  +  +  - ]
     955   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt16("+65535", &n) && n == 65535);
             -  +  +  - ]
     956   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt16("00000000000000000012", &n) && n == 12);
             -  +  +  - ]
     957   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt16("00000000000000000000", &n) && n == 0);
             -  +  +  - ]
     958                 :             :     // Invalid values
     959   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt16("-00000000000000000000", &n));
     960   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt16("", &n));
     961   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt16(" 1", &n)); // no padding inside
     962   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt16(" -1", &n));
     963   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt16("++1", &n));
     964   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt16("+-1", &n));
     965   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt16("-+1", &n));
     966   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt16("--1", &n));
     967   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt16("-1", &n));
     968   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt16("1 ", &n));
     969   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt16("1a", &n));
     970   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt16("aap", &n));
     971   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt16("0x1", &n)); // no hex
     972   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt16(STRING_WITH_EMBEDDED_NULL_CHAR, &n));
     973                 :             :     // Overflow and underflow
     974   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt16("-65535", &n));
     975   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt16("65536", &n));
     976   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt16("-123", &n));
     977   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt16("-123", nullptr));
     978   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt16("65536", nullptr));
     979                 :           2 : }
     980                 :             : 
     981   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(test_ParseUInt32)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
     982                 :             : {
     983                 :           2 :     uint32_t n;
     984                 :             :     // Valid values
     985   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseUInt32("1234", nullptr));
     986   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt32("0", &n) && n == 0);
             -  +  +  - ]
     987   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt32("1234", &n) && n == 1234);
             -  +  +  - ]
     988   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt32("01234", &n) && n == 1234); // no octal
             -  +  +  - ]
     989   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt32("2147483647", &n) && n == 2147483647);
             -  +  +  - ]
     990   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt32("2147483648", &n) && n == uint32_t{2147483648});
             -  +  +  - ]
     991   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt32("4294967295", &n) && n == uint32_t{4294967295});
             -  +  +  - ]
     992   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt32("+1234", &n) && n == 1234);
             -  +  +  - ]
     993   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt32("00000000000000001234", &n) && n == 1234);
             -  +  +  - ]
     994   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt32("00000000000000000000", &n) && n == 0);
             -  +  +  - ]
     995                 :             :     // Invalid values
     996   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt32("-00000000000000000000", &n));
     997   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt32("", &n));
     998   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt32(" 1", &n)); // no padding inside
     999   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt32(" -1", &n));
    1000   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt32("++1", &n));
    1001   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt32("+-1", &n));
    1002   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt32("-+1", &n));
    1003   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt32("--1", &n));
    1004   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt32("-1", &n));
    1005   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt32("1 ", &n));
    1006   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt32("1a", &n));
    1007   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt32("aap", &n));
    1008   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt32("0x1", &n)); // no hex
    1009   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt32(STRING_WITH_EMBEDDED_NULL_CHAR, &n));
    1010                 :             :     // Overflow and underflow
    1011   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt32("-2147483648", &n));
    1012   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt32("4294967296", &n));
    1013   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt32("-1234", &n));
    1014   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt32("-32482348723847471234", nullptr));
    1015   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt32("32482348723847471234", nullptr));
    1016                 :           2 : }
    1017                 :             : 
    1018   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(test_ParseUInt64)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1019                 :             : {
    1020                 :           2 :     uint64_t n;
    1021                 :             :     // Valid values
    1022   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseUInt64("1234", nullptr));
    1023   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt64("0", &n) && n == 0LL);
             -  +  +  - ]
    1024   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt64("1234", &n) && n == 1234LL);
             -  +  +  - ]
    1025   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt64("01234", &n) && n == 1234LL); // no octal
             -  +  +  - ]
    1026   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt64("2147483647", &n) && n == 2147483647LL);
             -  +  +  - ]
    1027   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt64("9223372036854775807", &n) && n == 9223372036854775807ULL);
             -  +  +  - ]
    1028   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt64("9223372036854775808", &n) && n == 9223372036854775808ULL);
             -  +  +  - ]
    1029   [ +  -  +  -  :           4 :     BOOST_CHECK(ParseUInt64("18446744073709551615", &n) && n == 18446744073709551615ULL);
             -  +  +  - ]
    1030                 :             :     // Invalid values
    1031   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt64("", &n));
    1032   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt64(" 1", &n)); // no padding inside
    1033   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt64(" -1", &n));
    1034   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt64("1 ", &n));
    1035   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt64("1a", &n));
    1036   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt64("aap", &n));
    1037   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt64("0x1", &n)); // no hex
    1038   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt64(STRING_WITH_EMBEDDED_NULL_CHAR, &n));
    1039                 :             :     // Overflow and underflow
    1040   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt64("-9223372036854775809", nullptr));
    1041   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt64("18446744073709551616", nullptr));
    1042   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt64("-32482348723847471234", nullptr));
    1043   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt64("-2147483648", &n));
    1044   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt64("-9223372036854775808", &n));
    1045   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseUInt64("-1234", &n));
    1046                 :           2 : }
    1047                 :             : 
    1048   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(test_FormatParagraph)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1049                 :             : {
    1050         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatParagraph("", 79, 0), "");
    1051         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatParagraph("test", 79, 0), "test");
    1052         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatParagraph(" test", 79, 0), " test");
    1053         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatParagraph("test test", 79, 0), "test test");
    1054         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatParagraph("test test", 4, 0), "test\ntest");
    1055         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatParagraph("testerde test", 4, 0), "testerde\ntest");
    1056         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatParagraph("test test", 4, 4), "test\n    test");
    1057                 :             : 
    1058                 :             :     // Make sure we don't indent a fully-new line following a too-long line ending
    1059         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatParagraph("test test\nabc", 4, 4), "test\n    test\nabc");
    1060                 :             : 
    1061         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatParagraph("This_is_a_very_long_test_string_without_any_spaces_so_it_should_just_get_returned_as_is_despite_the_length until it gets here", 79), "This_is_a_very_long_test_string_without_any_spaces_so_it_should_just_get_returned_as_is_despite_the_length\nuntil it gets here");
    1062                 :             : 
    1063                 :             :     // Test wrap length is exact
    1064         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatParagraph("a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 a b c de f g h i j k l m n o p", 79), "a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 a b c de\nf g h i j k l m n o p");
    1065         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatParagraph("x\na b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 a b c de f g h i j k l m n o p", 79), "x\na b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 a b c de\nf g h i j k l m n o p");
    1066                 :             :     // Indent should be included in length of lines
    1067         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatParagraph("x\na b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 a b c de f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e fg h i j k", 79, 4), "x\na b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 a b c de\n    f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e fg\n    h i j k");
    1068                 :             : 
    1069         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatParagraph("This is a very long test string. This is a second sentence in the very long test string.", 79), "This is a very long test string. This is a second sentence in the very long\ntest string.");
    1070         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatParagraph("This is a very long test string.\nThis is a second sentence in the very long test string. This is a third sentence in the very long test string.", 79), "This is a very long test string.\nThis is a second sentence in the very long test string. This is a third\nsentence in the very long test string.");
    1071         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatParagraph("This is a very long test string.\n\nThis is a second sentence in the very long test string. This is a third sentence in the very long test string.", 79), "This is a very long test string.\n\nThis is a second sentence in the very long test string. This is a third\nsentence in the very long test string.");
    1072         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(FormatParagraph("Testing that normal newlines do not get indented.\nLike here.", 79), "Testing that normal newlines do not get indented.\nLike here.");
    1073                 :           2 : }
    1074                 :             : 
    1075   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(test_FormatSubVersion)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1076                 :             : {
    1077                 :           2 :     std::vector<std::string> comments;
    1078         [ +  - ]:           2 :     comments.emplace_back("comment1");
    1079                 :           2 :     std::vector<std::string> comments2;
    1080         [ +  - ]:           2 :     comments2.emplace_back("comment1");
    1081   [ +  -  +  - ]:           4 :     comments2.push_back(SanitizeString(std::string("Comment2; .,_?@-; !\"#$%&'()*+/<=>[]\\^`{|}~"), SAFE_CHARS_UA_COMMENT)); // Semicolon is discouraged but not forbidden by BIP-0014
    1082   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(FormatSubVersion("Test", 99900, std::vector<std::string>()),std::string("/Test:9.99.0/"));
          +  -  +  -  +  
                      - ]
    1083   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(FormatSubVersion("Test", 99900, comments),std::string("/Test:9.99.0(comment1)/"));
          +  -  +  -  +  
                      - ]
    1084   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(FormatSubVersion("Test", 99900, comments2),std::string("/Test:9.99.0(comment1; Comment2; .,_?@-; )/"));
          +  -  +  -  +  
                      - ]
    1085                 :           2 : }
    1086                 :             : 
    1087   [ +  -  +  -  :          14 : BOOST_AUTO_TEST_CASE(test_ParseFixedPoint)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1088                 :             : {
    1089                 :           2 :     int64_t amount = 0;
    1090   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseFixedPoint("0", 8, &amount));
    1091         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(amount, 0LL);
    1092   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseFixedPoint("1", 8, &amount));
    1093         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(amount, 100000000LL);
    1094   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseFixedPoint("0.0", 8, &amount));
    1095         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(amount, 0LL);
    1096   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseFixedPoint("-0.1", 8, &amount));
    1097         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(amount, -10000000LL);
    1098   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseFixedPoint("1.1", 8, &amount));
    1099         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(amount, 110000000LL);
    1100   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseFixedPoint("1.10000000000000000", 8, &amount));
    1101         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(amount, 110000000LL);
    1102   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseFixedPoint("1.1e1", 8, &amount));
    1103         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(amount, 1100000000LL);
    1104   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseFixedPoint("1.1e-1", 8, &amount));
    1105         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(amount, 11000000LL);
    1106   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseFixedPoint("1000", 8, &amount));
    1107         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(amount, 100000000000LL);
    1108   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseFixedPoint("-1000", 8, &amount));
    1109         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(amount, -100000000000LL);
    1110   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseFixedPoint("0.00000001", 8, &amount));
    1111         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(amount, 1LL);
    1112   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseFixedPoint("0.0000000100000000", 8, &amount));
    1113         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(amount, 1LL);
    1114   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseFixedPoint("-0.00000001", 8, &amount));
    1115         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(amount, -1LL);
    1116   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseFixedPoint("1000000000.00000001", 8, &amount));
    1117         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(amount, 100000000000000001LL);
    1118   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseFixedPoint("9999999999.99999999", 8, &amount));
    1119         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(amount, 999999999999999999LL);
    1120   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseFixedPoint("-9999999999.99999999", 8, &amount));
    1121         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(amount, -999999999999999999LL);
    1122                 :             : 
    1123   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("", 8, &amount));
    1124   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("-", 8, &amount));
    1125   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("a-1000", 8, &amount));
    1126   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("-a1000", 8, &amount));
    1127   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("-1000a", 8, &amount));
    1128   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("-01000", 8, &amount));
    1129   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("00.1", 8, &amount));
    1130   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint(".1", 8, &amount));
    1131   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("--0.1", 8, &amount));
    1132   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("0.000000001", 8, &amount));
    1133   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("-0.000000001", 8, &amount));
    1134   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("0.00000001000000001", 8, &amount));
    1135   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("-10000000000.00000000", 8, &amount));
    1136   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("10000000000.00000000", 8, &amount));
    1137   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("-10000000000.00000001", 8, &amount));
    1138   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("10000000000.00000001", 8, &amount));
    1139   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("-10000000000.00000009", 8, &amount));
    1140   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("10000000000.00000009", 8, &amount));
    1141   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("-99999999999.99999999", 8, &amount));
    1142   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("99999909999.09999999", 8, &amount));
    1143   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("92233720368.54775807", 8, &amount));
    1144   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("92233720368.54775808", 8, &amount));
    1145   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("-92233720368.54775808", 8, &amount));
    1146   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("-92233720368.54775809", 8, &amount));
    1147   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("1.1e", 8, &amount));
    1148   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("1.1e-", 8, &amount));
    1149   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("1.", 8, &amount));
    1150                 :             : 
    1151                 :             :     // Test with 3 decimal places for fee rates in sat/vB.
    1152   [ +  -  +  - ]:           4 :     BOOST_CHECK(ParseFixedPoint("0.001", 3, &amount));
    1153         [ +  - ]:           2 :     BOOST_CHECK_EQUAL(amount, CAmount{1});
    1154   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("0.0009", 3, &amount));
    1155   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("31.00100001", 3, &amount));
    1156   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("31.0011", 3, &amount));
    1157   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("31.99999999", 3, &amount));
    1158   [ +  -  +  - ]:           4 :     BOOST_CHECK(!ParseFixedPoint("31.999999999999999999999", 3, &amount));
    1159                 :           2 : }
    1160                 :             : 
    1161                 :             : #ifndef WIN32 // Cannot do this test on WIN32 due to lack of fork()
    1162                 :             : static constexpr char LockCommand = 'L';
    1163                 :             : static constexpr char UnlockCommand = 'U';
    1164                 :             : static constexpr char ExitCommand = 'X';
    1165                 :             : enum : char {
    1166                 :             :     ResSuccess = 2, // Start with 2 to avoid accidental collision with common values 0 and 1
    1167                 :             :     ResErrorWrite,
    1168                 :             :     ResErrorLock,
    1169                 :             :     ResUnlockSuccess,
    1170                 :             : };
    1171                 :             : 
    1172                 :           1 : [[noreturn]] static void TestOtherProcess(fs::path dirname, fs::path lockname, int fd)
    1173                 :             : {
    1174                 :           6 :     char ch;
    1175                 :           6 :     while (true) {
    1176                 :           6 :         int rv = read(fd, &ch, 1); // Wait for command
    1177         [ -  + ]:           6 :         assert(rv == 1);
    1178   [ +  +  +  - ]:           6 :         switch (ch) {
    1179                 :           4 :         case LockCommand:
    1180                 :          12 :             ch = [&] {
    1181   [ +  +  -  + ]:           4 :                 switch (util::LockDirectory(dirname, lockname)) {
    1182                 :             :                 case util::LockResult::Success: return ResSuccess;
    1183                 :           1 :                 case util::LockResult::ErrorWrite: return ResErrorWrite;
    1184                 :           1 :                 case util::LockResult::ErrorLock: return ResErrorLock;
    1185                 :             :                 } // no default case, so the compiler can warn about missing cases
    1186                 :           0 :                 assert(false);
    1187                 :           4 :             }();
    1188                 :           4 :             rv = write(fd, &ch, 1);
    1189         [ +  - ]:           4 :             assert(rv == 1);
    1190                 :             :             break;
    1191                 :           1 :         case UnlockCommand:
    1192                 :           1 :             ReleaseDirectoryLocks();
    1193                 :           1 :             ch = ResUnlockSuccess; // Always succeeds
    1194                 :           1 :             rv = write(fd, &ch, 1);
    1195         [ +  - ]:           1 :             assert(rv == 1);
    1196                 :             :             break;
    1197                 :           1 :         case ExitCommand:
    1198                 :           1 :             close(fd);
    1199                 :           1 :             exit(0);
    1200                 :           0 :         default:
    1201                 :           0 :             assert(0);
    1202                 :             :         }
    1203                 :             :     }
    1204                 :             : }
    1205                 :             : #endif
    1206                 :             : 
    1207   [ +  -  +  -  :          12 : BOOST_AUTO_TEST_CASE(test_LockDirectory)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1208                 :             : {
    1209         [ +  - ]:           4 :     fs::path dirname = m_args.GetDataDirBase() / "lock_dir";
    1210         [ +  - ]:           2 :     const fs::path lockname = ".lock";
    1211                 :             : #ifndef WIN32
    1212                 :             :     // Revert SIGCHLD to default, otherwise boost.test will catch and fail on
    1213                 :             :     // it: there is BOOST_TEST_IGNORE_SIGCHLD but that only works when defined
    1214                 :             :     // at build-time of the boost library
    1215                 :           2 :     void (*old_handler)(int) = signal(SIGCHLD, SIG_DFL);
    1216                 :             : 
    1217                 :             :     // Fork another process for testing before creating the lock, so that we
    1218                 :             :     // won't fork while holding the lock (which might be undefined, and is not
    1219                 :             :     // relevant as test case as that is avoided with -daemonize).
    1220                 :           2 :     int fd[2];
    1221   [ +  -  +  - ]:           2 :     BOOST_CHECK_EQUAL(socketpair(AF_UNIX, SOCK_STREAM, 0, fd), 0);
    1222                 :           2 :     pid_t pid = fork();
    1223         [ +  + ]:           2 :     if (!pid) {
    1224   [ +  -  +  -  :           1 :         BOOST_CHECK_EQUAL(close(fd[1]), 0); // Child: close parent end
                   +  - ]
    1225   [ +  -  +  - ]:           1 :         TestOtherProcess(dirname, lockname, fd[0]);
    1226                 :             :     }
    1227   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(close(fd[0]), 0); // Parent: close child end
                   +  - ]
    1228                 :             : 
    1229                 :           1 :     char ch;
    1230                 :             :     // Lock on non-existent directory should fail
    1231   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(write(fd[1], &LockCommand, 1), 1);
                   +  - ]
    1232   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(read(fd[1], &ch, 1), 1);
                   +  - ]
    1233   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(ch, ResErrorWrite);
    1234                 :             : #endif
    1235                 :             :     // Lock on non-existent directory should fail
    1236   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(util::LockDirectory(dirname, lockname), util::LockResult::ErrorWrite);
                   +  - ]
    1237                 :             : 
    1238         [ +  - ]:           1 :     fs::create_directories(dirname);
    1239                 :             : 
    1240                 :             :     // Probing lock on new directory should succeed
    1241   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(util::LockDirectory(dirname, lockname, true), util::LockResult::Success);
                   +  - ]
    1242                 :             : 
    1243                 :             :     // Persistent lock on new directory should succeed
    1244   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(util::LockDirectory(dirname, lockname), util::LockResult::Success);
                   +  - ]
    1245                 :             : 
    1246                 :             :     // Another lock on the directory from the same thread should succeed
    1247   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(util::LockDirectory(dirname, lockname), util::LockResult::Success);
                   +  - ]
    1248                 :             : 
    1249                 :             :     // Another lock on the directory from a different thread within the same process should succeed
    1250                 :           1 :     util::LockResult threadresult;
    1251         [ +  - ]:           2 :     std::thread thr([&] { threadresult = util::LockDirectory(dirname, lockname); });
    1252         [ +  - ]:           1 :     thr.join();
    1253   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(threadresult, util::LockResult::Success);
    1254                 :             : #ifndef WIN32
    1255                 :             :     // Try to acquire lock in child process while we're holding it, this should fail.
    1256   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(write(fd[1], &LockCommand, 1), 1);
                   +  - ]
    1257   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(read(fd[1], &ch, 1), 1);
                   +  - ]
    1258   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(ch, ResErrorLock);
    1259                 :             : 
    1260                 :             :     // Give up our lock
    1261         [ +  - ]:           1 :     ReleaseDirectoryLocks();
    1262                 :             :     // Probing lock from our side now should succeed, but not hold on to the lock.
    1263   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(util::LockDirectory(dirname, lockname, true), util::LockResult::Success);
                   +  - ]
    1264                 :             : 
    1265                 :             :     // Try to acquire the lock in the child process, this should be successful.
    1266   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(write(fd[1], &LockCommand, 1), 1);
                   +  - ]
    1267   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(read(fd[1], &ch, 1), 1);
                   +  - ]
    1268   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(ch, ResSuccess);
    1269                 :             : 
    1270                 :             :     // When we try to probe the lock now, it should fail.
    1271   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(util::LockDirectory(dirname, lockname, true), util::LockResult::ErrorLock);
                   +  - ]
    1272                 :             : 
    1273                 :             :     // Unlock the lock in the child process
    1274   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(write(fd[1], &UnlockCommand, 1), 1);
                   +  - ]
    1275   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(read(fd[1], &ch, 1), 1);
                   +  - ]
    1276   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(ch, ResUnlockSuccess);
    1277                 :             : 
    1278                 :             :     // When we try to probe the lock now, it should succeed.
    1279   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(util::LockDirectory(dirname, lockname, true), util::LockResult::Success);
                   +  - ]
    1280                 :             : 
    1281                 :             :     // Re-lock the lock in the child process, then wait for it to exit, check
    1282                 :             :     // successful return. After that, we check that exiting the process
    1283                 :             :     // has released the lock as we would expect by probing it.
    1284                 :           1 :     int processstatus;
    1285   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(write(fd[1], &LockCommand, 1), 1);
                   +  - ]
    1286                 :             :     // The following line invokes the ~CNetCleanup dtor without
    1287                 :             :     // a paired SetupNetworking call. This is acceptable as long as
    1288                 :             :     // ~CNetCleanup is a no-op for non-Windows platforms.
    1289   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(write(fd[1], &ExitCommand, 1), 1);
                   +  - ]
    1290   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(waitpid(pid, &processstatus, 0), pid);
                   +  - ]
    1291   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(processstatus, 0);
    1292   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(util::LockDirectory(dirname, lockname, true), util::LockResult::Success);
                   +  - ]
    1293                 :             : 
    1294                 :             :     // Restore SIGCHLD
    1295                 :           1 :     signal(SIGCHLD, old_handler);
    1296   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(close(fd[1]), 0); // Close our side of the socketpair
                   +  - ]
    1297                 :             : #endif
    1298                 :             :     // Clean up
    1299         [ +  - ]:           1 :     ReleaseDirectoryLocks();
    1300         [ +  - ]:           1 :     fs::remove_all(dirname);
    1301                 :           3 : }
    1302                 :             : 
    1303   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(test_ToLower)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1304                 :             : {
    1305         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(ToLower('@'), '@');
    1306         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(ToLower('A'), 'a');
    1307         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(ToLower('Z'), 'z');
    1308         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(ToLower('['), '[');
    1309         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(ToLower(0), 0);
    1310         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(ToLower('\xff'), '\xff');
    1311                 :             : 
    1312         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(ToLower(""), "");
    1313         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(ToLower("#HODL"), "#hodl");
    1314         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(ToLower("\x00\xfe\xff"), "\x00\xfe\xff");
    1315                 :           1 : }
    1316                 :             : 
    1317   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(test_ToUpper)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1318                 :             : {
    1319         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(ToUpper('`'), '`');
    1320         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(ToUpper('a'), 'A');
    1321         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(ToUpper('z'), 'Z');
    1322         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(ToUpper('{'), '{');
    1323         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(ToUpper(0), 0);
    1324         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(ToUpper('\xff'), '\xff');
    1325                 :             : 
    1326         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(ToUpper(""), "");
    1327         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(ToUpper("#hodl"), "#HODL");
    1328         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(ToUpper("\x00\xfe\xff"), "\x00\xfe\xff");
    1329                 :           1 : }
    1330                 :             : 
    1331   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(test_Capitalize)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1332                 :             : {
    1333   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(Capitalize(""), "");
    1334   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(Capitalize("bitcoin"), "Bitcoin");
    1335   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(Capitalize("\x00\xfe\xff"), "\x00\xfe\xff");
    1336                 :           1 : }
    1337                 :             : 
    1338                 :          28 : static std::string SpanToStr(const Span<const char>& span)
    1339                 :             : {
    1340                 :          28 :     return std::string(span.begin(), span.end());
    1341                 :             : }
    1342                 :             : 
    1343   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(test_script_parsing)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1344                 :             : {
    1345                 :           1 :     using namespace script;
    1346         [ +  - ]:           1 :     std::string input;
    1347                 :           1 :     Span<const char> sp;
    1348                 :           1 :     bool success;
    1349                 :             : 
    1350                 :             :     // Const(...): parse a constant, update span to skip it if successful
    1351         [ +  - ]:           1 :     input = "MilkToastHoney";
    1352         [ +  - ]:           1 :     sp = input;
    1353   [ +  -  +  - ]:           1 :     success = Const("", sp); // empty
    1354   [ +  -  +  -  :           2 :     BOOST_CHECK(success);
                   +  - ]
    1355   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(sp), "MilkToastHoney");
                   +  - ]
    1356                 :             : 
    1357   [ +  -  +  - ]:           1 :     success = Const("Milk", sp);
    1358   [ +  -  +  -  :           2 :     BOOST_CHECK(success);
                   +  - ]
    1359   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(sp), "ToastHoney");
                   +  - ]
    1360                 :             : 
    1361   [ +  -  +  - ]:           1 :     success = Const("Bread", sp);
    1362   [ +  -  +  -  :           2 :     BOOST_CHECK(!success);
                   +  - ]
    1363                 :             : 
    1364   [ +  -  +  - ]:           1 :     success = Const("Toast", sp);
    1365   [ +  -  +  -  :           2 :     BOOST_CHECK(success);
                   +  - ]
    1366   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(sp), "Honey");
                   +  - ]
    1367                 :             : 
    1368   [ +  -  +  - ]:           1 :     success = Const("Honeybadger", sp);
    1369   [ +  -  +  -  :           2 :     BOOST_CHECK(!success);
                   +  - ]
    1370                 :             : 
    1371   [ +  -  +  - ]:           1 :     success = Const("Honey", sp);
    1372   [ +  -  +  -  :           2 :     BOOST_CHECK(success);
                   +  - ]
    1373   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(sp), "");
                   +  - ]
    1374                 :             : 
    1375                 :             :     // Func(...): parse a function call, update span to argument if successful
    1376         [ +  - ]:           1 :     input = "Foo(Bar(xy,z()))";
    1377         [ +  - ]:           1 :     sp = input;
    1378                 :             : 
    1379   [ +  -  +  - ]:           1 :     success = Func("FooBar", sp);
    1380   [ +  -  +  -  :           2 :     BOOST_CHECK(!success);
                   +  - ]
    1381                 :             : 
    1382   [ +  -  +  - ]:           1 :     success = Func("Foo(", sp);
    1383   [ +  -  +  -  :           2 :     BOOST_CHECK(!success);
                   +  - ]
    1384                 :             : 
    1385   [ +  -  +  - ]:           1 :     success = Func("Foo", sp);
    1386   [ +  -  +  -  :           2 :     BOOST_CHECK(success);
                   +  - ]
    1387   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(sp), "Bar(xy,z())");
                   +  - ]
    1388                 :             : 
    1389   [ +  -  +  - ]:           1 :     success = Func("Bar", sp);
    1390   [ +  -  +  -  :           2 :     BOOST_CHECK(success);
                   +  - ]
    1391   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(sp), "xy,z()");
                   +  - ]
    1392                 :             : 
    1393   [ +  -  +  - ]:           1 :     success = Func("xy", sp);
    1394   [ +  -  +  -  :           2 :     BOOST_CHECK(!success);
                   +  - ]
    1395                 :             : 
    1396                 :             :     // Expr(...): return expression that span begins with, update span to skip it
    1397                 :           1 :     Span<const char> result;
    1398                 :             : 
    1399         [ +  - ]:           1 :     input = "(n*(n-1))/2";
    1400         [ +  - ]:           1 :     sp = input;
    1401         [ +  - ]:           1 :     result = Expr(sp);
    1402   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(result), "(n*(n-1))/2");
                   +  - ]
    1403   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(sp), "");
                   +  - ]
    1404                 :             : 
    1405         [ +  - ]:           1 :     input = "foo,bar";
    1406         [ +  - ]:           1 :     sp = input;
    1407         [ +  - ]:           1 :     result = Expr(sp);
    1408   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(result), "foo");
                   +  - ]
    1409   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(sp), ",bar");
                   +  - ]
    1410                 :             : 
    1411         [ +  - ]:           1 :     input = "(aaaaa,bbbbb()),c";
    1412         [ +  - ]:           1 :     sp = input;
    1413         [ +  - ]:           1 :     result = Expr(sp);
    1414   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(result), "(aaaaa,bbbbb())");
                   +  - ]
    1415   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(sp), ",c");
                   +  - ]
    1416                 :             : 
    1417         [ +  - ]:           1 :     input = "xyz)foo";
    1418         [ +  - ]:           1 :     sp = input;
    1419         [ +  - ]:           1 :     result = Expr(sp);
    1420   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(result), "xyz");
                   +  - ]
    1421   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(sp), ")foo");
                   +  - ]
    1422                 :             : 
    1423         [ +  - ]:           1 :     input = "((a),(b),(c)),xxx";
    1424         [ +  - ]:           1 :     sp = input;
    1425         [ +  - ]:           1 :     result = Expr(sp);
    1426   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(result), "((a),(b),(c))");
                   +  - ]
    1427   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(sp), ",xxx");
                   +  - ]
    1428                 :             : 
    1429                 :             :     // Split(...): split a string on every instance of sep, return vector
    1430                 :           1 :     std::vector<Span<const char>> results;
    1431                 :             : 
    1432         [ +  - ]:           1 :     input = "xxx";
    1433         [ +  - ]:           2 :     results = Split(input, 'x');
    1434   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(results.size(), 4U);
    1435   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(results[0]), "");
                   +  - ]
    1436   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(results[1]), "");
                   +  - ]
    1437   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(results[2]), "");
                   +  - ]
    1438   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(results[3]), "");
                   +  - ]
    1439                 :             : 
    1440         [ +  - ]:           1 :     input = "one#two#three";
    1441         [ +  - ]:           2 :     results = Split(input, '-');
    1442   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(results.size(), 1U);
    1443   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(results[0]), "one#two#three");
                   +  - ]
    1444                 :             : 
    1445         [ +  - ]:           1 :     input = "one#two#three";
    1446         [ +  - ]:           2 :     results = Split(input, '#');
    1447   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(results.size(), 3U);
    1448   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(results[0]), "one");
                   +  - ]
    1449   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(results[1]), "two");
                   +  - ]
    1450   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(results[2]), "three");
                   +  - ]
    1451                 :             : 
    1452         [ +  - ]:           1 :     input = "*foo*bar*";
    1453         [ +  - ]:           2 :     results = Split(input, '*');
    1454   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(results.size(), 4U);
    1455   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(results[0]), "");
                   +  - ]
    1456   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(results[1]), "foo");
                   +  - ]
    1457   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(results[2]), "bar");
                   +  - ]
    1458   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(SpanToStr(results[3]), "");
                   +  - ]
    1459                 :           1 : }
    1460                 :             : 
    1461   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(test_SplitString)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1462                 :             : {
    1463                 :             :     // Empty string.
    1464                 :           1 :     {
    1465                 :           1 :         std::vector<std::string> result = SplitString("", '-');
    1466   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(result.size(), 1);
    1467   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(result[0], "");
    1468                 :           1 :     }
    1469                 :             : 
    1470                 :             :     // Empty items.
    1471                 :           1 :     {
    1472                 :           1 :         std::vector<std::string> result = SplitString("-", '-');
    1473   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(result.size(), 2);
    1474   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(result[0], "");
    1475   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(result[1], "");
    1476                 :           1 :     }
    1477                 :             : 
    1478                 :             :     // More empty items.
    1479                 :           1 :     {
    1480                 :           1 :         std::vector<std::string> result = SplitString("--", '-');
    1481   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(result.size(), 3);
    1482   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(result[0], "");
    1483   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(result[1], "");
    1484   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(result[2], "");
    1485                 :           1 :     }
    1486                 :             : 
    1487                 :             :     // Separator is not present.
    1488                 :           1 :     {
    1489                 :           1 :         std::vector<std::string> result = SplitString("abc", '-');
    1490   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(result.size(), 1);
    1491   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(result[0], "abc");
    1492                 :           1 :     }
    1493                 :             : 
    1494                 :             :     // Basic behavior.
    1495                 :           1 :     {
    1496                 :           1 :         std::vector<std::string> result = SplitString("a-b", '-');
    1497   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(result.size(), 2);
    1498   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(result[0], "a");
    1499   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(result[1], "b");
    1500                 :           1 :     }
    1501                 :             : 
    1502                 :             :     // Case-sensitivity of the separator.
    1503                 :           1 :     {
    1504                 :           1 :         std::vector<std::string> result = SplitString("AAA", 'a');
    1505   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(result.size(), 1);
    1506   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(result[0], "AAA");
    1507                 :           1 :     }
    1508                 :             : 
    1509                 :             :     // multiple split characters
    1510                 :           1 :     {
    1511                 :           1 :         using V = std::vector<std::string>;
    1512   [ +  -  +  +  :           9 :         BOOST_TEST(SplitString("a,b.c:d;e", ",;") == V({"a", "b.c:d", "e"}));
          +  -  +  -  +  
          -  +  -  +  +  
             -  -  -  - ]
    1513   [ +  -  +  +  :          13 :         BOOST_TEST(SplitString("a,b.c:d;e", ",;:.") == V({"a", "b", "c", "d", "e"}));
          +  -  +  -  +  
          -  +  -  +  +  
             -  -  -  - ]
    1514   [ +  -  +  +  :           5 :         BOOST_TEST(SplitString("a,b.c:d;e", "") == V({"a,b.c:d;e"}));
          +  -  +  -  +  
          -  +  -  +  +  
             -  -  -  - ]
    1515   [ +  -  +  +  :           5 :         BOOST_TEST(SplitString("aaa", "bcdefg") == V({"aaa"}));
          +  -  +  -  +  
          -  +  -  +  +  
             -  -  -  - ]
    1516   [ +  -  +  +  :           8 :         BOOST_TEST(SplitString("x\0a,b"s, "\0"s) == V({"x", "a,b"}));
          +  -  +  -  +  
          -  +  -  +  -  
          +  +  -  -  -  
                      - ]
    1517   [ +  -  +  +  :           8 :         BOOST_TEST(SplitString("x\0a,b"s, '\0') == V({"x", "a,b"}));
          +  -  +  -  +  
          -  +  -  +  +  
             -  -  -  - ]
    1518   [ +  -  +  +  :          10 :         BOOST_TEST(SplitString("x\0a,b"s, "\0,"s) == V({"x", "a", "b"}));
          +  -  +  -  +  
          -  +  -  +  -  
          +  +  -  -  -  
                      - ]
    1519   [ +  -  +  +  :          11 :         BOOST_TEST(SplitString("abcdefg", "bcd") == V({"a", "", "", "efg"}));
          +  -  +  -  +  
          -  +  -  +  +  
             -  -  -  - ]
    1520                 :             :     }
    1521                 :           1 : }
    1522                 :             : 
    1523   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(test_LogEscapeMessage)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1524                 :             : {
    1525                 :             :     // ASCII and UTF-8 must pass through unaltered.
    1526         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(BCLog::LogEscapeMessage("Valid log message貓"), "Valid log message貓");
    1527                 :             :     // Newlines must pass through unaltered.
    1528         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(BCLog::LogEscapeMessage("Message\n with newlines\n"), "Message\n with newlines\n");
    1529                 :             :     // Other control characters are escaped in C syntax.
    1530         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(BCLog::LogEscapeMessage("\x01\x7f Corrupted log message\x0d"), R"(\x01\x7f Corrupted log message\x0d)");
    1531                 :             :     // Embedded NULL characters are escaped too.
    1532                 :           1 :     const std::string NUL("O\x00O", 3);
    1533   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(BCLog::LogEscapeMessage(NUL), R"(O\x00O)");
                   +  - ]
    1534                 :           1 : }
    1535                 :             : 
    1536                 :             : namespace {
    1537                 :             : 
    1538                 :             : struct Tracker
    1539                 :             : {
    1540                 :             :     //! Points to the original object (possibly itself) we moved/copied from
    1541                 :             :     const Tracker* origin;
    1542                 :             :     //! How many copies where involved between the original object and this one (moves are not counted)
    1543                 :             :     int copies{0};
    1544                 :             : 
    1545                 :           1 :     Tracker() noexcept : origin(this) {}
    1546                 :          10 :     Tracker(const Tracker& t) noexcept : origin(t.origin), copies(t.copies + 1) {}
    1547                 :          13 :     Tracker(Tracker&& t) noexcept : origin(t.origin), copies(t.copies) {}
    1548                 :             :     Tracker& operator=(const Tracker& t) noexcept
    1549                 :             :     {
    1550                 :             :         if (this != &t) {
    1551                 :             :             origin = t.origin;
    1552                 :             :             copies = t.copies + 1;
    1553                 :             :         }
    1554                 :             :         return *this;
    1555                 :             :     }
    1556                 :             : };
    1557                 :             : 
    1558                 :             : }
    1559                 :             : 
    1560   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(test_tracked_vector)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1561                 :             : {
    1562                 :           1 :     Tracker t1;
    1563                 :           1 :     Tracker t2;
    1564                 :           1 :     Tracker t3;
    1565                 :             : 
    1566         [ +  - ]:           2 :     BOOST_CHECK(t1.origin == &t1);
    1567         [ +  - ]:           2 :     BOOST_CHECK(t2.origin == &t2);
    1568         [ +  - ]:           2 :     BOOST_CHECK(t3.origin == &t3);
    1569                 :             : 
    1570                 :           1 :     auto v1 = Vector(t1);
    1571   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v1.size(), 1U);
    1572   [ +  -  +  -  :           2 :     BOOST_CHECK(v1[0].origin == &t1);
                   +  - ]
    1573   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v1[0].copies, 1);
    1574                 :             : 
    1575         [ +  - ]:           1 :     auto v2 = Vector(std::move(t2));
    1576   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v2.size(), 1U);
    1577   [ +  -  +  -  :           2 :     BOOST_CHECK(v2[0].origin == &t2); // NOLINT(*-use-after-move)
                   +  - ]
    1578   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v2[0].copies, 0);
    1579                 :             : 
    1580         [ +  - ]:           1 :     auto v3 = Vector(t1, std::move(t2));
    1581   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v3.size(), 2U);
    1582   [ +  -  +  -  :           2 :     BOOST_CHECK(v3[0].origin == &t1);
                   +  - ]
    1583   [ +  -  +  -  :           2 :     BOOST_CHECK(v3[1].origin == &t2); // NOLINT(*-use-after-move)
                   +  - ]
    1584   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v3[0].copies, 1);
    1585   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v3[1].copies, 0);
    1586                 :             : 
    1587         [ +  - ]:           1 :     auto v4 = Vector(std::move(v3[0]), v3[1], std::move(t3));
    1588   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v4.size(), 3U);
    1589   [ +  -  +  -  :           2 :     BOOST_CHECK(v4[0].origin == &t1);
                   +  - ]
    1590   [ +  -  +  -  :           2 :     BOOST_CHECK(v4[1].origin == &t2);
                   +  - ]
    1591   [ +  -  +  -  :           2 :     BOOST_CHECK(v4[2].origin == &t3); // NOLINT(*-use-after-move)
                   +  - ]
    1592   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v4[0].copies, 1);
    1593   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v4[1].copies, 1);
    1594   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v4[2].copies, 0);
    1595                 :             : 
    1596   [ +  -  +  - ]:           1 :     auto v5 = Cat(v1, v4);
    1597   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v5.size(), 4U);
    1598   [ +  -  +  -  :           2 :     BOOST_CHECK(v5[0].origin == &t1);
                   +  - ]
    1599   [ +  -  +  -  :           2 :     BOOST_CHECK(v5[1].origin == &t1);
                   +  - ]
    1600   [ +  -  +  -  :           2 :     BOOST_CHECK(v5[2].origin == &t2);
                   +  - ]
    1601   [ +  -  +  -  :           2 :     BOOST_CHECK(v5[3].origin == &t3);
                   +  - ]
    1602   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v5[0].copies, 2);
    1603   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v5[1].copies, 2);
    1604   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v5[2].copies, 2);
    1605   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v5[3].copies, 1);
    1606                 :             : 
    1607         [ +  - ]:           1 :     auto v6 = Cat(std::move(v1), v3);
    1608   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v6.size(), 3U);
    1609   [ +  -  +  -  :           2 :     BOOST_CHECK(v6[0].origin == &t1);
                   +  - ]
    1610   [ +  -  +  -  :           2 :     BOOST_CHECK(v6[1].origin == &t1);
                   +  - ]
    1611   [ +  -  +  -  :           2 :     BOOST_CHECK(v6[2].origin == &t2);
                   +  - ]
    1612   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v6[0].copies, 1);
    1613   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v6[1].copies, 2);
    1614   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v6[2].copies, 1);
    1615                 :             : 
    1616   [ +  -  +  - ]:           1 :     auto v7 = Cat(v2, std::move(v4));
    1617   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v7.size(), 4U);
    1618   [ +  -  +  -  :           2 :     BOOST_CHECK(v7[0].origin == &t2);
                   +  - ]
    1619   [ +  -  +  -  :           2 :     BOOST_CHECK(v7[1].origin == &t1);
                   +  - ]
    1620   [ +  -  +  -  :           2 :     BOOST_CHECK(v7[2].origin == &t2);
                   +  - ]
    1621   [ +  -  +  -  :           2 :     BOOST_CHECK(v7[3].origin == &t3);
                   +  - ]
    1622   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v7[0].copies, 1);
    1623   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v7[1].copies, 1);
    1624   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v7[2].copies, 1);
    1625   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v7[3].copies, 0);
    1626                 :             : 
    1627         [ +  - ]:           1 :     auto v8 = Cat(std::move(v2), std::move(v3));
    1628   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v8.size(), 3U);
    1629   [ +  -  +  -  :           2 :     BOOST_CHECK(v8[0].origin == &t2);
                   +  - ]
    1630   [ +  -  +  -  :           2 :     BOOST_CHECK(v8[1].origin == &t1);
                   +  - ]
    1631   [ +  -  +  -  :           2 :     BOOST_CHECK(v8[2].origin == &t2);
                   +  - ]
    1632   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v8[0].copies, 0);
    1633   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v8[1].copies, 1);
    1634   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(v8[2].copies, 0);
    1635                 :           1 : }
    1636                 :             : 
    1637   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(message_sign)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1638                 :             : {
    1639                 :           1 :     const std::array<unsigned char, 32> privkey_bytes = {
    1640                 :             :         // just some random data
    1641                 :             :         // derived address from this private key: 15CRxFdyRpGZLW9w8HnHvVduizdL5jKNbs
    1642                 :             :         0xD9, 0x7F, 0x51, 0x08, 0xF1, 0x1C, 0xDA, 0x6E,
    1643                 :             :         0xEE, 0xBA, 0xAA, 0x42, 0x0F, 0xEF, 0x07, 0x26,
    1644                 :             :         0xB1, 0xF8, 0x98, 0x06, 0x0B, 0x98, 0x48, 0x9F,
    1645                 :             :         0xA3, 0x09, 0x84, 0x63, 0xC0, 0x03, 0x28, 0x66
    1646                 :             :     };
    1647                 :             : 
    1648                 :           1 :     const std::string message = "Trust no one";
    1649                 :             : 
    1650         [ +  - ]:           1 :     const std::string expected_signature =
    1651         [ +  - ]:           1 :         "IPojfrX2dfPnH26UegfbGQQLrdK844DlHq5157/P6h57WyuS/Qsl+h/WSVGDF4MUi4rWSswW38oimDYfNNUBUOk=";
    1652                 :             : 
    1653                 :           1 :     CKey privkey;
    1654         [ +  - ]:           1 :     std::string generated_signature;
    1655                 :             : 
    1656   [ +  -  +  -  :           2 :     BOOST_REQUIRE_MESSAGE(!privkey.IsValid(),
                   +  - ]
    1657                 :             :         "Confirm the private key is invalid");
    1658                 :             : 
    1659   [ +  -  +  -  :           2 :     BOOST_CHECK_MESSAGE(!MessageSign(privkey, message, generated_signature),
             +  -  +  - ]
    1660                 :             :         "Sign with an invalid private key");
    1661                 :             : 
    1662         [ +  - ]:           1 :     privkey.Set(privkey_bytes.begin(), privkey_bytes.end(), true);
    1663                 :             : 
    1664   [ +  -  +  -  :           2 :     BOOST_REQUIRE_MESSAGE(privkey.IsValid(),
                   +  - ]
    1665                 :             :         "Confirm the private key is valid");
    1666                 :             : 
    1667   [ +  -  +  -  :           2 :     BOOST_CHECK_MESSAGE(MessageSign(privkey, message, generated_signature),
             +  -  +  - ]
    1668                 :             :         "Sign with a valid private key");
    1669                 :             : 
    1670   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(expected_signature, generated_signature);
    1671                 :           1 : }
    1672                 :             : 
    1673   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(message_verify)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1674                 :             : {
    1675   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(
             +  -  +  - ]
    1676                 :             :         MessageVerify(
    1677                 :             :             "invalid address",
    1678                 :             :             "signature should be irrelevant",
    1679                 :             :             "message too"),
    1680                 :             :         MessageVerificationResult::ERR_INVALID_ADDRESS);
    1681                 :             : 
    1682   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(
             +  -  +  - ]
    1683                 :             :         MessageVerify(
    1684                 :             :             "3B5fQsEXEaV8v6U3ejYc8XaKXAkyQj2MjV",
    1685                 :             :             "signature should be irrelevant",
    1686                 :             :             "message too"),
    1687                 :             :         MessageVerificationResult::ERR_ADDRESS_NO_KEY);
    1688                 :             : 
    1689   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(
             +  -  +  - ]
    1690                 :             :         MessageVerify(
    1691                 :             :             "1KqbBpLy5FARmTPD4VZnDDpYjkUvkr82Pm",
    1692                 :             :             "invalid signature, not in base64 encoding",
    1693                 :             :             "message should be irrelevant"),
    1694                 :             :         MessageVerificationResult::ERR_MALFORMED_SIGNATURE);
    1695                 :             : 
    1696   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(
             +  -  +  - ]
    1697                 :             :         MessageVerify(
    1698                 :             :             "1KqbBpLy5FARmTPD4VZnDDpYjkUvkr82Pm",
    1699                 :             :             "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
    1700                 :             :             "message should be irrelevant"),
    1701                 :             :         MessageVerificationResult::ERR_PUBKEY_NOT_RECOVERED);
    1702                 :             : 
    1703   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(
             +  -  +  - ]
    1704                 :             :         MessageVerify(
    1705                 :             :             "15CRxFdyRpGZLW9w8HnHvVduizdL5jKNbs",
    1706                 :             :             "IPojfrX2dfPnH26UegfbGQQLrdK844DlHq5157/P6h57WyuS/Qsl+h/WSVGDF4MUi4rWSswW38oimDYfNNUBUOk=",
    1707                 :             :             "I never signed this"),
    1708                 :             :         MessageVerificationResult::ERR_NOT_SIGNED);
    1709                 :             : 
    1710   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(
             +  -  +  - ]
    1711                 :             :         MessageVerify(
    1712                 :             :             "15CRxFdyRpGZLW9w8HnHvVduizdL5jKNbs",
    1713                 :             :             "IPojfrX2dfPnH26UegfbGQQLrdK844DlHq5157/P6h57WyuS/Qsl+h/WSVGDF4MUi4rWSswW38oimDYfNNUBUOk=",
    1714                 :             :             "Trust no one"),
    1715                 :             :         MessageVerificationResult::OK);
    1716                 :             : 
    1717   [ +  -  +  -  :           1 :     BOOST_CHECK_EQUAL(
             +  -  +  - ]
    1718                 :             :         MessageVerify(
    1719                 :             :             "11canuhp9X2NocwCq7xNrQYTmUgZAnLK3",
    1720                 :             :             "IIcaIENoYW5jZWxsb3Igb24gYnJpbmsgb2Ygc2Vjb25kIGJhaWxvdXQgZm9yIGJhbmtzIAaHRtbCeDZINyavx14=",
    1721                 :             :             "Trust me"),
    1722                 :             :         MessageVerificationResult::OK);
    1723                 :           1 : }
    1724                 :             : 
    1725   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(message_hash)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1726                 :             : {
    1727                 :           1 :     const std::string unsigned_tx = "...";
    1728         [ +  - ]:           1 :     const std::string prefixed_message =
    1729         [ +  - ]:           2 :         std::string(1, (char)MESSAGE_MAGIC.length()) +
    1730         [ +  - ]:           2 :         MESSAGE_MAGIC +
    1731   [ +  -  +  -  :           2 :         std::string(1, (char)unsigned_tx.length()) +
                   +  - ]
    1732         [ +  - ]:           1 :         unsigned_tx;
    1733                 :             : 
    1734         [ +  - ]:           1 :     const uint256 signature_hash = Hash(unsigned_tx);
    1735         [ +  - ]:           1 :     const uint256 message_hash1 = Hash(prefixed_message);
    1736         [ +  - ]:           1 :     const uint256 message_hash2 = MessageHash(unsigned_tx);
    1737                 :             : 
    1738   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(message_hash1, message_hash2);
    1739   [ +  -  +  - ]:           1 :     BOOST_CHECK_NE(message_hash1, signature_hash);
    1740                 :           1 : }
    1741                 :             : 
    1742   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(remove_prefix)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1743                 :             : {
    1744         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(RemovePrefix("./common/system.h", "./"), "common/system.h");
    1745         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(RemovePrefixView("foo", "foo"), "");
    1746         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(RemovePrefix("foo", "fo"), "o");
    1747         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(RemovePrefixView("foo", "f"), "oo");
    1748         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(RemovePrefix("foo", ""), "foo");
    1749         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(RemovePrefixView("fo", "foo"), "fo");
    1750         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(RemovePrefix("f", "foo"), "f");
    1751         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(RemovePrefixView("", "foo"), "");
    1752         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(RemovePrefix("", ""), "");
    1753                 :           1 : }
    1754                 :             : 
    1755   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(util_ParseByteUnits)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1756                 :             : {
    1757                 :           1 :     auto noop = ByteUnit::NOOP;
    1758                 :             : 
    1759                 :             :     // no multiplier
    1760   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(ParseByteUnits("1", noop).value(), 1);
    1761   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(ParseByteUnits("0", noop).value(), 0);
    1762                 :             : 
    1763   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(ParseByteUnits("1k", noop).value(), 1000ULL);
    1764   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(ParseByteUnits("1K", noop).value(), 1ULL << 10);
    1765                 :             : 
    1766   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(ParseByteUnits("2m", noop).value(), 2'000'000ULL);
    1767   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(ParseByteUnits("2M", noop).value(), 2ULL << 20);
    1768                 :             : 
    1769   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(ParseByteUnits("3g", noop).value(), 3'000'000'000ULL);
    1770   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(ParseByteUnits("3G", noop).value(), 3ULL << 30);
    1771                 :             : 
    1772   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(ParseByteUnits("4t", noop).value(), 4'000'000'000'000ULL);
    1773   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(ParseByteUnits("4T", noop).value(), 4ULL << 40);
    1774                 :             : 
    1775                 :             :     // check default multiplier
    1776   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(ParseByteUnits("5", ByteUnit::K).value(), 5ULL << 10);
    1777                 :             : 
    1778                 :             :     // NaN
    1779   [ +  -  +  - ]:           2 :     BOOST_CHECK(!ParseByteUnits("", noop));
    1780   [ +  -  +  - ]:           2 :     BOOST_CHECK(!ParseByteUnits("foo", noop));
    1781                 :             : 
    1782                 :             :     // whitespace
    1783   [ +  -  +  - ]:           2 :     BOOST_CHECK(!ParseByteUnits("123m ", noop));
    1784   [ +  -  +  - ]:           2 :     BOOST_CHECK(!ParseByteUnits(" 123m", noop));
    1785                 :             : 
    1786                 :             :     // no +-
    1787   [ +  -  +  - ]:           2 :     BOOST_CHECK(!ParseByteUnits("-123m", noop));
    1788   [ +  -  +  - ]:           2 :     BOOST_CHECK(!ParseByteUnits("+123m", noop));
    1789                 :             : 
    1790                 :             :     // zero padding
    1791   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(ParseByteUnits("020M", noop).value(), 20ULL << 20);
    1792                 :             : 
    1793                 :             :     // fractions not allowed
    1794   [ +  -  +  - ]:           2 :     BOOST_CHECK(!ParseByteUnits("0.5T", noop));
    1795                 :             : 
    1796                 :             :     // overflow
    1797   [ +  -  +  - ]:           2 :     BOOST_CHECK(!ParseByteUnits("18446744073709551615g", noop));
    1798                 :             : 
    1799                 :             :     // invalid unit
    1800   [ +  -  +  - ]:           2 :     BOOST_CHECK(!ParseByteUnits("1x", noop));
    1801                 :           1 : }
    1802                 :             : 
    1803   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(util_ReadBinaryFile)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1804                 :             : {
    1805                 :           1 :     fs::path tmpfolder = m_args.GetDataDirBase();
    1806   [ +  -  +  - ]:           2 :     fs::path tmpfile = tmpfolder / "read_binary.dat";
    1807                 :           1 :     std::string expected_text;
    1808         [ +  + ]:          31 :     for (int i = 0; i < 30; i++) {
    1809         [ +  - ]:          30 :         expected_text += "0123456789";
    1810                 :             :     }
    1811                 :           1 :     {
    1812         [ +  - ]:           1 :         std::ofstream file{tmpfile};
    1813         [ +  - ]:           1 :         file << expected_text;
    1814                 :           1 :     }
    1815                 :           1 :     {
    1816                 :             :         // read all contents in file
    1817   [ +  -  +  - ]:           1 :         auto [valid, text] = ReadBinaryFile(tmpfile);
    1818   [ +  -  +  -  :           2 :         BOOST_CHECK(valid);
                   +  - ]
    1819   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(text, expected_text);
    1820                 :           0 :     }
    1821                 :           1 :     {
    1822                 :             :         // read half contents in file
    1823   [ +  -  +  - ]:           1 :         auto [valid, text] = ReadBinaryFile(tmpfile, expected_text.size() / 2);
    1824   [ +  -  +  -  :           2 :         BOOST_CHECK(valid);
                   +  - ]
    1825   [ +  -  +  -  :           1 :         BOOST_CHECK_EQUAL(text, expected_text.substr(0, expected_text.size() / 2));
                   +  - ]
    1826                 :           0 :     }
    1827                 :           1 :     {
    1828                 :             :         // read from non-existent file
    1829   [ +  -  +  - ]:           2 :         fs::path invalid_file = tmpfolder / "invalid_binary.dat";
    1830         [ +  - ]:           1 :         auto [valid, text] = ReadBinaryFile(invalid_file);
    1831   [ +  -  +  -  :           2 :         BOOST_CHECK(!valid);
                   +  - ]
    1832   [ +  -  +  - ]:           2 :         BOOST_CHECK(text.empty());
    1833                 :           2 :     }
    1834                 :           3 : }
    1835                 :             : 
    1836   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(util_WriteBinaryFile)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1837                 :             : {
    1838                 :           1 :     fs::path tmpfolder = m_args.GetDataDirBase();
    1839   [ +  -  +  - ]:           2 :     fs::path tmpfile = tmpfolder / "write_binary.dat";
    1840         [ +  - ]:           1 :     std::string expected_text = "bitcoin";
    1841         [ +  - ]:           1 :     auto valid = WriteBinaryFile(tmpfile, expected_text);
    1842         [ +  - ]:           1 :     std::string actual_text;
    1843         [ +  - ]:           1 :     std::ifstream file{tmpfile};
    1844         [ +  - ]:           1 :     file >> actual_text;
    1845   [ +  -  +  -  :           2 :     BOOST_CHECK(valid);
                   +  - ]
    1846   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(actual_text, expected_text);
    1847                 :           3 : }
    1848                 :             : 
    1849   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(clearshrink_test)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1850                 :             : {
    1851                 :           1 :     {
    1852                 :           1 :         std::vector<uint8_t> v = {1, 2, 3};
    1853                 :           1 :         ClearShrink(v);
    1854   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(v.size(), 0);
    1855   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(v.capacity(), 0);
    1856                 :           0 :     }
    1857                 :             : 
    1858                 :           1 :     {
    1859                 :           1 :         std::vector<bool> v = {false, true, false, false, true, true};
    1860                 :           1 :         ClearShrink(v);
    1861   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(v.size(), 0);
    1862   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(v.capacity(), 0);
    1863                 :           0 :     }
    1864                 :             : 
    1865                 :           1 :     {
    1866                 :           1 :         std::deque<int> v = {1, 3, 3, 7};
    1867                 :           1 :         ClearShrink(v);
    1868   [ +  -  +  - ]:           1 :         BOOST_CHECK_EQUAL(v.size(), 0);
    1869                 :             :         // std::deque has no capacity() we can observe.
    1870                 :           1 :     }
    1871                 :           1 : }
    1872                 :             : 
    1873                 :             : template <typename T>
    1874                 :           5 : void TestCheckedLeftShift()
    1875                 :             : {
    1876                 :           5 :     constexpr auto MAX{std::numeric_limits<T>::max()};
    1877                 :             : 
    1878                 :             :     // Basic operations
    1879         [ +  - ]:           5 :     BOOST_CHECK_EQUAL(CheckedLeftShift<T>(0, 1), 0);
    1880         [ +  - ]:           5 :     BOOST_CHECK_EQUAL(CheckedLeftShift<T>(0, 127), 0);
    1881         [ +  - ]:           5 :     BOOST_CHECK_EQUAL(CheckedLeftShift<T>(1, 1), 2);
    1882         [ +  - ]:           5 :     BOOST_CHECK_EQUAL(CheckedLeftShift<T>(2, 2), 8);
    1883         [ +  - ]:           5 :     BOOST_CHECK_EQUAL(CheckedLeftShift<T>(MAX >> 1, 1), MAX - 1);
    1884                 :             : 
    1885                 :             :     // Max left shift
    1886         [ +  - ]:           5 :     BOOST_CHECK_EQUAL(CheckedLeftShift<T>(1, std::numeric_limits<T>::digits - 1), MAX / 2 + 1);
    1887                 :             : 
    1888                 :             :     // Overflow cases
    1889         [ +  - ]:          10 :     BOOST_CHECK(!CheckedLeftShift<T>((MAX >> 1) + 1, 1));
    1890         [ +  - ]:          10 :     BOOST_CHECK(!CheckedLeftShift<T>(MAX, 1));
    1891         [ +  - ]:          10 :     BOOST_CHECK(!CheckedLeftShift<T>(1, std::numeric_limits<T>::digits));
    1892         [ +  - ]:          10 :     BOOST_CHECK(!CheckedLeftShift<T>(1, std::numeric_limits<T>::digits + 1));
    1893                 :             : 
    1894                 :             :     if constexpr (std::is_signed_v<T>) {
    1895                 :           2 :         constexpr auto MIN{std::numeric_limits<T>::min()};
    1896                 :             :         // Negative input
    1897         [ +  - ]:           2 :         BOOST_CHECK_EQUAL(CheckedLeftShift<T>(-1, 1), -2);
    1898         [ +  - ]:           2 :         BOOST_CHECK_EQUAL(CheckedLeftShift<T>((MIN >> 2), 1), MIN / 2);
    1899         [ +  - ]:           2 :         BOOST_CHECK_EQUAL(CheckedLeftShift<T>((MIN >> 1) + 1, 1), MIN + 2);
    1900         [ +  - ]:           2 :         BOOST_CHECK_EQUAL(CheckedLeftShift<T>(MIN >> 1, 1), MIN);
    1901                 :             :         // Overflow negative
    1902         [ +  - ]:           4 :         BOOST_CHECK(!CheckedLeftShift<T>((MIN >> 1) - 1, 1));
    1903         [ +  - ]:           4 :         BOOST_CHECK(!CheckedLeftShift<T>(MIN >> 1, 2));
    1904         [ +  - ]:           4 :         BOOST_CHECK(!CheckedLeftShift<T>(-1, 100));
    1905                 :             :     }
    1906                 :           5 : }
    1907                 :             : 
    1908                 :             : template <typename T>
    1909                 :           5 : void TestSaturatingLeftShift()
    1910                 :             : {
    1911                 :           5 :     constexpr auto MAX{std::numeric_limits<T>::max()};
    1912                 :             : 
    1913                 :             :     // Basic operations
    1914         [ +  - ]:           5 :     BOOST_CHECK_EQUAL(SaturatingLeftShift<T>(0, 1), 0);
    1915         [ +  - ]:           5 :     BOOST_CHECK_EQUAL(SaturatingLeftShift<T>(0, 127), 0);
    1916         [ +  - ]:           5 :     BOOST_CHECK_EQUAL(SaturatingLeftShift<T>(1, 1), 2);
    1917         [ +  - ]:           5 :     BOOST_CHECK_EQUAL(SaturatingLeftShift<T>(2, 2), 8);
    1918         [ +  - ]:           5 :     BOOST_CHECK_EQUAL(SaturatingLeftShift<T>(MAX >> 1, 1), MAX - 1);
    1919                 :             : 
    1920                 :             :     // Max left shift
    1921         [ +  - ]:           5 :     BOOST_CHECK_EQUAL(SaturatingLeftShift<T>(1, std::numeric_limits<T>::digits - 1), MAX / 2 + 1);
    1922                 :             : 
    1923                 :             :     // Saturation cases
    1924         [ +  - ]:           5 :     BOOST_CHECK_EQUAL(SaturatingLeftShift<T>((MAX >> 1) + 1, 1), MAX);
    1925         [ +  - ]:           5 :     BOOST_CHECK_EQUAL(SaturatingLeftShift<T>(MAX, 1), MAX);
    1926         [ +  - ]:           5 :     BOOST_CHECK_EQUAL(SaturatingLeftShift<T>(1, std::numeric_limits<T>::digits), MAX);
    1927         [ +  - ]:           5 :     BOOST_CHECK_EQUAL(SaturatingLeftShift<T>(1, std::numeric_limits<T>::digits + 1), MAX);
    1928                 :             : 
    1929                 :             :     if constexpr (std::is_signed_v<T>) {
    1930                 :           2 :         constexpr auto MIN{std::numeric_limits<T>::min()};
    1931                 :             :         // Negative input
    1932         [ +  - ]:           2 :         BOOST_CHECK_EQUAL(SaturatingLeftShift<T>(-1, 1), -2);
    1933         [ +  - ]:           2 :         BOOST_CHECK_EQUAL(SaturatingLeftShift<T>((MIN >> 2), 1), MIN / 2);
    1934         [ +  - ]:           2 :         BOOST_CHECK_EQUAL(SaturatingLeftShift<T>((MIN >> 1) + 1, 1), MIN + 2);
    1935         [ +  - ]:           2 :         BOOST_CHECK_EQUAL(SaturatingLeftShift<T>(MIN >> 1, 1), MIN);
    1936                 :             :         // Saturation negative
    1937         [ +  - ]:           2 :         BOOST_CHECK_EQUAL(SaturatingLeftShift<T>((MIN >> 1) - 1, 1), MIN);
    1938         [ +  - ]:           2 :         BOOST_CHECK_EQUAL(SaturatingLeftShift<T>(MIN >> 1, 2), MIN);
    1939         [ +  - ]:           2 :         BOOST_CHECK_EQUAL(SaturatingLeftShift<T>(-1, 100), MIN);
    1940                 :             :     }
    1941                 :           5 : }
    1942                 :             : 
    1943   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(checked_left_shift_test)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1944                 :             : {
    1945                 :           1 :     TestCheckedLeftShift<uint8_t>();
    1946                 :           1 :     TestCheckedLeftShift<int8_t>();
    1947                 :           1 :     TestCheckedLeftShift<size_t>();
    1948                 :           1 :     TestCheckedLeftShift<uint64_t>();
    1949                 :           1 :     TestCheckedLeftShift<int64_t>();
    1950                 :           1 : }
    1951                 :             : 
    1952   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(saturating_left_shift_test)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1953                 :             : {
    1954                 :           1 :     TestSaturatingLeftShift<uint8_t>();
    1955                 :           1 :     TestSaturatingLeftShift<int8_t>();
    1956                 :           1 :     TestSaturatingLeftShift<size_t>();
    1957                 :           1 :     TestSaturatingLeftShift<uint64_t>();
    1958                 :           1 :     TestSaturatingLeftShift<int64_t>();
    1959                 :           1 : }
    1960                 :             : 
    1961   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(mib_string_literal_test)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    1962                 :             : {
    1963         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(0_MiB, 0);
    1964         [ +  - ]:           1 :     BOOST_CHECK_EQUAL(1_MiB, 1024 * 1024);
    1965                 :           1 :     const auto max_mib{std::numeric_limits<size_t>::max() >> 20};
    1966   [ +  -  -  +  :           2 :     BOOST_CHECK_EXCEPTION(operator""_MiB(static_cast<unsigned long long>(max_mib) + 1), std::overflow_error, HasReason("MiB value too large for size_t byte conversion"));
          -  -  -  -  -  
          +  +  -  +  -  
                   +  - ]
    1967                 :           1 : }
    1968                 :             : 
    1969                 :             : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1