mirror of
https://github.com/aria2/aria2.git
synced 2025-04-05 21:47:37 +03:00
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.
111 lines
3 KiB
C++
111 lines
3 KiB
C++
#include "SegmentMan.h"
|
|
#include "File.h"
|
|
#include "prefs.h"
|
|
#include "Util.h"
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
using namespace std;
|
|
|
|
class SegmentManTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(SegmentManTest);
|
|
CPPUNIT_TEST(testSaveAndLoad);
|
|
CPPUNIT_TEST(testNullBitfield);
|
|
CPPUNIT_TEST(testCancelSegmentOnNullBitfield);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
private:
|
|
|
|
public:
|
|
void setUp() {
|
|
}
|
|
|
|
void testSaveAndLoad();
|
|
void testNullBitfield();
|
|
void testCancelSegmentOnNullBitfield();
|
|
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( SegmentManTest );
|
|
|
|
void SegmentManTest::testSaveAndLoad() {
|
|
string filename = "save-temp";
|
|
string aria2filename = filename+".aria2";
|
|
File saveFile(aria2filename);
|
|
if(saveFile.exists()) {
|
|
saveFile.remove();
|
|
assert(!saveFile.exists());
|
|
}
|
|
try {
|
|
SegmentMan segmentMan;
|
|
segmentMan.totalSize = 10*1024*1024;
|
|
segmentMan.ufilename = filename;
|
|
segmentMan.initBitfield(1024*1024, segmentMan.totalSize);
|
|
|
|
SegmentHandle seg1 = segmentMan.getSegment(1);
|
|
seg1->writtenLength = seg1->length;
|
|
segmentMan.completeSegment(1, seg1);
|
|
|
|
SegmentHandle seg2 = segmentMan.getSegment(2);
|
|
seg2->writtenLength = 512*1024;
|
|
//segmentMan.updateSegment(2, seg2);
|
|
|
|
SegmentHandle seg3 = segmentMan.getSegment(3);
|
|
seg3->writtenLength = 512*1024;
|
|
//segmentMan.updateSegment(2, seg2);
|
|
|
|
segmentMan.save();
|
|
|
|
CPPUNIT_ASSERT(saveFile.exists());
|
|
|
|
SegmentMan segmentManLoad;
|
|
segmentManLoad.ufilename = filename;
|
|
segmentManLoad.load();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(segmentMan.totalSize, segmentManLoad.totalSize);
|
|
|
|
SegmentHandle seg2Load = segmentManLoad.getSegment(2, seg2->index);
|
|
CPPUNIT_ASSERT_EQUAL(seg2, seg2Load);
|
|
|
|
SegmentHandle seg3Load = segmentManLoad.getSegment(3, seg3->index);
|
|
CPPUNIT_ASSERT_EQUAL(seg3, seg3Load);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(segmentMan.getDownloadLength(), segmentManLoad.getDownloadLength());
|
|
} catch(Exception* e) {
|
|
cerr << e->getMsg() << endl;
|
|
delete e;
|
|
}
|
|
}
|
|
|
|
void SegmentManTest::testNullBitfield() {
|
|
SegmentMan segmentMan;
|
|
Option op;
|
|
op.put(PREF_SEGMENT_SIZE, Util::itos(1024*1024));
|
|
segmentMan.option = &op;
|
|
|
|
SegmentHandle segment = segmentMan.getSegment(1);
|
|
CPPUNIT_ASSERT(!segment.isNull());
|
|
CPPUNIT_ASSERT_EQUAL(0, segment->index);
|
|
CPPUNIT_ASSERT_EQUAL(0, segment->length);
|
|
CPPUNIT_ASSERT_EQUAL(0, segment->segmentLength);
|
|
CPPUNIT_ASSERT_EQUAL(0, segment->writtenLength);
|
|
|
|
SegmentHandle segment2 = segmentMan.getSegment(2);
|
|
CPPUNIT_ASSERT(segment2.isNull());
|
|
|
|
int64_t totalLength = 1024*1024;
|
|
segment->writtenLength = totalLength;
|
|
CPPUNIT_ASSERT_EQUAL(totalLength, segmentMan.getDownloadLength());
|
|
CPPUNIT_ASSERT(segmentMan.completeSegment(1, segment));
|
|
CPPUNIT_ASSERT_EQUAL(totalLength, segmentMan.getDownloadLength());
|
|
}
|
|
|
|
void SegmentManTest::testCancelSegmentOnNullBitfield() {
|
|
SegmentMan segmentMan;
|
|
|
|
SegmentHandle segment = segmentMan.getSegment(1);
|
|
CPPUNIT_ASSERT(!segment.isNull());
|
|
segmentMan.cancelSegment(1);
|
|
CPPUNIT_ASSERT(!segmentMan.getSegment(1).isNull());
|
|
}
|
|
|