aria2/test/DHTFindNodeReplyMessageTest.cc

71 lines
1.9 KiB
C++
Raw Normal View History

#include "DHTFindNodeReplyMessage.h"
#include <cppunit/extensions/HelperMacros.h>
#include "DHTNode.h"
#include "Exception.h"
#include "Util.h"
#include "DHTBucket.h"
2009-09-29 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> Move all functions in PeerMessageUtil to bittorrent_helper. * src/BtBitfieldMessage.cc * src/BtBitfieldMessageValidator.h * src/BtExtendedMessage.cc * src/BtHandshakeMessage.cc * src/BtHandshakeMessageValidator.h * src/BtPieceMessage.cc * src/BtPieceMessageValidator.h * src/BtPortMessage.cc * src/DHTFindNodeReplyMessage.cc * src/DHTGetPeersReplyMessage.cc * src/DHTMessageFactoryImpl.cc * src/DHTRoutingTableDeserializer.cc * src/DHTRoutingTableSerializer.cc * src/DHTTokenTracker.cc * src/DefaultBtMessageFactory.cc * src/IndexBtMessage.cc * src/IndexBtMessage.h * src/IndexBtMessageValidator.h * src/Makefile.am * src/PeerMessageUtil.cc: Removed. * src/PeerMessageUtil.h: Removed. * src/RangeBtMessage.cc * src/RangeBtMessage.h * src/RangeBtMessageValidator.h * src/UTPexExtensionMessage.cc * src/ZeroBtMessage.cc * src/ZeroBtMessage.h * src/bittorrent_helper.cc * src/bittorrent_helper.h * test/BittorrentHelperTest.cc * test/BtAllowedFastMessageTest.cc * test/BtBitfieldMessageTest.cc * test/BtCancelMessageTest.cc * test/BtChokeMessageTest.cc * test/BtExtendedMessageTest.cc * test/BtHandshakeMessageTest.cc * test/BtHaveAllMessageTest.cc * test/BtHaveMessageTest.cc * test/BtHaveNoneMessageTest.cc * test/BtInterestedMessageTest.cc * test/BtNotInterestedMessageTest.cc * test/BtPieceMessageTest.cc * test/BtPortMessageTest.cc * test/BtRejectMessageTest.cc * test/BtRequestMessageTest.cc * test/BtSuggestPieceMessageTest.cc * test/BtUnchokeMessageTest.cc * test/DHTFindNodeReplyMessageTest.cc * test/DHTGetPeersReplyMessageTest.cc * test/DHTMessageFactoryImplTest.cc * test/DHTRoutingTableDeserializerTest.cc * test/DHTRoutingTableSerializerTest.cc * test/DefaultBtMessageFactoryTest.cc * test/DefaultExtensionMessageFactoryTest.cc * test/Makefile.am * test/PeerListProcessorTest.cc * test/PeerMessageUtilTest.cc: Removed. * test/UTPexExtensionMessageTest.cc
2009-09-29 14:52:42 +00:00
#include "bittorrent_helper.h"
#include "bencode.h"
namespace aria2 {
class DHTFindNodeReplyMessageTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(DHTFindNodeReplyMessageTest);
CPPUNIT_TEST(testGetBencodedMessage);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {}
void tearDown() {}
void testGetBencodedMessage();
};
CPPUNIT_TEST_SUITE_REGISTRATION(DHTFindNodeReplyMessageTest);
void DHTFindNodeReplyMessageTest::testGetBencodedMessage()
{
SharedHandle<DHTNode> localNode(new DHTNode());
SharedHandle<DHTNode> remoteNode(new DHTNode());
unsigned char tid[DHT_TRANSACTION_ID_LENGTH];
util::generateRandomData(tid, DHT_TRANSACTION_ID_LENGTH);
std::string transactionID(&tid[0], &tid[DHT_TRANSACTION_ID_LENGTH]);
DHTFindNodeReplyMessage msg(localNode, remoteNode, transactionID);
std::string compactNodeInfo;
SharedHandle<DHTNode> nodes[8];
for(size_t i = 0; i < DHTBucket::K; ++i) {
nodes[i].reset(new DHTNode());
nodes[i]->setIPAddress("192.168.0."+Util::uitos(i+1));
nodes[i]->setPort(6881+i);
unsigned char buf[6];
2009-09-29 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> Move all functions in PeerMessageUtil to bittorrent_helper. * src/BtBitfieldMessage.cc * src/BtBitfieldMessageValidator.h * src/BtExtendedMessage.cc * src/BtHandshakeMessage.cc * src/BtHandshakeMessageValidator.h * src/BtPieceMessage.cc * src/BtPieceMessageValidator.h * src/BtPortMessage.cc * src/DHTFindNodeReplyMessage.cc * src/DHTGetPeersReplyMessage.cc * src/DHTMessageFactoryImpl.cc * src/DHTRoutingTableDeserializer.cc * src/DHTRoutingTableSerializer.cc * src/DHTTokenTracker.cc * src/DefaultBtMessageFactory.cc * src/IndexBtMessage.cc * src/IndexBtMessage.h * src/IndexBtMessageValidator.h * src/Makefile.am * src/PeerMessageUtil.cc: Removed. * src/PeerMessageUtil.h: Removed. * src/RangeBtMessage.cc * src/RangeBtMessage.h * src/RangeBtMessageValidator.h * src/UTPexExtensionMessage.cc * src/ZeroBtMessage.cc * src/ZeroBtMessage.h * src/bittorrent_helper.cc * src/bittorrent_helper.h * test/BittorrentHelperTest.cc * test/BtAllowedFastMessageTest.cc * test/BtBitfieldMessageTest.cc * test/BtCancelMessageTest.cc * test/BtChokeMessageTest.cc * test/BtExtendedMessageTest.cc * test/BtHandshakeMessageTest.cc * test/BtHaveAllMessageTest.cc * test/BtHaveMessageTest.cc * test/BtHaveNoneMessageTest.cc * test/BtInterestedMessageTest.cc * test/BtNotInterestedMessageTest.cc * test/BtPieceMessageTest.cc * test/BtPortMessageTest.cc * test/BtRejectMessageTest.cc * test/BtRequestMessageTest.cc * test/BtSuggestPieceMessageTest.cc * test/BtUnchokeMessageTest.cc * test/DHTFindNodeReplyMessageTest.cc * test/DHTGetPeersReplyMessageTest.cc * test/DHTMessageFactoryImplTest.cc * test/DHTRoutingTableDeserializerTest.cc * test/DHTRoutingTableSerializerTest.cc * test/DefaultBtMessageFactoryTest.cc * test/DefaultExtensionMessageFactoryTest.cc * test/Makefile.am * test/PeerListProcessorTest.cc * test/PeerMessageUtilTest.cc: Removed. * test/UTPexExtensionMessageTest.cc
2009-09-29 14:52:42 +00:00
CPPUNIT_ASSERT(bittorrent::createcompact
(buf, nodes[i]->getIPAddress(), nodes[i]->getPort()));
compactNodeInfo +=
std::string(&nodes[i]->getID()[0], &nodes[i]->getID()[DHT_ID_LENGTH])+
std::string(&buf[0], &buf[sizeof(buf)]);
}
msg.setClosestKNodes(std::deque<SharedHandle<DHTNode> >(&nodes[0], &nodes[DHTBucket::K]));
std::string msgbody = msg.getBencodedMessage();
2009-04-27 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> Put BDE in aria2 namespace. BDE will also be used to store xml-rpc request. * src/AnnounceList.cc * src/AnnounceList.h * src/BDE.cc: Added * src/BDE.h: Added * src/DHTAbstractMessage.cc * src/DHTAbstractMessage.h * src/DHTAnnouncePeerMessage.cc * src/DHTAnnouncePeerMessage.h * src/DHTAnnouncePeerReplyMessage.cc * src/DHTAnnouncePeerReplyMessage.h * src/DHTFindNodeMessage.cc * src/DHTFindNodeMessage.h * src/DHTFindNodeReplyMessage.cc * src/DHTFindNodeReplyMessage.h * src/DHTGetPeersMessage.cc * src/DHTGetPeersMessage.h * src/DHTGetPeersReplyMessage.cc * src/DHTGetPeersReplyMessage.h * src/DHTMessageFactory.h * src/DHTMessageFactoryImpl.cc * src/DHTMessageFactoryImpl.h * src/DHTMessageReceiver.cc * src/DHTMessageTracker.cc * src/DHTMessageTracker.h * src/DHTPingMessage.cc * src/DHTPingMessage.h * src/DHTPingReplyMessage.cc * src/DHTPingReplyMessage.h * src/DHTQueryMessage.cc * src/DHTQueryMessage.h * src/DHTResponseMessage.cc * src/DHTResponseMessage.h * src/DefaultBtAnnounce.cc * src/DefaultBtContext.cc * src/DefaultBtContext.h * src/HandshakeExtensionMessage.cc * src/Makefile.am * src/PeerListProcessor.h * src/UTPexExtensionMessage.cc * src/bencode.cc * src/bencode.h * test/AnnounceListTest.cc * test/BDETest.cc: Added * test/BencodeTest.cc * test/DHTAnnouncePeerMessageTest.cc * test/DHTAnnouncePeerReplyMessageTest.cc * test/DHTFindNodeMessageTest.cc * test/DHTFindNodeReplyMessageTest.cc * test/DHTGetPeersMessageTest.cc * test/DHTGetPeersReplyMessageTest.cc * test/DHTMessageFactoryImplTest.cc * test/DHTMessageTrackerTest.cc * test/DHTPingMessageTest.cc * test/DHTPingReplyMessageTest.cc * test/Makefile.am * test/MockDHTMessageFactory.h * test/PeerListProcessorTest.cc
2009-04-27 11:45:22 +00:00
BDE dict = BDE::dict();
dict["t"] = transactionID;
2009-04-27 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> Put BDE in aria2 namespace. BDE will also be used to store xml-rpc request. * src/AnnounceList.cc * src/AnnounceList.h * src/BDE.cc: Added * src/BDE.h: Added * src/DHTAbstractMessage.cc * src/DHTAbstractMessage.h * src/DHTAnnouncePeerMessage.cc * src/DHTAnnouncePeerMessage.h * src/DHTAnnouncePeerReplyMessage.cc * src/DHTAnnouncePeerReplyMessage.h * src/DHTFindNodeMessage.cc * src/DHTFindNodeMessage.h * src/DHTFindNodeReplyMessage.cc * src/DHTFindNodeReplyMessage.h * src/DHTGetPeersMessage.cc * src/DHTGetPeersMessage.h * src/DHTGetPeersReplyMessage.cc * src/DHTGetPeersReplyMessage.h * src/DHTMessageFactory.h * src/DHTMessageFactoryImpl.cc * src/DHTMessageFactoryImpl.h * src/DHTMessageReceiver.cc * src/DHTMessageTracker.cc * src/DHTMessageTracker.h * src/DHTPingMessage.cc * src/DHTPingMessage.h * src/DHTPingReplyMessage.cc * src/DHTPingReplyMessage.h * src/DHTQueryMessage.cc * src/DHTQueryMessage.h * src/DHTResponseMessage.cc * src/DHTResponseMessage.h * src/DefaultBtAnnounce.cc * src/DefaultBtContext.cc * src/DefaultBtContext.h * src/HandshakeExtensionMessage.cc * src/Makefile.am * src/PeerListProcessor.h * src/UTPexExtensionMessage.cc * src/bencode.cc * src/bencode.h * test/AnnounceListTest.cc * test/BDETest.cc: Added * test/BencodeTest.cc * test/DHTAnnouncePeerMessageTest.cc * test/DHTAnnouncePeerReplyMessageTest.cc * test/DHTFindNodeMessageTest.cc * test/DHTFindNodeReplyMessageTest.cc * test/DHTGetPeersMessageTest.cc * test/DHTGetPeersReplyMessageTest.cc * test/DHTMessageFactoryImplTest.cc * test/DHTMessageTrackerTest.cc * test/DHTPingMessageTest.cc * test/DHTPingReplyMessageTest.cc * test/Makefile.am * test/MockDHTMessageFactory.h * test/PeerListProcessorTest.cc
2009-04-27 11:45:22 +00:00
dict["y"] = BDE("r");
BDE rDict = BDE::dict();
rDict["id"] = BDE(localNode->getID(), DHT_ID_LENGTH);
rDict["nodes"] = compactNodeInfo;
dict["r"] = rDict;
CPPUNIT_ASSERT_EQUAL(bencode::encode(dict), msgbody);
}
} // namespace aria2