2009-04-23 13:39:53 +00:00
|
|
|
#include "PeerListProcessor.h"
|
|
|
|
|
|
|
|
#include <cstdlib>
|
2008-12-09 15:03:29 +00:00
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2006-10-01 11:29:14 +00:00
|
|
|
#include "Exception.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "Peer.h"
|
2008-12-09 15:03:29 +00:00
|
|
|
#include "bencode.h"
|
2009-04-23 13:39:53 +00:00
|
|
|
#include "TimeA2.h"
|
2006-10-01 11:29:14 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2006-10-01 11:29:14 +00:00
|
|
|
|
2009-04-23 13:39:53 +00:00
|
|
|
class PeerListProcessorTest:public CppUnit::TestFixture {
|
2006-10-01 11:29:14 +00:00
|
|
|
|
2009-04-23 13:39:53 +00:00
|
|
|
CPPUNIT_TEST_SUITE(PeerListProcessorTest);
|
|
|
|
CPPUNIT_TEST(testExtractPeerFromList);
|
|
|
|
CPPUNIT_TEST(testExtract2PeersFromList);
|
2006-10-01 11:29:14 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp() {
|
|
|
|
}
|
|
|
|
|
2009-04-23 13:39:53 +00:00
|
|
|
void testExtractPeerFromList();
|
|
|
|
void testExtract2PeersFromList();
|
2006-10-01 11:29:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-04-23 13:39:53 +00:00
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( PeerListProcessorTest );
|
2006-10-01 11:29:14 +00:00
|
|
|
|
2009-04-23 13:39:53 +00:00
|
|
|
void PeerListProcessorTest::testExtractPeerFromList() {
|
|
|
|
PeerListProcessor proc;
|
2009-09-29 14:52:42 +00:00
|
|
|
std::string peersString =
|
|
|
|
"d5:peersld2:ip11:192.168.0.17:peer id20:aria2-00000000000000"
|
|
|
|
"4:porti2006eeee";
|
2006-10-01 11:29:14 +00:00
|
|
|
|
2009-04-27 11:45:22 +00:00
|
|
|
const BDE dict = bencode::decode(peersString);
|
2006-10-18 14:57:00 +00:00
|
|
|
|
2008-05-12 11:05:21 +00:00
|
|
|
std::deque<SharedHandle<Peer> > peers;
|
2009-04-23 13:39:53 +00:00
|
|
|
proc.extractPeerFromList(dict["peers"], std::back_inserter(peers));
|
2006-10-01 11:29:14 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, peers.size());
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Peer> peer = *peers.begin();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), peer->ipaddr);
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint16_t)2006, peer->port);
|
2006-10-01 11:29:14 +00:00
|
|
|
}
|
|
|
|
|
2009-04-23 13:39:53 +00:00
|
|
|
void PeerListProcessorTest::testExtract2PeersFromList() {
|
|
|
|
PeerListProcessor proc;
|
2009-09-29 14:52:42 +00:00
|
|
|
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";
|
2006-10-01 11:29:14 +00:00
|
|
|
|
2009-04-27 11:45:22 +00:00
|
|
|
const BDE dict = bencode::decode(peersString);
|
2006-10-01 11:29:14 +00:00
|
|
|
|
2008-05-12 11:05:21 +00:00
|
|
|
std::deque<SharedHandle<Peer> > peers;
|
2009-04-23 13:39:53 +00:00
|
|
|
proc.extractPeerFromList(dict["peers"], std::back_inserter(peers));
|
2006-10-01 11:29:14 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, peers.size());
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Peer> peer = *peers.begin();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), peer->ipaddr);
|
2008-12-09 15:03:29 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint16_t)65535, peer->port);
|
2006-10-01 11:29:14 +00:00
|
|
|
|
|
|
|
peer = *(peers.begin()+1);
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.2"), peer->ipaddr);
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint16_t)2007, peer->port);
|
2006-10-01 11:29:14 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|