From e46704dd904192d8731eae1226805252e5252a0e Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sat, 21 Apr 2012 01:37:34 +0200 Subject: [PATCH] Expose CRPCTable via bitcoinrpc.h for testing --- src/bitcoinrpc.cpp | 31 +++++-------------------------- src/bitcoinrpc.h | 34 ++++++++++++++++++++++++++++++++++ src/test/rpc_tests.cpp | 9 ++------- 3 files changed, 41 insertions(+), 33 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 24b1220..206347f 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -10,6 +10,7 @@ #include "net.h" #include "init.h" #include "ui_interface.h" +#include "bitcoinrpc.h" #undef printf #include @@ -22,9 +23,6 @@ #include typedef boost::asio::ssl::stream SSLStream; -#include "json/json_spirit_reader_template.h" -#include "json/json_spirit_writer_template.h" -#include "json/json_spirit_utils.h" #define printf OutputDebugStringF // MinGW 3.4.5 gets "fatal error: had to relocate PCH" if the json headers are // precompiled in headers.h. The problem might be when the pch file goes over @@ -37,27 +35,6 @@ using namespace boost::asio; using namespace json_spirit; void ThreadRPCServer2(void* parg); -typedef Value(*rpcfn_type)(const Array& params, bool fHelp); - -class CRPCCommand -{ -public: - string name; - rpcfn_type actor; - bool okSafeMode; -}; - -class CRPCTable -{ -private: - map mapCommands; -public: - CRPCTable(); - const CRPCCommand* operator[](string name) const; - string help(string name) const; -}; - -const CRPCTable tableRPC; static std::string strRPCUserColonPass; @@ -2028,7 +2005,7 @@ Value getblock(const Array& params, bool fHelp) // -static CRPCCommand vRPCCommands[] = +static const CRPCCommand vRPCCommands[] = { // name function safe mode? // ------------------------ ----------------------- ---------- { "help", &help, true }, @@ -2084,7 +2061,7 @@ CRPCTable::CRPCTable() unsigned int vcidx; for (vcidx = 0; vcidx < (sizeof(vRPCCommands) / sizeof(vRPCCommands[0])); vcidx++) { - CRPCCommand *pcmd; + const CRPCCommand *pcmd; pcmd = &vRPCCommands[vcidx]; mapCommands[pcmd->name] = pcmd; @@ -2785,3 +2762,5 @@ int main(int argc, char *argv[]) return 0; } #endif + +const CRPCTable tableRPC; diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index a9cf329..6b7293e 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -3,5 +3,39 @@ // Distributed under the MIT/X11 software license, see the accompanying // file license.txt or http://www.opensource.org/licenses/mit-license.php. +#ifndef _BITCOINRPC_H_ +#define _BITCOINRPC_H_ 1 + +#include +#include + +#include "json/json_spirit_reader_template.h" +#include "json/json_spirit_writer_template.h" +#include "json/json_spirit_utils.h" + void ThreadRPCServer(void* parg); int CommandLineRPC(int argc, char *argv[]); + +typedef json_spirit::Value(*rpcfn_type)(const json_spirit::Array& params, bool fHelp); + +class CRPCCommand +{ +public: + std::string name; + rpcfn_type actor; + bool okSafeMode; +}; + +class CRPCTable +{ +private: + std::map mapCommands; +public: + CRPCTable(); + const CRPCCommand* operator[](std::string name) const; + std::string help(std::string name) const; +}; + +extern const CRPCTable tableRPC; + +#endif diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp index 87462f7..7a438e5 100644 --- a/src/test/rpc_tests.cpp +++ b/src/test/rpc_tests.cpp @@ -3,16 +3,11 @@ #include "base58.h" #include "util.h" -#include "json/json_spirit_reader_template.h" -#include "json/json_spirit_writer_template.h" -#include "json/json_spirit_utils.h" +#include "bitcoinrpc.h" using namespace std; using namespace json_spirit; -typedef Value(*rpcfn_type)(const Array& params, bool fHelp); -extern map mapCallTable; - BOOST_AUTO_TEST_SUITE(rpc_tests) static Array @@ -36,7 +31,7 @@ struct TestNetFixture BOOST_FIXTURE_TEST_CASE(rpc_addmultisig, TestNetFixture) { - rpcfn_type addmultisig = mapCallTable["addmultisigaddress"]; + rpcfn_type addmultisig = tableRPC["addmultisigaddress"]->actor; // old, 65-byte-long: const char* address1Hex = "0434e3e09f49ea168c5bbf53f877ff4206923858aab7c7e1df25bc263978107c95e35065a27ef6f1b27222db0ec97e0e895eaca603d3ee0d4c060ce3d8a00286c8"; -- 1.7.1