mirror of
https://github.com/aria2/aria2.git
synced 2025-04-06 22:17:38 +03:00
70 lines
2 KiB
C++
70 lines
2 KiB
C++
#include "PeerListProcessor.h"
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
#include "Exception.h"
|
|
#include "Peer.h"
|
|
#include "TimeA2.h"
|
|
#include "bencode2.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-00000000000000"
|
|
"4:porti2006eeee";
|
|
|
|
SharedHandle<ValueBase> dict = bencode2::decode(peersString);
|
|
|
|
std::deque<SharedHandle<Peer> > peers;
|
|
proc.extractPeer(asDict(dict)->get("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->getIPAddress());
|
|
CPPUNIT_ASSERT_EQUAL((uint16_t)2006, peer->getPort());
|
|
}
|
|
|
|
void PeerListProcessorTest::testExtract2PeersFromList() {
|
|
PeerListProcessor proc;
|
|
std::string peersString =
|
|
"d5:peersld2:ip11:192.168.0.17:peer id20:aria2-00000000000000"
|
|
"4:porti65535eed2:ip11:192.168.0.27:peer id20:aria2-00000000000000"
|
|
"4:porti2007eeee";
|
|
|
|
SharedHandle<ValueBase> dict = bencode2::decode(peersString);
|
|
|
|
std::deque<SharedHandle<Peer> > peers;
|
|
proc.extractPeer(asDict(dict)->get("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->getIPAddress());
|
|
CPPUNIT_ASSERT_EQUAL((uint16_t)65535, peer->getPort());
|
|
|
|
peer = *(peers.begin()+1);
|
|
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.2"), peer->getIPAddress());
|
|
CPPUNIT_ASSERT_EQUAL((uint16_t)2007, peer->getPort());
|
|
}
|
|
|
|
} // namespace aria2
|