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,17 @@
#include "DefaultExtensionMessageFactory.h"
#include <iostream>
#include <cppunit/extensions/HelperMacros.h>
#include "Peer.h"
#include "MockBtContext.h"
#include "MockPeerStorage.h"
#include "PeerMessageUtil.h"
#include "HandshakeExtensionMessage.h"
#include "UTPexExtensionMessage.h"
#include "Exception.h"
#include "BtRegistry.h"
#include "BtRuntime.h"
#include "FileEntry.h"
#include <iostream>
#include <cppunit/extensions/HelperMacros.h>
namespace aria2 {
@ -22,29 +24,27 @@ class DefaultExtensionMessageFactoryTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE_END();
private:
SharedHandle<MockBtContext> _btContext;
SharedHandle<MockPeerStorage> _peerStorage;
SharedHandle<Peer> _peer;
SharedHandle<DefaultExtensionMessageFactory> _factory;
public:
void setUp()
{
BtRegistry::unregisterAll();
SharedHandle<MockBtContext> btContext(new MockBtContext());
_btContext.reset(new MockBtContext());
unsigned char infohash[20];
memset(infohash, 0, sizeof(infohash));
btContext->setInfoHash(infohash);
_btContext = btContext;
_btContext->setInfoHash(infohash);
SharedHandle<BtRuntime> btRuntime(new BtRuntime());
BtRegistry::registerBtRuntime(_btContext->getInfoHashAsString(),
btRuntime);
_peerStorage.reset(new MockPeerStorage());
_peer.reset(new Peer("192.168.0.1", 6969));
_peer->allocateSessionResource(1024, 1024*1024);
_peer->setExtension("ut_pex", 1);
}
void tearDown()
{
BtRegistry::unregisterAll();
_factory.reset(new DefaultExtensionMessageFactory());
_factory->setBtContext(_btContext);
_factory->setPeerStorage(_peerStorage);
_factory->setPeer(_peer);
}
void testCreateMessage_unknown();
@ -57,9 +57,6 @@ CPPUNIT_TEST_SUITE_REGISTRATION(DefaultExtensionMessageFactoryTest);
void DefaultExtensionMessageFactoryTest::testCreateMessage_unknown()
{
DefaultExtensionMessageFactory factory;
factory.setBtContext(_btContext);
factory.setPeer(_peer);
_peer->setExtension("foo", 255);
char id[1] = { 255 };
@ -67,8 +64,8 @@ void DefaultExtensionMessageFactoryTest::testCreateMessage_unknown()
std::string data = std::string(&id[0], &id[1]);
try {
// this test fails because localhost doesn't have extension id = 255.
factory.createMessage(reinterpret_cast<const unsigned char*>(data.c_str()),
data.size());
_factory->createMessage
(reinterpret_cast<const unsigned char*>(data.c_str()), data.size());
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace() << std::endl;
@ -77,26 +74,18 @@ void DefaultExtensionMessageFactoryTest::testCreateMessage_unknown()
void DefaultExtensionMessageFactoryTest::testCreateMessage_Handshake()
{
DefaultExtensionMessageFactory factory;
factory.setBtContext(_btContext);
factory.setPeer(_peer);
char id[1] = { 0 };
std::string data = std::string(&id[0], &id[1])+"d1:v5:aria2e";
SharedHandle<HandshakeExtensionMessage> m
(dynamic_pointer_cast<HandshakeExtensionMessage>
(factory.createMessage(reinterpret_cast<const unsigned char*>(data.c_str()),
data.size())));
(_factory->createMessage
(reinterpret_cast<const unsigned char*>(data.c_str()), data.size())));
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), m->getClientVersion());
}
void DefaultExtensionMessageFactoryTest::testCreateMessage_UTPex()
{
DefaultExtensionMessageFactory factory;
factory.setBtContext(_btContext);
factory.setPeer(_peer);
unsigned char c1[6];
unsigned char c2[6];
unsigned char c3[6];
@ -106,7 +95,7 @@ void DefaultExtensionMessageFactoryTest::testCreateMessage_UTPex()
PeerMessageUtil::createcompact(c3, "192.168.0.2", 6882);
PeerMessageUtil::createcompact(c4, "10.1.1.3",10000);
char id[1] = { factory.getExtensionMessageID("ut_pex") };
char id[1] = { _factory->getExtensionMessageID("ut_pex") };
std::string data = std::string(&id[0], &id[1])+"d5:added12:"+
std::string(&c1[0], &c1[6])+std::string(&c2[0], &c2[6])+
@ -116,9 +105,9 @@ void DefaultExtensionMessageFactoryTest::testCreateMessage_UTPex()
SharedHandle<UTPexExtensionMessage> m
(dynamic_pointer_cast<UTPexExtensionMessage>
(factory.createMessage(reinterpret_cast<const unsigned char*>(data.c_str()),
data.size())));
CPPUNIT_ASSERT_EQUAL(factory.getExtensionMessageID("ut_pex"),
(_factory->createMessage
(reinterpret_cast<const unsigned char*>(data.c_str()), data.size())));
CPPUNIT_ASSERT_EQUAL(_factory->getExtensionMessageID("ut_pex"),
m->getExtensionMessageID());
}