mirror of
https://github.com/aria2/aria2.git
synced 2025-04-05 21:47:37 +03:00
make clang-format using clang-format-3.6
This commit is contained in:
parent
4abad2f64c
commit
b1132d6b10
1095 changed files with 30423 additions and 33770 deletions
|
@ -18,14 +18,16 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
class BtRequestMessageTest:public CppUnit::TestFixture {
|
||||
class BtRequestMessageTest : public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(BtRequestMessageTest);
|
||||
CPPUNIT_TEST(testCreate);
|
||||
CPPUNIT_TEST(testCreateMessage);
|
||||
CPPUNIT_TEST(testDoReceivedAction_hasPieceAndAmNotChoking);
|
||||
CPPUNIT_TEST(testDoReceivedAction_hasPieceAndAmChokingAndFastExtensionEnabled);
|
||||
CPPUNIT_TEST(testDoReceivedAction_hasPieceAndAmChokingAndFastExtensionDisabled);
|
||||
CPPUNIT_TEST(
|
||||
testDoReceivedAction_hasPieceAndAmChokingAndFastExtensionEnabled);
|
||||
CPPUNIT_TEST(
|
||||
testDoReceivedAction_hasPieceAndAmChokingAndFastExtensionDisabled);
|
||||
CPPUNIT_TEST(testDoReceivedAction_doesntHavePieceAndFastExtensionEnabled);
|
||||
CPPUNIT_TEST(testDoReceivedAction_doesntHavePieceAndFastExtensionDisabled);
|
||||
CPPUNIT_TEST(testHandleAbortRequestEvent);
|
||||
|
@ -35,8 +37,8 @@ class BtRequestMessageTest:public CppUnit::TestFixture {
|
|||
CPPUNIT_TEST(testValidate);
|
||||
CPPUNIT_TEST(testValidate_lengthTooLong);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
private:
|
||||
public:
|
||||
void testCreate();
|
||||
void testCreateMessage();
|
||||
|
@ -54,24 +56,21 @@ public:
|
|||
|
||||
class MockPieceStorage2 : public MockPieceStorage {
|
||||
public:
|
||||
virtual bool hasPiece(size_t index) CXX11_OVERRIDE
|
||||
{
|
||||
return index == 1;
|
||||
}
|
||||
virtual bool hasPiece(size_t index) CXX11_OVERRIDE { return index == 1; }
|
||||
};
|
||||
|
||||
class MockBtMessageFactory2 : public MockBtMessageFactory {
|
||||
public:
|
||||
virtual std::unique_ptr<BtPieceMessage>
|
||||
createPieceMessage(size_t index, int32_t begin, int32_t length)
|
||||
CXX11_OVERRIDE
|
||||
createPieceMessage(size_t index, int32_t begin,
|
||||
int32_t length) CXX11_OVERRIDE
|
||||
{
|
||||
return make_unique<BtPieceMessage>(index, begin, length);
|
||||
}
|
||||
|
||||
virtual std::unique_ptr<BtRejectMessage>
|
||||
createRejectMessage(size_t index, int32_t begin, int32_t length)
|
||||
CXX11_OVERRIDE
|
||||
createRejectMessage(size_t index, int32_t begin,
|
||||
int32_t length) CXX11_OVERRIDE
|
||||
{
|
||||
return make_unique<BtRejectMessage>(index, begin, length);
|
||||
}
|
||||
|
@ -83,7 +82,8 @@ public:
|
|||
std::unique_ptr<MockBtMessageFactory> messageFactory_;
|
||||
std::unique_ptr<BtRequestMessage> msg;
|
||||
|
||||
void setUp() {
|
||||
void setUp()
|
||||
{
|
||||
pieceStorage_ = make_unique<MockPieceStorage2>();
|
||||
|
||||
peer_ = std::make_shared<Peer>("host", 6969);
|
||||
|
@ -105,10 +105,10 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(BtRequestMessageTest);
|
||||
|
||||
void BtRequestMessageTest::testCreate() {
|
||||
void BtRequestMessageTest::testCreate()
|
||||
{
|
||||
unsigned char msg[17];
|
||||
bittorrent::createPeerMessageString(msg, sizeof(msg), 13, 6);
|
||||
bittorrent::setIntParam(&msg[5], 12345);
|
||||
|
@ -126,7 +126,8 @@ void BtRequestMessageTest::testCreate() {
|
|||
bittorrent::createPeerMessageString(msg, sizeof(msg), 14, 6);
|
||||
BtRequestMessage::create(&msg[4], 14);
|
||||
CPPUNIT_FAIL("exception must be thrown.");
|
||||
} catch(...) {
|
||||
}
|
||||
catch (...) {
|
||||
}
|
||||
// case: id is wrong
|
||||
try {
|
||||
|
@ -134,11 +135,13 @@ void BtRequestMessageTest::testCreate() {
|
|||
bittorrent::createPeerMessageString(msg, sizeof(msg), 13, 7);
|
||||
BtRequestMessage::create(&msg[4], 13);
|
||||
CPPUNIT_FAIL("exception must be thrown.");
|
||||
} catch(...) {
|
||||
}
|
||||
catch (...) {
|
||||
}
|
||||
}
|
||||
|
||||
void BtRequestMessageTest::testCreateMessage() {
|
||||
void BtRequestMessageTest::testCreateMessage()
|
||||
{
|
||||
BtRequestMessage msg;
|
||||
msg.setIndex(12345);
|
||||
msg.setBegin(256);
|
||||
|
@ -150,24 +153,27 @@ void BtRequestMessageTest::testCreateMessage() {
|
|||
bittorrent::setIntParam(&data[13], 1_k);
|
||||
unsigned char* rawmsg = msg.createMessage();
|
||||
CPPUNIT_ASSERT(memcmp(rawmsg, data, 17) == 0);
|
||||
delete [] rawmsg;
|
||||
delete[] rawmsg;
|
||||
}
|
||||
|
||||
void BtRequestMessageTest::testDoReceivedAction_hasPieceAndAmNotChoking() {
|
||||
void BtRequestMessageTest::testDoReceivedAction_hasPieceAndAmNotChoking()
|
||||
{
|
||||
peer_->amChoking(false);
|
||||
msg->doReceivedAction();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, dispatcher_->messageQueue.size());
|
||||
CPPUNIT_ASSERT(BtPieceMessage::ID ==
|
||||
dispatcher_->messageQueue.front()->getId());
|
||||
auto pieceMsg = static_cast<const BtPieceMessage*>
|
||||
(dispatcher_->messageQueue.front().get());
|
||||
auto pieceMsg = static_cast<const BtPieceMessage*>(
|
||||
dispatcher_->messageQueue.front().get());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, pieceMsg->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL((int32_t)16, pieceMsg->getBegin());
|
||||
CPPUNIT_ASSERT_EQUAL((int32_t)32, pieceMsg->getBlockLength());
|
||||
}
|
||||
|
||||
void BtRequestMessageTest::testDoReceivedAction_hasPieceAndAmChokingAndFastExtensionEnabled() {
|
||||
void BtRequestMessageTest::
|
||||
testDoReceivedAction_hasPieceAndAmChokingAndFastExtensionEnabled()
|
||||
{
|
||||
peer_->amChoking(true);
|
||||
peer_->setFastExtensionEnabled(true);
|
||||
msg->doReceivedAction();
|
||||
|
@ -175,21 +181,25 @@ void BtRequestMessageTest::testDoReceivedAction_hasPieceAndAmChokingAndFastExten
|
|||
CPPUNIT_ASSERT_EQUAL((size_t)1, dispatcher_->messageQueue.size());
|
||||
CPPUNIT_ASSERT(BtRejectMessage::ID ==
|
||||
dispatcher_->messageQueue.front()->getId());
|
||||
auto rejectMsg = static_cast<const BtRejectMessage*>
|
||||
(dispatcher_->messageQueue.front().get());
|
||||
auto rejectMsg = static_cast<const BtRejectMessage*>(
|
||||
dispatcher_->messageQueue.front().get());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, rejectMsg->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL((int32_t)16, rejectMsg->getBegin());
|
||||
CPPUNIT_ASSERT_EQUAL((int32_t)32, rejectMsg->getLength());
|
||||
}
|
||||
|
||||
void BtRequestMessageTest::testDoReceivedAction_hasPieceAndAmChokingAndFastExtensionDisabled() {
|
||||
void BtRequestMessageTest::
|
||||
testDoReceivedAction_hasPieceAndAmChokingAndFastExtensionDisabled()
|
||||
{
|
||||
peer_->amChoking(true);
|
||||
msg->doReceivedAction();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)0, dispatcher_->messageQueue.size());
|
||||
}
|
||||
|
||||
void BtRequestMessageTest::testDoReceivedAction_doesntHavePieceAndFastExtensionEnabled() {
|
||||
void BtRequestMessageTest::
|
||||
testDoReceivedAction_doesntHavePieceAndFastExtensionEnabled()
|
||||
{
|
||||
msg->setIndex(2);
|
||||
peer_->amChoking(false);
|
||||
peer_->setFastExtensionEnabled(true);
|
||||
|
@ -198,14 +208,16 @@ void BtRequestMessageTest::testDoReceivedAction_doesntHavePieceAndFastExtensionE
|
|||
CPPUNIT_ASSERT_EQUAL((size_t)1, dispatcher_->messageQueue.size());
|
||||
CPPUNIT_ASSERT(BtRejectMessage::ID ==
|
||||
dispatcher_->messageQueue.front()->getId());
|
||||
auto rejectMsg = static_cast<const BtRejectMessage*>
|
||||
(dispatcher_->messageQueue.front().get());
|
||||
auto rejectMsg = static_cast<const BtRejectMessage*>(
|
||||
dispatcher_->messageQueue.front().get());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, rejectMsg->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL((int32_t)16, rejectMsg->getBegin());
|
||||
CPPUNIT_ASSERT_EQUAL((int32_t)32, rejectMsg->getLength());
|
||||
}
|
||||
|
||||
void BtRequestMessageTest::testDoReceivedAction_doesntHavePieceAndFastExtensionDisabled() {
|
||||
void BtRequestMessageTest::
|
||||
testDoReceivedAction_doesntHavePieceAndFastExtensionDisabled()
|
||||
{
|
||||
msg->setIndex(2);
|
||||
peer_->amChoking(false);
|
||||
msg->doReceivedAction();
|
||||
|
@ -213,21 +225,24 @@ void BtRequestMessageTest::testDoReceivedAction_doesntHavePieceAndFastExtensionD
|
|||
CPPUNIT_ASSERT_EQUAL((size_t)0, dispatcher_->messageQueue.size());
|
||||
}
|
||||
|
||||
void BtRequestMessageTest::testHandleAbortRequestEvent() {
|
||||
void BtRequestMessageTest::testHandleAbortRequestEvent()
|
||||
{
|
||||
auto piece = std::make_shared<Piece>(1, 16_k);
|
||||
CPPUNIT_ASSERT(!msg->isInvalidate());
|
||||
msg->onAbortOutstandingRequestEvent(BtAbortOutstandingRequestEvent(piece));
|
||||
CPPUNIT_ASSERT(msg->isInvalidate());
|
||||
}
|
||||
|
||||
void BtRequestMessageTest::testHandleAbortRequestEvent_indexNoMatch() {
|
||||
void BtRequestMessageTest::testHandleAbortRequestEvent_indexNoMatch()
|
||||
{
|
||||
auto piece = std::make_shared<Piece>(2, 16_k);
|
||||
CPPUNIT_ASSERT(!msg->isInvalidate());
|
||||
msg->onAbortOutstandingRequestEvent(BtAbortOutstandingRequestEvent(piece));
|
||||
CPPUNIT_ASSERT(!msg->isInvalidate());
|
||||
}
|
||||
|
||||
void BtRequestMessageTest::testHandleAbortRequestEvent_alreadyInvalidated() {
|
||||
void BtRequestMessageTest::testHandleAbortRequestEvent_alreadyInvalidated()
|
||||
{
|
||||
auto piece = std::make_shared<Piece>(1, 16_k);
|
||||
msg->setInvalidate(true);
|
||||
CPPUNIT_ASSERT(msg->isInvalidate());
|
||||
|
@ -235,26 +250,30 @@ void BtRequestMessageTest::testHandleAbortRequestEvent_alreadyInvalidated() {
|
|||
CPPUNIT_ASSERT(msg->isInvalidate());
|
||||
}
|
||||
|
||||
void BtRequestMessageTest::testToString() {
|
||||
void BtRequestMessageTest::testToString()
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("request index=1, begin=16, length=32"),
|
||||
msg->toString());
|
||||
}
|
||||
|
||||
void BtRequestMessageTest::testValidate() {
|
||||
void BtRequestMessageTest::testValidate()
|
||||
{
|
||||
BtRequestMessage msg(0, 0, 16_k);
|
||||
msg.setBtMessageValidator
|
||||
(make_unique<RangeBtMessageValidator>(&msg, 1_k, 256_k));
|
||||
msg.setBtMessageValidator(
|
||||
make_unique<RangeBtMessageValidator>(&msg, 1_k, 256_k));
|
||||
msg.validate();
|
||||
}
|
||||
|
||||
void BtRequestMessageTest::testValidate_lengthTooLong() {
|
||||
BtRequestMessage msg(0, 0, 16_k+1);
|
||||
msg.setBtMessageValidator
|
||||
(make_unique<RangeBtMessageValidator>(&msg, 1_k, 256_k));
|
||||
void BtRequestMessageTest::testValidate_lengthTooLong()
|
||||
{
|
||||
BtRequestMessage msg(0, 0, 16_k + 1);
|
||||
msg.setBtMessageValidator(
|
||||
make_unique<RangeBtMessageValidator>(&msg, 1_k, 256_k));
|
||||
try {
|
||||
msg.validate();
|
||||
CPPUNIT_FAIL("exception must be thrown.");
|
||||
} catch(DlAbortEx& e) {
|
||||
}
|
||||
catch (DlAbortEx& e) {
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("Length too long: 16385 > 16KB"),
|
||||
std::string(e.what()));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue