Line data Source code
1 : // Copyright (c) 2009-2019 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/node.h> 10 : #include <qt/bitcoin.h> 11 : #include <qt/test/apptests.h> 12 : #include <qt/test/rpcnestedtests.h> 13 : #include <qt/test/uritests.h> 14 : #include <qt/test/compattests.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 1 : const std::function<void(const std::string&)> G_TEST_LOG_FUN{}; 41 : 42 : // This is all you need to run all the tests 43 1 : 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 1 : BasicTestingSetup dummy{CBaseChainParams::REGTEST}; 53 1 : } 54 : 55 1 : NodeContext node_context; 56 1 : std::unique_ptr<interfaces::Node> node = interfaces::MakeNode(&node_context); 57 : 58 : bool fInvalid = false; 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 1 : setenv("QT_QPA_PLATFORM", "minimal", /* overwrite */ 0); 67 : #endif 68 : 69 : // Don't remove this, it's needed to access 70 : // QApplication:: and QCoreApplication:: in the tests 71 1 : BitcoinApplication app; 72 1 : app.setNode(*node); 73 1 : app.setApplicationName("Bitcoin-Qt-test"); 74 : 75 1 : app.node().context()->args = &gArgs; // Make gArgs available in the NodeContext 76 1 : AppTests app_tests(app); 77 1 : if (QTest::qExec(&app_tests) != 0) { 78 : fInvalid = true; 79 0 : } 80 1 : URITests test1; 81 1 : if (QTest::qExec(&test1) != 0) { 82 : fInvalid = true; 83 0 : } 84 1 : RPCNestedTests test3(app.node()); 85 1 : if (QTest::qExec(&test3) != 0) { 86 : fInvalid = true; 87 0 : } 88 1 : CompatTests test4; 89 1 : if (QTest::qExec(&test4) != 0) { 90 : fInvalid = true; 91 0 : } 92 : #ifdef ENABLE_WALLET 93 1 : WalletTests test5(app.node()); 94 1 : if (QTest::qExec(&test5) != 0) { 95 : fInvalid = true; 96 0 : } 97 1 : AddressBookTests test6(app.node()); 98 1 : if (QTest::qExec(&test6) != 0) { 99 : fInvalid = true; 100 0 : } 101 : #endif 102 : 103 1 : return fInvalid; 104 1 : }