2007-10-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Throw exception when chunck checksum verification fails.
	* src/DownloadCommand.cc (validatePieceHash): New function.
	* src/PiecedSegment.{h, cc} (clear): New function.
	* src/GrowSegment.{h, cc} (clear): New function.
	* src/Segment.h (clear): New function.
	* src/SegmentMan.{h, cc} (validatePieceHash): Removed.
	* test/SegmentTest.cc
	* test/GrowSegmentTest.cc
This commit is contained in:
Tatsuhiro Tsujikawa 2007-10-12 15:11:37 +00:00
parent 1d5834a6ca
commit 1171a2063f
12 changed files with 96 additions and 123 deletions

View file

@ -11,6 +11,7 @@ class SegmentTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testUpdateWrittenLength_overflow);
CPPUNIT_TEST(testUpdateWrittenLength_lastPiece);
CPPUNIT_TEST(testUpdateWrittenLength_incompleteLastPiece);
CPPUNIT_TEST(testClear);
CPPUNIT_TEST_SUITE_END();
private:
@ -21,6 +22,7 @@ public:
void testUpdateWrittenLength_overflow();
void testUpdateWrittenLength_lastPiece();
void testUpdateWrittenLength_incompleteLastPiece();
void testClear();
};
@ -69,3 +71,15 @@ void SegmentTest::testUpdateWrittenLength_incompleteLastPiece()
s.updateWrittenLength(1);
CPPUNIT_ASSERT(p->pieceComplete());
}
void SegmentTest::testClear()
{
PieceHandle p = new Piece(0, 16*1024*10);
PiecedSegment s(16*1024*10, p);
s.updateWrittenLength(16*1024*11);
CPPUNIT_ASSERT_EQUAL((int32_t)16*1024*10, s.getWrittenLength());
CPPUNIT_ASSERT_EQUAL((int32_t)16*1024, s.getOverflowLength());
s.clear();
CPPUNIT_ASSERT_EQUAL((int32_t)0, s.getWrittenLength());
CPPUNIT_ASSERT_EQUAL((int32_t)0, s.getOverflowLength());
}