remove GetBoolArg() fDefault parameter defaulting to false

- explicitly set the default of all GetBoolArg() calls
- rework getarg_test.cpp and util_tests.cpp to cover this change
- some indentation fixes
- move macdockiconhandler.h include in bitcoin.cpp to the "our headers"
  section
This commit is contained in:
Philip Kaufmann 2013-04-28 17:37:50 +02:00
parent 3d661110da
commit 3260b4c090
10 changed files with 61 additions and 76 deletions

View File

@ -757,7 +757,7 @@ void StartRPCThreads()
rpc_io_service = new asio::io_service();
rpc_ssl_context = new ssl::context(*rpc_io_service, ssl::context::sslv23);
const bool fUseSSL = GetBoolArg("-rpcssl");
const bool fUseSSL = GetBoolArg("-rpcssl", false);
if (fUseSSL)
{
@ -1037,7 +1037,7 @@ json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_s
// Observe safe mode
string strWarning = GetWarnings("rpc");
if (strWarning != "" && !GetBoolArg("-disablesafemode") &&
if (strWarning != "" && !GetBoolArg("-disablesafemode", false) &&
!pcmd->okSafeMode)
throw JSONRPCError(RPC_FORBIDDEN_BY_SAFE_MODE, string("Safe mode: ") + strWarning);
@ -1071,7 +1071,7 @@ Object CallRPC(const string& strMethod, const Array& params)
GetConfigFile().string().c_str()));
// Connect to localhost
bool fUseSSL = GetBoolArg("-rpcssl");
bool fUseSSL = GetBoolArg("-rpcssl", false);
asio::io_service io_service;
ssl::context context(io_service, ssl::context::sslv23);
context.set_options(ssl::context::no_sslv2);

View File

@ -198,7 +198,7 @@ bool AppInit(int argc, char* argv[])
exit(ret);
}
#if !defined(WIN32)
fDaemon = GetBoolArg("-daemon");
fDaemon = GetBoolArg("-daemon", false);
if (fDaemon)
{
// Daemonize
@ -495,7 +495,7 @@ bool AppInit2(boost::thread_group& threadGroup)
// ********************************************************* Step 2: parameter interactions
fTestNet = GetBoolArg("-testnet");
fTestNet = GetBoolArg("-testnet", false);
Checkpoints::fEnabled = GetBoolArg("-checkpoints", true);
if (mapArgs.count("-bind")) {
@ -526,7 +526,7 @@ bool AppInit2(boost::thread_group& threadGroup)
SoftSetBoolArg("-discover", false);
}
if (GetBoolArg("-salvagewallet")) {
if (GetBoolArg("-salvagewallet", false)) {
// Rewrite just private keys: rescan to find transactions
SoftSetBoolArg("-rescan", true);
}
@ -543,8 +543,8 @@ bool AppInit2(boost::thread_group& threadGroup)
// ********************************************************* Step 3: parameter-to-internal-flags
fDebug = GetBoolArg("-debug");
fBenchmark = GetBoolArg("-benchmark");
fDebug = GetBoolArg("-debug", false);
fBenchmark = GetBoolArg("-benchmark", false);
// -par=0 means autodetect, but nScriptCheckThreads==0 means no concurrency
nScriptCheckThreads = GetArg("-par", 0);
@ -559,20 +559,20 @@ bool AppInit2(boost::thread_group& threadGroup)
if (fDebug)
fDebugNet = true;
else
fDebugNet = GetBoolArg("-debugnet");
fDebugNet = GetBoolArg("-debugnet", false);
if (fDaemon)
fServer = true;
else
fServer = GetBoolArg("-server");
fServer = GetBoolArg("-server", false);
/* force fServer when running without GUI */
#if !defined(QT_GUI)
fServer = true;
#endif
fPrintToConsole = GetBoolArg("-printtoconsole");
fPrintToDebugger = GetBoolArg("-printtodebugger");
fLogTimestamps = GetBoolArg("-logtimestamps");
fPrintToConsole = GetBoolArg("-printtoconsole", false);
fPrintToDebugger = GetBoolArg("-printtodebugger", false);
fLogTimestamps = GetBoolArg("-logtimestamps", false);
if (mapArgs.count("-timeout"))
{
@ -677,7 +677,7 @@ bool AppInit2(boost::thread_group& threadGroup)
}
}
if (GetBoolArg("-salvagewallet"))
if (GetBoolArg("-salvagewallet", false))
{
// Recover readable keypairs:
if (!CWalletDB::Recover(bitdb, "wallet.dat", true))
@ -799,7 +799,7 @@ bool AppInit2(boost::thread_group& threadGroup)
// ********************************************************* Step 7: load block chain
fReindex = GetBoolArg("-reindex");
fReindex = GetBoolArg("-reindex", false);
// Upgrading to 0.8; hard-link the old blknnnn.dat files into /blocks/
filesystem::path blocksDir = GetDataDir() / "blocks";
@ -922,7 +922,7 @@ bool AppInit2(boost::thread_group& threadGroup)
}
printf(" block index %15"PRI64d"ms\n", GetTimeMillis() - nStart);
if (GetBoolArg("-printblockindex") || GetBoolArg("-printblocktree"))
if (GetBoolArg("-printblockindex", false) || GetBoolArg("-printblocktree", false))
{
PrintBlockTree();
return false;
@ -1018,7 +1018,7 @@ bool AppInit2(boost::thread_group& threadGroup)
RegisterWallet(pwalletMain);
CBlockIndex *pindexRescan = pindexBest;
if (GetBoolArg("-rescan"))
if (GetBoolArg("-rescan", false))
pindexRescan = pindexGenesisBlock;
else
{

View File

@ -2931,7 +2931,7 @@ string GetWarnings(string strFor)
string strStatusBar;
string strRPC;
if (GetBoolArg("-testsafemode"))
if (GetBoolArg("-testsafemode", false))
strRPC = "test";
if (!CLIENT_VERSION_IS_RELEASE)
@ -4175,7 +4175,7 @@ CBlockTemplate* CreateNewBlock(CReserveKey& reservekey)
// Priority order to process transactions
list<COrphan> vOrphan; // list memory doesn't move
map<uint256, vector<COrphan*> > mapDependers;
bool fPrintPriority = GetBoolArg("-printpriority");
bool fPrintPriority = GetBoolArg("-printpriority", false);
// This vector will be sorted into a priority queue:
vector<TxPriority> vecPriority;

View File

@ -15,6 +15,9 @@
#include "ui_interface.h"
#include "paymentserver.h"
#include "splashscreen.h"
#ifdef Q_OS_MAC
#include "macdockiconhandler.h"
#endif
#include <QMessageBox>
#include <QTextCodec>
@ -23,10 +26,6 @@
#include <QTranslator>
#include <QLibraryInfo>
#ifdef Q_OS_MAC
#include "macdockiconhandler.h"
#endif
#if defined(BITCOIN_NEED_QT_PLUGINS) && !defined(_BITCOIN_QT_PLUGINS_INCLUDED)
#define _BITCOIN_QT_PLUGINS_INCLUDED
#define __INSURE__
@ -152,7 +151,7 @@ int main(int argc, char *argv[])
// as it is used to locate QSettings)
QApplication::setOrganizationName("Bitcoin");
QApplication::setOrganizationDomain("bitcoin.org");
if(GetBoolArg("-testnet")) // Separate UI settings for testnet
if (GetBoolArg("-testnet", false)) // Separate UI settings for testnet
QApplication::setApplicationName("Bitcoin-Qt-testnet");
else
QApplication::setApplicationName("Bitcoin-Qt");
@ -204,13 +203,14 @@ int main(int argc, char *argv[])
#ifdef Q_OS_MAC
// on mac, also change the icon now because it would look strange to have a testnet splash (green) and a std app icon (orange)
if(GetBoolArg("-testnet")) {
if(GetBoolArg("-testnet", false))
{
MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
}
#endif
SplashScreen splash(QPixmap(), 0);
if (GetBoolArg("-splash", true) && !GetBoolArg("-min"))
if (GetBoolArg("-splash", true) && !GetBoolArg("-min", false))
{
splash.show();
splash.setAutoFillBackground(true);
@ -254,7 +254,7 @@ int main(int argc, char *argv[])
window.setCurrentWallet("~Default");
// If -min option passed, start window minimized.
if(GetBoolArg("-min"))
if(GetBoolArg("-min", false))
{
window.showMinimized();
}

View File

@ -26,7 +26,7 @@ SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f) :
// load the bitmap for writing some text over it
QPixmap newPixmap;
if(GetBoolArg("-testnet")) {
if(GetBoolArg("-testnet", false)) {
newPixmap = QPixmap(":/images/splash_testnet");
}
else {

View File

@ -33,7 +33,7 @@ Value getgenerate(const Array& params, bool fHelp)
"getgenerate\n"
"Returns true or false.");
return GetBoolArg("-gen");
return GetBoolArg("-gen", false);
}
@ -84,16 +84,16 @@ Value getmininginfo(const Array& params, bool fHelp)
"Returns an object containing mining-related information.");
Object obj;
obj.push_back(Pair("blocks", (int)nBestHeight));
obj.push_back(Pair("currentblocksize",(uint64_t)nLastBlockSize));
obj.push_back(Pair("currentblocktx",(uint64_t)nLastBlockTx));
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
obj.push_back(Pair("generate", GetBoolArg("-gen")));
obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", -1)));
obj.push_back(Pair("hashespersec", gethashespersec(params, false)));
obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
obj.push_back(Pair("testnet", fTestNet));
obj.push_back(Pair("blocks", (int)nBestHeight));
obj.push_back(Pair("currentblocksize", (uint64_t)nLastBlockSize));
obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx));
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
obj.push_back(Pair("generate", GetBoolArg("-gen", false)));
obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", -1)));
obj.push_back(Pair("hashespersec", gethashespersec(params, false)));
obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
obj.push_back(Pair("testnet", fTestNet));
return obj;
}

View File

@ -6,8 +6,7 @@
BOOST_AUTO_TEST_SUITE(getarg_tests)
static void
ResetArgs(const std::string& strArg)
static void ResetArgs(const std::string& strArg)
{
std::vector<std::string> vecArg;
boost::split(vecArg, strArg, boost::is_space(), boost::token_compress_on);
@ -26,62 +25,50 @@ ResetArgs(const std::string& strArg)
BOOST_AUTO_TEST_CASE(boolarg)
{
ResetArgs("-foo");
BOOST_CHECK(GetBoolArg("-foo"));
BOOST_CHECK(GetBoolArg("-foo", false));
BOOST_CHECK(GetBoolArg("-foo", true));
BOOST_CHECK(!GetBoolArg("-fo"));
BOOST_CHECK(!GetBoolArg("-fo", false));
BOOST_CHECK(GetBoolArg("-fo", true));
BOOST_CHECK(!GetBoolArg("-fooo"));
BOOST_CHECK(!GetBoolArg("-fooo", false));
BOOST_CHECK(GetBoolArg("-fooo", true));
ResetArgs("-foo=0");
BOOST_CHECK(!GetBoolArg("-foo"));
BOOST_CHECK(!GetBoolArg("-foo", false));
BOOST_CHECK(!GetBoolArg("-foo", true));
ResetArgs("-foo=1");
BOOST_CHECK(GetBoolArg("-foo"));
BOOST_CHECK(GetBoolArg("-foo", false));
BOOST_CHECK(GetBoolArg("-foo", true));
// New 0.6 feature: auto-map -nosomething to !-something:
ResetArgs("-nofoo");
BOOST_CHECK(!GetBoolArg("-foo"));
BOOST_CHECK(!GetBoolArg("-foo", false));
BOOST_CHECK(!GetBoolArg("-foo", true));
ResetArgs("-nofoo=1");
BOOST_CHECK(!GetBoolArg("-foo"));
BOOST_CHECK(!GetBoolArg("-foo", false));
BOOST_CHECK(!GetBoolArg("-foo", true));
ResetArgs("-foo -nofoo"); // -foo should win
BOOST_CHECK(GetBoolArg("-foo"));
BOOST_CHECK(GetBoolArg("-foo", false));
BOOST_CHECK(GetBoolArg("-foo", true));
ResetArgs("-foo=1 -nofoo=1"); // -foo should win
BOOST_CHECK(GetBoolArg("-foo"));
BOOST_CHECK(GetBoolArg("-foo", false));
BOOST_CHECK(GetBoolArg("-foo", true));
ResetArgs("-foo=0 -nofoo=0"); // -foo should win
BOOST_CHECK(!GetBoolArg("-foo"));
BOOST_CHECK(!GetBoolArg("-foo", false));
BOOST_CHECK(!GetBoolArg("-foo", true));
// New 0.6 feature: treat -- same as -:
ResetArgs("--foo=1");
BOOST_CHECK(GetBoolArg("-foo"));
BOOST_CHECK(GetBoolArg("-foo", false));
BOOST_CHECK(GetBoolArg("-foo", true));
ResetArgs("--nofoo=1");
BOOST_CHECK(!GetBoolArg("-foo"));
BOOST_CHECK(!GetBoolArg("-foo", false));
BOOST_CHECK(!GetBoolArg("-foo", true));
@ -133,7 +120,7 @@ BOOST_AUTO_TEST_CASE(intarg)
BOOST_AUTO_TEST_CASE(doubledash)
{
ResetArgs("--foo");
BOOST_CHECK_EQUAL(GetBoolArg("-foo"), true);
BOOST_CHECK_EQUAL(GetBoolArg("-foo", false), true);
ResetArgs("--foo=verbose --bar=1");
BOOST_CHECK_EQUAL(GetArg("-foo", ""), "verbose");
@ -143,25 +130,24 @@ BOOST_AUTO_TEST_CASE(doubledash)
BOOST_AUTO_TEST_CASE(boolargno)
{
ResetArgs("-nofoo");
BOOST_CHECK(!GetBoolArg("-foo"));
BOOST_CHECK(!GetBoolArg("-foo", true));
BOOST_CHECK(!GetBoolArg("-foo", false));
ResetArgs("-nofoo=1");
BOOST_CHECK(!GetBoolArg("-foo"));
BOOST_CHECK(!GetBoolArg("-foo", true));
BOOST_CHECK(!GetBoolArg("-foo", false));
ResetArgs("-nofoo=0");
BOOST_CHECK(GetBoolArg("-foo"));
BOOST_CHECK(GetBoolArg("-foo", true));
BOOST_CHECK(GetBoolArg("-foo", false));
ResetArgs("-foo --nofoo");
BOOST_CHECK(GetBoolArg("-foo"));
BOOST_CHECK(GetBoolArg("-foo", true));
BOOST_CHECK(GetBoolArg("-foo", false));
ResetArgs("-nofoo -foo"); // foo always wins:
BOOST_CHECK(GetBoolArg("-foo"));
BOOST_CHECK(GetBoolArg("-foo", true));
BOOST_CHECK(GetBoolArg("-foo", false));
}
BOOST_AUTO_TEST_SUITE_END()

View File

@ -31,7 +31,7 @@ BOOST_AUTO_TEST_CASE(util_criticalsection)
}
BOOST_AUTO_TEST_CASE(util_MedianFilter)
{
{
CMedianFilter<int> filter(5, 15);
BOOST_CHECK_EQUAL(filter.median(), 15);
@ -56,10 +56,10 @@ BOOST_AUTO_TEST_CASE(util_MedianFilter)
}
static const unsigned char ParseHex_expected[65] = {
0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, 0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7,
0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, 0xa6, 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde,
0xb6, 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, 0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12,
0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, 0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d,
0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, 0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7,
0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, 0xa6, 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde,
0xb6, 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, 0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12,
0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, 0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d,
0x5f
};
BOOST_AUTO_TEST_CASE(util_ParseHex)
@ -123,13 +123,13 @@ BOOST_AUTO_TEST_CASE(util_ParseParameters)
BOOST_CHECK(mapArgs.empty() && mapMultiArgs.empty());
ParseParameters(5, (char**)argv_test);
// expectation: -ignored is ignored (program name argument),
// expectation: -ignored is ignored (program name argument),
// -a, -b and -ccc end up in map, -d ignored because it is after
// a non-option argument (non-GNU option parsing)
BOOST_CHECK(mapArgs.size() == 3 && mapMultiArgs.size() == 3);
BOOST_CHECK(mapArgs.count("-a") && mapArgs.count("-b") && mapArgs.count("-ccc")
BOOST_CHECK(mapArgs.count("-a") && mapArgs.count("-b") && mapArgs.count("-ccc")
&& !mapArgs.count("f") && !mapArgs.count("-d"));
BOOST_CHECK(mapMultiArgs.count("-a") && mapMultiArgs.count("-b") && mapMultiArgs.count("-ccc")
BOOST_CHECK(mapMultiArgs.count("-a") && mapMultiArgs.count("-b") && mapMultiArgs.count("-ccc")
&& !mapMultiArgs.count("f") && !mapMultiArgs.count("-d"));
BOOST_CHECK(mapArgs["-a"] == "" && mapArgs["-ccc"] == "multiple");
@ -154,10 +154,10 @@ BOOST_AUTO_TEST_CASE(util_GetArg)
BOOST_CHECK_EQUAL(GetArg("inttest1", -1), 12345);
BOOST_CHECK_EQUAL(GetArg("inttest2", -1), 81985529216486895LL);
BOOST_CHECK_EQUAL(GetArg("inttest3", -1), -1);
BOOST_CHECK_EQUAL(GetBoolArg("booltest1"), true);
BOOST_CHECK_EQUAL(GetBoolArg("booltest2"), false);
BOOST_CHECK_EQUAL(GetBoolArg("booltest3"), false);
BOOST_CHECK_EQUAL(GetBoolArg("booltest4"), true);
BOOST_CHECK_EQUAL(GetBoolArg("booltest1", false), true);
BOOST_CHECK_EQUAL(GetBoolArg("booltest2", false), false);
BOOST_CHECK_EQUAL(GetBoolArg("booltest3", false), false);
BOOST_CHECK_EQUAL(GetBoolArg("booltest4", false), true);
}
BOOST_AUTO_TEST_CASE(util_WildcardMatch)

View File

@ -518,7 +518,7 @@ static void InterpretNegativeSetting(string name, map<string, string>& mapSettin
positive.append(name.begin()+3, name.end());
if (mapSettingsRet.count(positive) == 0)
{
bool value = !GetBoolArg(name);
bool value = !GetBoolArg(name, false);
mapSettingsRet[positive] = (value ? "1" : "0");
}
}
@ -1171,7 +1171,6 @@ bool TruncateFile(FILE *file, unsigned int length) {
#endif
}
// this function tries to raise the file descriptor limit to the requested number.
// It returns the actual file descriptor limit (which may be more or less than nMinFD)
int RaiseFileDescriptorLimit(int nMinFD) {
@ -1257,8 +1256,8 @@ void ShrinkDebugFile()
fclose(file);
}
}
else if(file != NULL)
fclose(file);
else if (file != NULL)
fclose(file);
}

View File

@ -390,7 +390,7 @@ int64 GetArg(const std::string& strArg, int64 nDefault);
* @param default (true or false)
* @return command-line argument or default value
*/
bool GetBoolArg(const std::string& strArg, bool fDefault=false);
bool GetBoolArg(const std::string& strArg, bool fDefault);
/**
* Set an argument if it doesn't already have a value