mirror of
https://github.com/aria2/aria2.git
synced 2025-04-06 14:07:37 +03:00
Extract the Peer class's member variables, which are only needed after PeerInteractionCommand, into PeerSessionResource class. This class is instantiated in PeerInteractionCommand class's ctor and released in its dtor. This will make Peer class lightweight and uses less memory for peers which are not connected and wait in the queue. * src/PeerChokeCommand.cc * src/PeerSessionResource.{h, cc} * src/PeerInteractionCommand.cc * src/PeerAbstractCommand.cc: Note: 0 is given to onAbort() function. * src/DefaultBtInteractive.cc * src/BtPieceMessage.cc * src/BtInterestedMessage.cc * src/BtUnchokeMessage.cc * src/DefaultPeerStorage.{h, cc} * src/PeerInitiateConnectionCommand.cc * src/ActivePeerConnectionCommand.cc * src/BtNotInterestedMessage.cc * src/DefaultBtMessageDispatcher.cc * src/BtChokeMessage.cc * src/BtRequestMessage.cc * src/Peer.{h, cc} * src/BtRegistry.h * src/TrackerWatcherCommand.cc * src/PeerReceiveHandshakeCommand.cc * test/BtExtendedMessageTest.cc * test/BtAllowedFastMessageTest.cc * test/BtCancelMessageTest.cc * test/DefaultPieceStorageTest.cc * test/BtBitfieldMessageTest.cc * test/BtHaveMessageTest.cc * test/BtNotInterestedMessageTest.cc * test/BtRequestMessageTest.cc * test/PeerSessionResourceTest.cc * test/DefaultBtMessageDispatcherTest.cc * test/PeerTest.cc * test/BtInterestedMessageTest.cc * test/BtRejectMessageTest.cc * test/BtChokeMessageTest.cc * test/DefaultPeerStorageTest.cc * test/BtHaveNoneMessageTest.cc * test/BtHaveAllMessageTest.cc * test/DefaultExtensionMessageFactoryTest.cc * test/BtUnchokeMessageTest.cc * test/DefaultBtMessageFactoryTest.cc * test/HandshakeExtensionMessageTest.cc * test/UTPexExtensionMessageTest.cc * test/DefaultBtRequestFactoryTest.cc * test/BtPieceMessageTest.cc Removed typedef PeerStats. * src/PeerStat.h * src/SegmentMan.cc
62 lines
1.4 KiB
C++
62 lines
1.4 KiB
C++
#include "Peer.h"
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
namespace aria2 {
|
|
|
|
class PeerTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(PeerTest);
|
|
CPPUNIT_TEST(testPeerAllowedIndexSet);
|
|
CPPUNIT_TEST(testAmAllowedIndexSet);
|
|
CPPUNIT_TEST(testGetId);
|
|
CPPUNIT_TEST(testOperatorEqual);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
private:
|
|
SharedHandle<Peer> peer;
|
|
public:
|
|
PeerTest():peer(0) {}
|
|
|
|
void setUp() {
|
|
peer = new Peer("localhost", 6969);
|
|
peer->allocateSessionResource(1024, 1024*1024);
|
|
}
|
|
|
|
void testPeerAllowedIndexSet();
|
|
void testAmAllowedIndexSet();
|
|
void testGetId();
|
|
void testOperatorEqual();
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(PeerTest);
|
|
|
|
void PeerTest::testPeerAllowedIndexSet() {
|
|
CPPUNIT_ASSERT(!peer->isInPeerAllowedIndexSet(0));
|
|
peer->addPeerAllowedIndex(0);
|
|
CPPUNIT_ASSERT(peer->isInPeerAllowedIndexSet(0));
|
|
}
|
|
|
|
void PeerTest::testAmAllowedIndexSet() {
|
|
CPPUNIT_ASSERT(!peer->isInAmAllowedIndexSet(0));
|
|
peer->addAmAllowedIndex(0);
|
|
CPPUNIT_ASSERT(peer->isInAmAllowedIndexSet(0));
|
|
}
|
|
|
|
void PeerTest::testGetId() {
|
|
CPPUNIT_ASSERT_EQUAL(std::string("f05897fc14a41cb3400e283e189158656d7184da"),
|
|
peer->getID());
|
|
}
|
|
|
|
void PeerTest::testOperatorEqual()
|
|
{
|
|
CPPUNIT_ASSERT(Peer("localhost", 6881) == Peer("localhost", 6881));
|
|
|
|
{
|
|
Peer p1("localhost", 6881);
|
|
Peer p2("localhsot", 0);
|
|
p2.port = 6881;
|
|
CPPUNIT_ASSERT(p1 != p2);
|
|
}
|
|
}
|
|
|
|
} // namespace aria2
|