2008-05-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Fixed compile error when configured with --without-gnutls
	--without-openssl
	* src/main.cc
	* test/DefaultBtProgressInfoFileTest.cc
	* test/SegmentManTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-05-20 00:42:34 +00:00
parent bbd2a995db
commit a70a747c23
4 changed files with 138 additions and 118 deletions

View File

@ -1,3 +1,11 @@
2008-05-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Fixed compile error when configured with --without-gnutls
--without-openssl
* src/main.cc
* test/DefaultBtProgressInfoFileTest.cc
* test/SegmentManTest.cc
2008-05-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Fixed compile error with OpenSSL.
@ -10838,4 +10846,4 @@
2006-02-17 Tatsuhiro Tsujikawa <tsujikawa at rednoah dot com>
* Release 0.1.0

View File

@ -66,6 +66,7 @@
#include "NullStatCalc.h"
#include "StringFormat.h"
#include "A2STR.h"
#include "RecoverableException.h"
#ifdef ENABLE_METALINK
# include "MetalinkHelper.h"
# include "Metalink2RequestGroup.h"

View File

@ -2,7 +2,9 @@
#include "Option.h"
#include "Util.h"
#include "Exception.h"
#ifdef ENABLE_BITTORRENT
#include "MockBtContext.h"
#endif // ENABLE_BITTORRENT
#include "MockPeerStorage.h"
#include "MockPieceStorage.h"
#include "BtRuntime.h"
@ -19,15 +21,21 @@ namespace aria2 {
class DefaultBtProgressInfoFileTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(DefaultBtProgressInfoFileTest);
#ifdef ENABLE_BITTORRENT
CPPUNIT_TEST(testSave);
CPPUNIT_TEST(testSave_nonBt);
CPPUNIT_TEST(testLoad);
#endif // ENABLE_BITTORRENT
CPPUNIT_TEST(testSave_nonBt);
CPPUNIT_TEST(testLoad_nonBt);
CPPUNIT_TEST(testLoad_nonBt_pieceLengthShorter);
CPPUNIT_TEST(testUpdateFilename);
CPPUNIT_TEST_SUITE_END();
private:
#ifdef ENABLE_BITTORRENT
SharedHandle<MockBtContext> _btContext;
#endif // ENABLE_BITTORRENT
SharedHandle<MockPieceStorage> _pieceStorage;
SharedHandle<Option> _option;
SharedHandle<BitfieldMan> _bitfield;
@ -38,22 +46,23 @@ public:
void initializeMembers(int32_t pieceLength, int64_t totalLength)
{
static unsigned char infoHash[] = {
0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa,
0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff,
};
_option.reset(new Option());
_option->put(PREF_DIR, ".");
_btContext.reset(new MockBtContext());
_btContext->setInfoHash(infoHash);
_bitfield.reset(new BitfieldMan(pieceLength, totalLength));
_pieceStorage.reset(new MockPieceStorage());
_pieceStorage->setBitfield(_bitfield.get());
#ifdef ENABLE_BITTORRENT
static unsigned char infoHash[] = {
0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa,
0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff,
};
_btContext.reset(new MockBtContext());
_btContext->setInfoHash(infoHash);
SharedHandle<MockPeerStorage> peerStorage(new MockPeerStorage());
SharedHandle<BtRuntime> btRuntime(new BtRuntime());
@ -66,6 +75,7 @@ public:
peerStorage);
BtRegistry::registerBtRuntime(_btContext->getInfoHashAsString(),
btRuntime);
#endif // ENABLE_BITTORRENT
}
void tearDown()
@ -86,6 +96,8 @@ public:
CPPUNIT_TEST_SUITE_REGISTRATION(DefaultBtProgressInfoFileTest);
#ifdef ENABLE_BITTORRENT
void DefaultBtProgressInfoFileTest::testLoad()
{
initializeMembers(1024, 81920);
@ -130,6 +142,111 @@ void DefaultBtProgressInfoFileTest::testLoad()
CPPUNIT_ASSERT_EQUAL((size_t)512, piece2->getLength());
}
void DefaultBtProgressInfoFileTest::testSave()
{
initializeMembers(1024, 81920);
_btContext->setName("save-temp");
_btContext->setPieceLength(1024);
_btContext->setTotalLength(81920);
_bitfield->setAllBit();
_bitfield->unsetBit(79);
_pieceStorage->setCompletedLength(80896);
TransferStat stat;
stat.setAllTimeUploadLength(1024);
dynamic_pointer_cast<MockPeerStorage>(PEER_STORAGE(_btContext))->setStat(stat);
SharedHandle<Piece> p1(new Piece(1, 1024));
SharedHandle<Piece> p2(new Piece(2, 512));
std::deque<SharedHandle<Piece> > inFlightPieces;
inFlightPieces.push_back(p1);
inFlightPieces.push_back(p2);
_pieceStorage->addInFlightPiece(inFlightPieces);
DefaultBtProgressInfoFile infoFile(_btContext, _pieceStorage, _option.get());
CPPUNIT_ASSERT_EQUAL(std::string("./save-temp.aria2"), infoFile.getFilename());
infoFile.save();
// read and validate
std::ifstream in(infoFile.getFilename().c_str());
//in.exceptions(ios::failbit);
unsigned char version[2];
in.read((char*)version, sizeof(version));
CPPUNIT_ASSERT_EQUAL(std::string("0000"), Util::toHex(version, sizeof(version)));
unsigned char extension[4];
in.read((char*)extension, sizeof(extension));
CPPUNIT_ASSERT_EQUAL(std::string("00000001"), Util::toHex(extension, sizeof(extension)));
uint32_t infoHashLength;
in.read(reinterpret_cast<char*>(&infoHashLength), sizeof(infoHashLength));
CPPUNIT_ASSERT_EQUAL((uint32_t)20, infoHashLength);
unsigned char infoHashRead[20];
in.read((char*)infoHashRead, sizeof(infoHashRead));
CPPUNIT_ASSERT_EQUAL(std::string("112233445566778899aabbccddeeff00ffffffff"),
Util::toHex(infoHashRead, sizeof(infoHashRead)));
uint32_t pieceLength;
in.read((char*)&pieceLength, sizeof(pieceLength));
CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength);
uint64_t totalLength;
in.read((char*)&totalLength, sizeof(totalLength));
CPPUNIT_ASSERT_EQUAL((uint64_t)81920/* 80*1024 */, totalLength);
uint64_t uploadLength;
in.read((char*)&uploadLength, sizeof(uploadLength));
CPPUNIT_ASSERT_EQUAL((uint64_t)1024, uploadLength);
uint32_t bitfieldLength;
in.read((char*)&bitfieldLength, sizeof(bitfieldLength));
CPPUNIT_ASSERT_EQUAL((uint32_t)10, bitfieldLength);
unsigned char bitfieldRead[10];
in.read((char*)bitfieldRead, sizeof(bitfieldRead));
CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffe"),
Util::toHex(bitfieldRead, sizeof(bitfieldRead)));
uint32_t numInFlightPiece;
in.read((char*)&numInFlightPiece, sizeof(numInFlightPiece));
CPPUNIT_ASSERT_EQUAL((uint32_t)2, numInFlightPiece);
// piece index 1
uint32_t index1;
in.read((char*)&index1, sizeof(index1));
CPPUNIT_ASSERT_EQUAL((uint32_t)1, index1);
uint32_t pieceLength1;
in.read((char*)&pieceLength1, sizeof(pieceLength1));
CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength1);
uint32_t pieceBitfieldLength1;
in.read((char*)&pieceBitfieldLength1, sizeof(pieceBitfieldLength1));
CPPUNIT_ASSERT_EQUAL((uint32_t)1, pieceBitfieldLength1);
unsigned char pieceBitfield1[1];
in.read((char*)pieceBitfield1, sizeof(pieceBitfield1));
CPPUNIT_ASSERT_EQUAL(std::string("00"),
Util::toHex(pieceBitfield1, sizeof(pieceBitfield1)));
// piece index 2
uint32_t index2;
in.read((char*)&index2, sizeof(index2));
CPPUNIT_ASSERT_EQUAL((uint32_t)2, index2);
uint32_t pieceLength2;
in.read((char*)&pieceLength2, sizeof(pieceLength2));
CPPUNIT_ASSERT_EQUAL((uint32_t)512, pieceLength2);
}
#endif // ENABLE_BITTORRENT
void DefaultBtProgressInfoFileTest::testLoad_nonBt()
{
initializeMembers(1024, 81920);
@ -286,109 +403,6 @@ void DefaultBtProgressInfoFileTest::testSave_nonBt()
}
void DefaultBtProgressInfoFileTest::testSave()
{
initializeMembers(1024, 81920);
_btContext->setName("save-temp");
_btContext->setPieceLength(1024);
_btContext->setTotalLength(81920);
_bitfield->setAllBit();
_bitfield->unsetBit(79);
_pieceStorage->setCompletedLength(80896);
TransferStat stat;
stat.setAllTimeUploadLength(1024);
dynamic_pointer_cast<MockPeerStorage>(PEER_STORAGE(_btContext))->setStat(stat);
SharedHandle<Piece> p1(new Piece(1, 1024));
SharedHandle<Piece> p2(new Piece(2, 512));
std::deque<SharedHandle<Piece> > inFlightPieces;
inFlightPieces.push_back(p1);
inFlightPieces.push_back(p2);
_pieceStorage->addInFlightPiece(inFlightPieces);
DefaultBtProgressInfoFile infoFile(_btContext, _pieceStorage, _option.get());
CPPUNIT_ASSERT_EQUAL(std::string("./save-temp.aria2"), infoFile.getFilename());
infoFile.save();
// read and validate
std::ifstream in(infoFile.getFilename().c_str());
//in.exceptions(ios::failbit);
unsigned char version[2];
in.read((char*)version, sizeof(version));
CPPUNIT_ASSERT_EQUAL(std::string("0000"), Util::toHex(version, sizeof(version)));
unsigned char extension[4];
in.read((char*)extension, sizeof(extension));
CPPUNIT_ASSERT_EQUAL(std::string("00000001"), Util::toHex(extension, sizeof(extension)));
uint32_t infoHashLength;
in.read(reinterpret_cast<char*>(&infoHashLength), sizeof(infoHashLength));
CPPUNIT_ASSERT_EQUAL((uint32_t)20, infoHashLength);
unsigned char infoHashRead[20];
in.read((char*)infoHashRead, sizeof(infoHashRead));
CPPUNIT_ASSERT_EQUAL(std::string("112233445566778899aabbccddeeff00ffffffff"),
Util::toHex(infoHashRead, sizeof(infoHashRead)));
uint32_t pieceLength;
in.read((char*)&pieceLength, sizeof(pieceLength));
CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength);
uint64_t totalLength;
in.read((char*)&totalLength, sizeof(totalLength));
CPPUNIT_ASSERT_EQUAL((uint64_t)81920/* 80*1024 */, totalLength);
uint64_t uploadLength;
in.read((char*)&uploadLength, sizeof(uploadLength));
CPPUNIT_ASSERT_EQUAL((uint64_t)1024, uploadLength);
uint32_t bitfieldLength;
in.read((char*)&bitfieldLength, sizeof(bitfieldLength));
CPPUNIT_ASSERT_EQUAL((uint32_t)10, bitfieldLength);
unsigned char bitfieldRead[10];
in.read((char*)bitfieldRead, sizeof(bitfieldRead));
CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffe"),
Util::toHex(bitfieldRead, sizeof(bitfieldRead)));
uint32_t numInFlightPiece;
in.read((char*)&numInFlightPiece, sizeof(numInFlightPiece));
CPPUNIT_ASSERT_EQUAL((uint32_t)2, numInFlightPiece);
// piece index 1
uint32_t index1;
in.read((char*)&index1, sizeof(index1));
CPPUNIT_ASSERT_EQUAL((uint32_t)1, index1);
uint32_t pieceLength1;
in.read((char*)&pieceLength1, sizeof(pieceLength1));
CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength1);
uint32_t pieceBitfieldLength1;
in.read((char*)&pieceBitfieldLength1, sizeof(pieceBitfieldLength1));
CPPUNIT_ASSERT_EQUAL((uint32_t)1, pieceBitfieldLength1);
unsigned char pieceBitfield1[1];
in.read((char*)pieceBitfield1, sizeof(pieceBitfield1));
CPPUNIT_ASSERT_EQUAL(std::string("00"),
Util::toHex(pieceBitfield1, sizeof(pieceBitfield1)));
// piece index 2
uint32_t index2;
in.read((char*)&index2, sizeof(index2));
CPPUNIT_ASSERT_EQUAL((uint32_t)2, index2);
uint32_t pieceLength2;
in.read((char*)&pieceLength2, sizeof(pieceLength2));
CPPUNIT_ASSERT_EQUAL((uint32_t)512, pieceLength2);
}
void DefaultBtProgressInfoFileTest::testUpdateFilename()
{
SharedHandle<SingleFileDownloadContext> dctx

View File

@ -7,7 +7,6 @@
#include "DefaultPieceStorage.h"
#include "Segment.h"
#include "Option.h"
#include "MockBtContext.h"
#include "FileEntry.h"
#include <cppunit/extensions/HelperMacros.h>
@ -62,10 +61,8 @@ void SegmentManTest::testCompleteSegment()
Option op;
size_t pieceLength = 1024*1024;
uint64_t totalLength = 64*1024*1024;
SharedHandle<MockBtContext> dctx(new MockBtContext());
dctx->setPieceLength(pieceLength);
dctx->setTotalLength(totalLength);
dctx->setNumPieces((totalLength+pieceLength-1)/pieceLength);
SharedHandle<SingleFileDownloadContext> dctx
(new SingleFileDownloadContext(pieceLength, totalLength, "aria2.tar.bz2"));
SharedHandle<DefaultPieceStorage> ps(new DefaultPieceStorage(dctx, &op));
SegmentMan segmentMan(&op, dctx, ps);