2006-12-24 06:25:21 +00:00
|
|
|
#include "Peer.h"
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2006-12-24 06:25:21 +00:00
|
|
|
|
|
|
|
class PeerTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(PeerTest);
|
|
|
|
CPPUNIT_TEST(testPeerAllowedIndexSet);
|
|
|
|
CPPUNIT_TEST(testAmAllowedIndexSet);
|
|
|
|
CPPUNIT_TEST(testGetId);
|
2008-01-10 14:59:11 +00:00
|
|
|
CPPUNIT_TEST(testOperatorEqual);
|
2009-06-07 05:34:10 +00:00
|
|
|
CPPUNIT_TEST(testCountSeeder);
|
2006-12-24 06:25:21 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Peer> peer;
|
2006-12-24 06:25:21 +00:00
|
|
|
public:
|
|
|
|
void setUp() {
|
2008-04-20 00:50:22 +00:00
|
|
|
peer.reset(new Peer("localhost", 6969));
|
2008-02-09 17:14:40 +00:00
|
|
|
peer->allocateSessionResource(1024, 1024*1024);
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void testPeerAllowedIndexSet();
|
|
|
|
void testAmAllowedIndexSet();
|
|
|
|
void testGetId();
|
2008-01-10 14:59:11 +00:00
|
|
|
void testOperatorEqual();
|
2009-06-07 05:34:10 +00:00
|
|
|
void testCountSeeder();
|
2006-12-24 06:25:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(PeerTest);
|
|
|
|
|
|
|
|
void PeerTest::testPeerAllowedIndexSet() {
|
|
|
|
CPPUNIT_ASSERT(!peer->isInPeerAllowedIndexSet(0));
|
|
|
|
peer->addPeerAllowedIndex(0);
|
|
|
|
CPPUNIT_ASSERT(peer->isInPeerAllowedIndexSet(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeerTest::testAmAllowedIndexSet() {
|
|
|
|
CPPUNIT_ASSERT(!peer->isInAmAllowedIndexSet(0));
|
|
|
|
peer->addAmAllowedIndex(0);
|
|
|
|
CPPUNIT_ASSERT(peer->isInAmAllowedIndexSet(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeerTest::testGetId() {
|
2010-03-05 12:54:20 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("localhost:6969"), peer->getID());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
2008-01-10 14:59:11 +00:00
|
|
|
|
|
|
|
void PeerTest::testOperatorEqual()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT(Peer("localhost", 6881) == Peer("localhost", 6881));
|
|
|
|
|
|
|
|
{
|
|
|
|
Peer p1("localhost", 6881);
|
|
|
|
Peer p2("localhsot", 0);
|
2010-06-13 01:53:49 +00:00
|
|
|
p2.setPort(6881);
|
2008-01-10 14:59:11 +00:00
|
|
|
CPPUNIT_ASSERT(p1 != p2);
|
|
|
|
}
|
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2009-06-07 05:34:10 +00:00
|
|
|
void PeerTest::testCountSeeder()
|
|
|
|
{
|
|
|
|
std::vector<SharedHandle<Peer> > peers(5);
|
|
|
|
peers[0].reset(new Peer("192.168.0.1", 7000));
|
|
|
|
peers[1].reset(new Peer("192.168.0.2", 7000));
|
|
|
|
peers[2].reset(new Peer("192.168.0.3", 7000));
|
|
|
|
peers[3].reset(new Peer("192.168.0.4", 7000));
|
|
|
|
peers[4].reset(new Peer("192.168.0.5", 7000));
|
|
|
|
for(std::vector<SharedHandle<Peer> >::iterator i = peers.begin();
|
|
|
|
i != peers.end(); ++i) {
|
|
|
|
(*i)->allocateSessionResource(1024, 1024*8);
|
|
|
|
}
|
|
|
|
unsigned char bitfield[] = { 0xff };
|
|
|
|
peers[1]->setBitfield(bitfield, 1);
|
|
|
|
peers[3]->setBitfield(bitfield, 1);
|
|
|
|
peers[4]->setBitfield(bitfield, 1);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, countSeeder(peers.begin(), peers.end()));
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|