Bitcoin Core
32.99.0
P2P Digital Currency
Loading...
Searching...
No Matches
src
qt
test
test_main.cpp
Go to the documentation of this file.
1
// Copyright (c) 2009-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 <bitcoin-build-config.h>
// IWYU pragma: keep
6
7
#include <
interfaces/init.h
>
8
#include <
interfaces/node.h
>
9
#include <
qt/bitcoin.h
>
10
#include <
qt/guiconstants.h
>
11
#include <
qt/test/apptests.h
>
12
#include <
qt/test/optiontests.h
>
13
#include <
qt/test/rpcnestedtests.h
>
14
#include <
qt/test/uritests.h
>
15
#include <
test/util/setup_common.h
>
16
#include <
util/chaintype.h
>
17
18
#ifdef ENABLE_WALLET
19
#include <
qt/test/addressbooktests.h
>
20
#include <
qt/test/wallettests.h
>
21
#endif
// ENABLE_WALLET
22
23
#include <QApplication>
24
#include <QDebug>
25
#include <QObject>
26
#include <QSettings>
27
#include <QTest>
28
29
#include <functional>
30
31
const
std::function<std::vector<const char*>()>
G_TEST_COMMAND_LINE_ARGUMENTS
{};
32
33
const
std::function<std::string()>
G_TEST_GET_FULL_NAME
{};
34
35
// This is all you need to run all the tests
36
int
main
(
int
argc
,
char
*
argv
[])
37
{
38
// Initialize persistent globals with the testing setup state for sanity.
39
// E.g. -datadir in gArgs is set to a temp directory dummy value (instead
40
// of defaulting to the default datadir), or globalChainParams is set to
41
// regtest params.
42
//
43
// All tests must use their own testing setup (if needed).
44
fs::create_directories([] {
45
BasicTestingSetup
dummy{
ChainType::REGTEST
};
46
return
gArgs
.
GetDataDirNet
() /
"blocks"
;
47
}());
48
49
std::unique_ptr<interfaces::Init>
init
=
interfaces::MakeGuiInit
(
argc
,
argv
);
50
gArgs
.
ForceSetArg
(
"-listen"
,
"0"
);
51
gArgs
.
ForceSetArg
(
"-listenonion"
,
"0"
);
52
gArgs
.
ForceSetArg
(
"-discover"
,
"0"
);
53
gArgs
.
ForceSetArg
(
"-dnsseed"
,
"0"
);
54
gArgs
.
ForceSetArg
(
"-fixedseeds"
,
"0"
);
55
gArgs
.
ForceSetArg
(
"-natpmp"
,
"0"
);
56
57
std::string error;
58
if
(!
gArgs
.
ReadConfigFiles
(error,
true
))
qWarning
() << error.c_str();
59
60
// Prefer the "minimal" platform for the test instead of the normal default
61
// platform ("xcb", "windows", or "cocoa") so tests can't unintentionally
62
// interfere with any background GUIs and don't require extra resources.
63
#if defined(WIN32)
64
if
(
getenv
(
"QT_QPA_PLATFORM"
) ==
nullptr
)
_putenv_s
(
"QT_QPA_PLATFORM"
,
"minimal"
);
65
#else
66
setenv
(
"QT_QPA_PLATFORM"
,
"minimal"
, 0
/* overwrite */
);
67
#endif
68
69
#ifdef Q_OS_MACOS
70
// QMacStyle assumes a Cocoa platform window, which the minimal platform
71
// does not provide. In particular, painting a QGroupBox can make Qt call
72
// addSubview: on an invalid native object (QTBUG-49686).
73
setenv
(
"QT_STYLE_OVERRIDE"
,
"fusion"
, 0
/* overwrite */
);
74
#endif
75
76
QCoreApplication::setOrganizationName(
QAPP_ORG_NAME
);
77
QCoreApplication::setApplicationName(
QAPP_APP_NAME_DEFAULT
"-test"
);
78
79
int
num_test_failures
{0};
80
81
{
82
BitcoinApplication
app
;
83
app
.
createNode
(*
init
);
84
85
AppTests
app_tests
(
app
);
86
num_test_failures
+= QTest::qExec(&
app_tests
);
87
88
OptionTests
options_tests
(
app
.node());
89
num_test_failures
+= QTest::qExec(&
options_tests
);
90
91
URITests
test1
;
92
num_test_failures
+= QTest::qExec(&
test1
);
93
94
RPCNestedTests
test3
(
app
.node());
95
num_test_failures
+= QTest::qExec(&
test3
);
96
97
#ifdef ENABLE_WALLET
98
WalletTests
test5
(
app
.node());
99
num_test_failures
+= QTest::qExec(&
test5
);
100
101
AddressBookTests
test6
(
app
.node());
102
num_test_failures
+= QTest::qExec(&
test6
);
103
#endif
104
105
if
(
num_test_failures
) {
106
qWarning
(
"\nFailed tests: %d\n"
,
num_test_failures
);
107
}
else
{
108
qDebug
(
"\nAll tests passed.\n"
);
109
}
110
}
111
112
QSettings
settings
;
113
settings
.clear();
114
115
return
num_test_failures
;
116
}
addressbooktests.h
apptests.h
gArgs
ArgsManager gArgs
Definition
args.cpp:38
bitcoin.h
chaintype.h
ChainType::REGTEST
@ REGTEST
AddressBookTests
Definition
addressbooktests.h:16
AppTests
Definition
apptests.h:18
ArgsManager::ReadConfigFiles
bool ReadConfigFiles(std::string &error, bool ignore_invalid_keys=false) EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Definition
config.cpp:132
ArgsManager::ForceSetArg
void ForceSetArg(const std::string &strArg, const std::string &strValue) EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Definition
args.cpp:610
ArgsManager::GetDataDirNet
fs::path GetDataDirNet() const EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Get data directory path with appended network identifier.
Definition
args.cpp:328
BitcoinApplication
Main Bitcoin application object.
Definition
bitcoin.h:35
BitcoinApplication::createNode
void createNode(interfaces::Init &init)
Create or spawn node.
Definition
bitcoin.cpp:280
OptionTests
Definition
optiontests.h:15
RPCNestedTests
Definition
rpcnestedtests.h:16
URITests
Definition
uritests.h:12
WalletTests
Definition
wallettests.h:16
main
int main(void)
Definition
bench.c:156
test1
const std::string test1
Definition
crypto_tests.cpp:375
guiconstants.h
QAPP_ORG_NAME
#define QAPP_ORG_NAME
Definition
guiconstants.h:47
QAPP_APP_NAME_DEFAULT
#define QAPP_APP_NAME_DEFAULT
Definition
guiconstants.h:49
init.h
init
Definition
basic.cpp:11
interfaces::MakeGuiInit
std::unique_ptr< Init > MakeGuiInit(int argc, char *argv[])
Return implementation of Init interface for the gui process.
Definition
bitcoin-gui.cpp:55
node.h
optiontests.h
rpcnestedtests.h
setup_common.h
BasicTestingSetup
Basic testing setup.
Definition
setup_common.h:58
G_TEST_COMMAND_LINE_ARGUMENTS
const std::function< std::vector< const char * >()> G_TEST_COMMAND_LINE_ARGUMENTS
Retrieve the command line arguments.
Definition
test_main.cpp:31
G_TEST_GET_FULL_NAME
const std::function< std::string()> G_TEST_GET_FULL_NAME
Retrieve the unit test name.
Definition
test_main.cpp:33
uritests.h
Ticks
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition
time.h:82
wallettests.h
Generated on Fri Oct 23 2026 20:00:27 for Bitcoin Core by
1.9.8