aria2/test/UtilTest.cc

1296 lines
42 KiB
C++
Raw Normal View History

#include "util.h"
#include <cstring>
#include <string>
#include <iostream>
#include <cppunit/extensions/HelperMacros.h>
#include "FixedNumberRandomizer.h"
2007-11-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Don't connect server before checking file integrity at startup, if filesize and output file path are known. * src/AbstractCommand.cc * src/StreamFileAllocationEntry.cc * src/Metalink2RequestGroup.cc * src/RequestGroup.{h, cc} * src/HttpResponseCommand.cc * src/FtpNegotiationCommand.cc Added DownloadFailureException. If it is thrown, RequestGroup should halt. * src/AbstractCommand.cc * src/DownloadFailureException.h * src/RequestGroup.cc Catch RecoverableException, instead of DlAbortEx. * src/RequestGroupMan.cc * src/FillRequestGroupCommand.cc * src/MetaFileUtil.cc * src/IteratableChunkChecksumValidator.cc Now first parameter of MSG_DOWNLOAD_ABORTED is gid(RequestGroup:: getGID()) * src/CheckIntegrityCommand.cc * src/message.h Print gid instead of idx. * src/RequestGroupMan.cc Removed exception throwers declaration. * src/DirectDiskAdaptor.{h, cc} * src/SocketCore.{h, cc} * src/MultiDiskAdaptor.{h, cc} * src/HttpConnection.{h, cc} * src/HttpResponse.{h, cc} * src/DiskAdaptor.{h, cc} * src/CopyDiskAdaptor.{h, cc} * src/MultiDiskAdaptor.{h, cc} * src/HttpHeaderProcessor.{h, cc} * src/AbstractSingleDiskAdaptor.{h, cc} * src/Util.{h, cc} * test/UtilTest.cc * src/DefaultDiskWriter.{h, cc} * src/FtpConnection.{h, cc} * src/AbstractDiskWriter.{h, cc} Removed duplicate code. * src/StreamCheckIntegrityEntry.cc Removed unnecessary include. * src/DiskWriter.h Included Exception.h * src/option_processing.cc Included 2 files and added doc * src/TrackerWatcherCommand.cc * src/SocketCore.cc (writeData): Fixed send error with GnuTLS.
2007-11-09 18:01:12 +00:00
#include "DlAbortEx.h"
#include "BitfieldMan.h"
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Rewritten to add content-type support. * src/DownloadHandler.{h, cc} * src/BtPostDownloadHandler.{h, cc} * test/BtPostDownloadHandlerTest.cc * src/MetalinkPostDownloadHandler.{h, cc} * test/MetalinkPostDownloadHandlerTest.cc * src/PostDownloadHandler.{h, cc} * src/DownloadHandlerConstants.{h, cc} * src/RequestGroup.cc * src/HttpResponseCommand.cc * src/FtpNegotiationCommand.cc * src/SingleFileDownloadContext.{h, cc} * src/RequestGroup.h * src/RequestGroupCriteria.h * src/ContentTypeRequestGroupCriteria.h Added 'mem' option value for --follow-metalink, --follow-torrent. If it is give, metalink/torrent file is not written to the disk, but just is kept in memory. Parsing is occurred on memory. * src/MetalinkHelper.{h, cc} * src/MetalinkProcessor.h * src/Xml2MetalinkProcessor.{h, cc} * test/Xml2MetalinkProcessorTest.cc * src/DownloadHandlerFactory.{h, cc} * test/DownloadHandlerFactoryTest.cc * src/PreDownloadHandler.{h, cc} * src/OptionHandlerFactory.cc * src/DefaultBtContext.{h, cc} * test/DefaultBtContextTest.cc * src/version_usage.cc * src/Metalink2RequestGroup.{h, cc} * src/RequestGroup.{h, cc} * src/a2functional.h * test/a2functionalTest.cc * src/MemoryBufferPreDownloadHandler.{h, cc} * src/OptionHandlerImpl.h * src/prefs.h * src/Util.{h, cc} * test/UtilTest.cc Keep DownloadResult rather than RequestGroup after downloads to reduce memory usage. * src/RequestGroupMan.{h, cc} * src/DownloadEngine.cc * src/BtDependency.{h, cc}: Changed the type of dependee from WeakHandle to SharedHandle because WeakHandle could be null. * src/RequestGroup.{h, cc} * src/DownloadEngineFactory.cc * src/DownloadResult.h Set totalLength after download finished * src/UnknownLengthPieceStorage.{h, cc} Keep torrent file specified in metalink in memory. * src/Metalink2RequestGroup.cc * src/BtDependency.cc * src/TrueRequestGroupCriteria.h Fixed the bug: seekg is used where seekp should be used. * src/ByteArrayDiskWriter.cc * test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
#include "ByteArrayDiskWriter.h"
#include "FileEntry.h"
#include "File.h"
#include "array_fun.h"
#include "BufferedFile.h"
#include "TestUtil.h"
2006-02-17 13:35:04 +00:00
namespace aria2 {
2006-02-17 13:35:04 +00:00
class UtilTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(UtilTest);
CPPUNIT_TEST(testStrip);
CPPUNIT_TEST(testDivide);
2006-02-17 13:35:04 +00:00
CPPUNIT_TEST(testSplit);
2006-02-21 12:27:17 +00:00
CPPUNIT_TEST(testEndsWith);
2006-02-21 15:01:05 +00:00
CPPUNIT_TEST(testReplace);
CPPUNIT_TEST(testStartsWith);
2006-05-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Each peer message has its own class. * src/PendingMessages.h: Removed. * src/PendingMessages.cc: Removed. The sending process was moved to each message class. * src/RequestSlotMan.h: Removed. * src/RequestSlotMan.cc: Removed. All functionarities were moved to SendMessageQueue. * src/RequestMessage.h: New class. * src/RequestMessage.cc: New class. * src/CancelMessage.h: New class. * src/CancelMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/ChokeMessage.h: New class. * src/ChokeMessage.cc: New class. * src/KeepAliveMessage.h: New class. * src/KeepAliveMessage.cc: New class. * src/PortMessage.h: New class. * src/UnchokeMessage.h: New class. * src/UnchokeMessage.cc: New class. * src/PieceMessage.h: New class. * src/PieceMessage.cc: New class. * src/HaveMessage.h: New class. * src/HaveMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/NotInterestedMessage.h: New class. * src/NotInterestedMessage.cc: New class. * src/InterestedMessage.h: New class. * src/InterestedMessage.cc: New class. * src/HandshakeMessage.h (sendMessageQueue): New variable. (getSendMessageQueue): New function. (setSendMessageQueue): New function. * src/HandshakeMessage.cc: New class. * src/PeerConnection.h (receiveMessage): Changed return value and arguments. (receiveHandshake): Changed return value and arguments. * src/PeerConnection.cc (receiveMessage): Do not create message class here. (receiveHandshake): Do not create handshake class here. * src/PeerInteractionCommand.h (peerConnection): Removed. (piece): Removed. (syncPiece): Removed. (sendInterest): Removed. (sendMessages): Removed. (createRequestPendingMessage): Removed. (checkPieceHash): Removed. (erasePieceOnDisk): Removed. (getNewPieceAndSendInterest): Removed. (onGotNewPice): Removed. (onGotWrongPiece): Removed. * src/PeerInteractionCommand.cc (PeerInteractionCommand): Removed peerConnection, piece. (~PeerInteractionCommand): Removed peerConnection. (executeInternal): Use sendMessageQueue instead of peerConnection. (syncPiece): Moved to SendMessageQueue. (decideChoking): Removed PendingMessage. (receiveMessage): Use sendMessageQueue instead of peerConnection. The action after receiving peer message was moved to each message class. (onGotNewPice): Moved to SendMessageQueue. (onGotWrongPiece): Moved to SendMessageQueue. (getNewPieceAndSendInterest): Moved to SendMessageQueue. (sendInterest): Moved to SendMessageQueue. (createRequestPendingMessage): Removed. (sendMessages): Moved to SendMessageQueue. (onAbort): Use SendMessageQueue::abortPiece() (keepAlive): Use sendMessageQueue instead of peerConnection. (beforeSocketCheck): Use sendMessageQueue instead of peerConnection. (checkPieceHash): Moved to SendMessageQueue. (erasePieceOnDisk): Moved to SendMessageQueue. * src/PeerMessageUtil.h (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessageUtil.cc (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessage.h (id): Removed. (index): Removed. (begin): Removed. (length): Removed. (bitfield): Removed. (bitfieldLength): Removed. (block): Removed. (blockLength): Removed. (inProgress): New variable. (cuid): New variable. (peer): New variable. (sendMessageQueue): New variable. (logger): New variable. (setBitfield): Removed. (getBitfield): Removed. (setBlock): Removed. (getBlock): Removed. (getBitfieldLength): Removed. (getBlockLength): Removed. (isInProgress): New function. (toString): Made pure virtual. (check): New function. (send): New function. (receivedAction): New function. (getId): Made pure virtual. (setId): Removed. (getIndex): Removed. (setIndex): Removed. (getBegin): Removed. (setBegin): Removed. (getLength): Removed. (setLength): Removed. (getCuid): New function. (setCuid): New function. (getPeer): New function. (setPeer): New function. (getSendMessageQueue): New function. (setSendMessageQueue): New function. (ID): Removed. * src/PeerMessage.cc (setBitfield): Removed. (setBlock): Removed. (toString): Removed. * src/TorrentMan.h (getPieceLength): New function. (getPieceLength): New function. * src/SendMessageQueue.h (REQUEST_TIME_OUT): New definition. (RequestSlots): New definition. (MessageQueue): New definition. (requestSlotMan): Removed. (pendingMessages): Removed. (requestSlots): New variable. (messageQueue): New variable. (torrentMan): New variable. (peerConnection): New variable. (peer): New variable. (piece): New variable. (getNewPieceAndSendInterest): New function. (createPeerMessage): New function. (createHandshakeMessage): New function. (send): Made private. (setPeerMessageCommonProperty): New function. (deleteAllRequestSlot): New function. (deleteRequestMessageInQueue): New function. (cancelAllRequest): Made private. (cancelAllRequest): Made private. (countRequestSlot): Made private. (addPendingMessage): Removed. (deletePendingPieceMessage): Removed. (deletePendingRequestMessage): Removed. (addMessage): New function. (deletePieceMessageInQueue): New function. (deleteTimeoutRequestSlot): Changed argument. (deleteCompletedRequestSlot): Changed argument. (getCorrespoindingRequestSlot): Renamed to getCorrespondingRequestSlot. (getCorrespondingRequestSlot): New function. (countPendingMessage): Removed. (countMessageInQueue): New function. (getTorrentMan): New function. (getPeerConnection): New function. (hasDownloadPiece): New function. (getDownloadPiece): New function. (setDownloadPiece): New function. (syncPiece): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (abortPiece): New function. (sendHandshake): New function. (receiveMessage): New function. (receiveHandshake): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. * src/SendMessageQueue.cc (SendMessageQueue): Removed requestSlotMan. Instantiated peerConnection here. (~SendMessageQueue): Removed requestSlotMan. Added deletion of peerConnection and the contents of messageQueue. (send): Updated according to the change of messageQueue. (addPendingMessage): Renamed to addMessage. (addMessage): New function. (deletePendingPieceMessage): Renamed to deletePieceMessageInQueue. (deletePieceMessageInQueue): New function. (deletePendingRequestMessage): Renamed to deleteRequestMessageInQueue. (deleteRequestMessageInQueue): New function. (deleteRequestSlot): RequestSlotMan::deleteRequestSlot(...) was moved here. (deleteTimeoutRequestSlot): RequestSlotMan::deleteTimeoutRequestSlot (...) was moved here. (deleteAllRequestSlot): RequestSlotMan::deleteAllRequestSlot(...) was moved here. (deleteCompletedRequestSlot): RequestSlotMan::deleteCompletedRequestSlot(...) was moved here. (getCorrespondingRequestSlot): RequestSlotMan::getCorrespoindingRequestSlot(...) was moved here. And renamed to getCorrespondingRequestSlot, correcting a typo. (countPendingMessage): Renamed to countMessageInQueue. (countMessageInQueue): New function. (countRequestSlot): RequestSlotMan::countRequestSlot() was moved here. (receiveHandshake): New function. (createHandshakeMessage): New function. (receiveMessage): New function. (createPeerMessage): New function. (syncPiece): New function. (getNewPieceAndSendInterest): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (sendHandshake): New function. (abortPiece): New function. (getDownloadPiece): New function. (getPeerMessageCommonProperty): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. To add simple Content-Disposition support: * src/HttpResponseCommand.h (determinFilename): New function. * src/HttpResponseCommand.cc (executeInternal): Use determinFilename(headers) instead of req->getFile() when comparing filename. (determinFilename): New function. (handleDefaultEncoding): Use determinFilename(headers) instead of req->getFile(). (handleOtherEncoding): Use determinFilename(headers) instead of req->getFile(). * src/Util.h (getContentDispositionFilename): New function. * src/Util.cc (getContentDispositionFilename): New function. * src/LogFactory.h (release): New function. * src/LogFactory.cc (release): New function. To fix a bug that causes out-of-bound exception when HTTP status line is wrong: * src/HttpConnection.cc (receiveResponse): Added a check for header size. * src/common.h (Deleter): New class. * src/SegmentMan.cc (~SegmentMan): Added deletion of splitter and diskWriter. * src/DownloadEngine.h (Commands): Use deque. (clearQueue): New function. * src/DownloadEngine.cc (~DownloadEngine): Added deletion of segmentMan. (cleanQueue): New function. * src/TorrentDownloadEngine.h (TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. (~TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. * src/TorrentDownloadEngine.cc (~TorrentDownloadEngine): Added deletion of torrentMan. * src/main.cc (clearRequest): Removed. (handler): Added deletion of e. (torrentHandler): Added deletion of te. (main): Do not share splitter. Use Deleter instead of clearRequest. Deletion of classes were updated.
2006-05-09 15:54:14 +00:00
// may be moved to other helper class in the future.
CPPUNIT_TEST(testGetContentDispositionFilename);
2006-06-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To make a listening socket non-block: * src/SocketCore.h (setNonBlockingMode): New function. * src/SocketCore.cc (setNonBlockingMode): New function. (beginListen): Added a call to setNonBlockingMode(). (acceptConnection): Call setNonBlockingMode(). (setBlockingMode): Updated. To handle tracker's NAT-checking: * src/PeerConnection.cc (receiveHandshake): 'msg' param is filled with received data and its length is assigned to 'length' param, even if all handshake message is not yet received. * src/PeerInteractionCommand.cc (executeInternal): Use peerInteraction->receiveHandshake(true) when a new peer connects to localhost. A call to peerInteraction->sendHandshake() was removed because it is called from peerInteraction->receiveHandshake(true). * src/PeerInteraction.h (quickReplied): New variable. (receiveHandshake): Added an argument. * src/PeerInteraction.cc (PeerInteraction): Added the initialization of quickReplied. (receiveHandshake): Send handshake message as soon as the info hash in a handshake message from a peer is correct. To change the random part of peer id and key parameter: * src/TorrentMan.h (key): New variable. * src/TorrentMan.cc (setupInternal1): Use Util::randomAlpha() to generate random part of peer id, which is now "-aria2-"+13 alphabet characters([A-Za-z]). key is also generated by Util::randomAlpha() and it is now 8 character long. * src/Util.h (randomAlpha): New function. * src/Util.cc (randomAlpha): New function. * src/TrackerWatcherCommand.cc (execute): In a tracker request: Use torrentMan->key as key parameter. Added no_peer_id=1. Set snubbing flag to false when a choke message is received from a snubbed peer. * src/ChokeMessage.cc (receivedAction): Set snubbing flag to false.
2006-06-22 15:26:18 +00:00
CPPUNIT_TEST(testRandomAlpha);
2006-07-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To add Metalink support(http/ftp only): * src/AbstractCommand.h (tryReserved): New function. * src/AbstractCommand.cc (execute): Call tryReserved(). (tryReserved): New function. * src/Request.h (Requests): New type definition. * src/SegmentMan.h (reserved): New variable. * src/Util.h (fileChecksum): New function. (toUpper): New function. (toLower): New function. * src/Util.cc (messageDigest.h): Included. (trim): Trim \r\n\t. (fileChecksum): New function. (toUpper): New function. (toLower): New function. * src/main.cc (normalDownload): New function. (main): Added 2 command-line options: metalink-file, metalink-connection. Their usage has not been written yet. * src/MetalinkProcessor.h: New class. * src/Xml2MetalinkProcessor.h: New class. * src/Xml2MetalinkProcessor.cc: New class. * src/MetalinkEntry.h: New class. * src/MetalinkEntry.cc: New class. * src/MetalinkResource.h: New class. * src/MetalinkResource.cc: New class. To add md5 message digest checking: * src/messageDigest.h: Rewritten. * src/MultiDiskWriter.cc: Updated according to the changes in messageDigest.h. * src/ShaVisitor.cc: Updated according to the changes in messageDigest.h. * src/Util.cc: Updated according to the changes in messageDigest.h. * src/AbstractDiskWriter.cc: Updated according to the changes in messageDigest.h. To fix a bug that causes segfault when the payload length in peer message is less than 0: * src/PeerConnection.cc: (receiveMessage): Fixed the bug. * src/PeerMessageUtil.cc (checkLength): Throw an exception if length is less than or equals to 0. To add new interfaces to Base64 encoding/decoding: * src/Base64.h (part_encode): Changed the method signature. (encode): New function(overload). (decode): New function(overload). * src/Base64.cc (part_encode): Rewritten. (encode): Rewritten. (encode): New function(overload). To prevent a peer to download same piece if there is an error in checksum: * src/PieceMessage.cc (receivedAction): Call peerInteraction->abortPiece().
2006-07-03 14:19:23 +00:00
CPPUNIT_TEST(testToUpper);
CPPUNIT_TEST(testToLower);
CPPUNIT_TEST(testUppercase);
CPPUNIT_TEST(testLowercase);
CPPUNIT_TEST(testPercentDecode);
CPPUNIT_TEST(testGetRealSize);
CPPUNIT_TEST(testAbbrevSize);
CPPUNIT_TEST(testToStream);
CPPUNIT_TEST(testIsNumber);
CPPUNIT_TEST(testIsLowercase);
CPPUNIT_TEST(testIsUppercase);
CPPUNIT_TEST(testAlphaToNum);
CPPUNIT_TEST(testMkdirs);
CPPUNIT_TEST(testConvertBitfield);
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
CPPUNIT_TEST(testParseIntRange);
CPPUNIT_TEST(testParseIntRange_invalidRange);
CPPUNIT_TEST(testParseInt);
CPPUNIT_TEST(testParseUInt);
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
CPPUNIT_TEST(testParseLLInt);
CPPUNIT_TEST(testParseULLInt);
CPPUNIT_TEST(testParseIntNoThrow);
CPPUNIT_TEST(testParseUIntNoThrow);
CPPUNIT_TEST(testParseLLIntNoThrow);
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Rewritten to add content-type support. * src/DownloadHandler.{h, cc} * src/BtPostDownloadHandler.{h, cc} * test/BtPostDownloadHandlerTest.cc * src/MetalinkPostDownloadHandler.{h, cc} * test/MetalinkPostDownloadHandlerTest.cc * src/PostDownloadHandler.{h, cc} * src/DownloadHandlerConstants.{h, cc} * src/RequestGroup.cc * src/HttpResponseCommand.cc * src/FtpNegotiationCommand.cc * src/SingleFileDownloadContext.{h, cc} * src/RequestGroup.h * src/RequestGroupCriteria.h * src/ContentTypeRequestGroupCriteria.h Added 'mem' option value for --follow-metalink, --follow-torrent. If it is give, metalink/torrent file is not written to the disk, but just is kept in memory. Parsing is occurred on memory. * src/MetalinkHelper.{h, cc} * src/MetalinkProcessor.h * src/Xml2MetalinkProcessor.{h, cc} * test/Xml2MetalinkProcessorTest.cc * src/DownloadHandlerFactory.{h, cc} * test/DownloadHandlerFactoryTest.cc * src/PreDownloadHandler.{h, cc} * src/OptionHandlerFactory.cc * src/DefaultBtContext.{h, cc} * test/DefaultBtContextTest.cc * src/version_usage.cc * src/Metalink2RequestGroup.{h, cc} * src/RequestGroup.{h, cc} * src/a2functional.h * test/a2functionalTest.cc * src/MemoryBufferPreDownloadHandler.{h, cc} * src/OptionHandlerImpl.h * src/prefs.h * src/Util.{h, cc} * test/UtilTest.cc Keep DownloadResult rather than RequestGroup after downloads to reduce memory usage. * src/RequestGroupMan.{h, cc} * src/DownloadEngine.cc * src/BtDependency.{h, cc}: Changed the type of dependee from WeakHandle to SharedHandle because WeakHandle could be null. * src/RequestGroup.{h, cc} * src/DownloadEngineFactory.cc * src/DownloadResult.h Set totalLength after download finished * src/UnknownLengthPieceStorage.{h, cc} Keep torrent file specified in metalink in memory. * src/Metalink2RequestGroup.cc * src/BtDependency.cc * src/TrueRequestGroupCriteria.h Fixed the bug: seekg is used where seekp should be used. * src/ByteArrayDiskWriter.cc * test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
CPPUNIT_TEST(testToString_binaryStream);
CPPUNIT_TEST(testItos);
CPPUNIT_TEST(testUitos);
CPPUNIT_TEST(testNtoh64);
CPPUNIT_TEST(testPercentEncode);
CPPUNIT_TEST(testHtmlEscape);
CPPUNIT_TEST(testJoinPath);
CPPUNIT_TEST(testParseIndexPath);
CPPUNIT_TEST(testCreateIndexPathMap);
CPPUNIT_TEST(testGenerateRandomData);
CPPUNIT_TEST(testFromHex);
CPPUNIT_TEST(testParsePrioritizePieceRange);
CPPUNIT_TEST(testApplyDir);
CPPUNIT_TEST(testFixTaintedBasename);
CPPUNIT_TEST(testIsNumericHost);
CPPUNIT_TEST(testDetectDirTraversal);
CPPUNIT_TEST(testEscapePath);
CPPUNIT_TEST(testGetCidrPrefix);
CPPUNIT_TEST(testInSameCidrBlock);
CPPUNIT_TEST(testIsUtf8String);
CPPUNIT_TEST(testNextParam);
2006-02-17 13:35:04 +00:00
CPPUNIT_TEST_SUITE_END();
private:
public:
void setUp() {
}
void testStrip();
void testDivide();
2006-02-17 13:35:04 +00:00
void testSplit();
2006-02-21 12:27:17 +00:00
void testEndsWith();
2006-02-21 15:01:05 +00:00
void testReplace();
void testStartsWith();
2006-05-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Each peer message has its own class. * src/PendingMessages.h: Removed. * src/PendingMessages.cc: Removed. The sending process was moved to each message class. * src/RequestSlotMan.h: Removed. * src/RequestSlotMan.cc: Removed. All functionarities were moved to SendMessageQueue. * src/RequestMessage.h: New class. * src/RequestMessage.cc: New class. * src/CancelMessage.h: New class. * src/CancelMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/ChokeMessage.h: New class. * src/ChokeMessage.cc: New class. * src/KeepAliveMessage.h: New class. * src/KeepAliveMessage.cc: New class. * src/PortMessage.h: New class. * src/UnchokeMessage.h: New class. * src/UnchokeMessage.cc: New class. * src/PieceMessage.h: New class. * src/PieceMessage.cc: New class. * src/HaveMessage.h: New class. * src/HaveMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/NotInterestedMessage.h: New class. * src/NotInterestedMessage.cc: New class. * src/InterestedMessage.h: New class. * src/InterestedMessage.cc: New class. * src/HandshakeMessage.h (sendMessageQueue): New variable. (getSendMessageQueue): New function. (setSendMessageQueue): New function. * src/HandshakeMessage.cc: New class. * src/PeerConnection.h (receiveMessage): Changed return value and arguments. (receiveHandshake): Changed return value and arguments. * src/PeerConnection.cc (receiveMessage): Do not create message class here. (receiveHandshake): Do not create handshake class here. * src/PeerInteractionCommand.h (peerConnection): Removed. (piece): Removed. (syncPiece): Removed. (sendInterest): Removed. (sendMessages): Removed. (createRequestPendingMessage): Removed. (checkPieceHash): Removed. (erasePieceOnDisk): Removed. (getNewPieceAndSendInterest): Removed. (onGotNewPice): Removed. (onGotWrongPiece): Removed. * src/PeerInteractionCommand.cc (PeerInteractionCommand): Removed peerConnection, piece. (~PeerInteractionCommand): Removed peerConnection. (executeInternal): Use sendMessageQueue instead of peerConnection. (syncPiece): Moved to SendMessageQueue. (decideChoking): Removed PendingMessage. (receiveMessage): Use sendMessageQueue instead of peerConnection. The action after receiving peer message was moved to each message class. (onGotNewPice): Moved to SendMessageQueue. (onGotWrongPiece): Moved to SendMessageQueue. (getNewPieceAndSendInterest): Moved to SendMessageQueue. (sendInterest): Moved to SendMessageQueue. (createRequestPendingMessage): Removed. (sendMessages): Moved to SendMessageQueue. (onAbort): Use SendMessageQueue::abortPiece() (keepAlive): Use sendMessageQueue instead of peerConnection. (beforeSocketCheck): Use sendMessageQueue instead of peerConnection. (checkPieceHash): Moved to SendMessageQueue. (erasePieceOnDisk): Moved to SendMessageQueue. * src/PeerMessageUtil.h (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessageUtil.cc (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessage.h (id): Removed. (index): Removed. (begin): Removed. (length): Removed. (bitfield): Removed. (bitfieldLength): Removed. (block): Removed. (blockLength): Removed. (inProgress): New variable. (cuid): New variable. (peer): New variable. (sendMessageQueue): New variable. (logger): New variable. (setBitfield): Removed. (getBitfield): Removed. (setBlock): Removed. (getBlock): Removed. (getBitfieldLength): Removed. (getBlockLength): Removed. (isInProgress): New function. (toString): Made pure virtual. (check): New function. (send): New function. (receivedAction): New function. (getId): Made pure virtual. (setId): Removed. (getIndex): Removed. (setIndex): Removed. (getBegin): Removed. (setBegin): Removed. (getLength): Removed. (setLength): Removed. (getCuid): New function. (setCuid): New function. (getPeer): New function. (setPeer): New function. (getSendMessageQueue): New function. (setSendMessageQueue): New function. (ID): Removed. * src/PeerMessage.cc (setBitfield): Removed. (setBlock): Removed. (toString): Removed. * src/TorrentMan.h (getPieceLength): New function. (getPieceLength): New function. * src/SendMessageQueue.h (REQUEST_TIME_OUT): New definition. (RequestSlots): New definition. (MessageQueue): New definition. (requestSlotMan): Removed. (pendingMessages): Removed. (requestSlots): New variable. (messageQueue): New variable. (torrentMan): New variable. (peerConnection): New variable. (peer): New variable. (piece): New variable. (getNewPieceAndSendInterest): New function. (createPeerMessage): New function. (createHandshakeMessage): New function. (send): Made private. (setPeerMessageCommonProperty): New function. (deleteAllRequestSlot): New function. (deleteRequestMessageInQueue): New function. (cancelAllRequest): Made private. (cancelAllRequest): Made private. (countRequestSlot): Made private. (addPendingMessage): Removed. (deletePendingPieceMessage): Removed. (deletePendingRequestMessage): Removed. (addMessage): New function. (deletePieceMessageInQueue): New function. (deleteTimeoutRequestSlot): Changed argument. (deleteCompletedRequestSlot): Changed argument. (getCorrespoindingRequestSlot): Renamed to getCorrespondingRequestSlot. (getCorrespondingRequestSlot): New function. (countPendingMessage): Removed. (countMessageInQueue): New function. (getTorrentMan): New function. (getPeerConnection): New function. (hasDownloadPiece): New function. (getDownloadPiece): New function. (setDownloadPiece): New function. (syncPiece): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (abortPiece): New function. (sendHandshake): New function. (receiveMessage): New function. (receiveHandshake): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. * src/SendMessageQueue.cc (SendMessageQueue): Removed requestSlotMan. Instantiated peerConnection here. (~SendMessageQueue): Removed requestSlotMan. Added deletion of peerConnection and the contents of messageQueue. (send): Updated according to the change of messageQueue. (addPendingMessage): Renamed to addMessage. (addMessage): New function. (deletePendingPieceMessage): Renamed to deletePieceMessageInQueue. (deletePieceMessageInQueue): New function. (deletePendingRequestMessage): Renamed to deleteRequestMessageInQueue. (deleteRequestMessageInQueue): New function. (deleteRequestSlot): RequestSlotMan::deleteRequestSlot(...) was moved here. (deleteTimeoutRequestSlot): RequestSlotMan::deleteTimeoutRequestSlot (...) was moved here. (deleteAllRequestSlot): RequestSlotMan::deleteAllRequestSlot(...) was moved here. (deleteCompletedRequestSlot): RequestSlotMan::deleteCompletedRequestSlot(...) was moved here. (getCorrespondingRequestSlot): RequestSlotMan::getCorrespoindingRequestSlot(...) was moved here. And renamed to getCorrespondingRequestSlot, correcting a typo. (countPendingMessage): Renamed to countMessageInQueue. (countMessageInQueue): New function. (countRequestSlot): RequestSlotMan::countRequestSlot() was moved here. (receiveHandshake): New function. (createHandshakeMessage): New function. (receiveMessage): New function. (createPeerMessage): New function. (syncPiece): New function. (getNewPieceAndSendInterest): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (sendHandshake): New function. (abortPiece): New function. (getDownloadPiece): New function. (getPeerMessageCommonProperty): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. To add simple Content-Disposition support: * src/HttpResponseCommand.h (determinFilename): New function. * src/HttpResponseCommand.cc (executeInternal): Use determinFilename(headers) instead of req->getFile() when comparing filename. (determinFilename): New function. (handleDefaultEncoding): Use determinFilename(headers) instead of req->getFile(). (handleOtherEncoding): Use determinFilename(headers) instead of req->getFile(). * src/Util.h (getContentDispositionFilename): New function. * src/Util.cc (getContentDispositionFilename): New function. * src/LogFactory.h (release): New function. * src/LogFactory.cc (release): New function. To fix a bug that causes out-of-bound exception when HTTP status line is wrong: * src/HttpConnection.cc (receiveResponse): Added a check for header size. * src/common.h (Deleter): New class. * src/SegmentMan.cc (~SegmentMan): Added deletion of splitter and diskWriter. * src/DownloadEngine.h (Commands): Use deque. (clearQueue): New function. * src/DownloadEngine.cc (~DownloadEngine): Added deletion of segmentMan. (cleanQueue): New function. * src/TorrentDownloadEngine.h (TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. (~TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. * src/TorrentDownloadEngine.cc (~TorrentDownloadEngine): Added deletion of torrentMan. * src/main.cc (clearRequest): Removed. (handler): Added deletion of e. (torrentHandler): Added deletion of te. (main): Do not share splitter. Use Deleter instead of clearRequest. Deletion of classes were updated.
2006-05-09 15:54:14 +00:00
// may be moved to other helper class in the future.
void testGetContentDispositionFilename();
2006-06-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To make a listening socket non-block: * src/SocketCore.h (setNonBlockingMode): New function. * src/SocketCore.cc (setNonBlockingMode): New function. (beginListen): Added a call to setNonBlockingMode(). (acceptConnection): Call setNonBlockingMode(). (setBlockingMode): Updated. To handle tracker's NAT-checking: * src/PeerConnection.cc (receiveHandshake): 'msg' param is filled with received data and its length is assigned to 'length' param, even if all handshake message is not yet received. * src/PeerInteractionCommand.cc (executeInternal): Use peerInteraction->receiveHandshake(true) when a new peer connects to localhost. A call to peerInteraction->sendHandshake() was removed because it is called from peerInteraction->receiveHandshake(true). * src/PeerInteraction.h (quickReplied): New variable. (receiveHandshake): Added an argument. * src/PeerInteraction.cc (PeerInteraction): Added the initialization of quickReplied. (receiveHandshake): Send handshake message as soon as the info hash in a handshake message from a peer is correct. To change the random part of peer id and key parameter: * src/TorrentMan.h (key): New variable. * src/TorrentMan.cc (setupInternal1): Use Util::randomAlpha() to generate random part of peer id, which is now "-aria2-"+13 alphabet characters([A-Za-z]). key is also generated by Util::randomAlpha() and it is now 8 character long. * src/Util.h (randomAlpha): New function. * src/Util.cc (randomAlpha): New function. * src/TrackerWatcherCommand.cc (execute): In a tracker request: Use torrentMan->key as key parameter. Added no_peer_id=1. Set snubbing flag to false when a choke message is received from a snubbed peer. * src/ChokeMessage.cc (receivedAction): Set snubbing flag to false.
2006-06-22 15:26:18 +00:00
void testRandomAlpha();
2006-07-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To add Metalink support(http/ftp only): * src/AbstractCommand.h (tryReserved): New function. * src/AbstractCommand.cc (execute): Call tryReserved(). (tryReserved): New function. * src/Request.h (Requests): New type definition. * src/SegmentMan.h (reserved): New variable. * src/Util.h (fileChecksum): New function. (toUpper): New function. (toLower): New function. * src/Util.cc (messageDigest.h): Included. (trim): Trim \r\n\t. (fileChecksum): New function. (toUpper): New function. (toLower): New function. * src/main.cc (normalDownload): New function. (main): Added 2 command-line options: metalink-file, metalink-connection. Their usage has not been written yet. * src/MetalinkProcessor.h: New class. * src/Xml2MetalinkProcessor.h: New class. * src/Xml2MetalinkProcessor.cc: New class. * src/MetalinkEntry.h: New class. * src/MetalinkEntry.cc: New class. * src/MetalinkResource.h: New class. * src/MetalinkResource.cc: New class. To add md5 message digest checking: * src/messageDigest.h: Rewritten. * src/MultiDiskWriter.cc: Updated according to the changes in messageDigest.h. * src/ShaVisitor.cc: Updated according to the changes in messageDigest.h. * src/Util.cc: Updated according to the changes in messageDigest.h. * src/AbstractDiskWriter.cc: Updated according to the changes in messageDigest.h. To fix a bug that causes segfault when the payload length in peer message is less than 0: * src/PeerConnection.cc: (receiveMessage): Fixed the bug. * src/PeerMessageUtil.cc (checkLength): Throw an exception if length is less than or equals to 0. To add new interfaces to Base64 encoding/decoding: * src/Base64.h (part_encode): Changed the method signature. (encode): New function(overload). (decode): New function(overload). * src/Base64.cc (part_encode): Rewritten. (encode): Rewritten. (encode): New function(overload). To prevent a peer to download same piece if there is an error in checksum: * src/PieceMessage.cc (receivedAction): Call peerInteraction->abortPiece().
2006-07-03 14:19:23 +00:00
void testToUpper();
void testToLower();
void testUppercase();
void testLowercase();
void testPercentDecode();
void testGetRealSize();
void testAbbrevSize();
void testToStream();
void testIsNumber();
void testIsLowercase();
void testIsUppercase();
void testAlphaToNum();
void testMkdirs();
void testConvertBitfield();
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
void testParseIntRange();
void testParseIntRange_invalidRange();
void testParseInt();
void testParseUInt();
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
void testParseLLInt();
void testParseULLInt();
void testParseIntNoThrow();
void testParseUIntNoThrow();
void testParseLLIntNoThrow();
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Rewritten to add content-type support. * src/DownloadHandler.{h, cc} * src/BtPostDownloadHandler.{h, cc} * test/BtPostDownloadHandlerTest.cc * src/MetalinkPostDownloadHandler.{h, cc} * test/MetalinkPostDownloadHandlerTest.cc * src/PostDownloadHandler.{h, cc} * src/DownloadHandlerConstants.{h, cc} * src/RequestGroup.cc * src/HttpResponseCommand.cc * src/FtpNegotiationCommand.cc * src/SingleFileDownloadContext.{h, cc} * src/RequestGroup.h * src/RequestGroupCriteria.h * src/ContentTypeRequestGroupCriteria.h Added 'mem' option value for --follow-metalink, --follow-torrent. If it is give, metalink/torrent file is not written to the disk, but just is kept in memory. Parsing is occurred on memory. * src/MetalinkHelper.{h, cc} * src/MetalinkProcessor.h * src/Xml2MetalinkProcessor.{h, cc} * test/Xml2MetalinkProcessorTest.cc * src/DownloadHandlerFactory.{h, cc} * test/DownloadHandlerFactoryTest.cc * src/PreDownloadHandler.{h, cc} * src/OptionHandlerFactory.cc * src/DefaultBtContext.{h, cc} * test/DefaultBtContextTest.cc * src/version_usage.cc * src/Metalink2RequestGroup.{h, cc} * src/RequestGroup.{h, cc} * src/a2functional.h * test/a2functionalTest.cc * src/MemoryBufferPreDownloadHandler.{h, cc} * src/OptionHandlerImpl.h * src/prefs.h * src/Util.{h, cc} * test/UtilTest.cc Keep DownloadResult rather than RequestGroup after downloads to reduce memory usage. * src/RequestGroupMan.{h, cc} * src/DownloadEngine.cc * src/BtDependency.{h, cc}: Changed the type of dependee from WeakHandle to SharedHandle because WeakHandle could be null. * src/RequestGroup.{h, cc} * src/DownloadEngineFactory.cc * src/DownloadResult.h Set totalLength after download finished * src/UnknownLengthPieceStorage.{h, cc} Keep torrent file specified in metalink in memory. * src/Metalink2RequestGroup.cc * src/BtDependency.cc * src/TrueRequestGroupCriteria.h Fixed the bug: seekg is used where seekp should be used. * src/ByteArrayDiskWriter.cc * test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
void testToString_binaryStream();
void testItos();
void testUitos();
void testNtoh64();
void testPercentEncode();
void testHtmlEscape();
void testJoinPath();
void testParseIndexPath();
void testCreateIndexPathMap();
void testGenerateRandomData();
void testFromHex();
void testParsePrioritizePieceRange();
void testApplyDir();
void testFixTaintedBasename();
void testIsNumericHost();
void testDetectDirTraversal();
void testEscapePath();
void testGetCidrPrefix();
void testInSameCidrBlock();
void testIsUtf8String();
void testNextParam();
2006-02-17 13:35:04 +00:00
};
CPPUNIT_TEST_SUITE_REGISTRATION( UtilTest );
void UtilTest::testStrip()
{
std::string str1 = "aria2";
CPPUNIT_ASSERT_EQUAL(str1, util::strip("aria2"));
CPPUNIT_ASSERT_EQUAL(str1, util::strip(" aria2"));
CPPUNIT_ASSERT_EQUAL(str1, util::strip("aria2 "));
CPPUNIT_ASSERT_EQUAL(str1, util::strip(" aria2 "));
CPPUNIT_ASSERT_EQUAL(str1, util::strip(" aria2 "));
std::string str2 = "aria2 debut";
CPPUNIT_ASSERT_EQUAL(str2, util::strip("aria2 debut"));
CPPUNIT_ASSERT_EQUAL(str2, util::strip(" aria2 debut "));
std::string str3 = "";
CPPUNIT_ASSERT_EQUAL(str3, util::strip(""));
CPPUNIT_ASSERT_EQUAL(str3, util::strip(" "));
CPPUNIT_ASSERT_EQUAL(str3, util::strip(" "));
std::string str4 = "A";
CPPUNIT_ASSERT_EQUAL(str4, util::strip("A"));
CPPUNIT_ASSERT_EQUAL(str4, util::strip(" A "));
CPPUNIT_ASSERT_EQUAL(str4, util::strip(" A "));
}
void UtilTest::testDivide() {
std::pair<std::string, std::string> p1;
util::divide(p1, "name=value", '=');
CPPUNIT_ASSERT_EQUAL(std::string("name"), p1.first);
CPPUNIT_ASSERT_EQUAL(std::string("value"), p1.second);
util::divide(p1, " name = value ", '=');
CPPUNIT_ASSERT_EQUAL(std::string("name"), p1.first);
CPPUNIT_ASSERT_EQUAL(std::string("value"), p1.second);
util::divide(p1, "=value", '=');
CPPUNIT_ASSERT_EQUAL(std::string(""), p1.first);
CPPUNIT_ASSERT_EQUAL(std::string("value"), p1.second);
util::divide(p1, "name=", '=');
CPPUNIT_ASSERT_EQUAL(std::string("name"), p1.first);
CPPUNIT_ASSERT_EQUAL(std::string(""), p1.second);
util::divide(p1, "name", '=');
CPPUNIT_ASSERT_EQUAL(std::string("name"), p1.first);
CPPUNIT_ASSERT_EQUAL(std::string(""), p1.second);
2006-02-17 13:35:04 +00:00
}
void UtilTest::testSplit() {
std::vector<std::string> v;
util::split("k1; k2;; k3", std::back_inserter(v), ";", true);
CPPUNIT_ASSERT_EQUAL((size_t)3, v.size());
std::vector<std::string>::iterator itr = v.begin();
CPPUNIT_ASSERT_EQUAL(std::string("k1"), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string("k2"), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string("k3"), *itr++);
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To divide TorrentMan into 6 classes: BtContext, BtRuntime, PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile * src/TrackerWatcherComand.h: Made subclass of BtContextAwareCommand. * src/SeedCheckCommand.cc: Use pieceStorage, btRuntime * src/PeerAbstractCommand.h: Made subclass of BtContextAwareCommand. * src/PeerAbstractCommand.cc: Use btRuntime. * src/BtContextAwareCommand.h: New class. * src/FileEntry.h: Added accessor methods for following variables. (path): Made private. (length): Made private. (offset): Made private. (extracted): Made private. (requested): Made private. (FileEntries): New definition. (FileEntryHandle): New definition. * src/FileEntry.cc: New file. * src/HaveEraseCommand.h: Made subclass of BtContextAwareCommand. * src/HaveEraseCommand.cc: Use btRuntime, pieceStorage. * src/PeerChokeCommand.h: Made subclass of BtContextAwareCommand. * src/PeerChokeCommand.cc: Use btRuntime, peerStorage, pieceStorage. * src/PieceStorage.h: New file. * src/PeerInteractionCommand.h: Use btContext. * src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage, btRuntime. * src/DefaultBtProgressInfoFile.h: New file. * src/DefaultBtProgressInfoFile.cc: New file. * src/File.cc (Util.h): New include. (mkdirs): New function. * src/MultiDiskAdaptor.h (mkdir): New function. * src/PeerListProcessor.h (Peers): Removed. * src/PeerInteraction.h (torrentMan): Removed. (btContext): New variable. (peerStorage): New variable. (pieceStorage): New variable. (btAnnounce): New variable. (getTorrentMan): Removed. (getBtContext): New function. * src/PeerInteraction.cc: Use btContext, peerStorage, pieceStorage, btAnnounce. * src/HandshakeMessage.h (TorrentMan.h): Removed. * src/HandshakeMessage.cc: Use btContext. * src/DefaultBtAnnounce.cc: New file. * src/MultiDiskWriter.cc: Use the accessor methods of FileEntry. * src/DefaultPieceStorage.cc: New file. * src/DefaultBtContext.h: New file. * src/TorrentRequestInfo.cc: Use btContext, pieceStorage. Use the accessor methods of FileEntry. * src/CookieBox.cc: Updated to use Util::slice(). * src/PieceMessage.cc: Use btContext, pieceStorage. * src/common.h (SharedHandle.h): New include. * src/PeerMessage.cc (PeerMessage): Added btContext, peerStorage, pieceStorage. * src/TorrentAutoSaveCommand.h: Made subclass of BtContextAwareCommand. * src/DiskAdaptor.h (topDir): Removed. (getFileEntryFromPath): Changed the return type to FileEntryHandle. (setTopDir): Removed. (getTopDir): Removed. * src/BtContext.h: New file. * src/DefaultPeerStorage.h: New file. * src/PieceMessage.h (TorrentMan.h): Removed. * src/RequestMessage.h (TorrentMan.h): Removed. * src/TorrentDownloadEngine.h (uploadLength): New variable. (btContext): New variable. (btRuntime): New variable. (pieceStorage): New variable. (peerStorage): New variable. (btAnnounce): New variable. (btProgressInfoFile): New variable. (torrentMan): Removed. (setBtContext): New function. * src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime, pieceStorage, peerStorage, btAnnounce, btProgressInfoFile. * src/Piece.h (toString): New function. (Pieces): New type definition. * src/Peer.h (active): New variable. (Peer): Added active. (activate): Set active to true. (deactivate): Set active to false. (isActive): New function. (Peers): New type definition. * src/DirectDiskAdaptor.cc (getFilePath): Use the accessor methods of FileEntry. * src/TorrentConsoleDownloadEngine.h (afterEachIteration): New function. * src/TorrentConsoleDownloadEngine.cc (haltRequested): New variable. (sendStatistics): Use pieceStorage, btRuntime. (afterEachIteration): New function. * src/AnnounceList: AnnounceTier->AnnounceTierHandle. * src/Directry.h (Directory): New function. (DirectoryHandle): New type definition. * src/BtProgressInfoFile.h: New file. * src/RequestMessage.cc: Use pieceStorage. * src/BtRuntime.h: New file. * src/DefaultBtContext.cc: New file. * src/BitfieldMan.h (getCompletedLength): New function(private). (getCompletedLength): New function. (getFilteredCompletedLength): New function. * src/BitfieldMan.h (getCompletedLength): New function(private). (getCompletedLength): New function. (getFilteredCompletedLength): New function. * src/MultiDiskAdaptor.cc (mkdir): New function. (openFile): Call mkdir(). (initAndOpenFile): Call mkdir(). * src/CancelMessage.h (TorrentMan.h): Removed. * src/RejectMessage.h (TorrentMan.h): Removed. * src/DownloadEngineFactory.cc (DefaultPieceStorage.h): New include. (DefaultPeerStorage.h): New include. (DefaultBtAnnounce.h): New include. (DefaultBtProgressInfoFile.h): New include. (newTorrentConsoleEngine): Rewritten. * src/ShareRatioSeedCriteria.h (torrentMan): Removed. (btContext): New variable. (peerStorage): New variable. (btRuntime): New variable. (evaluate): Use btContext, btRuntime, peerStorage. * src/AnnounceTier.h: New file. * src/BtAnnounce.h: New file. * src/BtRegistry.h: New file. * src/PeerInitiateConnectionCommand.h: Added btContext. * src/PeerConnection.h (TorrentMan.h): Removed. * src/PeerMessageFactory.cc: Use btContext, pieceStorage. * src/Util.h (slice): Added an argument. * src/Util.cc (slice): Added an argument to control whether trim is made or not. * src/PeerStorage.h: New file. * src/BtRegistry.cc: New file. * src/TrackerUpdateCommand.h: Made subclass of BtContextAwareCommand. * src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry. * src/MultiDiskWriter.h: FileEntry -> FileEntryHandle * src/PeerListenCommand.cc: Use btRuntime, peerStorage, btContext. * src/TorrentRequestInfo.h (e): Removed. (showFileEntry): Added an argument. (getDownloadEngine): Return 0. * src/DefaultBtAnnounce.h: New file. * src/TorrentAutoSaveCommand.cc: Use btRuntime, btProgressInfoFile. * src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce, * src/PeerMessageFactory.h (btContext): New variable. (pieceStorage): New variable. * src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage, btContext, btAnnounce. * src/DiskAdaptor.cc (DiskAdaptor): Removed topDir. (~DiskAdaptor): Removed topDir. * src/PeerListenCommand.h: Made subclass of BtContextAwareCommand. * src/SeedCheckCommand.h: Made subclass of BtContextAwareCommand. * src/File.h (mkdirs): New function. * src/DefaultPeerStorage): New file. * src/DownloadEngineFactory.h (newTorrentConsoleEngine): Use btContext. * src/BtContextAwareCommand.cc: New file. * src/PeerInitiateConnectionCommand.cc: Use btRuntime, peerStorage. * src/PeerMessage.h (btContext): New variable. (peerStorage): New variable. (pieceStorage): New variable. (setBtContext): New function. * src/Directry.cc (Directory): New function. (createDir): Do nothing if name.size() == 0. * src/AnnounceList.h (AnnounceTier): Removed. (AnnounceTiers): Removed. * src/DefaultPieceStorage.h: New file. * src/Piece.cc (toString): New function. To fix typo: * src/main.cc (showVersion): Fixed typo. To fix compile warning: * src/DelegatingPeerListProcessor.cc (canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
v.clear();
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To divide TorrentMan into 6 classes: BtContext, BtRuntime, PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile * src/TrackerWatcherComand.h: Made subclass of BtContextAwareCommand. * src/SeedCheckCommand.cc: Use pieceStorage, btRuntime * src/PeerAbstractCommand.h: Made subclass of BtContextAwareCommand. * src/PeerAbstractCommand.cc: Use btRuntime. * src/BtContextAwareCommand.h: New class. * src/FileEntry.h: Added accessor methods for following variables. (path): Made private. (length): Made private. (offset): Made private. (extracted): Made private. (requested): Made private. (FileEntries): New definition. (FileEntryHandle): New definition. * src/FileEntry.cc: New file. * src/HaveEraseCommand.h: Made subclass of BtContextAwareCommand. * src/HaveEraseCommand.cc: Use btRuntime, pieceStorage. * src/PeerChokeCommand.h: Made subclass of BtContextAwareCommand. * src/PeerChokeCommand.cc: Use btRuntime, peerStorage, pieceStorage. * src/PieceStorage.h: New file. * src/PeerInteractionCommand.h: Use btContext. * src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage, btRuntime. * src/DefaultBtProgressInfoFile.h: New file. * src/DefaultBtProgressInfoFile.cc: New file. * src/File.cc (Util.h): New include. (mkdirs): New function. * src/MultiDiskAdaptor.h (mkdir): New function. * src/PeerListProcessor.h (Peers): Removed. * src/PeerInteraction.h (torrentMan): Removed. (btContext): New variable. (peerStorage): New variable. (pieceStorage): New variable. (btAnnounce): New variable. (getTorrentMan): Removed. (getBtContext): New function. * src/PeerInteraction.cc: Use btContext, peerStorage, pieceStorage, btAnnounce. * src/HandshakeMessage.h (TorrentMan.h): Removed. * src/HandshakeMessage.cc: Use btContext. * src/DefaultBtAnnounce.cc: New file. * src/MultiDiskWriter.cc: Use the accessor methods of FileEntry. * src/DefaultPieceStorage.cc: New file. * src/DefaultBtContext.h: New file. * src/TorrentRequestInfo.cc: Use btContext, pieceStorage. Use the accessor methods of FileEntry. * src/CookieBox.cc: Updated to use Util::slice(). * src/PieceMessage.cc: Use btContext, pieceStorage. * src/common.h (SharedHandle.h): New include. * src/PeerMessage.cc (PeerMessage): Added btContext, peerStorage, pieceStorage. * src/TorrentAutoSaveCommand.h: Made subclass of BtContextAwareCommand. * src/DiskAdaptor.h (topDir): Removed. (getFileEntryFromPath): Changed the return type to FileEntryHandle. (setTopDir): Removed. (getTopDir): Removed. * src/BtContext.h: New file. * src/DefaultPeerStorage.h: New file. * src/PieceMessage.h (TorrentMan.h): Removed. * src/RequestMessage.h (TorrentMan.h): Removed. * src/TorrentDownloadEngine.h (uploadLength): New variable. (btContext): New variable. (btRuntime): New variable. (pieceStorage): New variable. (peerStorage): New variable. (btAnnounce): New variable. (btProgressInfoFile): New variable. (torrentMan): Removed. (setBtContext): New function. * src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime, pieceStorage, peerStorage, btAnnounce, btProgressInfoFile. * src/Piece.h (toString): New function. (Pieces): New type definition. * src/Peer.h (active): New variable. (Peer): Added active. (activate): Set active to true. (deactivate): Set active to false. (isActive): New function. (Peers): New type definition. * src/DirectDiskAdaptor.cc (getFilePath): Use the accessor methods of FileEntry. * src/TorrentConsoleDownloadEngine.h (afterEachIteration): New function. * src/TorrentConsoleDownloadEngine.cc (haltRequested): New variable. (sendStatistics): Use pieceStorage, btRuntime. (afterEachIteration): New function. * src/AnnounceList: AnnounceTier->AnnounceTierHandle. * src/Directry.h (Directory): New function. (DirectoryHandle): New type definition. * src/BtProgressInfoFile.h: New file. * src/RequestMessage.cc: Use pieceStorage. * src/BtRuntime.h: New file. * src/DefaultBtContext.cc: New file. * src/BitfieldMan.h (getCompletedLength): New function(private). (getCompletedLength): New function. (getFilteredCompletedLength): New function. * src/BitfieldMan.h (getCompletedLength): New function(private). (getCompletedLength): New function. (getFilteredCompletedLength): New function. * src/MultiDiskAdaptor.cc (mkdir): New function. (openFile): Call mkdir(). (initAndOpenFile): Call mkdir(). * src/CancelMessage.h (TorrentMan.h): Removed. * src/RejectMessage.h (TorrentMan.h): Removed. * src/DownloadEngineFactory.cc (DefaultPieceStorage.h): New include. (DefaultPeerStorage.h): New include. (DefaultBtAnnounce.h): New include. (DefaultBtProgressInfoFile.h): New include. (newTorrentConsoleEngine): Rewritten. * src/ShareRatioSeedCriteria.h (torrentMan): Removed. (btContext): New variable. (peerStorage): New variable. (btRuntime): New variable. (evaluate): Use btContext, btRuntime, peerStorage. * src/AnnounceTier.h: New file. * src/BtAnnounce.h: New file. * src/BtRegistry.h: New file. * src/PeerInitiateConnectionCommand.h: Added btContext. * src/PeerConnection.h (TorrentMan.h): Removed. * src/PeerMessageFactory.cc: Use btContext, pieceStorage. * src/Util.h (slice): Added an argument. * src/Util.cc (slice): Added an argument to control whether trim is made or not. * src/PeerStorage.h: New file. * src/BtRegistry.cc: New file. * src/TrackerUpdateCommand.h: Made subclass of BtContextAwareCommand. * src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry. * src/MultiDiskWriter.h: FileEntry -> FileEntryHandle * src/PeerListenCommand.cc: Use btRuntime, peerStorage, btContext. * src/TorrentRequestInfo.h (e): Removed. (showFileEntry): Added an argument. (getDownloadEngine): Return 0. * src/DefaultBtAnnounce.h: New file. * src/TorrentAutoSaveCommand.cc: Use btRuntime, btProgressInfoFile. * src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce, * src/PeerMessageFactory.h (btContext): New variable. (pieceStorage): New variable. * src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage, btContext, btAnnounce. * src/DiskAdaptor.cc (DiskAdaptor): Removed topDir. (~DiskAdaptor): Removed topDir. * src/PeerListenCommand.h: Made subclass of BtContextAwareCommand. * src/SeedCheckCommand.h: Made subclass of BtContextAwareCommand. * src/File.h (mkdirs): New function. * src/DefaultPeerStorage): New file. * src/DownloadEngineFactory.h (newTorrentConsoleEngine): Use btContext. * src/BtContextAwareCommand.cc: New file. * src/PeerInitiateConnectionCommand.cc: Use btRuntime, peerStorage. * src/PeerMessage.h (btContext): New variable. (peerStorage): New variable. (pieceStorage): New variable. (setBtContext): New function. * src/Directry.cc (Directory): New function. (createDir): Do nothing if name.size() == 0. * src/AnnounceList.h (AnnounceTier): Removed. (AnnounceTiers): Removed. * src/DefaultPieceStorage.h: New file. * src/Piece.cc (toString): New function. To fix typo: * src/main.cc (showVersion): Fixed typo. To fix compile warning: * src/DelegatingPeerListProcessor.cc (canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
util::split("k1; k2; k3",
std::back_inserter(v), ";");
CPPUNIT_ASSERT_EQUAL((size_t)3, v.size());
itr = v.begin();
CPPUNIT_ASSERT_EQUAL(std::string("k1"), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string(" k2"), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string(" k3"), *itr++);
v.clear();
util::split("k=v", std::back_inserter(v), ";", false, true);
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
itr = v.begin();
CPPUNIT_ASSERT_EQUAL(std::string("k=v"), *itr++);
v.clear();
util::split(";;k1;;k2;", std::back_inserter(v), ";", false, true);
CPPUNIT_ASSERT_EQUAL((size_t)6, v.size());
itr = v.begin();
CPPUNIT_ASSERT_EQUAL(std::string(""), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string(""), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string("k1"), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string(""), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string("k2"), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string(""), *itr++);
v.clear();
util::split(";;k1;;k2;", std::back_inserter(v), ";");
CPPUNIT_ASSERT_EQUAL((size_t)2, v.size());
itr = v.begin();
CPPUNIT_ASSERT_EQUAL(std::string("k1"), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string("k2"), *itr++);
v.clear();
util::split("k; ", std::back_inserter(v), ";");
CPPUNIT_ASSERT_EQUAL((size_t)2, v.size());
itr = v.begin();
CPPUNIT_ASSERT_EQUAL(std::string("k"), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string(" "), *itr++);
v.clear();
util::split(" ", std::back_inserter(v), ";", true, true);
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
CPPUNIT_ASSERT_EQUAL(std::string(""), v[0]);
v.clear();
util::split(" ", std::back_inserter(v), ";", true);
CPPUNIT_ASSERT_EQUAL((size_t)0, v.size());
v.clear();
util::split(" ", std::back_inserter(v), ";");
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
CPPUNIT_ASSERT_EQUAL(std::string(" "), v[0]);
v.clear();
util::split(";", std::back_inserter(v), ";");
CPPUNIT_ASSERT_EQUAL((size_t)0, v.size());
v.clear();
util::split(";", std::back_inserter(v), ";", false, true);
CPPUNIT_ASSERT_EQUAL((size_t)2, v.size());
itr = v.begin();
CPPUNIT_ASSERT_EQUAL(std::string(""), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string(""), *itr++);
v.clear();
util::split("", std::back_inserter(v), ";", false, true);
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
CPPUNIT_ASSERT_EQUAL(std::string(""), v[0]);
2006-02-17 13:35:04 +00:00
}
2006-02-21 12:27:17 +00:00
void UtilTest::testEndsWith() {
std::string target = "abcdefg";
std::string part = "fg";
CPPUNIT_ASSERT(util::endsWith(target, part));
2006-02-21 12:27:17 +00:00
target = "abdefg";
part = "g";
CPPUNIT_ASSERT(util::endsWith(target, part));
2006-02-21 12:27:17 +00:00
target = "abdefg";
part = "eg";
CPPUNIT_ASSERT(!util::endsWith(target, part));
2006-02-21 12:27:17 +00:00
target = "g";
part = "eg";
CPPUNIT_ASSERT(!util::endsWith(target, part));
2006-02-21 12:27:17 +00:00
target = "g";
part = "g";
CPPUNIT_ASSERT(util::endsWith(target, part));
2006-02-21 12:27:17 +00:00
target = "g";
part = "";
CPPUNIT_ASSERT(util::endsWith(target, part));
2006-02-21 12:27:17 +00:00
target = "";
part = "";
CPPUNIT_ASSERT(util::endsWith(target, part));
2006-02-21 12:27:17 +00:00
target = "";
part = "g";
CPPUNIT_ASSERT(!util::endsWith(target, part));
2006-02-21 12:27:17 +00:00
}
2006-02-21 15:01:05 +00:00
void UtilTest::testReplace() {
CPPUNIT_ASSERT_EQUAL(std::string("abc\n"), util::replace("abc\r\n", "\r", ""));
CPPUNIT_ASSERT_EQUAL(std::string("abc"), util::replace("abc\r\n", "\r\n", ""));
CPPUNIT_ASSERT_EQUAL(std::string(""), util::replace("", "\r\n", ""));
CPPUNIT_ASSERT_EQUAL(std::string("abc"), util::replace("abc", "", "a"));
CPPUNIT_ASSERT_EQUAL(std::string("xbc"), util::replace("abc", "a", "x"));
2006-02-21 15:01:05 +00:00
}
void UtilTest::testStartsWith() {
std::string target;
std::string part;
target = "abcdefg";
part = "abc";
CPPUNIT_ASSERT(util::startsWith(target, part));
target = "abcdefg";
part = "abx";
CPPUNIT_ASSERT(!util::startsWith(target, part));
target = "abcdefg";
part = "bcd";
CPPUNIT_ASSERT(!util::startsWith(target, part));
target = "";
part = "a";
CPPUNIT_ASSERT(!util::startsWith(target, part));
target = "";
part = "";
CPPUNIT_ASSERT(util::startsWith(target, part));
target = "a";
part = "";
CPPUNIT_ASSERT(util::startsWith(target, part));
target = "a";
part = "a";
CPPUNIT_ASSERT(util::startsWith(target, part));
}
2006-05-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Each peer message has its own class. * src/PendingMessages.h: Removed. * src/PendingMessages.cc: Removed. The sending process was moved to each message class. * src/RequestSlotMan.h: Removed. * src/RequestSlotMan.cc: Removed. All functionarities were moved to SendMessageQueue. * src/RequestMessage.h: New class. * src/RequestMessage.cc: New class. * src/CancelMessage.h: New class. * src/CancelMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/ChokeMessage.h: New class. * src/ChokeMessage.cc: New class. * src/KeepAliveMessage.h: New class. * src/KeepAliveMessage.cc: New class. * src/PortMessage.h: New class. * src/UnchokeMessage.h: New class. * src/UnchokeMessage.cc: New class. * src/PieceMessage.h: New class. * src/PieceMessage.cc: New class. * src/HaveMessage.h: New class. * src/HaveMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/NotInterestedMessage.h: New class. * src/NotInterestedMessage.cc: New class. * src/InterestedMessage.h: New class. * src/InterestedMessage.cc: New class. * src/HandshakeMessage.h (sendMessageQueue): New variable. (getSendMessageQueue): New function. (setSendMessageQueue): New function. * src/HandshakeMessage.cc: New class. * src/PeerConnection.h (receiveMessage): Changed return value and arguments. (receiveHandshake): Changed return value and arguments. * src/PeerConnection.cc (receiveMessage): Do not create message class here. (receiveHandshake): Do not create handshake class here. * src/PeerInteractionCommand.h (peerConnection): Removed. (piece): Removed. (syncPiece): Removed. (sendInterest): Removed. (sendMessages): Removed. (createRequestPendingMessage): Removed. (checkPieceHash): Removed. (erasePieceOnDisk): Removed. (getNewPieceAndSendInterest): Removed. (onGotNewPice): Removed. (onGotWrongPiece): Removed. * src/PeerInteractionCommand.cc (PeerInteractionCommand): Removed peerConnection, piece. (~PeerInteractionCommand): Removed peerConnection. (executeInternal): Use sendMessageQueue instead of peerConnection. (syncPiece): Moved to SendMessageQueue. (decideChoking): Removed PendingMessage. (receiveMessage): Use sendMessageQueue instead of peerConnection. The action after receiving peer message was moved to each message class. (onGotNewPice): Moved to SendMessageQueue. (onGotWrongPiece): Moved to SendMessageQueue. (getNewPieceAndSendInterest): Moved to SendMessageQueue. (sendInterest): Moved to SendMessageQueue. (createRequestPendingMessage): Removed. (sendMessages): Moved to SendMessageQueue. (onAbort): Use SendMessageQueue::abortPiece() (keepAlive): Use sendMessageQueue instead of peerConnection. (beforeSocketCheck): Use sendMessageQueue instead of peerConnection. (checkPieceHash): Moved to SendMessageQueue. (erasePieceOnDisk): Moved to SendMessageQueue. * src/PeerMessageUtil.h (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessageUtil.cc (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessage.h (id): Removed. (index): Removed. (begin): Removed. (length): Removed. (bitfield): Removed. (bitfieldLength): Removed. (block): Removed. (blockLength): Removed. (inProgress): New variable. (cuid): New variable. (peer): New variable. (sendMessageQueue): New variable. (logger): New variable. (setBitfield): Removed. (getBitfield): Removed. (setBlock): Removed. (getBlock): Removed. (getBitfieldLength): Removed. (getBlockLength): Removed. (isInProgress): New function. (toString): Made pure virtual. (check): New function. (send): New function. (receivedAction): New function. (getId): Made pure virtual. (setId): Removed. (getIndex): Removed. (setIndex): Removed. (getBegin): Removed. (setBegin): Removed. (getLength): Removed. (setLength): Removed. (getCuid): New function. (setCuid): New function. (getPeer): New function. (setPeer): New function. (getSendMessageQueue): New function. (setSendMessageQueue): New function. (ID): Removed. * src/PeerMessage.cc (setBitfield): Removed. (setBlock): Removed. (toString): Removed. * src/TorrentMan.h (getPieceLength): New function. (getPieceLength): New function. * src/SendMessageQueue.h (REQUEST_TIME_OUT): New definition. (RequestSlots): New definition. (MessageQueue): New definition. (requestSlotMan): Removed. (pendingMessages): Removed. (requestSlots): New variable. (messageQueue): New variable. (torrentMan): New variable. (peerConnection): New variable. (peer): New variable. (piece): New variable. (getNewPieceAndSendInterest): New function. (createPeerMessage): New function. (createHandshakeMessage): New function. (send): Made private. (setPeerMessageCommonProperty): New function. (deleteAllRequestSlot): New function. (deleteRequestMessageInQueue): New function. (cancelAllRequest): Made private. (cancelAllRequest): Made private. (countRequestSlot): Made private. (addPendingMessage): Removed. (deletePendingPieceMessage): Removed. (deletePendingRequestMessage): Removed. (addMessage): New function. (deletePieceMessageInQueue): New function. (deleteTimeoutRequestSlot): Changed argument. (deleteCompletedRequestSlot): Changed argument. (getCorrespoindingRequestSlot): Renamed to getCorrespondingRequestSlot. (getCorrespondingRequestSlot): New function. (countPendingMessage): Removed. (countMessageInQueue): New function. (getTorrentMan): New function. (getPeerConnection): New function. (hasDownloadPiece): New function. (getDownloadPiece): New function. (setDownloadPiece): New function. (syncPiece): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (abortPiece): New function. (sendHandshake): New function. (receiveMessage): New function. (receiveHandshake): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. * src/SendMessageQueue.cc (SendMessageQueue): Removed requestSlotMan. Instantiated peerConnection here. (~SendMessageQueue): Removed requestSlotMan. Added deletion of peerConnection and the contents of messageQueue. (send): Updated according to the change of messageQueue. (addPendingMessage): Renamed to addMessage. (addMessage): New function. (deletePendingPieceMessage): Renamed to deletePieceMessageInQueue. (deletePieceMessageInQueue): New function. (deletePendingRequestMessage): Renamed to deleteRequestMessageInQueue. (deleteRequestMessageInQueue): New function. (deleteRequestSlot): RequestSlotMan::deleteRequestSlot(...) was moved here. (deleteTimeoutRequestSlot): RequestSlotMan::deleteTimeoutRequestSlot (...) was moved here. (deleteAllRequestSlot): RequestSlotMan::deleteAllRequestSlot(...) was moved here. (deleteCompletedRequestSlot): RequestSlotMan::deleteCompletedRequestSlot(...) was moved here. (getCorrespondingRequestSlot): RequestSlotMan::getCorrespoindingRequestSlot(...) was moved here. And renamed to getCorrespondingRequestSlot, correcting a typo. (countPendingMessage): Renamed to countMessageInQueue. (countMessageInQueue): New function. (countRequestSlot): RequestSlotMan::countRequestSlot() was moved here. (receiveHandshake): New function. (createHandshakeMessage): New function. (receiveMessage): New function. (createPeerMessage): New function. (syncPiece): New function. (getNewPieceAndSendInterest): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (sendHandshake): New function. (abortPiece): New function. (getDownloadPiece): New function. (getPeerMessageCommonProperty): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. To add simple Content-Disposition support: * src/HttpResponseCommand.h (determinFilename): New function. * src/HttpResponseCommand.cc (executeInternal): Use determinFilename(headers) instead of req->getFile() when comparing filename. (determinFilename): New function. (handleDefaultEncoding): Use determinFilename(headers) instead of req->getFile(). (handleOtherEncoding): Use determinFilename(headers) instead of req->getFile(). * src/Util.h (getContentDispositionFilename): New function. * src/Util.cc (getContentDispositionFilename): New function. * src/LogFactory.h (release): New function. * src/LogFactory.cc (release): New function. To fix a bug that causes out-of-bound exception when HTTP status line is wrong: * src/HttpConnection.cc (receiveResponse): Added a check for header size. * src/common.h (Deleter): New class. * src/SegmentMan.cc (~SegmentMan): Added deletion of splitter and diskWriter. * src/DownloadEngine.h (Commands): Use deque. (clearQueue): New function. * src/DownloadEngine.cc (~DownloadEngine): Added deletion of segmentMan. (cleanQueue): New function. * src/TorrentDownloadEngine.h (TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. (~TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. * src/TorrentDownloadEngine.cc (~TorrentDownloadEngine): Added deletion of torrentMan. * src/main.cc (clearRequest): Removed. (handler): Added deletion of e. (torrentHandler): Added deletion of te. (main): Do not share splitter. Use Deleter instead of clearRequest. Deletion of classes were updated.
2006-05-09 15:54:14 +00:00
void UtilTest::testGetContentDispositionFilename() {
std::string h1 = "attachment; filename=\"aria2.tar.bz2\"";
CPPUNIT_ASSERT_EQUAL(std::string("aria2.tar.bz2"), util::getContentDispositionFilename(h1));
2006-05-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Each peer message has its own class. * src/PendingMessages.h: Removed. * src/PendingMessages.cc: Removed. The sending process was moved to each message class. * src/RequestSlotMan.h: Removed. * src/RequestSlotMan.cc: Removed. All functionarities were moved to SendMessageQueue. * src/RequestMessage.h: New class. * src/RequestMessage.cc: New class. * src/CancelMessage.h: New class. * src/CancelMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/ChokeMessage.h: New class. * src/ChokeMessage.cc: New class. * src/KeepAliveMessage.h: New class. * src/KeepAliveMessage.cc: New class. * src/PortMessage.h: New class. * src/UnchokeMessage.h: New class. * src/UnchokeMessage.cc: New class. * src/PieceMessage.h: New class. * src/PieceMessage.cc: New class. * src/HaveMessage.h: New class. * src/HaveMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/NotInterestedMessage.h: New class. * src/NotInterestedMessage.cc: New class. * src/InterestedMessage.h: New class. * src/InterestedMessage.cc: New class. * src/HandshakeMessage.h (sendMessageQueue): New variable. (getSendMessageQueue): New function. (setSendMessageQueue): New function. * src/HandshakeMessage.cc: New class. * src/PeerConnection.h (receiveMessage): Changed return value and arguments. (receiveHandshake): Changed return value and arguments. * src/PeerConnection.cc (receiveMessage): Do not create message class here. (receiveHandshake): Do not create handshake class here. * src/PeerInteractionCommand.h (peerConnection): Removed. (piece): Removed. (syncPiece): Removed. (sendInterest): Removed. (sendMessages): Removed. (createRequestPendingMessage): Removed. (checkPieceHash): Removed. (erasePieceOnDisk): Removed. (getNewPieceAndSendInterest): Removed. (onGotNewPice): Removed. (onGotWrongPiece): Removed. * src/PeerInteractionCommand.cc (PeerInteractionCommand): Removed peerConnection, piece. (~PeerInteractionCommand): Removed peerConnection. (executeInternal): Use sendMessageQueue instead of peerConnection. (syncPiece): Moved to SendMessageQueue. (decideChoking): Removed PendingMessage. (receiveMessage): Use sendMessageQueue instead of peerConnection. The action after receiving peer message was moved to each message class. (onGotNewPice): Moved to SendMessageQueue. (onGotWrongPiece): Moved to SendMessageQueue. (getNewPieceAndSendInterest): Moved to SendMessageQueue. (sendInterest): Moved to SendMessageQueue. (createRequestPendingMessage): Removed. (sendMessages): Moved to SendMessageQueue. (onAbort): Use SendMessageQueue::abortPiece() (keepAlive): Use sendMessageQueue instead of peerConnection. (beforeSocketCheck): Use sendMessageQueue instead of peerConnection. (checkPieceHash): Moved to SendMessageQueue. (erasePieceOnDisk): Moved to SendMessageQueue. * src/PeerMessageUtil.h (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessageUtil.cc (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessage.h (id): Removed. (index): Removed. (begin): Removed. (length): Removed. (bitfield): Removed. (bitfieldLength): Removed. (block): Removed. (blockLength): Removed. (inProgress): New variable. (cuid): New variable. (peer): New variable. (sendMessageQueue): New variable. (logger): New variable. (setBitfield): Removed. (getBitfield): Removed. (setBlock): Removed. (getBlock): Removed. (getBitfieldLength): Removed. (getBlockLength): Removed. (isInProgress): New function. (toString): Made pure virtual. (check): New function. (send): New function. (receivedAction): New function. (getId): Made pure virtual. (setId): Removed. (getIndex): Removed. (setIndex): Removed. (getBegin): Removed. (setBegin): Removed. (getLength): Removed. (setLength): Removed. (getCuid): New function. (setCuid): New function. (getPeer): New function. (setPeer): New function. (getSendMessageQueue): New function. (setSendMessageQueue): New function. (ID): Removed. * src/PeerMessage.cc (setBitfield): Removed. (setBlock): Removed. (toString): Removed. * src/TorrentMan.h (getPieceLength): New function. (getPieceLength): New function. * src/SendMessageQueue.h (REQUEST_TIME_OUT): New definition. (RequestSlots): New definition. (MessageQueue): New definition. (requestSlotMan): Removed. (pendingMessages): Removed. (requestSlots): New variable. (messageQueue): New variable. (torrentMan): New variable. (peerConnection): New variable. (peer): New variable. (piece): New variable. (getNewPieceAndSendInterest): New function. (createPeerMessage): New function. (createHandshakeMessage): New function. (send): Made private. (setPeerMessageCommonProperty): New function. (deleteAllRequestSlot): New function. (deleteRequestMessageInQueue): New function. (cancelAllRequest): Made private. (cancelAllRequest): Made private. (countRequestSlot): Made private. (addPendingMessage): Removed. (deletePendingPieceMessage): Removed. (deletePendingRequestMessage): Removed. (addMessage): New function. (deletePieceMessageInQueue): New function. (deleteTimeoutRequestSlot): Changed argument. (deleteCompletedRequestSlot): Changed argument. (getCorrespoindingRequestSlot): Renamed to getCorrespondingRequestSlot. (getCorrespondingRequestSlot): New function. (countPendingMessage): Removed. (countMessageInQueue): New function. (getTorrentMan): New function. (getPeerConnection): New function. (hasDownloadPiece): New function. (getDownloadPiece): New function. (setDownloadPiece): New function. (syncPiece): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (abortPiece): New function. (sendHandshake): New function. (receiveMessage): New function. (receiveHandshake): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. * src/SendMessageQueue.cc (SendMessageQueue): Removed requestSlotMan. Instantiated peerConnection here. (~SendMessageQueue): Removed requestSlotMan. Added deletion of peerConnection and the contents of messageQueue. (send): Updated according to the change of messageQueue. (addPendingMessage): Renamed to addMessage. (addMessage): New function. (deletePendingPieceMessage): Renamed to deletePieceMessageInQueue. (deletePieceMessageInQueue): New function. (deletePendingRequestMessage): Renamed to deleteRequestMessageInQueue. (deleteRequestMessageInQueue): New function. (deleteRequestSlot): RequestSlotMan::deleteRequestSlot(...) was moved here. (deleteTimeoutRequestSlot): RequestSlotMan::deleteTimeoutRequestSlot (...) was moved here. (deleteAllRequestSlot): RequestSlotMan::deleteAllRequestSlot(...) was moved here. (deleteCompletedRequestSlot): RequestSlotMan::deleteCompletedRequestSlot(...) was moved here. (getCorrespondingRequestSlot): RequestSlotMan::getCorrespoindingRequestSlot(...) was moved here. And renamed to getCorrespondingRequestSlot, correcting a typo. (countPendingMessage): Renamed to countMessageInQueue. (countMessageInQueue): New function. (countRequestSlot): RequestSlotMan::countRequestSlot() was moved here. (receiveHandshake): New function. (createHandshakeMessage): New function. (receiveMessage): New function. (createPeerMessage): New function. (syncPiece): New function. (getNewPieceAndSendInterest): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (sendHandshake): New function. (abortPiece): New function. (getDownloadPiece): New function. (getPeerMessageCommonProperty): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. To add simple Content-Disposition support: * src/HttpResponseCommand.h (determinFilename): New function. * src/HttpResponseCommand.cc (executeInternal): Use determinFilename(headers) instead of req->getFile() when comparing filename. (determinFilename): New function. (handleDefaultEncoding): Use determinFilename(headers) instead of req->getFile(). (handleOtherEncoding): Use determinFilename(headers) instead of req->getFile(). * src/Util.h (getContentDispositionFilename): New function. * src/Util.cc (getContentDispositionFilename): New function. * src/LogFactory.h (release): New function. * src/LogFactory.cc (release): New function. To fix a bug that causes out-of-bound exception when HTTP status line is wrong: * src/HttpConnection.cc (receiveResponse): Added a check for header size. * src/common.h (Deleter): New class. * src/SegmentMan.cc (~SegmentMan): Added deletion of splitter and diskWriter. * src/DownloadEngine.h (Commands): Use deque. (clearQueue): New function. * src/DownloadEngine.cc (~DownloadEngine): Added deletion of segmentMan. (cleanQueue): New function. * src/TorrentDownloadEngine.h (TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. (~TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. * src/TorrentDownloadEngine.cc (~TorrentDownloadEngine): Added deletion of torrentMan. * src/main.cc (clearRequest): Removed. (handler): Added deletion of e. (torrentHandler): Added deletion of te. (main): Do not share splitter. Use Deleter instead of clearRequest. Deletion of classes were updated.
2006-05-09 15:54:14 +00:00
std::string h2 = "attachment; filename=\"\"";
CPPUNIT_ASSERT_EQUAL(std::string(""), util::getContentDispositionFilename(h2));
2006-05-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Each peer message has its own class. * src/PendingMessages.h: Removed. * src/PendingMessages.cc: Removed. The sending process was moved to each message class. * src/RequestSlotMan.h: Removed. * src/RequestSlotMan.cc: Removed. All functionarities were moved to SendMessageQueue. * src/RequestMessage.h: New class. * src/RequestMessage.cc: New class. * src/CancelMessage.h: New class. * src/CancelMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/ChokeMessage.h: New class. * src/ChokeMessage.cc: New class. * src/KeepAliveMessage.h: New class. * src/KeepAliveMessage.cc: New class. * src/PortMessage.h: New class. * src/UnchokeMessage.h: New class. * src/UnchokeMessage.cc: New class. * src/PieceMessage.h: New class. * src/PieceMessage.cc: New class. * src/HaveMessage.h: New class. * src/HaveMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/NotInterestedMessage.h: New class. * src/NotInterestedMessage.cc: New class. * src/InterestedMessage.h: New class. * src/InterestedMessage.cc: New class. * src/HandshakeMessage.h (sendMessageQueue): New variable. (getSendMessageQueue): New function. (setSendMessageQueue): New function. * src/HandshakeMessage.cc: New class. * src/PeerConnection.h (receiveMessage): Changed return value and arguments. (receiveHandshake): Changed return value and arguments. * src/PeerConnection.cc (receiveMessage): Do not create message class here. (receiveHandshake): Do not create handshake class here. * src/PeerInteractionCommand.h (peerConnection): Removed. (piece): Removed. (syncPiece): Removed. (sendInterest): Removed. (sendMessages): Removed. (createRequestPendingMessage): Removed. (checkPieceHash): Removed. (erasePieceOnDisk): Removed. (getNewPieceAndSendInterest): Removed. (onGotNewPice): Removed. (onGotWrongPiece): Removed. * src/PeerInteractionCommand.cc (PeerInteractionCommand): Removed peerConnection, piece. (~PeerInteractionCommand): Removed peerConnection. (executeInternal): Use sendMessageQueue instead of peerConnection. (syncPiece): Moved to SendMessageQueue. (decideChoking): Removed PendingMessage. (receiveMessage): Use sendMessageQueue instead of peerConnection. The action after receiving peer message was moved to each message class. (onGotNewPice): Moved to SendMessageQueue. (onGotWrongPiece): Moved to SendMessageQueue. (getNewPieceAndSendInterest): Moved to SendMessageQueue. (sendInterest): Moved to SendMessageQueue. (createRequestPendingMessage): Removed. (sendMessages): Moved to SendMessageQueue. (onAbort): Use SendMessageQueue::abortPiece() (keepAlive): Use sendMessageQueue instead of peerConnection. (beforeSocketCheck): Use sendMessageQueue instead of peerConnection. (checkPieceHash): Moved to SendMessageQueue. (erasePieceOnDisk): Moved to SendMessageQueue. * src/PeerMessageUtil.h (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessageUtil.cc (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessage.h (id): Removed. (index): Removed. (begin): Removed. (length): Removed. (bitfield): Removed. (bitfieldLength): Removed. (block): Removed. (blockLength): Removed. (inProgress): New variable. (cuid): New variable. (peer): New variable. (sendMessageQueue): New variable. (logger): New variable. (setBitfield): Removed. (getBitfield): Removed. (setBlock): Removed. (getBlock): Removed. (getBitfieldLength): Removed. (getBlockLength): Removed. (isInProgress): New function. (toString): Made pure virtual. (check): New function. (send): New function. (receivedAction): New function. (getId): Made pure virtual. (setId): Removed. (getIndex): Removed. (setIndex): Removed. (getBegin): Removed. (setBegin): Removed. (getLength): Removed. (setLength): Removed. (getCuid): New function. (setCuid): New function. (getPeer): New function. (setPeer): New function. (getSendMessageQueue): New function. (setSendMessageQueue): New function. (ID): Removed. * src/PeerMessage.cc (setBitfield): Removed. (setBlock): Removed. (toString): Removed. * src/TorrentMan.h (getPieceLength): New function. (getPieceLength): New function. * src/SendMessageQueue.h (REQUEST_TIME_OUT): New definition. (RequestSlots): New definition. (MessageQueue): New definition. (requestSlotMan): Removed. (pendingMessages): Removed. (requestSlots): New variable. (messageQueue): New variable. (torrentMan): New variable. (peerConnection): New variable. (peer): New variable. (piece): New variable. (getNewPieceAndSendInterest): New function. (createPeerMessage): New function. (createHandshakeMessage): New function. (send): Made private. (setPeerMessageCommonProperty): New function. (deleteAllRequestSlot): New function. (deleteRequestMessageInQueue): New function. (cancelAllRequest): Made private. (cancelAllRequest): Made private. (countRequestSlot): Made private. (addPendingMessage): Removed. (deletePendingPieceMessage): Removed. (deletePendingRequestMessage): Removed. (addMessage): New function. (deletePieceMessageInQueue): New function. (deleteTimeoutRequestSlot): Changed argument. (deleteCompletedRequestSlot): Changed argument. (getCorrespoindingRequestSlot): Renamed to getCorrespondingRequestSlot. (getCorrespondingRequestSlot): New function. (countPendingMessage): Removed. (countMessageInQueue): New function. (getTorrentMan): New function. (getPeerConnection): New function. (hasDownloadPiece): New function. (getDownloadPiece): New function. (setDownloadPiece): New function. (syncPiece): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (abortPiece): New function. (sendHandshake): New function. (receiveMessage): New function. (receiveHandshake): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. * src/SendMessageQueue.cc (SendMessageQueue): Removed requestSlotMan. Instantiated peerConnection here. (~SendMessageQueue): Removed requestSlotMan. Added deletion of peerConnection and the contents of messageQueue. (send): Updated according to the change of messageQueue. (addPendingMessage): Renamed to addMessage. (addMessage): New function. (deletePendingPieceMessage): Renamed to deletePieceMessageInQueue. (deletePieceMessageInQueue): New function. (deletePendingRequestMessage): Renamed to deleteRequestMessageInQueue. (deleteRequestMessageInQueue): New function. (deleteRequestSlot): RequestSlotMan::deleteRequestSlot(...) was moved here. (deleteTimeoutRequestSlot): RequestSlotMan::deleteTimeoutRequestSlot (...) was moved here. (deleteAllRequestSlot): RequestSlotMan::deleteAllRequestSlot(...) was moved here. (deleteCompletedRequestSlot): RequestSlotMan::deleteCompletedRequestSlot(...) was moved here. (getCorrespondingRequestSlot): RequestSlotMan::getCorrespoindingRequestSlot(...) was moved here. And renamed to getCorrespondingRequestSlot, correcting a typo. (countPendingMessage): Renamed to countMessageInQueue. (countMessageInQueue): New function. (countRequestSlot): RequestSlotMan::countRequestSlot() was moved here. (receiveHandshake): New function. (createHandshakeMessage): New function. (receiveMessage): New function. (createPeerMessage): New function. (syncPiece): New function. (getNewPieceAndSendInterest): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (sendHandshake): New function. (abortPiece): New function. (getDownloadPiece): New function. (getPeerMessageCommonProperty): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. To add simple Content-Disposition support: * src/HttpResponseCommand.h (determinFilename): New function. * src/HttpResponseCommand.cc (executeInternal): Use determinFilename(headers) instead of req->getFile() when comparing filename. (determinFilename): New function. (handleDefaultEncoding): Use determinFilename(headers) instead of req->getFile(). (handleOtherEncoding): Use determinFilename(headers) instead of req->getFile(). * src/Util.h (getContentDispositionFilename): New function. * src/Util.cc (getContentDispositionFilename): New function. * src/LogFactory.h (release): New function. * src/LogFactory.cc (release): New function. To fix a bug that causes out-of-bound exception when HTTP status line is wrong: * src/HttpConnection.cc (receiveResponse): Added a check for header size. * src/common.h (Deleter): New class. * src/SegmentMan.cc (~SegmentMan): Added deletion of splitter and diskWriter. * src/DownloadEngine.h (Commands): Use deque. (clearQueue): New function. * src/DownloadEngine.cc (~DownloadEngine): Added deletion of segmentMan. (cleanQueue): New function. * src/TorrentDownloadEngine.h (TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. (~TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. * src/TorrentDownloadEngine.cc (~TorrentDownloadEngine): Added deletion of torrentMan. * src/main.cc (clearRequest): Removed. (handler): Added deletion of e. (torrentHandler): Added deletion of te. (main): Do not share splitter. Use Deleter instead of clearRequest. Deletion of classes were updated.
2006-05-09 15:54:14 +00:00
std::string h3 = "attachment; filename=\"";
CPPUNIT_ASSERT_EQUAL(std::string(""), util::getContentDispositionFilename(h3));
2006-05-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Each peer message has its own class. * src/PendingMessages.h: Removed. * src/PendingMessages.cc: Removed. The sending process was moved to each message class. * src/RequestSlotMan.h: Removed. * src/RequestSlotMan.cc: Removed. All functionarities were moved to SendMessageQueue. * src/RequestMessage.h: New class. * src/RequestMessage.cc: New class. * src/CancelMessage.h: New class. * src/CancelMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/ChokeMessage.h: New class. * src/ChokeMessage.cc: New class. * src/KeepAliveMessage.h: New class. * src/KeepAliveMessage.cc: New class. * src/PortMessage.h: New class. * src/UnchokeMessage.h: New class. * src/UnchokeMessage.cc: New class. * src/PieceMessage.h: New class. * src/PieceMessage.cc: New class. * src/HaveMessage.h: New class. * src/HaveMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/NotInterestedMessage.h: New class. * src/NotInterestedMessage.cc: New class. * src/InterestedMessage.h: New class. * src/InterestedMessage.cc: New class. * src/HandshakeMessage.h (sendMessageQueue): New variable. (getSendMessageQueue): New function. (setSendMessageQueue): New function. * src/HandshakeMessage.cc: New class. * src/PeerConnection.h (receiveMessage): Changed return value and arguments. (receiveHandshake): Changed return value and arguments. * src/PeerConnection.cc (receiveMessage): Do not create message class here. (receiveHandshake): Do not create handshake class here. * src/PeerInteractionCommand.h (peerConnection): Removed. (piece): Removed. (syncPiece): Removed. (sendInterest): Removed. (sendMessages): Removed. (createRequestPendingMessage): Removed. (checkPieceHash): Removed. (erasePieceOnDisk): Removed. (getNewPieceAndSendInterest): Removed. (onGotNewPice): Removed. (onGotWrongPiece): Removed. * src/PeerInteractionCommand.cc (PeerInteractionCommand): Removed peerConnection, piece. (~PeerInteractionCommand): Removed peerConnection. (executeInternal): Use sendMessageQueue instead of peerConnection. (syncPiece): Moved to SendMessageQueue. (decideChoking): Removed PendingMessage. (receiveMessage): Use sendMessageQueue instead of peerConnection. The action after receiving peer message was moved to each message class. (onGotNewPice): Moved to SendMessageQueue. (onGotWrongPiece): Moved to SendMessageQueue. (getNewPieceAndSendInterest): Moved to SendMessageQueue. (sendInterest): Moved to SendMessageQueue. (createRequestPendingMessage): Removed. (sendMessages): Moved to SendMessageQueue. (onAbort): Use SendMessageQueue::abortPiece() (keepAlive): Use sendMessageQueue instead of peerConnection. (beforeSocketCheck): Use sendMessageQueue instead of peerConnection. (checkPieceHash): Moved to SendMessageQueue. (erasePieceOnDisk): Moved to SendMessageQueue. * src/PeerMessageUtil.h (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessageUtil.cc (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessage.h (id): Removed. (index): Removed. (begin): Removed. (length): Removed. (bitfield): Removed. (bitfieldLength): Removed. (block): Removed. (blockLength): Removed. (inProgress): New variable. (cuid): New variable. (peer): New variable. (sendMessageQueue): New variable. (logger): New variable. (setBitfield): Removed. (getBitfield): Removed. (setBlock): Removed. (getBlock): Removed. (getBitfieldLength): Removed. (getBlockLength): Removed. (isInProgress): New function. (toString): Made pure virtual. (check): New function. (send): New function. (receivedAction): New function. (getId): Made pure virtual. (setId): Removed. (getIndex): Removed. (setIndex): Removed. (getBegin): Removed. (setBegin): Removed. (getLength): Removed. (setLength): Removed. (getCuid): New function. (setCuid): New function. (getPeer): New function. (setPeer): New function. (getSendMessageQueue): New function. (setSendMessageQueue): New function. (ID): Removed. * src/PeerMessage.cc (setBitfield): Removed. (setBlock): Removed. (toString): Removed. * src/TorrentMan.h (getPieceLength): New function. (getPieceLength): New function. * src/SendMessageQueue.h (REQUEST_TIME_OUT): New definition. (RequestSlots): New definition. (MessageQueue): New definition. (requestSlotMan): Removed. (pendingMessages): Removed. (requestSlots): New variable. (messageQueue): New variable. (torrentMan): New variable. (peerConnection): New variable. (peer): New variable. (piece): New variable. (getNewPieceAndSendInterest): New function. (createPeerMessage): New function. (createHandshakeMessage): New function. (send): Made private. (setPeerMessageCommonProperty): New function. (deleteAllRequestSlot): New function. (deleteRequestMessageInQueue): New function. (cancelAllRequest): Made private. (cancelAllRequest): Made private. (countRequestSlot): Made private. (addPendingMessage): Removed. (deletePendingPieceMessage): Removed. (deletePendingRequestMessage): Removed. (addMessage): New function. (deletePieceMessageInQueue): New function. (deleteTimeoutRequestSlot): Changed argument. (deleteCompletedRequestSlot): Changed argument. (getCorrespoindingRequestSlot): Renamed to getCorrespondingRequestSlot. (getCorrespondingRequestSlot): New function. (countPendingMessage): Removed. (countMessageInQueue): New function. (getTorrentMan): New function. (getPeerConnection): New function. (hasDownloadPiece): New function. (getDownloadPiece): New function. (setDownloadPiece): New function. (syncPiece): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (abortPiece): New function. (sendHandshake): New function. (receiveMessage): New function. (receiveHandshake): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. * src/SendMessageQueue.cc (SendMessageQueue): Removed requestSlotMan. Instantiated peerConnection here. (~SendMessageQueue): Removed requestSlotMan. Added deletion of peerConnection and the contents of messageQueue. (send): Updated according to the change of messageQueue. (addPendingMessage): Renamed to addMessage. (addMessage): New function. (deletePendingPieceMessage): Renamed to deletePieceMessageInQueue. (deletePieceMessageInQueue): New function. (deletePendingRequestMessage): Renamed to deleteRequestMessageInQueue. (deleteRequestMessageInQueue): New function. (deleteRequestSlot): RequestSlotMan::deleteRequestSlot(...) was moved here. (deleteTimeoutRequestSlot): RequestSlotMan::deleteTimeoutRequestSlot (...) was moved here. (deleteAllRequestSlot): RequestSlotMan::deleteAllRequestSlot(...) was moved here. (deleteCompletedRequestSlot): RequestSlotMan::deleteCompletedRequestSlot(...) was moved here. (getCorrespondingRequestSlot): RequestSlotMan::getCorrespoindingRequestSlot(...) was moved here. And renamed to getCorrespondingRequestSlot, correcting a typo. (countPendingMessage): Renamed to countMessageInQueue. (countMessageInQueue): New function. (countRequestSlot): RequestSlotMan::countRequestSlot() was moved here. (receiveHandshake): New function. (createHandshakeMessage): New function. (receiveMessage): New function. (createPeerMessage): New function. (syncPiece): New function. (getNewPieceAndSendInterest): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (sendHandshake): New function. (abortPiece): New function. (getDownloadPiece): New function. (getPeerMessageCommonProperty): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. To add simple Content-Disposition support: * src/HttpResponseCommand.h (determinFilename): New function. * src/HttpResponseCommand.cc (executeInternal): Use determinFilename(headers) instead of req->getFile() when comparing filename. (determinFilename): New function. (handleDefaultEncoding): Use determinFilename(headers) instead of req->getFile(). (handleOtherEncoding): Use determinFilename(headers) instead of req->getFile(). * src/Util.h (getContentDispositionFilename): New function. * src/Util.cc (getContentDispositionFilename): New function. * src/LogFactory.h (release): New function. * src/LogFactory.cc (release): New function. To fix a bug that causes out-of-bound exception when HTTP status line is wrong: * src/HttpConnection.cc (receiveResponse): Added a check for header size. * src/common.h (Deleter): New class. * src/SegmentMan.cc (~SegmentMan): Added deletion of splitter and diskWriter. * src/DownloadEngine.h (Commands): Use deque. (clearQueue): New function. * src/DownloadEngine.cc (~DownloadEngine): Added deletion of segmentMan. (cleanQueue): New function. * src/TorrentDownloadEngine.h (TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. (~TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. * src/TorrentDownloadEngine.cc (~TorrentDownloadEngine): Added deletion of torrentMan. * src/main.cc (clearRequest): Removed. (handler): Added deletion of e. (torrentHandler): Added deletion of te. (main): Do not share splitter. Use Deleter instead of clearRequest. Deletion of classes were updated.
2006-05-09 15:54:14 +00:00
std::string h4 = "attachment;";
CPPUNIT_ASSERT_EQUAL(std::string(""), util::getContentDispositionFilename(h4));
std::string h5 = "attachment; filename=aria2.tar.bz2";
CPPUNIT_ASSERT_EQUAL(std::string("aria2.tar.bz2"), util::getContentDispositionFilename(h5));
std::string h6 = "attachment; filename='aria2.tar.bz2'";
CPPUNIT_ASSERT_EQUAL(std::string("aria2.tar.bz2"), util::getContentDispositionFilename(h6));
std::string h7 = "attachment; filename='aria2.tar.bz2";
CPPUNIT_ASSERT_EQUAL(std::string("aria2.tar.bz2"), util::getContentDispositionFilename(h7));
std::string h8 = "attachment; filename=aria2.tar.bz2; creation-date=20 Jun 2007 00:00:00 GMT";
CPPUNIT_ASSERT_EQUAL(std::string("aria2.tar.bz2"), util::getContentDispositionFilename(h8));
std::string h9 = "attachment; filename=\"aria2.tar.bz2; creation-date=20 Jun 2007 00:00:00 GMT\"";
CPPUNIT_ASSERT_EQUAL(std::string("aria2.tar.bz2; creation-date=20 Jun 2007 00:00:00 GMT"),
util::getContentDispositionFilename(h9));
std::string h10 = "attachment; filename=";
CPPUNIT_ASSERT_EQUAL(std::string(""), util::getContentDispositionFilename(h10));
std::string h11 = "attachment; filename=;";
CPPUNIT_ASSERT_EQUAL(std::string(""), util::getContentDispositionFilename(h11));
std::string filenameWithDir = "attachment; filename=dir/file";
CPPUNIT_ASSERT_EQUAL(std::string(""),
util::getContentDispositionFilename(filenameWithDir));
std::string semicolonInside = "attachment; filename=\"foo;bar\"";
CPPUNIT_ASSERT_EQUAL(std::string("foo;bar"),
util::getContentDispositionFilename(semicolonInside));
CPPUNIT_ASSERT_EQUAL
(std::string(""),
util::getContentDispositionFilename("filename=\"%2E%2E%2Ffoo.html\""));
// RFC2231 Section4
std::string extparam2 = "filename*=''aria2";
CPPUNIT_ASSERT_EQUAL(std::string("aria2"),
util::getContentDispositionFilename(extparam2));
std::string extparam3 = "filename*='''";
CPPUNIT_ASSERT_EQUAL(std::string(""),
util::getContentDispositionFilename(extparam3));
std::string extparam4 = "filename*='aria2";
CPPUNIT_ASSERT_EQUAL(std::string(""),
util::getContentDispositionFilename(extparam4));
std::string extparam5 = "filename*='''aria2";
CPPUNIT_ASSERT_EQUAL(std::string(""),
util::getContentDispositionFilename(extparam5));
std::string extparam6 = "filename*";
CPPUNIT_ASSERT_EQUAL(std::string(""),
util::getContentDispositionFilename(extparam6));
std::string extparam7 = "filename*=UTF-8''aria2;filename=hello%20world";
CPPUNIT_ASSERT_EQUAL(std::string("aria2"),
util::getContentDispositionFilename(extparam7));
std::string extparam8 = "filename=aria2;filename*=UTF-8''hello%20world";
CPPUNIT_ASSERT_EQUAL(std::string("hello world"),
util::getContentDispositionFilename(extparam8));
std::string extparam9 = "filename*=ISO-8859-1''%A3";
std::string extparam9ans;
extparam9ans += 0xc2;
extparam9ans += 0xa3;
CPPUNIT_ASSERT_EQUAL(extparam9ans,
util::getContentDispositionFilename(extparam9));
CPPUNIT_ASSERT_EQUAL
(std::string(""),
util::getContentDispositionFilename("filename*=UTF-8''foo%2F.html"));
CPPUNIT_ASSERT_EQUAL
(std::string("foo.html"),
util::getContentDispositionFilename("filename*=UTF-8'';filename=\"foo.html\""));
CPPUNIT_ASSERT_EQUAL
(std::string(""),
util::getContentDispositionFilename("filename*=UTF-8''%2E%2E%2Ffoo.html"));
// Tests from http://greenbytes.de/tech/tc2231/
// attwithasciifnescapedchar
CPPUNIT_ASSERT_EQUAL
(std::string("foo.html"),
util::getContentDispositionFilename("filename=\"f\\oo.html\""));
// attwithasciifilenameucase
CPPUNIT_ASSERT_EQUAL
(std::string("foo.html"),
util::getContentDispositionFilename("FILENAME=\"foo.html\""));
// attwithisofn2231iso
CPPUNIT_ASSERT_EQUAL
(std::string("foo-ä.html"),
util::getContentDispositionFilename("filename*=iso-8859-1''foo-%E4.html"));
// attwithfn2231utf8
CPPUNIT_ASSERT_EQUAL
(std::string("foo-ä-€.html"),
util::getContentDispositionFilename
("filename*=UTF-8''foo-%c3%a4-%e2%82%ac.html"));
// attwithfn2231utf8-bad
CPPUNIT_ASSERT_EQUAL
(std::string(""),
util::getContentDispositionFilename
("filename*=iso-8859-1''foo-%c3%a4-%e2%82%ac.html"));
// attwithfn2231ws1
CPPUNIT_ASSERT_EQUAL
(std::string(""),
util::getContentDispositionFilename("filename *=UTF-8''foo-%c3%a4.html"));
// attwithfn2231ws2
CPPUNIT_ASSERT_EQUAL
(std::string("foo-ä.html"),
util::getContentDispositionFilename("filename*= UTF-8''foo-%c3%a4.html"));
// attwithfn2231ws3
CPPUNIT_ASSERT_EQUAL
(std::string("foo-ä.html"),
util::getContentDispositionFilename("filename* =UTF-8''foo-%c3%a4.html"));
// attwithfn2231quot
CPPUNIT_ASSERT_EQUAL
(std::string(""),
util::getContentDispositionFilename
("filename*=\"UTF-8''foo-%c3%a4.html\""));
2006-05-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Each peer message has its own class. * src/PendingMessages.h: Removed. * src/PendingMessages.cc: Removed. The sending process was moved to each message class. * src/RequestSlotMan.h: Removed. * src/RequestSlotMan.cc: Removed. All functionarities were moved to SendMessageQueue. * src/RequestMessage.h: New class. * src/RequestMessage.cc: New class. * src/CancelMessage.h: New class. * src/CancelMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/ChokeMessage.h: New class. * src/ChokeMessage.cc: New class. * src/KeepAliveMessage.h: New class. * src/KeepAliveMessage.cc: New class. * src/PortMessage.h: New class. * src/UnchokeMessage.h: New class. * src/UnchokeMessage.cc: New class. * src/PieceMessage.h: New class. * src/PieceMessage.cc: New class. * src/HaveMessage.h: New class. * src/HaveMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/NotInterestedMessage.h: New class. * src/NotInterestedMessage.cc: New class. * src/InterestedMessage.h: New class. * src/InterestedMessage.cc: New class. * src/HandshakeMessage.h (sendMessageQueue): New variable. (getSendMessageQueue): New function. (setSendMessageQueue): New function. * src/HandshakeMessage.cc: New class. * src/PeerConnection.h (receiveMessage): Changed return value and arguments. (receiveHandshake): Changed return value and arguments. * src/PeerConnection.cc (receiveMessage): Do not create message class here. (receiveHandshake): Do not create handshake class here. * src/PeerInteractionCommand.h (peerConnection): Removed. (piece): Removed. (syncPiece): Removed. (sendInterest): Removed. (sendMessages): Removed. (createRequestPendingMessage): Removed. (checkPieceHash): Removed. (erasePieceOnDisk): Removed. (getNewPieceAndSendInterest): Removed. (onGotNewPice): Removed. (onGotWrongPiece): Removed. * src/PeerInteractionCommand.cc (PeerInteractionCommand): Removed peerConnection, piece. (~PeerInteractionCommand): Removed peerConnection. (executeInternal): Use sendMessageQueue instead of peerConnection. (syncPiece): Moved to SendMessageQueue. (decideChoking): Removed PendingMessage. (receiveMessage): Use sendMessageQueue instead of peerConnection. The action after receiving peer message was moved to each message class. (onGotNewPice): Moved to SendMessageQueue. (onGotWrongPiece): Moved to SendMessageQueue. (getNewPieceAndSendInterest): Moved to SendMessageQueue. (sendInterest): Moved to SendMessageQueue. (createRequestPendingMessage): Removed. (sendMessages): Moved to SendMessageQueue. (onAbort): Use SendMessageQueue::abortPiece() (keepAlive): Use sendMessageQueue instead of peerConnection. (beforeSocketCheck): Use sendMessageQueue instead of peerConnection. (checkPieceHash): Moved to SendMessageQueue. (erasePieceOnDisk): Moved to SendMessageQueue. * src/PeerMessageUtil.h (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessageUtil.cc (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessage.h (id): Removed. (index): Removed. (begin): Removed. (length): Removed. (bitfield): Removed. (bitfieldLength): Removed. (block): Removed. (blockLength): Removed. (inProgress): New variable. (cuid): New variable. (peer): New variable. (sendMessageQueue): New variable. (logger): New variable. (setBitfield): Removed. (getBitfield): Removed. (setBlock): Removed. (getBlock): Removed. (getBitfieldLength): Removed. (getBlockLength): Removed. (isInProgress): New function. (toString): Made pure virtual. (check): New function. (send): New function. (receivedAction): New function. (getId): Made pure virtual. (setId): Removed. (getIndex): Removed. (setIndex): Removed. (getBegin): Removed. (setBegin): Removed. (getLength): Removed. (setLength): Removed. (getCuid): New function. (setCuid): New function. (getPeer): New function. (setPeer): New function. (getSendMessageQueue): New function. (setSendMessageQueue): New function. (ID): Removed. * src/PeerMessage.cc (setBitfield): Removed. (setBlock): Removed. (toString): Removed. * src/TorrentMan.h (getPieceLength): New function. (getPieceLength): New function. * src/SendMessageQueue.h (REQUEST_TIME_OUT): New definition. (RequestSlots): New definition. (MessageQueue): New definition. (requestSlotMan): Removed. (pendingMessages): Removed. (requestSlots): New variable. (messageQueue): New variable. (torrentMan): New variable. (peerConnection): New variable. (peer): New variable. (piece): New variable. (getNewPieceAndSendInterest): New function. (createPeerMessage): New function. (createHandshakeMessage): New function. (send): Made private. (setPeerMessageCommonProperty): New function. (deleteAllRequestSlot): New function. (deleteRequestMessageInQueue): New function. (cancelAllRequest): Made private. (cancelAllRequest): Made private. (countRequestSlot): Made private. (addPendingMessage): Removed. (deletePendingPieceMessage): Removed. (deletePendingRequestMessage): Removed. (addMessage): New function. (deletePieceMessageInQueue): New function. (deleteTimeoutRequestSlot): Changed argument. (deleteCompletedRequestSlot): Changed argument. (getCorrespoindingRequestSlot): Renamed to getCorrespondingRequestSlot. (getCorrespondingRequestSlot): New function. (countPendingMessage): Removed. (countMessageInQueue): New function. (getTorrentMan): New function. (getPeerConnection): New function. (hasDownloadPiece): New function. (getDownloadPiece): New function. (setDownloadPiece): New function. (syncPiece): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (abortPiece): New function. (sendHandshake): New function. (receiveMessage): New function. (receiveHandshake): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. * src/SendMessageQueue.cc (SendMessageQueue): Removed requestSlotMan. Instantiated peerConnection here. (~SendMessageQueue): Removed requestSlotMan. Added deletion of peerConnection and the contents of messageQueue. (send): Updated according to the change of messageQueue. (addPendingMessage): Renamed to addMessage. (addMessage): New function. (deletePendingPieceMessage): Renamed to deletePieceMessageInQueue. (deletePieceMessageInQueue): New function. (deletePendingRequestMessage): Renamed to deleteRequestMessageInQueue. (deleteRequestMessageInQueue): New function. (deleteRequestSlot): RequestSlotMan::deleteRequestSlot(...) was moved here. (deleteTimeoutRequestSlot): RequestSlotMan::deleteTimeoutRequestSlot (...) was moved here. (deleteAllRequestSlot): RequestSlotMan::deleteAllRequestSlot(...) was moved here. (deleteCompletedRequestSlot): RequestSlotMan::deleteCompletedRequestSlot(...) was moved here. (getCorrespondingRequestSlot): RequestSlotMan::getCorrespoindingRequestSlot(...) was moved here. And renamed to getCorrespondingRequestSlot, correcting a typo. (countPendingMessage): Renamed to countMessageInQueue. (countMessageInQueue): New function. (countRequestSlot): RequestSlotMan::countRequestSlot() was moved here. (receiveHandshake): New function. (createHandshakeMessage): New function. (receiveMessage): New function. (createPeerMessage): New function. (syncPiece): New function. (getNewPieceAndSendInterest): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (sendHandshake): New function. (abortPiece): New function. (getDownloadPiece): New function. (getPeerMessageCommonProperty): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. To add simple Content-Disposition support: * src/HttpResponseCommand.h (determinFilename): New function. * src/HttpResponseCommand.cc (executeInternal): Use determinFilename(headers) instead of req->getFile() when comparing filename. (determinFilename): New function. (handleDefaultEncoding): Use determinFilename(headers) instead of req->getFile(). (handleOtherEncoding): Use determinFilename(headers) instead of req->getFile(). * src/Util.h (getContentDispositionFilename): New function. * src/Util.cc (getContentDispositionFilename): New function. * src/LogFactory.h (release): New function. * src/LogFactory.cc (release): New function. To fix a bug that causes out-of-bound exception when HTTP status line is wrong: * src/HttpConnection.cc (receiveResponse): Added a check for header size. * src/common.h (Deleter): New class. * src/SegmentMan.cc (~SegmentMan): Added deletion of splitter and diskWriter. * src/DownloadEngine.h (Commands): Use deque. (clearQueue): New function. * src/DownloadEngine.cc (~DownloadEngine): Added deletion of segmentMan. (cleanQueue): New function. * src/TorrentDownloadEngine.h (TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. (~TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. * src/TorrentDownloadEngine.cc (~TorrentDownloadEngine): Added deletion of torrentMan. * src/main.cc (clearRequest): Removed. (handler): Added deletion of e. (torrentHandler): Added deletion of te. (main): Do not share splitter. Use Deleter instead of clearRequest. Deletion of classes were updated.
2006-05-09 15:54:14 +00:00
}
2006-05-18 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To remove a wait from download loop: * src/DownloadEngine.cc (run): Comment out shortSleep. To rewrite the message handling: * src/CancelMessage.h: Derived from SimplePeerMessage. (msg): New variable. (create): New function. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/CancelMessage.cc (create): New function. (receivedAction): Replaced deleteRequestMessageInQueue with rejectPieceMessageInQueue. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/BitfieldMessage.h: Derived from SimplePeerMessage. (msg): New variable. (msgLength): New variable. (~BitfieldMessage): Deleted msg. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/BitfieldMessage.cc (create): New function. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/ChokeMessage.h: Derived from SimplePeerMessage. (msg): New variable. (sendPredicate): New function. (onSendComplete): New function. (send): Removed. (getMessage): New function. (getMessageLength): New function. (create): New function. * src/ChokeMessage.cc (create): New function. (send): Removed. (sendPredicate): New function. (getMessage): New function. (getMessageLength): New function. (onSendComplete): New function. * src/KeepAliveMessage.h: Derived from SimplePeerMessage. (msg): New variable. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/KeepAliveMessage.cc (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/PortMessage.h (create): New function. (receivedAction): Updated log message. * src/PortMessage.cc: New file. * src/UnchokeMessage.h: Derived from SimplePeerMessage. (msg): New variable. (sendPredicate): New function. (onSendComplete): New function. (create): New function. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/UnchokeMessage.cc (create): New function. (send): Removed. (sendPredicate): New function. (getMessage): New function. (getMessageLength): New function. (onSendComplete): New function. * src/PieceMessage.h (leftPieceDataLength): Removed. (leftDataLength): New variable. (headerSend): New variable. (pendingCount): New variable. (msgHeader): New variable. (sendPieceData): New function. (incrementPendingCount): New function. (isPendingCountMax): New function. (create): New function. (getMessageHeader): New function. (getMessageHeaderLength): New function. * src/PieceMessage.cc (create): New function. (getMessageHeader): New function. (getMessageHeaderLength): New function. (send): Rewritten. (sendPieceData): New function. * src/HaveMessage.h: Derived from SimplePeerMessage. (msg): New variable. (create): New function. (getMessage): New function. (getMessageLength): New function. * src/HaveMessage.cc (create): New function. (send): Removed. (sendPieceData): New function. (getMessage): New function. (getMessageLength): New function. * src/RequestMessage.h: Derived from SimplePeerMessage. (msg): New variable. (create): New function. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/RequestMessage.cc (create): New function. (receivedAction): Added the handling of fast extension. Deleted torrentMan->addUploadLength, torrentMan->addDeltaUploadLength. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/InterestedMessage.h: Derived from SimplePeerMessage. (msg): New variable. (sendPredicate): New function. (onSendComplete): New function. (create): New function. (getMessage): New function. (getMessageLength): New function. * src/InterestedMessage.cc (create): New function. (send): Removed. (sendPieceData): New function. (getMessage): New function. (getMessageLength): New function. (onSendComplete): New function. * src/NotInterestedMessage.h: Derived from SimplePeerMessage. (msg): New variable. (sendPieceData): New function. (onSendComplete): New function. (create): New function. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/NotInterestedMessage.cc (create): New function. (send): Removed. (sendPredicate): New function. (getMessage): New function. (getMessageLength): New function. (onSendComplete): New function. * src/AllowedFastMessage.h: New class. * src/AllowedFastMessage.cc: New class. * src/RejectMessage.h: New class. * src/RejectMessage.cc: New class. * src/SuggestPieceMessage.h: New class. * src/SuggestPieceMessage.cc: New class. * src/HaveAllMessage.h: New class. * src/HaveAllMessage.cc: New class. * src/HaveNoneMessage.h: New class. * src/HaveNoneMessage.cc: New class. * src/HandshakeMessage.h: Derived from SimplePeerMessage. (msg): New variable. (reserved): New variable. (create): New function. (getId): New function. (receivedAction): New function. (getMessage): New function. (getMessageLength): New function. (isFastExtensionSupported): New function. * src/HandshakeMessage.cc (HandshakeMessage): Moved here from HandshakeMessage.h. (create): New function. (getMessage): New function. (getMessageLength): New function. (toString): Added the output of reserved field. (check): Added const qualifier. (isFastExtensionSupported): New function. * src/PeerMessageUtil.h (createChokeMessage): Removed. (createUnchokeMessage): Removed. (createInterestedMessage): Removed. (createNotInterestedMessage): Removed. (createHaveMessage): Removed. (createBitfieldMessage): Removed. (createRequestMessage): Removed. (createCancelMessage): Removed. (createPieceMessage): Removed. (createPortMessage): Removed. (createChokeMessage): Removed. (createUnchokeMessage): Removed. (createInterestedMessage): Removed. (createNotInterestedMessage): Removed. (createHaveMessage): Removed. (createBitfieldMessage): Removed. (createRequestMessage): Removed. (createCancelMessage): Removed. (createPieceMessage): Removed. (createKeepAliveMessage): Removed. (createHandshakeMessage): Removed. (setIntParam): New function. (createPeerMessageString): New function. * src/PeerMessageUtil.cc (createChokeMessage): Removed. (createUnchokeMessage): Removed. (createInterestedMessage): Removed. (createNotInterestedMessage): Removed. (createHaveMessage): Removed. (createBitfieldMessage): Removed. (createRequestMessage): Removed. (createCancelMessage): Removed. (createPieceMessage): Removed. (createPortMessage): Removed. (createRequestMessage): Removed. (createCancelMessage): Removed. (createPieceMessage): Removed. (createHaveMessage): Removed. (createChokeMessage): Removed. (createUnchokeMessage): Removed. (createInterestedMessage): Removed. (createNotInterestedMessage): Removed. (createBitfieldMessage): Removed. (createKeepAliveMessage): Removed. (createHandshakeMessage): Removed. (setIntParam): New function. (createPeerMessageString): New function. * src/PeerConnection.h (peer): Removed. (torrentMan): Removed. (createNLengthMessage): Removed. (setIntParam): Removed. (writeOutgoingMessageLog): Removed all overloaded functions. (PeerConnection): Deleted peer and torrentMan from its arguments. (sendMessage): New function. (sendHandshake): Removed. (sendKeepAlive): Removed. (sendChoke): Removed. (sendUnchoke): Removed. (sendInterested): Removed. (sendNotInterested): Removed. (sendHave): Removed. (sendBitfield): Removed. (sendRequest): Removed. (sendPiece): Removed. (sendPieceHeader): Removed. (sendPieceData): Removed. (sendCancel): Removed. (getPeer): Removed. * src/PeerConnection.cc (PeerConnection): Deleted peer and torrentMan from its arguments. (sendHandshake): Removed. (sendKeepAlive): Removed. (createNLengthMessage): Removed. (setIntParam): Removed. (writeOutgoingMessageLog): Removed all overloaded functions. (sendChoke): Removed. (sendUnchoke): Removed. (sendInterested): Removed. (sendNotInterested): Removed. (sendHave): Removed. (sendBitfield): Removed. (sendRequest): Removed. (sendPiece): Removed. (sendPieceHeader): Removed. (sendPieceData): Removed. (sendMessage): New function. (sendCancel): Removed. * src/PeerInteractionCommand.cc (PeerInteractionCommand): Call setUploadLimit. (executeInternal): Call setUploadLimit. Added the handling of "inProgress" state of handshake message. Call sendBitfield() or sendAllowdFast() instead of deprecated sendNow(). (keepAlive): Call addMessage and sendMessage instead of deprecated sendNow(). (beforeSocketCheck): Call addMessage instead of deprecated trySendNow() * src/TorrentMan.h (PEER_ID_LENGTH): New definition. (hasAllPieces): New function. * src/TorrentMan.cc (getMissingPiece): Added the handling of fast extension. (cancelPiece): Call updatePiece(). (hasAllPieces): New function. * src/PeerInteraction.h (fastSet): New variable. (getNewPieceAndSendInterest): Changed the return type to void. (send): Renamed as sendMessages. (deleteAllRequestSlot): Removed. (deleteRequestMessageInQueue): Renamed as rejectPieceMessageInQueue. (cancelAllRequest): Removed all overloaded functions. (deleteAllRequestSlot): Removed. (deletePieceMessageInQueue): Renamed as rejectAllPieceMessageInQueue. (rejectPieceMessageInQueue): New function. (rejectAllPieceMessageInQueue): New function. (onChoked): New function. (isSendingMessageInProgress): New function. (getCorrespondingRequestSlot): Changed its arguments. (isInFastSet): New function. (addFastSetIndex): New function. (addRequests): New function. (sendNow): Removed. (trySendNow): Removed. (sendBitfield): New function. (sendAllowdFast): New function. (createHaveAllMessage): New function. (createHaveNoneMessage): New function. (createRejectMessage): New function. (createAllowedFastMessage): New function. * src/PeerInteraction.cc (send): Renamed as sendMessages. (sendMessages): New function. (MsgPushBack): New class. (isSendingMessageInProgress): New function. (deletePieceMessageInQueue): Renamed as rejectAllPieceMessageInQueue. (rejectAllPieceMessageInQueue): New function. Added the handling of fast extension. (deleteRequestMessageInQueue): Renamed as rejectPieceMessageInQueue. (rejectPieceMessageInQueue): New function. Added the handling of fast extension. (deleteRequestSlot): Replaced for loop with std::find. (onChoked): New function. (deleteAllRequestSlot): Removed. (abortPiece): Rewirtten. (deleteTimeoutRequestSlot): Updated log messages. (getCorrespondingRequestSlot): Changed its arguments. (cancelAllRequest): Removed all overloaded functions. (receiveHandshake): Added the check to see whether an incoming peer supports fast extension. (createHandshakeMessage): Use HandshakeMessage::create instead of PeerMessageUtil. (createPeerMessage): Use create() of each message class instead of PeerMessageUtil. HaveAllMessage, HaveNoneMessage, RejectMessage, SuggestPieceMessage, AllowedFastMessage were added. (getNewPieceAndSendInterest): Changed its return value type to void. Added the handling of fast extension. (addRequests): New function. (sendNow): Removed. (sendHandshake): Rewritten. (trySendNow): Removed. (sendBitfield): New function. (sendAllowdFast): New function. (isInFastSet): New function. (addFastSetIndex): New function. (createRequestMessage): Use RequestMessage::create instead of PeerMessageUtil. (createCancelMessage): Use CancelMessage::create instead of PeerMessageUtil. (createPieceMessage): Use PieceMessage::create instead of PeerMessageUtil. (createHaveMessage): Use HaveMessage::create instead of PeerMessageUtil. (createChokeMessage): Use ChokeMessage::create instead of PeerMessageUtil. (createUnchokeMessage): Use UnchokeMessage::create instead of PeerMessageUtil. (createInterestedMessage): Use InterestedMessage::create instead of PeerMessageUtil. (createNotInterestedMessage): Use NotInterestedMessage::create instead of PeerMessageUtil. (createBitfieldMessage): Use BitfieldMessage::create instead of PeerMessageUtil. (createKeepAliveMessage): Use KeepAliveMessage::create instead of PeerMessageUtil. (createHaveAllMessage): New function. (createHaveNoneMessage): New function. (createRejectMessage): New function. (createAllowedFastMessage: New function. * src/Util.h (sha1Sum): New function. (computeFastSet): New function. * src/Util.cc (sha1Sum): New function. (computeFastSet): New function. * src/Peer.h (fastExtensionEnabled): New variable. (fastSet): New variable. (setAllBitfield): New function. (setFastExtensionEnabled): New function. (isFastExtensionEnabled): New function. (addFastSetIndex): New function. (getFastSet): New function. (isInFastSet): New function. (countFastSet): New function. * src/Peer.cc (isInFastSet): New function. (addFastSetIndex): New function. (setAllBitfield): New function. * src/AbstractCommand.cc (execute): Changed the procedure of checking sockets. * src/PeerAbstractCommand.cc (PeerAbstractCommand): Added the initialization for uploadLimitCheck and uploadLimit. (execute): Changed the procedure of checking sockets. The upload speed checking were added. (setUploadLimit): New function. (setUploadLimitCheck): New function. * src/PeerAbstractCommand.h (setUploadLimit): New function. (setUploadLimitCheck): New function. (uploadLimit): New variable. (uploadLimitCheck): New variable. To contact a tracker regularly: * src/TrackerWatcherCommand.h (interval): New variable. (checkPoint): New variable. (TrackerWatcherCommand): Added interval argument. * src/TrackerWatcherCommand.cc (TrackerWatcherCommand): Initialized checkPoint. (execute): Now a tracker is contacted in every specified period. If peer list is not needed, send request with numwant=0. * src/TrackerUpdateCommand.cc (execute): Updated log messages. * src/DownloadEngine.cc (~DownloadEngine): Removed two asserts. (waitData): Uncommented wfds. May be a bug fix.
2006-05-18 17:08:29 +00:00
class Printer {
public:
template<class T>
void operator()(T t) {
std::cerr << t << ", ";
2006-05-18 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To remove a wait from download loop: * src/DownloadEngine.cc (run): Comment out shortSleep. To rewrite the message handling: * src/CancelMessage.h: Derived from SimplePeerMessage. (msg): New variable. (create): New function. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/CancelMessage.cc (create): New function. (receivedAction): Replaced deleteRequestMessageInQueue with rejectPieceMessageInQueue. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/BitfieldMessage.h: Derived from SimplePeerMessage. (msg): New variable. (msgLength): New variable. (~BitfieldMessage): Deleted msg. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/BitfieldMessage.cc (create): New function. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/ChokeMessage.h: Derived from SimplePeerMessage. (msg): New variable. (sendPredicate): New function. (onSendComplete): New function. (send): Removed. (getMessage): New function. (getMessageLength): New function. (create): New function. * src/ChokeMessage.cc (create): New function. (send): Removed. (sendPredicate): New function. (getMessage): New function. (getMessageLength): New function. (onSendComplete): New function. * src/KeepAliveMessage.h: Derived from SimplePeerMessage. (msg): New variable. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/KeepAliveMessage.cc (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/PortMessage.h (create): New function. (receivedAction): Updated log message. * src/PortMessage.cc: New file. * src/UnchokeMessage.h: Derived from SimplePeerMessage. (msg): New variable. (sendPredicate): New function. (onSendComplete): New function. (create): New function. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/UnchokeMessage.cc (create): New function. (send): Removed. (sendPredicate): New function. (getMessage): New function. (getMessageLength): New function. (onSendComplete): New function. * src/PieceMessage.h (leftPieceDataLength): Removed. (leftDataLength): New variable. (headerSend): New variable. (pendingCount): New variable. (msgHeader): New variable. (sendPieceData): New function. (incrementPendingCount): New function. (isPendingCountMax): New function. (create): New function. (getMessageHeader): New function. (getMessageHeaderLength): New function. * src/PieceMessage.cc (create): New function. (getMessageHeader): New function. (getMessageHeaderLength): New function. (send): Rewritten. (sendPieceData): New function. * src/HaveMessage.h: Derived from SimplePeerMessage. (msg): New variable. (create): New function. (getMessage): New function. (getMessageLength): New function. * src/HaveMessage.cc (create): New function. (send): Removed. (sendPieceData): New function. (getMessage): New function. (getMessageLength): New function. * src/RequestMessage.h: Derived from SimplePeerMessage. (msg): New variable. (create): New function. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/RequestMessage.cc (create): New function. (receivedAction): Added the handling of fast extension. Deleted torrentMan->addUploadLength, torrentMan->addDeltaUploadLength. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/InterestedMessage.h: Derived from SimplePeerMessage. (msg): New variable. (sendPredicate): New function. (onSendComplete): New function. (create): New function. (getMessage): New function. (getMessageLength): New function. * src/InterestedMessage.cc (create): New function. (send): Removed. (sendPieceData): New function. (getMessage): New function. (getMessageLength): New function. (onSendComplete): New function. * src/NotInterestedMessage.h: Derived from SimplePeerMessage. (msg): New variable. (sendPieceData): New function. (onSendComplete): New function. (create): New function. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/NotInterestedMessage.cc (create): New function. (send): Removed. (sendPredicate): New function. (getMessage): New function. (getMessageLength): New function. (onSendComplete): New function. * src/AllowedFastMessage.h: New class. * src/AllowedFastMessage.cc: New class. * src/RejectMessage.h: New class. * src/RejectMessage.cc: New class. * src/SuggestPieceMessage.h: New class. * src/SuggestPieceMessage.cc: New class. * src/HaveAllMessage.h: New class. * src/HaveAllMessage.cc: New class. * src/HaveNoneMessage.h: New class. * src/HaveNoneMessage.cc: New class. * src/HandshakeMessage.h: Derived from SimplePeerMessage. (msg): New variable. (reserved): New variable. (create): New function. (getId): New function. (receivedAction): New function. (getMessage): New function. (getMessageLength): New function. (isFastExtensionSupported): New function. * src/HandshakeMessage.cc (HandshakeMessage): Moved here from HandshakeMessage.h. (create): New function. (getMessage): New function. (getMessageLength): New function. (toString): Added the output of reserved field. (check): Added const qualifier. (isFastExtensionSupported): New function. * src/PeerMessageUtil.h (createChokeMessage): Removed. (createUnchokeMessage): Removed. (createInterestedMessage): Removed. (createNotInterestedMessage): Removed. (createHaveMessage): Removed. (createBitfieldMessage): Removed. (createRequestMessage): Removed. (createCancelMessage): Removed. (createPieceMessage): Removed. (createPortMessage): Removed. (createChokeMessage): Removed. (createUnchokeMessage): Removed. (createInterestedMessage): Removed. (createNotInterestedMessage): Removed. (createHaveMessage): Removed. (createBitfieldMessage): Removed. (createRequestMessage): Removed. (createCancelMessage): Removed. (createPieceMessage): Removed. (createKeepAliveMessage): Removed. (createHandshakeMessage): Removed. (setIntParam): New function. (createPeerMessageString): New function. * src/PeerMessageUtil.cc (createChokeMessage): Removed. (createUnchokeMessage): Removed. (createInterestedMessage): Removed. (createNotInterestedMessage): Removed. (createHaveMessage): Removed. (createBitfieldMessage): Removed. (createRequestMessage): Removed. (createCancelMessage): Removed. (createPieceMessage): Removed. (createPortMessage): Removed. (createRequestMessage): Removed. (createCancelMessage): Removed. (createPieceMessage): Removed. (createHaveMessage): Removed. (createChokeMessage): Removed. (createUnchokeMessage): Removed. (createInterestedMessage): Removed. (createNotInterestedMessage): Removed. (createBitfieldMessage): Removed. (createKeepAliveMessage): Removed. (createHandshakeMessage): Removed. (setIntParam): New function. (createPeerMessageString): New function. * src/PeerConnection.h (peer): Removed. (torrentMan): Removed. (createNLengthMessage): Removed. (setIntParam): Removed. (writeOutgoingMessageLog): Removed all overloaded functions. (PeerConnection): Deleted peer and torrentMan from its arguments. (sendMessage): New function. (sendHandshake): Removed. (sendKeepAlive): Removed. (sendChoke): Removed. (sendUnchoke): Removed. (sendInterested): Removed. (sendNotInterested): Removed. (sendHave): Removed. (sendBitfield): Removed. (sendRequest): Removed. (sendPiece): Removed. (sendPieceHeader): Removed. (sendPieceData): Removed. (sendCancel): Removed. (getPeer): Removed. * src/PeerConnection.cc (PeerConnection): Deleted peer and torrentMan from its arguments. (sendHandshake): Removed. (sendKeepAlive): Removed. (createNLengthMessage): Removed. (setIntParam): Removed. (writeOutgoingMessageLog): Removed all overloaded functions. (sendChoke): Removed. (sendUnchoke): Removed. (sendInterested): Removed. (sendNotInterested): Removed. (sendHave): Removed. (sendBitfield): Removed. (sendRequest): Removed. (sendPiece): Removed. (sendPieceHeader): Removed. (sendPieceData): Removed. (sendMessage): New function. (sendCancel): Removed. * src/PeerInteractionCommand.cc (PeerInteractionCommand): Call setUploadLimit. (executeInternal): Call setUploadLimit. Added the handling of "inProgress" state of handshake message. Call sendBitfield() or sendAllowdFast() instead of deprecated sendNow(). (keepAlive): Call addMessage and sendMessage instead of deprecated sendNow(). (beforeSocketCheck): Call addMessage instead of deprecated trySendNow() * src/TorrentMan.h (PEER_ID_LENGTH): New definition. (hasAllPieces): New function. * src/TorrentMan.cc (getMissingPiece): Added the handling of fast extension. (cancelPiece): Call updatePiece(). (hasAllPieces): New function. * src/PeerInteraction.h (fastSet): New variable. (getNewPieceAndSendInterest): Changed the return type to void. (send): Renamed as sendMessages. (deleteAllRequestSlot): Removed. (deleteRequestMessageInQueue): Renamed as rejectPieceMessageInQueue. (cancelAllRequest): Removed all overloaded functions. (deleteAllRequestSlot): Removed. (deletePieceMessageInQueue): Renamed as rejectAllPieceMessageInQueue. (rejectPieceMessageInQueue): New function. (rejectAllPieceMessageInQueue): New function. (onChoked): New function. (isSendingMessageInProgress): New function. (getCorrespondingRequestSlot): Changed its arguments. (isInFastSet): New function. (addFastSetIndex): New function. (addRequests): New function. (sendNow): Removed. (trySendNow): Removed. (sendBitfield): New function. (sendAllowdFast): New function. (createHaveAllMessage): New function. (createHaveNoneMessage): New function. (createRejectMessage): New function. (createAllowedFastMessage): New function. * src/PeerInteraction.cc (send): Renamed as sendMessages. (sendMessages): New function. (MsgPushBack): New class. (isSendingMessageInProgress): New function. (deletePieceMessageInQueue): Renamed as rejectAllPieceMessageInQueue. (rejectAllPieceMessageInQueue): New function. Added the handling of fast extension. (deleteRequestMessageInQueue): Renamed as rejectPieceMessageInQueue. (rejectPieceMessageInQueue): New function. Added the handling of fast extension. (deleteRequestSlot): Replaced for loop with std::find. (onChoked): New function. (deleteAllRequestSlot): Removed. (abortPiece): Rewirtten. (deleteTimeoutRequestSlot): Updated log messages. (getCorrespondingRequestSlot): Changed its arguments. (cancelAllRequest): Removed all overloaded functions. (receiveHandshake): Added the check to see whether an incoming peer supports fast extension. (createHandshakeMessage): Use HandshakeMessage::create instead of PeerMessageUtil. (createPeerMessage): Use create() of each message class instead of PeerMessageUtil. HaveAllMessage, HaveNoneMessage, RejectMessage, SuggestPieceMessage, AllowedFastMessage were added. (getNewPieceAndSendInterest): Changed its return value type to void. Added the handling of fast extension. (addRequests): New function. (sendNow): Removed. (sendHandshake): Rewritten. (trySendNow): Removed. (sendBitfield): New function. (sendAllowdFast): New function. (isInFastSet): New function. (addFastSetIndex): New function. (createRequestMessage): Use RequestMessage::create instead of PeerMessageUtil. (createCancelMessage): Use CancelMessage::create instead of PeerMessageUtil. (createPieceMessage): Use PieceMessage::create instead of PeerMessageUtil. (createHaveMessage): Use HaveMessage::create instead of PeerMessageUtil. (createChokeMessage): Use ChokeMessage::create instead of PeerMessageUtil. (createUnchokeMessage): Use UnchokeMessage::create instead of PeerMessageUtil. (createInterestedMessage): Use InterestedMessage::create instead of PeerMessageUtil. (createNotInterestedMessage): Use NotInterestedMessage::create instead of PeerMessageUtil. (createBitfieldMessage): Use BitfieldMessage::create instead of PeerMessageUtil. (createKeepAliveMessage): Use KeepAliveMessage::create instead of PeerMessageUtil. (createHaveAllMessage): New function. (createHaveNoneMessage): New function. (createRejectMessage): New function. (createAllowedFastMessage: New function. * src/Util.h (sha1Sum): New function. (computeFastSet): New function. * src/Util.cc (sha1Sum): New function. (computeFastSet): New function. * src/Peer.h (fastExtensionEnabled): New variable. (fastSet): New variable. (setAllBitfield): New function. (setFastExtensionEnabled): New function. (isFastExtensionEnabled): New function. (addFastSetIndex): New function. (getFastSet): New function. (isInFastSet): New function. (countFastSet): New function. * src/Peer.cc (isInFastSet): New function. (addFastSetIndex): New function. (setAllBitfield): New function. * src/AbstractCommand.cc (execute): Changed the procedure of checking sockets. * src/PeerAbstractCommand.cc (PeerAbstractCommand): Added the initialization for uploadLimitCheck and uploadLimit. (execute): Changed the procedure of checking sockets. The upload speed checking were added. (setUploadLimit): New function. (setUploadLimitCheck): New function. * src/PeerAbstractCommand.h (setUploadLimit): New function. (setUploadLimitCheck): New function. (uploadLimit): New variable. (uploadLimitCheck): New variable. To contact a tracker regularly: * src/TrackerWatcherCommand.h (interval): New variable. (checkPoint): New variable. (TrackerWatcherCommand): Added interval argument. * src/TrackerWatcherCommand.cc (TrackerWatcherCommand): Initialized checkPoint. (execute): Now a tracker is contacted in every specified period. If peer list is not needed, send request with numwant=0. * src/TrackerUpdateCommand.cc (execute): Updated log messages. * src/DownloadEngine.cc (~DownloadEngine): Removed two asserts. (waitData): Uncommented wfds. May be a bug fix.
2006-05-18 17:08:29 +00:00
}
};
2006-06-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To make a listening socket non-block: * src/SocketCore.h (setNonBlockingMode): New function. * src/SocketCore.cc (setNonBlockingMode): New function. (beginListen): Added a call to setNonBlockingMode(). (acceptConnection): Call setNonBlockingMode(). (setBlockingMode): Updated. To handle tracker's NAT-checking: * src/PeerConnection.cc (receiveHandshake): 'msg' param is filled with received data and its length is assigned to 'length' param, even if all handshake message is not yet received. * src/PeerInteractionCommand.cc (executeInternal): Use peerInteraction->receiveHandshake(true) when a new peer connects to localhost. A call to peerInteraction->sendHandshake() was removed because it is called from peerInteraction->receiveHandshake(true). * src/PeerInteraction.h (quickReplied): New variable. (receiveHandshake): Added an argument. * src/PeerInteraction.cc (PeerInteraction): Added the initialization of quickReplied. (receiveHandshake): Send handshake message as soon as the info hash in a handshake message from a peer is correct. To change the random part of peer id and key parameter: * src/TorrentMan.h (key): New variable. * src/TorrentMan.cc (setupInternal1): Use Util::randomAlpha() to generate random part of peer id, which is now "-aria2-"+13 alphabet characters([A-Za-z]). key is also generated by Util::randomAlpha() and it is now 8 character long. * src/Util.h (randomAlpha): New function. * src/Util.cc (randomAlpha): New function. * src/TrackerWatcherCommand.cc (execute): In a tracker request: Use torrentMan->key as key parameter. Added no_peer_id=1. Set snubbing flag to false when a choke message is received from a snubbed peer. * src/ChokeMessage.cc (receivedAction): Set snubbing flag to false.
2006-06-22 15:26:18 +00:00
void UtilTest::testRandomAlpha() {
SharedHandle<Randomizer> rand(new FixedNumberRandomizer());
std::string s = util::randomAlpha(8, rand);
CPPUNIT_ASSERT_EQUAL(std::string("AAAAAAAA"), s);
2006-06-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To make a listening socket non-block: * src/SocketCore.h (setNonBlockingMode): New function. * src/SocketCore.cc (setNonBlockingMode): New function. (beginListen): Added a call to setNonBlockingMode(). (acceptConnection): Call setNonBlockingMode(). (setBlockingMode): Updated. To handle tracker's NAT-checking: * src/PeerConnection.cc (receiveHandshake): 'msg' param is filled with received data and its length is assigned to 'length' param, even if all handshake message is not yet received. * src/PeerInteractionCommand.cc (executeInternal): Use peerInteraction->receiveHandshake(true) when a new peer connects to localhost. A call to peerInteraction->sendHandshake() was removed because it is called from peerInteraction->receiveHandshake(true). * src/PeerInteraction.h (quickReplied): New variable. (receiveHandshake): Added an argument. * src/PeerInteraction.cc (PeerInteraction): Added the initialization of quickReplied. (receiveHandshake): Send handshake message as soon as the info hash in a handshake message from a peer is correct. To change the random part of peer id and key parameter: * src/TorrentMan.h (key): New variable. * src/TorrentMan.cc (setupInternal1): Use Util::randomAlpha() to generate random part of peer id, which is now "-aria2-"+13 alphabet characters([A-Za-z]). key is also generated by Util::randomAlpha() and it is now 8 character long. * src/Util.h (randomAlpha): New function. * src/Util.cc (randomAlpha): New function. * src/TrackerWatcherCommand.cc (execute): In a tracker request: Use torrentMan->key as key parameter. Added no_peer_id=1. Set snubbing flag to false when a choke message is received from a snubbed peer. * src/ChokeMessage.cc (receivedAction): Set snubbing flag to false.
2006-06-22 15:26:18 +00:00
}
2006-07-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To add Metalink support(http/ftp only): * src/AbstractCommand.h (tryReserved): New function. * src/AbstractCommand.cc (execute): Call tryReserved(). (tryReserved): New function. * src/Request.h (Requests): New type definition. * src/SegmentMan.h (reserved): New variable. * src/Util.h (fileChecksum): New function. (toUpper): New function. (toLower): New function. * src/Util.cc (messageDigest.h): Included. (trim): Trim \r\n\t. (fileChecksum): New function. (toUpper): New function. (toLower): New function. * src/main.cc (normalDownload): New function. (main): Added 2 command-line options: metalink-file, metalink-connection. Their usage has not been written yet. * src/MetalinkProcessor.h: New class. * src/Xml2MetalinkProcessor.h: New class. * src/Xml2MetalinkProcessor.cc: New class. * src/MetalinkEntry.h: New class. * src/MetalinkEntry.cc: New class. * src/MetalinkResource.h: New class. * src/MetalinkResource.cc: New class. To add md5 message digest checking: * src/messageDigest.h: Rewritten. * src/MultiDiskWriter.cc: Updated according to the changes in messageDigest.h. * src/ShaVisitor.cc: Updated according to the changes in messageDigest.h. * src/Util.cc: Updated according to the changes in messageDigest.h. * src/AbstractDiskWriter.cc: Updated according to the changes in messageDigest.h. To fix a bug that causes segfault when the payload length in peer message is less than 0: * src/PeerConnection.cc: (receiveMessage): Fixed the bug. * src/PeerMessageUtil.cc (checkLength): Throw an exception if length is less than or equals to 0. To add new interfaces to Base64 encoding/decoding: * src/Base64.h (part_encode): Changed the method signature. (encode): New function(overload). (decode): New function(overload). * src/Base64.cc (part_encode): Rewritten. (encode): Rewritten. (encode): New function(overload). To prevent a peer to download same piece if there is an error in checksum: * src/PieceMessage.cc (receivedAction): Call peerInteraction->abortPiece().
2006-07-03 14:19:23 +00:00
void UtilTest::testToUpper() {
std::string src = "608cabc0f2fa18c260cafd974516865c772363d5";
std::string upp = "608CABC0F2FA18C260CAFD974516865C772363D5";
2006-07-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To add Metalink support(http/ftp only): * src/AbstractCommand.h (tryReserved): New function. * src/AbstractCommand.cc (execute): Call tryReserved(). (tryReserved): New function. * src/Request.h (Requests): New type definition. * src/SegmentMan.h (reserved): New variable. * src/Util.h (fileChecksum): New function. (toUpper): New function. (toLower): New function. * src/Util.cc (messageDigest.h): Included. (trim): Trim \r\n\t. (fileChecksum): New function. (toUpper): New function. (toLower): New function. * src/main.cc (normalDownload): New function. (main): Added 2 command-line options: metalink-file, metalink-connection. Their usage has not been written yet. * src/MetalinkProcessor.h: New class. * src/Xml2MetalinkProcessor.h: New class. * src/Xml2MetalinkProcessor.cc: New class. * src/MetalinkEntry.h: New class. * src/MetalinkEntry.cc: New class. * src/MetalinkResource.h: New class. * src/MetalinkResource.cc: New class. To add md5 message digest checking: * src/messageDigest.h: Rewritten. * src/MultiDiskWriter.cc: Updated according to the changes in messageDigest.h. * src/ShaVisitor.cc: Updated according to the changes in messageDigest.h. * src/Util.cc: Updated according to the changes in messageDigest.h. * src/AbstractDiskWriter.cc: Updated according to the changes in messageDigest.h. To fix a bug that causes segfault when the payload length in peer message is less than 0: * src/PeerConnection.cc: (receiveMessage): Fixed the bug. * src/PeerMessageUtil.cc (checkLength): Throw an exception if length is less than or equals to 0. To add new interfaces to Base64 encoding/decoding: * src/Base64.h (part_encode): Changed the method signature. (encode): New function(overload). (decode): New function(overload). * src/Base64.cc (part_encode): Rewritten. (encode): Rewritten. (encode): New function(overload). To prevent a peer to download same piece if there is an error in checksum: * src/PieceMessage.cc (receivedAction): Call peerInteraction->abortPiece().
2006-07-03 14:19:23 +00:00
CPPUNIT_ASSERT_EQUAL(upp, util::toUpper(src));
2006-07-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To add Metalink support(http/ftp only): * src/AbstractCommand.h (tryReserved): New function. * src/AbstractCommand.cc (execute): Call tryReserved(). (tryReserved): New function. * src/Request.h (Requests): New type definition. * src/SegmentMan.h (reserved): New variable. * src/Util.h (fileChecksum): New function. (toUpper): New function. (toLower): New function. * src/Util.cc (messageDigest.h): Included. (trim): Trim \r\n\t. (fileChecksum): New function. (toUpper): New function. (toLower): New function. * src/main.cc (normalDownload): New function. (main): Added 2 command-line options: metalink-file, metalink-connection. Their usage has not been written yet. * src/MetalinkProcessor.h: New class. * src/Xml2MetalinkProcessor.h: New class. * src/Xml2MetalinkProcessor.cc: New class. * src/MetalinkEntry.h: New class. * src/MetalinkEntry.cc: New class. * src/MetalinkResource.h: New class. * src/MetalinkResource.cc: New class. To add md5 message digest checking: * src/messageDigest.h: Rewritten. * src/MultiDiskWriter.cc: Updated according to the changes in messageDigest.h. * src/ShaVisitor.cc: Updated according to the changes in messageDigest.h. * src/Util.cc: Updated according to the changes in messageDigest.h. * src/AbstractDiskWriter.cc: Updated according to the changes in messageDigest.h. To fix a bug that causes segfault when the payload length in peer message is less than 0: * src/PeerConnection.cc: (receiveMessage): Fixed the bug. * src/PeerMessageUtil.cc (checkLength): Throw an exception if length is less than or equals to 0. To add new interfaces to Base64 encoding/decoding: * src/Base64.h (part_encode): Changed the method signature. (encode): New function(overload). (decode): New function(overload). * src/Base64.cc (part_encode): Rewritten. (encode): Rewritten. (encode): New function(overload). To prevent a peer to download same piece if there is an error in checksum: * src/PieceMessage.cc (receivedAction): Call peerInteraction->abortPiece().
2006-07-03 14:19:23 +00:00
}
void UtilTest::testToLower() {
std::string src = "608CABC0F2FA18C260CAFD974516865C772363D5";
std::string upp = "608cabc0f2fa18c260cafd974516865c772363d5";
2006-07-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To add Metalink support(http/ftp only): * src/AbstractCommand.h (tryReserved): New function. * src/AbstractCommand.cc (execute): Call tryReserved(). (tryReserved): New function. * src/Request.h (Requests): New type definition. * src/SegmentMan.h (reserved): New variable. * src/Util.h (fileChecksum): New function. (toUpper): New function. (toLower): New function. * src/Util.cc (messageDigest.h): Included. (trim): Trim \r\n\t. (fileChecksum): New function. (toUpper): New function. (toLower): New function. * src/main.cc (normalDownload): New function. (main): Added 2 command-line options: metalink-file, metalink-connection. Their usage has not been written yet. * src/MetalinkProcessor.h: New class. * src/Xml2MetalinkProcessor.h: New class. * src/Xml2MetalinkProcessor.cc: New class. * src/MetalinkEntry.h: New class. * src/MetalinkEntry.cc: New class. * src/MetalinkResource.h: New class. * src/MetalinkResource.cc: New class. To add md5 message digest checking: * src/messageDigest.h: Rewritten. * src/MultiDiskWriter.cc: Updated according to the changes in messageDigest.h. * src/ShaVisitor.cc: Updated according to the changes in messageDigest.h. * src/Util.cc: Updated according to the changes in messageDigest.h. * src/AbstractDiskWriter.cc: Updated according to the changes in messageDigest.h. To fix a bug that causes segfault when the payload length in peer message is less than 0: * src/PeerConnection.cc: (receiveMessage): Fixed the bug. * src/PeerMessageUtil.cc (checkLength): Throw an exception if length is less than or equals to 0. To add new interfaces to Base64 encoding/decoding: * src/Base64.h (part_encode): Changed the method signature. (encode): New function(overload). (decode): New function(overload). * src/Base64.cc (part_encode): Rewritten. (encode): Rewritten. (encode): New function(overload). To prevent a peer to download same piece if there is an error in checksum: * src/PieceMessage.cc (receivedAction): Call peerInteraction->abortPiece().
2006-07-03 14:19:23 +00:00
CPPUNIT_ASSERT_EQUAL(upp, util::toLower(src));
2006-07-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To add Metalink support(http/ftp only): * src/AbstractCommand.h (tryReserved): New function. * src/AbstractCommand.cc (execute): Call tryReserved(). (tryReserved): New function. * src/Request.h (Requests): New type definition. * src/SegmentMan.h (reserved): New variable. * src/Util.h (fileChecksum): New function. (toUpper): New function. (toLower): New function. * src/Util.cc (messageDigest.h): Included. (trim): Trim \r\n\t. (fileChecksum): New function. (toUpper): New function. (toLower): New function. * src/main.cc (normalDownload): New function. (main): Added 2 command-line options: metalink-file, metalink-connection. Their usage has not been written yet. * src/MetalinkProcessor.h: New class. * src/Xml2MetalinkProcessor.h: New class. * src/Xml2MetalinkProcessor.cc: New class. * src/MetalinkEntry.h: New class. * src/MetalinkEntry.cc: New class. * src/MetalinkResource.h: New class. * src/MetalinkResource.cc: New class. To add md5 message digest checking: * src/messageDigest.h: Rewritten. * src/MultiDiskWriter.cc: Updated according to the changes in messageDigest.h. * src/ShaVisitor.cc: Updated according to the changes in messageDigest.h. * src/Util.cc: Updated according to the changes in messageDigest.h. * src/AbstractDiskWriter.cc: Updated according to the changes in messageDigest.h. To fix a bug that causes segfault when the payload length in peer message is less than 0: * src/PeerConnection.cc: (receiveMessage): Fixed the bug. * src/PeerMessageUtil.cc (checkLength): Throw an exception if length is less than or equals to 0. To add new interfaces to Base64 encoding/decoding: * src/Base64.h (part_encode): Changed the method signature. (encode): New function(overload). (decode): New function(overload). * src/Base64.cc (part_encode): Rewritten. (encode): Rewritten. (encode): New function(overload). To prevent a peer to download same piece if there is an error in checksum: * src/PieceMessage.cc (receivedAction): Call peerInteraction->abortPiece().
2006-07-03 14:19:23 +00:00
}
void UtilTest::testUppercase() {
std::string src = "608cabc0f2fa18c260cafd974516865c772363d5";
std::string ans = "608CABC0F2FA18C260CAFD974516865C772363D5";
util::uppercase(src);
CPPUNIT_ASSERT_EQUAL(ans, src);
}
void UtilTest::testLowercase() {
std::string src = "608CABC0F2FA18C260CAFD974516865C772363D5";
std::string ans = "608cabc0f2fa18c260cafd974516865c772363d5";
util::lowercase(src);
CPPUNIT_ASSERT_EQUAL(ans, src);
}
void UtilTest::testPercentDecode() {
std::string src = "http://aria2.sourceforge.net/aria2%200.7.0%20docs.html";
CPPUNIT_ASSERT_EQUAL(std::string("http://aria2.sourceforge.net/aria2 0.7.0 docs.html"),
util::percentDecode(src));
std::string src2 = "aria2+aria2";
CPPUNIT_ASSERT_EQUAL(std::string("aria2+aria2"), util::percentDecode(src2));
std::string src3 = "%5t%20";
CPPUNIT_ASSERT_EQUAL(std::string("%5t "), util::percentDecode(src3));
std::string src4 = "%";
CPPUNIT_ASSERT_EQUAL(std::string("%"), util::percentDecode(src4));
std::string src5 = "%3";
CPPUNIT_ASSERT_EQUAL(std::string("%3"), util::percentDecode(src5));
std::string src6 = "%2f";
CPPUNIT_ASSERT_EQUAL(std::string("/"), util::percentDecode(src6));
}
2007-01-28 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> * src/Xml2MetalinkProcessor.h (xpathExists): New function. * src/Xml2MetalinkProcessor.cc (xpathExists): New function. Not to send HEAD request if filename and size are available in Metalink file: * src/UrlRequestInfo.h (filename): New variable. (totalLength): New variable. (setTotalLength): New function. (setFilename): New function. * src/MetalinkRequestInfo.cc (execute): Set filename and size to UrlRequestInfo. * src/MetalinkEntry.cc (MetalinkEntry): Initialize size with 0. * src/UrlRequestInfo.cc (execute): Set filename and size to SegmentMan. Not to download rest of the files after selected files are downloaded in BitTorrent: * src/PieceStorage.h (allDownloadFinished): New function. * src/DefaultBtAnnounce.cc (isCompleteAnnounceReady): Use allDownloadFinished instead of downloadFinished. (getAnnounceUrl): Use allDownloadFinished instead of downloadFinished. * src/DefaultPieceStorage.cc (completePiece): Use allDownloadFinished instead of downloadFinished. Commented out the call to finishSelectiveDownloadingMode(). (downloadFinished): Call isFilteredAllBitSet() instead of isAllBitSet(). (allDownloadFinished): New function. * src/DefaultBtInteractive.cc (addBitfieldMessageToQueue): Call allDownloadFinished() instead of downloadFinished(). (checkHave): Call allDownloadFinished() instead of downloadFinished(). * src/TorrentDownloadEngine.cc (onEndOfRun): Call allDownloadFinished() instead of downloadFinished(). * src/BitfieldMan.h (isFilteredAllBitSet): New function. * src/ShareRatioSeedCriteria.h (PieceStorage.h): New include. (pieceStorage): New variable. (evaluate): btContext->getTotalLength() -> pieceStorage->getCompletedLength() * src/BitfieldMan.cc (isFilteredAllBitSet): New function. (isAllBitSet): Filter is not took into account. Rename --force-truncate as --allow-overwrite: * src/TorrentRequestInfo.cc (execute): PREF_FORCE_TRUNCATE -> PREF_ALLOW_OVERWRITE * src/main.cc (showUsage): --force-truncate -> --allow-overwrite * src/message.h (EX_FILE_ALREADY_EXISTS): --force-truncate -> --allow-overwrite * src/prefs.h (PREF_FORCE_TRUNCATE): Removed. (PREF_ALLOW_OVERWRITE): New definition. * src/SegmentMan.cc (shouldCancelDownloadForSafety): --force-truncate -> --allow-overwrite * src/MetalinkRequestInfo.cc (execute): Queueing message are now logged in info level. * src/common.h (LONG_LONG_MAX): Removed. (LONG_LONG_MIN): Removed. * src/HttpResponseCommand.cc (handleDefaultEncoding): LONG_LONG_MAX -> INT64_MAX * src/FtpNegotiateCommand.cc (recvSize): LONG_LONG_MAX -> INT64_MAX * src/main.cc (showUsage): Added --check-integiry and --realtime-chunk-checksum command-line option. (main): Added --check-integiry and --realtime-chunk-checksum command-line option. --force-truncate -> --allow-overwrite Set initial value of --check-integrity option to false. Don't show usage when error occurs while persing command-line options. Removed deprecated --upload-limit option.
2007-01-28 14:18:35 +00:00
void UtilTest::testGetRealSize()
{
CPPUNIT_ASSERT_EQUAL((int64_t)4294967296LL, util::getRealSize("4096M"));
CPPUNIT_ASSERT_EQUAL((int64_t)1024, util::getRealSize("1K"));
try {
util::getRealSize("");
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
}
try {
util::getRealSize("foo");
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
}
try {
util::getRealSize("-1");
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
}
try {
util::getRealSize("9223372036854775807K");
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
}
try {
util::getRealSize("9223372036854775807M");
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
}
}
void UtilTest::testAbbrevSize()
{
CPPUNIT_ASSERT_EQUAL(std::string("4,096.0Mi"), util::abbrevSize(4294967296LL));
CPPUNIT_ASSERT_EQUAL(std::string("1.0Ki"), util::abbrevSize(1024));
CPPUNIT_ASSERT_EQUAL(std::string("1,023"), util::abbrevSize(1023));
CPPUNIT_ASSERT_EQUAL(std::string("0"), util::abbrevSize(0));
CPPUNIT_ASSERT_EQUAL(std::string("1.1Ki"), util::abbrevSize(1127));
CPPUNIT_ASSERT_EQUAL(std::string("1.5Mi"), util::abbrevSize(1572864));
2007-06-10 12:01:32 +00:00
}
void UtilTest::testToStream()
{
std::ostringstream os;
SharedHandle<FileEntry> f1(new FileEntry("aria2.tar.bz2", 12300, 0));
SharedHandle<FileEntry> f2(new FileEntry("aria2.txt", 556, 0));
std::deque<SharedHandle<FileEntry> > entries;
entries.push_back(f1);
entries.push_back(f2);
std::string filename = A2_TEST_OUT_DIR"/aria2_UtilTest_testToStream";
BufferedFile fp(filename, BufferedFile::WRITE);
util::toStream(entries.begin(), entries.end(), fp);
fp.close();
CPPUNIT_ASSERT_EQUAL(
std::string("Files:\n"
"idx|path/length\n"
"===+===========================================================================\n"
" 1|aria2.tar.bz2\n"
" |12.0KiB (12,300)\n"
"---+---------------------------------------------------------------------------\n"
" 2|aria2.txt\n"
" |556B (556)\n"
"---+---------------------------------------------------------------------------\n"),
readFile(filename));
}
void UtilTest::testIsNumber()
{
CPPUNIT_ASSERT_EQUAL(true, util::isNumber("000"));
CPPUNIT_ASSERT_EQUAL(false, util::isNumber("a"));
CPPUNIT_ASSERT_EQUAL(false, util::isNumber("0a"));
CPPUNIT_ASSERT_EQUAL(false, util::isNumber(""));
CPPUNIT_ASSERT_EQUAL(false, util::isNumber(" "));
}
void UtilTest::testIsLowercase()
{
CPPUNIT_ASSERT_EQUAL(true, util::isLowercase("alpha"));
CPPUNIT_ASSERT_EQUAL(false, util::isLowercase("Alpha"));
CPPUNIT_ASSERT_EQUAL(false, util::isLowercase("1alpha"));
CPPUNIT_ASSERT_EQUAL(false, util::isLowercase(""));
CPPUNIT_ASSERT_EQUAL(false, util::isLowercase(" "));
}
void UtilTest::testIsUppercase()
{
CPPUNIT_ASSERT_EQUAL(true, util::isUppercase("ALPHA"));
CPPUNIT_ASSERT_EQUAL(false, util::isUppercase("Alpha"));
CPPUNIT_ASSERT_EQUAL(false, util::isUppercase("1ALPHA"));
CPPUNIT_ASSERT_EQUAL(false, util::isUppercase(""));
CPPUNIT_ASSERT_EQUAL(false, util::isUppercase(" "));
}
void UtilTest::testAlphaToNum()
{
CPPUNIT_ASSERT_EQUAL(0U, util::alphaToNum("a"));
CPPUNIT_ASSERT_EQUAL(0U, util::alphaToNum("aa"));
CPPUNIT_ASSERT_EQUAL(1U, util::alphaToNum("b"));
CPPUNIT_ASSERT_EQUAL(675U, util::alphaToNum("zz")); // 25*26+25
CPPUNIT_ASSERT_EQUAL(675U, util::alphaToNum("ZZ")); // 25*26+25
CPPUNIT_ASSERT_EQUAL(0U, util::alphaToNum(""));
CPPUNIT_ASSERT_EQUAL(4294967295U, util::alphaToNum("NXMRLXV"));
CPPUNIT_ASSERT_EQUAL(0U, util::alphaToNum("NXMRLXW")); // uint32_t overflow
}
void UtilTest::testMkdirs()
{
std::string dir = "./aria2-UtilTest-testMkdirs";
File d(dir);
if(d.exists()) {
CPPUNIT_ASSERT(d.remove());
}
CPPUNIT_ASSERT(!d.exists());
util::mkdirs(dir);
CPPUNIT_ASSERT(d.isDir());
std::string file = A2_TEST_DIR"/UtilTest.cc";
File f(file);
CPPUNIT_ASSERT(f.isFile());
try {
util::mkdirs(file);
CPPUNIT_FAIL("exception must be thrown.");
} catch(DlAbortEx& ex) {
std::cerr << ex.stackTrace() << std::endl;
}
}
void UtilTest::testConvertBitfield()
{
BitfieldMan srcBitfield(384*1024, 256*1024*256+1);
BitfieldMan destBitfield(512*1024, srcBitfield.getTotalLength());
srcBitfield.setAllBit();
srcBitfield.unsetBit(2);// <- range [768, 1152)
// which corresponds to the index [1,2] in destBitfield
util::convertBitfield(&destBitfield, &srcBitfield);
CPPUNIT_ASSERT_EQUAL(std::string("9fffffffffffffffffffffffffffffff80"),
util::toHex(destBitfield.getBitfield(),
destBitfield.getBitfieldLength()));
}
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
void UtilTest::testParseIntRange()
{
IntSequence seq = util::parseIntRange("1,3-8,10");
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
CPPUNIT_ASSERT(seq.hasNext());
CPPUNIT_ASSERT_EQUAL((int32_t)1, seq.next());
CPPUNIT_ASSERT(seq.hasNext());
CPPUNIT_ASSERT_EQUAL((int32_t)3, seq.next());
CPPUNIT_ASSERT(seq.hasNext());
CPPUNIT_ASSERT_EQUAL((int32_t)4, seq.next());
CPPUNIT_ASSERT(seq.hasNext());
CPPUNIT_ASSERT_EQUAL((int32_t)5, seq.next());
CPPUNIT_ASSERT(seq.hasNext());
CPPUNIT_ASSERT_EQUAL((int32_t)6, seq.next());
CPPUNIT_ASSERT(seq.hasNext());
CPPUNIT_ASSERT_EQUAL((int32_t)7, seq.next());
CPPUNIT_ASSERT(seq.hasNext());
CPPUNIT_ASSERT_EQUAL((int32_t)8, seq.next());
CPPUNIT_ASSERT(seq.hasNext());
CPPUNIT_ASSERT_EQUAL((int32_t)10, seq.next());
CPPUNIT_ASSERT(!seq.hasNext());
CPPUNIT_ASSERT_EQUAL((int32_t)0, seq.next());
}
void UtilTest::testParseIntRange_invalidRange()
{
try {
IntSequence seq = util::parseIntRange("-1");
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
}
try {
IntSequence seq = util::parseIntRange("2147483648");
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
}
try {
IntSequence seq = util::parseIntRange("2147483647-2147483648");
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
}
try {
IntSequence seq = util::parseIntRange("1-2x");
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
}
try {
IntSequence seq = util::parseIntRange("3x-4");
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
}
}
void UtilTest::testParseInt()
{
CPPUNIT_ASSERT_EQUAL(-1, util::parseInt(" -1 "));
CPPUNIT_ASSERT_EQUAL(2147483647, util::parseInt("2147483647"));
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
try {
util::parseInt("2147483648");
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
}
try {
util::parseInt("-2147483649");
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
}
try {
util::parseInt("12x");
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
}
try {
util::parseInt("");
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
}
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
}
void UtilTest::testParseUInt()
{
CPPUNIT_ASSERT_EQUAL(4294967295U, util::parseUInt(" 4294967295 "));
try {
util::parseUInt("-1");
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
}
try {
util::parseUInt("4294967296");
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
}
}
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
void UtilTest::testParseLLInt()
{
CPPUNIT_ASSERT_EQUAL((int64_t)-1LL, util::parseLLInt(" -1 "));
CPPUNIT_ASSERT_EQUAL((int64_t)9223372036854775807LL,
util::parseLLInt("9223372036854775807"));
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
try {
util::parseLLInt("9223372036854775808");
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
}
try {
util::parseLLInt("-9223372036854775809");
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
}
try {
util::parseLLInt("12x");
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
}
try {
util::parseLLInt("");
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
}
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
}
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Rewritten to add content-type support. * src/DownloadHandler.{h, cc} * src/BtPostDownloadHandler.{h, cc} * test/BtPostDownloadHandlerTest.cc * src/MetalinkPostDownloadHandler.{h, cc} * test/MetalinkPostDownloadHandlerTest.cc * src/PostDownloadHandler.{h, cc} * src/DownloadHandlerConstants.{h, cc} * src/RequestGroup.cc * src/HttpResponseCommand.cc * src/FtpNegotiationCommand.cc * src/SingleFileDownloadContext.{h, cc} * src/RequestGroup.h * src/RequestGroupCriteria.h * src/ContentTypeRequestGroupCriteria.h Added 'mem' option value for --follow-metalink, --follow-torrent. If it is give, metalink/torrent file is not written to the disk, but just is kept in memory. Parsing is occurred on memory. * src/MetalinkHelper.{h, cc} * src/MetalinkProcessor.h * src/Xml2MetalinkProcessor.{h, cc} * test/Xml2MetalinkProcessorTest.cc * src/DownloadHandlerFactory.{h, cc} * test/DownloadHandlerFactoryTest.cc * src/PreDownloadHandler.{h, cc} * src/OptionHandlerFactory.cc * src/DefaultBtContext.{h, cc} * test/DefaultBtContextTest.cc * src/version_usage.cc * src/Metalink2RequestGroup.{h, cc} * src/RequestGroup.{h, cc} * src/a2functional.h * test/a2functionalTest.cc * src/MemoryBufferPreDownloadHandler.{h, cc} * src/OptionHandlerImpl.h * src/prefs.h * src/Util.{h, cc} * test/UtilTest.cc Keep DownloadResult rather than RequestGroup after downloads to reduce memory usage. * src/RequestGroupMan.{h, cc} * src/DownloadEngine.cc * src/BtDependency.{h, cc}: Changed the type of dependee from WeakHandle to SharedHandle because WeakHandle could be null. * src/RequestGroup.{h, cc} * src/DownloadEngineFactory.cc * src/DownloadResult.h Set totalLength after download finished * src/UnknownLengthPieceStorage.{h, cc} Keep torrent file specified in metalink in memory. * src/Metalink2RequestGroup.cc * src/BtDependency.cc * src/TrueRequestGroupCriteria.h Fixed the bug: seekg is used where seekp should be used. * src/ByteArrayDiskWriter.cc * test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
void UtilTest::testParseULLInt()
{
CPPUNIT_ASSERT_EQUAL((uint64_t)18446744073709551615ULL,
util::parseULLInt("18446744073709551615"));
try {
util::parseUInt("-1");
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
}
try {
util::parseLLInt("18446744073709551616");
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace();
}
}
void UtilTest::testParseIntNoThrow()
{
int32_t n;
CPPUNIT_ASSERT(util::parseIntNoThrow(n, " -1 "));
CPPUNIT_ASSERT_EQUAL((int32_t)-1, n);
CPPUNIT_ASSERT(util::parseIntNoThrow(n, "2147483647"));
CPPUNIT_ASSERT_EQUAL((int32_t)2147483647, n);
CPPUNIT_ASSERT(!util::parseIntNoThrow(n, "2147483648"));
CPPUNIT_ASSERT(!util::parseIntNoThrow(n, "-2147483649"));
CPPUNIT_ASSERT(!util::parseIntNoThrow(n, "12x"));
CPPUNIT_ASSERT(!util::parseIntNoThrow(n, ""));
}
void UtilTest::testParseUIntNoThrow()
{
uint32_t n;
CPPUNIT_ASSERT(util::parseUIntNoThrow(n, " 4294967295 "));
CPPUNIT_ASSERT_EQUAL((uint32_t)UINT32_MAX, n);
CPPUNIT_ASSERT(!util::parseUIntNoThrow(n, "4294967296"));
CPPUNIT_ASSERT(!util::parseUIntNoThrow(n, "-1"));
}
void UtilTest::testParseLLIntNoThrow()
{
int64_t n;
CPPUNIT_ASSERT(util::parseLLIntNoThrow(n, " 9223372036854775807 "));
CPPUNIT_ASSERT_EQUAL((int64_t)INT64_MAX, n);
CPPUNIT_ASSERT(!util::parseLLIntNoThrow(n, "9223372036854775808"));
CPPUNIT_ASSERT(util::parseLLIntNoThrow(n, "-9223372036854775808"));
CPPUNIT_ASSERT_EQUAL((int64_t)INT64_MIN, n);
CPPUNIT_ASSERT(!util::parseLLIntNoThrow(n, "-9223372036854775809"));
}
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Rewritten to add content-type support. * src/DownloadHandler.{h, cc} * src/BtPostDownloadHandler.{h, cc} * test/BtPostDownloadHandlerTest.cc * src/MetalinkPostDownloadHandler.{h, cc} * test/MetalinkPostDownloadHandlerTest.cc * src/PostDownloadHandler.{h, cc} * src/DownloadHandlerConstants.{h, cc} * src/RequestGroup.cc * src/HttpResponseCommand.cc * src/FtpNegotiationCommand.cc * src/SingleFileDownloadContext.{h, cc} * src/RequestGroup.h * src/RequestGroupCriteria.h * src/ContentTypeRequestGroupCriteria.h Added 'mem' option value for --follow-metalink, --follow-torrent. If it is give, metalink/torrent file is not written to the disk, but just is kept in memory. Parsing is occurred on memory. * src/MetalinkHelper.{h, cc} * src/MetalinkProcessor.h * src/Xml2MetalinkProcessor.{h, cc} * test/Xml2MetalinkProcessorTest.cc * src/DownloadHandlerFactory.{h, cc} * test/DownloadHandlerFactoryTest.cc * src/PreDownloadHandler.{h, cc} * src/OptionHandlerFactory.cc * src/DefaultBtContext.{h, cc} * test/DefaultBtContextTest.cc * src/version_usage.cc * src/Metalink2RequestGroup.{h, cc} * src/RequestGroup.{h, cc} * src/a2functional.h * test/a2functionalTest.cc * src/MemoryBufferPreDownloadHandler.{h, cc} * src/OptionHandlerImpl.h * src/prefs.h * src/Util.{h, cc} * test/UtilTest.cc Keep DownloadResult rather than RequestGroup after downloads to reduce memory usage. * src/RequestGroupMan.{h, cc} * src/DownloadEngine.cc * src/BtDependency.{h, cc}: Changed the type of dependee from WeakHandle to SharedHandle because WeakHandle could be null. * src/RequestGroup.{h, cc} * src/DownloadEngineFactory.cc * src/DownloadResult.h Set totalLength after download finished * src/UnknownLengthPieceStorage.{h, cc} Keep torrent file specified in metalink in memory. * src/Metalink2RequestGroup.cc * src/BtDependency.cc * src/TrueRequestGroupCriteria.h Fixed the bug: seekg is used where seekp should be used. * src/ByteArrayDiskWriter.cc * test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
void UtilTest::testToString_binaryStream()
{
SharedHandle<DiskWriter> dw(new ByteArrayDiskWriter());
std::string data(16*1024+256, 'a');
dw->initAndOpenFile();
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Rewritten to add content-type support. * src/DownloadHandler.{h, cc} * src/BtPostDownloadHandler.{h, cc} * test/BtPostDownloadHandlerTest.cc * src/MetalinkPostDownloadHandler.{h, cc} * test/MetalinkPostDownloadHandlerTest.cc * src/PostDownloadHandler.{h, cc} * src/DownloadHandlerConstants.{h, cc} * src/RequestGroup.cc * src/HttpResponseCommand.cc * src/FtpNegotiationCommand.cc * src/SingleFileDownloadContext.{h, cc} * src/RequestGroup.h * src/RequestGroupCriteria.h * src/ContentTypeRequestGroupCriteria.h Added 'mem' option value for --follow-metalink, --follow-torrent. If it is give, metalink/torrent file is not written to the disk, but just is kept in memory. Parsing is occurred on memory. * src/MetalinkHelper.{h, cc} * src/MetalinkProcessor.h * src/Xml2MetalinkProcessor.{h, cc} * test/Xml2MetalinkProcessorTest.cc * src/DownloadHandlerFactory.{h, cc} * test/DownloadHandlerFactoryTest.cc * src/PreDownloadHandler.{h, cc} * src/OptionHandlerFactory.cc * src/DefaultBtContext.{h, cc} * test/DefaultBtContextTest.cc * src/version_usage.cc * src/Metalink2RequestGroup.{h, cc} * src/RequestGroup.{h, cc} * src/a2functional.h * test/a2functionalTest.cc * src/MemoryBufferPreDownloadHandler.{h, cc} * src/OptionHandlerImpl.h * src/prefs.h * src/Util.{h, cc} * test/UtilTest.cc Keep DownloadResult rather than RequestGroup after downloads to reduce memory usage. * src/RequestGroupMan.{h, cc} * src/DownloadEngine.cc * src/BtDependency.{h, cc}: Changed the type of dependee from WeakHandle to SharedHandle because WeakHandle could be null. * src/RequestGroup.{h, cc} * src/DownloadEngineFactory.cc * src/DownloadResult.h Set totalLength after download finished * src/UnknownLengthPieceStorage.{h, cc} Keep torrent file specified in metalink in memory. * src/Metalink2RequestGroup.cc * src/BtDependency.cc * src/TrueRequestGroupCriteria.h Fixed the bug: seekg is used where seekp should be used. * src/ByteArrayDiskWriter.cc * test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
dw->writeData((const unsigned char*)data.c_str(), data.size(), 0);
std::string readData = util::toString(dw);
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Rewritten to add content-type support. * src/DownloadHandler.{h, cc} * src/BtPostDownloadHandler.{h, cc} * test/BtPostDownloadHandlerTest.cc * src/MetalinkPostDownloadHandler.{h, cc} * test/MetalinkPostDownloadHandlerTest.cc * src/PostDownloadHandler.{h, cc} * src/DownloadHandlerConstants.{h, cc} * src/RequestGroup.cc * src/HttpResponseCommand.cc * src/FtpNegotiationCommand.cc * src/SingleFileDownloadContext.{h, cc} * src/RequestGroup.h * src/RequestGroupCriteria.h * src/ContentTypeRequestGroupCriteria.h Added 'mem' option value for --follow-metalink, --follow-torrent. If it is give, metalink/torrent file is not written to the disk, but just is kept in memory. Parsing is occurred on memory. * src/MetalinkHelper.{h, cc} * src/MetalinkProcessor.h * src/Xml2MetalinkProcessor.{h, cc} * test/Xml2MetalinkProcessorTest.cc * src/DownloadHandlerFactory.{h, cc} * test/DownloadHandlerFactoryTest.cc * src/PreDownloadHandler.{h, cc} * src/OptionHandlerFactory.cc * src/DefaultBtContext.{h, cc} * test/DefaultBtContextTest.cc * src/version_usage.cc * src/Metalink2RequestGroup.{h, cc} * src/RequestGroup.{h, cc} * src/a2functional.h * test/a2functionalTest.cc * src/MemoryBufferPreDownloadHandler.{h, cc} * src/OptionHandlerImpl.h * src/prefs.h * src/Util.{h, cc} * test/UtilTest.cc Keep DownloadResult rather than RequestGroup after downloads to reduce memory usage. * src/RequestGroupMan.{h, cc} * src/DownloadEngine.cc * src/BtDependency.{h, cc}: Changed the type of dependee from WeakHandle to SharedHandle because WeakHandle could be null. * src/RequestGroup.{h, cc} * src/DownloadEngineFactory.cc * src/DownloadResult.h Set totalLength after download finished * src/UnknownLengthPieceStorage.{h, cc} Keep torrent file specified in metalink in memory. * src/Metalink2RequestGroup.cc * src/BtDependency.cc * src/TrueRequestGroupCriteria.h Fixed the bug: seekg is used where seekp should be used. * src/ByteArrayDiskWriter.cc * test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
CPPUNIT_ASSERT_EQUAL(data, readData);
}
void UtilTest::testItos()
{
{
int i = 0;
CPPUNIT_ASSERT_EQUAL(std::string("0"), util::itos(i));
}
{
int i = 100;
CPPUNIT_ASSERT_EQUAL(std::string("100"), util::itos(i, true));
}
{
int i = 100;
CPPUNIT_ASSERT_EQUAL(std::string("100"), util::itos(i));
}
{
int i = 12345;
CPPUNIT_ASSERT_EQUAL(std::string("12,345"), util::itos(i, true));
}
{
int i = 12345;
CPPUNIT_ASSERT_EQUAL(std::string("12345"), util::itos(i));
}
{
int i = -12345;
CPPUNIT_ASSERT_EQUAL(std::string("-12,345"), util::itos(i, true));
}
{
int64_t i = INT64_MAX;
CPPUNIT_ASSERT_EQUAL(std::string("9,223,372,036,854,775,807"),
util::itos(i, true));
}
{
int64_t i = INT64_MIN;
CPPUNIT_ASSERT_EQUAL(std::string("-9,223,372,036,854,775,808"),
util::itos(i, true));
}
}
void UtilTest::testUitos()
{
{
uint16_t i = 12345;
CPPUNIT_ASSERT_EQUAL(std::string("12345"), util::uitos(i));
}
{
int16_t i = -12345;
CPPUNIT_ASSERT_EQUAL(std::string("/.-,+"), util::uitos(i));
}
}
void UtilTest::testNtoh64()
{
uint64_t x = 0xff00ff00ee00ee00LL;
#ifdef WORDS_BIGENDIAN
CPPUNIT_ASSERT_EQUAL(x, ntoh64(x));
CPPUNIT_ASSERT_EQUAL(x, hton64(x));
#else // !WORDS_BIGENDIAN
uint64_t y = 0x00ee00ee00ff00ffLL;
CPPUNIT_ASSERT_EQUAL(y, ntoh64(x));
CPPUNIT_ASSERT_EQUAL(x, hton64(y));
#endif // !WORDS_BIGENDIAN
}
void UtilTest::testPercentEncode()
{
CPPUNIT_ASSERT_EQUAL
(std::string("%3A%2F%3F%23%5B%5D%40%21%25%26%27%28%29%2A%2B%2C%3B%3D"),
util::percentEncode(":/?#[]@!%&'()*+,;="));
std::string unreserved =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789"
"-._~";
CPPUNIT_ASSERT_EQUAL(unreserved, util::percentEncode(unreserved));
CPPUNIT_ASSERT_EQUAL(std::string("1%5EA%20"), util::percentEncode("1^A "));
}
void UtilTest::testHtmlEscape()
{
CPPUNIT_ASSERT_EQUAL(std::string("aria2&lt;&gt;&quot;&#39;util"),
util::htmlEscape("aria2<>\"'util"));
}
void UtilTest::testJoinPath()
{
const std::string dir1dir2file[] = { "dir1", "dir2", "file" };
CPPUNIT_ASSERT_EQUAL
(std::string("dir1/dir2/file"),
util::joinPath(vbegin(dir1dir2file), vend(dir1dir2file)));
const std::string dirparentfile[] = { "dir", "..", "file" };
CPPUNIT_ASSERT_EQUAL
(std::string("file"),
util::joinPath(vbegin(dirparentfile), vend(dirparentfile)));
const std::string dirparentparentfile[] = { "dir", "..", "..", "file" };
CPPUNIT_ASSERT_EQUAL
(std::string("file"),
util::joinPath(vbegin(dirparentparentfile), vend(dirparentparentfile)));
const std::string dirdotfile[] = { "dir", ".", "file" };
CPPUNIT_ASSERT_EQUAL(std::string("dir/file"),
util::joinPath(vbegin(dirdotfile), vend(dirdotfile)));
const std::string empty[] = {};
CPPUNIT_ASSERT_EQUAL(std::string(""), util::joinPath(&empty[0], &empty[0]));
const std::string parentdot[] = { "..", "." };
CPPUNIT_ASSERT_EQUAL(std::string(""),
util::joinPath(vbegin(parentdot), vend(parentdot)));
}
void UtilTest::testParseIndexPath()
{
std::map<size_t, std::string>::value_type p = util::parseIndexPath("1=foo");
CPPUNIT_ASSERT_EQUAL((size_t)1, p.first);
CPPUNIT_ASSERT_EQUAL(std::string("foo"), p.second);
try {
util::parseIndexPath("1X=foo");
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
// success
}
try {
util::parseIndexPath("1=");
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
// success
}
}
void UtilTest::testCreateIndexPathMap()
{
std::stringstream in
("1=/tmp/myfile\n"
"100=/myhome/mypicture.png\n");
std::map<size_t, std::string> m = util::createIndexPathMap(in);
CPPUNIT_ASSERT_EQUAL((size_t)2, m.size());
CPPUNIT_ASSERT(m.find(1) != m.end());
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile"), m[1]);
CPPUNIT_ASSERT(m.find(100) != m.end());
CPPUNIT_ASSERT_EQUAL(std::string("/myhome/mypicture.png"), m[100]);
}
void UtilTest::testGenerateRandomData()
{
unsigned char data1[20];
util::generateRandomData(data1, sizeof(data1));
unsigned char data2[20];
util::generateRandomData(data2, sizeof(data2));
CPPUNIT_ASSERT(memcmp(data1, data2, sizeof(data1)) != 0);
}
void UtilTest::testFromHex()
{
std::string src;
std::string dest;
src = "0011fF";
dest = util::fromHex(src);
CPPUNIT_ASSERT_EQUAL((size_t)3, dest.size());
CPPUNIT_ASSERT_EQUAL((char)0x00, dest[0]);
CPPUNIT_ASSERT_EQUAL((char)0x11, dest[1]);
CPPUNIT_ASSERT_EQUAL((char)0xff, dest[2]);
src = "0011f";
CPPUNIT_ASSERT(util::fromHex(src).empty());
src = "001g";
CPPUNIT_ASSERT(util::fromHex(src).empty());
}
void UtilTest::testParsePrioritizePieceRange()
{
// piece index
// 0 1 2 3 4 5 6 7
// | | | |
// file1 | | |
// | | |
// file2 | |
// file3 |
// | |
// file4 |
size_t pieceLength = 1024;
std::vector<SharedHandle<FileEntry> > entries(4, SharedHandle<FileEntry>());
entries[0].reset(new FileEntry("file1", 1024, 0));
entries[1].reset(new FileEntry("file2",2560,entries[0]->getLastOffset()));
entries[2].reset(new FileEntry("file3",0,entries[1]->getLastOffset()));
entries[3].reset(new FileEntry("file4",3584,entries[2]->getLastOffset()));
std::vector<size_t> result;
util::parsePrioritizePieceRange(result, "head=1", entries, pieceLength);
CPPUNIT_ASSERT_EQUAL((size_t)3, result.size());
CPPUNIT_ASSERT_EQUAL((size_t)0, result[0]);
CPPUNIT_ASSERT_EQUAL((size_t)1, result[1]);
CPPUNIT_ASSERT_EQUAL((size_t)3, result[2]);
result.clear();
util::parsePrioritizePieceRange(result, "tail=1", entries, pieceLength);
CPPUNIT_ASSERT_EQUAL((size_t)3, result.size());
CPPUNIT_ASSERT_EQUAL((size_t)0, result[0]);
CPPUNIT_ASSERT_EQUAL((size_t)3, result[1]);
CPPUNIT_ASSERT_EQUAL((size_t)6, result[2]);
result.clear();
util::parsePrioritizePieceRange(result, "head=1K", entries, pieceLength);
CPPUNIT_ASSERT_EQUAL((size_t)4, result.size());
CPPUNIT_ASSERT_EQUAL((size_t)0, result[0]);
CPPUNIT_ASSERT_EQUAL((size_t)1, result[1]);
CPPUNIT_ASSERT_EQUAL((size_t)3, result[2]);
CPPUNIT_ASSERT_EQUAL((size_t)4, result[3]);
result.clear();
util::parsePrioritizePieceRange(result, "head", entries, pieceLength, 1024);
CPPUNIT_ASSERT_EQUAL((size_t)4, result.size());
CPPUNIT_ASSERT_EQUAL((size_t)0, result[0]);
CPPUNIT_ASSERT_EQUAL((size_t)1, result[1]);
CPPUNIT_ASSERT_EQUAL((size_t)3, result[2]);
CPPUNIT_ASSERT_EQUAL((size_t)4, result[3]);
result.clear();
util::parsePrioritizePieceRange(result, "tail=1K", entries, pieceLength);
CPPUNIT_ASSERT_EQUAL((size_t)4, result.size());
CPPUNIT_ASSERT_EQUAL((size_t)0, result[0]);
CPPUNIT_ASSERT_EQUAL((size_t)2, result[1]);
CPPUNIT_ASSERT_EQUAL((size_t)3, result[2]);
CPPUNIT_ASSERT_EQUAL((size_t)6, result[3]);
result.clear();
util::parsePrioritizePieceRange(result, "tail", entries, pieceLength, 1024);
CPPUNIT_ASSERT_EQUAL((size_t)4, result.size());
CPPUNIT_ASSERT_EQUAL((size_t)0, result[0]);
CPPUNIT_ASSERT_EQUAL((size_t)2, result[1]);
CPPUNIT_ASSERT_EQUAL((size_t)3, result[2]);
CPPUNIT_ASSERT_EQUAL((size_t)6, result[3]);
result.clear();
util::parsePrioritizePieceRange(result, "head=1,tail=1", entries, pieceLength);
CPPUNIT_ASSERT_EQUAL((size_t)4, result.size());
CPPUNIT_ASSERT_EQUAL((size_t)0, result[0]);
CPPUNIT_ASSERT_EQUAL((size_t)1, result[1]);
CPPUNIT_ASSERT_EQUAL((size_t)3, result[2]);
CPPUNIT_ASSERT_EQUAL((size_t)6, result[3]);
result.clear();
util::parsePrioritizePieceRange(result, "head=300M,tail=300M",
entries, pieceLength);
CPPUNIT_ASSERT_EQUAL((size_t)7, result.size());
for(size_t i = 0; i < 7; ++i) {
CPPUNIT_ASSERT_EQUAL(i, result[i]);
}
result.clear();
util::parsePrioritizePieceRange(result, "", entries, pieceLength);
CPPUNIT_ASSERT(result.empty());
}
void UtilTest::testApplyDir()
{
CPPUNIT_ASSERT_EQUAL(std::string("./pred"), util::applyDir("", "pred"));
CPPUNIT_ASSERT_EQUAL(std::string("/pred"), util::applyDir("/", "pred"));
CPPUNIT_ASSERT_EQUAL(std::string("./pred"), util::applyDir(".", "pred"));
CPPUNIT_ASSERT_EQUAL(std::string("/dl/pred"), util::applyDir("/dl", "pred"));
}
void UtilTest::testFixTaintedBasename()
{
CPPUNIT_ASSERT_EQUAL(std::string("a%2Fb"), util::fixTaintedBasename("a/b"));
#ifdef __MINGW32__
CPPUNIT_ASSERT_EQUAL(std::string("a%5Cb"), util::fixTaintedBasename("a\\b"));
#else // !__MINGW32__
CPPUNIT_ASSERT_EQUAL(std::string("a\\b"), util::fixTaintedBasename("a\\b"));
#endif // !__MINGW32__
}
void UtilTest::testIsNumericHost()
{
CPPUNIT_ASSERT(util::isNumericHost("192.168.0.1"));
CPPUNIT_ASSERT(!util::isNumericHost("aria2.sf.net"));
CPPUNIT_ASSERT(util::isNumericHost("::1"));
}
void UtilTest::testDetectDirTraversal()
{
CPPUNIT_ASSERT(util::detectDirTraversal("/foo"));
CPPUNIT_ASSERT(util::detectDirTraversal("./foo"));
CPPUNIT_ASSERT(util::detectDirTraversal("../foo"));
CPPUNIT_ASSERT(util::detectDirTraversal("foo/../bar"));
CPPUNIT_ASSERT(util::detectDirTraversal("foo/./bar"));
CPPUNIT_ASSERT(util::detectDirTraversal("foo/."));
CPPUNIT_ASSERT(util::detectDirTraversal("foo/.."));
CPPUNIT_ASSERT(util::detectDirTraversal("."));
CPPUNIT_ASSERT(util::detectDirTraversal(".."));
CPPUNIT_ASSERT(util::detectDirTraversal("/"));
CPPUNIT_ASSERT(util::detectDirTraversal("foo/"));
CPPUNIT_ASSERT(util::detectDirTraversal("\t"));
CPPUNIT_ASSERT(!util::detectDirTraversal("foo/bar"));
CPPUNIT_ASSERT(!util::detectDirTraversal("foo"));
}
void UtilTest::testEscapePath()
{
CPPUNIT_ASSERT_EQUAL(std::string("foo%00bar%00%01"),
util::escapePath(std::string("foo")+(char)0x00+
std::string("bar")+(char)0x00+
(char)0x01));
#ifdef __MINGW32__
CPPUNIT_ASSERT_EQUAL(std::string("foo%5Cbar"), util::escapePath("foo\\bar"));
#else // !__MINGW32__
CPPUNIT_ASSERT_EQUAL(std::string("foo\\bar"), util::escapePath("foo\\bar"));
#endif // !__MINGW32__
}
void UtilTest::testGetCidrPrefix()
{
struct in_addr in;
CPPUNIT_ASSERT(util::getCidrPrefix(in, "192.168.0.1", 16));
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.0"), std::string(inet_ntoa(in)));
CPPUNIT_ASSERT(util::getCidrPrefix(in, "192.168.255.255", 17));
CPPUNIT_ASSERT_EQUAL(std::string("192.168.128.0"),std::string(inet_ntoa(in)));
CPPUNIT_ASSERT(util::getCidrPrefix(in, "192.168.128.1", 16));
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.0"), std::string(inet_ntoa(in)));
CPPUNIT_ASSERT(util::getCidrPrefix(in, "192.168.0.1", 32));
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), std::string(inet_ntoa(in)));
CPPUNIT_ASSERT(util::getCidrPrefix(in, "192.168.0.1", 0));
CPPUNIT_ASSERT_EQUAL(std::string("0.0.0.0"), std::string(inet_ntoa(in)));
CPPUNIT_ASSERT(util::getCidrPrefix(in, "10.10.1.44", 27));
CPPUNIT_ASSERT_EQUAL(std::string("10.10.1.32"), std::string(inet_ntoa(in)));
CPPUNIT_ASSERT(!util::getCidrPrefix(in, "::1", 32));
}
void UtilTest::testInSameCidrBlock()
{
CPPUNIT_ASSERT(util::inSameCidrBlock("192.168.128.1", "192.168.0.1", 16));
CPPUNIT_ASSERT(!util::inSameCidrBlock("192.168.128.1", "192.168.0.1", 17));
}
void UtilTest::testIsUtf8String()
{
CPPUNIT_ASSERT(util::isUtf8("ascii"));
// "Hello World" in Japanese UTF-8
CPPUNIT_ASSERT(util::isUtf8
(util::fromHex("e38193e38293e381abe381a1e381afe4b896e7958c")));
// "World" in Shift_JIS
CPPUNIT_ASSERT(!util::isUtf8(util::fromHex("90a28a")+"E"));
// UTF8-2
CPPUNIT_ASSERT(util::isUtf8(util::fromHex("c280")));
CPPUNIT_ASSERT(util::isUtf8(util::fromHex("dfbf")));
// UTF8-3
CPPUNIT_ASSERT(util::isUtf8(util::fromHex("e0a080")));
CPPUNIT_ASSERT(util::isUtf8(util::fromHex("e0bf80")));
CPPUNIT_ASSERT(util::isUtf8(util::fromHex("e18080")));
CPPUNIT_ASSERT(util::isUtf8(util::fromHex("ec8080")));
CPPUNIT_ASSERT(util::isUtf8(util::fromHex("ed8080")));
CPPUNIT_ASSERT(util::isUtf8(util::fromHex("ed9f80")));
CPPUNIT_ASSERT(util::isUtf8(util::fromHex("ee8080")));
CPPUNIT_ASSERT(util::isUtf8(util::fromHex("ef8080")));
// UTF8-4
CPPUNIT_ASSERT(util::isUtf8(util::fromHex("f0908080")));
CPPUNIT_ASSERT(util::isUtf8(util::fromHex("f0bf8080")));
CPPUNIT_ASSERT(util::isUtf8(util::fromHex("f1808080")));
CPPUNIT_ASSERT(util::isUtf8(util::fromHex("f3808080")));
CPPUNIT_ASSERT(util::isUtf8(util::fromHex("f4808080")));
CPPUNIT_ASSERT(util::isUtf8(util::fromHex("f48f8080")));
CPPUNIT_ASSERT(util::isUtf8(""));
CPPUNIT_ASSERT(!util::isUtf8(util::fromHex("00")));
}
void UtilTest::testNextParam()
{
std::string s1 = " :a : b=c :d=b::::g::";
std::pair<std::string::iterator, bool> r;
std::string name, value;
r = util::nextParam(name, value, s1.begin(), s1.end(), ':');
CPPUNIT_ASSERT(r.second);
CPPUNIT_ASSERT_EQUAL(std::string("a"), name);
CPPUNIT_ASSERT_EQUAL(std::string(), value);
r = util::nextParam(name, value, r.first, s1.end(), ':');
CPPUNIT_ASSERT(r.second);
CPPUNIT_ASSERT_EQUAL(std::string("b"), name);
CPPUNIT_ASSERT_EQUAL(std::string("c"), value);
r = util::nextParam(name, value, r.first, s1.end(), ':');
CPPUNIT_ASSERT(r.second);
CPPUNIT_ASSERT_EQUAL(std::string("d"), name);
CPPUNIT_ASSERT_EQUAL(std::string("b"), value);
r = util::nextParam(name, value, r.first, s1.end(), ':');
CPPUNIT_ASSERT(r.second);
CPPUNIT_ASSERT_EQUAL(std::string("g"), name);
CPPUNIT_ASSERT_EQUAL(std::string(), value);
std::string s2 = "";
r = util::nextParam(name, value, s2.begin(), s2.end(), ':');
CPPUNIT_ASSERT(!r.second);
std::string s3 = " ";
r = util::nextParam(name, value, s3.begin(), s3.end(), ':');
CPPUNIT_ASSERT(!r.second);
std::string s4 = ":::";
r = util::nextParam(name, value, s4.begin(), s4.end(), ':');
CPPUNIT_ASSERT(!r.second);
}
} // namespace aria2