2006-03-21 14:12:51 +00:00
|
|
|
#include "BitfieldMan.h"
|
2009-02-11 07:54:03 +00:00
|
|
|
|
2008-03-15 04:19:46 +00:00
|
|
|
#include <cstring>
|
2009-02-11 07:54:03 +00:00
|
|
|
|
2006-03-21 14:12:51 +00:00
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2009-02-11 07:54:03 +00:00
|
|
|
#include "FixedNumberRandomizer.h"
|
2009-03-28 13:29:38 +00:00
|
|
|
#include "bitfield.h"
|
2009-02-11 07:54:03 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
|
|
|
|
2006-03-21 14:12:51 +00:00
|
|
|
class BitfieldManTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(BitfieldManTest);
|
|
|
|
CPPUNIT_TEST(testGetBlockSize);
|
|
|
|
CPPUNIT_TEST(testGetFirstMissingUnusedIndex);
|
2008-01-11 13:32:00 +00:00
|
|
|
CPPUNIT_TEST(testGetFirstMissingIndex);
|
2006-03-21 14:12:51 +00:00
|
|
|
CPPUNIT_TEST(testIsAllBitSet);
|
2006-04-06 12:52:16 +00:00
|
|
|
CPPUNIT_TEST(testFilter);
|
2009-02-11 07:54:03 +00:00
|
|
|
CPPUNIT_TEST(testAddFilter_zeroLength);
|
2009-06-30 17:03:57 +00:00
|
|
|
CPPUNIT_TEST(testAddNotFilter);
|
|
|
|
CPPUNIT_TEST(testAddNotFilter_zeroLength);
|
|
|
|
CPPUNIT_TEST(testAddNotFilter_overflow);
|
2006-07-30 12:58:27 +00:00
|
|
|
CPPUNIT_TEST(testGetMissingIndex);
|
2006-09-19 14:52:59 +00:00
|
|
|
CPPUNIT_TEST(testGetSparceMissingUnusedIndex);
|
2007-08-31 15:18:48 +00:00
|
|
|
CPPUNIT_TEST(testGetSparceMissingUnusedIndex_setBit);
|
2007-02-06 14:49:22 +00:00
|
|
|
CPPUNIT_TEST(testIsBitSetOffsetRange);
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
CPPUNIT_TEST(testGetMissingUnusedLength);
|
2007-03-24 14:32:49 +00:00
|
|
|
CPPUNIT_TEST(testSetBitRange);
|
2008-01-11 13:32:00 +00:00
|
|
|
CPPUNIT_TEST(testGetAllMissingIndexes);
|
|
|
|
CPPUNIT_TEST(testGetAllMissingIndexes_noarg);
|
2009-03-28 13:29:38 +00:00
|
|
|
CPPUNIT_TEST(testGetAllMissingIndexes_checkLastByte);
|
2008-05-11 07:37:46 +00:00
|
|
|
CPPUNIT_TEST(testGetAllMissingUnusedIndexes);
|
2008-01-11 13:32:00 +00:00
|
|
|
CPPUNIT_TEST(testGetMissingUnusedIndex);
|
|
|
|
CPPUNIT_TEST(testGetMissingIndex_noarg);
|
|
|
|
CPPUNIT_TEST(testGetMissingUnusedIndex_noarg);
|
|
|
|
CPPUNIT_TEST(testCountFilteredBlock);
|
2008-06-17 11:43:29 +00:00
|
|
|
CPPUNIT_TEST(testCountMissingBlock);
|
2009-05-12 15:19:27 +00:00
|
|
|
CPPUNIT_TEST(testZeroLengthFilter);
|
2006-03-21 14:12:51 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Randomizer> fixedNumberRandomizer;
|
2006-03-21 14:12:51 +00:00
|
|
|
|
|
|
|
public:
|
2008-04-20 00:50:22 +00:00
|
|
|
BitfieldManTest() {
|
2006-12-24 06:25:21 +00:00
|
|
|
FixedNumberRandomizer* randomizer = new FixedNumberRandomizer();
|
|
|
|
randomizer->setFixedNumber(0);
|
2008-04-20 00:50:22 +00:00
|
|
|
this->fixedNumberRandomizer.reset(randomizer);
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
2006-03-21 14:12:51 +00:00
|
|
|
void setUp() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void testGetBlockSize();
|
|
|
|
void testGetFirstMissingUnusedIndex();
|
2008-01-11 13:32:00 +00:00
|
|
|
void testGetFirstMissingIndex();
|
|
|
|
void testGetMissingIndex();
|
|
|
|
void testGetMissingIndex_noarg();
|
|
|
|
void testGetMissingUnusedIndex();
|
|
|
|
void testGetMissingUnusedIndex_noarg();
|
|
|
|
void testGetAllMissingIndexes();
|
|
|
|
void testGetAllMissingIndexes_noarg();
|
2009-03-28 13:29:38 +00:00
|
|
|
void testGetAllMissingIndexes_checkLastByte();
|
2008-05-11 07:37:46 +00:00
|
|
|
void testGetAllMissingUnusedIndexes();
|
|
|
|
|
2006-03-21 14:12:51 +00:00
|
|
|
void testIsAllBitSet();
|
2006-04-06 12:52:16 +00:00
|
|
|
void testFilter();
|
2009-02-11 07:54:03 +00:00
|
|
|
void testAddFilter_zeroLength();
|
2009-06-30 17:03:57 +00:00
|
|
|
void testAddNotFilter();
|
|
|
|
void testAddNotFilter_zeroLength();
|
|
|
|
void testAddNotFilter_overflow();
|
2006-09-19 14:52:59 +00:00
|
|
|
void testGetSparceMissingUnusedIndex();
|
2007-08-31 15:18:48 +00:00
|
|
|
void testGetSparceMissingUnusedIndex_setBit();
|
2007-02-06 14:49:22 +00:00
|
|
|
void testIsBitSetOffsetRange();
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
void testGetMissingUnusedLength();
|
2007-03-24 14:32:49 +00:00
|
|
|
void testSetBitRange();
|
2008-01-11 13:32:00 +00:00
|
|
|
void testCountFilteredBlock();
|
2008-06-17 11:43:29 +00:00
|
|
|
void testCountMissingBlock();
|
2009-05-12 15:19:27 +00:00
|
|
|
void testZeroLengthFilter();
|
2006-03-21 14:12:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( BitfieldManTest );
|
|
|
|
|
|
|
|
void BitfieldManTest::testGetBlockSize() {
|
|
|
|
BitfieldMan bt1(1024, 1024*10);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1024, bt1.getBlockLength(9));
|
2006-03-21 14:12:51 +00:00
|
|
|
|
|
|
|
BitfieldMan bt2(1024, 1024*10+1);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1024, bt2.getBlockLength(9));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, bt2.getBlockLength(10));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, bt2.getBlockLength(11));
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
|
|
|
|
2008-01-11 13:32:00 +00:00
|
|
|
void BitfieldManTest::testGetFirstMissingUnusedIndex()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
BitfieldMan bt1(1024, 1024*10);
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getFirstMissingUnusedIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.setUseBit(0);
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getFirstMissingUnusedIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.unsetUseBit(0);
|
|
|
|
bt1.setBit(0);
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getFirstMissingUnusedIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.setAllBit();
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(!bt1.getFirstMissingUnusedIndex(index));
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
BitfieldMan bt1(1024, 1024*10);
|
|
|
|
|
|
|
|
bt1.addFilter(1024, 1024*10);
|
|
|
|
bt1.enableFilter();
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getFirstMissingUnusedIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.setUseBit(1);
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getFirstMissingUnusedIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.setBit(2);
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getFirstMissingUnusedIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-21 14:12:51 +00:00
|
|
|
|
2008-01-11 13:32:00 +00:00
|
|
|
void BitfieldManTest::testGetFirstMissingIndex()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
BitfieldMan bt1(1024, 1024*10);
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getFirstMissingIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.setUseBit(0);
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getFirstMissingIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.unsetUseBit(0);
|
|
|
|
bt1.setBit(0);
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getFirstMissingIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.setAllBit();
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(!bt1.getFirstMissingIndex(index));
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
BitfieldMan bt1(1024, 1024*10);
|
|
|
|
|
|
|
|
bt1.addFilter(1024, 1024*10);
|
|
|
|
bt1.enableFilter();
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getFirstMissingIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.setUseBit(1);
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getFirstMissingIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.setBit(1);
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getFirstMissingIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-21 14:12:51 +00:00
|
|
|
|
2008-01-11 13:32:00 +00:00
|
|
|
void BitfieldManTest::testGetMissingUnusedIndex_noarg()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
BitfieldMan bt1(1024, 1024*10);
|
|
|
|
bt1.setRandomizer(fixedNumberRandomizer);
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getMissingUnusedIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.setUseBit(0);
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getMissingUnusedIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.unsetUseBit(0);
|
|
|
|
bt1.setBit(0);
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getMissingUnusedIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.setAllBit();
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(!bt1.getMissingUnusedIndex(index));
|
|
|
|
}
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
{
|
|
|
|
BitfieldMan bt1(1024, 1024*10);
|
|
|
|
bt1.setRandomizer(fixedNumberRandomizer);
|
|
|
|
|
|
|
|
bt1.addFilter(1024, 1024*10);
|
|
|
|
bt1.enableFilter();
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getMissingUnusedIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.setUseBit(1);
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getMissingUnusedIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.setBit(2);
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getMissingUnusedIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-21 14:12:51 +00:00
|
|
|
|
2008-01-11 13:32:00 +00:00
|
|
|
void BitfieldManTest::testGetMissingIndex_noarg()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
BitfieldMan bt1(1024, 1024*10);
|
|
|
|
bt1.setRandomizer(fixedNumberRandomizer);
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getMissingIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.setUseBit(0);
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getMissingIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.unsetUseBit(0);
|
|
|
|
bt1.setBit(0);
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getMissingIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.setAllBit();
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(!bt1.getMissingIndex(index));
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
BitfieldMan bt1(1024, 1024*10);
|
|
|
|
bt1.setRandomizer(fixedNumberRandomizer);
|
|
|
|
|
|
|
|
bt1.addFilter(1024, 1024*10);
|
|
|
|
bt1.enableFilter();
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getMissingIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.setUseBit(1);
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getMissingIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.setBit(1);
|
2008-03-08 08:04:28 +00:00
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getMissingIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, index);
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
}
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BitfieldManTest::testIsAllBitSet() {
|
|
|
|
BitfieldMan bt1(1024, 1024*10);
|
|
|
|
CPPUNIT_ASSERT(!bt1.isAllBitSet());
|
|
|
|
bt1.setBit(1);
|
|
|
|
CPPUNIT_ASSERT(!bt1.isAllBitSet());
|
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
for(size_t i = 0; i < 8; i++) {
|
2006-03-21 14:12:51 +00:00
|
|
|
CPPUNIT_ASSERT(bt1.setBit(i));
|
|
|
|
}
|
|
|
|
CPPUNIT_ASSERT(!bt1.isAllBitSet());
|
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
for(size_t i = 0; i < bt1.countBlock(); i++) {
|
2006-03-21 14:12:51 +00:00
|
|
|
CPPUNIT_ASSERT(bt1.setBit(i));
|
|
|
|
}
|
|
|
|
CPPUNIT_ASSERT(bt1.isAllBitSet());
|
2007-07-09 13:30:45 +00:00
|
|
|
|
|
|
|
BitfieldMan btzero(1024, 0);
|
|
|
|
CPPUNIT_ASSERT(btzero.isAllBitSet());
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
2006-04-06 12:52:16 +00:00
|
|
|
|
|
|
|
void BitfieldManTest::testFilter() {
|
|
|
|
BitfieldMan btman(2, 32);
|
2006-12-24 06:25:21 +00:00
|
|
|
btman.setRandomizer(fixedNumberRandomizer);
|
2006-04-06 12:52:16 +00:00
|
|
|
|
|
|
|
// test offset=4, length=12
|
|
|
|
btman.addFilter(4, 12);
|
|
|
|
btman.enableFilter();
|
|
|
|
unsigned char peerBt[2];
|
|
|
|
memset(peerBt, 0xff, sizeof(peerBt));
|
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(btman.getMissingUnusedIndex(index, peerBt, sizeof(peerBt)));
|
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
btman.setUseBit(index);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, index);
|
|
|
|
CPPUNIT_ASSERT(btman.getMissingUnusedIndex(index, peerBt, sizeof(peerBt)));
|
2006-04-06 12:52:16 +00:00
|
|
|
btman.setUseBit(index);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, index);
|
|
|
|
CPPUNIT_ASSERT(btman.getMissingUnusedIndex(index, peerBt, sizeof(peerBt)));
|
2006-04-06 12:52:16 +00:00
|
|
|
btman.setUseBit(index);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)4, index);
|
|
|
|
CPPUNIT_ASSERT(btman.getMissingUnusedIndex(index, peerBt, sizeof(peerBt)));
|
2006-04-06 12:52:16 +00:00
|
|
|
btman.setUseBit(index);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)5, index);
|
|
|
|
CPPUNIT_ASSERT(btman.getMissingUnusedIndex(index, peerBt, sizeof(peerBt)));
|
2006-04-06 12:52:16 +00:00
|
|
|
btman.setUseBit(index);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)6, index);
|
|
|
|
CPPUNIT_ASSERT(btman.getMissingUnusedIndex(index, peerBt, sizeof(peerBt)));
|
2006-04-06 12:52:16 +00:00
|
|
|
btman.setUseBit(index);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)7, index);
|
|
|
|
CPPUNIT_ASSERT(!btman.getMissingUnusedIndex(index, peerBt, sizeof(peerBt)));
|
2008-07-31 12:28:12 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint64_t)12ULL, btman.getFilteredTotalLength());
|
2006-04-06 12:52:16 +00:00
|
|
|
|
|
|
|
// test offset=5, length=2
|
|
|
|
btman.clearAllBit();
|
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
btman.clearAllUseBit();
|
2006-04-06 12:52:16 +00:00
|
|
|
btman.clearFilter();
|
|
|
|
btman.addFilter(5, 2);
|
|
|
|
btman.enableFilter();
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT(btman.getMissingUnusedIndex(index, peerBt, sizeof(peerBt)));
|
2006-04-06 12:52:16 +00:00
|
|
|
btman.setUseBit(index);
|
|
|
|
btman.setBit(index);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, index);
|
|
|
|
CPPUNIT_ASSERT(btman.getMissingUnusedIndex(index, peerBt, sizeof(peerBt)));
|
2006-04-06 12:52:16 +00:00
|
|
|
btman.setUseBit(index);
|
|
|
|
btman.setBit(index);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, index);
|
|
|
|
CPPUNIT_ASSERT(!btman.getMissingUnusedIndex(index, peerBt, sizeof(peerBt)));
|
2008-07-31 12:28:12 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint64_t)4ULL, btman.getFilteredTotalLength());
|
2007-01-28 14:18:35 +00:00
|
|
|
CPPUNIT_ASSERT(btman.isFilteredAllBitSet());
|
2006-04-06 12:52:16 +00:00
|
|
|
|
|
|
|
BitfieldMan btman2(2, 31);
|
|
|
|
btman2.addFilter(0, 31);
|
|
|
|
btman2.enableFilter();
|
2008-07-31 12:28:12 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint64_t)31ULL, btman2.getFilteredTotalLength());
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2006-04-06 12:52:16 +00:00
|
|
|
}
|
2006-07-30 12:58:27 +00:00
|
|
|
|
2009-02-11 07:54:03 +00:00
|
|
|
void BitfieldManTest::testAddFilter_zeroLength()
|
|
|
|
{
|
|
|
|
BitfieldMan bits(1024, 1024*1024);
|
|
|
|
bits.addFilter(2048, 0);
|
|
|
|
bits.enableFilter();
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, bits.countMissingBlock());
|
|
|
|
CPPUNIT_ASSERT(bits.isFilteredAllBitSet());
|
|
|
|
}
|
|
|
|
|
2009-06-30 17:03:57 +00:00
|
|
|
void BitfieldManTest::testAddNotFilter() {
|
|
|
|
BitfieldMan btman(2, 32);
|
|
|
|
|
|
|
|
btman.addNotFilter(3, 6);
|
|
|
|
CPPUNIT_ASSERT(bitfield::test(btman.getFilterBitfield(), 16, 0));
|
|
|
|
for(size_t i = 1; i < 5; ++i) {
|
|
|
|
CPPUNIT_ASSERT(!bitfield::test(btman.getFilterBitfield(), 16, i));
|
|
|
|
}
|
|
|
|
for(size_t i = 5; i < 16; ++i) {
|
|
|
|
CPPUNIT_ASSERT(bitfield::test(btman.getFilterBitfield(), 16, i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitfieldManTest::testAddNotFilter_zeroLength() {
|
|
|
|
BitfieldMan btman(2, 6);
|
|
|
|
btman.addNotFilter(2, 0);
|
|
|
|
CPPUNIT_ASSERT(!bitfield::test(btman.getFilterBitfield(), 3, 0));
|
|
|
|
CPPUNIT_ASSERT(!bitfield::test(btman.getFilterBitfield(), 3, 1));
|
|
|
|
CPPUNIT_ASSERT(!bitfield::test(btman.getFilterBitfield(), 3, 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitfieldManTest::testAddNotFilter_overflow() {
|
|
|
|
BitfieldMan btman(2, 6);
|
|
|
|
btman.addNotFilter(6, 100);
|
|
|
|
CPPUNIT_ASSERT(bitfield::test(btman.getFilterBitfield(), 3, 0));
|
|
|
|
CPPUNIT_ASSERT(bitfield::test(btman.getFilterBitfield(), 3, 1));
|
|
|
|
CPPUNIT_ASSERT(bitfield::test(btman.getFilterBitfield(), 3, 2));
|
|
|
|
}
|
|
|
|
|
2006-07-30 12:58:27 +00:00
|
|
|
void BitfieldManTest::testGetMissingIndex() {
|
|
|
|
BitfieldMan bt1(1024, 1024*256);
|
2006-12-24 06:25:21 +00:00
|
|
|
bt1.setRandomizer(fixedNumberRandomizer);
|
2006-07-30 12:58:27 +00:00
|
|
|
|
|
|
|
unsigned char bitArray[] = {
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
};
|
2008-03-08 08:04:28 +00:00
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(bt1.getMissingIndex(index, bitArray, 32));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, index);
|
2006-07-30 12:58:27 +00:00
|
|
|
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.addFilter(1024, 1024*256);
|
|
|
|
bt1.enableFilter();
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT(bt1.getMissingIndex(index, bitArray, 32));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, index);
|
2008-01-11 13:32:00 +00:00
|
|
|
bt1.disableFilter();
|
|
|
|
|
2006-07-30 12:58:27 +00:00
|
|
|
unsigned char bitArray2[] = {
|
2006-12-24 06:25:21 +00:00
|
|
|
0x0f, 0xff, 0xff, 0xff,
|
2006-07-30 12:58:27 +00:00
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
};
|
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT(bt1.getMissingIndex(index, bitArray2, 32));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)4, index);
|
2006-07-30 12:58:27 +00:00
|
|
|
|
|
|
|
unsigned char bitArray3[] = {
|
2006-12-24 06:25:21 +00:00
|
|
|
0x00, 0xff, 0xff, 0xff,
|
2006-07-30 12:58:27 +00:00
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
};
|
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT(bt1.getMissingIndex(index, bitArray3, 32));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)8, index);
|
2006-07-30 12:58:27 +00:00
|
|
|
|
|
|
|
unsigned char bitArray4[] = {
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
};
|
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT(!bt1.getMissingIndex(index, bitArray4, 32));
|
2006-07-30 12:58:27 +00:00
|
|
|
|
|
|
|
}
|
2006-09-19 14:52:59 +00:00
|
|
|
|
2009-06-28 10:37:15 +00:00
|
|
|
// TODO1.5 add test using ignoreBitfield
|
2006-09-19 14:52:59 +00:00
|
|
|
void BitfieldManTest::testGetSparceMissingUnusedIndex() {
|
|
|
|
BitfieldMan bitfield(1024*1024, 10*1024*1024);
|
2009-06-28 10:37:15 +00:00
|
|
|
const size_t length = 2;
|
|
|
|
unsigned char ignoreBitfield[length];
|
|
|
|
memset(ignoreBitfield, 0, sizeof(ignoreBitfield));
|
2008-03-08 08:04:28 +00:00
|
|
|
size_t index;
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, index);
|
2007-08-31 15:18:48 +00:00
|
|
|
bitfield.setUseBit(0);
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)5, index);
|
2006-09-19 14:52:59 +00:00
|
|
|
bitfield.setUseBit(5);
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, index);
|
2007-08-31 15:18:48 +00:00
|
|
|
bitfield.setUseBit(3);
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)8, index);
|
2007-08-31 15:18:48 +00:00
|
|
|
bitfield.setUseBit(8);
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, index);
|
2007-08-31 15:18:48 +00:00
|
|
|
bitfield.setUseBit(2);
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)7, index);
|
2007-08-31 15:18:48 +00:00
|
|
|
bitfield.setUseBit(7);
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, index);
|
2007-08-31 15:18:48 +00:00
|
|
|
bitfield.setUseBit(1);
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)4, index);
|
2007-08-31 15:18:48 +00:00
|
|
|
bitfield.setUseBit(4);
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)6, index);
|
2007-08-31 15:18:48 +00:00
|
|
|
bitfield.setUseBit(6);
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)9, index);
|
2007-08-31 15:18:48 +00:00
|
|
|
bitfield.setUseBit(9);
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(!bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2007-08-31 15:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BitfieldManTest::testGetSparceMissingUnusedIndex_setBit() {
|
|
|
|
BitfieldMan bitfield(1024*1024, 10*1024*1024);
|
2009-06-28 10:37:15 +00:00
|
|
|
const size_t length = 2;
|
|
|
|
unsigned char ignoreBitfield[length];
|
|
|
|
memset(ignoreBitfield, 0, sizeof(ignoreBitfield));
|
2008-03-08 08:04:28 +00:00
|
|
|
size_t index;
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, index);
|
2007-08-31 15:18:48 +00:00
|
|
|
bitfield.setBit(0);
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, index);
|
2006-09-19 14:52:59 +00:00
|
|
|
bitfield.setBit(1);
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, index);
|
2007-08-31 15:18:48 +00:00
|
|
|
bitfield.setBit(2);
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, index);
|
2007-08-31 15:18:48 +00:00
|
|
|
bitfield.setBit(3);
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)4, index);
|
2006-09-19 14:52:59 +00:00
|
|
|
bitfield.setBit(4);
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)5, index);
|
2007-08-31 15:18:48 +00:00
|
|
|
bitfield.setBit(5);
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)6, index);
|
2006-09-19 14:52:59 +00:00
|
|
|
bitfield.setBit(6);
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)7, index);
|
2007-08-31 15:18:48 +00:00
|
|
|
bitfield.setBit(7);
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)8, index);
|
2007-08-31 15:18:48 +00:00
|
|
|
bitfield.setBit(8);
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)9, index);
|
2006-09-19 14:52:59 +00:00
|
|
|
bitfield.setBit(9);
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT(!bitfield.getSparseMissingUnusedIndex(index,
|
|
|
|
ignoreBitfield, length));
|
2006-09-19 14:52:59 +00:00
|
|
|
}
|
2007-02-06 14:49:22 +00:00
|
|
|
|
|
|
|
void BitfieldManTest::testIsBitSetOffsetRange()
|
|
|
|
{
|
2008-03-08 08:04:28 +00:00
|
|
|
int64_t totalLength = 4ULL*1024*1024*1024;
|
2007-02-06 14:49:22 +00:00
|
|
|
int32_t pieceLength = 4*1024*1024;
|
|
|
|
BitfieldMan bitfield(pieceLength, totalLength);
|
|
|
|
bitfield.setAllBit();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!bitfield.isBitSetOffsetRange(0, 0));
|
|
|
|
CPPUNIT_ASSERT(!bitfield.isBitSetOffsetRange(totalLength, 100));
|
|
|
|
CPPUNIT_ASSERT(!bitfield.isBitSetOffsetRange(totalLength+1, 100));
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(bitfield.isBitSetOffsetRange(0, totalLength));
|
|
|
|
CPPUNIT_ASSERT(bitfield.isBitSetOffsetRange(0, totalLength+1));
|
|
|
|
|
|
|
|
bitfield.clearAllBit();
|
|
|
|
|
|
|
|
bitfield.setBit(100);
|
|
|
|
bitfield.setBit(101);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(bitfield.isBitSetOffsetRange(pieceLength*100, pieceLength*2));
|
|
|
|
CPPUNIT_ASSERT(!bitfield.isBitSetOffsetRange(pieceLength*100-10, pieceLength*2));
|
|
|
|
CPPUNIT_ASSERT(!bitfield.isBitSetOffsetRange(pieceLength*100, pieceLength*2+1));
|
|
|
|
|
|
|
|
bitfield.clearAllBit();
|
|
|
|
|
|
|
|
bitfield.setBit(100);
|
|
|
|
bitfield.setBit(102);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!bitfield.isBitSetOffsetRange(pieceLength*100, pieceLength*3));
|
|
|
|
}
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
|
|
|
|
void BitfieldManTest::testGetMissingUnusedLength()
|
|
|
|
{
|
2008-03-08 08:04:28 +00:00
|
|
|
uint64_t totalLength = 1024*10+10;
|
|
|
|
size_t blockLength = 1024;
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
|
|
|
|
BitfieldMan bf(blockLength, totalLength);
|
|
|
|
|
|
|
|
// from index 0 and all blocks are unused and not acquired.
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(totalLength, bf.getMissingUnusedLength(0));
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
|
|
|
|
// from index 10 and all blocks are unused and not acquired.
|
2008-07-31 12:28:12 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint64_t)10ULL, bf.getMissingUnusedLength(10));
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
|
|
|
|
// from index 11
|
2008-07-31 12:28:12 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint64_t)0ULL, bf.getMissingUnusedLength(11));
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
|
|
|
|
// from index 12
|
2008-07-31 12:28:12 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint64_t)0ULL, bf.getMissingUnusedLength(12));
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
|
|
|
|
// from index 0 and 5th block is used.
|
|
|
|
bf.setUseBit(5);
|
2008-07-31 12:28:12 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint64_t)5ULL*blockLength, bf.getMissingUnusedLength(0));
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
|
|
|
|
// from index 0 and 4th block is acquired.
|
|
|
|
bf.setBit(4);
|
2008-07-31 12:28:12 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint64_t)4ULL*blockLength, bf.getMissingUnusedLength(0));
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
|
|
|
|
// from index 1
|
2008-07-31 12:28:12 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint64_t)3ULL*blockLength, bf.getMissingUnusedLength(1));
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
}
|
2007-03-24 14:32:49 +00:00
|
|
|
|
|
|
|
void BitfieldManTest::testSetBitRange()
|
|
|
|
{
|
2008-03-08 08:04:28 +00:00
|
|
|
size_t blockLength = 1024*1024;
|
|
|
|
uint64_t totalLength = 10*blockLength;
|
2007-03-24 14:32:49 +00:00
|
|
|
|
|
|
|
BitfieldMan bf(blockLength, totalLength);
|
|
|
|
|
|
|
|
bf.setBitRange(0, 4);
|
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
for(size_t i = 0; i < 5; ++i) {
|
2007-03-24 14:32:49 +00:00
|
|
|
CPPUNIT_ASSERT(bf.isBitSet(i));
|
|
|
|
}
|
2008-03-08 08:04:28 +00:00
|
|
|
for(size_t i = 5; i < 10; ++i) {
|
2007-03-24 14:32:49 +00:00
|
|
|
CPPUNIT_ASSERT(!bf.isBitSet(i));
|
|
|
|
}
|
2008-07-31 12:28:12 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint64_t)5ULL*blockLength, bf.getCompletedLength());
|
2007-03-24 14:32:49 +00:00
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
|
|
|
|
void BitfieldManTest::testGetAllMissingIndexes_noarg()
|
|
|
|
{
|
2008-03-08 08:04:28 +00:00
|
|
|
size_t blockLength = 16*1024;
|
|
|
|
uint64_t totalLength = 1024*1024;
|
2009-03-28 13:29:38 +00:00
|
|
|
size_t nbits = (totalLength+blockLength-1)/blockLength;
|
2008-01-11 13:32:00 +00:00
|
|
|
BitfieldMan bf(blockLength, totalLength);
|
2009-03-28 13:29:38 +00:00
|
|
|
unsigned char misbitfield[8];
|
|
|
|
CPPUNIT_ASSERT(bf.getAllMissingIndexes(misbitfield, sizeof(misbitfield)));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)64, bitfield::countSetBit(misbitfield, nbits));
|
2008-01-11 13:32:00 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
for(size_t i = 0; i < 63; ++i) {
|
2008-01-11 13:32:00 +00:00
|
|
|
bf.setBit(i);
|
|
|
|
}
|
2009-03-28 13:29:38 +00:00
|
|
|
CPPUNIT_ASSERT(bf.getAllMissingIndexes(misbitfield, sizeof(misbitfield)));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, bitfield::countSetBit(misbitfield, nbits));
|
|
|
|
CPPUNIT_ASSERT(bitfield::test(misbitfield, nbits, 63));
|
|
|
|
}
|
|
|
|
|
|
|
|
// See garbage bits of last byte are 0
|
|
|
|
void BitfieldManTest::testGetAllMissingIndexes_checkLastByte()
|
|
|
|
{
|
|
|
|
size_t blockLength = 16*1024;
|
|
|
|
uint64_t totalLength = blockLength*2;
|
|
|
|
size_t nbits = (totalLength+blockLength-1)/blockLength;
|
|
|
|
BitfieldMan bf(blockLength, totalLength);
|
|
|
|
unsigned char misbitfield[1];
|
|
|
|
CPPUNIT_ASSERT(bf.getAllMissingIndexes(misbitfield, sizeof(misbitfield)));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, bitfield::countSetBit(misbitfield, nbits));
|
|
|
|
CPPUNIT_ASSERT(bitfield::test(misbitfield, nbits, 0));
|
|
|
|
CPPUNIT_ASSERT(bitfield::test(misbitfield, nbits, 1));
|
2008-01-11 13:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BitfieldManTest::testGetAllMissingIndexes()
|
|
|
|
{
|
2008-03-08 08:04:28 +00:00
|
|
|
size_t blockLength = 16*1024;
|
|
|
|
uint64_t totalLength = 1024*1024;
|
2009-03-28 13:29:38 +00:00
|
|
|
size_t nbits = (totalLength+blockLength-1)/blockLength;
|
2008-01-11 13:32:00 +00:00
|
|
|
BitfieldMan bf(blockLength, totalLength);
|
|
|
|
BitfieldMan peerBf(blockLength, totalLength);
|
|
|
|
peerBf.setAllBit();
|
2009-03-28 13:29:38 +00:00
|
|
|
unsigned char misbitfield[8];
|
2008-01-11 13:32:00 +00:00
|
|
|
|
2009-03-28 13:29:38 +00:00
|
|
|
CPPUNIT_ASSERT(bf.getAllMissingIndexes(misbitfield, sizeof(misbitfield),
|
|
|
|
peerBf.getBitfield(),
|
|
|
|
peerBf.getBitfieldLength()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)64, bitfield::countSetBit(misbitfield, nbits));
|
2008-03-08 08:04:28 +00:00
|
|
|
for(size_t i = 0; i < 62; ++i) {
|
2008-01-11 13:32:00 +00:00
|
|
|
bf.setBit(i);
|
|
|
|
}
|
|
|
|
peerBf.unsetBit(62);
|
2009-03-28 13:29:38 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT(bf.getAllMissingIndexes(misbitfield, sizeof(misbitfield),
|
|
|
|
peerBf.getBitfield(),
|
|
|
|
peerBf.getBitfieldLength()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, bitfield::countSetBit(misbitfield, nbits));
|
|
|
|
CPPUNIT_ASSERT(bitfield::test(misbitfield, nbits, 63));
|
2008-05-11 07:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BitfieldManTest::testGetAllMissingUnusedIndexes()
|
|
|
|
{
|
|
|
|
size_t blockLength = 16*1024;
|
|
|
|
uint64_t totalLength = 1024*1024;
|
2009-03-28 13:29:38 +00:00
|
|
|
size_t nbits = (totalLength+blockLength-1)/blockLength;
|
2008-05-11 07:37:46 +00:00
|
|
|
BitfieldMan bf(blockLength, totalLength);
|
|
|
|
BitfieldMan peerBf(blockLength, totalLength);
|
|
|
|
peerBf.setAllBit();
|
2009-03-28 13:29:38 +00:00
|
|
|
unsigned char misbitfield[8];
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(bf.getAllMissingUnusedIndexes(misbitfield,
|
|
|
|
sizeof(misbitfield),
|
|
|
|
peerBf.getBitfield(),
|
|
|
|
peerBf.getBitfieldLength()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)64, bitfield::countSetBit(misbitfield, nbits));
|
2008-01-11 13:32:00 +00:00
|
|
|
|
2008-05-11 07:37:46 +00:00
|
|
|
for(size_t i = 0; i < 61; ++i) {
|
|
|
|
bf.setBit(i);
|
|
|
|
}
|
|
|
|
bf.setUseBit(61);
|
|
|
|
peerBf.unsetBit(62);
|
2009-03-28 13:29:38 +00:00
|
|
|
CPPUNIT_ASSERT(bf.getAllMissingUnusedIndexes(misbitfield,
|
|
|
|
sizeof(misbitfield),
|
|
|
|
peerBf.getBitfield(),
|
|
|
|
peerBf.getBitfieldLength()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, bitfield::countSetBit(misbitfield, nbits));
|
|
|
|
CPPUNIT_ASSERT(bitfield::test(misbitfield, nbits, 63));
|
2008-01-11 13:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BitfieldManTest::testGetMissingUnusedIndex()
|
|
|
|
{
|
|
|
|
BitfieldMan bt1(1024, 1024*256);
|
|
|
|
bt1.setRandomizer(fixedNumberRandomizer);
|
2008-03-08 08:04:28 +00:00
|
|
|
size_t index;
|
|
|
|
{
|
|
|
|
unsigned char bitArray[] = {
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
};
|
|
|
|
CPPUNIT_ASSERT(bt1.getMissingUnusedIndex(index, bitArray, 32));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, index);
|
2008-01-11 13:32:00 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
bt1.addFilter(1024, 1024*256);
|
|
|
|
bt1.enableFilter();
|
|
|
|
CPPUNIT_ASSERT(bt1.getMissingUnusedIndex(index, bitArray, 32));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, index);
|
|
|
|
bt1.setUseBit(1);
|
|
|
|
CPPUNIT_ASSERT(bt1.getMissingUnusedIndex(index, bitArray, 32));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, index);
|
|
|
|
bt1.disableFilter();
|
2008-01-11 13:32:00 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
bt1.setBit(0);
|
|
|
|
CPPUNIT_ASSERT(bt1.getMissingUnusedIndex(index, bitArray, 32));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, index);
|
2008-01-11 13:32:00 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
bt1.setAllBit();
|
|
|
|
CPPUNIT_ASSERT(!bt1.getMissingUnusedIndex(index, bitArray, 32));
|
2008-01-11 13:32:00 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
bt1.clearAllBit();
|
|
|
|
bt1.setAllUseBit();
|
|
|
|
CPPUNIT_ASSERT(!bt1.getMissingUnusedIndex(index, bitArray, 32));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
unsigned char bitArray4[] = {
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
};
|
|
|
|
CPPUNIT_ASSERT(!bt1.getMissingUnusedIndex(index, bitArray4, 32));
|
|
|
|
}
|
2008-01-11 13:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BitfieldManTest::testCountFilteredBlock()
|
|
|
|
{
|
|
|
|
BitfieldMan bt(1024, 1024*256);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)256, bt.countBlock());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, bt.countFilteredBlock());
|
2008-01-11 13:32:00 +00:00
|
|
|
bt.addFilter(1024, 1024*256);
|
|
|
|
bt.enableFilter();
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)256, bt.countBlock());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)255, bt.countFilteredBlock());
|
2008-01-11 13:32:00 +00:00
|
|
|
bt.disableFilter();
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)256, bt.countBlock());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, bt.countFilteredBlock());
|
2008-01-11 13:32:00 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-06-17 11:43:29 +00:00
|
|
|
void BitfieldManTest::testCountMissingBlock()
|
|
|
|
{
|
|
|
|
BitfieldMan bt(1024, 1024*10);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)10, bt.countMissingBlock());
|
|
|
|
bt.setBit(1);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)9, bt.countMissingBlock());
|
|
|
|
bt.setAllBit();
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, bt.countMissingBlock());
|
|
|
|
}
|
|
|
|
|
2009-05-12 15:19:27 +00:00
|
|
|
void BitfieldManTest::testZeroLengthFilter()
|
|
|
|
{
|
|
|
|
BitfieldMan bt(1024, 1024*10);
|
|
|
|
bt.enableFilter();
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, bt.countMissingBlock());
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|