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);
|
2009-06-07 05:34:10 +00:00
|
|
|
CPPUNIT_TEST(testCountSeeder);
|
2006-12-24 06:25:21 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<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();
|
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));
|
|
|
|
}
|
|
|
|
|
2009-06-07 05:34:10 +00:00
|
|
|
void PeerTest::testCountSeeder()
|
|
|
|
{
|
2013-06-21 16:10:38 +00:00
|
|
|
std::vector<std::shared_ptr<Peer> > peers(5);
|
2009-06-07 05:34:10 +00:00
|
|
|
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));
|
2013-06-21 16:10:38 +00:00
|
|
|
for(std::vector<std::shared_ptr<Peer> >::iterator i = peers.begin();
|
2009-06-07 05:34:10 +00:00
|
|
|
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
|