aria2/test/SegmentManTest.cc

78 lines
2.2 KiB
C++
Raw Normal View History

2006-09-23 11:58:23 +00:00
#include "SegmentMan.h"
#include "File.h"
#include "prefs.h"
#include "Util.h"
#include "SingleFileDownloadContext.h"
#include "UnknownLengthPieceStorage.h"
#include "Segment.h"
#include "Option.h"
2006-09-23 11:58:23 +00:00
#include <cppunit/extensions/HelperMacros.h>
using namespace std;
class SegmentManTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(SegmentManTest);
CPPUNIT_TEST(testNullBitfield);
CPPUNIT_TEST(testMarkPieceDone_usedSegment);
2006-09-23 11:58:23 +00:00
CPPUNIT_TEST_SUITE_END();
private:
public:
void setUp() {
}
void testNullBitfield();
void testMarkPieceDone_usedSegment();
2006-09-23 11:58:23 +00:00
};
CPPUNIT_TEST_SUITE_REGISTRATION( SegmentManTest );
void SegmentManTest::testNullBitfield()
{
2006-09-23 11:58:23 +00:00
Option op;
SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "aria2.tar.bz2");
UnknownLengthPieceStorageHandle ps = new UnknownLengthPieceStorage(dctx, &op);
SegmentMan segmentMan(&op, dctx, ps);
2006-09-23 11:58:23 +00:00
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To handle Segment as SegmentHandle: * src/AbstractCommand.cc (execute): Rewritten. * src/SegmentMan.h: Segment -> SegmentHandle Introducded HttpResponse class, HttpRequest class to improve code extensiveness and make it clear: * src/HttpDownloadCommand.cc: transfer encoders are now managed by HttpResponse class. * src/HttpRequest.h, src/HttpRequest.cc: New class. * src/HttpResponse.h, src/HttpResponse.cc: New class. * src/HttpConnection.cc: Contruction of http request were moved to HttpRequest class. * src/HttpResponseCommand.h, src/HttpResponseCommand.cc: Refactored. * src/HttpRequestCommand.cc (executeInternal): Rewritten. * src/HttpAuthConfig.h: New class. * src/Range.h: New class. To make FtpTunnel{Request, Response}Command and HttpProxy{Request, Response}Command derived from AbstractProxy{Request, Response}Command: * src/FtpTunnelResponseCommand.h, src/FtpTunnelResponseCommand.cc: Derived from AbstractProxyRequestCommand class. * src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc: Derived from AbstractProxyResponseCommand class. * src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc: Derived from AbstractProxyRequestCommand class. * src/HttpProxyResponseCommand.h, src/HttpProxyResponseCommand.cc: Derived from AbstractProxyResponseCommand class. * src/AbstractProxyRequestCommand.h, src/AbstractProxyRequestCommand.cc : New class. * src/AbstractProxyResponseCommand.h, src/AbstractProxyResponseCommand.cc: New class. To add netrc support: * src/Netrc.h, src/Netrc.cc: New class. * src/Util.h, src/Util.cc (split): New function. * src/HttpHeader.cc (getRange): Fixed so that it inspects "Content-Range" header instead of "Range" header. * src/HttpHeader.h (getStatus): Removed. (setStatus): Removed. * src/Segment.h (getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
SegmentHandle segment = segmentMan.getSegment(1);
CPPUNIT_ASSERT(!segment.isNull());
CPPUNIT_ASSERT_EQUAL((int32_t)0, segment->getIndex());
CPPUNIT_ASSERT_EQUAL((int32_t)0, segment->getLength());
CPPUNIT_ASSERT_EQUAL((int32_t)0, segment->getSegmentLength());
CPPUNIT_ASSERT_EQUAL((int32_t)0, segment->getWrittenLength());
2006-09-23 11:58:23 +00:00
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To handle Segment as SegmentHandle: * src/AbstractCommand.cc (execute): Rewritten. * src/SegmentMan.h: Segment -> SegmentHandle Introducded HttpResponse class, HttpRequest class to improve code extensiveness and make it clear: * src/HttpDownloadCommand.cc: transfer encoders are now managed by HttpResponse class. * src/HttpRequest.h, src/HttpRequest.cc: New class. * src/HttpResponse.h, src/HttpResponse.cc: New class. * src/HttpConnection.cc: Contruction of http request were moved to HttpRequest class. * src/HttpResponseCommand.h, src/HttpResponseCommand.cc: Refactored. * src/HttpRequestCommand.cc (executeInternal): Rewritten. * src/HttpAuthConfig.h: New class. * src/Range.h: New class. To make FtpTunnel{Request, Response}Command and HttpProxy{Request, Response}Command derived from AbstractProxy{Request, Response}Command: * src/FtpTunnelResponseCommand.h, src/FtpTunnelResponseCommand.cc: Derived from AbstractProxyRequestCommand class. * src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc: Derived from AbstractProxyResponseCommand class. * src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc: Derived from AbstractProxyRequestCommand class. * src/HttpProxyResponseCommand.h, src/HttpProxyResponseCommand.cc: Derived from AbstractProxyResponseCommand class. * src/AbstractProxyRequestCommand.h, src/AbstractProxyRequestCommand.cc : New class. * src/AbstractProxyResponseCommand.h, src/AbstractProxyResponseCommand.cc: New class. To add netrc support: * src/Netrc.h, src/Netrc.cc: New class. * src/Util.h, src/Util.cc (split): New function. * src/HttpHeader.cc (getRange): Fixed so that it inspects "Content-Range" header instead of "Range" header. * src/HttpHeader.h (getStatus): Removed. (setStatus): Removed. * src/Segment.h (getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
SegmentHandle segment2 = segmentMan.getSegment(2);
CPPUNIT_ASSERT(segment2.isNull());
2006-09-23 11:58:23 +00:00
2006-10-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To add timeout to async name resolution: * src/AbstractCommand.h (nameResolveFinished): New function. This is not elegant way. It needs to be more refined. (nameResolverCheck): New variable. * src/AbstractCommand.cc (AbstractCommand): Added nameResolverCheck. (execute): Added the check whether the name resolution has finished. (setNameResolverCheck): Set nameResolverCheck to true. (disableNameResolverCheck): Set nameResolverCheck to false. (nameResolverFinished): New function. * src/FtpInitiateConnectionCommand.h (nameResolverFinished): New function. * src/HttpInitiateConnectionCommand.h (nameResolverFinished): New function. To add the support for a non-compact response from a tracker: * src/PeerListProcessor.h: New class. * src/DefaultPeerListProcessor.h: New class. * src/DefaultPeerListProcessor.cc: New class. * src/CompactPeerListProcessor.h: New class. * src/CompactPeerListProcessor.cc: New class. * src/DelegatingPeerListProcessor.h: New class. * src/DelegatingPeerListProcessor.cc: New class. * src/TorrentMan.cc (addPeer): New function(overload). (addPeer): Delete unused peers only when new peer is added. * src/TorrentMan.h (PeerListProcessor.h): Included. (Peers): Removed. (addPeer): New function(overload). * src/TrackerUpdateCommand.cc (netinet/in.h): Removed. (DelegatingPeerListProcessor.h): Included. (execute): Updated to use DelegatingPeerListProcessor. To fix the memory leak in TorrentMan::peers: * src/PeerAbstractCommand.cc (onAbort): Added peer->resetStatus(). * src/Peer.h (resetStatus): Made public. To improve the precision of the speed calculation: * src/SpeedCalc.h (nextInterval): New variable. * src/SpeedCalc.cc (reset): Added nextInterval. (isIntervalOver): Use nextInterval instead of CHANGE_INTERVAL_SEC. (changeSw): Set nextInterval to 15 seconds relative to the current instant time. * src/main.cc (showVersion): Updated.
2006-10-01 11:29:14 +00:00
segmentMan.cancelSegment(1);
CPPUNIT_ASSERT(!segmentMan.getSegment(2).isNull());
}
void SegmentManTest::testMarkPieceDone_usedSegment()
{
// TODO implement this later
/*
SegmentMan segmentMan;
int32_t pieceLength = 1024*1024;
int64_t totalLength = 10*pieceLength;
segmentMan.initBitfield(pieceLength, totalLength);
segmentMan.markPieceDone(5*pieceLength+100);
for(int32_t i = 0; i < 5; ++i) {
CPPUNIT_ASSERT(segmentMan.hasSegment(i));
}
for(int32_t i = 5; i < 10; ++i) {
CPPUNIT_ASSERT(!segmentMan.hasSegment(i));
}
SegmentHandle segment = segmentMan.getSegment(0, 5);
CPPUNIT_ASSERT(!segment.isNull());
CPPUNIT_ASSERT_EQUAL((int32_t)5, segment->index);
2007-07-23 14:09:46 +00:00
CPPUNIT_ASSERT_EQUAL(pieceLength, (int32_t) segment->length);
CPPUNIT_ASSERT_EQUAL(pieceLength, (int32_t) segment->segmentLength);
CPPUNIT_ASSERT_EQUAL((int32_t)100, segment->writtenLength);
*/
}