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();
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
private:
|
2007-10-11 16:58:24 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(SegmentTest);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
void SegmentTest::testUpdateWrittenLength()
|
|
|
|
{
|
2015-06-21 09:04:30 +00:00
|
|
|
std::shared_ptr<Piece> p(new Piece(0, 160_k));
|
|
|
|
PiecedSegment s(160_k, 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
|
|
|
|
2015-06-21 09:04:30 +00:00
|
|
|
s.updateWrittenLength(16_k);
|
2007-10-11 16:58:24 +00:00
|
|
|
CPPUNIT_ASSERT(p->hasBlock(0));
|
|
|
|
CPPUNIT_ASSERT(!p->hasBlock(1));
|
|
|
|
|
2015-06-21 09:04:30 +00:00
|
|
|
s.updateWrittenLength(16_k * 9);
|
2007-10-11 16:58:24 +00:00
|
|
|
CPPUNIT_ASSERT(p->pieceComplete());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SegmentTest::testUpdateWrittenLength_lastPiece()
|
|
|
|
{
|
2015-06-21 09:04:30 +00:00
|
|
|
std::shared_ptr<Piece> p(new Piece(0, 16_k * 9 + 1));
|
|
|
|
PiecedSegment s(160_k, p);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
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()
|
|
|
|
{
|
2015-06-21 09:04:30 +00:00
|
|
|
std::shared_ptr<Piece> p(new Piece(0, 16_k * 9 + 2));
|
|
|
|
PiecedSegment s(160_k, p);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2015-06-21 09:04:30 +00:00
|
|
|
s.updateWrittenLength(16_k * 9 + 1);
|
2007-10-11 16:58:24 +00:00
|
|
|
CPPUNIT_ASSERT(!p->pieceComplete());
|
|
|
|
s.updateWrittenLength(1);
|
|
|
|
CPPUNIT_ASSERT(p->pieceComplete());
|
|
|
|
}
|
2007-10-12 15:11:37 +00:00
|
|
|
|
|
|
|
void SegmentTest::testClear()
|
|
|
|
{
|
2015-06-21 09:04:30 +00:00
|
|
|
std::shared_ptr<Piece> p(new Piece(0, 160_k));
|
|
|
|
PiecedSegment s(160_k, p);
|
|
|
|
s.updateWrittenLength(160_k);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)160_k, 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
|