2009-12-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Fixed compile error if ENABLE_BITTORRENT is undefined.
	* src/DefaultPieceStorage.cc
	* src/DefaultPieceStorage.h
	* src/PieceStorage.h
	* src/UnknownLengthPieceStorage.cc
	* src/UnknownLengthPieceStorage.h
	* test/MockPieceStorage.h
	* test/ProtocolDetectorTest.cc
	* test/XmlRpcMethodTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2009-12-05 11:35:18 +00:00
parent 66e864daf2
commit 9a6a73dd96
9 changed files with 62 additions and 24 deletions

View File

@ -1,3 +1,15 @@
2009-12-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed compile error if ENABLE_BITTORRENT is undefined.
* src/DefaultPieceStorage.cc
* src/DefaultPieceStorage.h
* src/PieceStorage.h
* src/UnknownLengthPieceStorage.cc
* src/UnknownLengthPieceStorage.h
* test/MockPieceStorage.h
* test/ProtocolDetectorTest.cc
* test/XmlRpcMethodTest.cc
2009-12-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2009-12-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Documented in man page that if getifaddrs() is missing, Documented in man page that if getifaddrs() is missing,

View File

@ -196,12 +196,6 @@ bool DefaultPieceStorage::hasMissingPiece(const PeerHandle& peer)
peer->getBitfieldLength()); peer->getBitfieldLength());
} }
bool DefaultPieceStorage::hasMissingUnusedPiece()
{
size_t index;
return bitfieldMan->getFirstMissingUnusedIndex(index);
}
PieceHandle DefaultPieceStorage::getMissingPiece(const SharedHandle<Peer>& peer) PieceHandle DefaultPieceStorage::getMissingPiece(const SharedHandle<Peer>& peer)
{ {
return getMissingPiece(peer->getBitfield(), peer->getBitfieldLength()); return getMissingPiece(peer->getBitfield(), peer->getBitfieldLength());
@ -267,6 +261,12 @@ SharedHandle<Piece> DefaultPieceStorage::getMissingFastPiece
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
bool DefaultPieceStorage::hasMissingUnusedPiece()
{
size_t index;
return bitfieldMan->getFirstMissingUnusedIndex(index);
}
PieceHandle DefaultPieceStorage::getSparseMissingUnusedPiece PieceHandle DefaultPieceStorage::getSparseMissingUnusedPiece
(const unsigned char* ignoreBitfield, size_t length) (const unsigned char* ignoreBitfield, size_t length)
{ {

View File

@ -121,8 +121,6 @@ public:
virtual bool hasMissingPiece(const SharedHandle<Peer>& peer); virtual bool hasMissingPiece(const SharedHandle<Peer>& peer);
virtual bool hasMissingUnusedPiece();
virtual SharedHandle<Piece> getMissingPiece(const SharedHandle<Peer>& peer); virtual SharedHandle<Piece> getMissingPiece(const SharedHandle<Peer>& peer);
virtual SharedHandle<Piece> getMissingFastPiece(const SharedHandle<Peer>& peer); virtual SharedHandle<Piece> getMissingFastPiece(const SharedHandle<Peer>& peer);
@ -135,6 +133,8 @@ public:
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
virtual bool hasMissingUnusedPiece();
virtual SharedHandle<Piece> getSparseMissingUnusedPiece virtual SharedHandle<Piece> getSparseMissingUnusedPiece
(const unsigned char* ignoreBitfield, size_t length); (const unsigned char* ignoreBitfield, size_t length);

View File

@ -62,8 +62,6 @@ public:
*/ */
virtual bool hasMissingPiece(const SharedHandle<Peer>& peer) = 0; virtual bool hasMissingPiece(const SharedHandle<Peer>& peer) = 0;
virtual bool hasMissingUnusedPiece() = 0;
/** /**
* Returns a piece that the peer has but localhost doesn't. * Returns a piece that the peer has but localhost doesn't.
* The piece will be marked "used" status in order to prevent other command * The piece will be marked "used" status in order to prevent other command
@ -101,6 +99,9 @@ public:
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
// Returns true if there is at least one missing and unused piece.
virtual bool hasMissingUnusedPiece() = 0;
/** /**
* Returns a missing piece if available. Otherwise returns 0; * Returns a missing piece if available. Otherwise returns 0;
* If ignoreBitfield is set, indexes of true bit are excluded. * If ignoreBitfield is set, indexes of true bit are excluded.

View File

@ -78,11 +78,6 @@ bool UnknownLengthPieceStorage::hasMissingPiece(const SharedHandle<Peer>& peer)
abort(); abort();
} }
bool UnknownLengthPieceStorage::hasMissingUnusedPiece()
{
abort();
}
SharedHandle<Piece> UnknownLengthPieceStorage::getMissingPiece(const SharedHandle<Peer>& peer) SharedHandle<Piece> UnknownLengthPieceStorage::getMissingPiece(const SharedHandle<Peer>& peer)
{ {
abort(); abort();
@ -107,6 +102,11 @@ SharedHandle<Piece> UnknownLengthPieceStorage::getMissingFastPiece
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
bool UnknownLengthPieceStorage::hasMissingUnusedPiece()
{
abort();
}
SharedHandle<Piece> UnknownLengthPieceStorage::getSparseMissingUnusedPiece SharedHandle<Piece> UnknownLengthPieceStorage::getSparseMissingUnusedPiece
(const unsigned char* ignoreBitfield, size_t length) (const unsigned char* ignoreBitfield, size_t length)
{ {

View File

@ -73,8 +73,6 @@ public:
*/ */
virtual bool hasMissingPiece(const SharedHandle<Peer>& peer); virtual bool hasMissingPiece(const SharedHandle<Peer>& peer);
virtual bool hasMissingUnusedPiece();
/** /**
* Returns a piece that the peer has but localhost doesn't. * Returns a piece that the peer has but localhost doesn't.
* The piece will be marked "used" status in order to prevent other command * The piece will be marked "used" status in order to prevent other command
@ -100,6 +98,8 @@ public:
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
virtual bool hasMissingUnusedPiece();
/** /**
* Returns a missing piece if available. Otherwise returns 0; * Returns a missing piece if available. Otherwise returns 0;
*/ */

View File

@ -44,11 +44,6 @@ public:
return false; return false;
} }
virtual bool hasMissingUnusedPiece()
{
return false;
}
virtual SharedHandle<Piece> getMissingPiece(const SharedHandle<Peer>& peer) { virtual SharedHandle<Piece> getMissingPiece(const SharedHandle<Peer>& peer) {
return SharedHandle<Piece>(new Piece()); return SharedHandle<Piece>(new Piece());
} }
@ -71,6 +66,11 @@ public:
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
virtual bool hasMissingUnusedPiece()
{
return false;
}
virtual SharedHandle<Piece> getSparseMissingUnusedPiece virtual SharedHandle<Piece> getSparseMissingUnusedPiece
(const unsigned char* ignoreBitfield, size_t length) (const unsigned char* ignoreBitfield, size_t length)
{ {

View File

@ -1,8 +1,9 @@
#include "ProtocolDetector.h" #include "ProtocolDetector.h"
#include <cppunit/extensions/HelperMacros.h>
#include "Exception.h" #include "Exception.h"
#include "util.h" #include "util.h"
#include <iostream>
#include <cppunit/extensions/HelperMacros.h>
namespace aria2 { namespace aria2 {
@ -47,10 +48,16 @@ void ProtocolDetectorTest::testGuessTorrentFile()
void ProtocolDetectorTest::testGuessTorrentMagnet() void ProtocolDetectorTest::testGuessTorrentMagnet()
{ {
ProtocolDetector detector; ProtocolDetector detector;
#ifdef ENABLE_BITTORRENT
CPPUNIT_ASSERT CPPUNIT_ASSERT
(detector.guessTorrentMagnet (detector.guessTorrentMagnet
("magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c")); ("magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c"));
CPPUNIT_ASSERT(!detector.guessTorrentMagnet("magnet:?")); CPPUNIT_ASSERT(!detector.guessTorrentMagnet("magnet:?"));
#else // !ENABLE_BITTORRENT
CPPUNIT_ASSERT
(!detector.guessTorrentMagnet
("magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c"));
#endif // !ENABLE_BITTORRENT
} }
void ProtocolDetectorTest::testGuessMetalinkFile() void ProtocolDetectorTest::testGuessMetalinkFile()

View File

@ -538,6 +538,8 @@ static void addUri(const std::string& uri,
CPPUNIT_ASSERT_EQUAL(0, m.execute(req, e.get())._code); CPPUNIT_ASSERT_EQUAL(0, m.execute(req, e.get())._code);
} }
#ifdef ENABLE_BITTORRENT
static void addTorrent static void addTorrent
(const std::string& torrentFile, const SharedHandle<DownloadEngine>& e) (const std::string& torrentFile, const SharedHandle<DownloadEngine>& e)
{ {
@ -547,12 +549,16 @@ static void addTorrent
XmlRpcResponse res = m.execute(req, e.get()); XmlRpcResponse res = m.execute(req, e.get());
} }
#endif // ENABLE_BITTORRENT
void XmlRpcMethodTest::testTellWaiting() void XmlRpcMethodTest::testTellWaiting()
{ {
addUri("http://1/", _e); addUri("http://1/", _e);
addUri("http://2/", _e); addUri("http://2/", _e);
addUri("http://3/", _e); addUri("http://3/", _e);
#ifdef ENABLE_BITTORRENT
addTorrent("single.torrent", _e); addTorrent("single.torrent", _e);
#endif // ENABLE_BITTORRENT
TellWaitingXmlRpcMethod m; TellWaitingXmlRpcMethod m;
XmlRpcRequest req("aria2.tellWaiting", BDE::list()); XmlRpcRequest req("aria2.tellWaiting", BDE::list());
@ -566,17 +572,29 @@ void XmlRpcMethodTest::testTellWaiting()
// waiting.size() == offset+num // waiting.size() == offset+num
req = XmlRpcRequest("aria2.tellWaiting", BDE::list()); req = XmlRpcRequest("aria2.tellWaiting", BDE::list());
req._params << BDE((int64_t)1); req._params << BDE((int64_t)1);
#ifdef ENABLE_BITTORRENT
req._params << BDE((int64_t)3); req._params << BDE((int64_t)3);
#else // !ENABLE_BITTORRENT
req._params << BDE((int64_t)2);
#endif // !ENABLE_BITTORRENT
res = m.execute(req, _e.get()); res = m.execute(req, _e.get());
CPPUNIT_ASSERT_EQUAL(0, res._code); CPPUNIT_ASSERT_EQUAL(0, res._code);
#ifdef ENABLE_BITTORRENT
CPPUNIT_ASSERT_EQUAL((size_t)3, res._param.size()); CPPUNIT_ASSERT_EQUAL((size_t)3, res._param.size());
#else // !ENABLE_BITTORRENT
CPPUNIT_ASSERT_EQUAL((size_t)2, res._param.size());
#endif // !ENABLE_BITTORRENT
// waiting.size() < offset+num // waiting.size() < offset+num
req = XmlRpcRequest("aria2.tellWaiting", BDE::list()); req = XmlRpcRequest("aria2.tellWaiting", BDE::list());
req._params << BDE((int64_t)1); req._params << BDE((int64_t)1);
req._params << BDE((int64_t)4); req._params << BDE((int64_t)4);
res = m.execute(req, _e.get()); res = m.execute(req, _e.get());
CPPUNIT_ASSERT_EQUAL(0, res._code); CPPUNIT_ASSERT_EQUAL(0, res._code);
#ifdef ENABLE_BITTORRENT
CPPUNIT_ASSERT_EQUAL((size_t)3, res._param.size()); CPPUNIT_ASSERT_EQUAL((size_t)3, res._param.size());
#else //!ENABLE_BITTORRENT
CPPUNIT_ASSERT_EQUAL((size_t)2, res._param.size());
#endif // !ENABLE_BITTORRENT
} }
void XmlRpcMethodTest::testTellWaiting_fail() void XmlRpcMethodTest::testTellWaiting_fail()