clang-format-5.0

pull/1079/head
Tatsuhiro Tsujikawa 2017-11-23 14:11:43 +09:00
parent 20a7c43f2d
commit 795a0474df
48 changed files with 595 additions and 284 deletions

View File

@ -128,10 +128,11 @@ int main(int argc, char** argv)
if (dh) { if (dh) {
std::cerr << " [" << aria2::gidToHex(gid) << "] " std::cerr << " [" << aria2::gidToHex(gid) << "] "
<< dh->getCompletedLength() << "/" << dh->getTotalLength() << dh->getCompletedLength() << "/" << dh->getTotalLength()
<< "(" << (dh->getTotalLength() > 0 << "("
? (100 * dh->getCompletedLength() / << (dh->getTotalLength() > 0
dh->getTotalLength()) ? (100 * dh->getCompletedLength() /
: 0) dh->getTotalLength())
: 0)
<< "%)" << "%)"
<< " D:" << dh->getDownloadSpeed() / 1024 << " D:" << dh->getDownloadSpeed() / 1024
<< "KiB/s, U:" << dh->getUploadSpeed() / 1024 << "KiB/s" << "KiB/s, U:" << dh->getUploadSpeed() / 1024 << "KiB/s"

View File

@ -119,7 +119,7 @@ void AbstractDiskWriter::openFile(int64_t totalLength)
#else // !__MINGW32__ #else // !__MINGW32__
e.getErrNum() == ENOENT e.getErrNum() == ENOENT
#endif // !__MINGW32__ #endif // !__MINGW32__
) { ) {
initAndOpenFile(totalLength); initAndOpenFile(totalLength);
} }
else { else {
@ -201,9 +201,10 @@ HANDLE openFileWithFlags(const std::string& filename, int flags,
FILE_ATTRIBUTE_NORMAL, /* hTemplateFile */ 0); FILE_ATTRIBUTE_NORMAL, /* hTemplateFile */ 0);
if (hn == INVALID_HANDLE_VALUE) { if (hn == INVALID_HANDLE_VALUE) {
int errNum = GetLastError(); int errNum = GetLastError();
throw DL_ABORT_EX3(errNum, fmt(EX_FILE_OPEN, filename.c_str(), throw DL_ABORT_EX3(
fileStrerror(errNum).c_str()), errNum,
errCode); fmt(EX_FILE_OPEN, filename.c_str(), fileStrerror(errNum).c_str()),
errCode);
} }
return hn; return hn;
} }
@ -217,9 +218,10 @@ int openFileWithFlags(const std::string& filename, int flags,
; ;
if (fd < 0) { if (fd < 0) {
int errNum = errno; int errNum = errno;
throw DL_ABORT_EX3(errNum, fmt(EX_FILE_OPEN, filename.c_str(), throw DL_ABORT_EX3(
util::safeStrerror(errNum).c_str()), errNum,
errCode); fmt(EX_FILE_OPEN, filename.c_str(), util::safeStrerror(errNum).c_str()),
errCode);
} }
util::make_fd_cloexec(fd); util::make_fd_cloexec(fd);
#if defined(__APPLE__) && defined(__MACH__) #if defined(__APPLE__) && defined(__MACH__)
@ -454,9 +456,10 @@ void AbstractDiskWriter::writeData(const unsigned char* data, size_t len,
error_code::NOT_ENOUGH_DISK_SPACE); error_code::NOT_ENOUGH_DISK_SPACE);
} }
else { else {
throw DL_ABORT_EX3(errNum, fmt(EX_FILE_WRITE, filename_.c_str(), throw DL_ABORT_EX3(
fileStrerror(errNum).c_str()), errNum,
error_code::FILE_IO_ERROR); fmt(EX_FILE_WRITE, filename_.c_str(), fileStrerror(errNum).c_str()),
error_code::FILE_IO_ERROR);
} }
} }
} }
@ -467,9 +470,10 @@ ssize_t AbstractDiskWriter::readData(unsigned char* data, size_t len,
ssize_t ret; ssize_t ret;
if ((ret = readDataInternal(data, len, offset)) < 0) { if ((ret = readDataInternal(data, len, offset)) < 0) {
int errNum = fileError(); int errNum = fileError();
throw DL_ABORT_EX3(errNum, fmt(EX_FILE_READ, filename_.c_str(), throw DL_ABORT_EX3(
fileStrerror(errNum).c_str()), errNum,
error_code::FILE_IO_ERROR); fmt(EX_FILE_READ, filename_.c_str(), fileStrerror(errNum).c_str()),
error_code::FILE_IO_ERROR);
} }
return ret; return ret;
} }
@ -526,17 +530,17 @@ void AbstractDiskWriter::allocate(int64_t offset, int64_t length, bool sparse)
} }
#elif defined(__APPLE__) && defined(__MACH__) #elif defined(__APPLE__) && defined(__MACH__)
const auto toalloc = offset + length - size(); const auto toalloc = offset + length - size();
fstore_t fstore = { fstore_t fstore = {F_ALLOCATECONTIG | F_ALLOCATEALL, F_PEOFPOSMODE, 0,
F_ALLOCATECONTIG | F_ALLOCATEALL, F_PEOFPOSMODE, toalloc, 0};
0, toalloc, 0};
if (fcntl(fd_, F_PREALLOCATE, &fstore) == -1) { if (fcntl(fd_, F_PREALLOCATE, &fstore) == -1) {
// Retry non-contig. // Retry non-contig.
fstore.fst_flags = F_ALLOCATEALL; fstore.fst_flags = F_ALLOCATEALL;
if (fcntl(fd_, F_PREALLOCATE, &fstore) == -1) { if (fcntl(fd_, F_PREALLOCATE, &fstore) == -1) {
int err = errno; int err = errno;
throw DL_ABORT_EX3( throw DL_ABORT_EX3(
err, fmt("fcntl(F_PREALLOCATE) of %" PRId64 " failed. cause: %s", err,
fstore.fst_length, util::safeStrerror(err).c_str()), fmt("fcntl(F_PREALLOCATE) of %" PRId64 " failed. cause: %s",
fstore.fst_length, util::safeStrerror(err).c_str()),
error_code::FILE_IO_ERROR); error_code::FILE_IO_ERROR);
} }
} }
@ -559,10 +563,11 @@ void AbstractDiskWriter::allocate(int64_t offset, int64_t length, bool sparse)
#elif HAVE_POSIX_FALLOCATE #elif HAVE_POSIX_FALLOCATE
int r = posix_fallocate(fd_, offset, length); int r = posix_fallocate(fd_, offset, length);
if (r != 0) { if (r != 0) {
throw DL_ABORT_EX3(r, fmt("posix_fallocate failed. cause: %s", throw DL_ABORT_EX3(
util::safeStrerror(r).c_str()), r,
isDiskFullError(r) ? error_code::NOT_ENOUGH_DISK_SPACE fmt("posix_fallocate failed. cause: %s", util::safeStrerror(r).c_str()),
: error_code::FILE_IO_ERROR); isDiskFullError(r) ? error_code::NOT_ENOUGH_DISK_SPACE
: error_code::FILE_IO_ERROR);
} }
#else #else
#error "no *_fallocate function available." #error "no *_fallocate function available."

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 = std::min(numNewConnection_, numConnection =
btRuntime_->getMaxPeers() - std::min(numNewConnection_, btRuntime_->getMaxPeers() -
btRuntime_->getConnections()); btRuntime_->getConnections());
} }
} }
else { else {

View File

@ -128,6 +128,6 @@ private:
OSStatus sockWrite(const void* data, size_t* len); OSStatus sockWrite(const void* data, size_t* len);
OSStatus sockRead(void* data, size_t* len); OSStatus sockRead(void* data, size_t* len);
}; };
} } // namespace aria2
#endif // TLS_SESSION_H #endif // TLS_SESSION_H

View File

@ -73,7 +73,7 @@ public:
, ,
ares_addr_node* servers ares_addr_node* servers
#endif // HAVE_ARES_ADDR_NODE #endif // HAVE_ARES_ADDR_NODE
); );
~AsyncNameResolver(); ~AsyncNameResolver();

View File

@ -93,7 +93,7 @@ void AsyncNameResolverMan::startAsyncFamily(const std::string& hostname,
, ,
e->getAsyncDNSServers() e->getAsyncDNSServers()
#endif // HAVE_ARES_ADDR_NODE #endif // HAVE_ARES_ADDR_NODE
); );
asyncNameResolver_[numResolver_]->resolve(hostname); asyncNameResolver_[numResolver_]->resolve(hostname);
setNameResolverCheck(numResolver_, e, command); setNameResolverCheck(numResolver_, e, command);
} }

View File

@ -78,8 +78,9 @@ void ChecksumCheckIntegrityEntry::onDownloadIncomplete(
std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e) std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e)
{ {
if (redownload_) { if (redownload_) {
proceedFileAllocation(commands, make_unique<StreamFileAllocationEntry>( proceedFileAllocation(commands,
getRequestGroup(), popNextCommand()), make_unique<StreamFileAllocationEntry>(
getRequestGroup(), popNextCommand()),
e); e);
return; return;
} }

View File

@ -245,9 +245,8 @@ bool DHTBucket::operator==(const DHTBucket& bucket) const
bool DHTBucket::needsRefresh() const bool DHTBucket::needsRefresh() const
{ {
return nodes_.size() < K || return nodes_.size() < K || lastUpdated_.difference(global::wallclock()) >=
lastUpdated_.difference(global::wallclock()) >= DHT_BUCKET_REFRESH_INTERVAL;
DHT_BUCKET_REFRESH_INTERVAL;
} }
void DHTBucket::notifyUpdate() { lastUpdated_ = global::wallclock(); } void DHTBucket::notifyUpdate() { lastUpdated_ = global::wallclock(); }

View File

@ -87,9 +87,8 @@ bool DHTNode::isBad() const { return condition_ >= BAD_CONDITION; }
bool DHTNode::isQuestionable() const bool DHTNode::isQuestionable() const
{ {
return !isBad() && return !isBad() && lastContact_.difference(global::wallclock()) >=
lastContact_.difference(global::wallclock()) >= DHT_NODE_CONTACT_INTERVAL;
DHT_NODE_CONTACT_INTERVAL;
} }
void DHTNode::markGood() { condition_ = 0; } void DHTNode::markGood() { condition_ = 0; }

View File

@ -55,6 +55,6 @@ struct DHTNodeLookupEntry {
bool operator==(const DHTNodeLookupEntry& entry) const; bool operator==(const DHTNodeLookupEntry& entry) const;
}; };
} // namespace aria2; } // namespace aria2
#endif // D_DHT_NODE_LOOKUP_ENTRY_H #endif // D_DHT_NODE_LOOKUP_ENTRY_H

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 = fmt("REST %" PRId64 "\r\n", std::string request =
segment ? segment->getPositionToWrite() fmt("REST %" PRId64 "\r\n", 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

@ -202,7 +202,7 @@ bool HttpHeader::fieldContains(int hdKey, const char* value)
util::splitIter((*i).second.begin(), (*i).second.end(), util::splitIter((*i).second.begin(), (*i).second.end(),
std::back_inserter(values), ',', std::back_inserter(values), ',',
true // doStrip true // doStrip
); );
for (const auto& v : values) { for (const auto& v : values) {
if (util::strieq(v.first, v.second, value)) { if (util::strieq(v.first, v.second, value)) {
return true; return true;

View File

@ -163,6 +163,6 @@ public:
int idInterestingHeader(const char* hdName); int idInterestingHeader(const char* hdName);
} // namespace } // namespace aria2
#endif // D_HTTP_HEADER_H #endif // D_HTTP_HEADER_H

View File

@ -279,9 +279,8 @@ bool HttpResponseCommand::executeInternal()
// we ignore content-length when inflate is required // we ignore content-length when inflate is required
fe->setLength(0); fe->setLength(0);
if (req->getMethod() == Request::METHOD_GET && if (req->getMethod() == Request::METHOD_GET &&
(totalLength != 0 || (totalLength != 0 || !httpResponse->getHttpHeader()->defined(
!httpResponse->getHttpHeader()->defined( HttpHeader::CONTENT_LENGTH))) {
HttpHeader::CONTENT_LENGTH))) {
// DownloadContext::knowsTotalLength() == true only when // DownloadContext::knowsTotalLength() == true only when
// server says the size of file is 0 explicitly. // server says the size of file is 0 explicitly.
getDownloadContext()->markTotalLengthIsUnknown(); getDownloadContext()->markTotalLengthIsUnknown();
@ -422,9 +421,8 @@ bool HttpResponseCommand::handleOtherEncoding(
httpResponse.get(), getContentEncodingStreamFilter(httpResponse.get())); httpResponse.get(), getContentEncodingStreamFilter(httpResponse.get()));
// If chunked transfer-encoding is specified, we have to read end of // If chunked transfer-encoding is specified, we have to read end of
// chunk markers(0\r\n\r\n, for example). // chunk markers(0\r\n\r\n, for example).
bool chunkedUsed = bool chunkedUsed = streamFilter && streamFilter->getName() ==
streamFilter && ChunkedDecodingStreamFilter::NAME;
streamFilter->getName() == ChunkedDecodingStreamFilter::NAME;
// For zero-length file, check existing file comparing its size // For zero-length file, check existing file comparing its size
if (!chunkedUsed && getDownloadContext()->knowsTotalLength() && if (!chunkedUsed && getDownloadContext()->knowsTotalLength() &&

View File

@ -57,8 +57,8 @@ namespace util {
namespace security { namespace security {
class HMAC; class HMAC;
class HMACResult; class HMACResult;
} } // namespace security
} } // namespace util
enum RequestType { RPC_TYPE_NONE, RPC_TYPE_XML, RPC_TYPE_JSON, RPC_TYPE_JSONP }; enum RequestType { RPC_TYPE_NONE, RPC_TYPE_XML, RPC_TYPE_JSON, RPC_TYPE_JSONP };

View File

@ -58,7 +58,7 @@ InitiateConnectionCommandFactory::createInitiateConnectionCommand(
// for SSL // for SSL
|| req->getProtocol() == "https" || req->getProtocol() == "https"
#endif // ENABLE_SSL #endif // ENABLE_SSL
) { ) {
if (requestGroup->getOption()->getAsBool(PREF_ENABLE_HTTP_KEEP_ALIVE)) { if (requestGroup->getOption()->getAsBool(PREF_ENABLE_HTTP_KEEP_ALIVE)) {
req->setKeepAliveHint(true); req->setKeepAliveHint(true);
@ -74,7 +74,7 @@ InitiateConnectionCommandFactory::createInitiateConnectionCommand(
#ifdef HAVE_LIBSSH2 #ifdef HAVE_LIBSSH2
|| req->getProtocol() == "sftp" || req->getProtocol() == "sftp"
#endif // HAVE_LIBSSH2 #endif // HAVE_LIBSSH2
) { ) {
if (req->getFile().empty()) { if (req->getFile().empty()) {
throw DL_ABORT_EX(fmt("FTP/SFTP URI %s doesn't contain file path.", throw DL_ABORT_EX(fmt("FTP/SFTP URI %s doesn't contain file path.",
req->getUri().c_str())); req->getUri().c_str()));

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_, rv_ = gnutls_init(&sslSession_, tlsContext_->getSide() == TLS_CLIENT
tlsContext_->getSide() == TLS_CLIENT ? GNUTLS_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,15 +125,14 @@ 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_CTX_set_options(sslCtx_, SSL_OP_ALL | SSL_OP_NO_SSLv2 | ver_opts
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);
SSL_CTX_set_mode(sslCtx_, SSL_MODE_ENABLE_PARTIAL_WRITE); SSL_CTX_set_mode(sslCtx_, SSL_MODE_ENABLE_PARTIAL_WRITE);
#ifdef SSL_MODE_RELEASE_BUFFERS #ifdef SSL_MODE_RELEASE_BUFFERS

View File

@ -66,7 +66,7 @@ template <typename T> static void close_callback(uv_handle_t* handle)
} }
static void timer_callback(uv_timer_t* handle) { uv_stop(handle->loop); } static void timer_callback(uv_timer_t* handle) { uv_stop(handle->loop); }
} } // namespace
namespace aria2 { namespace aria2 {

View File

@ -121,4 +121,4 @@ std::string createLpdRequest(const std::string& multicastAddress,
} // namespace bittorrent } // namespace bittorrent
} // namespac aria2 } // namespace aria2

View File

@ -61,7 +61,7 @@ HashTypeEntry hashTypes[] = {
HashTypeEntry("sha-512", 5), HashTypeEntry("md5", 0), HashTypeEntry("sha-512", 5), HashTypeEntry("md5", 0),
HashTypeEntry("adler32", 0), HashTypeEntry("adler32", 0),
}; };
} // namespace aria2 } // namespace
MessageDigest::MessageDigest(std::unique_ptr<MessageDigestImpl> impl) MessageDigest::MessageDigest(std::unique_ptr<MessageDigestImpl> impl)
: pImpl_{std::move(impl)} : pImpl_{std::move(impl)}

View File

@ -139,9 +139,10 @@ void Metalink2RequestGroup::generate(
const std::shared_ptr<Option>& option, const std::string& baseUri) const std::shared_ptr<Option>& option, const std::string& baseUri)
{ {
std::vector<std::shared_ptr<RequestGroup>> tempgroups; std::vector<std::shared_ptr<RequestGroup>> tempgroups;
createRequestGroup(tempgroups, metalink::parseAndQuery(binaryStream.get(), createRequestGroup(
option.get(), baseUri), tempgroups,
option); metalink::parseAndQuery(binaryStream.get(), option.get(), baseUri),
option);
auto mi = std::make_shared<MetadataInfo>(); auto mi = std::make_shared<MetadataInfo>();
setMetadataInfo(std::begin(tempgroups), std::end(tempgroups), mi); setMetadataInfo(std::begin(tempgroups), std::end(tempgroups), mi);
groups.insert(std::end(groups), std::begin(tempgroups), std::end(tempgroups)); groups.insert(std::end(groups), std::begin(tempgroups), std::end(tempgroups));

View File

@ -254,7 +254,7 @@ void MetalinkParserController::commitResourceTransaction()
else { else {
tEntry_->resources.push_back(std::move(tResource_)); tEntry_->resources.push_back(std::move(tResource_));
} }
#else // !ENABLE_BITTORRENT #else // !ENABLE_BITTORRENT
tEntry_->resources.push_back(std::move(tResource_)); tEntry_->resources.push_back(std::move(tResource_));
#endif // !ENABLE_BITTORRENT #endif // !ENABLE_BITTORRENT
tResource_.reset(); tResource_.reset();

View File

@ -62,6 +62,6 @@ public:
} // namespace rpc } // namespace rpc
} // aria2 } // namespace aria2
#endif // D_NULL_WEB_SOCKET_SESSION_MAN_H #endif // D_NULL_WEB_SOCKET_SESSION_MAN_H

View File

@ -67,9 +67,8 @@ 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( std::advance(mark, SimpleRandomizer::getInstance()->getRandomNumber(
mark, requestGroups.size()));
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

@ -755,7 +755,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
new LocalFilePathOptionHandler( new LocalFilePathOptionHandler(
PREF_RPC_CERTIFICATE, TEXT_RPC_CERTIFICATE, NO_DEFAULT_VALUE, false) PREF_RPC_CERTIFICATE, TEXT_RPC_CERTIFICATE, NO_DEFAULT_VALUE, false)
#endif // HAVE_APPLETLS #endif // HAVE_APPLETLS
); );
op->addTag(TAG_RPC); op->addTag(TAG_RPC);
handlers.push_back(op); handlers.push_back(op);
} }
@ -1041,7 +1041,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
new LocalFilePathOptionHandler(PREF_CERTIFICATE, TEXT_CERTIFICATE, new LocalFilePathOptionHandler(PREF_CERTIFICATE, TEXT_CERTIFICATE,
NO_DEFAULT_VALUE, false) NO_DEFAULT_VALUE, false)
#endif // HAVE_APPLETLS #endif // HAVE_APPLETLS
); );
op->addTag(TAG_HTTP); op->addTag(TAG_HTTP);
op->addTag(TAG_HTTPS); op->addTag(TAG_HTTPS);
handlers.push_back(op); handlers.push_back(op);
@ -1480,10 +1480,10 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
handlers.push_back(op); handlers.push_back(op);
} }
{ {
OptionHandler* op(new DefaultOptionHandler(PREF_BT_EXCLUDE_TRACKER, OptionHandler* op(new DefaultOptionHandler(
TEXT_BT_EXCLUDE_TRACKER, PREF_BT_EXCLUDE_TRACKER, TEXT_BT_EXCLUDE_TRACKER, NO_DESCRIPTION,
NO_DESCRIPTION, "URI,... " "URI,... "
"or *")); "or *"));
op->addTag(TAG_BITTORRENT); op->addTag(TAG_BITTORRENT);
op->setInitialOption(true); op->setInitialOption(true);
op->setChangeGlobalOption(true); op->setChangeGlobalOption(true);

View File

@ -85,7 +85,7 @@ void gnutls_log_callback(int level, const char* str)
msg.resize(msg.size() - 1); msg.resize(msg.size() - 1);
A2_LOG_DEBUG(fmt("GnuTLS: <%d> %s", level, msg.c_str())); A2_LOG_DEBUG(fmt("GnuTLS: <%d> %s", level, msg.c_str()));
} }
} } // namespace
#endif // HAVE_LIBGNUTLS #endif // HAVE_LIBGNUTLS
bool Platform::initialized_ = false; bool Platform::initialized_ = false;

View File

@ -791,9 +791,10 @@ void gatherProgress(Dict* entryDict, const std::shared_ptr<RequestGroup>& group,
gatherProgressCommon(entryDict, group, keys); gatherProgressCommon(entryDict, group, keys);
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
if (group->getDownloadContext()->hasAttribute(CTX_ATTR_BT)) { if (group->getDownloadContext()->hasAttribute(CTX_ATTR_BT)) {
gatherProgressBitTorrent(entryDict, group, bittorrent::getTorrentAttrs( gatherProgressBitTorrent(
group->getDownloadContext()), entryDict, group,
e->getBtRegistry()->get(group->getGID()), keys); bittorrent::getTorrentAttrs(group->getDownloadContext()),
e->getBtRegistry()->get(group->getGID()), keys);
} }
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
if (e->getCheckIntegrityMan()) { if (e->getCheckIntegrityMan()) {
@ -1601,7 +1602,7 @@ void changeOption(const std::shared_ptr<RequestGroup>& group,
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
&& !dctx->hasAttribute(CTX_ATTR_BT) && !dctx->hasAttribute(CTX_ATTR_BT)
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
) { ) {
// In case of Metalink // In case of Metalink
for (auto& fileEntry : dctx->getFileEntries()) { for (auto& fileEntry : dctx->getFileEntries()) {
// PREF_OUT is not applicable to Metalink. We have always // PREF_OUT is not applicable to Metalink. We have always

View File

@ -135,6 +135,6 @@ private:
LIBSSH2_SFTP_HANDLE* sftph_; LIBSSH2_SFTP_HANDLE* sftph_;
sock_t fd_; sock_t fd_;
}; };
} } // namespace aria2
#endif // SSH_SESSION_H #endif // SSH_SESSION_H

View File

@ -199,7 +199,7 @@ void SelectEventPoll::poll(const struct timeval& tv)
// winsock will report non-blocking connect() errors in efds, // winsock will report non-blocking connect() errors in efds,
// unlike posix, which will mark such sockets as writable. // unlike posix, which will mark such sockets as writable.
retval = select(fdmax_ + 1, &rfds, &wfds, &efds, &ttv); retval = select(fdmax_ + 1, &rfds, &wfds, &efds, &ttv);
#else // !__MINGW32__ #else // !__MINGW32__
retval = select(fdmax_ + 1, &rfds, &wfds, nullptr, &ttv); retval = select(fdmax_ + 1, &rfds, &wfds, nullptr, &ttv);
#endif // !__MINGW32__ #endif // !__MINGW32__
} while (retval == -1 && errno == EINTR); } while (retval == -1 && errno == EINTR);

View File

@ -223,14 +223,12 @@ bool writeDownloadResult(IOFile& fp, std::set<a2_gid_t>& metainfoCache,
// also exists in remaining URIs. // also exists in remaining URIs.
{ {
Unique<std::string> unique; Unique<std::string> unique;
if (hasRemaining && if (hasRemaining && !writeUri(fp, file->getRemainingUris().begin(),
!writeUri(fp, file->getRemainingUris().begin(), file->getRemainingUris().end(), unique)) {
file->getRemainingUris().end(), unique)) {
return false; return false;
} }
if (hasSpent && if (hasSpent && !writeUri(fp, file->getSpentUris().begin(),
!writeUri(fp, file->getSpentUris().begin(), file->getSpentUris().end(), unique)) {
file->getSpentUris().end(), unique)) {
return false; return false;
} }
} }

View File

@ -58,8 +58,9 @@ void StreamCheckIntegrityEntry::onDownloadIncomplete(
if (getRequestGroup()->getOption()->getAsBool(PREF_HASH_CHECK_ONLY)) { if (getRequestGroup()->getOption()->getAsBool(PREF_HASH_CHECK_ONLY)) {
return; return;
} }
proceedFileAllocation(commands, make_unique<StreamFileAllocationEntry>( proceedFileAllocation(commands,
getRequestGroup(), popNextCommand()), make_unique<StreamFileAllocationEntry>(
getRequestGroup(), popNextCommand()),
e); e);
} }

View File

@ -118,6 +118,6 @@ private:
TLSSession(const TLSSession&); TLSSession(const TLSSession&);
TLSSession& operator=(const TLSSession&); TLSSession& operator=(const TLSSession&);
}; };
} } // namespace aria2
#endif // TLS_SESSION_H #endif // TLS_SESSION_H

View File

@ -47,7 +47,7 @@ class ValueBase;
namespace rpc { namespace rpc {
class XmlRpcRequestParserController; class XmlRpcRequestParserController;
} // namespace rpc; } // namespace rpc
class ValueBaseStructParserState; class ValueBaseStructParserState;

View File

@ -55,8 +55,8 @@ WebSocketResponseCommand::~WebSocketResponseCommand() = default;
void WebSocketResponseCommand::afterSend( void WebSocketResponseCommand::afterSend(
const std::shared_ptr<HttpServer>& httpServer, DownloadEngine* e) const std::shared_ptr<HttpServer>& httpServer, DownloadEngine* e)
{ {
auto wsSession = std::make_shared<WebSocketSession>( auto wsSession = std::make_shared<WebSocketSession>(httpServer->getSocket(),
httpServer->getSocket(), getDownloadEngine()); getDownloadEngine());
auto command = make_unique<WebSocketInteractionCommand>( auto command = make_unique<WebSocketInteractionCommand>(
getCuid(), wsSession, e, wsSession->getSocket()); getCuid(), wsSession, e, wsSession->getSocket());
wsSession->setCommand(command.get()); wsSession->setCommand(command.get());

View File

@ -69,6 +69,6 @@ private:
} // namespace rpc } // namespace rpc
} // aria2 } // namespace aria2
#endif // D_WEB_SOCKET_SESSION_MAN_H #endif // D_WEB_SOCKET_SESSION_MAN_H

View File

@ -612,7 +612,7 @@ restart:
// ... and start sending it // ... and start sending it
state_ = st_handshake_write; state_ = st_handshake_write;
} }
// Fall through // Fall through
case st_handshake_write_last: case st_handshake_write_last:
case st_handshake_write: { case st_handshake_write: {
@ -644,7 +644,7 @@ restart:
// Have to read one or more response messages. // Have to read one or more response messages.
state_ = st_handshake_read; state_ = st_handshake_read;
} }
// Fall through // Fall through
case st_handshake_read: { case st_handshake_read: {
read: read:
@ -764,7 +764,7 @@ restart:
goto restart; goto restart;
} }
} }
// Fall through // Fall through
case st_handshake_done: case st_handshake_done:
if (obtainTLSRecordSizes() != 0) { if (obtainTLSRecordSizes() != 0) {

View File

@ -48,7 +48,7 @@ namespace {
Console consoleCout; Console consoleCout;
Console consoleCerr; Console consoleCerr;
Console consoleCoutBackup; Console consoleCoutBackup;
}; }; // namespace
void initConsole(bool suppress) void initConsole(bool suppress)
{ {

View File

@ -323,7 +323,7 @@ bool isUtf8(const std::string& str)
firstChar == 0x0au || // \n firstChar == 0x0au || // \n
firstChar == 0x0cu || // \f firstChar == 0x0cu || // \f
firstChar == 0x0du // \r firstChar == 0x0du // \r
) { ) {
// UTF8-1 (without ctrl chars) // UTF8-1 (without ctrl chars)
} }
else if (in(firstChar, 0xc2u, 0xdfu)) { else if (in(firstChar, 0xc2u, 0xdfu)) {
@ -810,28 +810,375 @@ static const uint8_t utf8d[] = {
* The first part of the table maps bytes to character classes that * The first part of the table maps bytes to character classes that
* to reduce the size of the transition table and create bitmasks. * to reduce the size of the transition table and create bitmasks.
*/ */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 0,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 2, 2, 2, 2, 2, 2, 0,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 10, 0,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 11, 6, 6, 6, 5, 8, 8, 8, 8, 8, 0,
8, 8, 8, 8, 8, 8, 0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
9,
9,
9,
9,
9,
9,
9,
9,
9,
9,
9,
9,
9,
9,
9,
9,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
8,
8,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
10,
3,
3,
3,
3,
3,
3,
3,
3,
3,
3,
3,
3,
4,
3,
3,
11,
6,
6,
6,
5,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
/* /*
* The second part is a transition table that maps a combination * The second part is a transition table that maps a combination
* of a state of the automaton and a character class to a state. * of a state of the automaton and a character class to a state.
*/ */
0, 12, 24, 36, 60, 96, 84, 12, 12, 12, 48, 72, 12, 12, 12, 12, 12, 12, 12, 0,
12, 12, 12, 12, 12, 12, 0, 12, 12, 12, 12, 12, 0, 12, 0, 12, 12, 12, 24, 12, 12,
12, 12, 12, 12, 24, 12, 24, 12, 12, 12, 12, 12, 12, 12, 12, 12, 24, 12, 12, 24,
12, 12, 12, 24, 12, 12, 12, 12, 12, 12, 12, 24, 12, 12, 12, 12, 12, 12, 12, 36,
12, 12, 36, 12, 36, 12, 12, 12, 36, 12, 12, 12, 12, 12, 36, 12, 36, 12, 12, 60,
12, 36, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 96,
84,
12,
12,
12,
48,
72,
12,
12,
12,
12,
12,
12,
12,
12,
12,
12,
12,
12,
12,
0,
12,
12,
12,
12,
12,
0,
12,
0,
12,
12,
12,
24,
12,
12,
12,
12,
12,
24,
12,
24,
12,
12,
12,
12,
12,
12,
12,
12,
12,
24,
12,
12,
12,
12,
12,
24,
12,
12,
12,
12,
12,
12,
12,
24,
12,
12,
12,
12,
12,
12,
12,
12,
12,
36,
12,
36,
12,
12,
12,
36,
12,
12,
12,
12,
12,
36,
12,
36,
12,
12,
12,
36,
12,
12,
12,
12,
12,
12,
12,
12,
12,
12,
}; };
static uint32_t utf8dfa(uint32_t* state, uint32_t* codep, uint32_t byte) static uint32_t utf8dfa(uint32_t* state, uint32_t* codep, uint32_t byte)
@ -1341,7 +1688,7 @@ static BOOL WINAPI HandlerRoutine(DWORD ctrlType)
} }
return FALSE; return FALSE;
} }
} } // namespace
#endif #endif
void setGlobalSignalHandler(int sig, sigset_t* mask, signal_handler_t handler, void setGlobalSignalHandler(int sig, sigset_t* mask, signal_handler_t handler,
@ -1444,7 +1791,7 @@ std::string getXDGDir(const std::string& environmentVariable,
if (p && if (p &&
#ifndef __MINGW32__ #ifndef __MINGW32__
p[0] == '/' p[0] == '/'
#else // __MINGW32__ #else // __MINGW32__
p[0] && p[1] == ':' p[0] && p[1] == ':'
#endif // __MINGW32__ #endif // __MINGW32__
) { ) {
@ -1598,9 +1945,10 @@ void mkdirs(const std::string& dirpath)
if (!dir.mkdirs()) { if (!dir.mkdirs()) {
int errNum = errno; int errNum = errno;
if (!dir.isDir()) { if (!dir.isDir()) {
throw DL_ABORT_EX3(errNum, fmt(EX_MAKE_DIR, dir.getPath().c_str(), throw DL_ABORT_EX3(
safeStrerror(errNum).c_str()), errNum,
error_code::DIR_CREATE_ERROR); fmt(EX_MAKE_DIR, dir.getPath().c_str(), safeStrerror(errNum).c_str()),
error_code::DIR_CREATE_ERROR);
} }
} }
} }
@ -1840,12 +2188,11 @@ std::string escapePath(const std::string& s)
unsigned char c = cc; unsigned char c = cc;
if (in(c, 0x00u, 0x1fu) || c == 0x7fu if (in(c, 0x00u, 0x1fu) || c == 0x7fu
#ifdef __MINGW32__ #ifdef __MINGW32__
|| || std::find(std::begin(WIN_INVALID_PATH_CHARS),
std::find(std::begin(WIN_INVALID_PATH_CHARS), std::end(WIN_INVALID_PATH_CHARS),
std::end(WIN_INVALID_PATH_CHARS), c) != std::end(WIN_INVALID_PATH_CHARS)
c) != std::end(WIN_INVALID_PATH_CHARS)
#endif // __MINGW32__ #endif // __MINGW32__
) { ) {
d += fmt("%%%02X", c); d += fmt("%%%02X", c);
} }
else { else {

View File

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

View File

@ -113,12 +113,10 @@ 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( CPPUNIT_ASSERT_EQUAL((uint8_t)1, peer->getExtensionMessageID(
(uint8_t)1, ExtensionMessageRegistry::UT_PEX));
peer->getExtensionMessageID(ExtensionMessageRegistry::UT_PEX)); CPPUNIT_ASSERT_EQUAL((uint8_t)3, peer->getExtensionMessageID(
CPPUNIT_ASSERT_EQUAL( ExtensionMessageRegistry::UT_METADATA));
(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

@ -625,8 +625,9 @@ void HttpRequestTest::testCreateRequest_wantDigest()
"Cache-Control: no-cache\r\n" "Cache-Control: no-cache\r\n"
"Connection: close\r\n" "Connection: close\r\n"
"Want-Digest: " + "Want-Digest: " +
wantDigest + "\r\n" wantDigest +
"\r\n"; "\r\n"
"\r\n";
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest()); CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
} }

View File

@ -405,7 +405,7 @@ namespace {
struct RemoveOdd { struct RemoveOdd {
bool operator()(int* p) const { return *p % 2 == 1; } bool operator()(int* p) const { return *p % 2 == 1; }
}; };
} } // namespace
void IndexedListTest::testRemoveIf() void IndexedListTest::testRemoveIf()
{ {
int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

View File

@ -140,7 +140,7 @@ void MetalinkProcessorTest::testParseFileV4()
mu->url); mu->url);
CPPUNIT_ASSERT_EQUAL(2, mu->priority); CPPUNIT_ASSERT_EQUAL(2, mu->priority);
CPPUNIT_ASSERT_EQUAL(std::string("torrent"), mu->mediatype); CPPUNIT_ASSERT_EQUAL(std::string("torrent"), mu->mediatype);
#else // !ENABLE_BITTORRENT #else // !ENABLE_BITTORRENT
CPPUNIT_ASSERT_EQUAL((size_t)0, e->metaurls.size()); CPPUNIT_ASSERT_EQUAL((size_t)0, e->metaurls.size());
#endif // !ENABLE_BITTORRENT #endif // !ENABLE_BITTORRENT
} }

View File

@ -140,9 +140,8 @@ 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( CPPUNIT_ASSERT_EQUAL((uint8_t)0, res.getExtensionMessageID(
(uint8_t)0, ExtensionMessageRegistry::UT_METADATA));
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,53 +149,38 @@ 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( CPPUNIT_ASSERT_EQUAL((size_t)0, rm.changeReservedGroupPosition(
(size_t)0, gs[0]->getGID(), 0, OFFSET_MODE_SET));
rm.changeReservedGroupPosition(gs[0]->getGID(), 0, OFFSET_MODE_SET)); CPPUNIT_ASSERT_EQUAL((size_t)1, rm.changeReservedGroupPosition(
CPPUNIT_ASSERT_EQUAL( gs[0]->getGID(), 1, OFFSET_MODE_SET));
(size_t)1, CPPUNIT_ASSERT_EQUAL((size_t)3, rm.changeReservedGroupPosition(
rm.changeReservedGroupPosition(gs[0]->getGID(), 1, OFFSET_MODE_SET)); gs[0]->getGID(), 10, OFFSET_MODE_SET));
CPPUNIT_ASSERT_EQUAL( CPPUNIT_ASSERT_EQUAL((size_t)0, rm.changeReservedGroupPosition(
(size_t)3, gs[0]->getGID(), -10, OFFSET_MODE_SET));
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( CPPUNIT_ASSERT_EQUAL((size_t)1, rm.changeReservedGroupPosition(
(size_t)1, gs[1]->getGID(), 0, OFFSET_MODE_CUR));
rm.changeReservedGroupPosition(gs[1]->getGID(), 0, OFFSET_MODE_CUR)); CPPUNIT_ASSERT_EQUAL((size_t)2, rm.changeReservedGroupPosition(
CPPUNIT_ASSERT_EQUAL( gs[1]->getGID(), 1, OFFSET_MODE_CUR));
(size_t)2, 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)0, rm.changeReservedGroupPosition(
(size_t)1, gs[1]->getGID(), -10, OFFSET_MODE_CUR));
rm.changeReservedGroupPosition(gs[1]->getGID(), -1, OFFSET_MODE_CUR)); CPPUNIT_ASSERT_EQUAL((size_t)1, rm.changeReservedGroupPosition(
CPPUNIT_ASSERT_EQUAL( gs[1]->getGID(), 1, OFFSET_MODE_CUR));
(size_t)0, CPPUNIT_ASSERT_EQUAL((size_t)3, rm.changeReservedGroupPosition(
rm.changeReservedGroupPosition(gs[1]->getGID(), -10, OFFSET_MODE_CUR)); gs[1]->getGID(), 10, OFFSET_MODE_CUR));
CPPUNIT_ASSERT_EQUAL( CPPUNIT_ASSERT_EQUAL((size_t)1, rm.changeReservedGroupPosition(
(size_t)1, gs[1]->getGID(), -2, OFFSET_MODE_CUR));
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( CPPUNIT_ASSERT_EQUAL((size_t)3, rm.changeReservedGroupPosition(
(size_t)3, gs[3]->getGID(), 0, OFFSET_MODE_END));
rm.changeReservedGroupPosition(gs[3]->getGID(), 0, OFFSET_MODE_END)); CPPUNIT_ASSERT_EQUAL((size_t)2, rm.changeReservedGroupPosition(
CPPUNIT_ASSERT_EQUAL( gs[3]->getGID(), -1, OFFSET_MODE_END));
(size_t)2, CPPUNIT_ASSERT_EQUAL((size_t)0, rm.changeReservedGroupPosition(
rm.changeReservedGroupPosition(gs[3]->getGID(), -1, OFFSET_MODE_END)); gs[3]->getGID(), -10, OFFSET_MODE_END));
CPPUNIT_ASSERT_EQUAL( CPPUNIT_ASSERT_EQUAL((size_t)3, rm.changeReservedGroupPosition(
(size_t)0, gs[3]->getGID(), 10, OFFSET_MODE_END));
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,11 +369,10 @@ 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, CPPUNIT_ASSERT_EQUAL((size_t)1, group->getDownloadContext()
group->getDownloadContext() ->getFirstFileEntry()
->getFirstFileEntry() ->getRemainingUris()
->getRemainingUris() .size());
.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()
@ -1288,7 +1287,9 @@ void RpcMethodTest::testGetSessionInfo()
void RpcMethodTest::testPause() void RpcMethodTest::testPause()
{ {
std::vector<std::string> uris{ std::vector<std::string> uris{
"http://url1", "http://url2", "http://url3", "http://url1",
"http://url2",
"http://url3",
}; };
option_->put(PREF_FORCE_SEQUENTIAL, A2_V_TRUE); option_->put(PREF_FORCE_SEQUENTIAL, A2_V_TRUE);
std::vector<std::shared_ptr<RequestGroup>> groups; std::vector<std::shared_ptr<RequestGroup>> groups;

View File

@ -61,9 +61,8 @@ 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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) | (1 << USR_USERINFO) | (1 << USR_USER));
(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));
@ -72,10 +71,9 @@ 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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) | (1 << USR_USERINFO) | (1 << USR_USER) |
(1 << USR_USERINFO) | (1 << USR_USER) | (1 << USR_PASSWD));
(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));
@ -89,10 +87,9 @@ 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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) | (1 << USR_USERINFO) | (1 << USR_USER) |
(1 << USR_USERINFO) | (1 << USR_USER) | (1 << USR_PASSWD));
(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"),
@ -104,9 +101,8 @@ 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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) | (1 << USR_PATH));
(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));
@ -116,10 +112,9 @@ 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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) | (1 << USR_PATH) | (1 << USR_USERINFO) |
(1 << USR_PATH) | (1 << USR_USERINFO) | (1 << USR_USER) | (1 << USR_USER) | (1 << USR_PASSWD));
(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));
@ -131,9 +126,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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) | (1 << USR_PATH) | (1 << USR_USERINFO) |
(1 << USR_PATH) | (1 << USR_USERINFO) | (1 << USR_USER)); (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));
@ -157,9 +152,8 @@ 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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_USERINFO) | (1 << USR_USERINFO) | (1 << USR_USER));
(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));
@ -167,9 +161,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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_USERINFO) | (1 << USR_USERINFO) | (1 << USR_USER) |
(1 << USR_USER) | (1 << USR_PASSWD)); (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));
@ -178,9 +172,8 @@ 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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) | (1 << USR_QUERY) | (1 << USR_FRAGMENT));
(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));
@ -207,9 +200,8 @@ 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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) | (1 << USR_QUERY));
(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);
@ -218,9 +210,8 @@ 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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) | (1 << USR_FRAGMENT));
(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);
@ -229,10 +220,9 @@ 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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) | (1 << USR_QUERY) | (1 << USR_USERINFO) |
(1 << USR_QUERY) | (1 << USR_USERINFO) | (1 << USR_USER) | (1 << USR_USER) | (1 << USR_PASSWD));
(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));
@ -243,10 +233,9 @@ 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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) | (1 << USR_FRAGMENT) | (1 << USR_USERINFO) |
(1 << USR_FRAGMENT) | (1 << USR_USERINFO) | (1 << USR_USER) | (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_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));
@ -257,10 +246,9 @@ 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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_QUERY) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_QUERY) | (1 << USR_USERINFO) | (1 << USR_USER) |
(1 << USR_USERINFO) | (1 << USR_USER) | (1 << USR_PASSWD));
(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,10 +258,9 @@ 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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_FRAGMENT) | (1 << USR_FRAGMENT) | (1 << USR_USERINFO) |
(1 << USR_USERINFO) | (1 << USR_USER) | (1 << USR_USER) | (1 << USR_PASSWD));
(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));
@ -283,9 +270,8 @@ 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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) | (1 << USR_QUERY));
(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));
@ -294,9 +280,8 @@ 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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) | (1 << USR_FRAGMENT));
(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));
@ -305,9 +290,8 @@ 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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) | (1 << USR_QUERY) | (1 << USR_FRAGMENT));
(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));
@ -333,9 +317,8 @@ 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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_USERINFO) | (1 << USR_USERINFO) | (1 << USR_USER));
(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));
@ -345,9 +328,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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_USERINFO) | (1 << USR_USERINFO) | (1 << USR_USER) |
(1 << USR_USER) | (1 << USR_PASSWD)); (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));
@ -357,18 +340,16 @@ 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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) | (1 << USR_BASENAME));
(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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) | (1 << USR_BASENAME));
(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));
@ -376,9 +357,8 @@ 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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PORT) | (1 << USR_PATH) | (1 << USR_BASENAME));
(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));
@ -386,10 +366,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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_USERINFO) | (1 << USR_USERINFO) | (1 << USR_USER) |
(1 << USR_USER) | (1 << USR_PASSWD) | (1 << USR_PATH) | (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));
@ -398,9 +378,8 @@ 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, CHECK_FIELD_SET(res, (1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) |
(1 << USR_SCHEME) | (1 << USR_HOST) | (1 << USR_PATH) | (1 << USR_QUERY) | (1 << USR_BASENAME));
(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));