mirror of https://github.com/aria2/aria2
60 lines
1.3 KiB
C++
60 lines
1.3 KiB
C++
#include "Peer.h"
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
using namespace std;
|
|
|
|
class PeerTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(PeerTest);
|
|
CPPUNIT_TEST(testPeerAllowedIndexSet);
|
|
CPPUNIT_TEST(testAmAllowedIndexSet);
|
|
CPPUNIT_TEST(testGetId);
|
|
CPPUNIT_TEST(testOperatorEqual);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
private:
|
|
PeerHandle peer;
|
|
public:
|
|
PeerTest():peer(0) {}
|
|
|
|
void setUp() {
|
|
peer = new Peer("localhost", 6969);
|
|
}
|
|
|
|
void testPeerAllowedIndexSet();
|
|
void testAmAllowedIndexSet();
|
|
void testGetId();
|
|
void testOperatorEqual();
|
|
};
|
|
|
|
|
|
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() {
|
|
CPPUNIT_ASSERT_EQUAL(string("f05897fc14a41cb3400e283e189158656d7184da"),
|
|
peer->getId());
|
|
}
|
|
|
|
void PeerTest::testOperatorEqual()
|
|
{
|
|
CPPUNIT_ASSERT(Peer("localhost", 6881) == Peer("localhost", 6881));
|
|
|
|
{
|
|
Peer p1("localhost", 6881);
|
|
Peer p2("localhsot", 0);
|
|
p2.port = 6881;
|
|
CPPUNIT_ASSERT(p1 != p2);
|
|
}
|
|
}
|