2006-09-23 11:58:23 +00:00
|
|
|
#include "SegmentMan.h"
|
|
|
|
#include "File.h"
|
|
|
|
#include "prefs.h"
|
|
|
|
#include "Util.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "SingleFileDownloadContext.h"
|
|
|
|
#include "UnknownLengthPieceStorage.h"
|
2008-01-06 16:37:25 +00:00
|
|
|
#include "DefaultPieceStorage.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "Segment.h"
|
|
|
|
#include "Option.h"
|
2008-01-06 16:37:25 +00:00
|
|
|
#include "MockBtContext.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "FileEntry.h"
|
2006-09-23 11:58:23 +00:00
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2006-09-23 11:58:23 +00:00
|
|
|
|
|
|
|
class SegmentManTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(SegmentManTest);
|
|
|
|
CPPUNIT_TEST(testNullBitfield);
|
2008-01-06 16:37:25 +00:00
|
|
|
CPPUNIT_TEST(testCompleteSegment);
|
2007-03-24 14:32:49 +00:00
|
|
|
CPPUNIT_TEST(testMarkPieceDone_usedSegment);
|
2006-09-23 11:58:23 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void testNullBitfield();
|
2008-01-06 16:37:25 +00:00
|
|
|
void testCompleteSegment();
|
2007-03-24 14:32:49 +00:00
|
|
|
void testMarkPieceDone_usedSegment();
|
2006-09-23 11:58:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( SegmentManTest );
|
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
void SegmentManTest::testNullBitfield()
|
|
|
|
{
|
2006-09-23 11:58:23 +00:00
|
|
|
Option op;
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<SingleFileDownloadContext> dctx
|
|
|
|
(new SingleFileDownloadContext(0, 0, "aria2.tar.bz2"));
|
|
|
|
SharedHandle<UnknownLengthPieceStorage> ps
|
|
|
|
(new UnknownLengthPieceStorage(dctx, &op));
|
2007-10-11 16:58:24 +00:00
|
|
|
SegmentMan segmentMan(&op, dctx, ps);
|
2006-09-23 11:58:23 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Segment> segment = segmentMan.getSegment(1);
|
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
|
|
|
CPPUNIT_ASSERT(!segment.isNull());
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, segment->getIndex());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, segment->getLength());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, segment->getSegmentLength());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, segment->getWrittenLength());
|
2006-09-23 11:58:23 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Segment> segment2 = segmentMan.getSegment(2);
|
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
|
|
|
CPPUNIT_ASSERT(segment2.isNull());
|
2006-09-23 11:58:23 +00:00
|
|
|
|
2006-10-01 11:29:14 +00:00
|
|
|
segmentMan.cancelSegment(1);
|
2007-10-11 16:58:24 +00:00
|
|
|
CPPUNIT_ASSERT(!segmentMan.getSegment(2).isNull());
|
2007-03-24 14:32:49 +00:00
|
|
|
}
|
|
|
|
|
2008-01-06 16:37:25 +00:00
|
|
|
void SegmentManTest::testCompleteSegment()
|
|
|
|
{
|
|
|
|
Option op;
|
2008-03-08 08:04:28 +00:00
|
|
|
size_t pieceLength = 1024*1024;
|
|
|
|
uint64_t totalLength = 64*1024*1024;
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<MockBtContext> dctx(new MockBtContext());
|
2008-01-06 16:37:25 +00:00
|
|
|
dctx->setPieceLength(pieceLength);
|
|
|
|
dctx->setTotalLength(totalLength);
|
|
|
|
dctx->setNumPieces((totalLength+pieceLength-1)/pieceLength);
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<DefaultPieceStorage> ps(new DefaultPieceStorage(dctx, &op));
|
2008-01-06 16:37:25 +00:00
|
|
|
|
|
|
|
SegmentMan segmentMan(&op, dctx, ps);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!segmentMan.getSegment(1, 0).isNull());
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Segment> seg = segmentMan.getSegment(1, 1);
|
2008-01-06 16:37:25 +00:00
|
|
|
CPPUNIT_ASSERT(!seg.isNull());
|
|
|
|
CPPUNIT_ASSERT(!segmentMan.getSegment(1, 2).isNull());
|
|
|
|
|
|
|
|
seg->updateWrittenLength(pieceLength);
|
|
|
|
segmentMan.completeSegment(1, seg);
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<SharedHandle<Segment> > segments = segmentMan.getInFlightSegment(1);
|
2008-01-06 16:37:25 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, segments.size());
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, segments[0]->getIndex());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, segments[1]->getIndex());
|
2008-01-06 16:37:25 +00:00
|
|
|
}
|
|
|
|
|
2007-03-24 14:32:49 +00:00
|
|
|
void SegmentManTest::testMarkPieceDone_usedSegment()
|
|
|
|
{
|
2007-10-11 16:58:24 +00:00
|
|
|
// TODO implement this later
|
|
|
|
/*
|
2007-03-24 14:32:49 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Segment> segment = segmentMan.getSegment(0, 5);
|
2007-03-24 14:32:49 +00:00
|
|
|
CPPUNIT_ASSERT(!segment.isNull());
|
2007-08-15 15:11:01 +00:00
|
|
|
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);
|
2007-08-15 15:11:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)100, segment->writtenLength);
|
2007-10-11 16:58:24 +00:00
|
|
|
*/
|
2007-03-24 14:32:49 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|