Bitcoin Core
22.99.0
P2P Digital Currency
src
qt
test
test_main.cpp
Go to the documentation of this file.
1
// Copyright (c) 2009-2020 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
#if defined(HAVE_CONFIG_H)
6
#include <
config/bitcoin-config.h
>
7
#endif
8
9
#include <
interfaces/init.h
>
10
#include <
interfaces/node.h
>
11
#include <
qt/bitcoin.h
>
12
#include <
qt/test/apptests.h
>
13
#include <
qt/test/rpcnestedtests.h
>
14
#include <
qt/test/uritests.h
>
15
#include <
test/util/setup_common.h
>
16
17
#ifdef ENABLE_WALLET
18
#include <
qt/test/addressbooktests.h
>
19
#include <
qt/test/wallettests.h
>
20
#endif
// ENABLE_WALLET
21
22
#include <QApplication>
23
#include <QObject>
24
#include <QTest>
25
26
#if defined(QT_STATICPLUGIN)
27
#include <QtPlugin>
28
#if defined(QT_QPA_PLATFORM_MINIMAL)
29
Q_IMPORT_PLUGIN(QMinimalIntegrationPlugin);
30
#endif
31
#if defined(QT_QPA_PLATFORM_XCB)
32
Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
33
#elif defined(QT_QPA_PLATFORM_WINDOWS)
34
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
35
#elif defined(QT_QPA_PLATFORM_COCOA)
36
Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
37
#endif
38
#endif
39
40
const
std::function<void(
const
std::string&)>
G_TEST_LOG_FUN
{};
41
42
// This is all you need to run all the tests
43
int
main
(
int
argc,
char
* argv[])
44
{
45
// Initialize persistent globals with the testing setup state for sanity.
46
// E.g. -datadir in gArgs is set to a temp directory dummy value (instead
47
// of defaulting to the default datadir), or globalChainParams is set to
48
// regtest params.
49
//
50
// All tests must use their own testing setup (if needed).
51
{
52
BasicTestingSetup
dummy{
CBaseChainParams::REGTEST
};
53
}
54
55
std::unique_ptr<interfaces::Init>
init
=
interfaces::MakeGuiInit
(argc, argv);
56
gArgs
.
ForceSetArg
(
"-listen"
,
"0"
);
57
gArgs
.
ForceSetArg
(
"-listenonion"
,
"0"
);
58
gArgs
.
ForceSetArg
(
"-discover"
,
"0"
);
59
gArgs
.
ForceSetArg
(
"-dnsseed"
,
"0"
);
60
gArgs
.
ForceSetArg
(
"-fixedseeds"
,
"0"
);
61
gArgs
.
ForceSetArg
(
"-upnp"
,
"0"
);
62
gArgs
.
ForceSetArg
(
"-natpmp"
,
"0"
);
63
64
bool
fInvalid =
false
;
65
66
// Prefer the "minimal" platform for the test instead of the normal default
67
// platform ("xcb", "windows", or "cocoa") so tests can't unintentionally
68
// interfere with any background GUIs and don't require extra resources.
69
#if defined(WIN32)
70
if
(getenv(
"QT_QPA_PLATFORM"
) ==
nullptr
) _putenv_s(
"QT_QPA_PLATFORM"
,
"minimal"
);
71
#else
72
setenv(
"QT_QPA_PLATFORM"
,
"minimal"
,
/* overwrite */
0);
73
#endif
74
75
// Don't remove this, it's needed to access
76
// QApplication:: and QCoreApplication:: in the tests
77
BitcoinApplication
app;
78
app.setApplicationName(
"Bitcoin-Qt-test"
);
79
app.
createNode
(*
init
);
80
81
AppTests
app_tests(app);
82
if
(QTest::qExec(&app_tests) != 0) {
83
fInvalid =
true
;
84
}
85
URITests
test1
;
86
if
(QTest::qExec(&
test1
) != 0) {
87
fInvalid =
true
;
88
}
89
RPCNestedTests
test3(app.
node
());
90
if
(QTest::qExec(&test3) != 0) {
91
fInvalid =
true
;
92
}
93
#ifdef ENABLE_WALLET
94
WalletTests
test5(app.
node
());
95
if
(QTest::qExec(&test5) != 0) {
96
fInvalid =
true
;
97
}
98
AddressBookTests
test6(app.
node
());
99
if
(QTest::qExec(&test6) != 0) {
100
fInvalid =
true
;
101
}
102
#endif
103
104
return
fInvalid;
105
}
addressbooktests.h
apptests.h
bitcoin-config.h
bitcoin.h
AddressBookTests
Definition:
addressbooktests.h:16
AppTests
Definition:
apptests.h:18
ArgsManager::ForceSetArg
void ForceSetArg(const std::string &strArg, const std::string &strValue)
Definition:
system.cpp:624
BitcoinApplication
Main Bitcoin application object.
Definition:
bitcoin.h:37
BitcoinApplication::node
interfaces::Node & node() const
Definition:
bitcoin.h:74
BitcoinApplication::createNode
void createNode(interfaces::Init &init)
Create or spawn node.
Definition:
bitcoin.cpp:281
CBaseChainParams::REGTEST
static const std::string REGTEST
Definition:
chainparamsbase.h:25
RPCNestedTests
Definition:
rpcnestedtests.h:16
URITests
Definition:
uritests.h:12
WalletTests
Definition:
wallettests.h:16
test1
const std::string test1
Definition:
crypto_tests.cpp:205
init.h
init
Definition:
bitcoin-gui.cpp:16
interfaces::MakeGuiInit
std::unique_ptr< Init > MakeGuiInit(int argc, char *argv[])
Return implementation of Init interface for the gui process.
Definition:
bitcoin-gui.cpp:43
node.h
rpcnestedtests.h
setup_common.h
BasicTestingSetup
Basic testing setup.
Definition:
setup_common.h:76
main
int main(int argc, char *argv[])
Definition:
test_main.cpp:43
G_TEST_LOG_FUN
const std::function< void(const std::string &)> G_TEST_LOG_FUN
This is connected to the logger.
Definition:
test_main.cpp:40
uritests.h
gArgs
ArgsManager gArgs
Definition:
system.cpp:85
wallettests.h
Generated on Mon Nov 8 2021 14:20:06 for Bitcoin Core by
1.9.2