15
15
#include " util.h"
16
16
17
17
#include < QDir>
18
+ #include < QtGlobal>
18
19
19
20
#include < boost/filesystem.hpp>
20
21
22
+ static UniValue rpcNestedTest_rpc (const JSONRPCRequest& request)
23
+ {
24
+ if (request.fHelp ) {
25
+ return " help message" ;
26
+ }
27
+ return request.params .write (0 , 0 );
28
+ }
29
+
30
+ static const CRPCCommand vRPCCommands[] =
31
+ {
32
+ { " test" , " rpcNestedTest" , &rpcNestedTest_rpc, true },
33
+ };
34
+
21
35
void RPCNestedTests::rpcNestedTests ()
22
36
{
23
37
UniValue jsonRPCError;
@@ -26,6 +40,7 @@ void RPCNestedTests::rpcNestedTests()
26
40
// could be moved to a more generic place when we add more tests on QT level
27
41
const CChainParams& chainparams = Params ();
28
42
RegisterAllCoreRPCCommands (tableRPC);
43
+ tableRPC.appendCommand (" rpcNestedTest" , &vRPCCommands[0 ]);
29
44
ClearDatadirCache ();
30
45
std::string path = QDir::tempPath ().toStdString () + " /" + strprintf (" test_bitcoin_qt_%lu_%i" , (unsigned long )GetTime (), (int )(GetRand (100000 )));
31
46
QDir dir (QString::fromStdString (path));
@@ -63,16 +78,6 @@ void RPCNestedTests::rpcNestedTests()
63
78
RPCConsole::RPCExecuteCommandLine (result, " getblockchaininfo " ); // whitespace at the end will be tolerated
64
79
QVERIFY (result.substr (0 ,1 ) == " {" );
65
80
66
- #if QT_VERSION >= 0x050300
67
- // do the QVERIFY_EXCEPTION_THROWN checks only with Qt5.3 and higher (QVERIFY_EXCEPTION_THROWN was introduced in Qt5.3)
68
- QVERIFY_EXCEPTION_THROWN (RPCConsole::RPCExecuteCommandLine (result, " getblockchaininfo() .\n " ), std::runtime_error); // invalid syntax
69
- QVERIFY_EXCEPTION_THROWN (RPCConsole::RPCExecuteCommandLine (result, " getblockchaininfo() getblockchaininfo()" ), std::runtime_error); // invalid syntax
70
- (RPCConsole::RPCExecuteCommandLine (result, " getblockchaininfo(" )); // tolerate non closing brackets if we have no arguments
71
- (RPCConsole::RPCExecuteCommandLine (result, " getblockchaininfo()()()" )); // tolerate non command brackts
72
- QVERIFY_EXCEPTION_THROWN (RPCConsole::RPCExecuteCommandLine (result, " getblockchaininfo(True)" ), UniValue); // invalid argument
73
- QVERIFY_EXCEPTION_THROWN (RPCConsole::RPCExecuteCommandLine (result, " a(getblockchaininfo(True))" ), UniValue); // method not found
74
- #endif
75
-
76
81
(RPCConsole::RPCExecuteCommandLine (result, " getblockchaininfo()[\" chain\" ]" )); // Quote path identifier are allowed, but look after a child contaning the quotes in the key
77
82
QVERIFY (result == " null" );
78
83
@@ -85,6 +90,40 @@ void RPCNestedTests::rpcNestedTests()
85
90
RPCConsole::RPCExecuteCommandLine (result, " getblock(getbestblockhash())[tx][0]" );
86
91
QVERIFY (result == " 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b" );
87
92
93
+ RPCConsole::RPCExecuteCommandLine (result, " rpcNestedTest" );
94
+ QVERIFY (result == " []" );
95
+ RPCConsole::RPCExecuteCommandLine (result, " rpcNestedTest ''" );
96
+ QVERIFY (result == " [\"\" ]" );
97
+ RPCConsole::RPCExecuteCommandLine (result, " rpcNestedTest \"\" " );
98
+ QVERIFY (result == " [\"\" ]" );
99
+ RPCConsole::RPCExecuteCommandLine (result, " rpcNestedTest '' abc" );
100
+ QVERIFY (result == " [\"\" ,\" abc\" ]" );
101
+ RPCConsole::RPCExecuteCommandLine (result, " rpcNestedTest abc '' abc" );
102
+ QVERIFY (result == " [\" abc\" ,\"\" ,\" abc\" ]" );
103
+ RPCConsole::RPCExecuteCommandLine (result, " rpcNestedTest abc abc" );
104
+ QVERIFY (result == " [\" abc\" ,\" abc\" ]" );
105
+ RPCConsole::RPCExecuteCommandLine (result, " rpcNestedTest abc\t\t abc" );
106
+ QVERIFY (result == " [\" abc\" ,\" abc\" ]" );
107
+ RPCConsole::RPCExecuteCommandLine (result, " rpcNestedTest(abc )" );
108
+ QVERIFY (result == " [\" abc\" ]" );
109
+ RPCConsole::RPCExecuteCommandLine (result, " rpcNestedTest( abc )" );
110
+ QVERIFY (result == " [\" abc\" ]" );
111
+ RPCConsole::RPCExecuteCommandLine (result, " rpcNestedTest( abc , cba )" );
112
+ QVERIFY (result == " [\" abc\" ,\" cba\" ]" );
113
+
114
+ #if QT_VERSION >= 0x050300
115
+ // do the QVERIFY_EXCEPTION_THROWN checks only with Qt5.3 and higher (QVERIFY_EXCEPTION_THROWN was introduced in Qt5.3)
116
+ QVERIFY_EXCEPTION_THROWN (RPCConsole::RPCExecuteCommandLine (result, " getblockchaininfo() .\n " ), std::runtime_error); // invalid syntax
117
+ QVERIFY_EXCEPTION_THROWN (RPCConsole::RPCExecuteCommandLine (result, " getblockchaininfo() getblockchaininfo()" ), std::runtime_error); // invalid syntax
118
+ (RPCConsole::RPCExecuteCommandLine (result, " getblockchaininfo(" )); // tolerate non closing brackets if we have no arguments
119
+ (RPCConsole::RPCExecuteCommandLine (result, " getblockchaininfo()()()" )); // tolerate non command brackts
120
+ QVERIFY_EXCEPTION_THROWN (RPCConsole::RPCExecuteCommandLine (result, " getblockchaininfo(True)" ), UniValue); // invalid argument
121
+ QVERIFY_EXCEPTION_THROWN (RPCConsole::RPCExecuteCommandLine (result, " a(getblockchaininfo(True))" ), UniValue); // method not found
122
+ QVERIFY_EXCEPTION_THROWN (RPCConsole::RPCExecuteCommandLine (result, " rpcNestedTest abc,,abc" ), std::runtime_error); // don't tollerate empty arguments when using ,
123
+ QVERIFY_EXCEPTION_THROWN (RPCConsole::RPCExecuteCommandLine (result, " rpcNestedTest(abc,,abc)" ), std::runtime_error); // don't tollerate empty arguments when using ,
124
+ QVERIFY_EXCEPTION_THROWN (RPCConsole::RPCExecuteCommandLine (result, " rpcNestedTest(abc,,)" ), std::runtime_error); // don't tollerate empty arguments when using ,
125
+ #endif
126
+
88
127
delete pcoinsTip;
89
128
delete pcoinsdbview;
90
129
delete pblocktree;
0 commit comments