aria2/test/SegmentTest.cc
Tatsuhiro Tsujikawa 518a200d57 2008-03-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Type clarification: size_t for length or size, uint64_t for file
	length, off_t for file offset.

	* src/PiecedSegment.cc
	* src/GrowSegment.h
	* src/DefaultBtRequestFactory.h
	* src/DefaultBtProgressInfoFile.cc
	* src/UnknownLengthPieceStorage.h
	* src/DefaultPieceStorage.cc
	* src/UnknownLengthPieceStorage.cc
	* src/DefaultBtInteractive.cc
	* src/GrowSegment.cc
	* src/BitfieldMan.h
	* src/DownloadCommand.cc
	* src/BtRequestFactory.h
	* src/PiecedSegment.h
	* src/DefaultPieceStorage.h
	* src/Piece.cc
	* src/DefaultBtRequestFactory.cc
	* src/PieceStorage.h
	* src/Segment.h
	* src/Piece.h
	* src/BitfieldMan.cc
	* src/Util.cc
	* test/DefaultBtProgressInfoFileTest.cc
	* test/DefaultPieceStorageTest.cc
	* test/MockPieceStorage.h
	* test/BtRequestMessageTest.cc
	* test/DefaultBtMessageDispatcherTest.cc
	* test/BitfieldManTest.cc
	* test/GrowSegmentTest.cc
	* test/PieceTest.cc
	* test/SegmentTest.cc
	* test/SegmentManTest.cc
	* test/DefaultBtRequestFactoryTest.cc
	* test/MockBtRequestFactory.h
2008-03-08 08:04:28 +00:00

87 lines
2.3 KiB
C++

#include "PiecedSegment.h"
#include "Piece.h"
#include <cppunit/extensions/HelperMacros.h>
namespace aria2 {
class SegmentTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(SegmentTest);
CPPUNIT_TEST(testUpdateWrittenLength);
CPPUNIT_TEST(testUpdateWrittenLength_overflow);
CPPUNIT_TEST(testUpdateWrittenLength_lastPiece);
CPPUNIT_TEST(testUpdateWrittenLength_incompleteLastPiece);
CPPUNIT_TEST(testClear);
CPPUNIT_TEST_SUITE_END();
private:
public:
void setUp() {}
void testUpdateWrittenLength();
void testUpdateWrittenLength_overflow();
void testUpdateWrittenLength_lastPiece();
void testUpdateWrittenLength_incompleteLastPiece();
void testClear();
};
CPPUNIT_TEST_SUITE_REGISTRATION( SegmentTest );
void SegmentTest::testUpdateWrittenLength()
{
SharedHandle<Piece> p = new Piece(0, 16*1024*10);
PiecedSegment s(16*1024*10, p);
CPPUNIT_ASSERT_EQUAL((size_t)0, s.getWrittenLength());
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_overflow()
{
SharedHandle<Piece> p = new Piece(0, 16*1024*10);
PiecedSegment s(16*1024*10, p);
s.updateWrittenLength(16*1024*11);
CPPUNIT_ASSERT(p->pieceComplete());
CPPUNIT_ASSERT_EQUAL((size_t)16*1024, s.getOverflowLength());
}
void SegmentTest::testUpdateWrittenLength_lastPiece()
{
SharedHandle<Piece> p = new Piece(0, 16*1024*9+1);
PiecedSegment s(16*1024*10, p);
s.updateWrittenLength(16*1024*10);
CPPUNIT_ASSERT(p->pieceComplete());
}
void SegmentTest::testUpdateWrittenLength_incompleteLastPiece()
{
SharedHandle<Piece> p = new Piece(0, 16*1024*9+2);
PiecedSegment s(16*1024*10, p);
s.updateWrittenLength(16*1024*9+1);
CPPUNIT_ASSERT(!p->pieceComplete());
s.updateWrittenLength(1);
CPPUNIT_ASSERT(p->pieceComplete());
}
void SegmentTest::testClear()
{
SharedHandle<Piece> p = new Piece(0, 16*1024*10);
PiecedSegment s(16*1024*10, p);
s.updateWrittenLength(16*1024*11);
CPPUNIT_ASSERT_EQUAL((size_t)16*1024*10, s.getWrittenLength());
CPPUNIT_ASSERT_EQUAL((size_t)16*1024, s.getOverflowLength());
s.clear();
CPPUNIT_ASSERT_EQUAL((size_t)0, s.getWrittenLength());
CPPUNIT_ASSERT_EQUAL((size_t)0, s.getOverflowLength());
}
} // namespace aria2