2008-11-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Made BtRegistry non-static object. Now DownloadEngine has a
	reference to its object.
	* src/AbstractBtMessage.cc
	* src/ActivePeerConnectionCommand.cc
	* src/ActivePeerConnectionCommand.h
	* src/BtContextAwareCommand.cc
	* src/BtContextAwareCommand.h
	* src/BtExtendedMessage.cc
	* src/BtExtendedMessage.h
	* src/BtInterestedMessage.cc
	* src/BtInterestedMessage.h
	* src/BtNotInterestedMessage.cc
	* src/BtNotInterestedMessage.h
	* src/BtRegistry.cc
	* src/BtRegistry.h
	* src/BtSeederStateChoke.cc
	* src/BtSetup.cc
	* src/DHTGetPeersCommand.cc
	* src/DHTGetPeersCommand.h
	* src/DHTPeerAnnounceEntry.cc
	* src/DHTPeerAnnounceEntry.h
	* src/DHTPeerAnnounceStorage.cc
	* src/DHTPeerAnnounceStorage.h
	* src/DHTPeerLookupTask.cc
	* src/DHTPeerLookupTask.h
	* src/DHTSetup.cc
	* src/DHTSetup.h
	* src/DHTTaskFactory.h
	* src/DHTTaskFactoryImpl.cc
	* src/DHTTaskFactoryImpl.h
	* src/DefaultBtAnnounce.cc
	* src/DefaultBtInteractive.cc
	* src/DefaultBtInteractive.h
	* src/DefaultBtMessageDispatcher.cc
	* src/DefaultBtMessageDispatcher.h
	* src/DefaultBtMessageFactory.cc
	* src/DefaultBtMessageFactory.h
	* src/DefaultBtMessageReceiver.cc
	* src/DefaultBtProgressInfoFile.cc
	* src/DefaultBtProgressInfoFile.h
	* src/DefaultBtRequestFactory.cc
	* src/DefaultBtRequestFactory.h
	* src/DefaultExtensionMessageFactory.cc
	* src/DefaultExtensionMessageFactory.h
	* src/DefaultPeerStorage.cc
	* src/DefaultPeerStorage.h
	* src/DownloadEngine.cc
	* src/DownloadEngine.h
	* src/InitiatorMSEHandshakeCommand.cc
	* src/InitiatorMSEHandshakeCommand.h
	* src/MSEHandshake.cc
	* src/MSEHandshake.h
	* src/Makefile.am
	* src/Makefile.in
	* src/PeerChokeCommand.cc
	* src/PeerChokeCommand.h
	* src/PeerInitiateConnectionCommand.cc
	* src/PeerInitiateConnectionCommand.h
	* src/PeerInteractionCommand.cc
	* src/PeerInteractionCommand.h
	* src/PeerObject.h
	* src/PeerReceiveHandshakeCommand.cc
	* src/PeerReceiveHandshakeCommand.h
	* src/ReceiverMSEHandshakeCommand.cc
	* src/RequestGroup.cc
	* src/RequestGroup.h
	* src/RequestGroupMan.cc
	* src/RequestGroupMan.h
	* src/SeedCheckCommand.cc
	* src/SeedCheckCommand.h
	* src/ShareRatioSeedCriteria.h
	* src/SimpleBtMessage.cc
	* src/TrackerWatcherCommand.cc
	* src/TrackerWatcherCommand.h
	* src/UTPexExtensionMessage.cc
	* src/UTPexExtensionMessage.h
	* test/BtCancelMessageTest.cc
	* test/BtChokeMessageTest.cc
	* test/BtExtendedMessageTest.cc
	* test/BtInterestedMessageTest.cc
	* test/BtNotInterestedMessageTest.cc
	* test/BtPieceMessageTest.cc
	* test/BtPortMessageTest.cc
	* test/BtRegistryTest.cc
	* test/BtRejectMessageTest.cc
	* test/BtRequestMessageTest.cc
	* test/DHTPeerAnnounceEntryTest.cc
	* test/DHTPeerAnnounceStorageTest.cc
	* test/DefaultBtMessageDispatcherTest.cc
	* test/DefaultBtMessageFactoryTest.cc
	* test/DefaultBtProgressInfoFileTest.cc
	* test/DefaultBtRequestFactoryTest.cc
	* test/DefaultExtensionMessageFactoryTest.cc
	* test/MSEHandshakeTest.cc
	* test/MockDHTTaskFactory.h
	* test/ShareRatioSeedCriteriaTest.cc
	* test/UTPexExtensionMessageTest.cc
This commit is contained in:
Tatsuhiro Tsujikawa 2008-11-03 06:49:02 +00:00
parent 93edc7bd20
commit 7cf589e784
96 changed files with 1709 additions and 1423 deletions

View file

@ -1,15 +1,16 @@
#include "UTPexExtensionMessage.h"
#include <iostream>
#include <cppunit/extensions/HelperMacros.h>
#include "Peer.h"
#include "a2netcompat.h"
#include "Util.h"
#include "PeerMessageUtil.h"
#include "BtRegistry.h"
#include "MockBtContext.h"
#include "MockPeerStorage.h"
#include "Exception.h"
#include "FileEntry.h"
#include <iostream>
#include <cppunit/extensions/HelperMacros.h>
namespace aria2 {
@ -28,24 +29,11 @@ class UTPexExtensionMessageTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testDroppedPeersAreFull);
CPPUNIT_TEST_SUITE_END();
private:
SharedHandle<MockBtContext> _btContext;
SharedHandle<MockPeerStorage> _peerStorage;
public:
void setUp()
{
BtRegistry::unregisterAll();
SharedHandle<MockBtContext> btContext(new MockBtContext());
unsigned char infohash[20];
memset(infohash, 0, sizeof(infohash));
btContext->setInfoHash(infohash);
_btContext = btContext;
SharedHandle<MockPeerStorage> peerStorage(new MockPeerStorage());
BtRegistry::registerPeerStorage(_btContext->getInfoHashAsString(),
peerStorage);
}
void tearDown()
{
BtRegistry::unregisterAll();
_peerStorage.reset(new MockPeerStorage());
}
void testGetExtensionMessageID();
@ -143,18 +131,18 @@ void UTPexExtensionMessageTest::testDoReceivedAction()
SharedHandle<Peer> p4(new Peer("10.1.1.3", 10000));
p4->startBadCondition();
msg.addDroppedPeer(p4);
msg.setBtContext(_btContext);
msg.setPeerStorage(_peerStorage);
msg.doReceivedAction();
CPPUNIT_ASSERT_EQUAL((size_t)2, PEER_STORAGE(_btContext)->getPeers().size());
CPPUNIT_ASSERT_EQUAL((size_t)2, _peerStorage->getPeers().size());
{
SharedHandle<Peer> p = PEER_STORAGE(_btContext)->getPeers()[0];
SharedHandle<Peer> p = _peerStorage->getPeers()[0];
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), p->ipaddr);
CPPUNIT_ASSERT_EQUAL((uint16_t)6881, p->port);
}
{
SharedHandle<Peer> p = PEER_STORAGE(_btContext)->getPeers()[1];
SharedHandle<Peer> p = _peerStorage->getPeers()[1];
CPPUNIT_ASSERT_EQUAL(std::string("10.1.1.2"), p->ipaddr);
CPPUNIT_ASSERT_EQUAL((uint16_t)9999, p->port);
}
@ -162,9 +150,6 @@ void UTPexExtensionMessageTest::testDoReceivedAction()
void UTPexExtensionMessageTest::testCreate()
{
_btContext->setPieceLength(256*1024);
_btContext->setTotalLength(1024*1024);
unsigned char c1[6];
unsigned char c2[6];
unsigned char c3[6];
@ -183,26 +168,30 @@ void UTPexExtensionMessageTest::testCreate()
"e";
SharedHandle<UTPexExtensionMessage> msg =
UTPexExtensionMessage::create(_btContext,
reinterpret_cast<const unsigned char*>(data.c_str()),
data.size());
UTPexExtensionMessage::create
(reinterpret_cast<const unsigned char*>(data.c_str()), data.size());
CPPUNIT_ASSERT_EQUAL((uint8_t)1, msg->getExtensionMessageID());
CPPUNIT_ASSERT_EQUAL((size_t)2, msg->getFreshPeers().size());
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), msg->getFreshPeers()[0]->ipaddr);
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"),
msg->getFreshPeers()[0]->ipaddr);
CPPUNIT_ASSERT_EQUAL((uint16_t)6881, msg->getFreshPeers()[0]->port);
CPPUNIT_ASSERT_EQUAL(std::string("10.1.1.2"), msg->getFreshPeers()[1]->ipaddr);
CPPUNIT_ASSERT_EQUAL(std::string("10.1.1.2"),
msg->getFreshPeers()[1]->ipaddr);
CPPUNIT_ASSERT_EQUAL((uint16_t)9999, msg->getFreshPeers()[1]->port);
CPPUNIT_ASSERT_EQUAL((size_t)2, msg->getDroppedPeers().size());
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.2"), msg->getDroppedPeers()[0]->ipaddr);
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.2"),
msg->getDroppedPeers()[0]->ipaddr);
CPPUNIT_ASSERT_EQUAL((uint16_t)6882, msg->getDroppedPeers()[0]->port);
CPPUNIT_ASSERT_EQUAL(std::string("10.1.1.3"), msg->getDroppedPeers()[1]->ipaddr);
CPPUNIT_ASSERT_EQUAL((uint16_t)10000, msg->getDroppedPeers()[1]->port);
CPPUNIT_ASSERT_EQUAL(std::string("10.1.1.3"),
msg->getDroppedPeers()[1]->ipaddr);
CPPUNIT_ASSERT_EQUAL((uint16_t)10000,
msg->getDroppedPeers()[1]->port);
try {
// 0 length data
std::string in = "";
UTPexExtensionMessage::create(_btContext,
reinterpret_cast<const unsigned char*>(in.c_str()),
in.size());
UTPexExtensionMessage::create
(reinterpret_cast<const unsigned char*>(in.c_str()), in.size());
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace() << std::endl;