Browse Source

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
0.10
Philip Kaufmann 12 years ago
parent
commit
3260b4c090
  1. 6
      src/bitcoinrpc.cpp
  2. 28
      src/init.cpp
  3. 4
      src/main.cpp
  4. 16
      src/qt/bitcoin.cpp
  5. 2
      src/qt/splashscreen.cpp
  6. 4
      src/rpcmining.cpp
  7. 26
      src/test/getarg_tests.cpp
  8. 8
      src/test/util_tests.cpp
  9. 3
      src/util.cpp
  10. 2
      src/util.h

6
src/bitcoinrpc.cpp

@ -757,7 +757,7 @@ void StartRPCThreads() @@ -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 @@ -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) @@ -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);

28
src/init.cpp

@ -198,7 +198,7 @@ bool AppInit(int argc, char* argv[]) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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
{

4
src/main.cpp

@ -2931,7 +2931,7 @@ string GetWarnings(string strFor) @@ -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) @@ -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;

16
src/qt/bitcoin.cpp

@ -15,6 +15,9 @@ @@ -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 @@ @@ -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[]) @@ -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[]) @@ -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[]) @@ -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();
}

2
src/qt/splashscreen.cpp

@ -26,7 +26,7 @@ SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f) : @@ -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 {

4
src/rpcmining.cpp

@ -33,7 +33,7 @@ Value getgenerate(const Array& params, bool fHelp) @@ -33,7 +33,7 @@ Value getgenerate(const Array& params, bool fHelp)
"getgenerate\n"
"Returns true or false.");
return GetBoolArg("-gen");
return GetBoolArg("-gen", false);
}
@ -89,7 +89,7 @@ Value getmininginfo(const Array& params, bool fHelp) @@ -89,7 +89,7 @@ Value getmininginfo(const Array& params, bool fHelp)
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("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()));

26
src/test/getarg_tests.cpp

@ -6,8 +6,7 @@ @@ -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) @@ -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) @@ -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) @@ -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()

8
src/test/util_tests.cpp

@ -154,10 +154,10 @@ BOOST_AUTO_TEST_CASE(util_GetArg) @@ -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)

3
src/util.cpp

@ -518,7 +518,7 @@ static void InterpretNegativeSetting(string name, map<string, string>& mapSettin @@ -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) { @@ -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) {

2
src/util.h

@ -390,7 +390,7 @@ int64 GetArg(const std::string& strArg, int64 nDefault); @@ -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

Loading…
Cancel
Save