1
/***************************************************************************
2
* Copyright (C) 2005 by Joris Guisson *
3
* joris.guisson@gmail.com *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19
***************************************************************************/
20
#include <torrent/bdecoder.h>
21
#include <torrent/bnode.h>
22
#include <kademlia/rpcmsg.h>
24
#include <torrent/globals.h>
25
#include "dhtmsgparsetest.h"
34
DHTMsgParseTest::DHTMsgParseTest() : UnitTest("DHTMsgParseTest")
38
DHTMsgParseTest::~DHTMsgParseTest()
41
bool DHTMsgParseTest::doTest(const QString & data,int method)
43
QByteArray bdata(data.length());
45
for (int i = 0;i < data.length();i++)
50
BDecoder bdec(bdata,false);
52
BNode* n = bdec.decode();
53
if (n->getType() != BNode::DICT)
56
Out() << "Packet does not contain a dictionary" << endl;
60
MsgBase* msg = MakeRPCMsgTest((BDictNode*)n,(dht::Method)method);
64
Out() << "Error parsing message : " << endl;
74
bool DHTMsgParseTest::doTest()
77
QString test_str[] = {
78
"d1:rd2:id20:####################5:token20:####################6:valuesl6:######6:######6:######6:######6:######6:######6:######6:######ee1:t1:#1:y1:re",
80
"d1:ad2:id20:####################9:info_hash20:####################e1:q9:get_peers1:t1:#1:y1:qe",
82
"d1:rd2:id20:####################5:nodes208:################################################################################################################################################################################################################5:token20:####################e1:t1:#1:y1:re",
87
int types[] = {dht::GET_PEERS,dht::NONE,dht::GET_PEERS};
90
while (!test_str[i].isNull())
92
// read and decode the packet
93
if (!doTest(test_str[i],types[i]))
95
Out() << "Testing packet " << i << " : Failed" << endl;
100
Out() << "Testing packet " << i << " : OK" << endl;