summaryrefslogtreecommitdiff
path: root/test/DHTBucketTest.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-01-05 16:01:46 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-01-05 16:01:46 +0000
commit4db349c1f32b4a313d12d114137432441633d00a (patch)
tree417451971e264834312cfd8339c79930d680a5d1 /test/DHTBucketTest.cc
parent338e8aca09331d3e7fa4e1e8e1f9d10260986772 (diff)
2010-01-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Untabify. Fixed one line in copyright which is longer than 80 columns. * src * test
Diffstat (limited to 'test/DHTBucketTest.cc')
-rw-r--r--test/DHTBucketTest.cc186
1 files changed, 93 insertions, 93 deletions
diff --git a/test/DHTBucketTest.cc b/test/DHTBucketTest.cc
index 3ee56497..5db4e879 100644
--- a/test/DHTBucketTest.cc
+++ b/test/DHTBucketTest.cc
@@ -48,9 +48,9 @@ CPPUNIT_TEST_SUITE_REGISTRATION(DHTBucketTest);
void DHTBucketTest::testGetRandomNodeID()
{
unsigned char localNodeID[] = { 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, 0x00, 0x00, 0x00 };
SharedHandle<DHTNode> localNode(new DHTNode(localNodeID));
{
DHTBucket bucket(localNode);
@@ -59,33 +59,33 @@ void DHTBucketTest::testGetRandomNodeID()
}
{
unsigned char max[] = { 0x01, 0x01, 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, 0xff };
unsigned char min[] = { 0x01, 0x01, 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, 0x00 };
DHTBucket bucket(16, max, min, localNode);
unsigned char nodeID[DHT_ID_LENGTH];
bucket.getRandomNodeID(nodeID);
CPPUNIT_ASSERT_EQUAL(std::string("0101"),
- util::toHex(nodeID, sizeof(nodeID)).substr(0, 4));
+ util::toHex(nodeID, sizeof(nodeID)).substr(0, 4));
}
}
void DHTBucketTest::testIsInRange()
{
unsigned char localNodeID[] = { 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, 0x00, 0x00, 0x00 };
SharedHandle<DHTNode> localNode(new DHTNode(localNodeID));
{
unsigned char nodeID[] = { 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, 0x00, 0x00, 0x00 };
SharedHandle<DHTNode> node(new DHTNode(nodeID));
DHTBucket bucket(localNode);
CPPUNIT_ASSERT(bucket.isInRange(node));
@@ -94,19 +94,19 @@ void DHTBucketTest::testIsInRange()
}
{
unsigned char max[] = { 0x01, 0x01, 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, 0xff };
unsigned char min[] = { 0x01, 0x01, 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, 0x00 };
{
//min
unsigned char nodeID[] = { 0x01, 0x01, 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, 0x00 };
SharedHandle<DHTNode> node(new DHTNode(nodeID));
DHTBucket bucket(16, max, min, localNode);
CPPUNIT_ASSERT(bucket.isInRange(node));
@@ -114,18 +114,18 @@ void DHTBucketTest::testIsInRange()
{
//max
unsigned char nodeID[] = { 0x01, 0x01, 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, 0xff };
SharedHandle<DHTNode> node(new DHTNode(nodeID));
DHTBucket bucket(16, max, min, localNode);
CPPUNIT_ASSERT(bucket.isInRange(node));
}
{
unsigned char nodeID[] = { 0x01, 0x01, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff };
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff };
SharedHandle<DHTNode> node(new DHTNode(nodeID));
DHTBucket bucket(16, max, min, localNode);
CPPUNIT_ASSERT(bucket.isInRange(node));
@@ -133,9 +133,9 @@ void DHTBucketTest::testIsInRange()
{
// nodeID is out of range: smaller than this range
unsigned char nodeID[] = { 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, 0x00, 0x00, 0x00 };
SharedHandle<DHTNode> node(new DHTNode(nodeID));
DHTBucket bucket(16, max, min, localNode);
CPPUNIT_ASSERT(!bucket.isInRange(node));
@@ -143,9 +143,9 @@ void DHTBucketTest::testIsInRange()
{
// nodeID is out of range: larger than this range
unsigned char nodeID[] = { 0x01, 0x02, 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, 0xff };
SharedHandle<DHTNode> node(new DHTNode(nodeID));
DHTBucket bucket(16, max, min, localNode);
CPPUNIT_ASSERT(!bucket.isInRange(node));
@@ -157,36 +157,36 @@ void DHTBucketTest::testSplitAllowed()
{
{
unsigned char localNodeID[] = { 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, 0x00, 0x00, 0x00 };
SharedHandle<DHTNode> localNode(new DHTNode(localNodeID));
DHTBucket bucket(localNode);
CPPUNIT_ASSERT(bucket.splitAllowed());
}
{
unsigned char max[] = { 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, 0xff, 0xff, 0xff };
unsigned char min[] = { 0xe0, 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, 0x00, 0x00 };
{
unsigned char localNodeID[] = { 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, 0x00, 0x00, 0x00 };
SharedHandle<DHTNode> localNode(new DHTNode(localNodeID));
DHTBucket bucket(3, max, min, localNode);
CPPUNIT_ASSERT(!bucket.splitAllowed());
}
{
unsigned char localNodeID[] = { 0xe0, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x01 };
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x01 };
SharedHandle<DHTNode> localNode(new DHTNode(localNodeID));
DHTBucket bucket(3, max, min, localNode);
CPPUNIT_ASSERT(bucket.splitAllowed());
@@ -204,51 +204,51 @@ void DHTBucketTest::testSplit()
DHTBucket bucket(localNode);
SharedHandle<DHTBucket> r = bucket.split();
{
- unsigned char expectedRMax[] = { 0x7f, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff };
- unsigned char expectedRMin[DHT_ID_LENGTH];
- memset(expectedRMin, 0, DHT_ID_LENGTH);
- CPPUNIT_ASSERT_EQUAL(util::toHex(expectedRMax, DHT_ID_LENGTH),
- util::toHex(r->getMaxID(), DHT_ID_LENGTH));
- CPPUNIT_ASSERT_EQUAL(util::toHex(expectedRMin, DHT_ID_LENGTH),
- util::toHex(r->getMinID(), DHT_ID_LENGTH));
- CPPUNIT_ASSERT_EQUAL((size_t)1, r->getPrefixLength());
+ unsigned char expectedRMax[] = { 0x7f, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff };
+ unsigned char expectedRMin[DHT_ID_LENGTH];
+ memset(expectedRMin, 0, DHT_ID_LENGTH);
+ CPPUNIT_ASSERT_EQUAL(util::toHex(expectedRMax, DHT_ID_LENGTH),
+ util::toHex(r->getMaxID(), DHT_ID_LENGTH));
+ CPPUNIT_ASSERT_EQUAL(util::toHex(expectedRMin, DHT_ID_LENGTH),
+ util::toHex(r->getMinID(), DHT_ID_LENGTH));
+ CPPUNIT_ASSERT_EQUAL((size_t)1, r->getPrefixLength());
}
{
- unsigned char expectedLMax[DHT_ID_LENGTH];
- memset(expectedLMax, 0xff, DHT_ID_LENGTH);
- unsigned char expectedLMin[] = { 0x80, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00 };
- CPPUNIT_ASSERT_EQUAL(util::toHex(expectedLMax, DHT_ID_LENGTH),
- util::toHex(bucket.getMaxID(), DHT_ID_LENGTH));
- CPPUNIT_ASSERT_EQUAL(util::toHex(expectedLMin, DHT_ID_LENGTH),
- util::toHex(bucket.getMinID(), DHT_ID_LENGTH));
- CPPUNIT_ASSERT_EQUAL((size_t)1, bucket.getPrefixLength());
+ unsigned char expectedLMax[DHT_ID_LENGTH];
+ memset(expectedLMax, 0xff, DHT_ID_LENGTH);
+ unsigned char expectedLMin[] = { 0x80, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00 };
+ CPPUNIT_ASSERT_EQUAL(util::toHex(expectedLMax, DHT_ID_LENGTH),
+ util::toHex(bucket.getMaxID(), DHT_ID_LENGTH));
+ CPPUNIT_ASSERT_EQUAL(util::toHex(expectedLMin, DHT_ID_LENGTH),
+ util::toHex(bucket.getMinID(), DHT_ID_LENGTH));
+ CPPUNIT_ASSERT_EQUAL((size_t)1, bucket.getPrefixLength());
}
}
{
SharedHandle<DHTBucket> bucket(new DHTBucket(localNode));
for(int i = 0; i < 159; ++i) {
- CPPUNIT_ASSERT(bucket->splitAllowed());
- SharedHandle<DHTBucket> t = bucket;
- bucket = bucket->split();
- CPPUNIT_ASSERT(!t->splitAllowed());
+ CPPUNIT_ASSERT(bucket->splitAllowed());
+ SharedHandle<DHTBucket> t = bucket;
+ bucket = bucket->split();
+ CPPUNIT_ASSERT(!t->splitAllowed());
}
CPPUNIT_ASSERT(!bucket->splitAllowed());
unsigned char expectedMax[] = { 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x01 };
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x01 };
unsigned char expectedMin[DHT_ID_LENGTH];
memset(expectedMin, 0, DHT_ID_LENGTH);
CPPUNIT_ASSERT_EQUAL(util::toHex(expectedMax, DHT_ID_LENGTH),
- util::toHex(bucket->getMaxID(), DHT_ID_LENGTH));
+ util::toHex(bucket->getMaxID(), DHT_ID_LENGTH));
CPPUNIT_ASSERT_EQUAL(util::toHex(expectedMin, DHT_ID_LENGTH),
- util::toHex(bucket->getMinID(), DHT_ID_LENGTH));
+ util::toHex(bucket->getMinID(), DHT_ID_LENGTH));
CPPUNIT_ASSERT_EQUAL((size_t)159, bucket->getPrefixLength());
}
}
@@ -261,28 +261,28 @@ void DHTBucketTest::testSplit()
SharedHandle<DHTBucket> r = bucket.split();
{
unsigned char expectedRMax[] = { 0x7f, 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, 0xff, 0xff };
unsigned char expectedRMin[DHT_ID_LENGTH];
memset(expectedRMin, 0, DHT_ID_LENGTH);
CPPUNIT_ASSERT_EQUAL(util::toHex(expectedRMax, DHT_ID_LENGTH),
- util::toHex(r->getMaxID(), DHT_ID_LENGTH));
+ util::toHex(r->getMaxID(), DHT_ID_LENGTH));
CPPUNIT_ASSERT_EQUAL(util::toHex(expectedRMin, DHT_ID_LENGTH),
- util::toHex(r->getMinID(), DHT_ID_LENGTH));
+ util::toHex(r->getMinID(), DHT_ID_LENGTH));
CPPUNIT_ASSERT_EQUAL((size_t)1, r->getPrefixLength());
}
{
unsigned char expectedLMax[DHT_ID_LENGTH];
memset(expectedLMax, 0xff, DHT_ID_LENGTH);
unsigned char expectedLMin[] = { 0x80, 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, 0x00, 0x00 };
CPPUNIT_ASSERT_EQUAL(util::toHex(expectedLMax, DHT_ID_LENGTH),
- util::toHex(bucket.getMaxID(), DHT_ID_LENGTH));
+ util::toHex(bucket.getMaxID(), DHT_ID_LENGTH));
CPPUNIT_ASSERT_EQUAL(util::toHex(expectedLMin, DHT_ID_LENGTH),
- util::toHex(bucket.getMinID(), DHT_ID_LENGTH));
+ util::toHex(bucket.getMinID(), DHT_ID_LENGTH));
CPPUNIT_ASSERT_EQUAL((size_t)1, bucket.getPrefixLength());
}
}