2006-12-24 06:25:21 +00:00
|
|
|
#include "DefaultBtRequestFactory.h"
|
2008-11-03 06:49:02 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2006-12-24 06:25:21 +00:00
|
|
|
#include "MockBtMessage.h"
|
|
|
|
#include "MockBtMessageFactory.h"
|
|
|
|
#include "MockBtMessageDispatcher.h"
|
|
|
|
#include "MockPieceStorage.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "Peer.h"
|
|
|
|
#include "FileEntry.h"
|
2008-04-20 00:50:22 +00:00
|
|
|
#include "BtHandshakeMessage.h"
|
2009-06-28 10:37:15 +00:00
|
|
|
#include "DownloadContext.h"
|
|
|
|
#include "bittorrent_helper.h"
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2006-12-24 06:25:21 +00:00
|
|
|
|
|
|
|
class DefaultBtRequestFactoryTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(DefaultBtRequestFactoryTest);
|
|
|
|
CPPUNIT_TEST(testAddTargetPiece);
|
|
|
|
CPPUNIT_TEST(testRemoveCompletedPiece);
|
|
|
|
CPPUNIT_TEST(testCreateRequestMessages);
|
|
|
|
CPPUNIT_TEST(testCreateRequestMessages_onEndGame);
|
|
|
|
CPPUNIT_TEST(testRemoveTargetPiece);
|
2008-09-19 14:11:41 +00:00
|
|
|
CPPUNIT_TEST(testGetTargetPieceIndexes);
|
2006-12-24 06:25:21 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
2008-11-03 06:49:02 +00:00
|
|
|
SharedHandle<Peer> _peer;
|
|
|
|
SharedHandle<DefaultBtRequestFactory> _requestFactory;
|
2009-06-28 10:37:15 +00:00
|
|
|
SharedHandle<DownloadContext> _dctx;
|
2008-11-03 06:49:02 +00:00
|
|
|
SharedHandle<MockPieceStorage> _pieceStorage;
|
|
|
|
SharedHandle<MockBtMessageFactory> _messageFactory;
|
|
|
|
SharedHandle<MockBtMessageDispatcher> _dispatcher;
|
2006-12-24 06:25:21 +00:00
|
|
|
public:
|
|
|
|
void testAddTargetPiece();
|
|
|
|
void testRemoveCompletedPiece();
|
|
|
|
void testCreateRequestMessages();
|
|
|
|
void testCreateRequestMessages_onEndGame();
|
|
|
|
void testRemoveTargetPiece();
|
2008-09-19 14:11:41 +00:00
|
|
|
void testGetTargetPieceIndexes();
|
2006-12-24 06:25:21 +00:00
|
|
|
|
|
|
|
class MockBtRequestMessage : public MockBtMessage {
|
|
|
|
public:
|
2008-03-08 08:04:28 +00:00
|
|
|
size_t index;
|
|
|
|
size_t blockIndex;
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
MockBtRequestMessage(size_t index, size_t blockIndex):
|
|
|
|
index(index), blockIndex(blockIndex) {}
|
2006-12-24 06:25:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef SharedHandle<MockBtRequestMessage> MockBtRequestMessageHandle;
|
|
|
|
|
|
|
|
class MockBtMessageFactory2 : public MockBtMessageFactory {
|
|
|
|
public:
|
2008-02-08 15:53:45 +00:00
|
|
|
virtual SharedHandle<BtMessage>
|
2008-03-09 12:24:01 +00:00
|
|
|
createRequestMessage(const SharedHandle<Piece>& piece, size_t blockIndex) {
|
2008-04-20 00:50:22 +00:00
|
|
|
return SharedHandle<BtMessage>
|
2010-01-05 16:01:46 +00:00
|
|
|
(new MockBtRequestMessage(piece->getIndex(), blockIndex));
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class MockBtMessageDispatcher2 : public MockBtMessageDispatcher {
|
|
|
|
public:
|
2008-03-09 12:24:01 +00:00
|
|
|
virtual bool isOutstandingRequest(size_t index, size_t blockIndex) {
|
2006-12-24 06:25:21 +00:00
|
|
|
return index == 0 && blockIndex == 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
class SortMockBtRequestMessage {
|
|
|
|
public:
|
|
|
|
bool operator()(const SharedHandle<MockBtRequestMessage>& a,
|
2010-01-05 16:01:46 +00:00
|
|
|
const SharedHandle<MockBtRequestMessage>& b) {
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
if(a->index < b->index) {
|
2010-01-05 16:01:46 +00:00
|
|
|
return true;
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
} else if(b->index < a->index) {
|
2010-01-05 16:01:46 +00:00
|
|
|
return false;
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
} else if(a->blockIndex < b->blockIndex) {
|
2010-01-05 16:01:46 +00:00
|
|
|
return true;
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
} else if(b->blockIndex < a->blockIndex) {
|
2010-01-05 16:01:46 +00:00
|
|
|
return false;
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
} else {
|
2010-01-05 16:01:46 +00:00
|
|
|
return true;
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
void setUp()
|
|
|
|
{
|
|
|
|
_pieceStorage.reset(new MockPieceStorage());
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
_peer.reset(new Peer("host", 6969));
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
_messageFactory.reset(new MockBtMessageFactory2());
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
_dispatcher.reset(new MockBtMessageDispatcher());
|
2008-04-20 00:50:22 +00:00
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
_requestFactory.reset(new DefaultBtRequestFactory());
|
|
|
|
_requestFactory->setPieceStorage(_pieceStorage);
|
|
|
|
_requestFactory->setPeer(_peer);
|
|
|
|
_requestFactory->setBtMessageDispatcher(_dispatcher);
|
|
|
|
_requestFactory->setBtMessageFactory(_messageFactory);
|
2008-04-20 00:50:22 +00:00
|
|
|
}
|
2006-12-24 06:25:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(DefaultBtRequestFactoryTest);
|
|
|
|
|
|
|
|
void DefaultBtRequestFactoryTest::testAddTargetPiece() {
|
2008-06-17 11:43:29 +00:00
|
|
|
{
|
|
|
|
SharedHandle<Piece> piece(new Piece(0, 16*1024*10));
|
2008-11-03 06:49:02 +00:00
|
|
|
_requestFactory->addTargetPiece(piece);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, _requestFactory->countTargetPiece());
|
2008-06-17 11:43:29 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
SharedHandle<Piece> piece(new Piece(1, 16*1024*9));
|
|
|
|
piece->completeBlock(0);
|
2008-11-03 06:49:02 +00:00
|
|
|
_requestFactory->addTargetPiece(piece);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, _requestFactory->countTargetPiece());
|
2008-06-17 11:43:29 +00:00
|
|
|
}
|
2008-11-03 06:49:02 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)18, _requestFactory->countMissingBlock());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtRequestFactoryTest::testRemoveCompletedPiece() {
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<Piece> piece1(new Piece(0, 16*1024));
|
|
|
|
SharedHandle<Piece> piece2(new Piece(1, 16*1024));
|
2006-12-24 06:25:21 +00:00
|
|
|
piece2->setAllBlock();
|
2008-11-03 06:49:02 +00:00
|
|
|
_requestFactory->addTargetPiece(piece1);
|
|
|
|
_requestFactory->addTargetPiece(piece2);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, _requestFactory->countTargetPiece());
|
|
|
|
_requestFactory->removeCompletedPiece();
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, _requestFactory->countTargetPiece());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0,
|
2010-01-05 16:01:46 +00:00
|
|
|
_requestFactory->getTargetPieces().front()->getIndex());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtRequestFactoryTest::testCreateRequestMessages() {
|
|
|
|
int PIECE_LENGTH = 16*1024*2;
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<Piece> piece1(new Piece(0, PIECE_LENGTH));
|
|
|
|
SharedHandle<Piece> piece2(new Piece(1, PIECE_LENGTH));
|
2008-11-03 06:49:02 +00:00
|
|
|
_requestFactory->addTargetPiece(piece1);
|
|
|
|
_requestFactory->addTargetPiece(piece2);
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<BtMessage> > msgs;
|
2008-11-03 06:49:02 +00:00
|
|
|
_requestFactory->createRequestMessages(msgs, 3);
|
2006-12-24 06:25:21 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, msgs.size());
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<BtMessage> >::iterator itr = msgs.begin();
|
2009-11-15 13:25:44 +00:00
|
|
|
SharedHandle<MockBtRequestMessage> msg =
|
|
|
|
dynamic_pointer_cast<MockBtRequestMessage>(*itr);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, msg->index);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, msg->blockIndex);
|
2006-12-24 06:25:21 +00:00
|
|
|
++itr;
|
2009-11-15 13:25:44 +00:00
|
|
|
msg = dynamic_pointer_cast<MockBtRequestMessage>(*itr);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, msg->index);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, msg->blockIndex);
|
2006-12-24 06:25:21 +00:00
|
|
|
++itr;
|
2009-11-15 13:25:44 +00:00
|
|
|
msg = dynamic_pointer_cast<MockBtRequestMessage>(*itr);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, msg->index);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, msg->blockIndex);
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-05-12 10:54:36 +00:00
|
|
|
{
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<BtMessage> > msgs;
|
2008-11-03 06:49:02 +00:00
|
|
|
_requestFactory->createRequestMessages(msgs, 3);
|
2008-05-12 10:54:36 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, msgs.size());
|
|
|
|
}
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtRequestFactoryTest::testCreateRequestMessages_onEndGame() {
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<MockBtMessageDispatcher2> dispatcher
|
|
|
|
(new MockBtMessageDispatcher2());
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
_requestFactory->setBtMessageDispatcher(dispatcher);
|
2006-12-24 06:25:21 +00:00
|
|
|
|
|
|
|
int PIECE_LENGTH = 16*1024*2;
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<Piece> piece1(new Piece(0, PIECE_LENGTH));
|
|
|
|
SharedHandle<Piece> piece2(new Piece(1, PIECE_LENGTH));
|
2008-11-03 06:49:02 +00:00
|
|
|
_requestFactory->addTargetPiece(piece1);
|
|
|
|
_requestFactory->addTargetPiece(piece2);
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<BtMessage> > msgs;
|
2008-11-03 06:49:02 +00:00
|
|
|
_requestFactory->createRequestMessagesOnEndGame(msgs, 3);
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<MockBtRequestMessage> > mmsgs;
|
|
|
|
for(std::vector<SharedHandle<BtMessage> >::iterator i = msgs.begin();
|
2008-04-20 00:50:22 +00:00
|
|
|
i != msgs.end(); ++i) {
|
|
|
|
mmsgs.push_back(dynamic_pointer_cast<MockBtRequestMessage>(*i));
|
|
|
|
}
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
|
2008-04-20 00:50:22 +00:00
|
|
|
std::sort(mmsgs.begin(), mmsgs.end(), SortMockBtRequestMessage());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, mmsgs.size());
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<MockBtRequestMessage> >::iterator itr =mmsgs.begin();
|
2008-04-20 00:50:22 +00:00
|
|
|
MockBtRequestMessage* msg = (*itr).get();
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, msg->index);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, msg->blockIndex);
|
2006-12-24 06:25:21 +00:00
|
|
|
++itr;
|
2008-04-20 00:50:22 +00:00
|
|
|
msg = (*itr).get();
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, msg->index);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, msg->blockIndex);
|
2006-12-24 06:25:21 +00:00
|
|
|
++itr;
|
2008-04-20 00:50:22 +00:00
|
|
|
msg = (*itr).get();
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, msg->index);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, msg->blockIndex);
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtRequestFactoryTest::testRemoveTargetPiece() {
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<Piece> piece1(new Piece(0, 16*1024));
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
_requestFactory->addTargetPiece(piece1);
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
CPPUNIT_ASSERT(std::find(_requestFactory->getTargetPieces().begin(),
|
2010-01-05 16:01:46 +00:00
|
|
|
_requestFactory->getTargetPieces().end(),
|
|
|
|
piece1) !=
|
|
|
|
_requestFactory->getTargetPieces().end());
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
_requestFactory->removeTargetPiece(piece1);
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
CPPUNIT_ASSERT(std::find(_requestFactory->getTargetPieces().begin(),
|
2010-01-05 16:01:46 +00:00
|
|
|
_requestFactory->getTargetPieces().end(),
|
|
|
|
piece1) ==
|
|
|
|
_requestFactory->getTargetPieces().end());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-09-19 14:11:41 +00:00
|
|
|
void DefaultBtRequestFactoryTest::testGetTargetPieceIndexes()
|
|
|
|
{
|
2009-06-28 10:37:15 +00:00
|
|
|
SharedHandle<Piece> piece1(new Piece(1, 16*1024));
|
|
|
|
SharedHandle<Piece> piece3(new Piece(3, 16*1024));
|
|
|
|
SharedHandle<Piece> piece5(new Piece(5, 16*1024));
|
2008-09-19 14:11:41 +00:00
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
_requestFactory->addTargetPiece(piece3);
|
|
|
|
_requestFactory->addTargetPiece(piece1);
|
|
|
|
_requestFactory->addTargetPiece(piece5);
|
2008-09-19 14:11:41 +00:00
|
|
|
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<size_t> indexes;
|
2008-11-03 06:49:02 +00:00
|
|
|
_requestFactory->getTargetPieceIndexes(indexes);
|
2008-09-19 14:11:41 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, indexes.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, indexes[0]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, indexes[1]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)5, indexes[2]);
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|