clang-format-4.0

This commit is contained in:
Tatsuhiro Tsujikawa 2017-05-19 21:32:25 +09:00
parent 823bcc4ab0
commit 9677586336
19 changed files with 210 additions and 161 deletions

View file

@ -107,9 +107,9 @@ bool ActivePeerConnectionCommand::execute()
int numConnection = 0; int numConnection = 0;
if (pieceStorage_->downloadFinished()) { if (pieceStorage_->downloadFinished()) {
if (btRuntime_->getMaxPeers() > btRuntime_->getConnections()) { if (btRuntime_->getMaxPeers() > btRuntime_->getConnections()) {
numConnection = numConnection = std::min(numNewConnection_,
std::min(numNewConnection_, btRuntime_->getMaxPeers() - btRuntime_->getMaxPeers() -
btRuntime_->getConnections()); btRuntime_->getConnections());
} }
} }
else { else {

View file

@ -173,10 +173,10 @@ bool BitfieldMan::hasMissingPiece(const unsigned char* peerBitfield,
bool BitfieldMan::getFirstMissingUnusedIndex(size_t& index) const bool BitfieldMan::getFirstMissingUnusedIndex(size_t& index) const
{ {
if (filterEnabled_) { if (filterEnabled_) {
return bitfield::getFirstSetBitIndex(index, ~array(bitfield_) & return bitfield::getFirstSetBitIndex(
~array(useBitfield_) & index,
array(filterBitfield_), ~array(bitfield_) & ~array(useBitfield_) & array(filterBitfield_),
blocks_); blocks_);
} }
else { else {
return bitfield::getFirstSetBitIndex( return bitfield::getFirstSetBitIndex(
@ -305,8 +305,9 @@ bool BitfieldMan::getSparseMissingUnusedIndex(
{ {
if (filterEnabled_) { if (filterEnabled_) {
return aria2::getSparseMissingUnusedIndex( return aria2::getSparseMissingUnusedIndex(
index, minSplitSize, array(ignoreBitfield) | ~array(filterBitfield_) | index, minSplitSize,
array(bitfield_) | array(useBitfield_), array(ignoreBitfield) | ~array(filterBitfield_) | array(bitfield_) |
array(useBitfield_),
useBitfield_, blockLength_, blocks_); useBitfield_, blockLength_, blocks_);
} }
else { else {
@ -361,8 +362,9 @@ bool BitfieldMan::getGeomMissingUnusedIndex(size_t& index, int32_t minSplitSize,
{ {
if (filterEnabled_) { if (filterEnabled_) {
return aria2::getGeomMissingUnusedIndex( return aria2::getGeomMissingUnusedIndex(
index, minSplitSize, array(ignoreBitfield) | ~array(filterBitfield_) | index, minSplitSize,
array(bitfield_) | array(useBitfield_), array(ignoreBitfield) | ~array(filterBitfield_) | array(bitfield_) |
array(useBitfield_),
useBitfield_, blockLength_, blocks_, base, offsetIndex); useBitfield_, blockLength_, blocks_, base, offsetIndex);
} }
else { else {
@ -497,8 +499,9 @@ bool BitfieldMan::getAllMissingIndexes(unsigned char* misbitfield, size_t len,
return false; return false;
} }
if (filterEnabled_) { if (filterEnabled_) {
return copyBitfield(misbitfield, ~array(bitfield_) & array(peerBitfield) & return copyBitfield(misbitfield,
array(filterBitfield_), ~array(bitfield_) & array(peerBitfield) &
array(filterBitfield_),
blocks_); blocks_);
} }
else { else {
@ -523,8 +526,9 @@ bool BitfieldMan::getAllMissingUnusedIndexes(unsigned char* misbitfield,
blocks_); blocks_);
} }
else { else {
return copyBitfield(misbitfield, ~array(bitfield_) & ~array(useBitfield_) & return copyBitfield(misbitfield,
array(peerBitfield), ~array(bitfield_) & ~array(useBitfield_) &
array(peerBitfield),
blocks_); blocks_);
} }
} }

View file

@ -235,9 +235,9 @@ bool FtpConnection::sendPort(const std::shared_ptr<SocketCore>& serverSocket)
bool FtpConnection::sendRest(const std::shared_ptr<Segment>& segment) bool FtpConnection::sendRest(const std::shared_ptr<Segment>& segment)
{ {
if (socketBuffer_.sendBufferIsEmpty()) { if (socketBuffer_.sendBufferIsEmpty()) {
std::string request = std::string request = fmt("REST %" PRId64 "\r\n",
fmt("REST %" PRId64 "\r\n", segment ? segment->getPositionToWrite() segment ? segment->getPositionToWrite()
: static_cast<int64_t>(0LL)); : static_cast<int64_t>(0LL));
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_, request.c_str())); A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_, request.c_str()));
socketBuffer_.pushStr(std::move(request)); socketBuffer_.pushStr(std::move(request));
} }

View file

@ -87,8 +87,9 @@ FtpNegotiationCommand::FtpNegotiationCommand(
: AbstractCommand(cuid, req, fileEntry, requestGroup, e, socket), : AbstractCommand(cuid, req, fileEntry, requestGroup, e, socket),
sequence_(seq), sequence_(seq),
ftp_(std::make_shared<FtpConnection>( ftp_(std::make_shared<FtpConnection>(
cuid, socket, req, e->getAuthConfigFactory()->createAuthConfig( cuid, socket, req,
req, requestGroup->getOption().get()), e->getAuthConfigFactory()->createAuthConfig(
req, requestGroup->getOption().get()),
getOption().get())), getOption().get())),
pasvPort_(0) pasvPort_(0)
{ {

View file

@ -107,9 +107,9 @@ int GnuTLSSession::init(sock_t sockfd)
rv_ = gnutls_init(&sslSession_, flags); rv_ = gnutls_init(&sslSession_, flags);
#else // GNUTLS_VERSION_NUMBER >= 0x030000 #else // GNUTLS_VERSION_NUMBER >= 0x030000
rv_ = gnutls_init(&sslSession_, tlsContext_->getSide() == TLS_CLIENT rv_ = gnutls_init(&sslSession_,
? GNUTLS_CLIENT tlsContext_->getSide() == TLS_CLIENT ? GNUTLS_CLIENT
: GNUTLS_SERVER); : GNUTLS_SERVER);
#endif // GNUTLS_VERSION_NUMBER >= 0x030000 #endif // GNUTLS_VERSION_NUMBER >= 0x030000
if (rv_ != GNUTLS_E_SUCCESS) { if (rv_ != GNUTLS_E_SUCCESS) {
return TLS_ERR_ERROR; return TLS_ERR_ERROR;

View file

@ -125,12 +125,13 @@ OpenSSLTLSContext::OpenSSLTLSContext(TLSSessionSide side, TLSVersion minVer)
}; };
// Disable SSLv2 and enable all workarounds for buggy servers // Disable SSLv2 and enable all workarounds for buggy servers
SSL_CTX_set_options(sslCtx_, SSL_OP_ALL | SSL_OP_NO_SSLv2 | ver_opts SSL_CTX_set_options(sslCtx_,
SSL_OP_ALL | SSL_OP_NO_SSLv2 | ver_opts
#ifdef SSL_OP_SINGLE_ECDH_USE #ifdef SSL_OP_SINGLE_ECDH_USE
| SSL_OP_SINGLE_ECDH_USE | SSL_OP_SINGLE_ECDH_USE
#endif // SSL_OP_SINGLE_ECDH_USE #endif // SSL_OP_SINGLE_ECDH_USE
#ifdef SSL_OP_NO_COMPRESSION #ifdef SSL_OP_NO_COMPRESSION
| SSL_OP_NO_COMPRESSION | SSL_OP_NO_COMPRESSION
#endif // SSL_OP_NO_COMPRESSION #endif // SSL_OP_NO_COMPRESSION
); );
SSL_CTX_set_mode(sslCtx_, SSL_MODE_AUTO_RETRY); SSL_CTX_set_mode(sslCtx_, SSL_MODE_AUTO_RETRY);

View file

@ -67,8 +67,9 @@ void OpenedFileCounter::ensureMaxOpenFileLimit(size_t numNewFiles)
auto& requestGroups = rgman_->getRequestGroups(); auto& requestGroups = rgman_->getRequestGroups();
auto mark = std::begin(requestGroups); auto mark = std::begin(requestGroups);
std::advance(mark, SimpleRandomizer::getInstance()->getRandomNumber( std::advance(
requestGroups.size())); mark,
SimpleRandomizer::getInstance()->getRandomNumber(requestGroups.size()));
auto closeFun = [&left](const std::shared_ptr<RequestGroup>& group) { auto closeFun = [&left](const std::shared_ptr<RequestGroup>& group) {
auto& ps = group->getPieceStorage(); auto& ps = group->getPieceStorage();

View file

@ -319,14 +319,14 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
handlers.push_back(op); handlers.push_back(op);
} }
{ {
OptionHandler* op( OptionHandler* op(new ParameterOptionHandler(
new ParameterOptionHandler(PREF_FILE_ALLOCATION, TEXT_FILE_ALLOCATION, PREF_FILE_ALLOCATION, TEXT_FILE_ALLOCATION, V_PREALLOC,
V_PREALLOC, {V_NONE, V_PREALLOC, V_TRUNC, {V_NONE, V_PREALLOC, V_TRUNC,
#ifdef HAVE_SOME_FALLOCATE #ifdef HAVE_SOME_FALLOCATE
V_FALLOC V_FALLOC
#endif // HAVE_SOME_FALLOCATE #endif // HAVE_SOME_FALLOCATE
}, },
'a')); 'a'));
op->addTag(TAG_BASIC); op->addTag(TAG_BASIC);
op->addTag(TAG_FILE); op->addTag(TAG_FILE);
op->setInitialOption(true); op->setInitialOption(true);

View file

@ -108,9 +108,8 @@ void showUsage(const std::string& keyword,
out->printf("\n"); out->printf("\n");
out->printf(_("Options:")); out->printf(_("Options:"));
out->printf("\n"); out->printf("\n");
for (std::vector<const OptionHandler *>::const_iterator for (std::vector<const OptionHandler*>::const_iterator i = handlers.begin(),
i = handlers.begin(), eoi = handlers.end();
eoi = handlers.end();
i != eoi; ++i) { i != eoi; ++i) {
write(out, *(*i)); write(out, *(*i));
out->printf("\n"); out->printf("\n");
@ -125,7 +124,7 @@ void showUsage(const std::string& keyword,
out->printf("\n"); out->printf("\n");
out->printf(_("Options:")); out->printf(_("Options:"));
out->printf("\n"); out->printf("\n");
for (std::vector<const OptionHandler *>::const_iterator for (std::vector<const OptionHandler*>::const_iterator
i = handlers.begin(), i = handlers.begin(),
eoi = handlers.end(); eoi = handlers.end();
i != eoi; ++i) { i != eoi; ++i) {

View file

@ -274,10 +274,10 @@ void BtRequestMessageTest::testValidate_lengthTooLong()
CPPUNIT_FAIL("exception must be thrown."); CPPUNIT_FAIL("exception must be thrown.");
} }
catch (DlAbortEx& e) { catch (DlAbortEx& e) {
CPPUNIT_ASSERT_EQUAL("Length too long: " + CPPUNIT_ASSERT_EQUAL(
util::uitos(MAX_BLOCK_LENGTH + 1) + " > " + "Length too long: " + util::uitos(MAX_BLOCK_LENGTH + 1) + " > " +
util::uitos(MAX_BLOCK_LENGTH / 1024) + "KB", util::uitos(MAX_BLOCK_LENGTH / 1024) + "KB",
std::string(e.what())); std::string(e.what()));
} }
} }

View file

@ -209,9 +209,10 @@ void ChunkedDecodingStreamFilterTest::testTransform()
void ChunkedDecodingStreamFilterTest::testTransform_withoutTrailer() void ChunkedDecodingStreamFilterTest::testTransform_withoutTrailer()
{ {
CPPUNIT_ASSERT_EQUAL( CPPUNIT_ASSERT_EQUAL(
(ssize_t)0, filter_->transform( (ssize_t)0,
writer_, segment_, filter_->transform(writer_, segment_,
reinterpret_cast<const unsigned char*>("0\r\n\r\n"), 5)); reinterpret_cast<const unsigned char*>("0\r\n\r\n"),
5));
CPPUNIT_ASSERT(filter_->finished()); CPPUNIT_ASSERT(filter_->finished());
} }

View file

@ -141,9 +141,9 @@ void DefaultExtensionMessageFactoryTest::testCreateMessage_UTPex()
std::string data = getExtensionMessageID(ExtensionMessageRegistry::UT_PEX) + std::string data = getExtensionMessageID(ExtensionMessageRegistry::UT_PEX) +
"d5:added12:" + std::string(&c1[0], &c1[6]) + "d5:added12:" + std::string(&c1[0], &c1[6]) +
std::string(&c2[0], &c2[6]) + "7:added.f2:207:dropped12:" + std::string(&c2[0], &c2[6]) +
std::string(&c3[0], &c3[6]) + std::string(&c4[0], &c4[6]) + "7:added.f2:207:dropped12:" + std::string(&c3[0], &c3[6]) +
"e"; std::string(&c4[0], &c4[6]) + "e";
auto m = createMessage<UTPexExtensionMessage>(data); auto m = createMessage<UTPexExtensionMessage>(data);
CPPUNIT_ASSERT_EQUAL( CPPUNIT_ASSERT_EQUAL(

View file

@ -113,10 +113,12 @@ void HandshakeExtensionMessageTest::testDoReceivedAction()
msg.doReceivedAction(); msg.doReceivedAction();
CPPUNIT_ASSERT_EQUAL((uint16_t)6889, peer->getPort()); CPPUNIT_ASSERT_EQUAL((uint16_t)6889, peer->getPort());
CPPUNIT_ASSERT_EQUAL((uint8_t)1, peer->getExtensionMessageID( CPPUNIT_ASSERT_EQUAL(
ExtensionMessageRegistry::UT_PEX)); (uint8_t)1,
CPPUNIT_ASSERT_EQUAL((uint8_t)3, peer->getExtensionMessageID( peer->getExtensionMessageID(ExtensionMessageRegistry::UT_PEX));
ExtensionMessageRegistry::UT_METADATA)); CPPUNIT_ASSERT_EQUAL(
(uint8_t)3,
peer->getExtensionMessageID(ExtensionMessageRegistry::UT_METADATA));
CPPUNIT_ASSERT(peer->isSeeder()); CPPUNIT_ASSERT(peer->isSeeder());
auto attrs = bittorrent::getTorrentAttrs(dctx); auto attrs = bittorrent::getTorrentAttrs(dctx);
CPPUNIT_ASSERT_EQUAL((size_t)1_k, attrs->metadataSize); CPPUNIT_ASSERT_EQUAL((size_t)1_k, attrs->metadataSize);

View file

@ -109,7 +109,7 @@ void IndexedListTest::testErase()
CPPUNIT_ASSERT_EQUAL((size_t)(std::distance(i, list.end())), list.size()); CPPUNIT_ASSERT_EQUAL((size_t)(std::distance(i, list.end())), list.size());
int* pp = ++p; int* pp = ++p;
for (IndexedList<int, int *>::iterator j = list.begin(); j != list.end(); for (IndexedList<int, int*>::iterator j = list.begin(); j != list.end();
++j, ++pp) { ++j, ++pp) {
CPPUNIT_ASSERT_EQUAL(*pp, **j); CPPUNIT_ASSERT_EQUAL(*pp, **j);
} }

View file

@ -140,8 +140,9 @@ void PeerSessionResourceTest::testGetExtensionMessageID()
res.addExtension(ExtensionMessageRegistry::UT_PEX, 9); res.addExtension(ExtensionMessageRegistry::UT_PEX, 9);
CPPUNIT_ASSERT_EQUAL( CPPUNIT_ASSERT_EQUAL(
(uint8_t)9, res.getExtensionMessageID(ExtensionMessageRegistry::UT_PEX)); (uint8_t)9, res.getExtensionMessageID(ExtensionMessageRegistry::UT_PEX));
CPPUNIT_ASSERT_EQUAL((uint8_t)0, res.getExtensionMessageID( CPPUNIT_ASSERT_EQUAL(
ExtensionMessageRegistry::UT_METADATA)); (uint8_t)0,
res.getExtensionMessageID(ExtensionMessageRegistry::UT_METADATA));
CPPUNIT_ASSERT_EQUAL(std::string("ut_pex"), CPPUNIT_ASSERT_EQUAL(std::string("ut_pex"),
std::string(res.getExtensionName(9))); std::string(res.getExtensionName(9)));

View file

@ -149,38 +149,53 @@ void RequestGroupManTest::testChangeReservedGroupPosition()
std::make_shared<RequestGroup>(GroupId::create(), util::copy(option_))}; std::make_shared<RequestGroup>(GroupId::create(), util::copy(option_))};
RequestGroupMan rm(gs, 0, option_.get()); RequestGroupMan rm(gs, 0, option_.get());
CPPUNIT_ASSERT_EQUAL((size_t)0, rm.changeReservedGroupPosition( CPPUNIT_ASSERT_EQUAL(
gs[0]->getGID(), 0, OFFSET_MODE_SET)); (size_t)0,
CPPUNIT_ASSERT_EQUAL((size_t)1, rm.changeReservedGroupPosition( rm.changeReservedGroupPosition(gs[0]->getGID(), 0, OFFSET_MODE_SET));
gs[0]->getGID(), 1, OFFSET_MODE_SET)); CPPUNIT_ASSERT_EQUAL(
CPPUNIT_ASSERT_EQUAL((size_t)3, rm.changeReservedGroupPosition( (size_t)1,
gs[0]->getGID(), 10, OFFSET_MODE_SET)); rm.changeReservedGroupPosition(gs[0]->getGID(), 1, OFFSET_MODE_SET));
CPPUNIT_ASSERT_EQUAL((size_t)0, rm.changeReservedGroupPosition( CPPUNIT_ASSERT_EQUAL(
gs[0]->getGID(), -10, OFFSET_MODE_SET)); (size_t)3,
rm.changeReservedGroupPosition(gs[0]->getGID(), 10, OFFSET_MODE_SET));
CPPUNIT_ASSERT_EQUAL(
(size_t)0,
rm.changeReservedGroupPosition(gs[0]->getGID(), -10, OFFSET_MODE_SET));
CPPUNIT_ASSERT_EQUAL((size_t)1, rm.changeReservedGroupPosition( CPPUNIT_ASSERT_EQUAL(
gs[1]->getGID(), 0, OFFSET_MODE_CUR)); (size_t)1,
CPPUNIT_ASSERT_EQUAL((size_t)2, rm.changeReservedGroupPosition( rm.changeReservedGroupPosition(gs[1]->getGID(), 0, OFFSET_MODE_CUR));
gs[1]->getGID(), 1, OFFSET_MODE_CUR)); CPPUNIT_ASSERT_EQUAL(
CPPUNIT_ASSERT_EQUAL((size_t)1, rm.changeReservedGroupPosition( (size_t)2,
gs[1]->getGID(), -1, OFFSET_MODE_CUR)); rm.changeReservedGroupPosition(gs[1]->getGID(), 1, OFFSET_MODE_CUR));
CPPUNIT_ASSERT_EQUAL((size_t)0, rm.changeReservedGroupPosition( CPPUNIT_ASSERT_EQUAL(
gs[1]->getGID(), -10, OFFSET_MODE_CUR)); (size_t)1,
CPPUNIT_ASSERT_EQUAL((size_t)1, rm.changeReservedGroupPosition( rm.changeReservedGroupPosition(gs[1]->getGID(), -1, OFFSET_MODE_CUR));
gs[1]->getGID(), 1, OFFSET_MODE_CUR)); CPPUNIT_ASSERT_EQUAL(
CPPUNIT_ASSERT_EQUAL((size_t)3, rm.changeReservedGroupPosition( (size_t)0,
gs[1]->getGID(), 10, OFFSET_MODE_CUR)); rm.changeReservedGroupPosition(gs[1]->getGID(), -10, OFFSET_MODE_CUR));
CPPUNIT_ASSERT_EQUAL((size_t)1, rm.changeReservedGroupPosition( CPPUNIT_ASSERT_EQUAL(
gs[1]->getGID(), -2, OFFSET_MODE_CUR)); (size_t)1,
rm.changeReservedGroupPosition(gs[1]->getGID(), 1, OFFSET_MODE_CUR));
CPPUNIT_ASSERT_EQUAL(
(size_t)3,
rm.changeReservedGroupPosition(gs[1]->getGID(), 10, OFFSET_MODE_CUR));
CPPUNIT_ASSERT_EQUAL(
(size_t)1,
rm.changeReservedGroupPosition(gs[1]->getGID(), -2, OFFSET_MODE_CUR));
CPPUNIT_ASSERT_EQUAL((size_t)3, rm.changeReservedGroupPosition( CPPUNIT_ASSERT_EQUAL(
gs[3]->getGID(), 0, OFFSET_MODE_END)); (size_t)3,
CPPUNIT_ASSERT_EQUAL((size_t)2, rm.changeReservedGroupPosition( rm.changeReservedGroupPosition(gs[3]->getGID(), 0, OFFSET_MODE_END));
gs[3]->getGID(), -1, OFFSET_MODE_END)); CPPUNIT_ASSERT_EQUAL(
CPPUNIT_ASSERT_EQUAL((size_t)0, rm.changeReservedGroupPosition( (size_t)2,
gs[3]->getGID(), -10, OFFSET_MODE_END)); rm.changeReservedGroupPosition(gs[3]->getGID(), -1, OFFSET_MODE_END));
CPPUNIT_ASSERT_EQUAL((size_t)3, rm.changeReservedGroupPosition( CPPUNIT_ASSERT_EQUAL(
gs[3]->getGID(), 10, OFFSET_MODE_END)); (size_t)0,
rm.changeReservedGroupPosition(gs[3]->getGID(), -10, OFFSET_MODE_END));
CPPUNIT_ASSERT_EQUAL(
(size_t)3,
rm.changeReservedGroupPosition(gs[3]->getGID(), 10, OFFSET_MODE_END));
CPPUNIT_ASSERT_EQUAL((size_t)4, rm.getReservedGroups().size()); CPPUNIT_ASSERT_EQUAL((size_t)4, rm.getReservedGroups().size());

View file

@ -369,10 +369,11 @@ void RpcMethodTest::testAddTorrent()
CPPUNIT_ASSERT_EQUAL(e_->getOption()->get(PREF_DIR) + CPPUNIT_ASSERT_EQUAL(e_->getOption()->get(PREF_DIR) +
"/aria2-0.8.2.tar.bz2", "/aria2-0.8.2.tar.bz2",
group->getFirstFilePath()); group->getFirstFilePath());
CPPUNIT_ASSERT_EQUAL((size_t)1, group->getDownloadContext() CPPUNIT_ASSERT_EQUAL((size_t)1,
->getFirstFileEntry() group->getDownloadContext()
->getRemainingUris() ->getFirstFileEntry()
.size()); ->getRemainingUris()
.size());
CPPUNIT_ASSERT_EQUAL(std::string("http://localhost/aria2-0.8.2.tar.bz2"), CPPUNIT_ASSERT_EQUAL(std::string("http://localhost/aria2-0.8.2.tar.bz2"),
group->getDownloadContext() group->getDownloadContext()
->getFirstFileEntry() ->getFirstFileEntry()

View file

@ -108,8 +108,9 @@ void UTPexExtensionMessageTest::testGetBencodedData()
"d5:added12:" + std::string(&c1[0], &c1[6]) + "d5:added12:" + std::string(&c1[0], &c1[6]) +
std::string(&c2[0], &c2[6]) + "7:added.f2:" + fromHex("0200") + std::string(&c2[0], &c2[6]) + "7:added.f2:" + fromHex("0200") +
"6:added618:" + std::string(&c5[0], &c5[COMPACT_LEN_IPV6]) + "6:added618:" + std::string(&c5[0], &c5[COMPACT_LEN_IPV6]) +
"8:added6.f1:" + fromHex("00") + "7:dropped12:" + "8:added6.f1:" + fromHex("00") +
std::string(&c3[0], &c3[6]) + std::string(&c4[0], &c4[6]) + "7:dropped12:" + std::string(&c3[0], &c3[6]) +
std::string(&c4[0], &c4[6]) +
"8:dropped618:" + std::string(&c6[0], &c6[COMPACT_LEN_IPV6]) + "e"; "8:dropped618:" + std::string(&c6[0], &c6[COMPACT_LEN_IPV6]) + "e";
std::string bd = msg.getPayload(); std::string bd = msg.getPayload();
CPPUNIT_ASSERT_EQUAL(util::percentEncode(expected), util::percentEncode(bd)); CPPUNIT_ASSERT_EQUAL(util::percentEncode(expected), util::percentEncode(bd));
@ -195,14 +196,15 @@ void UTPexExtensionMessageTest::testCreate()
char id[1] = {1}; char id[1] = {1};
std::string data = std::string(&id[0], &id[1]) + "d5:added12:" + std::string data =
std::string(&c1[0], &c1[6]) + std::string(&c2[0], &c2[6]) + std::string(&id[0], &id[1]) +
"7:added.f2:" + fromHex("0200") + "6:added618:" + "d5:added12:" + std::string(&c1[0], &c1[6]) +
std::string(&c5[0], &c5[COMPACT_LEN_IPV6]) + std::string(&c2[0], &c2[6]) + "7:added.f2:" + fromHex("0200") +
"8:added6.f1:" + fromHex("00") + "7:dropped12:" + "6:added618:" + std::string(&c5[0], &c5[COMPACT_LEN_IPV6]) +
std::string(&c3[0], &c3[6]) + std::string(&c4[0], &c4[6]) + "8:added6.f1:" + fromHex("00") +
"8:dropped618:" + "7:dropped12:" + std::string(&c3[0], &c3[6]) +
std::string(&c6[0], &c6[COMPACT_LEN_IPV6]) + "e"; std::string(&c4[0], &c4[6]) +
"8:dropped618:" + std::string(&c6[0], &c6[COMPACT_LEN_IPV6]) + "e";
auto msg = UTPexExtensionMessage::create( auto msg = UTPexExtensionMessage::create(
reinterpret_cast<const unsigned char*>(data.c_str()), data.size()); reinterpret_cast<const unsigned char*>(data.c_str()), data.size());

View file

@ -61,8 +61,9 @@ void UriSplitTest::testUriSplit()
uri = "http://user@aria2.sf.net/path/"; uri = "http://user@aria2.sf.net/path/";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) | CHECK_FIELD_SET(res,
(1 << USR_USERINFO) | (1 << USR_USER)); (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) |
(1 << USR_USERINFO) | (1 << USR_USER));
CPPUNIT_ASSERT_EQUAL(std::string("aria2.sf.net"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("aria2.sf.net"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("/path/"), mkstr(res, USR_PATH, uri)); CPPUNIT_ASSERT_EQUAL(std::string("/path/"), mkstr(res, USR_PATH, uri));
CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USERINFO, uri)); CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USERINFO, uri));
@ -71,9 +72,10 @@ void UriSplitTest::testUriSplit()
uri = "http://user:pass@aria2.sf.net/path/"; uri = "http://user:pass@aria2.sf.net/path/";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) | CHECK_FIELD_SET(res,
(1 << USR_USERINFO) | (1 << USR_USER) | (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) |
(1 << USR_PASSWD)); (1 << USR_USERINFO) | (1 << USR_USER) |
(1 << USR_PASSWD));
CPPUNIT_ASSERT_EQUAL(std::string("aria2.sf.net"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("aria2.sf.net"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("/path/"), mkstr(res, USR_PATH, uri)); CPPUNIT_ASSERT_EQUAL(std::string("/path/"), mkstr(res, USR_PATH, uri));
CPPUNIT_ASSERT_EQUAL(std::string("user:pass"), mkstr(res, USR_USERINFO, uri)); CPPUNIT_ASSERT_EQUAL(std::string("user:pass"), mkstr(res, USR_USERINFO, uri));
@ -87,9 +89,10 @@ void UriSplitTest::testUriSplit()
uri = "http://user@foo.com:pass@aria2.sf.net/path/"; uri = "http://user@foo.com:pass@aria2.sf.net/path/";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) | CHECK_FIELD_SET(res,
(1 << USR_USERINFO) | (1 << USR_USER) | (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) |
(1 << USR_PASSWD)); (1 << USR_USERINFO) | (1 << USR_USER) |
(1 << USR_PASSWD));
CPPUNIT_ASSERT_EQUAL(std::string("aria2.sf.net"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("aria2.sf.net"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("/path/"), mkstr(res, USR_PATH, uri)); CPPUNIT_ASSERT_EQUAL(std::string("/path/"), mkstr(res, USR_PATH, uri));
CPPUNIT_ASSERT_EQUAL(std::string("user@foo.com:pass"), CPPUNIT_ASSERT_EQUAL(std::string("user@foo.com:pass"),
@ -101,8 +104,9 @@ void UriSplitTest::testUriSplit()
uri = "https://aria2.sf.net:443/path/"; uri = "https://aria2.sf.net:443/path/";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) | CHECK_FIELD_SET(res,
(1 << USR_PATH)); (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) |
(1 << USR_PATH));
CPPUNIT_ASSERT_EQUAL(std::string("https"), mkstr(res, USR_SCHEME, uri)); CPPUNIT_ASSERT_EQUAL(std::string("https"), mkstr(res, USR_SCHEME, uri));
CPPUNIT_ASSERT_EQUAL(std::string("aria2.sf.net"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("aria2.sf.net"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("/path/"), mkstr(res, USR_PATH, uri)); CPPUNIT_ASSERT_EQUAL(std::string("/path/"), mkstr(res, USR_PATH, uri));
@ -112,9 +116,10 @@ void UriSplitTest::testUriSplit()
uri = "https://user:pass@aria2.sf.net:443/path/"; uri = "https://user:pass@aria2.sf.net:443/path/";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) | CHECK_FIELD_SET(res,
(1 << USR_PATH) | (1 << USR_USERINFO) | (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) |
(1 << USR_USER) | (1 << USR_PASSWD)); (1 << USR_PATH) | (1 << USR_USERINFO) | (1 << USR_USER) |
(1 << USR_PASSWD));
CPPUNIT_ASSERT_EQUAL(std::string("aria2.sf.net"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("aria2.sf.net"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("/path/"), mkstr(res, USR_PATH, uri)); CPPUNIT_ASSERT_EQUAL(std::string("/path/"), mkstr(res, USR_PATH, uri));
CPPUNIT_ASSERT_EQUAL(std::string("user:pass"), mkstr(res, USR_USERINFO, uri)); CPPUNIT_ASSERT_EQUAL(std::string("user:pass"), mkstr(res, USR_USERINFO, uri));
@ -126,9 +131,9 @@ void UriSplitTest::testUriSplit()
uri = "https://user@aria2.sf.net:443/path/"; uri = "https://user@aria2.sf.net:443/path/";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) | CHECK_FIELD_SET(res,
(1 << USR_PATH) | (1 << USR_USERINFO) | (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) |
(1 << USR_USER)); (1 << USR_PATH) | (1 << USR_USERINFO) | (1 << USR_USER));
CPPUNIT_ASSERT_EQUAL(std::string("aria2.sf.net"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("aria2.sf.net"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("/path/"), mkstr(res, USR_PATH, uri)); CPPUNIT_ASSERT_EQUAL(std::string("/path/"), mkstr(res, USR_PATH, uri));
CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USERINFO, uri)); CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USERINFO, uri));
@ -152,8 +157,9 @@ void UriSplitTest::testUriSplit()
uri = "http://user@aria2"; uri = "http://user@aria2";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | CHECK_FIELD_SET(res,
(1 << USR_USERINFO) | (1 << USR_USER)); (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_USERINFO) |
(1 << USR_USER));
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USERINFO, uri)); CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USERINFO, uri));
CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USER, uri)); CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USER, uri));
@ -161,9 +167,9 @@ void UriSplitTest::testUriSplit()
uri = "http://user:@aria2"; uri = "http://user:@aria2";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | CHECK_FIELD_SET(res,
(1 << USR_USERINFO) | (1 << USR_USER) | (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_USERINFO) |
(1 << USR_PASSWD)); (1 << USR_USER) | (1 << USR_PASSWD));
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("user:"), mkstr(res, USR_USERINFO, uri)); CPPUNIT_ASSERT_EQUAL(std::string("user:"), mkstr(res, USR_USERINFO, uri));
CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USER, uri)); CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USER, uri));
@ -172,8 +178,9 @@ void UriSplitTest::testUriSplit()
uri = "http://aria2/?foo#bar"; uri = "http://aria2/?foo#bar";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) | CHECK_FIELD_SET(res,
(1 << USR_QUERY) | (1 << USR_FRAGMENT)); (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) |
(1 << USR_QUERY) | (1 << USR_FRAGMENT));
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("/"), mkstr(res, USR_PATH, uri)); CPPUNIT_ASSERT_EQUAL(std::string("/"), mkstr(res, USR_PATH, uri));
CPPUNIT_ASSERT_EQUAL(std::string("foo"), mkstr(res, USR_QUERY, uri)); CPPUNIT_ASSERT_EQUAL(std::string("foo"), mkstr(res, USR_QUERY, uri));
@ -200,8 +207,9 @@ void UriSplitTest::testUriSplit()
uri = "https://aria2:443?foo"; uri = "https://aria2:443?foo";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) | CHECK_FIELD_SET(res,
(1 << USR_QUERY)); (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) |
(1 << USR_QUERY));
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("foo"), mkstr(res, USR_QUERY, uri)); CPPUNIT_ASSERT_EQUAL(std::string("foo"), mkstr(res, USR_QUERY, uri));
CPPUNIT_ASSERT_EQUAL((uint16_t)443, res.port); CPPUNIT_ASSERT_EQUAL((uint16_t)443, res.port);
@ -210,8 +218,9 @@ void UriSplitTest::testUriSplit()
uri = "https://aria2:443#bar"; uri = "https://aria2:443#bar";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) | CHECK_FIELD_SET(res,
(1 << USR_FRAGMENT)); (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) |
(1 << USR_FRAGMENT));
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("bar"), mkstr(res, USR_FRAGMENT, uri)); CPPUNIT_ASSERT_EQUAL(std::string("bar"), mkstr(res, USR_FRAGMENT, uri));
CPPUNIT_ASSERT_EQUAL((uint16_t)443, res.port); CPPUNIT_ASSERT_EQUAL((uint16_t)443, res.port);
@ -220,9 +229,10 @@ void UriSplitTest::testUriSplit()
uri = "https://user:pass@aria2:443?foo"; uri = "https://user:pass@aria2:443?foo";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) | CHECK_FIELD_SET(res,
(1 << USR_QUERY) | (1 << USR_USERINFO) | (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) |
(1 << USR_USER) | (1 << USR_PASSWD)); (1 << USR_QUERY) | (1 << USR_USERINFO) | (1 << USR_USER) |
(1 << USR_PASSWD));
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USER, uri)); CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USER, uri));
CPPUNIT_ASSERT_EQUAL(std::string("pass"), mkstr(res, USR_PASSWD, uri)); CPPUNIT_ASSERT_EQUAL(std::string("pass"), mkstr(res, USR_PASSWD, uri));
@ -233,9 +243,10 @@ void UriSplitTest::testUriSplit()
uri = "https://user:pass@aria2:443#bar"; uri = "https://user:pass@aria2:443#bar";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) | CHECK_FIELD_SET(res,
(1 << USR_FRAGMENT) | (1 << USR_USERINFO) | (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) |
(1 << USR_USER) | (1 << USR_PASSWD)); (1 << USR_FRAGMENT) | (1 << USR_USERINFO) |
(1 << USR_USER) | (1 << USR_PASSWD));
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USER, uri)); CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USER, uri));
CPPUNIT_ASSERT_EQUAL(std::string("pass"), mkstr(res, USR_PASSWD, uri)); CPPUNIT_ASSERT_EQUAL(std::string("pass"), mkstr(res, USR_PASSWD, uri));
@ -246,9 +257,10 @@ void UriSplitTest::testUriSplit()
uri = "http://user:pass@aria2?foo"; uri = "http://user:pass@aria2?foo";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_QUERY) | CHECK_FIELD_SET(res,
(1 << USR_USERINFO) | (1 << USR_USER) | (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_QUERY) |
(1 << USR_PASSWD)); (1 << USR_USERINFO) | (1 << USR_USER) |
(1 << USR_PASSWD));
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USER, uri)); CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USER, uri));
CPPUNIT_ASSERT_EQUAL(std::string("pass"), mkstr(res, USR_PASSWD, uri)); CPPUNIT_ASSERT_EQUAL(std::string("pass"), mkstr(res, USR_PASSWD, uri));
@ -258,9 +270,10 @@ void UriSplitTest::testUriSplit()
uri = "http://user:pass@aria2#bar"; uri = "http://user:pass@aria2#bar";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | CHECK_FIELD_SET(res,
(1 << USR_FRAGMENT) | (1 << USR_USERINFO) | (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_FRAGMENT) |
(1 << USR_USER) | (1 << USR_PASSWD)); (1 << USR_USERINFO) | (1 << USR_USER) |
(1 << USR_PASSWD));
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USER, uri)); CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USER, uri));
CPPUNIT_ASSERT_EQUAL(std::string("pass"), mkstr(res, USR_PASSWD, uri)); CPPUNIT_ASSERT_EQUAL(std::string("pass"), mkstr(res, USR_PASSWD, uri));
@ -270,8 +283,9 @@ void UriSplitTest::testUriSplit()
uri = "http://aria2/?"; uri = "http://aria2/?";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) | CHECK_FIELD_SET(res,
(1 << USR_QUERY)); (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) |
(1 << USR_QUERY));
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("/"), mkstr(res, USR_PATH, uri)); CPPUNIT_ASSERT_EQUAL(std::string("/"), mkstr(res, USR_PATH, uri));
CPPUNIT_ASSERT_EQUAL(std::string(""), mkstr(res, USR_QUERY, uri)); CPPUNIT_ASSERT_EQUAL(std::string(""), mkstr(res, USR_QUERY, uri));
@ -280,8 +294,9 @@ void UriSplitTest::testUriSplit()
uri = "http://aria2/#"; uri = "http://aria2/#";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) | CHECK_FIELD_SET(res,
(1 << USR_FRAGMENT)); (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) |
(1 << USR_FRAGMENT));
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("/"), mkstr(res, USR_PATH, uri)); CPPUNIT_ASSERT_EQUAL(std::string("/"), mkstr(res, USR_PATH, uri));
CPPUNIT_ASSERT_EQUAL(std::string(""), mkstr(res, USR_FRAGMENT, uri)); CPPUNIT_ASSERT_EQUAL(std::string(""), mkstr(res, USR_FRAGMENT, uri));
@ -290,8 +305,9 @@ void UriSplitTest::testUriSplit()
uri = "http://aria2/?#"; uri = "http://aria2/?#";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) | CHECK_FIELD_SET(res,
(1 << USR_QUERY) | (1 << USR_FRAGMENT)); (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) |
(1 << USR_QUERY) | (1 << USR_FRAGMENT));
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("aria2"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("/"), mkstr(res, USR_PATH, uri)); CPPUNIT_ASSERT_EQUAL(std::string("/"), mkstr(res, USR_PATH, uri));
CPPUNIT_ASSERT_EQUAL(std::string(""), mkstr(res, USR_QUERY, uri)); CPPUNIT_ASSERT_EQUAL(std::string(""), mkstr(res, USR_QUERY, uri));
@ -317,8 +333,9 @@ void UriSplitTest::testUriSplit()
uri = "https://user@[::1]"; uri = "https://user@[::1]";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | CHECK_FIELD_SET(res,
(1 << USR_USERINFO) | (1 << USR_USER)); (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_USERINFO) |
(1 << USR_USER));
CPPUNIT_ASSERT_EQUAL(std::string("::1"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("::1"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USERINFO, uri)); CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USERINFO, uri));
CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USER, uri)); CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USER, uri));
@ -328,9 +345,9 @@ void UriSplitTest::testUriSplit()
uri = "https://user:pass@[::1]"; uri = "https://user:pass@[::1]";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | CHECK_FIELD_SET(res,
(1 << USR_USERINFO) | (1 << USR_USER) | (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_USERINFO) |
(1 << USR_PASSWD)); (1 << USR_USER) | (1 << USR_PASSWD));
CPPUNIT_ASSERT_EQUAL(std::string("::1"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("::1"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("user:pass"), mkstr(res, USR_USERINFO, uri)); CPPUNIT_ASSERT_EQUAL(std::string("user:pass"), mkstr(res, USR_USERINFO, uri));
CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USER, uri)); CPPUNIT_ASSERT_EQUAL(std::string("user"), mkstr(res, USR_USER, uri));
@ -340,16 +357,18 @@ void UriSplitTest::testUriSplit()
uri = "http://aria2/f"; uri = "http://aria2/f";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) | CHECK_FIELD_SET(res,
(1 << USR_BASENAME)); (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) |
(1 << USR_BASENAME));
CPPUNIT_ASSERT_EQUAL(std::string("/f"), mkstr(res, USR_PATH, uri)); CPPUNIT_ASSERT_EQUAL(std::string("/f"), mkstr(res, USR_PATH, uri));
CPPUNIT_ASSERT_EQUAL(std::string("f"), mkstr(res, USR_BASENAME, uri)); CPPUNIT_ASSERT_EQUAL(std::string("f"), mkstr(res, USR_BASENAME, uri));
uri = "http://[::1]/f"; uri = "http://[::1]/f";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) | CHECK_FIELD_SET(res,
(1 << USR_BASENAME)); (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) |
(1 << USR_BASENAME));
CPPUNIT_ASSERT_EQUAL(std::string("::1"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("::1"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("/f"), mkstr(res, USR_PATH, uri)); CPPUNIT_ASSERT_EQUAL(std::string("/f"), mkstr(res, USR_PATH, uri));
CPPUNIT_ASSERT_EQUAL(std::string("f"), mkstr(res, USR_BASENAME, uri)); CPPUNIT_ASSERT_EQUAL(std::string("f"), mkstr(res, USR_BASENAME, uri));
@ -357,8 +376,9 @@ void UriSplitTest::testUriSplit()
uri = "http://[::1]:8080/f"; uri = "http://[::1]:8080/f";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) | CHECK_FIELD_SET(res,
(1 << USR_PATH) | (1 << USR_BASENAME)); (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) |
(1 << USR_PATH) | (1 << USR_BASENAME));
CPPUNIT_ASSERT_EQUAL((uint16_t)8080, res.port); CPPUNIT_ASSERT_EQUAL((uint16_t)8080, res.port);
CPPUNIT_ASSERT_EQUAL(std::string("/f"), mkstr(res, USR_PATH, uri)); CPPUNIT_ASSERT_EQUAL(std::string("/f"), mkstr(res, USR_PATH, uri));
CPPUNIT_ASSERT_EQUAL(std::string("f"), mkstr(res, USR_BASENAME, uri)); CPPUNIT_ASSERT_EQUAL(std::string("f"), mkstr(res, USR_BASENAME, uri));
@ -366,10 +386,10 @@ void UriSplitTest::testUriSplit()
uri = "https://user:pass@host/f"; uri = "https://user:pass@host/f";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | CHECK_FIELD_SET(res,
(1 << USR_USERINFO) | (1 << USR_USER) | (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_USERINFO) |
(1 << USR_PASSWD) | (1 << USR_PATH) | (1 << USR_USER) | (1 << USR_PASSWD) | (1 << USR_PATH) |
(1 << USR_BASENAME)); (1 << USR_BASENAME));
CPPUNIT_ASSERT_EQUAL(std::string("host"), mkstr(res, USR_HOST, uri)); CPPUNIT_ASSERT_EQUAL(std::string("host"), mkstr(res, USR_HOST, uri));
CPPUNIT_ASSERT_EQUAL(std::string("user:pass"), mkstr(res, USR_USERINFO, uri)); CPPUNIT_ASSERT_EQUAL(std::string("user:pass"), mkstr(res, USR_USERINFO, uri));
CPPUNIT_ASSERT_EQUAL(std::string("/f"), mkstr(res, USR_PATH, uri)); CPPUNIT_ASSERT_EQUAL(std::string("/f"), mkstr(res, USR_PATH, uri));
@ -378,8 +398,9 @@ void UriSplitTest::testUriSplit()
uri = "http://aria2/index.html?foo"; uri = "http://aria2/index.html?foo";
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri)); CPPUNIT_ASSERT_EQUAL(0, uri_split(&res, uri));
CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) | CHECK_FIELD_SET(res,
(1 << USR_QUERY) | (1 << USR_BASENAME)); (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) |
(1 << USR_QUERY) | (1 << USR_BASENAME));
CPPUNIT_ASSERT_EQUAL(std::string("/index.html"), mkstr(res, USR_PATH, uri)); CPPUNIT_ASSERT_EQUAL(std::string("/index.html"), mkstr(res, USR_PATH, uri));
CPPUNIT_ASSERT_EQUAL(std::string("index.html"), CPPUNIT_ASSERT_EQUAL(std::string("index.html"),
mkstr(res, USR_BASENAME, uri)); mkstr(res, USR_BASENAME, uri));