aria2/test/ShareRatioSeedCriteriaTest.cc
Tatsuhiro Tsujikawa becd34bcb9 2009-04-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed the bug that removed peer's session upload/download length
	are counted twice in _cachedTransferStat before it is
	re-calculated.  This affected the calculation of shara ratio,
	resulting aria2 wrongly determines that specified share ratio is
	reached. Also fixed the typo in calculateStatFor function name.
	* src/BtSetup.cc
	* src/DefaultPeerStorage.cc
	* src/ShareRatioSeedCriteria.h
	* test/ShareRatioSeedCriteriaTest.cc
2009-04-05 10:38:15 +00:00

54 lines
1.4 KiB
C++

#include "ShareRatioSeedCriteria.h"
#include <cppunit/extensions/HelperMacros.h>
#include "MockBtContext.h"
#include "MockPeerStorage.h"
#include "MockPieceStorage.h"
#include "FileEntry.h"
namespace aria2 {
class ShareRatioSeedCriteriaTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(ShareRatioSeedCriteriaTest);
CPPUNIT_TEST(testEvaluate);
CPPUNIT_TEST_SUITE_END();
public:
void testEvaluate();
};
CPPUNIT_TEST_SUITE_REGISTRATION(ShareRatioSeedCriteriaTest);
void ShareRatioSeedCriteriaTest::testEvaluate() {
std::string infoHash = "01234567890123456789";
std::string infoHashString =
Util::toHex((const unsigned char*)infoHash.c_str(), infoHash.size());
SharedHandle<MockBtContext> btContext(new MockBtContext());
btContext->setTotalLength(1000000);
btContext->setInfoHash((const unsigned char*)infoHash.c_str());
SharedHandle<MockPeerStorage> peerStorage(new MockPeerStorage());
TransferStat stat;
stat.setAllTimeUploadLength(1000000);
peerStorage->setStat(stat);
SharedHandle<MockPieceStorage> pieceStorage(new MockPieceStorage());
pieceStorage->setCompletedLength(1000000);
ShareRatioSeedCriteria cri(1.0, btContext);
cri.setPeerStorage(peerStorage);
cri.setPieceStorage(pieceStorage);
CPPUNIT_ASSERT(cri.evaluate());
cri.setRatio(2.0);
CPPUNIT_ASSERT(!cri.evaluate());
// check div by zero
btContext->setTotalLength(0);
CPPUNIT_ASSERT(!cri.evaluate());
}
} // namespace aria2