2007-10-11 16:58:24 +00:00
|
|
|
#include "PiecedSegment.h"
|
2010-06-26 13:01:52 +00:00
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2010-06-26 13:01:52 +00:00
|
|
|
#include "Piece.h"
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
class SegmentTest : public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(SegmentTest);
|
|
|
|
CPPUNIT_TEST(testUpdateWrittenLength);
|
|
|
|
CPPUNIT_TEST(testUpdateWrittenLength_lastPiece);
|
|
|
|
CPPUNIT_TEST(testUpdateWrittenLength_incompleteLastPiece);
|
2007-10-12 15:11:37 +00:00
|
|
|
CPPUNIT_TEST(testClear);
|
2007-10-11 16:58:24 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp() {}
|
|
|
|
|
|
|
|
void testUpdateWrittenLength();
|
|
|
|
void testUpdateWrittenLength_lastPiece();
|
|
|
|
void testUpdateWrittenLength_incompleteLastPiece();
|
2007-10-12 15:11:37 +00:00
|
|
|
void testClear();
|
2007-10-11 16:58:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( SegmentTest );
|
|
|
|
|
|
|
|
void SegmentTest::testUpdateWrittenLength()
|
|
|
|
{
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<Piece> p(new Piece(0, 16*1024*10));
|
2007-10-11 16:58:24 +00:00
|
|
|
PiecedSegment s(16*1024*10, p);
|
2014-05-24 20:42:23 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)0, s.getWrittenLength());
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
s.updateWrittenLength(16*1024);
|
|
|
|
CPPUNIT_ASSERT(p->hasBlock(0));
|
|
|
|
CPPUNIT_ASSERT(!p->hasBlock(1));
|
|
|
|
|
|
|
|
s.updateWrittenLength(16*1024*9);
|
|
|
|
CPPUNIT_ASSERT(p->pieceComplete());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SegmentTest::testUpdateWrittenLength_lastPiece()
|
|
|
|
{
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<Piece> p(new Piece(0, 16*1024*9+1));
|
2007-10-11 16:58:24 +00:00
|
|
|
PiecedSegment s(16*1024*10, p);
|
|
|
|
|
2010-06-26 13:01:52 +00:00
|
|
|
s.updateWrittenLength(p->getLength());
|
2007-10-11 16:58:24 +00:00
|
|
|
CPPUNIT_ASSERT(p->pieceComplete());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SegmentTest::testUpdateWrittenLength_incompleteLastPiece()
|
|
|
|
{
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<Piece> p(new Piece(0, 16*1024*9+2));
|
2007-10-11 16:58:24 +00:00
|
|
|
PiecedSegment s(16*1024*10, p);
|
|
|
|
|
|
|
|
s.updateWrittenLength(16*1024*9+1);
|
|
|
|
CPPUNIT_ASSERT(!p->pieceComplete());
|
|
|
|
s.updateWrittenLength(1);
|
|
|
|
CPPUNIT_ASSERT(p->pieceComplete());
|
|
|
|
}
|
2007-10-12 15:11:37 +00:00
|
|
|
|
|
|
|
void SegmentTest::testClear()
|
|
|
|
{
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<Piece> p(new Piece(0, 16*1024*10));
|
2007-10-12 15:11:37 +00:00
|
|
|
PiecedSegment s(16*1024*10, p);
|
2010-06-26 13:01:52 +00:00
|
|
|
s.updateWrittenLength(16*1024*10);
|
2014-05-24 20:42:23 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)16*1024*10, s.getWrittenLength());
|
2013-08-20 16:57:17 +00:00
|
|
|
s.clear(nullptr);
|
2014-05-24 20:42:23 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)0, s.getWrittenLength());
|
2007-10-12 15:11:37 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|