mirror of
https://github.com/aria2/aria2.git
synced 2024-11-30 09:30:48 +00:00
2008-08-24 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Bump up version number of .aria2 control file to 0001. New aria2 can still load version 0000 file but it saves the file in version 0001 format. It means that new aria2 can resume download started by old aria2 but the opposite is not true. * src/DefaultBtProgressInfoFile.cc * src/DefaultBtProgressInfoFile.h * test/DefaultBtProgressInfoFileTest.cc
This commit is contained in:
parent
02dde388b8
commit
335a0fb36f
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
||||
2008-08-24 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Bump up version number of .aria2 control file to 0001.
|
||||
New aria2 can still load version 0000 file but it saves the file in
|
||||
version 0001 format. It means that new aria2 can resume download
|
||||
started by old aria2 but the opposite is not true.
|
||||
* src/DefaultBtProgressInfoFile.cc
|
||||
* src/DefaultBtProgressInfoFile.h
|
||||
* test/DefaultBtProgressInfoFileTest.cc
|
||||
|
||||
2008-08-24 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Added ntoh64 and hton64 as inline functions.
|
||||
|
@ -59,6 +59,7 @@
|
||||
namespace aria2 {
|
||||
|
||||
const std::string DefaultBtProgressInfoFile::V0000("0000");
|
||||
const std::string DefaultBtProgressInfoFile::V0001("0001");
|
||||
|
||||
static std::string createFilename(const SharedHandle<DownloadContext>& dctx)
|
||||
{
|
||||
@ -88,6 +89,7 @@ bool DefaultBtProgressInfoFile::isTorrentDownload()
|
||||
return !dynamic_pointer_cast<BtContext>(_dctx).isNull();
|
||||
}
|
||||
|
||||
// Since version 0001, Integers are saved in binary form, network byte order.
|
||||
void DefaultBtProgressInfoFile::save() {
|
||||
_logger->info(MSG_SAVING_SEGMENT_FILE, _filename.c_str());
|
||||
std::string filenameTemp = _filename+"__temp";
|
||||
@ -96,9 +98,9 @@ void DefaultBtProgressInfoFile::save() {
|
||||
o.exceptions(std::ios::failbit);
|
||||
bool torrentDownload = isTorrentDownload();
|
||||
// file version: 16 bits
|
||||
// value: '0'
|
||||
uint16_t version = 0;
|
||||
o.write(reinterpret_cast<const char*>(&version), sizeof(version));
|
||||
// values: '1'
|
||||
char version[] = { 0x00, 0x01 };
|
||||
o.write(version, sizeof(version));
|
||||
// extension: 32 bits
|
||||
// If this is BitTorrent download, then 0x00000001
|
||||
// Otherwise, 0x00000000
|
||||
@ -112,9 +114,9 @@ void DefaultBtProgressInfoFile::save() {
|
||||
// infoHashLength:
|
||||
// length: 32 bits
|
||||
BtContextHandle btContext(dynamic_pointer_cast<BtContext>(_dctx));
|
||||
uint32_t infoHashLength = btContext->getInfoHashLength();
|
||||
o.write(reinterpret_cast<const char*>(&infoHashLength),
|
||||
sizeof(infoHashLength));
|
||||
uint32_t infoHashLengthNL = htonl(btContext->getInfoHashLength());
|
||||
o.write(reinterpret_cast<const char*>(&infoHashLengthNL),
|
||||
sizeof(infoHashLengthNL));
|
||||
// infoHash:
|
||||
o.write(reinterpret_cast<const char*>(btContext->getInfoHash()),
|
||||
btContext->getInfoHashLength());
|
||||
@ -126,44 +128,47 @@ void DefaultBtProgressInfoFile::save() {
|
||||
sizeof(infoHashLength));
|
||||
}
|
||||
// pieceLength: 32 bits
|
||||
uint32_t pieceLength = _dctx->getPieceLength();
|
||||
o.write(reinterpret_cast<const char*>(&pieceLength), sizeof(pieceLength));
|
||||
uint32_t pieceLengthNL = htonl(_dctx->getPieceLength());
|
||||
o.write(reinterpret_cast<const char*>(&pieceLengthNL),
|
||||
sizeof(pieceLengthNL));
|
||||
// totalLength: 64 bits
|
||||
uint64_t totalLength = _dctx->getTotalLength();
|
||||
o.write(reinterpret_cast<const char*>(&totalLength), sizeof(totalLength));
|
||||
uint64_t totalLengthNL = hton64(_dctx->getTotalLength());
|
||||
o.write(reinterpret_cast<const char*>(&totalLengthNL),
|
||||
sizeof(totalLengthNL));
|
||||
// uploadLength: 64 bits
|
||||
uint64_t uploadLength = 0;
|
||||
uint64_t uploadLengthNL = 0;
|
||||
if(torrentDownload) {
|
||||
BtContextHandle btContext(dynamic_pointer_cast<BtContext>(_dctx));
|
||||
TransferStat stat = PEER_STORAGE(btContext)->calculateStat();
|
||||
uploadLength = stat.getAllTimeUploadLength();
|
||||
uploadLengthNL = hton64(stat.getAllTimeUploadLength());
|
||||
}
|
||||
o.write(reinterpret_cast<const char*>(&uploadLength), sizeof(uploadLength));
|
||||
o.write(reinterpret_cast<const char*>(&uploadLengthNL),
|
||||
sizeof(uploadLengthNL));
|
||||
// bitfieldLength: 32 bits
|
||||
uint32_t bitfieldLength = _pieceStorage->getBitfieldLength();
|
||||
o.write(reinterpret_cast<const char*>(&bitfieldLength),
|
||||
sizeof(bitfieldLength));
|
||||
uint32_t bitfieldLengthNL = htonl(_pieceStorage->getBitfieldLength());
|
||||
o.write(reinterpret_cast<const char*>(&bitfieldLengthNL),
|
||||
sizeof(bitfieldLengthNL));
|
||||
// bitfield
|
||||
o.write(reinterpret_cast<const char*>(_pieceStorage->getBitfield()),
|
||||
_pieceStorage->getBitfieldLength());
|
||||
// the number of in-flight piece: 32 bits
|
||||
// TODO implement this
|
||||
uint32_t numInFlightPiece = _pieceStorage->countInFlightPiece();
|
||||
o.write(reinterpret_cast<const char*>(&numInFlightPiece),
|
||||
sizeof(numInFlightPiece));
|
||||
uint32_t numInFlightPieceNL = htonl(_pieceStorage->countInFlightPiece());
|
||||
o.write(reinterpret_cast<const char*>(&numInFlightPieceNL),
|
||||
sizeof(numInFlightPieceNL));
|
||||
Pieces inFlightPieces;
|
||||
_pieceStorage->getInFlightPieces(inFlightPieces);
|
||||
for(Pieces::const_iterator itr = inFlightPieces.begin();
|
||||
itr != inFlightPieces.end(); ++itr) {
|
||||
uint32_t index = (*itr)->getIndex();
|
||||
o.write(reinterpret_cast<const char*>(&index), sizeof(index));
|
||||
uint32_t length = (*itr)->getLength();
|
||||
o.write(reinterpret_cast<const char*>(&length), sizeof(length));
|
||||
uint32_t bitfieldLength = (*itr)->getBitfieldLength();
|
||||
o.write(reinterpret_cast<const char*>(&bitfieldLength),
|
||||
sizeof(bitfieldLength));
|
||||
uint32_t indexNL = htonl((*itr)->getIndex());
|
||||
o.write(reinterpret_cast<const char*>(&indexNL), sizeof(indexNL));
|
||||
uint32_t lengthNL = htonl((*itr)->getLength());
|
||||
o.write(reinterpret_cast<const char*>(&lengthNL), sizeof(lengthNL));
|
||||
uint32_t bitfieldLengthNL = htonl((*itr)->getBitfieldLength());
|
||||
o.write(reinterpret_cast<const char*>(&bitfieldLengthNL),
|
||||
sizeof(bitfieldLengthNL));
|
||||
o.write(reinterpret_cast<const char*>((*itr)->getBitfield()),
|
||||
bitfieldLength);
|
||||
(*itr)->getBitfieldLength());
|
||||
}
|
||||
|
||||
o.close();
|
||||
@ -179,6 +184,9 @@ void DefaultBtProgressInfoFile::save() {
|
||||
}
|
||||
}
|
||||
|
||||
// It is assumed that integers are saved as:
|
||||
// 1) host byte order if version == 0000
|
||||
// 2) network byte order if version == 0001
|
||||
void DefaultBtProgressInfoFile::load()
|
||||
{
|
||||
_logger->info(MSG_LOADING_SEGMENT_FILE, _filename.c_str());
|
||||
@ -187,13 +195,18 @@ void DefaultBtProgressInfoFile::load()
|
||||
unsigned char* savedBitfield = 0;
|
||||
try {
|
||||
in.exceptions(std::ios::failbit);
|
||||
unsigned char version[2];
|
||||
in.read((char*)version, sizeof(version));
|
||||
if(DefaultBtProgressInfoFile::V0000 !=
|
||||
Util::toHex(version, sizeof(version))) {
|
||||
unsigned char versionBuf[2];
|
||||
in.read((char*)versionBuf, sizeof(versionBuf));
|
||||
std::string versionHex = Util::toHex(versionBuf, sizeof(versionBuf));
|
||||
int version;
|
||||
if(DefaultBtProgressInfoFile::V0000 == versionHex) {
|
||||
version = 0;
|
||||
} else if(DefaultBtProgressInfoFile::V0001 == versionHex) {
|
||||
version = 1;
|
||||
} else {
|
||||
throw DlAbortEx
|
||||
(StringFormat("Unsupported ctrl file version: %s",
|
||||
Util::toHex(version, sizeof(version)).c_str()).str());
|
||||
versionHex.c_str()).str());
|
||||
}
|
||||
unsigned char extension[4];
|
||||
in.read((char*)extension, sizeof(extension));
|
||||
@ -206,6 +219,9 @@ void DefaultBtProgressInfoFile::load()
|
||||
|
||||
uint32_t infoHashLength;
|
||||
in.read(reinterpret_cast<char*>(&infoHashLength), sizeof(infoHashLength));
|
||||
if(version >= 1) {
|
||||
infoHashLength = ntohl(infoHashLength);
|
||||
}
|
||||
if((infoHashLength < 0) ||
|
||||
((infoHashLength == 0) && infoHashCheckEnabled)) {
|
||||
throw DlAbortEx
|
||||
@ -230,9 +246,15 @@ void DefaultBtProgressInfoFile::load()
|
||||
|
||||
uint32_t pieceLength;
|
||||
in.read(reinterpret_cast<char*>(&pieceLength), sizeof(pieceLength));
|
||||
if(version >= 1) {
|
||||
pieceLength = ntohl(pieceLength);
|
||||
}
|
||||
|
||||
uint64_t totalLength;
|
||||
in.read(reinterpret_cast<char*>(&totalLength), sizeof(totalLength));
|
||||
if(version >= 1) {
|
||||
totalLength = ntoh64(totalLength);
|
||||
}
|
||||
if(totalLength != _dctx->getTotalLength()) {
|
||||
throw DlAbortEx
|
||||
(StringFormat("total length mismatch. expected: %s, actual: %s",
|
||||
@ -241,6 +263,9 @@ void DefaultBtProgressInfoFile::load()
|
||||
}
|
||||
uint64_t uploadLength;
|
||||
in.read(reinterpret_cast<char*>(&uploadLength), sizeof(uploadLength));
|
||||
if(version >= 1) {
|
||||
uploadLength = ntoh64(uploadLength);
|
||||
}
|
||||
if(isTorrentDownload()) {
|
||||
BT_RUNTIME(dynamic_pointer_cast<BtContext>(_dctx))->
|
||||
setUploadLengthAtStartup(uploadLength);
|
||||
@ -249,6 +274,9 @@ void DefaultBtProgressInfoFile::load()
|
||||
// TODO implement the conversion mechanism between different piece length.
|
||||
uint32_t bitfieldLength;
|
||||
in.read(reinterpret_cast<char*>(&bitfieldLength), sizeof(bitfieldLength));
|
||||
if(version >= 1) {
|
||||
bitfieldLength = ntohl(bitfieldLength);
|
||||
}
|
||||
uint32_t expectedBitfieldLength =
|
||||
((totalLength+pieceLength-1)/pieceLength+7)/8;
|
||||
if(expectedBitfieldLength != bitfieldLength) {
|
||||
@ -269,17 +297,25 @@ void DefaultBtProgressInfoFile::load()
|
||||
uint32_t numInFlightPiece;
|
||||
in.read(reinterpret_cast<char*>(&numInFlightPiece),
|
||||
sizeof(numInFlightPiece));
|
||||
|
||||
if(version >= 1) {
|
||||
numInFlightPiece = ntohl(numInFlightPiece);
|
||||
}
|
||||
Pieces inFlightPieces;
|
||||
while(numInFlightPiece--) {
|
||||
uint32_t index;
|
||||
in.read(reinterpret_cast<char*>(&index), sizeof(index));
|
||||
if(version >= 1) {
|
||||
index = ntohl(index);
|
||||
}
|
||||
if(!(index < _dctx->getNumPieces())) {
|
||||
throw DlAbortEx
|
||||
(StringFormat("piece index out of range: %u", index).str());
|
||||
}
|
||||
uint32_t length;
|
||||
in.read(reinterpret_cast<char*>(&length), sizeof(length));
|
||||
if(version >= 1) {
|
||||
length = ntohl(length);
|
||||
}
|
||||
if(!(length <=_dctx->getPieceLength())) {
|
||||
throw DlAbortEx
|
||||
(StringFormat("piece length out of range: %u", length).str());
|
||||
@ -288,6 +324,9 @@ void DefaultBtProgressInfoFile::load()
|
||||
uint32_t bitfieldLength;
|
||||
in.read(reinterpret_cast<char*>(&bitfieldLength),
|
||||
sizeof(bitfieldLength));
|
||||
if(version >= 1) {
|
||||
bitfieldLength = ntohl(bitfieldLength);
|
||||
}
|
||||
if(piece->getBitfieldLength() != bitfieldLength) {
|
||||
throw DlAbortEx
|
||||
(StringFormat("piece bitfield length mismatch."
|
||||
@ -314,6 +353,9 @@ void DefaultBtProgressInfoFile::load()
|
||||
uint32_t numInFlightPiece;
|
||||
in.read(reinterpret_cast<char*>(&numInFlightPiece),
|
||||
sizeof(numInFlightPiece));
|
||||
if(version >= 1) {
|
||||
numInFlightPiece = ntohl(numInFlightPiece);
|
||||
}
|
||||
BitfieldMan src(pieceLength, totalLength);
|
||||
src.setBitfield(savedBitfield, bitfieldLength);
|
||||
if((src.getCompletedLength() || numInFlightPiece) &&
|
||||
|
@ -55,6 +55,7 @@ private:
|
||||
bool isTorrentDownload();
|
||||
|
||||
static const std::string V0000;
|
||||
static const std::string V0001;
|
||||
public:
|
||||
DefaultBtProgressInfoFile(const SharedHandle<DownloadContext>& btContext,
|
||||
const SharedHandle<PieceStorage>& pieceStorage,
|
||||
|
@ -24,9 +24,11 @@ class DefaultBtProgressInfoFileTest:public CppUnit::TestFixture {
|
||||
#ifdef ENABLE_BITTORRENT
|
||||
CPPUNIT_TEST(testSave);
|
||||
CPPUNIT_TEST(testLoad);
|
||||
CPPUNIT_TEST(testLoad_compat);
|
||||
#endif // ENABLE_BITTORRENT
|
||||
CPPUNIT_TEST(testSave_nonBt);
|
||||
CPPUNIT_TEST(testLoad_nonBt);
|
||||
CPPUNIT_TEST(testLoad_nonBt_compat);
|
||||
CPPUNIT_TEST(testLoad_nonBt_pieceLengthShorter);
|
||||
CPPUNIT_TEST(testUpdateFilename);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
@ -85,8 +87,10 @@ public:
|
||||
|
||||
void testSave();
|
||||
void testLoad();
|
||||
void testLoad_compat();
|
||||
void testSave_nonBt();
|
||||
void testLoad_nonBt();
|
||||
void testLoad_nonBt_compat();
|
||||
void testLoad_nonBt_pieceLengthShorter();
|
||||
void testUpdateFilename();
|
||||
};
|
||||
@ -98,7 +102,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(DefaultBtProgressInfoFileTest);
|
||||
|
||||
#ifdef ENABLE_BITTORRENT
|
||||
|
||||
void DefaultBtProgressInfoFileTest::testLoad()
|
||||
void DefaultBtProgressInfoFileTest::testLoad_compat()
|
||||
{
|
||||
initializeMembers(1024, 81920);
|
||||
|
||||
@ -114,6 +118,57 @@ void DefaultBtProgressInfoFileTest::testLoad()
|
||||
|
||||
// check the contents of objects
|
||||
|
||||
// total length
|
||||
CPPUNIT_ASSERT_EQUAL((uint64_t)81920, _btContext->getTotalLength());
|
||||
|
||||
// upload length
|
||||
CPPUNIT_ASSERT_EQUAL((uint64_t)1024, BT_RUNTIME(_btContext)->getUploadLengthAtStartup());
|
||||
|
||||
// bitfield
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffe"),
|
||||
Util::toHex(_bitfield->getBitfield(), _bitfield->getBitfieldLength()));
|
||||
|
||||
// the number of in-flight pieces
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2,
|
||||
_pieceStorage->countInFlightPiece());
|
||||
|
||||
// piece index 1
|
||||
std::deque<SharedHandle<Piece> > inFlightPieces;
|
||||
_pieceStorage->getInFlightPieces(inFlightPieces);
|
||||
|
||||
SharedHandle<Piece> piece1 = inFlightPieces[0];
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1024, piece1->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getBitfieldLength());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("00"), Util::toHex(piece1->getBitfield(),
|
||||
piece1->getBitfieldLength()));
|
||||
|
||||
// piece index 2
|
||||
SharedHandle<Piece> piece2 = inFlightPieces[1];
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, piece2->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)512, piece2->getLength());
|
||||
}
|
||||
|
||||
void DefaultBtProgressInfoFileTest::testLoad()
|
||||
{
|
||||
initializeMembers(1024, 81920);
|
||||
|
||||
_btContext->setName("load-v0001");
|
||||
_btContext->setPieceLength(1024);
|
||||
_btContext->setTotalLength(81920);
|
||||
_btContext->setNumPieces(80);
|
||||
|
||||
DefaultBtProgressInfoFile infoFile(_btContext, _pieceStorage, _option.get());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("./load-v0001.aria2"),
|
||||
infoFile.getFilename());
|
||||
|
||||
infoFile.load();
|
||||
|
||||
// check the contents of objects
|
||||
|
||||
// total length
|
||||
CPPUNIT_ASSERT_EQUAL((uint64_t)81920, _btContext->getTotalLength());
|
||||
|
||||
// upload length
|
||||
CPPUNIT_ASSERT_EQUAL((uint64_t)1024, BT_RUNTIME(_btContext)->getUploadLengthAtStartup());
|
||||
|
||||
@ -175,7 +230,8 @@ void DefaultBtProgressInfoFileTest::testSave()
|
||||
|
||||
unsigned char version[2];
|
||||
in.read((char*)version, sizeof(version));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("0000"), Util::toHex(version, sizeof(version)));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("0001"),
|
||||
Util::toHex(version, sizeof(version)));
|
||||
|
||||
unsigned char extension[4];
|
||||
in.read((char*)extension, sizeof(extension));
|
||||
@ -183,6 +239,7 @@ void DefaultBtProgressInfoFileTest::testSave()
|
||||
|
||||
uint32_t infoHashLength;
|
||||
in.read(reinterpret_cast<char*>(&infoHashLength), sizeof(infoHashLength));
|
||||
infoHashLength = ntohl(infoHashLength);
|
||||
CPPUNIT_ASSERT_EQUAL((uint32_t)20, infoHashLength);
|
||||
|
||||
unsigned char infoHashRead[20];
|
||||
@ -192,18 +249,22 @@ void DefaultBtProgressInfoFileTest::testSave()
|
||||
|
||||
uint32_t pieceLength;
|
||||
in.read((char*)&pieceLength, sizeof(pieceLength));
|
||||
pieceLength = ntohl(pieceLength);
|
||||
CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength);
|
||||
|
||||
uint64_t totalLength;
|
||||
in.read((char*)&totalLength, sizeof(totalLength));
|
||||
totalLength = ntoh64(totalLength);
|
||||
CPPUNIT_ASSERT_EQUAL((uint64_t)81920/* 80*1024 */, totalLength);
|
||||
|
||||
uint64_t uploadLength;
|
||||
in.read((char*)&uploadLength, sizeof(uploadLength));
|
||||
uploadLength = ntoh64(uploadLength);
|
||||
CPPUNIT_ASSERT_EQUAL((uint64_t)1024, uploadLength);
|
||||
|
||||
uint32_t bitfieldLength;
|
||||
in.read((char*)&bitfieldLength, sizeof(bitfieldLength));
|
||||
bitfieldLength = ntohl(bitfieldLength);
|
||||
CPPUNIT_ASSERT_EQUAL((uint32_t)10, bitfieldLength);
|
||||
|
||||
unsigned char bitfieldRead[10];
|
||||
@ -213,19 +274,23 @@ void DefaultBtProgressInfoFileTest::testSave()
|
||||
|
||||
uint32_t numInFlightPiece;
|
||||
in.read((char*)&numInFlightPiece, sizeof(numInFlightPiece));
|
||||
numInFlightPiece = ntohl(numInFlightPiece);
|
||||
CPPUNIT_ASSERT_EQUAL((uint32_t)2, numInFlightPiece);
|
||||
|
||||
// piece index 1
|
||||
uint32_t index1;
|
||||
in.read((char*)&index1, sizeof(index1));
|
||||
index1 = ntohl(index1);
|
||||
CPPUNIT_ASSERT_EQUAL((uint32_t)1, index1);
|
||||
|
||||
uint32_t pieceLength1;
|
||||
in.read((char*)&pieceLength1, sizeof(pieceLength1));
|
||||
pieceLength1 = ntohl(pieceLength1);
|
||||
CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength1);
|
||||
|
||||
uint32_t pieceBitfieldLength1;
|
||||
in.read((char*)&pieceBitfieldLength1, sizeof(pieceBitfieldLength1));
|
||||
pieceBitfieldLength1 = ntohl(pieceBitfieldLength1);
|
||||
CPPUNIT_ASSERT_EQUAL((uint32_t)1, pieceBitfieldLength1);
|
||||
|
||||
unsigned char pieceBitfield1[1];
|
||||
@ -236,18 +301,18 @@ void DefaultBtProgressInfoFileTest::testSave()
|
||||
// piece index 2
|
||||
uint32_t index2;
|
||||
in.read((char*)&index2, sizeof(index2));
|
||||
index2 = ntohl(index2);
|
||||
CPPUNIT_ASSERT_EQUAL((uint32_t)2, index2);
|
||||
|
||||
uint32_t pieceLength2;
|
||||
in.read((char*)&pieceLength2, sizeof(pieceLength2));
|
||||
pieceLength2 = ntohl(pieceLength2);
|
||||
CPPUNIT_ASSERT_EQUAL((uint32_t)512, pieceLength2);
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // ENABLE_BITTORRENT
|
||||
|
||||
void DefaultBtProgressInfoFileTest::testLoad_nonBt()
|
||||
void DefaultBtProgressInfoFileTest::testLoad_nonBt_compat()
|
||||
{
|
||||
initializeMembers(1024, 81920);
|
||||
|
||||
@ -260,6 +325,9 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt()
|
||||
|
||||
// check the contents of objects
|
||||
|
||||
// total length
|
||||
CPPUNIT_ASSERT_EQUAL((uint64_t)81920, dctx->getTotalLength());
|
||||
|
||||
// bitfield
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffe"),
|
||||
Util::toHex(_bitfield->getBitfield(), _bitfield->getBitfieldLength()));
|
||||
@ -283,7 +351,48 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt()
|
||||
SharedHandle<Piece> piece2 = inFlightPieces[1];
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, piece2->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)512, piece2->getLength());
|
||||
}
|
||||
|
||||
void DefaultBtProgressInfoFileTest::testLoad_nonBt()
|
||||
{
|
||||
initializeMembers(1024, 81920);
|
||||
|
||||
SharedHandle<SingleFileDownloadContext> dctx
|
||||
(new SingleFileDownloadContext(1024, 81920, "load-nonBt-v0001"));
|
||||
|
||||
DefaultBtProgressInfoFile infoFile(dctx, _pieceStorage, _option.get());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("./load-nonBt-v0001.aria2"),
|
||||
infoFile.getFilename());
|
||||
infoFile.load();
|
||||
|
||||
// check the contents of objects
|
||||
|
||||
// total length
|
||||
CPPUNIT_ASSERT_EQUAL((uint64_t)81920, dctx->getTotalLength());
|
||||
|
||||
// bitfield
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffe"),
|
||||
Util::toHex(_bitfield->getBitfield(), _bitfield->getBitfieldLength()));
|
||||
|
||||
// the number of in-flight pieces
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2,
|
||||
_pieceStorage->countInFlightPiece());
|
||||
|
||||
// piece index 1
|
||||
std::deque<SharedHandle<Piece> > inFlightPieces;
|
||||
_pieceStorage->getInFlightPieces(inFlightPieces);
|
||||
|
||||
SharedHandle<Piece> piece1 = inFlightPieces[0];
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1024, piece1->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getBitfieldLength());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("00"), Util::toHex(piece1->getBitfield(),
|
||||
piece1->getBitfieldLength()));
|
||||
|
||||
// piece index 2
|
||||
SharedHandle<Piece> piece2 = inFlightPieces[1];
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, piece2->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)512, piece2->getLength());
|
||||
}
|
||||
|
||||
void DefaultBtProgressInfoFileTest::testLoad_nonBt_pieceLengthShorter()
|
||||
@ -292,10 +401,11 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt_pieceLengthShorter()
|
||||
_option->put(PREF_ALLOW_PIECE_LENGTH_CHANGE, V_TRUE);
|
||||
|
||||
SharedHandle<SingleFileDownloadContext> dctx
|
||||
(new SingleFileDownloadContext(512, 81920, "load-nonBt"));
|
||||
(new SingleFileDownloadContext(512, 81920, "load-nonBt-v0001"));
|
||||
|
||||
DefaultBtProgressInfoFile infoFile(dctx, _pieceStorage, _option.get());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("./load-nonBt.aria2"), infoFile.getFilename());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("./load-nonBt-v0001.aria2"),
|
||||
infoFile.getFilename());
|
||||
infoFile.load();
|
||||
|
||||
// check the contents of objects
|
||||
@ -339,7 +449,8 @@ void DefaultBtProgressInfoFileTest::testSave_nonBt()
|
||||
|
||||
unsigned char version[2];
|
||||
in.read((char*)version, sizeof(version));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("0000"), Util::toHex(version, sizeof(version)));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("0001"),
|
||||
Util::toHex(version, sizeof(version)));
|
||||
|
||||
unsigned char extension[4];
|
||||
in.read((char*)extension, sizeof(extension));
|
||||
@ -347,22 +458,27 @@ void DefaultBtProgressInfoFileTest::testSave_nonBt()
|
||||
|
||||
uint32_t infoHashLength;
|
||||
in.read(reinterpret_cast<char*>(&infoHashLength), sizeof(infoHashLength));
|
||||
infoHashLength = ntohl(infoHashLength);
|
||||
CPPUNIT_ASSERT_EQUAL((uint32_t)0, infoHashLength);
|
||||
|
||||
uint32_t pieceLength;
|
||||
in.read((char*)&pieceLength, sizeof(pieceLength));
|
||||
pieceLength = ntohl(pieceLength);
|
||||
CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength);
|
||||
|
||||
uint64_t totalLength;
|
||||
in.read((char*)&totalLength, sizeof(totalLength));
|
||||
totalLength = ntoh64(totalLength);
|
||||
CPPUNIT_ASSERT_EQUAL((uint64_t)81920/* 80*1024 */, totalLength);
|
||||
|
||||
uint64_t uploadLength;
|
||||
in.read((char*)&uploadLength, sizeof(uploadLength));
|
||||
uploadLength = ntoh64(uploadLength);
|
||||
CPPUNIT_ASSERT_EQUAL((uint64_t)0, uploadLength);
|
||||
|
||||
uint32_t bitfieldLength;
|
||||
in.read((char*)&bitfieldLength, sizeof(bitfieldLength));
|
||||
bitfieldLength = ntohl(bitfieldLength);
|
||||
CPPUNIT_ASSERT_EQUAL((uint32_t)10, bitfieldLength);
|
||||
|
||||
unsigned char bitfieldRead[10];
|
||||
@ -372,19 +488,23 @@ void DefaultBtProgressInfoFileTest::testSave_nonBt()
|
||||
|
||||
uint32_t numInFlightPiece;
|
||||
in.read((char*)&numInFlightPiece, sizeof(numInFlightPiece));
|
||||
numInFlightPiece = ntohl(numInFlightPiece);
|
||||
CPPUNIT_ASSERT_EQUAL((uint32_t)2, numInFlightPiece);
|
||||
|
||||
// piece index 1
|
||||
uint32_t index1;
|
||||
in.read((char*)&index1, sizeof(index1));
|
||||
index1 = ntohl(index1);
|
||||
CPPUNIT_ASSERT_EQUAL((uint32_t)1, index1);
|
||||
|
||||
uint32_t pieceLength1;
|
||||
in.read((char*)&pieceLength1, sizeof(pieceLength1));
|
||||
pieceLength1 = ntohl(pieceLength1);
|
||||
CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength1);
|
||||
|
||||
uint32_t pieceBitfieldLength1;
|
||||
in.read((char*)&pieceBitfieldLength1, sizeof(pieceBitfieldLength1));
|
||||
pieceBitfieldLength1 = ntohl(pieceBitfieldLength1);
|
||||
CPPUNIT_ASSERT_EQUAL((uint32_t)1, pieceBitfieldLength1);
|
||||
|
||||
unsigned char pieceBitfield1[1];
|
||||
@ -395,10 +515,12 @@ void DefaultBtProgressInfoFileTest::testSave_nonBt()
|
||||
// piece index 2
|
||||
uint32_t index2;
|
||||
in.read((char*)&index2, sizeof(index2));
|
||||
index2 = ntohl(index2);
|
||||
CPPUNIT_ASSERT_EQUAL((uint32_t)2, index2);
|
||||
|
||||
uint32_t pieceLength2;
|
||||
in.read((char*)&pieceLength2, sizeof(pieceLength2));
|
||||
pieceLength2 = ntohl(pieceLength2);
|
||||
CPPUNIT_ASSERT_EQUAL((uint32_t)512, pieceLength2);
|
||||
|
||||
}
|
||||
|
BIN
test/load-nonBt-v0001.aria2
Normal file
BIN
test/load-nonBt-v0001.aria2
Normal file
Binary file not shown.
BIN
test/load-v0001.aria2
Normal file
BIN
test/load-v0001.aria2
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user