Bitcoin Core 22.99.0
P2P Digital Currency
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)
7#endif
8
9#include <interfaces/init.h>
10#include <interfaces/node.h>
11#include <qt/bitcoin.h>
12#include <qt/test/apptests.h>
14#include <qt/test/uritests.h>
16
17#ifdef ENABLE_WALLET
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)
29Q_IMPORT_PLUGIN(QMinimalIntegrationPlugin);
30#endif
31#if defined(QT_QPA_PLATFORM_XCB)
32Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
33#elif defined(QT_QPA_PLATFORM_WINDOWS)
34Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
35#elif defined(QT_QPA_PLATFORM_COCOA)
36Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
37#endif
38#endif
39
40const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
41
42// This is all you need to run all the tests
43int 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 {
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
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 }
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}
void ForceSetArg(const std::string &strArg, const std::string &strValue)
Definition: system.cpp:624
Main Bitcoin application object.
Definition: bitcoin.h:37
interfaces::Node & node() const
Definition: bitcoin.h:74
void createNode(interfaces::Init &init)
Create or spawn node.
Definition: bitcoin.cpp:281
static const std::string REGTEST
const std::string test1
std::unique_ptr< Init > MakeGuiInit(int argc, char *argv[])
Return implementation of Init interface for the gui process.
Definition: bitcoin-gui.cpp:43
Basic testing setup.
Definition: setup_common.h:76
int main(int argc, char *argv[])
Definition: test_main.cpp:43
const std::function< void(const std::string &)> G_TEST_LOG_FUN
This is connected to the logger.
Definition: test_main.cpp:40
ArgsManager gArgs
Definition: system.cpp:85