mirror of
https://github.com/aria2/aria2.git
synced 2025-04-06 05:57:36 +03:00
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
66 lines
1.9 KiB
C++
66 lines
1.9 KiB
C++
#include "PeerListProcessor.h"
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
#include "Exception.h"
|
|
#include "Peer.h"
|
|
#include "bencode.h"
|
|
#include "TimeA2.h"
|
|
#include "PeerMessageUtil.h"
|
|
|
|
namespace aria2 {
|
|
|
|
class PeerListProcessorTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(PeerListProcessorTest);
|
|
CPPUNIT_TEST(testExtractPeerFromList);
|
|
CPPUNIT_TEST(testExtract2PeersFromList);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
private:
|
|
|
|
public:
|
|
void setUp() {
|
|
}
|
|
|
|
void testExtractPeerFromList();
|
|
void testExtract2PeersFromList();
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( PeerListProcessorTest );
|
|
|
|
void PeerListProcessorTest::testExtractPeerFromList() {
|
|
PeerListProcessor proc;
|
|
std::string peersString = "d5:peersld2:ip11:192.168.0.17:peer id20:aria2-000000000000004:porti2006eeee";
|
|
|
|
const BDE dict = bencode::decode(peersString);
|
|
|
|
std::deque<SharedHandle<Peer> > peers;
|
|
proc.extractPeerFromList(dict["peers"], std::back_inserter(peers));
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, peers.size());
|
|
SharedHandle<Peer> peer = *peers.begin();
|
|
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), peer->ipaddr);
|
|
CPPUNIT_ASSERT_EQUAL((uint16_t)2006, peer->port);
|
|
}
|
|
|
|
void PeerListProcessorTest::testExtract2PeersFromList() {
|
|
PeerListProcessor proc;
|
|
std::string peersString = "d5:peersld2:ip11:192.168.0.17:peer id20:aria2-000000000000004:porti65535eed2:ip11:192.168.0.27:peer id20:aria2-000000000000004:porti2007eeee";
|
|
|
|
const BDE dict = bencode::decode(peersString);
|
|
|
|
std::deque<SharedHandle<Peer> > peers;
|
|
proc.extractPeerFromList(dict["peers"], std::back_inserter(peers));
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, peers.size());
|
|
SharedHandle<Peer> peer = *peers.begin();
|
|
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), peer->ipaddr);
|
|
CPPUNIT_ASSERT_EQUAL((uint16_t)65535, peer->port);
|
|
|
|
peer = *(peers.begin()+1);
|
|
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.2"), peer->ipaddr);
|
|
CPPUNIT_ASSERT_EQUAL((uint16_t)2007, peer->port);
|
|
}
|
|
|
|
} // namespace aria2
|