2021-12-30 19:36:57 +02:00
|
|
|
// Copyright (c) 2009-2021 The Bitcoin Core developers
|
2014-09-05 13:11:11 +02:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2013-12-11 15:00:56 +01:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
2017-11-10 13:57:53 +13:00
|
|
|
#include <config/bitcoin-config.h>
|
2013-12-11 15:00:56 +01:00
|
|
|
#endif
|
|
|
|
|
2017-12-05 15:57:12 -05:00
|
|
|
#include <interfaces/init.h>
|
2017-11-06 20:11:43 -05:00
|
|
|
#include <interfaces/node.h>
|
|
|
|
#include <qt/bitcoin.h>
|
|
|
|
#include <qt/test/apptests.h>
|
test: Add tests for GetArg methods / settings.json type coercion
Just add tests. No changes to application behavior. Tests will be
updated in the next commit changing & improving current behavior.
Include a Qt test for GUI startup crash reported by Rspigler in
https://github.com/bitcoin/bitcoin/issues/24457 caused by GetArg
behavior that happens if settings.json contains an integer value for any
of the configuration options which GUI settings can currently clash with
(-dbcache, -par, -spendzeroconfchange, -signer, -upnp, -natpmp, -listen,
-server, -proxy, -proxy, -onion, -onion, -lang, and -prune).
2022-03-07 13:29:46 -05:00
|
|
|
#include <qt/test/optiontests.h>
|
2017-11-10 13:57:53 +13:00
|
|
|
#include <qt/test/rpcnestedtests.h>
|
|
|
|
#include <qt/test/uritests.h>
|
2019-11-05 15:18:59 -05:00
|
|
|
#include <test/util/setup_common.h>
|
2014-09-05 13:11:11 +02:00
|
|
|
|
2013-12-11 15:00:56 +01:00
|
|
|
#ifdef ENABLE_WALLET
|
2018-03-29 10:59:57 -04:00
|
|
|
#include <qt/test/addressbooktests.h>
|
2017-11-10 13:57:53 +13:00
|
|
|
#include <qt/test/wallettests.h>
|
2017-11-06 19:12:47 +01:00
|
|
|
#endif // ENABLE_WALLET
|
2013-04-13 00:13:08 -05:00
|
|
|
|
2017-03-10 15:58:53 -05:00
|
|
|
#include <QApplication>
|
2022-04-06 22:43:11 +02:00
|
|
|
#include <QDebug>
|
2013-04-13 00:13:08 -05:00
|
|
|
#include <QObject>
|
|
|
|
#include <QTest>
|
2022-04-06 22:43:11 +02:00
|
|
|
|
2021-10-08 18:11:40 +02:00
|
|
|
#include <functional>
|
2013-07-22 16:50:39 +10:00
|
|
|
|
2017-03-14 20:45:00 -04:00
|
|
|
#if defined(QT_STATICPLUGIN)
|
2013-12-18 15:46:48 -05:00
|
|
|
#include <QtPlugin>
|
2017-04-03 11:07:40 -04:00
|
|
|
#if defined(QT_QPA_PLATFORM_MINIMAL)
|
|
|
|
Q_IMPORT_PLUGIN(QMinimalIntegrationPlugin);
|
|
|
|
#endif
|
2017-03-14 20:45:00 -04:00
|
|
|
#if defined(QT_QPA_PLATFORM_XCB)
|
|
|
|
Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
|
|
|
|
#elif defined(QT_QPA_PLATFORM_WINDOWS)
|
|
|
|
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
|
|
|
|
#elif defined(QT_QPA_PLATFORM_COCOA)
|
|
|
|
Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
|
2021-12-12 08:15:06 +01:00
|
|
|
#elif defined(QT_QPA_PLATFORM_ANDROID)
|
|
|
|
Q_IMPORT_PLUGIN(QAndroidPlatformIntegrationPlugin)
|
2017-03-14 20:45:00 -04:00
|
|
|
#endif
|
|
|
|
#endif
|
2013-12-18 15:46:48 -05:00
|
|
|
|
2019-09-27 11:53:34 -04:00
|
|
|
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
|
|
|
|
|
2021-10-08 18:11:40 +02:00
|
|
|
const std::function<std::vector<const char*>()> G_TEST_COMMAND_LINE_ARGUMENTS{};
|
|
|
|
|
2013-07-22 16:50:39 +10:00
|
|
|
// This is all you need to run all the tests
|
2020-05-11 17:40:21 +02:00
|
|
|
int main(int argc, char* argv[])
|
2013-07-22 16:50:39 +10:00
|
|
|
{
|
2019-06-26 16:42:33 -04:00
|
|
|
// Initialize persistent globals with the testing setup state for sanity.
|
|
|
|
// E.g. -datadir in gArgs is set to a temp directory dummy value (instead
|
|
|
|
// of defaulting to the default datadir), or globalChainParams is set to
|
|
|
|
// regtest params.
|
|
|
|
//
|
|
|
|
// All tests must use their own testing setup (if needed).
|
2019-04-29 15:29:00 -04:00
|
|
|
fs::create_directories([] {
|
2019-06-26 16:42:33 -04:00
|
|
|
BasicTestingSetup dummy{CBaseChainParams::REGTEST};
|
2019-04-29 15:29:00 -04:00
|
|
|
return gArgs.GetDataDirNet() / "blocks";
|
|
|
|
}());
|
2019-05-28 14:34:50 -04:00
|
|
|
|
2017-12-05 15:57:12 -05:00
|
|
|
std::unique_ptr<interfaces::Init> init = interfaces::MakeGuiInit(argc, argv);
|
2021-03-01 16:10:46 -05:00
|
|
|
gArgs.ForceSetArg("-listen", "0");
|
|
|
|
gArgs.ForceSetArg("-listenonion", "0");
|
|
|
|
gArgs.ForceSetArg("-discover", "0");
|
|
|
|
gArgs.ForceSetArg("-dnsseed", "0");
|
|
|
|
gArgs.ForceSetArg("-fixedseeds", "0");
|
|
|
|
gArgs.ForceSetArg("-upnp", "0");
|
|
|
|
gArgs.ForceSetArg("-natpmp", "0");
|
2016-08-20 11:19:35 +02:00
|
|
|
|
2017-04-03 11:07:40 -04:00
|
|
|
// Prefer the "minimal" platform for the test instead of the normal default
|
2017-08-16 00:24:39 +02:00
|
|
|
// platform ("xcb", "windows", or "cocoa") so tests can't unintentionally
|
2017-04-03 11:07:40 -04:00
|
|
|
// interfere with any background GUIs and don't require extra resources.
|
2017-07-21 17:20:14 -04:00
|
|
|
#if defined(WIN32)
|
2019-10-01 17:03:09 -04:00
|
|
|
if (getenv("QT_QPA_PLATFORM") == nullptr) _putenv_s("QT_QPA_PLATFORM", "minimal");
|
2017-07-21 17:20:14 -04:00
|
|
|
#else
|
2021-09-15 11:10:51 +02:00
|
|
|
setenv("QT_QPA_PLATFORM", "minimal", 0 /* overwrite */);
|
2017-07-21 17:20:14 -04:00
|
|
|
#endif
|
2017-04-03 11:07:40 -04:00
|
|
|
|
2018-08-23 13:42:31 -04:00
|
|
|
BitcoinApplication app;
|
2013-11-14 19:21:16 +01:00
|
|
|
app.setApplicationName("Bitcoin-Qt-test");
|
2017-12-05 15:57:12 -05:00
|
|
|
app.createNode(*init);
|
2013-11-14 19:21:16 +01:00
|
|
|
|
2022-04-06 23:43:27 +02:00
|
|
|
int num_test_failures{0};
|
2022-04-06 23:39:51 +02:00
|
|
|
|
2017-11-06 20:11:43 -05:00
|
|
|
AppTests app_tests(app);
|
2022-04-06 23:43:27 +02:00
|
|
|
num_test_failures += QTest::qExec(&app_tests);
|
2022-04-06 23:39:51 +02:00
|
|
|
|
test: Add tests for GetArg methods / settings.json type coercion
Just add tests. No changes to application behavior. Tests will be
updated in the next commit changing & improving current behavior.
Include a Qt test for GUI startup crash reported by Rspigler in
https://github.com/bitcoin/bitcoin/issues/24457 caused by GetArg
behavior that happens if settings.json contains an integer value for any
of the configuration options which GUI settings can currently clash with
(-dbcache, -par, -spendzeroconfchange, -signer, -upnp, -natpmp, -listen,
-server, -proxy, -proxy, -onion, -onion, -lang, and -prune).
2022-03-07 13:29:46 -05:00
|
|
|
OptionTests options_tests(app.node());
|
2022-04-06 23:43:27 +02:00
|
|
|
num_test_failures += QTest::qExec(&options_tests);
|
2022-04-06 23:39:51 +02:00
|
|
|
|
2013-07-22 16:50:39 +10:00
|
|
|
URITests test1;
|
2022-04-06 23:43:27 +02:00
|
|
|
num_test_failures += QTest::qExec(&test1);
|
2022-04-06 23:39:51 +02:00
|
|
|
|
2018-08-23 13:42:31 -04:00
|
|
|
RPCNestedTests test3(app.node());
|
2022-04-06 23:43:27 +02:00
|
|
|
num_test_failures += QTest::qExec(&test3);
|
2022-04-06 23:39:51 +02:00
|
|
|
|
2017-03-10 15:58:53 -05:00
|
|
|
#ifdef ENABLE_WALLET
|
2018-08-23 13:42:31 -04:00
|
|
|
WalletTests test5(app.node());
|
2022-04-06 23:43:27 +02:00
|
|
|
num_test_failures += QTest::qExec(&test5);
|
2022-04-06 23:39:51 +02:00
|
|
|
|
2018-08-23 13:42:31 -04:00
|
|
|
AddressBookTests test6(app.node());
|
2022-04-06 23:43:27 +02:00
|
|
|
num_test_failures += QTest::qExec(&test6);
|
2017-03-10 15:58:53 -05:00
|
|
|
#endif
|
2013-07-22 16:50:39 +10:00
|
|
|
|
2022-04-06 23:43:27 +02:00
|
|
|
if (num_test_failures) {
|
|
|
|
qWarning("\nFailed tests: %d\n", num_test_failures);
|
2022-04-06 22:43:11 +02:00
|
|
|
} else {
|
|
|
|
qDebug("\nAll tests passed.\n");
|
|
|
|
}
|
2022-04-06 23:43:27 +02:00
|
|
|
return num_test_failures;
|
2013-07-22 16:50:39 +10:00
|
|
|
}
|