mirror of https://github.com/aria2/aria2
2008-11-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed the bug that DefaultPieceStorage::getCompletedLength() returns the value larger than DefaultPieceStorage::getTotalLength() when in flight pieces are involved. * src/DefaultPieceStorage.cc * test/DefaultPieceStorageTest.ccpull/1/head
parent
383be271a2
commit
e5e19ddeb9
|
@ -1,3 +1,11 @@
|
||||||
|
2008-11-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Fixed the bug that DefaultPieceStorage::getCompletedLength() returns
|
||||||
|
the value larger than DefaultPieceStorage::getTotalLength() when
|
||||||
|
in flight pieces are involved.
|
||||||
|
* src/DefaultPieceStorage.cc
|
||||||
|
* test/DefaultPieceStorageTest.cc
|
||||||
|
|
||||||
2008-11-09 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2008-11-09 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Bump up version number to 1.0.0a.
|
Bump up version number to 1.0.0a.
|
||||||
|
|
|
@ -33,6 +33,10 @@
|
||||||
*/
|
*/
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "DefaultPieceStorage.h"
|
#include "DefaultPieceStorage.h"
|
||||||
|
|
||||||
|
#include <numeric>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "DownloadContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "Piece.h"
|
#include "Piece.h"
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
|
@ -54,8 +58,6 @@
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
#include "StringFormat.h"
|
#include "StringFormat.h"
|
||||||
#include "RarestPieceSelector.h"
|
#include "RarestPieceSelector.h"
|
||||||
#include <numeric>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -392,7 +394,13 @@ uint64_t DefaultPieceStorage::getFilteredTotalLength()
|
||||||
|
|
||||||
uint64_t DefaultPieceStorage::getCompletedLength()
|
uint64_t DefaultPieceStorage::getCompletedLength()
|
||||||
{
|
{
|
||||||
return bitfieldMan->getCompletedLength()+getInFlightPieceCompletedLength();
|
uint64_t completedLength =
|
||||||
|
bitfieldMan->getCompletedLength()+getInFlightPieceCompletedLength();
|
||||||
|
uint64_t totalLength = getTotalLength();
|
||||||
|
if(completedLength > totalLength) {
|
||||||
|
completedLength = totalLength;
|
||||||
|
}
|
||||||
|
return completedLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t DefaultPieceStorage::getFilteredCompletedLength()
|
uint64_t DefaultPieceStorage::getFilteredCompletedLength()
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
#include "DefaultPieceStorage.h"
|
#include "DefaultPieceStorage.h"
|
||||||
|
|
||||||
|
#include <cppunit/extensions/HelperMacros.h>
|
||||||
|
|
||||||
#include "DefaultBtContext.h"
|
#include "DefaultBtContext.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
|
@ -9,7 +12,6 @@
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
#include "FileEntry.h"
|
#include "FileEntry.h"
|
||||||
#include "MockBtContext.h"
|
#include "MockBtContext.h"
|
||||||
#include <cppunit/extensions/HelperMacros.h>
|
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -28,6 +30,7 @@ class DefaultPieceStorageTest:public CppUnit::TestFixture {
|
||||||
CPPUNIT_TEST(testGetPieceCompletedPiece);
|
CPPUNIT_TEST(testGetPieceCompletedPiece);
|
||||||
CPPUNIT_TEST(testCancelPiece);
|
CPPUNIT_TEST(testCancelPiece);
|
||||||
CPPUNIT_TEST(testMarkPiecesDone);
|
CPPUNIT_TEST(testMarkPiecesDone);
|
||||||
|
CPPUNIT_TEST(testGetCompletedLength);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
private:
|
private:
|
||||||
SharedHandle<BtContext> btContext;
|
SharedHandle<BtContext> btContext;
|
||||||
|
@ -68,6 +71,7 @@ public:
|
||||||
void testGetPieceCompletedPiece();
|
void testGetPieceCompletedPiece();
|
||||||
void testCancelPiece();
|
void testCancelPiece();
|
||||||
void testMarkPiecesDone();
|
void testMarkPiecesDone();
|
||||||
|
void testGetCompletedLength();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -268,4 +272,35 @@ void DefaultPieceStorageTest::testMarkPiecesDone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DefaultPieceStorageTest::testGetCompletedLength()
|
||||||
|
{
|
||||||
|
SharedHandle<MockBtContext> dctx(new MockBtContext());
|
||||||
|
dctx->setPieceLength(1024*1024);
|
||||||
|
dctx->setTotalLength(256*1024*1024);
|
||||||
|
|
||||||
|
DefaultPieceStorage ps(dctx, option);
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)0, ps.getCompletedLength());
|
||||||
|
|
||||||
|
ps.markPiecesDone(250*1024*1024);
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)250*1024*1024, ps.getCompletedLength());
|
||||||
|
|
||||||
|
std::deque<SharedHandle<Piece> > inFlightPieces;
|
||||||
|
for(int i = 0; i < 2; ++i) {
|
||||||
|
SharedHandle<Piece> p(new Piece(250+i, 1024*1024));
|
||||||
|
for(int j = 0; j < 32; ++j) {
|
||||||
|
p->completeBlock(j);
|
||||||
|
}
|
||||||
|
inFlightPieces.push_back(p);
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)512*1024, p->getCompletedLength());
|
||||||
|
}
|
||||||
|
ps.addInFlightPiece(inFlightPieces);
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)251*1024*1024, ps.getCompletedLength());
|
||||||
|
|
||||||
|
ps.markPiecesDone(256*1024*1024);
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)256*1024*1024, ps.getCompletedLength());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
Loading…
Reference in New Issue