Bitcoin Core  22.99.0
P2P Digital Currency
Classes | Namespaces | Macros | Functions | Variables
util_tests.cpp File Reference
#include <util/system.h>
#include <clientversion.h>
#include <hash.h>
#include <key.h>
#include <sync.h>
#include <test/util/logging.h>
#include <test/util/setup_common.h>
#include <test/util/str.h>
#include <uint256.h>
#include <util/getuniquepath.h>
#include <util/message.h>
#include <util/moneystr.h>
#include <util/overflow.h>
#include <util/spanparsing.h>
#include <util/strencodings.h>
#include <util/string.h>
#include <util/time.h>
#include <util/vector.h>
#include <array>
#include <optional>
#include <limits>
#include <map>
#include <stdint.h>
#include <thread>
#include <univalue.h>
#include <utility>
#include <vector>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <boost/test/unit_test.hpp>
Include dependency graph for util_tests.cpp:

Go to the source code of this file.

Classes

struct  TestArgsManager
 
class  CheckValueTest
 Test GetSetting and GetArg type coercion, negation, and default value handling. More...
 
struct  CheckValueTest::Expect
 
struct  NoIncludeConfTest
 
struct  ArgsMergeTestingSetup
 
struct  ChainMergeTestingSetup
 

Namespaces

 BCLog
 

Macros

#define B   "check_prefix"
 
#define E   "check_postfix"
 

Functions

std::string BCLog::LogEscapeMessage (const std::string &str)
 Belts and suspenders: make sure outgoing log messages don't contain potentially suspicious characters, such as terminal control codes. More...
 
 BOOST_AUTO_TEST_CASE (util_datadir)
 
 BOOST_AUTO_TEST_CASE (util_check)
 
 BOOST_AUTO_TEST_CASE (util_criticalsection)
 
 BOOST_AUTO_TEST_CASE (util_ParseHex)
 
 BOOST_AUTO_TEST_CASE (util_HexStr)
 
 BOOST_AUTO_TEST_CASE (span_write_bytes)
 
 BOOST_AUTO_TEST_CASE (util_Join)
 
 BOOST_AUTO_TEST_CASE (util_TrimString)
 
 BOOST_AUTO_TEST_CASE (util_FormatParseISO8601DateTime)
 
 BOOST_AUTO_TEST_CASE (util_FormatISO8601Date)
 
 BOOST_FIXTURE_TEST_CASE (util_CheckValue, CheckValueTest)
 
 BOOST_FIXTURE_TEST_CASE (util_NoIncludeConf, NoIncludeConfTest)
 
 BOOST_AUTO_TEST_CASE (util_ParseParameters)
 
 BOOST_AUTO_TEST_CASE (util_ParseInvalidParameters)
 
static void TestParse (const std::string &str, bool expected_bool, int64_t expected_int)
 
 BOOST_AUTO_TEST_CASE (util_ArgParsing)
 
 BOOST_AUTO_TEST_CASE (util_GetBoolArg)
 
 BOOST_AUTO_TEST_CASE (util_GetBoolArgEdgeCases)
 
 BOOST_AUTO_TEST_CASE (util_ReadConfigStream)
 
 BOOST_AUTO_TEST_CASE (util_GetArg)
 
 BOOST_AUTO_TEST_CASE (util_GetChainName)
 
 BOOST_FIXTURE_TEST_CASE (util_ArgsMerge, ArgsMergeTestingSetup)
 
 BOOST_FIXTURE_TEST_CASE (util_ChainMerge, ChainMergeTestingSetup)
 
 BOOST_AUTO_TEST_CASE (util_ReadWriteSettings)
 
 BOOST_AUTO_TEST_CASE (util_FormatMoney)
 
 BOOST_AUTO_TEST_CASE (util_ParseMoney)
 
 BOOST_AUTO_TEST_CASE (util_IsHex)
 
 BOOST_AUTO_TEST_CASE (util_IsHexNumber)
 
 BOOST_AUTO_TEST_CASE (util_seed_insecure_rand)
 
 BOOST_AUTO_TEST_CASE (util_TimingResistantEqual)
 
 BOOST_AUTO_TEST_CASE (strprintf_numbers)
 
 BOOST_AUTO_TEST_CASE (gettime)
 
 BOOST_AUTO_TEST_CASE (util_time_GetTime)
 
 BOOST_AUTO_TEST_CASE (test_IsDigit)
 
template<typename T >
static void TestAddMatrixOverflow ()
 
template<typename T >
static void TestAddMatrix ()
 
 BOOST_AUTO_TEST_CASE (util_overflow)
 
 BOOST_AUTO_TEST_CASE (test_ParseInt32)
 
template<typename T >
static void RunToIntegralTests ()
 
 BOOST_AUTO_TEST_CASE (test_ToIntegral)
 
int64_t atoi64_legacy (const std::string &str)
 
 BOOST_AUTO_TEST_CASE (test_LocaleIndependentAtoi)
 
 BOOST_AUTO_TEST_CASE (test_ParseInt64)
 
 BOOST_AUTO_TEST_CASE (test_ParseUInt8)
 
 BOOST_AUTO_TEST_CASE (test_ParseUInt16)
 
 BOOST_AUTO_TEST_CASE (test_ParseUInt32)
 
 BOOST_AUTO_TEST_CASE (test_ParseUInt64)
 
 BOOST_AUTO_TEST_CASE (test_FormatParagraph)
 
 BOOST_AUTO_TEST_CASE (test_FormatSubVersion)
 
 BOOST_AUTO_TEST_CASE (test_ParseFixedPoint)
 
static void TestOtherThread (fs::path dirname, std::string lockname, bool *result)
 
static void TestOtherProcess (fs::path dirname, std::string lockname, int fd)
 
 BOOST_AUTO_TEST_CASE (test_LockDirectory)
 
 BOOST_AUTO_TEST_CASE (test_DirIsWritable)
 
 BOOST_AUTO_TEST_CASE (test_ToLower)
 
 BOOST_AUTO_TEST_CASE (test_ToUpper)
 
 BOOST_AUTO_TEST_CASE (test_Capitalize)
 
static std::string SpanToStr (const Span< const char > &span)
 
 BOOST_AUTO_TEST_CASE (test_spanparsing)
 
 BOOST_AUTO_TEST_CASE (test_LogEscapeMessage)
 
 BOOST_AUTO_TEST_CASE (test_tracked_vector)
 
 BOOST_AUTO_TEST_CASE (message_sign)
 
 BOOST_AUTO_TEST_CASE (message_verify)
 
 BOOST_AUTO_TEST_CASE (message_hash)
 
 BOOST_AUTO_TEST_CASE (remove_prefix)
 
 BOOST_AUTO_TEST_CASE (util_ParseByteUnits)
 

Variables

static const std::string STRING_WITH_EMBEDDED_NULL_CHAR {"1"s "\0" "1"s}
 
static const unsigned char ParseHex_expected [65]
 
static constexpr char LockCommand = 'L'
 
static constexpr char UnlockCommand = 'U'
 
static constexpr char ExitCommand = 'X'
 

Macro Definition Documentation

◆ B

#define B   "check_prefix"

Definition at line 1400 of file util_tests.cpp.

◆ E

#define E   "check_postfix"

Definition at line 1401 of file util_tests.cpp.

Function Documentation

◆ atoi64_legacy()

int64_t atoi64_legacy ( const std::string &  str)

Definition at line 1626 of file util_tests.cpp.

Here is the caller graph for this function:

◆ BOOST_AUTO_TEST_CASE() [1/54]

BOOST_AUTO_TEST_CASE ( gettime  )

Definition at line 1428 of file util_tests.cpp.

◆ BOOST_AUTO_TEST_CASE() [2/54]

BOOST_AUTO_TEST_CASE ( message_hash  )

Definition at line 2500 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/54]

BOOST_AUTO_TEST_CASE ( message_sign  )

Definition at line 2412 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/54]

BOOST_AUTO_TEST_CASE ( message_verify  )

Definition at line 2448 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [5/54]

BOOST_AUTO_TEST_CASE ( remove_prefix  )

Definition at line 2517 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [6/54]

BOOST_AUTO_TEST_CASE ( span_write_bytes  )

Definition at line 167 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [7/54]

BOOST_AUTO_TEST_CASE ( strprintf_numbers  )

Definition at line 1402 of file util_tests.cpp.

◆ BOOST_AUTO_TEST_CASE() [8/54]

BOOST_AUTO_TEST_CASE ( test_Capitalize  )

Definition at line 2170 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [9/54]

BOOST_AUTO_TEST_CASE ( test_DirIsWritable  )

Definition at line 2126 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [10/54]

BOOST_AUTO_TEST_CASE ( test_FormatParagraph  )

Definition at line 1887 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [11/54]

BOOST_AUTO_TEST_CASE ( test_FormatSubVersion  )

Definition at line 1914 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [12/54]

BOOST_AUTO_TEST_CASE ( test_IsDigit  )

Definition at line 1454 of file util_tests.cpp.

◆ BOOST_AUTO_TEST_CASE() [13/54]

BOOST_AUTO_TEST_CASE ( test_LocaleIndependentAtoi  )

Definition at line 1631 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [14/54]

BOOST_AUTO_TEST_CASE ( test_LockDirectory  )

Definition at line 2038 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [15/54]

BOOST_AUTO_TEST_CASE ( test_LogEscapeMessage  )

Definition at line 2300 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [16/54]

BOOST_AUTO_TEST_CASE ( test_ParseFixedPoint  )

Definition at line 1926 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [17/54]

BOOST_AUTO_TEST_CASE ( test_ParseInt32  )

Definition at line 1501 of file util_tests.cpp.

◆ BOOST_AUTO_TEST_CASE() [18/54]

BOOST_AUTO_TEST_CASE ( test_ParseInt64  )

Definition at line 1722 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [19/54]

BOOST_AUTO_TEST_CASE ( test_ParseUInt16  )

Definition at line 1785 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [20/54]

BOOST_AUTO_TEST_CASE ( test_ParseUInt32  )

Definition at line 1820 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [21/54]

BOOST_AUTO_TEST_CASE ( test_ParseUInt64  )

Definition at line 1857 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [22/54]

BOOST_AUTO_TEST_CASE ( test_ParseUInt8  )

Definition at line 1750 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [23/54]

BOOST_AUTO_TEST_CASE ( test_spanparsing  )

Definition at line 2182 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [24/54]

BOOST_AUTO_TEST_CASE ( test_ToIntegral  )

Definition at line 1564 of file util_tests.cpp.

◆ BOOST_AUTO_TEST_CASE() [25/54]

BOOST_AUTO_TEST_CASE ( test_ToLower  )

Definition at line 2142 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [26/54]

BOOST_AUTO_TEST_CASE ( test_ToUpper  )

Definition at line 2156 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [27/54]

BOOST_AUTO_TEST_CASE ( test_tracked_vector  )

Definition at line 2335 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [28/54]

BOOST_AUTO_TEST_CASE ( util_ArgParsing  )

Definition at line 454 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [29/54]

BOOST_AUTO_TEST_CASE ( util_check  )

Definition at line 78 of file util_tests.cpp.

◆ BOOST_AUTO_TEST_CASE() [30/54]

BOOST_AUTO_TEST_CASE ( util_criticalsection  )

Definition at line 91 of file util_tests.cpp.

◆ BOOST_AUTO_TEST_CASE() [31/54]

BOOST_AUTO_TEST_CASE ( util_datadir  )

Definition at line 53 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [32/54]

BOOST_AUTO_TEST_CASE ( util_FormatISO8601Date  )

Definition at line 219 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [33/54]

BOOST_AUTO_TEST_CASE ( util_FormatMoney  )

Definition at line 1218 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [34/54]

BOOST_AUTO_TEST_CASE ( util_FormatParseISO8601DateTime  )

Definition at line 206 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [35/54]

BOOST_AUTO_TEST_CASE ( util_GetArg  )

Definition at line 776 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [36/54]

BOOST_AUTO_TEST_CASE ( util_GetBoolArg  )

Definition at line 493 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [37/54]

BOOST_AUTO_TEST_CASE ( util_GetBoolArgEdgeCases  )

Definition at line 534 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [38/54]

BOOST_AUTO_TEST_CASE ( util_GetChainName  )

Definition at line 815 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [39/54]

BOOST_AUTO_TEST_CASE ( util_HexStr  )

Definition at line 141 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [40/54]

BOOST_AUTO_TEST_CASE ( util_IsHex  )

Definition at line 1322 of file util_tests.cpp.

◆ BOOST_AUTO_TEST_CASE() [41/54]

BOOST_AUTO_TEST_CASE ( util_IsHexNumber  )

Definition at line 1337 of file util_tests.cpp.

◆ BOOST_AUTO_TEST_CASE() [42/54]

BOOST_AUTO_TEST_CASE ( util_Join  )

Definition at line 176 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [43/54]

BOOST_AUTO_TEST_CASE ( util_overflow  )

Definition at line 1495 of file util_tests.cpp.

◆ BOOST_AUTO_TEST_CASE() [44/54]

BOOST_AUTO_TEST_CASE ( util_ParseByteUnits  )

Definition at line 2530 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [45/54]

BOOST_AUTO_TEST_CASE ( util_ParseHex  )

Definition at line 120 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [46/54]

BOOST_AUTO_TEST_CASE ( util_ParseInvalidParameters  )

Definition at line 418 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [47/54]

BOOST_AUTO_TEST_CASE ( util_ParseMoney  )

Definition at line 1253 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [48/54]

BOOST_AUTO_TEST_CASE ( util_ParseParameters  )

Definition at line 381 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [49/54]

BOOST_AUTO_TEST_CASE ( util_ReadConfigStream  )

Definition at line 587 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [50/54]

BOOST_AUTO_TEST_CASE ( util_ReadWriteSettings  )

Definition at line 1194 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [51/54]

BOOST_AUTO_TEST_CASE ( util_seed_insecure_rand  )

Definition at line 1362 of file util_tests.cpp.

◆ BOOST_AUTO_TEST_CASE() [52/54]

BOOST_AUTO_TEST_CASE ( util_time_GetTime  )

Definition at line 1433 of file util_tests.cpp.

◆ BOOST_AUTO_TEST_CASE() [53/54]

BOOST_AUTO_TEST_CASE ( util_TimingResistantEqual  )

Definition at line 1387 of file util_tests.cpp.

◆ BOOST_AUTO_TEST_CASE() [54/54]

BOOST_AUTO_TEST_CASE ( util_TrimString  )

Definition at line 190 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_FIXTURE_TEST_CASE() [1/4]

BOOST_FIXTURE_TEST_CASE ( util_ArgsMerge  ,
ArgsMergeTestingSetup   
)

Definition at line 975 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_FIXTURE_TEST_CASE() [2/4]

BOOST_FIXTURE_TEST_CASE ( util_ChainMerge  ,
ChainMergeTestingSetup   
)

Definition at line 1110 of file util_tests.cpp.

Here is the call graph for this function:

◆ BOOST_FIXTURE_TEST_CASE() [3/4]

BOOST_FIXTURE_TEST_CASE ( util_CheckValue  ,
CheckValueTest   
)

Definition at line 343 of file util_tests.cpp.

◆ BOOST_FIXTURE_TEST_CASE() [4/4]

BOOST_FIXTURE_TEST_CASE ( util_NoIncludeConf  ,
NoIncludeConfTest   
)

Definition at line 374 of file util_tests.cpp.

Here is the call graph for this function:

◆ RunToIntegralTests()

template<typename T >
static void RunToIntegralTests ( )
static

Definition at line 1536 of file util_tests.cpp.

◆ SpanToStr()

static std::string SpanToStr ( const Span< const char > &  span)
static

Definition at line 2177 of file util_tests.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestAddMatrix()

template<typename T >
static void TestAddMatrix ( )
static

Definition at line 1483 of file util_tests.cpp.

◆ TestAddMatrixOverflow()

template<typename T >
static void TestAddMatrixOverflow ( )
static

Definition at line 1471 of file util_tests.cpp.

◆ TestOtherProcess()

static void TestOtherProcess ( fs::path  dirname,
std::string  lockname,
int  fd 
)
static

Definition at line 2010 of file util_tests.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestOtherThread()

static void TestOtherThread ( fs::path  dirname,
std::string  lockname,
bool *  result 
)
static

Definition at line 2000 of file util_tests.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestParse()

static void TestParse ( const std::string &  str,
bool  expected_bool,
int64_t  expected_int 
)
static

Definition at line 439 of file util_tests.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ ExitCommand

constexpr char ExitCommand = 'X'
staticconstexpr

Definition at line 2008 of file util_tests.cpp.

◆ LockCommand

constexpr char LockCommand = 'L'
staticconstexpr

Definition at line 2006 of file util_tests.cpp.

◆ ParseHex_expected

const unsigned char ParseHex_expected[65]
static
Initial value:
= {
0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, 0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7,
0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, 0xa6, 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde,
0xb6, 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, 0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12,
0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, 0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d,
0x5f
}

Definition at line 113 of file util_tests.cpp.

◆ STRING_WITH_EMBEDDED_NULL_CHAR

const std::string STRING_WITH_EMBEDDED_NULL_CHAR {"1"s "\0" "1"s}
static

Definition at line 44 of file util_tests.cpp.

◆ UnlockCommand

constexpr char UnlockCommand = 'U'
staticconstexpr

Definition at line 2007 of file util_tests.cpp.