2006-02-17 13:35:04 +00:00
|
|
|
#include "Util.h"
|
2007-11-04 12:26:12 +00:00
|
|
|
#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"
|
2007-11-13 10:10:11 +00:00
|
|
|
#include "BitfieldMan.h"
|
2006-02-17 13:35:04 +00:00
|
|
|
#include <string>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
class UtilTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(UtilTest);
|
|
|
|
CPPUNIT_TEST(testTrim);
|
|
|
|
CPPUNIT_TEST(testSplit);
|
|
|
|
CPPUNIT_TEST(testSlice);
|
2006-02-21 12:27:17 +00:00
|
|
|
CPPUNIT_TEST(testEndsWith);
|
2006-02-21 15:01:05 +00:00
|
|
|
CPPUNIT_TEST(testReplace);
|
2006-02-28 02:25:45 +00:00
|
|
|
CPPUNIT_TEST(testStartsWith);
|
2006-05-09 15:54:14 +00:00
|
|
|
// may be moved to other helper class in the future.
|
|
|
|
CPPUNIT_TEST(testGetContentDispositionFilename);
|
2006-06-22 15:26:18 +00:00
|
|
|
CPPUNIT_TEST(testRandomAlpha);
|
2006-07-03 14:19:23 +00:00
|
|
|
CPPUNIT_TEST(testToUpper);
|
|
|
|
CPPUNIT_TEST(testToLower);
|
2006-08-28 12:40:41 +00:00
|
|
|
CPPUNIT_TEST(testUrldecode);
|
2007-01-28 14:18:35 +00:00
|
|
|
CPPUNIT_TEST(testCountBit);
|
2007-03-26 12:16:57 +00:00
|
|
|
CPPUNIT_TEST(testGetRealSize);
|
2007-06-05 11:37:25 +00:00
|
|
|
CPPUNIT_TEST(testAbbrevSize);
|
2007-07-01 10:40:30 +00:00
|
|
|
CPPUNIT_TEST(testToStream);
|
2007-08-28 11:51:20 +00:00
|
|
|
CPPUNIT_TEST(testIsNumber);
|
|
|
|
CPPUNIT_TEST(testIsLowercase);
|
|
|
|
CPPUNIT_TEST(testIsUppercase);
|
|
|
|
CPPUNIT_TEST(testAlphaToNum);
|
2007-11-05 15:13:55 +00:00
|
|
|
CPPUNIT_TEST(testMkdirs);
|
2007-11-13 10:10:11 +00:00
|
|
|
CPPUNIT_TEST(testConvertBitfield);
|
2007-11-21 16:14:40 +00:00
|
|
|
CPPUNIT_TEST(testParseIntRange);
|
|
|
|
CPPUNIT_TEST(testParseIntRange_invalidRange);
|
|
|
|
CPPUNIT_TEST(testParseInt);
|
|
|
|
CPPUNIT_TEST(testParseLLInt);
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void testTrim();
|
|
|
|
void testSplit();
|
|
|
|
void testSlice();
|
2006-02-21 12:27:17 +00:00
|
|
|
void testEndsWith();
|
2006-02-21 15:01:05 +00:00
|
|
|
void testReplace();
|
2006-02-28 02:25:45 +00:00
|
|
|
void testStartsWith();
|
2006-05-09 15:54:14 +00:00
|
|
|
// may be moved to other helper class in the future.
|
|
|
|
void testGetContentDispositionFilename();
|
2006-06-22 15:26:18 +00:00
|
|
|
void testRandomAlpha();
|
2006-07-03 14:19:23 +00:00
|
|
|
void testToUpper();
|
|
|
|
void testToLower();
|
2006-08-28 12:40:41 +00:00
|
|
|
void testUrldecode();
|
2007-01-28 14:18:35 +00:00
|
|
|
void testCountBit();
|
2007-03-26 12:16:57 +00:00
|
|
|
void testGetRealSize();
|
2007-06-05 11:37:25 +00:00
|
|
|
void testAbbrevSize();
|
2007-07-01 10:40:30 +00:00
|
|
|
void testToStream();
|
2007-08-28 11:51:20 +00:00
|
|
|
void testIsNumber();
|
|
|
|
void testIsLowercase();
|
|
|
|
void testIsUppercase();
|
|
|
|
void testAlphaToNum();
|
2007-11-05 15:13:55 +00:00
|
|
|
void testMkdirs();
|
2007-11-13 10:10:11 +00:00
|
|
|
void testConvertBitfield();
|
2007-11-21 16:14:40 +00:00
|
|
|
void testParseIntRange();
|
|
|
|
void testParseIntRange_invalidRange();
|
|
|
|
void testParseInt();
|
|
|
|
void testParseLLInt();
|
2006-02-17 13:35:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( UtilTest );
|
|
|
|
|
|
|
|
void UtilTest::testTrim() {
|
|
|
|
string str1 = "aria2";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str1, Util::trim("aria2"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str1, Util::trim(" aria2"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str1, Util::trim(" aria2 "));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str1, Util::trim(" aria2 "));
|
|
|
|
string str2 = "aria2 debut";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str2, Util::trim("aria2 debut"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str2, Util::trim(" aria2 debut "));
|
|
|
|
string str3 = "";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str3, Util::trim(""));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str3, Util::trim(" "));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str3, Util::trim(" "));
|
|
|
|
string str4 = "A";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str4, Util::trim("A"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str4, Util::trim(" A "));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str4, Util::trim(" A "));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UtilTest::testSplit() {
|
|
|
|
pair<string, string> p1;
|
|
|
|
Util::split(p1, "name=value", '=');
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("name"), p1.first);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("value"), p1.second);
|
|
|
|
Util::split(p1, " name = value ", '=');
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("name"), p1.first);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("value"), p1.second);
|
|
|
|
Util::split(p1, "=value", '=');
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string(""), p1.first);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("value"), p1.second);
|
|
|
|
Util::split(p1, "name=", '=');
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("name"), p1.first);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string(""), p1.second);
|
|
|
|
Util::split(p1, "name", '=');
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("name"), p1.first);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string(""), p1.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UtilTest::testSlice() {
|
2006-04-06 12:52:16 +00:00
|
|
|
Strings v1;
|
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::slice(v1, "name1=value1; name2=value2; name3=value3;", ';', true);
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(3, (int)v1.size());
|
|
|
|
v1.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::slice(v1, "name1=value1; name2=value2; name3=value3", ';', true);
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(3, (int)v1.size());
|
2006-04-06 12:52:16 +00:00
|
|
|
Strings::iterator itr = v1.begin();
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("name1=value1"), *itr++);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("name2=value2"), *itr++);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("name3=value3"), *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
|
|
|
|
|
|
|
v1.clear();
|
|
|
|
|
|
|
|
Util::slice(v1, "name1=value1; name2=value2; name3=value3", ';', false);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(3, (int)v1.size());
|
|
|
|
itr = v1.begin();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("name1=value1"), *itr++);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string(" name2=value2"), *itr++);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string(" name3=value3"), *itr++);
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
2006-02-21 12:27:17 +00:00
|
|
|
|
|
|
|
void UtilTest::testEndsWith() {
|
|
|
|
string target = "abcdefg";
|
|
|
|
string part = "fg";
|
|
|
|
CPPUNIT_ASSERT(Util::endsWith(target, part));
|
|
|
|
|
|
|
|
target = "abdefg";
|
|
|
|
part = "g";
|
|
|
|
CPPUNIT_ASSERT(Util::endsWith(target, part));
|
|
|
|
|
|
|
|
target = "abdefg";
|
|
|
|
part = "eg";
|
|
|
|
CPPUNIT_ASSERT(!Util::endsWith(target, part));
|
|
|
|
|
|
|
|
target = "g";
|
|
|
|
part = "eg";
|
|
|
|
CPPUNIT_ASSERT(!Util::endsWith(target, part));
|
|
|
|
|
|
|
|
target = "g";
|
|
|
|
part = "g";
|
|
|
|
CPPUNIT_ASSERT(Util::endsWith(target, part));
|
|
|
|
|
|
|
|
target = "g";
|
|
|
|
part = "";
|
|
|
|
CPPUNIT_ASSERT(Util::endsWith(target, part));
|
|
|
|
|
|
|
|
target = "";
|
|
|
|
part = "";
|
|
|
|
CPPUNIT_ASSERT(Util::endsWith(target, part));
|
|
|
|
|
|
|
|
target = "";
|
|
|
|
part = "g";
|
|
|
|
CPPUNIT_ASSERT(!Util::endsWith(target, part));
|
|
|
|
}
|
2006-02-21 15:01:05 +00:00
|
|
|
|
|
|
|
void UtilTest::testReplace() {
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("abc\n"), Util::replace("abc\r\n", "\r", ""));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("abc"), Util::replace("abc\r\n", "\r\n", ""));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string(""), Util::replace("", "\r\n", ""));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("abc"), Util::replace("abc", "", "a"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("xbc"), Util::replace("abc", "a", "x"));
|
|
|
|
}
|
2006-02-28 02:25:45 +00:00
|
|
|
|
|
|
|
void UtilTest::testStartsWith() {
|
|
|
|
string target;
|
|
|
|
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 15:54:14 +00:00
|
|
|
|
|
|
|
void UtilTest::testGetContentDispositionFilename() {
|
|
|
|
string h1 = "attachment; filename=\"aria2.tar.bz2\"";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("aria2.tar.bz2"), Util::getContentDispositionFilename(h1));
|
|
|
|
|
|
|
|
string h2 = "attachment; filename=\"\"";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string(""), Util::getContentDispositionFilename(h2));
|
|
|
|
|
|
|
|
string h3 = "attachment; filename=\"";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string(""), Util::getContentDispositionFilename(h3));
|
|
|
|
|
|
|
|
string h4 = "attachment;";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string(""), Util::getContentDispositionFilename(h4));
|
2007-07-18 11:36:41 +00:00
|
|
|
|
|
|
|
string h5 = "attachment; filename=aria2.tar.bz2";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("aria2.tar.bz2"), Util::getContentDispositionFilename(h5));
|
|
|
|
|
|
|
|
string h6 = "attachment; filename='aria2.tar.bz2'";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("aria2.tar.bz2"), Util::getContentDispositionFilename(h6));
|
|
|
|
|
|
|
|
string h7 = "attachment; filename='aria2.tar.bz2";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("aria2.tar.bz2"), Util::getContentDispositionFilename(h7));
|
|
|
|
|
|
|
|
string h8 = "attachment; filename=aria2.tar.bz2; creation-date=20 Jun 2007 00:00:00 GMT";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("aria2.tar.bz2"), Util::getContentDispositionFilename(h8));
|
|
|
|
|
|
|
|
string h9 = "attachment; filename=\"aria2.tar.bz2; creation-date=20 Jun 2007 00:00:00 GMT\"";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("aria2.tar.bz2; creation-date=20 Jun 2007 00:00:00 GMT"), Util::getContentDispositionFilename(h9));
|
|
|
|
|
|
|
|
string h10 = "attachment; filename=";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string(""), Util::getContentDispositionFilename(h10));
|
|
|
|
|
|
|
|
string h11 = "attachment; filename=;";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string(""), Util::getContentDispositionFilename(h11));
|
|
|
|
|
2006-05-09 15:54:14 +00:00
|
|
|
}
|
2006-05-18 17:08:29 +00:00
|
|
|
|
|
|
|
class Printer {
|
|
|
|
public:
|
|
|
|
template<class T>
|
|
|
|
void operator()(T t) {
|
|
|
|
cerr << t << ", ";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-06-22 15:26:18 +00:00
|
|
|
void UtilTest::testRandomAlpha() {
|
2007-11-04 12:26:12 +00:00
|
|
|
string s = Util::randomAlpha(8, new FixedNumberRandomizer());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("AAAAAAAA"), s);
|
2006-06-22 15:26:18 +00:00
|
|
|
}
|
2006-07-03 14:19:23 +00:00
|
|
|
|
|
|
|
void UtilTest::testToUpper() {
|
|
|
|
string src = "608cabc0f2fa18c260cafd974516865c772363d5";
|
|
|
|
string upp = "608CABC0F2FA18C260CAFD974516865C772363D5";
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(upp, Util::toUpper(src));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UtilTest::testToLower() {
|
|
|
|
string src = "608CABC0F2FA18C260CAFD974516865C772363D5";
|
|
|
|
string upp = "608cabc0f2fa18c260cafd974516865c772363d5";
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(upp, Util::toLower(src));
|
|
|
|
}
|
2006-08-28 12:40:41 +00:00
|
|
|
|
|
|
|
#include "SharedHandle.h"
|
|
|
|
|
|
|
|
void UtilTest::testUrldecode() {
|
|
|
|
string src = "http://aria2.sourceforge.net/aria2%200.7.0%20docs.html";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("http://aria2.sourceforge.net/aria2 0.7.0 docs.html"),
|
|
|
|
Util::urldecode(src));
|
|
|
|
|
|
|
|
string src2 = "aria2+aria2";
|
2006-10-18 14:57:00 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("aria2+aria2"), Util::urldecode(src2));
|
2006-08-28 12:40:41 +00:00
|
|
|
|
|
|
|
string src3 = "%5t%20";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("%5t "), Util::urldecode(src3));
|
|
|
|
|
|
|
|
string src4 = "%";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("%"), Util::urldecode(src4));
|
|
|
|
|
|
|
|
string src5 = "%3";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("%3"), Util::urldecode(src5));
|
|
|
|
|
|
|
|
string src6 = "%2f";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("/"), Util::urldecode(src6));
|
|
|
|
}
|
2007-01-28 14:18:35 +00:00
|
|
|
|
|
|
|
void UtilTest::testCountBit() {
|
2007-07-23 14:09:46 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)32, Util::countBit(UINT32_MAX));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)8, Util::countBit(255));
|
2007-01-28 14:18:35 +00:00
|
|
|
}
|
2007-03-26 12:16:57 +00:00
|
|
|
|
|
|
|
void UtilTest::testGetRealSize()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)4294967296LL, Util::getRealSize("4096M"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)1024, Util::getRealSize("1K"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)0, Util::getRealSize(""));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)0, Util::getRealSize("foo"));
|
|
|
|
}
|
2007-06-05 11:37:25 +00:00
|
|
|
|
|
|
|
void UtilTest::testAbbrevSize()
|
|
|
|
{
|
2007-07-01 10:40:30 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("4,096.0Mi"), Util::abbrevSize(4294967296LL));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("1.0Ki"), Util::abbrevSize(1024));
|
2007-06-05 11:37:25 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("1,023"), Util::abbrevSize(1023));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("0"), Util::abbrevSize(0));
|
2007-07-01 10:40:30 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("1.1Ki"), Util::abbrevSize(1127));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("1.5Mi"), Util::abbrevSize(1572864));
|
2007-06-10 12:01:32 +00:00
|
|
|
|
2007-06-05 11:37:25 +00:00
|
|
|
}
|
2007-07-01 10:40:30 +00:00
|
|
|
|
|
|
|
void UtilTest::testToStream()
|
|
|
|
{
|
|
|
|
ostringstream os;
|
|
|
|
FileEntryHandle f1 = new FileEntry("aria2.tar.bz2", 12300, 0);
|
|
|
|
FileEntryHandle f2 = new FileEntry("aria2.txt", 556, 0);
|
|
|
|
FileEntries entries;
|
|
|
|
entries.push_back(f1);
|
|
|
|
entries.push_back(f2);
|
|
|
|
Util::toStream(os, entries);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(
|
|
|
|
string("Files:\n"
|
|
|
|
"idx|path/length\n"
|
|
|
|
"===+===========================================================================\n"
|
|
|
|
" 1|aria2.tar.bz2\n"
|
2007-11-03 08:58:45 +00:00
|
|
|
" |12.0KiB\n"
|
2007-07-01 10:40:30 +00:00
|
|
|
"---+---------------------------------------------------------------------------\n"
|
|
|
|
" 2|aria2.txt\n"
|
2007-11-03 08:58:45 +00:00
|
|
|
" |556B\n"
|
2007-07-01 10:40:30 +00:00
|
|
|
"---+---------------------------------------------------------------------------\n"),
|
|
|
|
os.str());
|
|
|
|
}
|
2007-08-28 11:51:20 +00:00
|
|
|
|
|
|
|
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((int32_t)0, Util::alphaToNum("a"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)0, Util::alphaToNum("aa"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)1, Util::alphaToNum("b"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)675, Util::alphaToNum("zz")); // 25*26+25
|
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)675, Util::alphaToNum("ZZ")); // 25*26+25
|
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)0, Util::alphaToNum(""));
|
|
|
|
}
|
2007-11-05 15:13:55 +00:00
|
|
|
|
|
|
|
void UtilTest::testMkdirs()
|
|
|
|
{
|
|
|
|
string dir = "/tmp/aria2-UtilTest-testMkdirs";
|
|
|
|
File d(dir);
|
|
|
|
if(d.exists()) {
|
|
|
|
CPPUNIT_ASSERT(d.remove());
|
|
|
|
}
|
|
|
|
CPPUNIT_ASSERT(!d.exists());
|
|
|
|
Util::mkdirs(dir);
|
|
|
|
CPPUNIT_ASSERT(d.isDir());
|
|
|
|
|
|
|
|
string file = "./UtilTest.cc";
|
|
|
|
File f(file);
|
|
|
|
CPPUNIT_ASSERT(f.isFile());
|
|
|
|
try {
|
|
|
|
Util::mkdirs(file);
|
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(DlAbortEx* ex) {
|
|
|
|
cerr << ex->getMsg() << endl;
|
|
|
|
delete ex;
|
|
|
|
}
|
|
|
|
}
|
2007-11-13 10:10:11 +00:00
|
|
|
|
|
|
|
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(string("9fffffffffffffffffffffffffffffff80"),
|
|
|
|
Util::toHex(destBitfield.getBitfield(),
|
|
|
|
destBitfield.getBitfieldLength()));
|
|
|
|
}
|
2007-11-21 16:14:40 +00:00
|
|
|
|
|
|
|
void UtilTest::testParseIntRange()
|
|
|
|
{
|
|
|
|
IntSequence seq = Util::parseIntRange("1,3-8,10");
|
|
|
|
|
|
|
|
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");
|
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(Exception* e) {
|
|
|
|
cerr << *e;
|
|
|
|
delete e;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
IntSequence seq = Util::parseIntRange("2147483648");
|
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(Exception* e) {
|
|
|
|
cerr << *e;
|
|
|
|
delete e;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
IntSequence seq = Util::parseIntRange("2147483647-2147483648");
|
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(Exception* e) {
|
|
|
|
cerr << *e;
|
|
|
|
delete e;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
IntSequence seq = Util::parseIntRange("1-2x");
|
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(Exception* e) {
|
|
|
|
cerr << *e;
|
|
|
|
delete e;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
IntSequence seq = Util::parseIntRange("3x-4");
|
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(Exception* e) {
|
|
|
|
cerr << *e;
|
|
|
|
delete e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UtilTest::testParseInt()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)-1, Util::parseInt("-1"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)2147483647, Util::parseInt("2147483647"));
|
|
|
|
try {
|
|
|
|
Util::parseInt("2147483648");
|
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(Exception* e) {
|
|
|
|
cerr << *e;
|
|
|
|
delete e;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
Util::parseInt("-2147483649");
|
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(Exception* e) {
|
|
|
|
cerr << *e;
|
|
|
|
delete e;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
Util::parseInt("12x");
|
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(Exception* e) {
|
|
|
|
cerr << *e;
|
|
|
|
delete e;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void UtilTest::testParseLLInt()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)-1, Util::parseLLInt("-1"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)9223372036854775807LL,
|
|
|
|
Util::parseLLInt("9223372036854775807"));
|
|
|
|
try {
|
|
|
|
Util::parseLLInt("9223372036854775808");
|
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(Exception* e) {
|
|
|
|
cerr << *e;
|
|
|
|
delete e;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
Util::parseLLInt("-9223372036854775809");
|
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(Exception* e) {
|
|
|
|
cerr << *e;
|
|
|
|
delete e;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
Util::parseLLInt("12x");
|
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(Exception* e) {
|
|
|
|
cerr << *e;
|
|
|
|
delete e;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|