From 9a6a73dd9641f0967f58f3bd2cdee29a4cec3d65 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 5 Dec 2009 11:35:18 +0000 Subject: [PATCH] 2009-12-05 Tatsuhiro Tsujikawa 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 --- ChangeLog | 12 ++++++++++++ src/DefaultPieceStorage.cc | 12 ++++++------ src/DefaultPieceStorage.h | 4 ++-- src/PieceStorage.h | 5 +++-- src/UnknownLengthPieceStorage.cc | 10 +++++----- src/UnknownLengthPieceStorage.h | 4 ++-- test/MockPieceStorage.h | 10 +++++----- test/ProtocolDetectorTest.cc | 11 +++++++++-- test/XmlRpcMethodTest.cc | 18 ++++++++++++++++++ 9 files changed, 62 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 301c35f4..aa5d24b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2009-12-05 Tatsuhiro Tsujikawa + + 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 Documented in man page that if getifaddrs() is missing, diff --git a/src/DefaultPieceStorage.cc b/src/DefaultPieceStorage.cc index 353c564e..5d42ba23 100644 --- a/src/DefaultPieceStorage.cc +++ b/src/DefaultPieceStorage.cc @@ -196,12 +196,6 @@ bool DefaultPieceStorage::hasMissingPiece(const PeerHandle& peer) peer->getBitfieldLength()); } -bool DefaultPieceStorage::hasMissingUnusedPiece() -{ - size_t index; - return bitfieldMan->getFirstMissingUnusedIndex(index); -} - PieceHandle DefaultPieceStorage::getMissingPiece(const SharedHandle& peer) { return getMissingPiece(peer->getBitfield(), peer->getBitfieldLength()); @@ -267,6 +261,12 @@ SharedHandle DefaultPieceStorage::getMissingFastPiece #endif // ENABLE_BITTORRENT +bool DefaultPieceStorage::hasMissingUnusedPiece() +{ + size_t index; + return bitfieldMan->getFirstMissingUnusedIndex(index); +} + PieceHandle DefaultPieceStorage::getSparseMissingUnusedPiece (const unsigned char* ignoreBitfield, size_t length) { diff --git a/src/DefaultPieceStorage.h b/src/DefaultPieceStorage.h index 834026e0..63c062d4 100644 --- a/src/DefaultPieceStorage.h +++ b/src/DefaultPieceStorage.h @@ -121,8 +121,6 @@ public: virtual bool hasMissingPiece(const SharedHandle& peer); - virtual bool hasMissingUnusedPiece(); - virtual SharedHandle getMissingPiece(const SharedHandle& peer); virtual SharedHandle getMissingFastPiece(const SharedHandle& peer); @@ -135,6 +133,8 @@ public: #endif // ENABLE_BITTORRENT + virtual bool hasMissingUnusedPiece(); + virtual SharedHandle getSparseMissingUnusedPiece (const unsigned char* ignoreBitfield, size_t length); diff --git a/src/PieceStorage.h b/src/PieceStorage.h index 95402ec9..ab492625 100644 --- a/src/PieceStorage.h +++ b/src/PieceStorage.h @@ -62,8 +62,6 @@ public: */ virtual bool hasMissingPiece(const SharedHandle& peer) = 0; - virtual bool hasMissingUnusedPiece() = 0; - /** * Returns a piece that the peer has but localhost doesn't. * The piece will be marked "used" status in order to prevent other command @@ -101,6 +99,9 @@ public: #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; * If ignoreBitfield is set, indexes of true bit are excluded. diff --git a/src/UnknownLengthPieceStorage.cc b/src/UnknownLengthPieceStorage.cc index 72f7d173..b74d5a25 100644 --- a/src/UnknownLengthPieceStorage.cc +++ b/src/UnknownLengthPieceStorage.cc @@ -78,11 +78,6 @@ bool UnknownLengthPieceStorage::hasMissingPiece(const SharedHandle& peer) abort(); } -bool UnknownLengthPieceStorage::hasMissingUnusedPiece() -{ - abort(); -} - SharedHandle UnknownLengthPieceStorage::getMissingPiece(const SharedHandle& peer) { abort(); @@ -107,6 +102,11 @@ SharedHandle UnknownLengthPieceStorage::getMissingFastPiece #endif // ENABLE_BITTORRENT +bool UnknownLengthPieceStorage::hasMissingUnusedPiece() +{ + abort(); +} + SharedHandle UnknownLengthPieceStorage::getSparseMissingUnusedPiece (const unsigned char* ignoreBitfield, size_t length) { diff --git a/src/UnknownLengthPieceStorage.h b/src/UnknownLengthPieceStorage.h index 1ef3618b..be81b761 100644 --- a/src/UnknownLengthPieceStorage.h +++ b/src/UnknownLengthPieceStorage.h @@ -73,8 +73,6 @@ public: */ virtual bool hasMissingPiece(const SharedHandle& peer); - virtual bool hasMissingUnusedPiece(); - /** * Returns a piece that the peer has but localhost doesn't. * The piece will be marked "used" status in order to prevent other command @@ -100,6 +98,8 @@ public: #endif // ENABLE_BITTORRENT + virtual bool hasMissingUnusedPiece(); + /** * Returns a missing piece if available. Otherwise returns 0; */ diff --git a/test/MockPieceStorage.h b/test/MockPieceStorage.h index b8e19498..bbc6d49e 100644 --- a/test/MockPieceStorage.h +++ b/test/MockPieceStorage.h @@ -44,11 +44,6 @@ public: return false; } - virtual bool hasMissingUnusedPiece() - { - return false; - } - virtual SharedHandle getMissingPiece(const SharedHandle& peer) { return SharedHandle(new Piece()); } @@ -71,6 +66,11 @@ public: #endif // ENABLE_BITTORRENT + virtual bool hasMissingUnusedPiece() + { + return false; + } + virtual SharedHandle getSparseMissingUnusedPiece (const unsigned char* ignoreBitfield, size_t length) { diff --git a/test/ProtocolDetectorTest.cc b/test/ProtocolDetectorTest.cc index 0acdb1dc..731b1db3 100644 --- a/test/ProtocolDetectorTest.cc +++ b/test/ProtocolDetectorTest.cc @@ -1,8 +1,9 @@ #include "ProtocolDetector.h" + +#include + #include "Exception.h" #include "util.h" -#include -#include namespace aria2 { @@ -47,10 +48,16 @@ void ProtocolDetectorTest::testGuessTorrentFile() void ProtocolDetectorTest::testGuessTorrentMagnet() { ProtocolDetector detector; +#ifdef ENABLE_BITTORRENT CPPUNIT_ASSERT (detector.guessTorrentMagnet ("magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c")); CPPUNIT_ASSERT(!detector.guessTorrentMagnet("magnet:?")); +#else // !ENABLE_BITTORRENT + CPPUNIT_ASSERT + (!detector.guessTorrentMagnet + ("magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c")); +#endif // !ENABLE_BITTORRENT } void ProtocolDetectorTest::testGuessMetalinkFile() diff --git a/test/XmlRpcMethodTest.cc b/test/XmlRpcMethodTest.cc index afc671b2..22c1b2f7 100644 --- a/test/XmlRpcMethodTest.cc +++ b/test/XmlRpcMethodTest.cc @@ -538,6 +538,8 @@ static void addUri(const std::string& uri, CPPUNIT_ASSERT_EQUAL(0, m.execute(req, e.get())._code); } +#ifdef ENABLE_BITTORRENT + static void addTorrent (const std::string& torrentFile, const SharedHandle& e) { @@ -547,12 +549,16 @@ static void addTorrent XmlRpcResponse res = m.execute(req, e.get()); } +#endif // ENABLE_BITTORRENT + void XmlRpcMethodTest::testTellWaiting() { addUri("http://1/", _e); addUri("http://2/", _e); addUri("http://3/", _e); +#ifdef ENABLE_BITTORRENT addTorrent("single.torrent", _e); +#endif // ENABLE_BITTORRENT TellWaitingXmlRpcMethod m; XmlRpcRequest req("aria2.tellWaiting", BDE::list()); @@ -566,17 +572,29 @@ void XmlRpcMethodTest::testTellWaiting() // waiting.size() == offset+num req = XmlRpcRequest("aria2.tellWaiting", BDE::list()); req._params << BDE((int64_t)1); +#ifdef ENABLE_BITTORRENT req._params << BDE((int64_t)3); +#else // !ENABLE_BITTORRENT + req._params << BDE((int64_t)2); +#endif // !ENABLE_BITTORRENT res = m.execute(req, _e.get()); CPPUNIT_ASSERT_EQUAL(0, res._code); +#ifdef ENABLE_BITTORRENT 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 req = XmlRpcRequest("aria2.tellWaiting", BDE::list()); req._params << BDE((int64_t)1); req._params << BDE((int64_t)4); res = m.execute(req, _e.get()); CPPUNIT_ASSERT_EQUAL(0, res._code); +#ifdef ENABLE_BITTORRENT 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()