diff --git a/src/AbstractSingleDiskAdaptor.cc b/src/AbstractSingleDiskAdaptor.cc index 974af822..899168f1 100644 --- a/src/AbstractSingleDiskAdaptor.cc +++ b/src/AbstractSingleDiskAdaptor.cc @@ -101,7 +101,7 @@ void AbstractSingleDiskAdaptor::writeCache(const WrDiskCacheEntry* entry) // activity especially on Windows 7 NTFS. In this code, we assume // that maximum length of DataCell data is 16KiB to simplify the // code. - unsigned char buf[16*1024]; + unsigned char buf[16_k]; int64_t start = 0; size_t buflen = 0; size_t buffoffset = 0; diff --git a/src/AdaptiveFileAllocationIterator.cc b/src/AdaptiveFileAllocationIterator.cc index 36a2e928..f86517a8 100644 --- a/src/AdaptiveFileAllocationIterator.cc +++ b/src/AdaptiveFileAllocationIterator.cc @@ -61,8 +61,8 @@ void AdaptiveFileAllocationIterator::allocateChunk() try { A2_LOG_DEBUG("Testing file system supports fallocate."); if(offset_ < totalLength_) { - int64_t len = std::min(totalLength_-offset_, - static_cast(4096)); + int64_t len = + std::min(totalLength_ - offset_, static_cast(4_k)); stream_->allocate(offset_, len, false); offset_ += len; } diff --git a/src/AdaptiveURISelector.cc b/src/AdaptiveURISelector.cc index ebe7bd0b..b820b803 100644 --- a/src/AdaptiveURISelector.cc +++ b/src/AdaptiveURISelector.cc @@ -226,7 +226,7 @@ void AdaptiveURISelector::adjustLowestSpeedLimit int lowest = requestGroup_->getOption()->getAsInt(PREF_LOWEST_SPEED_LIMIT); if (lowest > 0) { - int low_lowest = 4 * 1024; + int low_lowest = 4_k; int max = getMaxDownloadSpeed(uris); if (max > 0 && lowest > max / 4) { A2_LOG_NOTICE(fmt(_("Lowering lowest-speed-limit since known max speed is" diff --git a/src/BtConstants.h b/src/BtConstants.h index 12268664..2c933888 100644 --- a/src/BtConstants.h +++ b/src/BtConstants.h @@ -36,6 +36,7 @@ #define D_BT_CONSTANTS_H #include "common.h" +#include "a2functional.h" namespace aria2 { @@ -45,14 +46,14 @@ constexpr size_t PIECE_HASH_LENGTH = 20; constexpr size_t PEER_ID_LENGTH = 20; -constexpr size_t MAX_BLOCK_LENGTH = 16 * 1024; +constexpr size_t MAX_BLOCK_LENGTH = 16_k; constexpr size_t DEFAULT_MAX_OUTSTANDING_REQUEST = 6; // Upper Bound of the number of outstanding request constexpr size_t UB_MAX_OUTSTANDING_REQUEST = 256; -constexpr size_t METADATA_PIECE_SIZE = 16 * 1024; +constexpr size_t METADATA_PIECE_SIZE = 16_k; constexpr const char LPD_MULTICAST_ADDR[] = "239.192.152.143"; diff --git a/src/BtPieceMessage.cc b/src/BtPieceMessage.cc index de41b4f1..e21321cc 100644 --- a/src/BtPieceMessage.cc +++ b/src/BtPieceMessage.cc @@ -213,7 +213,7 @@ void BtPieceMessage::send() void BtPieceMessage::pushPieceData(int64_t offset, int32_t length) const { - assert(length <= 16*1024); + assert(length <= 16_k); auto buf = make_unique(length+MESSAGE_HEADER_LENGTH); createMessageHeader(buf.get()); ssize_t r; diff --git a/src/ByteArrayDiskWriter.h b/src/ByteArrayDiskWriter.h index a9d2dda9..b5ca7140 100644 --- a/src/ByteArrayDiskWriter.h +++ b/src/ByteArrayDiskWriter.h @@ -38,6 +38,8 @@ #include "DiskWriter.h" #include +#include "a2functional.h" + namespace aria2 { class ByteArrayDiskWriter : public DiskWriter { @@ -46,7 +48,7 @@ private: size_t maxLength_; void clear(); public: - ByteArrayDiskWriter(size_t maxLength = 5*1024*1024); + ByteArrayDiskWriter(size_t maxLength = 5_m); virtual ~ByteArrayDiskWriter(); virtual void initAndOpenFile(int64_t totalLength = 0) CXX11_OVERRIDE; diff --git a/src/DHTInteractionCommand.cc b/src/DHTInteractionCommand.cc index f39c4803..732ba29e 100644 --- a/src/DHTInteractionCommand.cc +++ b/src/DHTInteractionCommand.cc @@ -100,10 +100,10 @@ bool DHTInteractionCommand::execute() std::string remoteAddr; uint16_t remotePort; - unsigned char data[64*1024]; + std::array data; try { while(1) { - ssize_t length = connection_->receiveMessage(data, sizeof(data), + ssize_t length = connection_->receiveMessage(data.data(), data.size(), remoteAddr, remotePort); if(length <= 0) { break; @@ -111,11 +111,11 @@ bool DHTInteractionCommand::execute() if(data[0] == 'd') { // udp tracker response does not start with 'd', so assume // this message belongs to DHT. nothrow. - receiver_->receiveMessage(remoteAddr, remotePort, data, length); + receiver_->receiveMessage(remoteAddr, remotePort, data.data(), length); } else { // this may be udp tracker response. nothrow. - udpTrackerClient_->receiveReply(data, length, remoteAddr, remotePort, - global::wallclock()); + udpTrackerClient_->receiveReply(data.data(), length, remoteAddr, + remotePort, global::wallclock()); } } } catch(RecoverableException& e) { @@ -126,7 +126,7 @@ bool DHTInteractionCommand::execute() dispatcher_->sendMessages(); while(!udpTrackerClient_->getPendingRequests().empty()) { // no throw - ssize_t length = udpTrackerClient_->createRequest(data, sizeof(data), + ssize_t length = udpTrackerClient_->createRequest(data.data(), data.size(), remoteAddr, remotePort, global::wallclock()); if(length == -1) { @@ -134,7 +134,7 @@ bool DHTInteractionCommand::execute() } try { // throw - connection_->sendMessage(data, length, remoteAddr, remotePort); + connection_->sendMessage(data.data(), length, remoteAddr, remotePort); udpTrackerClient_->requestSent(global::wallclock()); } catch(RecoverableException& e) { A2_LOG_INFO_EX("Exception thrown while sending UDP tracker request.", e); diff --git a/src/FeedbackURISelector.cc b/src/FeedbackURISelector.cc index d101d7e6..b9fbd539 100644 --- a/src/FeedbackURISelector.cc +++ b/src/FeedbackURISelector.cc @@ -121,9 +121,9 @@ std::string FeedbackURISelector::selectFaster const std::vector >& usedHosts) { // Use first 10 good URIs to introduce some randomness. - const size_t NUM_URI = 10; + constexpr size_t NUM_URI = 10; // Ignore low speed server - const int SPEED_THRESHOLD = 20*1024; + constexpr int SPEED_THRESHOLD = 20_k; std::vector, std::string> > fastCands; std::vector normCands; for (const auto& u: uris) { diff --git a/src/FileEntry.cc b/src/FileEntry.cc index 35b660e8..08c42c25 100644 --- a/src/FileEntry.cc +++ b/src/FileEntry.cc @@ -251,7 +251,7 @@ FileEntry::findFasterRequest const std::vector >& usedHosts, const std::shared_ptr& serverStatMan) { - const int SPEED_THRESHOLD = 20*1024; + constexpr int SPEED_THRESHOLD = 20_k; if(lastFasterReplace_.difference(global::wallclock()) < startupIdleTime) { return nullptr; } diff --git a/src/FtpConnection.cc b/src/FtpConnection.cc index d7475494..e008f721 100644 --- a/src/FtpConnection.cc +++ b/src/FtpConnection.cc @@ -332,10 +332,10 @@ FtpConnection::findEndOfResponse bool FtpConnection::bulkReceiveResponse(std::pair& response) { - char buf[1024]; + std::array buf; while(1) { - size_t size = sizeof(buf); - socket_->readData(buf, size); + size_t size = buf.size(); + socket_->readData(buf.data(), size); if(size == 0) { if(socket_->wantRead() || socket_->wantWrite()) { break; @@ -348,7 +348,7 @@ bool FtpConnection::bulkReceiveResponse(std::pair& response) (fmt("Max FTP recv buffer reached. length=%lu", static_cast(strbuf_.size()+size))); } - strbuf_.append(&buf[0], &buf[size]); + strbuf_.append(std::begin(buf), std::begin(buf) + size); } int status; if(strbuf_.size() >= 4) { diff --git a/src/FtpConnection.h b/src/FtpConnection.h index b751f50c..bc4f0025 100644 --- a/src/FtpConnection.h +++ b/src/FtpConnection.h @@ -44,6 +44,7 @@ #include "TimeA2.h" #include "SocketBuffer.h" #include "Command.h" +#include "a2functional.h" namespace aria2 { @@ -75,7 +76,7 @@ private: bool bulkReceiveResponse(std::pair& response); //prepare for large banners - static const size_t MAX_RECV_BUFFER = 65536; + static const size_t MAX_RECV_BUFFER = 64_k; public: FtpConnection(cuid_t cuid, const std::shared_ptr& socket, const std::shared_ptr& req, diff --git a/src/GZipDecodingStreamFilter.h b/src/GZipDecodingStreamFilter.h index 259379e4..6707e974 100644 --- a/src/GZipDecodingStreamFilter.h +++ b/src/GZipDecodingStreamFilter.h @@ -38,6 +38,8 @@ #include "StreamFilter.h" #include +#include "a2functional.h" + namespace aria2 { // GZipDecodingStreamFilter can decode both gzip and deflate format. @@ -49,7 +51,7 @@ private: size_t bytesProcessed_; - static const size_t OUTBUF_LENGTH = 16*1024; + static const size_t OUTBUF_LENGTH = 16_k; public: GZipDecodingStreamFilter (std::unique_ptr delegate = nullptr); diff --git a/src/GZipEncoder.cc b/src/GZipEncoder.cc index 2a3f6720..323faf19 100644 --- a/src/GZipEncoder.cc +++ b/src/GZipEncoder.cc @@ -42,10 +42,6 @@ namespace aria2 { -namespace { -const int OUTBUF_LENGTH = 4096; -} // namespace - GZipEncoder::GZipEncoder():strm_(nullptr) {} GZipEncoder::~GZipEncoder() @@ -84,16 +80,16 @@ std::string GZipEncoder::encode strm_->avail_in = length; strm_->next_in = const_cast(in); std::string out; - unsigned char outbuf[OUTBUF_LENGTH]; + std::array outbuf; while(1) { - strm_->avail_out = OUTBUF_LENGTH; - strm_->next_out = outbuf; + strm_->avail_out = outbuf.size(); + strm_->next_out = outbuf.data(); int ret = ::deflate(strm_, flush); if(ret == Z_STREAM_ERROR) { throw DL_ABORT_EX(fmt("libz::deflate() failed. cause:%s", strm_->msg)); } - size_t produced = OUTBUF_LENGTH-strm_->avail_out; + size_t produced = outbuf.size() - strm_->avail_out; out.append(&outbuf[0], &outbuf[produced]); if(strm_->avail_out > 0) { break; diff --git a/src/GZipFile.cc b/src/GZipFile.cc index ed2e4920..f669b185 100644 --- a/src/GZipFile.cc +++ b/src/GZipFile.cc @@ -45,7 +45,7 @@ namespace aria2 { GZipFile::GZipFile(const char* filename, const char* mode) : fp_(nullptr), - buflen_(1024), buf_(reinterpret_cast(malloc(buflen_))) + buflen_(1_k), buf_(reinterpret_cast(malloc(buflen_))) { FILE* fp = #ifdef __MINGW32__ diff --git a/src/GenericParser.h b/src/GenericParser.h index 780a3feb..80db5c5f 100644 --- a/src/GenericParser.h +++ b/src/GenericParser.h @@ -98,11 +98,11 @@ typename Parser::ResultType parseFile(Parser& parser, return Parser::ParserStateMachineType::noResult(); } auto fdclose = defer(fd, close); - char buf[4096]; + std::array buf; ssize_t nread; ssize_t nproc; - while((nread = read(fd, buf, sizeof(buf))) > 0) { - nproc = parser.parseUpdate(buf, nread); + while((nread = read(fd, buf.data(), buf.size())) > 0) { + nproc = parser.parseUpdate(buf.data(), nread); if(nproc < 0) { break; } diff --git a/src/HandshakeExtensionMessage.cc b/src/HandshakeExtensionMessage.cc index b7883e15..a1bbf634 100644 --- a/src/HandshakeExtensionMessage.cc +++ b/src/HandshakeExtensionMessage.cc @@ -215,7 +215,7 @@ HandshakeExtensionMessage::create(const unsigned char* data, size_t length) // Only accept metadata smaller than 1MiB. Be aware that broken // client can send negative size! - if(size > 0 && size <= 1024*1024) { + if(size > 0 && size <= 1_m) { msg->metadataSize_ = size; } } diff --git a/src/HttpHeaderProcessor.cc b/src/HttpHeaderProcessor.cc index ac8a6f2b..5a5fab35 100644 --- a/src/HttpHeaderProcessor.cc +++ b/src/HttpHeaderProcessor.cc @@ -440,7 +440,7 @@ fin: // http://httpd.apache.org/docs/2.2/en/mod/core.html about size // limit of HTTP headers. The page states that the number of request // fields rarely exceeds 20. - if (lastFieldName_.size() > 1024 || buf_.size() > 8192) { + if (lastFieldName_.size() > 1024 || buf_.size() > 8_k) { throw DL_ABORT_EX("Too large HTTP header"); } diff --git a/src/IOFile.cc b/src/IOFile.cc index 3cf01c69..9df2ebc4 100644 --- a/src/IOFile.cc +++ b/src/IOFile.cc @@ -91,15 +91,15 @@ std::string IOFile::getLine() if(eof()) { return res; } - char buf[4096]; - while(gets(buf, sizeof(buf))) { - size_t len = strlen(buf); + std::array buf; + while(gets(buf.data(), buf.size())) { + size_t len = strlen(buf.data()); bool lineBreak = false; if(buf[len-1] == '\n') { --len; lineBreak = true; } - res.append(buf, len); + res.append(buf.data(), len); if(lineBreak) { break; } @@ -120,12 +120,12 @@ bool IOFile::eof() size_t IOFile::transfer(std::ostream& out) { size_t count = 0; - char buf[4096]; + std::array buf; while(1) { - size_t r = this->read(buf, sizeof(buf)); - out.write(buf, r); + size_t r = this->read(buf.data(), buf.size()); + out.write(buf.data(), r); count += r; - if(r < sizeof(buf)) { + if(r < buf.size()) { break; } } diff --git a/src/IteratableChecksumValidator.cc b/src/IteratableChecksumValidator.cc index ecf36cb4..f5d29b15 100644 --- a/src/IteratableChecksumValidator.cc +++ b/src/IteratableChecksumValidator.cc @@ -63,10 +63,10 @@ void IteratableChecksumValidator::validateChunk() { // Don't guard with !finished() to allow zero-length file to be // verified. - unsigned char buf[4096]; + std::array buf; size_t length = pieceStorage_->getDiskAdaptor()->readDataDropCache - (buf, sizeof(buf), currentOffset_); - ctx_->update(buf, length); + (buf.data(), buf.size(), currentOffset_); + ctx_->update(buf.data(), length); currentOffset_ += length; if(finished()) { std::string actualDigest = ctx_->digest(); diff --git a/src/IteratableChunkChecksumValidator.cc b/src/IteratableChunkChecksumValidator.cc index 595e5c44..5d37e977 100644 --- a/src/IteratableChunkChecksumValidator.cc +++ b/src/IteratableChunkChecksumValidator.cc @@ -121,18 +121,19 @@ void IteratableChunkChecksumValidator::init() std::string IteratableChunkChecksumValidator::digest(int64_t offset, size_t length) { - unsigned char buf[4096]; + std::array buf; ctx_->reset(); int64_t max = offset+length; while(offset < max) { - size_t r = pieceStorage_->getDiskAdaptor()->readDataDropCache - (buf, std::min(static_cast(sizeof(buf)), max-offset), offset); + size_t r = pieceStorage_->getDiskAdaptor()->readDataDropCache( + buf.data(), std::min(static_cast(buf.size()), max - offset), + offset); if(r == 0) { throw DL_ABORT_EX (fmt(EX_FILE_READ, dctx_->getBasePath().c_str(), "data is too short")); } - ctx_->update(buf, r); + ctx_->update(buf.data(), r); offset += r; } return ctx_->digest(); diff --git a/src/MSEHandshake.cc b/src/MSEHandshake.cc index 3b3f67fc..f6a6d1ad 100644 --- a/src/MSEHandshake.cc +++ b/src/MSEHandshake.cc @@ -198,15 +198,15 @@ void MSEHandshake::initCipher(const unsigned char* infoHash) decryptor_->init(peerCipherKey, sizeof(peerCipherKey)); // discard first 1024 bytes ARC4 output. - unsigned char garbage[1024]; - encryptor_->encrypt(1024, garbage, garbage); - decryptor_->encrypt(1024, garbage, garbage); + std::array garbage; + encryptor_->encrypt(garbage.size(), garbage.data(), garbage.data()); + decryptor_->encrypt(garbage.size(), garbage.data(), garbage.data()); if(initiator_) { ARC4Encryptor enc; enc.init(peerCipherKey, sizeof(peerCipherKey)); // discard first 1024 bytes ARC4 output. - enc.encrypt(1024, garbage, garbage); + enc.encrypt(garbage.size(), garbage.data(), garbage.data()); enc.encrypt(VC_LENGTH, initiatorVCMarker_, VC); } } diff --git a/src/MultiDiskAdaptor.cc b/src/MultiDiskAdaptor.cc index 8f9c6c20..807e9121 100644 --- a/src/MultiDiskAdaptor.cc +++ b/src/MultiDiskAdaptor.cc @@ -423,7 +423,7 @@ void MultiDiskAdaptor::writeCache(const WrDiskCacheEntry* entry) { // Write cached data in 4KiB aligned offset. This reduces disk // activity especially on Windows 7 NTFS. - unsigned char buf[16*1024]; + unsigned char buf[16_k]; size_t buflen = 0; size_t buffoffset = 0; auto& dataSet = entry->getDataSet(); diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index ea1fa3bf..433d815c 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -574,7 +574,7 @@ std::vector OptionHandlerFactory::createOptionHandlers() (PREF_MIN_SPLIT_SIZE, TEXT_MIN_SPLIT_SIZE, "20M", - 1024*1024, 1024*1024*1024, + 1_m, 1_g, 'k')); op->addTag(TAG_BASIC); op->addTag(TAG_FTP); @@ -1072,8 +1072,7 @@ std::vector OptionHandlerFactory::createOptionHandlers() (PREF_PIECE_LENGTH, TEXT_PIECE_LENGTH, "1M", - 1024*1024, - 1024*1024*1024)); + 1_m, 1_g)); op->addTag(TAG_ADVANCED); op->addTag(TAG_FTP); op->addTag(TAG_HTTP); diff --git a/src/PeerConnection.cc b/src/PeerConnection.cc index 7caaa4ec..f494d26c 100644 --- a/src/PeerConnection.cc +++ b/src/PeerConnection.cc @@ -166,7 +166,7 @@ bool PeerConnection::receiveMessage(unsigned char* data, size_t& dataLength) size_t nread; // To reduce the amount of copy involved in buffer shift, large // payload will be read exactly. - if(currentPayloadLength_ > 4096) { + if(currentPayloadLength_ > 4_k) { nread = currentPayloadLength_ + 4 - resbufLength_; } else { nread = bufferCapacity_ - resbufLength_; diff --git a/src/PeerConnection.h b/src/PeerConnection.h index b724ab4f..ebd61133 100644 --- a/src/PeerConnection.h +++ b/src/PeerConnection.h @@ -42,6 +42,7 @@ #include "SocketBuffer.h" #include "Command.h" +#include "a2functional.h" namespace aria2 { @@ -52,7 +53,7 @@ class ARC4Encryptor; // The maximum length of buffer. If the message length (including 4 // bytes length and payload length) is larger than this value, it is // dropped. -constexpr size_t MAX_BUFFER_CAPACITY = 16 * 1024 + 128; +constexpr size_t MAX_BUFFER_CAPACITY = 16_k + 128; class PeerConnection { private: diff --git a/src/Piece.cc b/src/Piece.cc index e5c3c9c7..54453657 100644 --- a/src/Piece.cc +++ b/src/Piece.cc @@ -245,23 +245,22 @@ void updateHashWithRead(MessageDigest* mdctx, const std::shared_ptr& adaptor, int64_t offset, size_t len) { - const size_t BUFSIZE = 4096; - unsigned char buf[BUFSIZE]; - ldiv_t res = ldiv(len, BUFSIZE); + std::array buf; + ldiv_t res = ldiv(len, buf.size()); for(int j = 0; j < res.quot; ++j) { - ssize_t nread = adaptor->readData(buf, BUFSIZE, offset); - if((size_t)nread != BUFSIZE) { + ssize_t nread = adaptor->readData(buf.data(), buf.size(), offset); + if((size_t)nread != buf.size()) { throw DL_ABORT_EX(fmt(EX_FILE_READ, "n/a", "data is too short")); } - mdctx->update(buf, nread); + mdctx->update(buf.data(), nread); offset += nread; } if(res.rem) { - ssize_t nread = adaptor->readData(buf, res.rem, offset); + ssize_t nread = adaptor->readData(buf.data(), res.rem, offset); if(nread != res.rem) { throw DL_ABORT_EX(fmt(EX_FILE_READ, "n/a", "data is too short")); } - mdctx->update(buf, nread); + mdctx->update(buf.data(), nread); } } } // namespace diff --git a/src/Piece.h b/src/Piece.h index de4e1657..bf370383 100644 --- a/src/Piece.h +++ b/src/Piece.h @@ -43,6 +43,7 @@ #include #include "Command.h" +#include "a2functional.h" namespace aria2 { @@ -71,7 +72,7 @@ private: Piece& operator=(const Piece& piece) = delete; public: - static const int32_t BLOCK_LENGTH = 16*1024; + static const int32_t BLOCK_LENGTH = 16_k; Piece(); Piece(size_t index, int64_t length, int32_t blockLength = BLOCK_LENGTH); diff --git a/src/SingleFileAllocationIterator.cc b/src/SingleFileAllocationIterator.cc index c2aa16c7..cbc704fa 100644 --- a/src/SingleFileAllocationIterator.cc +++ b/src/SingleFileAllocationIterator.cc @@ -45,7 +45,7 @@ namespace aria2 { -constexpr size_t BUFSIZE = 256 * 1024; +constexpr size_t BUFSIZE = 256_k; constexpr size_t ALIGNMENT = 512; SingleFileAllocationIterator::SingleFileAllocationIterator diff --git a/src/SinkStreamFilter.cc b/src/SinkStreamFilter.cc index 28ea7fe0..a1abdf06 100644 --- a/src/SinkStreamFilter.cc +++ b/src/SinkStreamFilter.cc @@ -79,7 +79,7 @@ ssize_t SinkStreamFilter::transform inbuf, wlen); if(alen < wlen) { size_t len = wlen - alen; - size_t capacity = std::max(len, static_cast(4096)); + size_t capacity = std::max(len, static_cast(4_k)); auto dataCopy = new unsigned char[capacity]; memcpy(dataCopy, inbuf + alen, len); piece->updateWrCache(wrDiskCache_, dataCopy, 0, len, capacity, diff --git a/src/SocketBuffer.cc b/src/SocketBuffer.cc index f941df90..a9e27c5d 100644 --- a/src/SocketBuffer.cc +++ b/src/SocketBuffer.cc @@ -135,7 +135,7 @@ ssize_t SocketBuffer::send() while(!bufq_.empty()) { size_t num; size_t bufqlen = bufq_.size(); - ssize_t amount = 24*1024; + ssize_t amount = 24_k; ssize_t firstlen = bufq_.front()->getLength() - offset_; amount -= firstlen; iov[0].A2IOVEC_BASE = diff --git a/src/SocketCore.cc b/src/SocketCore.cc index 6948fa21..3b8cb4a5 100644 --- a/src/SocketCore.cc +++ b/src/SocketCore.cc @@ -1518,7 +1518,7 @@ void checkAddrconfig() { #ifdef HAVE_IPHLPAPI_H A2_LOG_INFO("Checking configured addresses"); - ULONG bufsize = 15*1024; + ULONG bufsize = 15_k; ULONG retval = 0; IP_ADAPTER_ADDRESSES* buf = 0; int numTry = 0; diff --git a/src/SocketRecvBuffer.h b/src/SocketRecvBuffer.h index ceee253e..f642a6d1 100644 --- a/src/SocketRecvBuffer.h +++ b/src/SocketRecvBuffer.h @@ -40,6 +40,8 @@ #include #include +#include "a2functional.h" + namespace aria2 { class SocketCore; @@ -79,7 +81,7 @@ public: } private: - std::array buf_; + std::array buf_; std::shared_ptr socket_; unsigned char *pos_; unsigned char *last_; diff --git a/src/WinTLSSession.cc b/src/WinTLSSession.cc index dba2db41..4a180eb1 100644 --- a/src/WinTLSSession.cc +++ b/src/WinTLSSession.cc @@ -494,7 +494,7 @@ ssize_t WinTLSSession::readData(void* data, size_t len) } // Read as many bytes as available from the connection, up to len + 4k. - readBuf_.resize(len + 4096); + readBuf_.resize(len + 4_k); while (readBuf_.free()) { ssize_t read = ::recv(sockfd_, readBuf_.end(), readBuf_.free(), 0); errno = ::WSAGetLastError(); @@ -697,7 +697,7 @@ restart: // Read as many bytes as possible, up to 4k new bytes. // We do not know how many bytes will arrive from the server at this // point. - readBuf_.resize(readBuf_.size() + 4096); + readBuf_.resize(readBuf_.size() + 4_k); while (readBuf_.free()) { ssize_t read = ::recv(sockfd_, readBuf_.end(), readBuf_.free(), 0); errno = ::WSAGetLastError(); diff --git a/src/XmlParser.cc b/src/XmlParser.cc index 289d04bb..546ff746 100644 --- a/src/XmlParser.cc +++ b/src/XmlParser.cc @@ -55,11 +55,11 @@ bool parseFile(const std::string& filename, ParserStateMachine* psm) } auto fdclose = defer(fd, close); XmlParser ps(psm); - char buf[4096]; + std::array buf; ssize_t nread; bool retval = true; - while((nread = read(fd, buf, sizeof(buf))) > 0) { - if(ps.parseUpdate(buf, nread) < 0) { + while((nread = read(fd, buf.data(), buf.size())) > 0) { + if(ps.parseUpdate(buf.data(), nread) < 0) { retval = false; break; } diff --git a/src/a2functional.h b/src/a2functional.h index ff0bcb95..481cc590 100644 --- a/src/a2functional.h +++ b/src/a2functional.h @@ -188,6 +188,23 @@ make_unique(size_t size) return std::unique_ptr(new typename std::remove_extent::type[size]()); } +// User-defined literals for K, M, and G (powers of 1024) + +constexpr unsigned long long operator"" _k(unsigned long long k) +{ + return k * 1024; +} + +constexpr unsigned long long operator"" _m(unsigned long long m) +{ + return m * 1024 * 1024; +} + +constexpr unsigned long long operator"" _g(unsigned long long g) +{ + return g * 1024 * 1024 * 1024; +} + constexpr std::chrono::hours operator"" _h(unsigned long long h) { return std::chrono::hours(h); diff --git a/src/message_digest_helper.cc b/src/message_digest_helper.cc index 80b41b42..be612aac 100644 --- a/src/message_digest_helper.cc +++ b/src/message_digest_helper.cc @@ -53,25 +53,24 @@ std::string digest const std::shared_ptr& bs, int64_t offset, int64_t length) { - size_t BUFSIZE = 4096; - unsigned char BUF[BUFSIZE]; - lldiv_t res = lldiv(length, BUFSIZE); + std::array buf; + lldiv_t res = lldiv(length, buf.size()); int64_t iteration = res.quot; size_t tail = res.rem; for(int64_t i = 0; i < iteration; ++i) { - ssize_t readLength = bs->readData(BUF, BUFSIZE, offset); - if((size_t)readLength != BUFSIZE) { + ssize_t readLength = bs->readData(buf.data(), buf.size(), offset); + if((size_t)readLength != buf.size()) { throw DL_ABORT_EX(fmt(EX_FILE_READ, "n/a", "data is too short")); } - ctx->update(BUF, readLength); + ctx->update(buf.data(), readLength); offset += readLength; } if(tail) { - ssize_t readLength = bs->readData(BUF, tail, offset); + ssize_t readLength = bs->readData(buf.data(), tail, offset); if((size_t)readLength != tail) { throw DL_ABORT_EX(fmt(EX_FILE_READ, "n/a", "data is too short")); } - ctx->update(BUF, readLength); + ctx->update(buf.data(), readLength); } return ctx->digest(); } diff --git a/src/metalink_helper.cc b/src/metalink_helper.cc index 9a24fe40..09264b1e 100644 --- a/src/metalink_helper.cc +++ b/src/metalink_helper.cc @@ -42,6 +42,7 @@ #include "DlAbortEx.h" #include "BinaryStream.h" #include "MetalinkMetaurl.h" +#include "a2functional.h" namespace aria2 { @@ -131,12 +132,12 @@ std::unique_ptr parseBinaryStream MetalinkParserStateMachine psm; psm.setBaseUri(baseUri); xml::XmlParser ps(&psm); - unsigned char buf[4096]; + std::array buf; ssize_t nread; int64_t offread = 0; bool retval = true; - while((nread = bs->readData(buf, sizeof(buf), offread)) > 0) { - if(ps.parseUpdate(reinterpret_cast(buf), nread) < 0) { + while((nread = bs->readData(buf.data(), buf.size(), offread)) > 0) { + if(ps.parseUpdate(reinterpret_cast(buf.data()), nread) < 0) { retval = false; break; } diff --git a/src/util.cc b/src/util.cc index 1905f637..b94be42d 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1132,11 +1132,11 @@ ssize_t parse_content_disposition(char *dest, size_t destlen, std::string getContentDispositionFilename(const std::string& header) { - char cdval[1024]; - size_t cdvallen = sizeof(cdval); + std::array cdval; + size_t cdvallen = cdval.size(); const char* charset; size_t charsetlen; - ssize_t rv = parse_content_disposition(cdval, cdvallen, + ssize_t rv = parse_content_disposition(cdval.data(), cdvallen, &charset, &charsetlen, header.c_str(), header.size()); if(rv == -1) { @@ -1145,9 +1145,9 @@ std::string getContentDispositionFilename(const std::string& header) std::string res; if(!charset || strieq(charset, charset+charsetlen, "iso-8859-1")) { - res = iso8859p1ToUtf8(cdval, rv); + res = iso8859p1ToUtf8(cdval.data(), rv); } else { - res.assign(cdval, rv); + res.assign(cdval.data(), rv); } if(!detectDirTraversal(res) && res.find_first_of("/\\") == std::string::npos) { @@ -1378,11 +1378,11 @@ int64_t getRealSize(const std::string& sizeWithUnit) switch(sizeWithUnit[p]) { case 'K': case 'k': - mult = 1024; + mult = 1_k; break; case 'M': case 'm': - mult = 1024*1024; + mult = 1_m; break; } size.assign(sizeWithUnit.begin(), sizeWithUnit.begin()+p); @@ -1405,8 +1405,8 @@ std::string abbrevSize(int64_t size) int64_t t = size; size_t uidx = 0; int r = 0; - while(t >= 1024 && uidx+1 < sizeof(UNITS)/sizeof(UNITS[0])) { - lldiv_t d = lldiv(t, 1024); + while(t >= 1_k && uidx+1 < sizeof(UNITS)/sizeof(UNITS[0])) { + lldiv_t d = lldiv(t, 1_k); t = d.quot; r = d.rem; ++uidx; @@ -1420,7 +1420,7 @@ std::string abbrevSize(int64_t size) res += itos(t, true); if(t < 10 && uidx > 0) { res += "."; - res += itos(r*10/1024); + res += itos(r * 10 / 1_k); } res += UNITS[uidx]; return res; diff --git a/test/BitfieldManTest.cc b/test/BitfieldManTest.cc index 0e809027..0ed28d15 100644 --- a/test/BitfieldManTest.cc +++ b/test/BitfieldManTest.cc @@ -78,19 +78,19 @@ public: CPPUNIT_TEST_SUITE_REGISTRATION( BitfieldManTest ); void BitfieldManTest::testGetBlockSize() { - BitfieldMan bt1(1024, 1024*10); - CPPUNIT_ASSERT_EQUAL(1024, bt1.getBlockLength(9)); + BitfieldMan bt1(1_k, 10_k); + CPPUNIT_ASSERT_EQUAL((int32_t)1_k, bt1.getBlockLength(9)); - BitfieldMan bt2(1024, 1024*10+1); - CPPUNIT_ASSERT_EQUAL(1024, bt2.getBlockLength(9)); - CPPUNIT_ASSERT_EQUAL(1, bt2.getBlockLength(10)); - CPPUNIT_ASSERT_EQUAL(0, bt2.getBlockLength(11)); + BitfieldMan bt2(1_k, 10_k + 1); + CPPUNIT_ASSERT_EQUAL((int32_t)1_k, bt2.getBlockLength(9)); + CPPUNIT_ASSERT_EQUAL((int32_t)1, bt2.getBlockLength(10)); + CPPUNIT_ASSERT_EQUAL((int32_t)0, bt2.getBlockLength(11)); } void BitfieldManTest::testGetFirstMissingUnusedIndex() { { - BitfieldMan bt1(1024, 1024*10); + BitfieldMan bt1(1_k, 10_k); { size_t index; CPPUNIT_ASSERT(bt1.getFirstMissingUnusedIndex(index)); @@ -116,9 +116,9 @@ void BitfieldManTest::testGetFirstMissingUnusedIndex() } } { - BitfieldMan bt1(1024, 1024*10); + BitfieldMan bt1(1_k, 10_k); - bt1.addFilter(1024, 1024*10); + bt1.addFilter(1_k, 10_k); bt1.enableFilter(); { size_t index; @@ -143,7 +143,7 @@ void BitfieldManTest::testGetFirstMissingUnusedIndex() void BitfieldManTest::testGetFirstMissingIndex() { { - BitfieldMan bt1(1024, 1024*10); + BitfieldMan bt1(1_k, 10_k); { size_t index; CPPUNIT_ASSERT(bt1.getFirstMissingIndex(index)); @@ -169,9 +169,9 @@ void BitfieldManTest::testGetFirstMissingIndex() } } { - BitfieldMan bt1(1024, 1024*10); + BitfieldMan bt1(1_k, 10_k); - bt1.addFilter(1024, 1024*10); + bt1.addFilter(1_k, 10_k); bt1.enableFilter(); { size_t index; @@ -194,7 +194,7 @@ void BitfieldManTest::testGetFirstMissingIndex() } void BitfieldManTest::testIsAllBitSet() { - BitfieldMan bt1(1024, 1024*10); + BitfieldMan bt1(1_k, 10_k); CPPUNIT_ASSERT(!bt1.isAllBitSet()); bt1.setBit(1); CPPUNIT_ASSERT(!bt1.isAllBitSet()); @@ -209,7 +209,7 @@ void BitfieldManTest::testIsAllBitSet() { } CPPUNIT_ASSERT(bt1.isAllBitSet()); - BitfieldMan btzero(1024, 0); + BitfieldMan btzero(1_k, 0); CPPUNIT_ASSERT(btzero.isAllBitSet()); } @@ -261,8 +261,8 @@ void BitfieldManTest::testIsFilterBitSet() void BitfieldManTest::testAddFilter_zeroLength() { - BitfieldMan bits(1024, 1024*1024); - bits.addFilter(2048, 0); + BitfieldMan bits(1_k, 1_m); + bits.addFilter(2_k, 0); bits.enableFilter(); CPPUNIT_ASSERT_EQUAL((size_t)0, bits.countMissingBlock()); CPPUNIT_ASSERT(bits.isFilteredAllBitSet()); @@ -299,11 +299,11 @@ void BitfieldManTest::testAddNotFilter_overflow() { // TODO1.5 add test using ignoreBitfield void BitfieldManTest::testGetSparseMissingUnusedIndex() { - BitfieldMan bitfield(1024*1024, 10*1024*1024); + BitfieldMan bitfield(1_m, 10_m); const size_t length = 2; unsigned char ignoreBitfield[length]; memset(ignoreBitfield, 0, sizeof(ignoreBitfield)); - size_t minSplitSize = 1024*1024; + size_t minSplitSize = 1_m; size_t index; CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index, minSplitSize, ignoreBitfield, length)); @@ -350,11 +350,11 @@ void BitfieldManTest::testGetSparseMissingUnusedIndex() { } void BitfieldManTest::testGetSparseMissingUnusedIndex_setBit() { - BitfieldMan bitfield(1024*1024, 10*1024*1024); + BitfieldMan bitfield(1_m, 10_m); const size_t length = 2; unsigned char ignoreBitfield[length]; memset(ignoreBitfield, 0, sizeof(ignoreBitfield)); - size_t minSplitSize = 1024*1024; + size_t minSplitSize = 1_m; size_t index; CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index, minSplitSize, ignoreBitfield, length)); @@ -402,11 +402,11 @@ void BitfieldManTest::testGetSparseMissingUnusedIndex_setBit() { void BitfieldManTest::testGetSparseMissingUnusedIndex_withMinSplitSize() { - BitfieldMan bitfield(1024*1024, 10*1024*1024); + BitfieldMan bitfield(1_m, 10_m); const size_t length = 2; unsigned char ignoreBitfield[length]; memset(ignoreBitfield, 0, sizeof(ignoreBitfield)); - size_t minSplitSize = 2*1024*1024; + size_t minSplitSize = 2_m; size_t index; bitfield.setUseBit(1); CPPUNIT_ASSERT(bitfield.getSparseMissingUnusedIndex(index, minSplitSize, @@ -435,8 +435,8 @@ void BitfieldManTest::testGetSparseMissingUnusedIndex_withMinSplitSize() void BitfieldManTest::testIsBitSetOffsetRange() { - int64_t totalLength = 4ULL*1024*1024*1024; - int32_t pieceLength = 4*1024*1024; + int64_t totalLength = 4_g; + int32_t pieceLength = 4_m; BitfieldMan bitfield(pieceLength, totalLength); bitfield.setAllBit(); @@ -466,9 +466,9 @@ void BitfieldManTest::testIsBitSetOffsetRange() void BitfieldManTest::testGetOffsetCompletedLength() { - BitfieldMan bt(1024, 1024*20); + BitfieldMan bt(1_k, 20_k); // 00000|00000|00000|00000 - CPPUNIT_ASSERT_EQUAL((int64_t)0, bt.getOffsetCompletedLength(0, 1024)); + CPPUNIT_ASSERT_EQUAL((int64_t)0, bt.getOffsetCompletedLength(0, 1_k)); CPPUNIT_ASSERT_EQUAL((int64_t)0, bt.getOffsetCompletedLength(0, 0)); for(size_t i = 2; i <= 4; ++i) { bt.setBit(i); @@ -480,10 +480,10 @@ void BitfieldManTest::testGetOffsetCompletedLength() CPPUNIT_ASSERT_EQUAL((int64_t)0, bt.getOffsetCompletedLength(2048, 0)); CPPUNIT_ASSERT_EQUAL((int64_t)1, bt.getOffsetCompletedLength(2048, 1)); CPPUNIT_ASSERT_EQUAL((int64_t)0, bt.getOffsetCompletedLength(2047, 1)); - CPPUNIT_ASSERT_EQUAL((int64_t)3072, bt.getOffsetCompletedLength(0, 1024*20)); + CPPUNIT_ASSERT_EQUAL((int64_t)3072, bt.getOffsetCompletedLength(0, 20_k)); CPPUNIT_ASSERT_EQUAL((int64_t)3072, - bt.getOffsetCompletedLength(0, 1024*20+10)); - CPPUNIT_ASSERT_EQUAL((int64_t)0, bt.getOffsetCompletedLength(1024*20, 1)); + bt.getOffsetCompletedLength(0, 20_k + 10)); + CPPUNIT_ASSERT_EQUAL((int64_t)0, bt.getOffsetCompletedLength(20_k, 1)); } void BitfieldManTest::testGetOffsetCompletedLength_largeFile() @@ -508,8 +508,8 @@ void BitfieldManTest::testGetOffsetCompletedLength_largeFile() void BitfieldManTest::testGetMissingUnusedLength() { - int64_t totalLength = 1024*10+10; - size_t blockLength = 1024; + int64_t totalLength = 10_k + 10; + size_t blockLength = 1_k; BitfieldMan bf(blockLength, totalLength); @@ -539,7 +539,7 @@ void BitfieldManTest::testGetMissingUnusedLength() void BitfieldManTest::testSetBitRange() { - size_t blockLength = 1024*1024; + size_t blockLength = 1_m; int64_t totalLength = 10*blockLength; BitfieldMan bf(blockLength, totalLength); @@ -557,8 +557,8 @@ void BitfieldManTest::testSetBitRange() void BitfieldManTest::testGetAllMissingIndexes_noarg() { - size_t blockLength = 16*1024; - int64_t totalLength = 1024*1024; + size_t blockLength = 16_k; + int64_t totalLength = 1_m; size_t nbits = (totalLength+blockLength-1)/blockLength; BitfieldMan bf(blockLength, totalLength); unsigned char misbitfield[8]; @@ -576,7 +576,7 @@ void BitfieldManTest::testGetAllMissingIndexes_noarg() // See garbage bits of last byte are 0 void BitfieldManTest::testGetAllMissingIndexes_checkLastByte() { - size_t blockLength = 16*1024; + size_t blockLength = 16_k; int64_t totalLength = blockLength*2; size_t nbits = (totalLength+blockLength-1)/blockLength; BitfieldMan bf(blockLength, totalLength); @@ -589,8 +589,8 @@ void BitfieldManTest::testGetAllMissingIndexes_checkLastByte() void BitfieldManTest::testGetAllMissingIndexes() { - size_t blockLength = 16*1024; - int64_t totalLength = 1024*1024; + size_t blockLength = 16_k; + int64_t totalLength = 1_m; size_t nbits = (totalLength+blockLength-1)/blockLength; BitfieldMan bf(blockLength, totalLength); BitfieldMan peerBf(blockLength, totalLength); @@ -615,8 +615,8 @@ void BitfieldManTest::testGetAllMissingIndexes() void BitfieldManTest::testGetAllMissingUnusedIndexes() { - size_t blockLength = 16*1024; - int64_t totalLength = 1024*1024; + size_t blockLength = 16_k; + int64_t totalLength = 1_m; size_t nbits = (totalLength+blockLength-1)/blockLength; BitfieldMan bf(blockLength, totalLength); BitfieldMan peerBf(blockLength, totalLength); @@ -644,10 +644,10 @@ void BitfieldManTest::testGetAllMissingUnusedIndexes() void BitfieldManTest::testCountFilteredBlock() { - BitfieldMan bt(1024, 1024*256); + BitfieldMan bt(1_k, 256_k); CPPUNIT_ASSERT_EQUAL((size_t)256, bt.countBlock()); CPPUNIT_ASSERT_EQUAL((size_t)0, bt.countFilteredBlock()); - bt.addFilter(1024, 1024*256); + bt.addFilter(1_k, 256_k); bt.enableFilter(); CPPUNIT_ASSERT_EQUAL((size_t)256, bt.countBlock()); CPPUNIT_ASSERT_EQUAL((size_t)255, bt.countFilteredBlock()); @@ -658,7 +658,7 @@ void BitfieldManTest::testCountFilteredBlock() void BitfieldManTest::testCountMissingBlock() { - BitfieldMan bt(1024, 1024*10); + BitfieldMan bt(1_k, 10_k); CPPUNIT_ASSERT_EQUAL((size_t)10, bt.countMissingBlock()); bt.setBit(1); CPPUNIT_ASSERT_EQUAL((size_t)9, bt.countMissingBlock()); @@ -668,14 +668,14 @@ void BitfieldManTest::testCountMissingBlock() void BitfieldManTest::testZeroLengthFilter() { - BitfieldMan bt(1024, 1024*10); + BitfieldMan bt(1_k, 10_k); bt.enableFilter(); CPPUNIT_ASSERT_EQUAL((size_t)0, bt.countMissingBlock()); } void BitfieldManTest::testGetFirstNMissingUnusedIndex() { - BitfieldMan bt(1024, 1024*10); + BitfieldMan bt(1_k, 10_k); bt.setUseBit(1); bt.setBit(5); std::vector out; @@ -696,7 +696,7 @@ void BitfieldManTest::testGetFirstNMissingUnusedIndex() CPPUNIT_ASSERT_EQUAL((size_t)0, bt.getFirstNMissingUnusedIndex(out, 10)); bt.clearAllBit(); out.clear(); - bt.addFilter(1024*9, 1024); + bt.addFilter(9_k, 1_k); bt.enableFilter(); CPPUNIT_ASSERT_EQUAL((size_t)1, bt.getFirstNMissingUnusedIndex(out, 256)); CPPUNIT_ASSERT_EQUAL((size_t)1, out.size()); @@ -705,11 +705,11 @@ void BitfieldManTest::testGetFirstNMissingUnusedIndex() void BitfieldManTest::testGetInorderMissingUnusedIndex() { - BitfieldMan bt(1024, 1024*20); + BitfieldMan bt(1_k, 20_k); const size_t length = 3; unsigned char ignoreBitfield[length]; memset(ignoreBitfield, 0, sizeof(ignoreBitfield)); - size_t minSplitSize = 1024; + size_t minSplitSize = 1_k; size_t index; // 00000|00000|00000|00000 CPPUNIT_ASSERT @@ -722,7 +722,7 @@ void BitfieldManTest::testGetInorderMissingUnusedIndex() (bt.getInorderMissingUnusedIndex (index, minSplitSize, ignoreBitfield, length)); CPPUNIT_ASSERT_EQUAL((size_t)1, index); - minSplitSize = 1024*2; + minSplitSize = 2_k; CPPUNIT_ASSERT (bt.getInorderMissingUnusedIndex (index, minSplitSize, ignoreBitfield, length)); @@ -759,7 +759,7 @@ void BitfieldManTest::testGetInorderMissingUnusedIndex() (bt.getInorderMissingUnusedIndex (index, minSplitSize, ignoreBitfield, length)); CPPUNIT_ASSERT_EQUAL((size_t)2, index); - bt.addFilter(1024*3, 1024*3); + bt.addFilter(3_k, 3_k); bt.enableFilter(); CPPUNIT_ASSERT (bt.getInorderMissingUnusedIndex @@ -769,11 +769,11 @@ void BitfieldManTest::testGetInorderMissingUnusedIndex() void BitfieldManTest::testGetGeomMissingUnusedIndex() { - BitfieldMan bt(1024, 1024*20); + BitfieldMan bt(1_k, 20_k); const size_t length = 3; unsigned char ignoreBitfield[length]; memset(ignoreBitfield, 0, sizeof(ignoreBitfield)); - size_t minSplitSize = 1024; + size_t minSplitSize = 1_k; size_t index; // 00000|00000|00000|00000 CPPUNIT_ASSERT diff --git a/test/BittorrentHelperTest.cc b/test/BittorrentHelperTest.cc index 24f84c51..73e0c235 100644 --- a/test/BittorrentHelperTest.cc +++ b/test/BittorrentHelperTest.cc @@ -417,13 +417,13 @@ void BittorrentHelperTest::testLoadFromMemory_multiFileNonUtf8Path() path->append("path"); path->append(fromHex("90a28a")+"E"); auto file = Dict::g(); - file->put("length", Integer::g(1024)); + file->put("length", Integer::g(1_k)); file->put("path", std::move(path)); auto files = List::g(); files->append(std::move(file)); auto info = Dict::g(); info->put("files", std::move(files)); - info->put("piece length", Integer::g(1024)); + info->put("piece length", Integer::g(1_k)); info->put("pieces", "01234567890123456789"); info->put("name", fromHex("1b")+"$B%O%m!<"+fromHex("1b")+"(B"); Dict dict; @@ -445,10 +445,10 @@ void BittorrentHelperTest::testLoadFromMemory_multiFileNonUtf8Path() void BittorrentHelperTest::testLoadFromMemory_singleFileNonUtf8Path() { auto info = Dict::g(); - info->put("piece length", Integer::g(1024)); + info->put("piece length", Integer::g(1_k)); info->put("pieces", "01234567890123456789"); info->put("name", fromHex("90a28a")+"E"); - info->put("length", Integer::g(1024)); + info->put("length", Integer::g(1_k)); Dict dict; dict.put("info", std::move(info)); auto dctx = std::make_shared(); diff --git a/test/BtAllowedFastMessageTest.cc b/test/BtAllowedFastMessageTest.cc index a1065997..ab4f9a26 100644 --- a/test/BtAllowedFastMessageTest.cc +++ b/test/BtAllowedFastMessageTest.cc @@ -77,7 +77,7 @@ void BtAllowedFastMessageTest::testDoReceivedAction() { BtAllowedFastMessage msg; msg.setIndex(1); std::shared_ptr peer(new Peer("localhost", 6969)); - peer->allocateSessionResource(1024, 1024*1024); + peer->allocateSessionResource(1_k, 1_m); peer->setFastExtensionEnabled(true); msg.setPeer(peer); CPPUNIT_ASSERT(!peer->isInPeerAllowedIndexSet(1)); @@ -95,7 +95,7 @@ void BtAllowedFastMessageTest::testOnSendComplete() { BtAllowedFastMessage msg; msg.setIndex(1); std::shared_ptr peer(new Peer("localhost", 6969)); - peer->allocateSessionResource(1024, 1024*1024); + peer->allocateSessionResource(1_k, 1_m); peer->setFastExtensionEnabled(true); msg.setPeer(peer); CPPUNIT_ASSERT(!peer->isInAmAllowedIndexSet(1)); diff --git a/test/BtBitfieldMessageTest.cc b/test/BtBitfieldMessageTest.cc index 9331b94b..095fd9e8 100644 --- a/test/BtBitfieldMessageTest.cc +++ b/test/BtBitfieldMessageTest.cc @@ -82,7 +82,7 @@ void BtBitfieldMessageTest::testCreateMessage() { void BtBitfieldMessageTest::testDoReceivedAction() { std::shared_ptr peer(new Peer("host1", 6969)); - peer->allocateSessionResource(16*1024, 16*16*1024); + peer->allocateSessionResource(16_k, 256_k); BtBitfieldMessage msg; msg.setPeer(peer); auto pieceStorage = make_unique(); @@ -100,7 +100,7 @@ void BtBitfieldMessageTest::testDoReceivedAction() { void BtBitfieldMessageTest::testDoReceivedAction_goodByeSeeder() { std::shared_ptr peer(new Peer("ip", 6000)); - peer->allocateSessionResource(1024, 1024); + peer->allocateSessionResource(1_k, 1_k); BtBitfieldMessage msg; msg.setPeer(peer); auto pieceStorage = make_unique(); diff --git a/test/BtCancelMessageTest.cc b/test/BtCancelMessageTest.cc index e382c6f0..906a21dc 100644 --- a/test/BtCancelMessageTest.cc +++ b/test/BtCancelMessageTest.cc @@ -57,12 +57,12 @@ void BtCancelMessageTest::testCreate() { bittorrent::createPeerMessageString(msg, sizeof(msg), 13, 8); bittorrent::setIntParam(&msg[5], 12345); bittorrent::setIntParam(&msg[9], 256); - bittorrent::setIntParam(&msg[13], 1024); + bittorrent::setIntParam(&msg[13], 1_k); auto pm = BtCancelMessage::create(&msg[4], 13); CPPUNIT_ASSERT_EQUAL((uint8_t)8, pm->getId()); CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex()); CPPUNIT_ASSERT_EQUAL(256, pm->getBegin()); - CPPUNIT_ASSERT_EQUAL(1024, pm->getLength()); + CPPUNIT_ASSERT_EQUAL((int32_t)1_k, pm->getLength()); // case: payload size is wrong try { @@ -86,12 +86,12 @@ void BtCancelMessageTest::testCreateMessage() { BtCancelMessage msg; msg.setIndex(12345); msg.setBegin(256); - msg.setLength(1024); + msg.setLength(1_k); unsigned char data[17]; bittorrent::createPeerMessageString(data, sizeof(data), 13, 8); bittorrent::setIntParam(&data[5], 12345); bittorrent::setIntParam(&data[9], 256); - bittorrent::setIntParam(&data[13], 1024); + bittorrent::setIntParam(&data[13], 1_k); unsigned char* rawmsg = msg.createMessage(); CPPUNIT_ASSERT(memcmp(rawmsg, data, 17) == 0); delete [] rawmsg; @@ -100,8 +100,8 @@ void BtCancelMessageTest::testCreateMessage() { void BtCancelMessageTest::testDoReceivedAction() { BtCancelMessage msg; msg.setIndex(1); - msg.setBegin(2*16*1024); - msg.setLength(16*1024); + msg.setBegin(32_k); + msg.setLength(16_k); msg.setPeer(peer); auto dispatcher = make_unique(); msg.setBtMessageDispatcher(dispatcher.get()); diff --git a/test/BtChokeMessageTest.cc b/test/BtChokeMessageTest.cc index 85d2dbf6..2980427e 100644 --- a/test/BtChokeMessageTest.cc +++ b/test/BtChokeMessageTest.cc @@ -29,7 +29,7 @@ public: void setUp() { peer.reset(new Peer("host", 6969)); - peer->allocateSessionResource(1024, 1024*1024); + peer->allocateSessionResource(1_k, 1_m); } void testCreate(); diff --git a/test/BtDependencyTest.cc b/test/BtDependencyTest.cc index 84676567..03d377b3 100644 --- a/test/BtDependencyTest.cc +++ b/test/BtDependencyTest.cc @@ -60,7 +60,7 @@ class BtDependencyTest:public CppUnit::TestFixture { std::shared_ptr dependee(new RequestGroup(GroupId::create(), util::copy(option))); std::shared_ptr dctx - (new DownloadContext(1024*1024, length, torrentFile)); + (new DownloadContext(1_m, length, torrentFile)); dependee->setDownloadContext(dctx); dependee->initPieceStorage(); return dependee; diff --git a/test/BtExtendedMessageTest.cc b/test/BtExtendedMessageTest.cc index 642b9a2c..dd6775ab 100644 --- a/test/BtExtendedMessageTest.cc +++ b/test/BtExtendedMessageTest.cc @@ -34,7 +34,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(BtExtendedMessageTest); void BtExtendedMessageTest::testCreate() { auto peer = std::make_shared("192.168.0.1", 6969); - peer->allocateSessionResource(1024, 1024*1024); + peer->allocateSessionResource(1_k, 1_m); auto exmsgFactory = MockExtensionMessageFactory{}; // payload:{4:name3:foo}->11bytes diff --git a/test/BtHaveAllMessageTest.cc b/test/BtHaveAllMessageTest.cc index 5e8987c6..9f3e6c12 100644 --- a/test/BtHaveAllMessageTest.cc +++ b/test/BtHaveAllMessageTest.cc @@ -71,7 +71,7 @@ void BtHaveAllMessageTest::testCreateMessage() { void BtHaveAllMessageTest::testDoReceivedAction() { BtHaveAllMessage msg; std::shared_ptr peer(new Peer("host", 6969)); - peer->allocateSessionResource(16*1024, 256*1024); + peer->allocateSessionResource(16_k, 256_k); peer->setFastExtensionEnabled(true); msg.setPeer(peer); auto pieceStorage = make_unique(); @@ -93,7 +93,7 @@ void BtHaveAllMessageTest::testDoReceivedAction_goodByeSeeder() { BtHaveAllMessage msg; std::shared_ptr peer(new Peer("ip", 6000)); - peer->allocateSessionResource(1024, 1024); + peer->allocateSessionResource(1_k, 1_k); peer->setFastExtensionEnabled(true); msg.setPeer(peer); auto pieceStorage = make_unique(); diff --git a/test/BtHaveMessageTest.cc b/test/BtHaveMessageTest.cc index 9e78ee9f..8b9fbea7 100644 --- a/test/BtHaveMessageTest.cc +++ b/test/BtHaveMessageTest.cc @@ -76,7 +76,7 @@ void BtHaveMessageTest::testCreateMessage() { void BtHaveMessageTest::testDoReceivedAction() { std::shared_ptr peer(new Peer("host", 6969)); - peer->allocateSessionResource(16*1024, 256*1024); + peer->allocateSessionResource(16_k, 256_k); BtHaveMessage msg; msg.setIndex(1); msg.setPeer(peer); @@ -93,7 +93,7 @@ void BtHaveMessageTest::testDoReceivedAction() { void BtHaveMessageTest::testDoReceivedAction_goodByeSeeder() { std::shared_ptr peer(new Peer("ip", 6000)); - peer->allocateSessionResource(1024, 2*1024); + peer->allocateSessionResource(1_k, 2_k); BtHaveMessage msg; msg.setIndex(0); msg.setPeer(peer); diff --git a/test/BtHaveNoneMessageTest.cc b/test/BtHaveNoneMessageTest.cc index 7f049780..6e051f87 100644 --- a/test/BtHaveNoneMessageTest.cc +++ b/test/BtHaveNoneMessageTest.cc @@ -68,7 +68,7 @@ void BtHaveNoneMessageTest::testCreateMessage() { void BtHaveNoneMessageTest::testDoReceivedAction() { BtHaveNoneMessage msg; std::shared_ptr peer(new Peer("host", 6969)); - peer->allocateSessionResource(1024, 1024*1024); + peer->allocateSessionResource(1_k, 1_m); peer->setFastExtensionEnabled(true); msg.setPeer(peer); msg.doReceivedAction(); diff --git a/test/BtInterestedMessageTest.cc b/test/BtInterestedMessageTest.cc index 1dc5e5a7..2731414a 100644 --- a/test/BtInterestedMessageTest.cc +++ b/test/BtInterestedMessageTest.cc @@ -68,7 +68,7 @@ void BtInterestedMessageTest::testCreateMessage() { void BtInterestedMessageTest::testDoReceivedAction() { BtInterestedMessage msg; std::shared_ptr peer(new Peer("host", 6969)); - peer->allocateSessionResource(1024, 1024*1024); + peer->allocateSessionResource(1_k, 1_m); msg.setPeer(peer); auto peerStorage = make_unique(); @@ -88,7 +88,7 @@ void BtInterestedMessageTest::testDoReceivedAction() { void BtInterestedMessageTest::testOnSendComplete() { BtInterestedMessage msg; std::shared_ptr peer(new Peer("host", 6969)); - peer->allocateSessionResource(1024, 1024*1024); + peer->allocateSessionResource(1_k, 1_m); msg.setPeer(peer); CPPUNIT_ASSERT(!peer->amInterested()); std::shared_ptr pu(msg.getProgressUpdate()); diff --git a/test/BtNotInterestedMessageTest.cc b/test/BtNotInterestedMessageTest.cc index 181c5665..15f90276 100644 --- a/test/BtNotInterestedMessageTest.cc +++ b/test/BtNotInterestedMessageTest.cc @@ -67,7 +67,7 @@ void BtNotInterestedMessageTest::testCreateMessage() { void BtNotInterestedMessageTest::testDoReceivedAction() { std::shared_ptr peer(new Peer("host", 6969)); - peer->allocateSessionResource(1024, 1024*1024); + peer->allocateSessionResource(1_k, 1_m); peer->peerInterested(true); auto peerStorage = make_unique(); @@ -88,7 +88,7 @@ void BtNotInterestedMessageTest::testDoReceivedAction() { void BtNotInterestedMessageTest::testOnSendComplete() { std::shared_ptr peer(new Peer("host", 6969)); - peer->allocateSessionResource(1024, 1024*1024); + peer->allocateSessionResource(1_k, 1_m); peer->amInterested(true); BtNotInterestedMessage msg; msg.setPeer(peer); diff --git a/test/BtPieceMessageTest.cc b/test/BtPieceMessageTest.cc index 77ef609f..7c8e952a 100644 --- a/test/BtPieceMessageTest.cc +++ b/test/BtPieceMessageTest.cc @@ -66,7 +66,7 @@ public: std::unique_ptr msg; void setUp() { - dctx_ = make_unique(16*1024, 256*1024, "/path/to/file"); + dctx_ = make_unique(16_k, 256_k, "/path/to/file"); peer = std::make_shared("host", 6969); peer->allocateSessionResource(dctx_->getPieceLength(), @@ -77,8 +77,8 @@ public: msg = make_unique(); msg->setIndex(1); - msg->setBegin(1024); - msg->setBlockLength(16*1024); + msg->setBegin(1_k); + msg->setBlockLength(16_k); msg->setDownloadContext(dctx_.get()); msg->setPeer(peer); msg->setBtMessageDispatcher(btMessageDispatcher.get()); @@ -125,9 +125,9 @@ void BtPieceMessageTest::testCreateMessageHeader() { BtPieceMessage msg; msg.setIndex(12345); msg.setBegin(256); - msg.setBlockLength(1024); + msg.setBlockLength(1_k); unsigned char data[13]; - bittorrent::createPeerMessageString(data, sizeof(data), 9+1024, 7); + bittorrent::createPeerMessageString(data, sizeof(data), 9+1_k, 7); bittorrent::setIntParam(&data[5], 12345); bittorrent::setIntParam(&data[9], 256); unsigned char rawmsg[13]; @@ -160,8 +160,8 @@ void BtPieceMessageTest::testChokingEvent_allowedFastEnabled() { auto rej = static_cast (btMessageDispatcher->messageQueue.front().get()); CPPUNIT_ASSERT_EQUAL((size_t)1, rej->getIndex()); - CPPUNIT_ASSERT_EQUAL((int32_t)1024, rej->getBegin()); - CPPUNIT_ASSERT_EQUAL((int32_t)16*1024, rej->getLength()); + CPPUNIT_ASSERT_EQUAL((int32_t)1_k, rej->getBegin()); + CPPUNIT_ASSERT_EQUAL((int32_t)16_k, rej->getLength()); } void BtPieceMessageTest::testChokingEvent_inAmAllowedIndexSet() { @@ -194,7 +194,7 @@ void BtPieceMessageTest::testCancelSendingPieceEvent() { CPPUNIT_ASSERT(!msg->isInvalidate()); CPPUNIT_ASSERT(!peer->isFastExtensionEnabled()); - msg->onCancelSendingPieceEvent(BtCancelSendingPieceEvent(1, 1024, 16*1024)); + msg->onCancelSendingPieceEvent(BtCancelSendingPieceEvent(1, 1_k, 16_k)); CPPUNIT_ASSERT(msg->isInvalidate()); } @@ -203,15 +203,15 @@ void BtPieceMessageTest::testCancelSendingPieceEvent_noMatch() { CPPUNIT_ASSERT(!msg->isInvalidate()); CPPUNIT_ASSERT(!peer->isFastExtensionEnabled()); - msg->onCancelSendingPieceEvent(BtCancelSendingPieceEvent(0, 1024, 16*1024)); + msg->onCancelSendingPieceEvent(BtCancelSendingPieceEvent(0, 1_k, 16_k)); CPPUNIT_ASSERT(!msg->isInvalidate()); - msg->onCancelSendingPieceEvent(BtCancelSendingPieceEvent(1, 0, 16*1024)); + msg->onCancelSendingPieceEvent(BtCancelSendingPieceEvent(1, 0, 16_k)); CPPUNIT_ASSERT(!msg->isInvalidate()); - msg->onCancelSendingPieceEvent(BtCancelSendingPieceEvent(1, 1024, 0)); + msg->onCancelSendingPieceEvent(BtCancelSendingPieceEvent(1, 1_k, 0)); CPPUNIT_ASSERT(!msg->isInvalidate()); } @@ -221,15 +221,15 @@ void BtPieceMessageTest::testCancelSendingPieceEvent_allowedFastEnabled() { CPPUNIT_ASSERT(!msg->isInvalidate()); CPPUNIT_ASSERT(peer->isFastExtensionEnabled()); - msg->onCancelSendingPieceEvent(BtCancelSendingPieceEvent(1, 1024, 16*1024)); + msg->onCancelSendingPieceEvent(BtCancelSendingPieceEvent(1, 1_k, 16_k)); CPPUNIT_ASSERT(msg->isInvalidate()); CPPUNIT_ASSERT_EQUAL((size_t)1, btMessageDispatcher->messageQueue.size()); auto rej = static_cast (btMessageDispatcher->messageQueue.front().get()); CPPUNIT_ASSERT_EQUAL((size_t)1, rej->getIndex()); - CPPUNIT_ASSERT_EQUAL((int32_t)1024, rej->getBegin()); - CPPUNIT_ASSERT_EQUAL((int32_t)16*1024, rej->getLength()); + CPPUNIT_ASSERT_EQUAL((int32_t)1_k, rej->getBegin()); + CPPUNIT_ASSERT_EQUAL((int32_t)16_k, rej->getLength()); } void BtPieceMessageTest::testCancelSendingPieceEvent_invalidate() { @@ -238,7 +238,7 @@ void BtPieceMessageTest::testCancelSendingPieceEvent_invalidate() { CPPUNIT_ASSERT(msg->isInvalidate()); CPPUNIT_ASSERT(peer->isFastExtensionEnabled()); - msg->onCancelSendingPieceEvent(BtCancelSendingPieceEvent(1, 1024, 16*1024)); + msg->onCancelSendingPieceEvent(BtCancelSendingPieceEvent(1, 1_k, 16_k)); CPPUNIT_ASSERT(msg->isInvalidate()); CPPUNIT_ASSERT_EQUAL((size_t)0, btMessageDispatcher->messageQueue.size()); diff --git a/test/BtPostDownloadHandlerTest.cc b/test/BtPostDownloadHandlerTest.cc index 36a6f6f8..ef27de5b 100644 --- a/test/BtPostDownloadHandlerTest.cc +++ b/test/BtPostDownloadHandlerTest.cc @@ -69,7 +69,7 @@ void BtPostDownloadHandlerTest::testCanHandle_contentType() void BtPostDownloadHandlerTest::testGetNextRequestGroups() { std::shared_ptr dctx - (new DownloadContext(1024, 0, A2_TEST_DIR"/test.torrent")); + (new DownloadContext(1_k, 0, A2_TEST_DIR"/test.torrent")); RequestGroup rg(GroupId::create(), option_); rg.setDownloadContext(dctx); rg.initPieceStorage(); diff --git a/test/BtRejectMessageTest.cc b/test/BtRejectMessageTest.cc index ac700fdf..53004554 100644 --- a/test/BtRejectMessageTest.cc +++ b/test/BtRejectMessageTest.cc @@ -70,7 +70,7 @@ public: void setUp() { peer.reset(new Peer("host", 6969)); - peer->allocateSessionResource(1024, 1024*1024); + peer->allocateSessionResource(1_k, 1_m); dispatcher.reset(new MockBtMessageDispatcher2()); @@ -91,12 +91,12 @@ void BtRejectMessageTest::testCreate() { bittorrent::createPeerMessageString(msg, sizeof(msg), 13, 16); bittorrent::setIntParam(&msg[5], 12345); bittorrent::setIntParam(&msg[9], 256); - bittorrent::setIntParam(&msg[13], 1024); + bittorrent::setIntParam(&msg[13], 1_k); std::shared_ptr pm(BtRejectMessage::create(&msg[4], 13)); CPPUNIT_ASSERT_EQUAL((uint8_t)16, pm->getId()); CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex()); CPPUNIT_ASSERT_EQUAL(256, pm->getBegin()); - CPPUNIT_ASSERT_EQUAL(1024, pm->getLength()); + CPPUNIT_ASSERT_EQUAL((int32_t)1_k, pm->getLength()); // case: payload size is wrong try { @@ -120,12 +120,12 @@ void BtRejectMessageTest::testCreateMessage() { BtRejectMessage msg; msg.setIndex(12345); msg.setBegin(256); - msg.setLength(1024); + msg.setLength(1_k); unsigned char data[17]; bittorrent::createPeerMessageString(data, sizeof(data), 13, 16); bittorrent::setIntParam(&data[5], 12345); bittorrent::setIntParam(&data[9], 256); - bittorrent::setIntParam(&data[13], 1024); + bittorrent::setIntParam(&data[13], 1_k); unsigned char* rawmsg = msg.createMessage(); CPPUNIT_ASSERT(memcmp(rawmsg, data, 17) == 0); delete [] rawmsg; diff --git a/test/BtRequestMessageTest.cc b/test/BtRequestMessageTest.cc index e718d2d8..b1d36101 100644 --- a/test/BtRequestMessageTest.cc +++ b/test/BtRequestMessageTest.cc @@ -87,7 +87,7 @@ public: pieceStorage_ = make_unique(); peer_ = std::make_shared("host", 6969); - peer_->allocateSessionResource(16*1024, 256*1024); + peer_->allocateSessionResource(16_k, 256_k); dispatcher_ = make_unique(); @@ -113,12 +113,12 @@ void BtRequestMessageTest::testCreate() { bittorrent::createPeerMessageString(msg, sizeof(msg), 13, 6); bittorrent::setIntParam(&msg[5], 12345); bittorrent::setIntParam(&msg[9], 256); - bittorrent::setIntParam(&msg[13], 1024); + bittorrent::setIntParam(&msg[13], 1_k); auto pm = BtRequestMessage::create(&msg[4], 13); CPPUNIT_ASSERT_EQUAL((uint8_t)6, pm->getId()); CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex()); CPPUNIT_ASSERT_EQUAL(256, pm->getBegin()); - CPPUNIT_ASSERT_EQUAL(1024, pm->getLength()); + CPPUNIT_ASSERT_EQUAL((int32_t)1_k, pm->getLength()); // case: payload size is wrong try { @@ -142,12 +142,12 @@ void BtRequestMessageTest::testCreateMessage() { BtRequestMessage msg; msg.setIndex(12345); msg.setBegin(256); - msg.setLength(1024); + msg.setLength(1_k); unsigned char data[17]; bittorrent::createPeerMessageString(data, sizeof(data), 13, 6); bittorrent::setIntParam(&data[5], 12345); bittorrent::setIntParam(&data[9], 256); - bittorrent::setIntParam(&data[13], 1024); + bittorrent::setIntParam(&data[13], 1_k); unsigned char* rawmsg = msg.createMessage(); CPPUNIT_ASSERT(memcmp(rawmsg, data, 17) == 0); delete [] rawmsg; @@ -214,21 +214,21 @@ void BtRequestMessageTest::testDoReceivedAction_doesntHavePieceAndFastExtensionD } void BtRequestMessageTest::testHandleAbortRequestEvent() { - auto piece = std::make_shared(1, 16*1024); + auto piece = std::make_shared(1, 16_k); CPPUNIT_ASSERT(!msg->isInvalidate()); msg->onAbortOutstandingRequestEvent(BtAbortOutstandingRequestEvent(piece)); CPPUNIT_ASSERT(msg->isInvalidate()); } void BtRequestMessageTest::testHandleAbortRequestEvent_indexNoMatch() { - auto piece = std::make_shared(2, 16*1024); + auto piece = std::make_shared(2, 16_k); CPPUNIT_ASSERT(!msg->isInvalidate()); msg->onAbortOutstandingRequestEvent(BtAbortOutstandingRequestEvent(piece)); CPPUNIT_ASSERT(!msg->isInvalidate()); } void BtRequestMessageTest::testHandleAbortRequestEvent_alreadyInvalidated() { - auto piece = std::make_shared(1, 16*1024); + auto piece = std::make_shared(1, 16_k); msg->setInvalidate(true); CPPUNIT_ASSERT(msg->isInvalidate()); msg->onAbortOutstandingRequestEvent(BtAbortOutstandingRequestEvent(piece)); @@ -241,16 +241,16 @@ void BtRequestMessageTest::testToString() { } void BtRequestMessageTest::testValidate() { - BtRequestMessage msg(0, 0, 16*1024); + BtRequestMessage msg(0, 0, 16_k); msg.setBtMessageValidator - (make_unique(&msg, 1024, 256*1024)); + (make_unique(&msg, 1_k, 256_k)); msg.validate(); } void BtRequestMessageTest::testValidate_lengthTooLong() { - BtRequestMessage msg(0, 0, 16*1024+1); + BtRequestMessage msg(0, 0, 16_k+1); msg.setBtMessageValidator - (make_unique(&msg, 1024, 256*1024)); + (make_unique(&msg, 1_k, 256_k)); try { msg.validate(); CPPUNIT_FAIL("exception must be thrown."); diff --git a/test/BtUnchokeMessageTest.cc b/test/BtUnchokeMessageTest.cc index c8a92ac7..f2c5be6a 100644 --- a/test/BtUnchokeMessageTest.cc +++ b/test/BtUnchokeMessageTest.cc @@ -68,7 +68,7 @@ void BtUnchokeMessageTest::testCreateMessage() { void BtUnchokeMessageTest::testDoReceivedAction() { std::shared_ptr peer(new Peer("host", 6969)); - peer->allocateSessionResource(1024, 1024*1024); + peer->allocateSessionResource(1_k, 1_m); peer->peerChoking(true); BtUnchokeMessage msg; msg.setPeer(peer); @@ -80,7 +80,7 @@ void BtUnchokeMessageTest::testDoReceivedAction() { void BtUnchokeMessageTest::testOnSendComplete() { std::shared_ptr peer(new Peer("host", 6969)); - peer->allocateSessionResource(1024, 1024*1024); + peer->allocateSessionResource(1_k, 1_m); peer->amChoking(true); BtUnchokeMessage msg; msg.setPeer(peer); diff --git a/test/DefaultBtAnnounceTest.cc b/test/DefaultBtAnnounceTest.cc index 273637f5..6a43cf89 100644 --- a/test/DefaultBtAnnounceTest.cc +++ b/test/DefaultBtAnnounceTest.cc @@ -49,8 +49,8 @@ public: void setUp() { option_ = new Option(); - int64_t totalLength = 4*1024*1024; - int32_t pieceLength = 256*1024; + int64_t totalLength = 4_m; + int32_t pieceLength = 256_k; static const unsigned char infoHash[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, diff --git a/test/DefaultBtMessageDispatcherTest.cc b/test/DefaultBtMessageDispatcherTest.cc index ce792af7..9f52e1ba 100644 --- a/test/DefaultBtMessageDispatcherTest.cc +++ b/test/DefaultBtMessageDispatcherTest.cc @@ -200,7 +200,9 @@ void DefaultBtMessageDispatcherTest::testDoCancelSendingPieceAction() CPPUNIT_ASSERT(evcheck2.doCancelActionCalled); } -int MY_PIECE_LENGTH = 16*1024; +namespace { +int MY_PIECE_LENGTH = 16_k; +} // namespace void DefaultBtMessageDispatcherTest::testCheckRequestSlotAndDoNecessaryThing() { @@ -277,23 +279,23 @@ void DefaultBtMessageDispatcherTest::testIsOutstandingRequest() { } void DefaultBtMessageDispatcherTest::testGetOutstandingRequest() { - btMessageDispatcher->addOutstandingRequest - (make_unique(1, 1024, 16*1024, 10)); + btMessageDispatcher->addOutstandingRequest( + make_unique(1, 1_k, 16_k, 10)); - CPPUNIT_ASSERT(btMessageDispatcher->getOutstandingRequest(1, 1024, 16*1024)); + CPPUNIT_ASSERT(btMessageDispatcher->getOutstandingRequest(1, 1_k, 16_k)); CPPUNIT_ASSERT(!btMessageDispatcher-> - getOutstandingRequest(1, 1024, 17*1024)); + getOutstandingRequest(1, 1_k, 17_k)); CPPUNIT_ASSERT(!btMessageDispatcher-> - getOutstandingRequest(1, 2*1024, 16*1024)); + getOutstandingRequest(1, 2_k, 16_k)); CPPUNIT_ASSERT(!btMessageDispatcher-> - getOutstandingRequest(2, 1024, 16*1024)); + getOutstandingRequest(2, 1_k, 16_k)); } void DefaultBtMessageDispatcherTest::testRemoveOutstandingRequest() { - auto piece = std::make_shared(1, 1024*1024); + auto piece = std::make_shared(1, 1_m); size_t blockIndex = 0; CPPUNIT_ASSERT(piece->getMissingUnusedBlockIndex(blockIndex)); uint32_t begin = blockIndex*piece->getBlockLength(); diff --git a/test/DefaultBtMessageFactoryTest.cc b/test/DefaultBtMessageFactoryTest.cc index d9a14940..ad870c1f 100644 --- a/test/DefaultBtMessageFactoryTest.cc +++ b/test/DefaultBtMessageFactoryTest.cc @@ -34,7 +34,7 @@ public: dctx_ = make_unique(); peer_ = std::make_shared("192.168.0.1", 6969); - peer_->allocateSessionResource(1024, 1024*1024); + peer_->allocateSessionResource(1_k, 1_m); peer_->setExtendedMessagingEnabled(true); exmsgFactory_ = std::make_shared(); diff --git a/test/DefaultBtProgressInfoFileTest.cc b/test/DefaultBtProgressInfoFileTest.cc index 631ba149..3498b089 100644 --- a/test/DefaultBtProgressInfoFileTest.cc +++ b/test/DefaultBtProgressInfoFileTest.cc @@ -113,7 +113,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(DefaultBtProgressInfoFileTest); #ifndef WORDS_BIGENDIAN void DefaultBtProgressInfoFileTest::testLoad_compat() { - initializeMembers(1024, 81920); + initializeMembers(1_k, 80_k); dctx_->setBasePath(A2_TEST_DIR"/load"); DefaultBtProgressInfoFile infoFile(dctx_, pieceStorage_, option_.get()); @@ -128,10 +128,10 @@ void DefaultBtProgressInfoFileTest::testLoad_compat() // check the contents of objects // total length - CPPUNIT_ASSERT_EQUAL((int64_t)81920, dctx_->getTotalLength()); + CPPUNIT_ASSERT_EQUAL((int64_t)80_k, dctx_->getTotalLength()); // upload length - CPPUNIT_ASSERT_EQUAL((int64_t)1024, btRuntime_->getUploadLengthAtStartup()); + CPPUNIT_ASSERT_EQUAL((int64_t)1_k, btRuntime_->getUploadLengthAtStartup()); // bitfield CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffe"), @@ -148,7 +148,7 @@ void DefaultBtProgressInfoFileTest::testLoad_compat() std::shared_ptr piece1 = inFlightPieces[0]; CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getIndex()); - CPPUNIT_ASSERT_EQUAL((int64_t)1024, piece1->getLength()); + CPPUNIT_ASSERT_EQUAL((int64_t)1_k, piece1->getLength()); CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getBitfieldLength()); CPPUNIT_ASSERT_EQUAL(std::string("00"), util::toHex(piece1->getBitfield(), piece1->getBitfieldLength())); @@ -162,7 +162,7 @@ void DefaultBtProgressInfoFileTest::testLoad_compat() void DefaultBtProgressInfoFileTest::testLoad() { - initializeMembers(1024, 81920); + initializeMembers(1_k, 80_k); dctx_->setBasePath(A2_TEST_DIR"/load-v0001"); @@ -177,10 +177,10 @@ void DefaultBtProgressInfoFileTest::testLoad() // check the contents of objects // total length - CPPUNIT_ASSERT_EQUAL((int64_t)81920, dctx_->getTotalLength()); + CPPUNIT_ASSERT_EQUAL((int64_t)80_k, dctx_->getTotalLength()); // upload length - CPPUNIT_ASSERT_EQUAL((int64_t)1024, btRuntime_->getUploadLengthAtStartup()); + CPPUNIT_ASSERT_EQUAL((int64_t)1_k, btRuntime_->getUploadLengthAtStartup()); // bitfield CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffe"), @@ -197,7 +197,7 @@ void DefaultBtProgressInfoFileTest::testLoad() std::shared_ptr piece1 = inFlightPieces[0]; CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getIndex()); - CPPUNIT_ASSERT_EQUAL((int64_t)1024, piece1->getLength()); + CPPUNIT_ASSERT_EQUAL((int64_t)1_k, piece1->getLength()); CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getBitfieldLength()); CPPUNIT_ASSERT_EQUAL(std::string("00"), util::toHex(piece1->getBitfield(), piece1->getBitfieldLength())); @@ -210,7 +210,7 @@ void DefaultBtProgressInfoFileTest::testLoad() void DefaultBtProgressInfoFileTest::testSave() { - initializeMembers(1024, 81920); + initializeMembers(1_k, 80_k); dctx_->setBasePath(A2_TEST_OUT_DIR"/save-temp"); dctx_->getNetStat().updateUploadLength(768); @@ -219,7 +219,7 @@ void DefaultBtProgressInfoFileTest::testSave() bitfield_->unsetBit(79); pieceStorage_->setCompletedLength(80896); - std::shared_ptr p1(new Piece(1, 1024)); + std::shared_ptr p1(new Piece(1, 1_k)); std::shared_ptr p2(new Piece(2, 512)); std::vector > inFlightPieces; inFlightPieces.push_back(p1); @@ -263,17 +263,17 @@ void DefaultBtProgressInfoFileTest::testSave() uint32_t pieceLength; in.read((char*)&pieceLength, sizeof(pieceLength)); pieceLength = ntohl(pieceLength); - CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength); + CPPUNIT_ASSERT_EQUAL((uint32_t)1_k, pieceLength); uint64_t totalLength; in.read((char*)&totalLength, sizeof(totalLength)); totalLength = ntoh64(totalLength); - CPPUNIT_ASSERT_EQUAL((uint64_t)81920/* 80*1024 */, totalLength); + CPPUNIT_ASSERT_EQUAL((uint64_t)80_k, totalLength); uint64_t uploadLength; in.read((char*)&uploadLength, sizeof(uploadLength)); uploadLength = ntoh64(uploadLength); - CPPUNIT_ASSERT_EQUAL((uint64_t)1024, uploadLength); + CPPUNIT_ASSERT_EQUAL((uint64_t)1_k, uploadLength); uint32_t bitfieldLength; in.read((char*)&bitfieldLength, sizeof(bitfieldLength)); @@ -299,7 +299,7 @@ void DefaultBtProgressInfoFileTest::testSave() uint32_t pieceLength1; in.read((char*)&pieceLength1, sizeof(pieceLength1)); pieceLength1 = ntohl(pieceLength1); - CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength1); + CPPUNIT_ASSERT_EQUAL((uint32_t)1_k, pieceLength1); uint32_t pieceBitfieldLength1; in.read((char*)&pieceBitfieldLength1, sizeof(pieceBitfieldLength1)); @@ -330,10 +330,10 @@ void DefaultBtProgressInfoFileTest::testSave() #ifndef WORDS_BIGENDIAN void DefaultBtProgressInfoFileTest::testLoad_nonBt_compat() { - initializeMembers(1024, 81920); + initializeMembers(1_k, 80_k); std::shared_ptr dctx - (new DownloadContext(1024, 81920, A2_TEST_DIR"/load-nonBt")); + (new DownloadContext(1_k, 80_k, A2_TEST_DIR"/load-nonBt")); DefaultBtProgressInfoFile infoFile(dctx, pieceStorage_, option_.get()); @@ -344,7 +344,7 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt_compat() // check the contents of objects // total length - CPPUNIT_ASSERT_EQUAL((int64_t)81920, dctx->getTotalLength()); + CPPUNIT_ASSERT_EQUAL((int64_t)80_k, dctx->getTotalLength()); // bitfield CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffe"), @@ -361,7 +361,7 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt_compat() std::shared_ptr piece1 = inFlightPieces[0]; CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getIndex()); - CPPUNIT_ASSERT_EQUAL((int64_t)1024, piece1->getLength()); + CPPUNIT_ASSERT_EQUAL((int64_t)1_k, piece1->getLength()); CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getBitfieldLength()); CPPUNIT_ASSERT_EQUAL(std::string("00"), util::toHex(piece1->getBitfield(), piece1->getBitfieldLength())); @@ -375,10 +375,10 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt_compat() void DefaultBtProgressInfoFileTest::testLoad_nonBt() { - initializeMembers(1024, 81920); + initializeMembers(1_k, 80_k); std::shared_ptr dctx - (new DownloadContext(1024, 81920, A2_TEST_DIR"/load-nonBt-v0001")); + (new DownloadContext(1_k, 80_k, A2_TEST_DIR"/load-nonBt-v0001")); DefaultBtProgressInfoFile infoFile(dctx, pieceStorage_, option_.get()); @@ -389,7 +389,7 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt() // check the contents of objects // total length - CPPUNIT_ASSERT_EQUAL((int64_t)81920, dctx->getTotalLength()); + CPPUNIT_ASSERT_EQUAL((int64_t)80_k, dctx->getTotalLength()); // bitfield CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffe"), @@ -406,7 +406,7 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt() std::shared_ptr piece1 = inFlightPieces[0]; CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getIndex()); - CPPUNIT_ASSERT_EQUAL((int64_t)1024, piece1->getLength()); + CPPUNIT_ASSERT_EQUAL((int64_t)1_k, piece1->getLength()); CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getBitfieldLength()); CPPUNIT_ASSERT_EQUAL(std::string("00"), util::toHex(piece1->getBitfield(), piece1->getBitfieldLength())); @@ -419,11 +419,11 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt() void DefaultBtProgressInfoFileTest::testLoad_nonBt_pieceLengthShorter() { - initializeMembers(512, 81920); + initializeMembers(512, 80_k); option_->put(PREF_ALLOW_PIECE_LENGTH_CHANGE, A2_V_TRUE); std::shared_ptr dctx - (new DownloadContext(512, 81920, A2_TEST_DIR"/load-nonBt-v0001")); + (new DownloadContext(512, 80_k, A2_TEST_DIR"/load-nonBt-v0001")); DefaultBtProgressInfoFile infoFile(dctx, pieceStorage_, option_.get()); @@ -445,16 +445,16 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt_pieceLengthShorter() void DefaultBtProgressInfoFileTest::testSave_nonBt() { - initializeMembers(1024, 81920); + initializeMembers(1_k, 80_k); std::shared_ptr dctx - (new DownloadContext(1024, 81920, A2_TEST_OUT_DIR"/save-temp")); + (new DownloadContext(1_k, 80_k, A2_TEST_OUT_DIR"/save-temp")); bitfield_->setAllBit(); bitfield_->unsetBit(79); pieceStorage_->setCompletedLength(80896); - std::shared_ptr p1(new Piece(1, 1024)); + std::shared_ptr p1(new Piece(1, 1_k)); std::shared_ptr p2(new Piece(2, 512)); std::vector > inFlightPieces; inFlightPieces.push_back(p1); @@ -491,12 +491,12 @@ void DefaultBtProgressInfoFileTest::testSave_nonBt() uint32_t pieceLength; in.read((char*)&pieceLength, sizeof(pieceLength)); pieceLength = ntohl(pieceLength); - CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength); + CPPUNIT_ASSERT_EQUAL((uint32_t)1_k, pieceLength); uint64_t totalLength; in.read((char*)&totalLength, sizeof(totalLength)); totalLength = ntoh64(totalLength); - CPPUNIT_ASSERT_EQUAL((uint64_t)81920/* 80*1024 */, totalLength); + CPPUNIT_ASSERT_EQUAL((uint64_t)80_k, totalLength); uint64_t uploadLength; in.read((char*)&uploadLength, sizeof(uploadLength)); @@ -527,7 +527,7 @@ void DefaultBtProgressInfoFileTest::testSave_nonBt() uint32_t pieceLength1; in.read((char*)&pieceLength1, sizeof(pieceLength1)); pieceLength1 = ntohl(pieceLength1); - CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength1); + CPPUNIT_ASSERT_EQUAL((uint32_t)1_k, pieceLength1); uint32_t pieceBitfieldLength1; in.read((char*)&pieceBitfieldLength1, sizeof(pieceBitfieldLength1)); @@ -555,7 +555,7 @@ void DefaultBtProgressInfoFileTest::testSave_nonBt() void DefaultBtProgressInfoFileTest::testUpdateFilename() { std::shared_ptr dctx - (new DownloadContext(1024, 81920, A2_TEST_DIR"/file1")); + (new DownloadContext(1_k, 80_k, A2_TEST_DIR"/file1")); DefaultBtProgressInfoFile infoFile(dctx, std::shared_ptr(), nullptr); #ifdef ENABLE_BITTORRENT diff --git a/test/DefaultBtRequestFactoryTest.cc b/test/DefaultBtRequestFactoryTest.cc index fda9cb3a..4b9d6114 100644 --- a/test/DefaultBtRequestFactoryTest.cc +++ b/test/DefaultBtRequestFactoryTest.cc @@ -100,12 +100,12 @@ CPPUNIT_TEST_SUITE_REGISTRATION(DefaultBtRequestFactoryTest); void DefaultBtRequestFactoryTest::testAddTargetPiece() { { - auto piece = std::make_shared(0, 16*1024*10); + auto piece = std::make_shared(0, 160_k); requestFactory_->addTargetPiece(piece); CPPUNIT_ASSERT_EQUAL((size_t)1, requestFactory_->countTargetPiece()); } { - auto piece = std::make_shared(1, 16*1024*9); + auto piece = std::make_shared(1, 16_k * 9); piece->completeBlock(0); requestFactory_->addTargetPiece(piece); CPPUNIT_ASSERT_EQUAL((size_t)2, requestFactory_->countTargetPiece()); @@ -115,8 +115,8 @@ void DefaultBtRequestFactoryTest::testAddTargetPiece() void DefaultBtRequestFactoryTest::testRemoveCompletedPiece() { - auto piece1 = std::make_shared(0, 16*1024); - auto piece2 = std::make_shared(1, 16*1024); + auto piece1 = std::make_shared(0, 16_k); + auto piece2 = std::make_shared(1, 16_k); piece2->setAllBlock(); requestFactory_->addTargetPiece(piece1); requestFactory_->addTargetPiece(piece2); @@ -129,7 +129,7 @@ void DefaultBtRequestFactoryTest::testRemoveCompletedPiece() void DefaultBtRequestFactoryTest::testCreateRequestMessages() { - int PIECE_LENGTH = 16*1024*2; + constexpr int PIECE_LENGTH = 32_k; auto piece1 = std::make_shared(0, PIECE_LENGTH); auto piece2 = std::make_shared(1, PIECE_LENGTH); requestFactory_->addTargetPiece(piece1); @@ -160,7 +160,7 @@ void DefaultBtRequestFactoryTest::testCreateRequestMessages_onEndGame() requestFactory_->setBtMessageDispatcher(dispatcher.get()); - int PIECE_LENGTH = 16*1024*2; + constexpr int PIECE_LENGTH = 32_k; auto piece1 = std::make_shared(0, PIECE_LENGTH); auto piece2 = std::make_shared(1, PIECE_LENGTH); requestFactory_->addTargetPiece(piece1); @@ -183,7 +183,7 @@ void DefaultBtRequestFactoryTest::testCreateRequestMessages_onEndGame() void DefaultBtRequestFactoryTest::testRemoveTargetPiece() { - auto piece1 = std::make_shared(0, 16*1024); + auto piece1 = std::make_shared(0, 16_k); requestFactory_->addTargetPiece(piece1); @@ -202,9 +202,9 @@ void DefaultBtRequestFactoryTest::testRemoveTargetPiece() void DefaultBtRequestFactoryTest::testGetTargetPieceIndexes() { - auto piece1 = std::make_shared(1, 16*1024); - auto piece3 = std::make_shared(3, 16*1024); - auto piece5 = std::make_shared(5, 16*1024); + auto piece1 = std::make_shared(1, 16_k); + auto piece3 = std::make_shared(3, 16_k); + auto piece5 = std::make_shared(5, 16_k); requestFactory_->addTargetPiece(piece3); requestFactory_->addTargetPiece(piece1); diff --git a/test/DefaultDiskWriterTest.cc b/test/DefaultDiskWriterTest.cc index 8f2d8b2d..641c7a51 100644 --- a/test/DefaultDiskWriterTest.cc +++ b/test/DefaultDiskWriterTest.cc @@ -1,6 +1,8 @@ #include "DefaultDiskWriter.h" #include +#include "a2functional.h" + namespace aria2 { class DefaultDiskWriterTest:public CppUnit::TestFixture { @@ -25,7 +27,7 @@ void DefaultDiskWriterTest::testSize() DefaultDiskWriter dw(A2_TEST_DIR"/4096chunk.txt"); dw.enableReadOnly(); dw.openExistingFile(); - CPPUNIT_ASSERT_EQUAL((int64_t)4096LL, dw.size()); + CPPUNIT_ASSERT_EQUAL((int64_t)4_k, dw.size()); } } // namespace aria2 diff --git a/test/DefaultExtensionMessageFactoryTest.cc b/test/DefaultExtensionMessageFactoryTest.cc index d5fe00a3..bbd798a8 100644 --- a/test/DefaultExtensionMessageFactoryTest.cc +++ b/test/DefaultExtensionMessageFactoryTest.cc @@ -52,7 +52,7 @@ public: peerStorage_ = make_unique(); peer_ = std::make_shared("192.168.0.1", 6969); - peer_->allocateSessionResource(1024, 1024*1024); + peer_->allocateSessionResource(1_k, 1_m); peer_->setExtension(ExtensionMessageRegistry::UT_PEX, 1); registry_ = make_unique(); diff --git a/test/DefaultPeerStorageTest.cc b/test/DefaultPeerStorageTest.cc index 6d6f15c7..f696747a 100644 --- a/test/DefaultPeerStorageTest.cc +++ b/test/DefaultPeerStorageTest.cc @@ -157,9 +157,9 @@ void DefaultPeerStorageTest::testReturnPeer() DefaultPeerStorage ps; std::shared_ptr peer1(new Peer("192.168.0.1", 0)); - peer1->allocateSessionResource(1024*1024, 1024*1024*10); + peer1->allocateSessionResource(1_m, 10_m); std::shared_ptr peer2(new Peer("192.168.0.2", 6889)); - peer2->allocateSessionResource(1024*1024, 1024*1024*10); + peer2->allocateSessionResource(1_m, 10_m); std::shared_ptr peer3(new Peer("192.168.0.1", 6889)); peer2->setDisconnectedGracefully(true); ps.addPeer(peer1); diff --git a/test/DefaultPieceStorageTest.cc b/test/DefaultPieceStorageTest.cc index 0329b464..57973666 100644 --- a/test/DefaultPieceStorageTest.cc +++ b/test/DefaultPieceStorageTest.cc @@ -265,7 +265,7 @@ void DefaultPieceStorageTest::testGetPieceCompletedPiece() { void DefaultPieceStorageTest::testCancelPiece() { - size_t pieceLength = 256*1024; + size_t pieceLength = 256_k; int64_t totalLength = 32*pieceLength; // <-- make the number of piece greater than END_GAME_PIECE_NUM std::deque uris1; uris1.push_back("http://localhost/src/file1.txt"); @@ -291,13 +291,13 @@ void DefaultPieceStorageTest::testCancelPiece() void DefaultPieceStorageTest::testMarkPiecesDone() { - size_t pieceLength = 256*1024; - int64_t totalLength = 4*1024*1024; + size_t pieceLength = 256_k; + int64_t totalLength = 4_m; auto dctx =std::make_shared(pieceLength, totalLength); DefaultPieceStorage ps(dctx, option_.get()); - ps.markPiecesDone(pieceLength*10+16*1024*2+1); + ps.markPiecesDone(pieceLength * 10 + 32_k + 1); for(size_t i = 0; i < 10; ++i) { CPPUNIT_ASSERT(ps.hasPiece(i)); @@ -305,7 +305,7 @@ void DefaultPieceStorageTest::testMarkPiecesDone() for(size_t i = 10; i < (totalLength+pieceLength-1)/pieceLength; ++i) { CPPUNIT_ASSERT(!ps.hasPiece(i)); } - CPPUNIT_ASSERT_EQUAL((int64_t)pieceLength*10+16*1024*2, + CPPUNIT_ASSERT_EQUAL((int64_t)pieceLength * 10 + (int64_t)32_k, ps.getCompletedLength()); ps.markPiecesDone(totalLength); @@ -320,36 +320,36 @@ void DefaultPieceStorageTest::testMarkPiecesDone() void DefaultPieceStorageTest::testGetCompletedLength() { - auto dctx = std::make_shared(1024*1024, 256*1024*1024); + auto dctx = std::make_shared(1_m, 256_m); DefaultPieceStorage ps(dctx, option_.get()); CPPUNIT_ASSERT_EQUAL((int64_t)0, ps.getCompletedLength()); - ps.markPiecesDone(250*1024*1024); - CPPUNIT_ASSERT_EQUAL((int64_t)250*1024*1024, ps.getCompletedLength()); + ps.markPiecesDone(250_m); + CPPUNIT_ASSERT_EQUAL((int64_t)250_m, ps.getCompletedLength()); std::vector> inFlightPieces; for(int i = 0; i < 2; ++i) { - auto p = std::make_shared(250+i, 1024*1024); + auto p = std::make_shared(250+i, 1_m); for(int j = 0; j < 32; ++j) { p->completeBlock(j); } inFlightPieces.push_back(p); - CPPUNIT_ASSERT_EQUAL((int64_t)512*1024, p->getCompletedLength()); + CPPUNIT_ASSERT_EQUAL((int64_t)512_k, p->getCompletedLength()); } ps.addInFlightPiece(inFlightPieces); - CPPUNIT_ASSERT_EQUAL((int64_t)251*1024*1024, ps.getCompletedLength()); + CPPUNIT_ASSERT_EQUAL((int64_t)251_m, ps.getCompletedLength()); - ps.markPiecesDone(256*1024*1024); + ps.markPiecesDone(256_m); - CPPUNIT_ASSERT_EQUAL((int64_t)256*1024*1024, ps.getCompletedLength()); + CPPUNIT_ASSERT_EQUAL((int64_t)256_m, ps.getCompletedLength()); } void DefaultPieceStorageTest::testGetFilteredCompletedLength() { - const size_t pieceLength = 1024*1024; + const size_t pieceLength = 1_m; auto dctx = std::make_shared(); dctx->setPieceLength(pieceLength); auto files = std::vector>{ @@ -373,7 +373,7 @@ void DefaultPieceStorageTest::testGetFilteredCompletedLength() auto piece = ps.getMissingPiece(0, 1); ps.completePiece(piece); - CPPUNIT_ASSERT_EQUAL((int64_t)pieceLength+16*1024, + CPPUNIT_ASSERT_EQUAL((int64_t)pieceLength+(int64_t)16_k, ps.getFilteredCompletedLength()); } diff --git a/test/DirectDiskAdaptorTest.cc b/test/DirectDiskAdaptorTest.cc index a9aad1ad..b99fbb7b 100644 --- a/test/DirectDiskAdaptorTest.cc +++ b/test/DirectDiskAdaptorTest.cc @@ -60,7 +60,7 @@ void DirectDiskAdaptorTest::testWriteCache() adaptor->setDiskWriter(std::move(sdw)); } WrDiskCacheEntry cache{adaptor}; - std::string data1(4096, '1'), data2(4094, '2'); + std::string data1(4_k, '1'), data2(4094, '2'); cache.cacheData(createDataCell(5, data1.c_str())); cache.cacheData(createDataCell(5+data1.size(), data2.c_str())); adaptor->writeCache(&cache); @@ -68,9 +68,9 @@ void DirectDiskAdaptorTest::testWriteCache() cache.clear(); dw->setString(""); - cache.cacheData(createDataCell(4096, data1.c_str())); + cache.cacheData(createDataCell(4_k, data1.c_str())); adaptor->writeCache(&cache); - CPPUNIT_ASSERT_EQUAL(data1, dw->getString().substr(4096)); + CPPUNIT_ASSERT_EQUAL(data1, dw->getString().substr(4_k)); cache.clear(); dw->setString("???????"); diff --git a/test/FallocFileAllocationIteratorTest.cc b/test/FallocFileAllocationIteratorTest.cc index baa18686..14dfc6e8 100644 --- a/test/FallocFileAllocationIteratorTest.cc +++ b/test/FallocFileAllocationIteratorTest.cc @@ -39,7 +39,7 @@ void FallocFileAllocationIteratorTest::testAllocate() DefaultDiskWriter writer(fn); int64_t offset = 10; - int64_t totalLength = 40960; + int64_t totalLength = 40_k; // we have to open file first. writer.openExistingFile(); @@ -48,7 +48,7 @@ void FallocFileAllocationIteratorTest::testAllocate() itr.allocateChunk(); CPPUNIT_ASSERT(itr.finished()); - CPPUNIT_ASSERT_EQUAL((int64_t)40960, f.size()); + CPPUNIT_ASSERT_EQUAL((int64_t)40_k, f.size()); #endif // !HAVE_FALLOCATE } diff --git a/test/FileTest.cc b/test/FileTest.cc index 5125dba6..eea7daea 100644 --- a/test/FileTest.cc +++ b/test/FileTest.cc @@ -110,7 +110,7 @@ void FileTest::testRemove() { void FileTest::testSize() { File f(A2_TEST_DIR"/4096chunk.txt"); - CPPUNIT_ASSERT_EQUAL(4096, (int)f.size()); + CPPUNIT_ASSERT_EQUAL((int64_t)4_k, f.size()); } void FileTest::testMkdir() { diff --git a/test/FtpConnectionTest.cc b/test/FtpConnectionTest.cc index ace44482..230c7334 100644 --- a/test/FtpConnectionTest.cc +++ b/test/FtpConnectionTest.cc @@ -206,7 +206,7 @@ void FtpConnectionTest::testReceiveMdtmResponse() void FtpConnectionTest::testReceiveResponse_overflow() { - char data[1024]; + char data[1_k]; memset(data, 0, sizeof(data)); memcpy(data, "213 ", 4); for(int i = 0; i < 64; ++i) { diff --git a/test/GZipDecoder.h b/test/GZipDecoder.h index eacb83f2..f3d552c7 100644 --- a/test/GZipDecoder.h +++ b/test/GZipDecoder.h @@ -41,6 +41,8 @@ #include +#include "a2functional.h" + namespace aria2 { // GZipDecoder can decode both gzip and deflate format. @@ -50,7 +52,7 @@ private: bool finished_; - static const size_t OUTBUF_LENGTH = 16*1024; + static const size_t OUTBUF_LENGTH = 16_k; static const std::string NAME; public: diff --git a/test/GZipDecoderTest.cc b/test/GZipDecoderTest.cc index f6451cf1..1d969251 100644 --- a/test/GZipDecoderTest.cc +++ b/test/GZipDecoderTest.cc @@ -35,7 +35,7 @@ void GZipDecoderTest::testDecode() std::string outfile(A2_TEST_OUT_DIR"/aria2_GZipDecoderTest_testDecode"); - char buf[4096]; + char buf[4_k]; std::ifstream in(A2_TEST_DIR"/gzip_decode_test.gz", std::ios::binary); std::ofstream out(outfile.c_str(), std::ios::binary); while(in) { diff --git a/test/GZipDecodingStreamFilterTest.cc b/test/GZipDecodingStreamFilterTest.cc index 95713399..c430ae9c 100644 --- a/test/GZipDecodingStreamFilterTest.cc +++ b/test/GZipDecodingStreamFilterTest.cc @@ -61,7 +61,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(GZipDecodingStreamFilterTest); void GZipDecodingStreamFilterTest::testTransform() { - unsigned char buf[4096]; + unsigned char buf[4_k]; std::ifstream in(A2_TEST_DIR"/gzip_decode_test.gz", std::ios::binary); while(in) { in.read(reinterpret_cast(buf), sizeof(buf)); diff --git a/test/GeomStreamPieceSelectorTest.cc b/test/GeomStreamPieceSelectorTest.cc index 13de0611..35212a70 100644 --- a/test/GeomStreamPieceSelectorTest.cc +++ b/test/GeomStreamPieceSelectorTest.cc @@ -23,7 +23,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(GeomStreamPieceSelectorTest); void GeomStreamPieceSelectorTest::testOnBitfieldInit() { - BitfieldMan bf(1024, 1024*20); + BitfieldMan bf(1_k, 20_k); bf.setBitRange(0, 10); GeomStreamPieceSelector sel(&bf, 2); sel.onBitfieldInit(); @@ -31,19 +31,19 @@ void GeomStreamPieceSelectorTest::testOnBitfieldInit() memset(igbf, 0, 3); size_t index; // 11111|11111|00000|00000 - CPPUNIT_ASSERT(sel.select(index, 1024*20, igbf, sizeof(igbf))); + CPPUNIT_ASSERT(sel.select(index, 20_k, igbf, sizeof(igbf))); CPPUNIT_ASSERT_EQUAL((size_t)11, index); bf.setUseBit(11); // 11111|11111|10000|00000 - CPPUNIT_ASSERT(sel.select(index, 1024*20, igbf, sizeof(igbf))); + CPPUNIT_ASSERT(sel.select(index, 20_k, igbf, sizeof(igbf))); CPPUNIT_ASSERT_EQUAL((size_t)12, index); bf.setUseBit(12); // 11111|11111|11000|00000 - CPPUNIT_ASSERT(sel.select(index, 1024*20, igbf, sizeof(igbf))); + CPPUNIT_ASSERT(sel.select(index, 20_k, igbf, sizeof(igbf))); CPPUNIT_ASSERT_EQUAL((size_t)13, index); bf.setUseBit(13); // 11111|11111|11100|00000 - CPPUNIT_ASSERT(sel.select(index, 1024*20, igbf, sizeof(igbf))); + CPPUNIT_ASSERT(sel.select(index, 20_k, igbf, sizeof(igbf))); CPPUNIT_ASSERT_EQUAL((size_t)15, index); } diff --git a/test/GrowSegmentTest.cc b/test/GrowSegmentTest.cc index b71689e5..2d895ba4 100644 --- a/test/GrowSegmentTest.cc +++ b/test/GrowSegmentTest.cc @@ -25,9 +25,9 @@ CPPUNIT_TEST_SUITE_REGISTRATION( GrowSegmentTest ); void GrowSegmentTest::testUpdateWrittenLength() { GrowSegment segment(std::shared_ptr(new Piece())); - segment.updateWrittenLength(32*1024); + segment.updateWrittenLength(32_k); - CPPUNIT_ASSERT_EQUAL((int64_t)32*1024, segment.getPositionToWrite()); + CPPUNIT_ASSERT_EQUAL((int64_t)32_k, segment.getPositionToWrite()); CPPUNIT_ASSERT(!segment.complete()); CPPUNIT_ASSERT(segment.getPiece()->pieceComplete()); } @@ -35,8 +35,8 @@ void GrowSegmentTest::testUpdateWrittenLength() void GrowSegmentTest::testClear() { GrowSegment segment(std::shared_ptr(new Piece())); - segment.updateWrittenLength(32*1024); - CPPUNIT_ASSERT_EQUAL((int64_t)32*1024, segment.getWrittenLength()); + segment.updateWrittenLength(32_k); + CPPUNIT_ASSERT_EQUAL((int64_t)32_k, segment.getWrittenLength()); segment.clear(nullptr); CPPUNIT_ASSERT_EQUAL((int64_t)0, segment.getWrittenLength()); } diff --git a/test/HandshakeExtensionMessageTest.cc b/test/HandshakeExtensionMessageTest.cc index 8a4d35e6..323e6874 100644 --- a/test/HandshakeExtensionMessageTest.cc +++ b/test/HandshakeExtensionMessageTest.cc @@ -62,7 +62,7 @@ void HandshakeExtensionMessageTest::testGetBencodedData() msg.setTCPPort(6889); msg.setExtension(ExtensionMessageRegistry::UT_PEX, 1); msg.setExtension(ExtensionMessageRegistry::UT_METADATA, 2); - msg.setMetadataSize(1024); + msg.setMetadataSize(1_k); CPPUNIT_ASSERT_EQUAL (std::string("d" "1:md11:ut_metadatai2e6:ut_pexi1ee" @@ -83,7 +83,7 @@ void HandshakeExtensionMessageTest::testToString() msg.setTCPPort(6889); msg.setExtension(ExtensionMessageRegistry::UT_PEX, 1); msg.setExtension(ExtensionMessageRegistry::UT_METADATA, 2); - msg.setMetadataSize(1024); + msg.setMetadataSize(1_k); CPPUNIT_ASSERT_EQUAL (std::string("handshake client=aria2, tcpPort=6889, metadataSize=1024," " ut_metadata=2, ut_pex=1"), msg.toString()); @@ -100,13 +100,13 @@ void HandshakeExtensionMessageTest::testDoReceivedAction() dctx->markTotalLengthIsUnknown(); auto peer = std::make_shared("192.168.0.1", 0); - peer->allocateSessionResource(1024, 1024*1024); + peer->allocateSessionResource(1_k, 1_m); HandshakeExtensionMessage msg; msg.setClientVersion("aria2"); msg.setTCPPort(6889); msg.setExtension(ExtensionMessageRegistry::UT_PEX, 1); msg.setExtension(ExtensionMessageRegistry::UT_METADATA, 3); - msg.setMetadataSize(1024); + msg.setMetadataSize(1_k); msg.setPeer(peer); msg.setDownloadContext(dctx.get()); @@ -121,13 +121,13 @@ void HandshakeExtensionMessageTest::testDoReceivedAction() (ExtensionMessageRegistry::UT_METADATA)); CPPUNIT_ASSERT(peer->isSeeder()); auto attrs = bittorrent::getTorrentAttrs(dctx); - CPPUNIT_ASSERT_EQUAL((size_t)1024, attrs->metadataSize); - CPPUNIT_ASSERT_EQUAL((int64_t)1024, dctx->getTotalLength()); + CPPUNIT_ASSERT_EQUAL((size_t)1_k, attrs->metadataSize); + CPPUNIT_ASSERT_EQUAL((int64_t)1_k, dctx->getTotalLength()); CPPUNIT_ASSERT(dctx->knowsTotalLength()); // See Peer is not marked as seeder if !attrs->metadata.empty() - peer->allocateSessionResource(1024, 1024*1024); - attrs->metadataSize = 1024; + peer->allocateSessionResource(1_k, 1_m); + attrs->metadataSize = 1_k; attrs->metadata = std::string('0', attrs->metadataSize); msg.doReceivedAction(); CPPUNIT_ASSERT(!peer->isSeeder()); @@ -146,7 +146,7 @@ void HandshakeExtensionMessageTest::testCreate() CPPUNIT_ASSERT_EQUAL((uint8_t)1, m->getExtensionMessageID (ExtensionMessageRegistry::UT_PEX)); - CPPUNIT_ASSERT_EQUAL((size_t)1024, m->getMetadataSize()); + CPPUNIT_ASSERT_EQUAL((size_t)1_k, m->getMetadataSize()); try { // bad payload format std::string in = "011:hello world"; diff --git a/test/HttpRequestTest.cc b/test/HttpRequestTest.cc index 6d93d4ae..273f6825 100644 --- a/test/HttpRequestTest.cc +++ b/test/HttpRequestTest.cc @@ -74,23 +74,23 @@ CPPUNIT_TEST_SUITE_REGISTRATION( HttpRequestTest ); void HttpRequestTest::testGetStartByte() { HttpRequest httpRequest; - auto p = std::make_shared(1, 1024); - auto segment = std::make_shared(1024, p); - auto fileEntry = std::make_shared("file", 1024*10, 0); + auto p = std::make_shared(1, 1_k); + auto segment = std::make_shared(1_k, p); + auto fileEntry = std::make_shared("file", 10_k, 0); CPPUNIT_ASSERT_EQUAL((int64_t)0LL, httpRequest.getStartByte()); httpRequest.setSegment(segment); httpRequest.setFileEntry(fileEntry); - CPPUNIT_ASSERT_EQUAL((int64_t)1024LL, httpRequest.getStartByte()); + CPPUNIT_ASSERT_EQUAL((int64_t)1_k, httpRequest.getStartByte()); } void HttpRequestTest::testGetEndByte() { size_t index = 1; - size_t length = 1024*1024-1024; - size_t segmentLength = 1024*1024; + size_t length = 1_m-1_k; + size_t segmentLength = 1_m; HttpRequest httpRequest; auto piece = std::make_shared(index, length); @@ -130,9 +130,9 @@ void HttpRequestTest::testCreateRequest() request->supportsPersistentConnection(true); request->setUri("http://localhost:8080/archives/aria2-1.0.0.tar.bz2"); - auto p = std::make_shared(0, 1024); - auto segment = std::make_shared(1024, p); - auto fileEntry = std::make_shared("file", 1024*1024*10, 0); + auto p = std::make_shared(0, 1_k); + auto segment = std::make_shared(1_k, p); + auto fileEntry = std::make_shared("file", 10_m, 0); HttpRequest httpRequest; httpRequest.disableContentEncoding(); @@ -169,8 +169,8 @@ void HttpRequestTest::testCreateRequest() CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest()); - p.reset(new Piece(1, 1024*1024)); - segment.reset(new PiecedSegment(1024*1024, p)); + p.reset(new Piece(1, 1_m)); + segment.reset(new PiecedSegment(1_m, p)); httpRequest.setSegment(segment); expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" @@ -233,8 +233,8 @@ void HttpRequestTest::testCreateRequest() request->resetUri(); - p.reset(new Piece(0, 1024*1024)); - segment.reset(new PiecedSegment(1024*1024, p)); + p.reset(new Piece(0, 1_m)); + segment.reset(new PiecedSegment(1_m, p)); httpRequest.setSegment(segment); // enable http auth @@ -322,9 +322,9 @@ void HttpRequestTest::testCreateRequest_ftp() ("http://localhost:9000")); HttpRequest httpRequest; - auto p = std::make_shared(0, 1024*1024); - auto segment = std::make_shared(1024*1024, p); - auto fileEntry = std::make_shared("file", 1024*1024*10, 0); + auto p = std::make_shared(0, 1_m); + auto segment = std::make_shared(1_m, p); + auto fileEntry = std::make_shared("file", 10_m, 0); httpRequest.disableContentEncoding(); httpRequest.setRequest(request); @@ -379,9 +379,9 @@ void HttpRequestTest::testCreateRequest_with_cookie() { auto request = std::make_shared(); request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2"); - auto p = std::make_shared(0, 1024*1024); - auto segment = std::make_shared(1024*1024, p); - auto fileEntry = std::make_shared("file", 1024*1024*10, 0); + auto p = std::make_shared(0, 1_m); + auto segment = std::make_shared(1_m, p); + auto fileEntry = std::make_shared("file", 10_m, 0); auto st = CookieStorage{}; CPPUNIT_ASSERT(st.store(createCookie("name1", "value1", "localhost", true, @@ -540,11 +540,11 @@ void HttpRequestTest::testCreateRequest_endOffsetOverride() httpRequest.setRequest(request); httpRequest.setAuthConfigFactory(authConfigFactory_.get()); httpRequest.setOption(option_.get()); - auto p = std::make_shared(0, 1024*1024); - auto segment = std::make_shared(1024*1024, p); + auto p = std::make_shared(0, 1_m); + auto segment = std::make_shared(1_m, p); httpRequest.setSegment(segment); - httpRequest.setEndOffsetOverride(1024*1024*1024); - auto fileEntry = std::make_shared("file", 1024*1024*1024*10LL, 0); + httpRequest.setEndOffsetOverride(1_g); + auto fileEntry = std::make_shared("file", 10_g, 0); httpRequest.setFileEntry(fileEntry); // End byte is passed if it is not 0 std::string expectedText = @@ -580,8 +580,8 @@ void HttpRequestTest::testCreateProxyRequest() { auto request = std::make_shared(); request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2"); - auto p = std::make_shared(0, 1024*1024); - auto segment = std::make_shared(1024*1024, p); + auto p = std::make_shared(0, 1_m); + auto segment = std::make_shared(1_m, p); auto proxyRequest = std::make_shared(); CPPUNIT_ASSERT(proxyRequest->setUri("http://localhost:9000")); @@ -645,8 +645,8 @@ void HttpRequestTest::testIsRangeSatisfied() request->supportsPersistentConnection(true); request->setUri("http://localhost:8080/archives/aria2-1.0.0.tar.bz2"); request->setPipeliningHint(false); // default: false - auto p = std::make_shared(0, 1024*1024); - auto segment = std::make_shared(1024*1024, p); + auto p = std::make_shared(0, 1_m); + auto segment = std::make_shared(1_m, p); auto fileEntry = std::make_shared("file", 0, 0); HttpRequest httpRequest; @@ -659,8 +659,8 @@ void HttpRequestTest::testIsRangeSatisfied() CPPUNIT_ASSERT(httpRequest.isRangeSatisfied(range)); - p.reset(new Piece(1, 1024*1024)); - segment.reset(new PiecedSegment(1024*1024, p)); + p.reset(new Piece(1, 1_m)); + segment.reset(new PiecedSegment(1_m, p)); httpRequest.setSegment(segment); CPPUNIT_ASSERT(!httpRequest.isRangeSatisfied(range)); @@ -707,8 +707,8 @@ void HttpRequestTest::testUserAgent() auto request = std::make_shared(); request->setUri("http://localhost:8080/archives/aria2-1.0.0.tar.bz2"); - //std::shared_ptr p(new Piece(0, 1024)); - //std::shared_ptr segment(new PiecedSegment(1024, p)); + //std::shared_ptr p(new Piece(0, 1_k)); + //std::shared_ptr segment(new PiecedSegment(1_k, p)); HttpRequest httpRequest; httpRequest.disableContentEncoding(); diff --git a/test/HttpResponseTest.cc b/test/HttpResponseTest.cc index 6c97ffd0..397fc567 100644 --- a/test/HttpResponseTest.cc +++ b/test/HttpResponseTest.cc @@ -384,10 +384,10 @@ void HttpResponseTest::testValidateResponse_good_range() httpResponse.setHttpHeader(make_unique()); auto httpRequest = make_unique(); - auto p = std::make_shared(1, 1024*1024); - auto segment = std::make_shared(1024*1024, p); + auto p = std::make_shared(1, 1_m); + auto segment = std::make_shared(1_m, p); httpRequest->setSegment(segment); - auto fileEntry = std::make_shared("file", 1024*1024*10, 0); + auto fileEntry = std::make_shared("file", 10_m, 0); httpRequest->setFileEntry(fileEntry); auto request = std::make_shared(); request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2"); @@ -412,10 +412,10 @@ void HttpResponseTest::testValidateResponse_bad_range() httpResponse.setHttpHeader(make_unique()); auto httpRequest = make_unique(); - auto p = std::make_shared(1, 1024*1024); - auto segment = std::make_shared(1024*1024, p); + auto p = std::make_shared(1, 1_m); + auto segment = std::make_shared(1_m, p); httpRequest->setSegment(segment); - auto fileEntry = std::make_shared("file", 1024*1024*10, 0); + auto fileEntry = std::make_shared("file", 10_m, 0); httpRequest->setFileEntry(fileEntry); auto request = std::make_shared(); request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2"); @@ -438,10 +438,10 @@ void HttpResponseTest::testValidateResponse_chunked() httpResponse.setHttpHeader(make_unique()); auto httpRequest = make_unique(); - auto p = std::make_shared(1, 1024*1024); - auto segment = std::make_shared(1024*1024, p); + auto p = std::make_shared(1, 1_m); + auto segment = std::make_shared(1_m, p); httpRequest->setSegment(segment); - auto fileEntry = std::make_shared("file", 1024*1024*10, 0); + auto fileEntry = std::make_shared("file", 10_m, 0); httpRequest->setFileEntry(fileEntry); auto request = std::make_shared(); request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2"); diff --git a/test/LongestSequencePieceSelectorTest.cc b/test/LongestSequencePieceSelectorTest.cc index af7ea0b9..899a39f6 100644 --- a/test/LongestSequencePieceSelectorTest.cc +++ b/test/LongestSequencePieceSelectorTest.cc @@ -4,6 +4,7 @@ #include "array_fun.h" #include "BitfieldMan.h" +#include "a2functional.h" namespace aria2 { @@ -26,7 +27,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(LongestSequencePieceSelectorTest); void LongestSequencePieceSelectorTest::testSelect() { size_t A[] = { 1,2,3,4,7,10,11,12,13,14,15,100,112,113,114 }; - BitfieldMan bf(1024, 1024*256); + BitfieldMan bf(1_k, 256_k); for(size_t i = 0; i < arraySize(A); ++i) { bf.setBit(A[i]); } diff --git a/test/MessageDigestHelperTest.cc b/test/MessageDigestHelperTest.cc index c345fd50..185c9e20 100644 --- a/test/MessageDigestHelperTest.cc +++ b/test/MessageDigestHelperTest.cc @@ -33,7 +33,7 @@ void MessageDigestHelperTest::testDigestDiskWriter() { CPPUNIT_ASSERT_EQUAL(std::string("608cabc0f2fa18c260cafd974516865c772363d5"), util::toHex(message_digest::digest (MessageDigest::sha1().get(), - diskio, 0, 4096))); + diskio, 0, 4_k))); CPPUNIT_ASSERT_EQUAL(std::string("7a4a9ae537ebbbb826b1060e704490ad0f365ead"), util::toHex(message_digest::digest diff --git a/test/MetalinkParserControllerTest.cc b/test/MetalinkParserControllerTest.cc index aded4223..2bb45716 100644 --- a/test/MetalinkParserControllerTest.cc +++ b/test/MetalinkParserControllerTest.cc @@ -52,7 +52,7 @@ void MetalinkParserControllerTest::testEntryTransaction() ctrl.newEntryTransaction(); ctrl.setFileNameOfEntry("aria2.tar.bz2"); - ctrl.setFileLengthOfEntry(1024*1024); + ctrl.setFileLengthOfEntry(1_m); ctrl.setVersionOfEntry("1.0"); ctrl.setLanguageOfEntry("ja_JP"); ctrl.setOSOfEntry("Linux"); @@ -64,7 +64,7 @@ void MetalinkParserControllerTest::testEntryTransaction() CPPUNIT_ASSERT_EQUAL((size_t)1, m->getEntries().size()); auto& e = m->getEntries()[0]; CPPUNIT_ASSERT_EQUAL(std::string("aria2.tar.bz2"), e->file->getPath()); - CPPUNIT_ASSERT_EQUAL((int64_t)(1024*1024LL), e->file->getLength()); + CPPUNIT_ASSERT_EQUAL((int64_t)1_m, e->file->getLength()); CPPUNIT_ASSERT_EQUAL((int64_t)0, e->file->getOffset()); CPPUNIT_ASSERT_EQUAL(std::string("1.0"), e->version); CPPUNIT_ASSERT_EQUAL(std::string("ja_JP"), e->languages[0]); @@ -215,7 +215,7 @@ void MetalinkParserControllerTest::testChunkChecksumTransaction() ctrl.newEntryTransaction(); ctrl.newChunkChecksumTransaction(); ctrl.setTypeOfChunkChecksum("md5"); - ctrl.setLengthOfChunkChecksum(256*1024); + ctrl.setLengthOfChunkChecksum(256_k); ctrl.addHashOfChunkChecksum(4, "4cbd18db4cc2f85cedef654fccc4a4d8"); ctrl.addHashOfChunkChecksum(1, "1cbd18db4cc2f85cedef654fccc4a4d8"); ctrl.addHashOfChunkChecksum(3, "3cbd18db4cc2f85cedef654fccc4a4d8"); @@ -226,7 +226,7 @@ void MetalinkParserControllerTest::testChunkChecksumTransaction() ctrl.newEntryTransaction(); ctrl.newChunkChecksumTransaction(); ctrl.setTypeOfChunkChecksum("md5"); - ctrl.setLengthOfChunkChecksum(256*1024); + ctrl.setLengthOfChunkChecksum(256_k); ctrl.addHashOfChunkChecksum(1, "badhash"); ctrl.commitEntryTransaction(); @@ -238,7 +238,7 @@ void MetalinkParserControllerTest::testChunkChecksumTransaction() auto m = ctrl.getResult(); auto& md = m->getEntries()[0]->chunkChecksum; CPPUNIT_ASSERT_EQUAL(std::string("md5"), md->getHashType()); - CPPUNIT_ASSERT_EQUAL(256*1024, md->getPieceLength()); + CPPUNIT_ASSERT_EQUAL((int32_t)256_k, md->getPieceLength()); CPPUNIT_ASSERT_EQUAL((size_t)5, md->countPieceHash()); CPPUNIT_ASSERT_EQUAL(std::string("1cbd18db4cc2f85cedef654fccc4a4d8"), md->getPieceHashes()[0]); @@ -263,7 +263,7 @@ void MetalinkParserControllerTest::testChunkChecksumTransactionV4() ctrl.newEntryTransaction(); ctrl.newChunkChecksumTransactionV4(); ctrl.setTypeOfChunkChecksumV4("sha-1"); - ctrl.setLengthOfChunkChecksumV4(256*1024); + ctrl.setLengthOfChunkChecksumV4(256_k); ctrl.addHashOfChunkChecksumV4("5bd9f7248df0f3a6a86ab6c95f48787d546efa14"); ctrl.addHashOfChunkChecksumV4("9413ee70957a09d55704123687478e07f18c7b29"); @@ -273,7 +273,7 @@ void MetalinkParserControllerTest::testChunkChecksumTransactionV4() ctrl.newEntryTransaction(); ctrl.newChunkChecksumTransactionV4(); ctrl.setTypeOfChunkChecksumV4("sha-1"); - ctrl.setLengthOfChunkChecksumV4(256*1024); + ctrl.setLengthOfChunkChecksumV4(256_k); ctrl.addHashOfChunkChecksumV4("5bd9f7248df0f3a6a86ab6c95f48787d546efa14"); ctrl.addHashOfChunkChecksumV4("badhash"); ctrl.commitEntryTransaction(); @@ -286,7 +286,7 @@ void MetalinkParserControllerTest::testChunkChecksumTransactionV4() auto m = ctrl.getResult(); auto& md = m->getEntries()[0]->chunkChecksum; CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), md->getHashType()); - CPPUNIT_ASSERT_EQUAL(256*1024, md->getPieceLength()); + CPPUNIT_ASSERT_EQUAL((int32_t)256_k, md->getPieceLength()); CPPUNIT_ASSERT_EQUAL((size_t)3, md->countPieceHash()); CPPUNIT_ASSERT_EQUAL (std::string("5bd9f7248df0f3a6a86ab6c95f48787d546efa14"), diff --git a/test/MetalinkPostDownloadHandlerTest.cc b/test/MetalinkPostDownloadHandlerTest.cc index 19fcea61..bef0b654 100644 --- a/test/MetalinkPostDownloadHandlerTest.cc +++ b/test/MetalinkPostDownloadHandlerTest.cc @@ -70,7 +70,7 @@ void MetalinkPostDownloadHandlerTest::testCanHandle_contentType() void MetalinkPostDownloadHandlerTest::testGetNextRequestGroups() { std::shared_ptr dctx - (new DownloadContext(1024, 0, A2_TEST_DIR"/test.xml")); + (new DownloadContext(1_k, 0, A2_TEST_DIR"/test.xml")); RequestGroup rg(GroupId::create(), option_); rg.setDownloadContext(dctx); rg.initPieceStorage(); @@ -89,7 +89,7 @@ void MetalinkPostDownloadHandlerTest::testGetNextRequestGroups() void MetalinkPostDownloadHandlerTest::testGetNextRequestGroups_withBaseUri() { std::shared_ptr dctx - (new DownloadContext(1024, 0, A2_TEST_DIR"/base_uri.xml")); + (new DownloadContext(1_k, 0, A2_TEST_DIR"/base_uri.xml")); dctx->getFirstFileEntry()->addUri("http://base/dir/base_uri.xml"); RequestGroup rg(GroupId::create(), option_); rg.setDownloadContext(dctx); diff --git a/test/MetalinkProcessorTest.cc b/test/MetalinkProcessorTest.cc index 618cbd94..874290a5 100644 --- a/test/MetalinkProcessorTest.cc +++ b/test/MetalinkProcessorTest.cc @@ -847,7 +847,7 @@ void MetalinkProcessorTest::testMultiplePieces() auto& e = m->getEntries()[0]; auto& c = e->chunkChecksum; CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), c->getHashType()); - CPPUNIT_ASSERT_EQUAL(1024, c->getPieceLength()); + CPPUNIT_ASSERT_EQUAL((int32_t)1_k, c->getPieceLength()); } catch(Exception& e) { CPPUNIT_FAIL(e.stackTrace()); } @@ -878,7 +878,7 @@ void MetalinkProcessorTest::testBadPieceNo() auto& e = m->getEntries()[0]; auto& c = e->chunkChecksum; CPPUNIT_ASSERT(c); - CPPUNIT_ASSERT_EQUAL(1024, c->getPieceLength()); + CPPUNIT_ASSERT_EQUAL((int32_t)1_k, c->getPieceLength()); CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), c->getHashType()); } catch(Exception& e) { CPPUNIT_FAIL(e.stackTrace()); @@ -910,7 +910,7 @@ void MetalinkProcessorTest::testBadPieceLength() auto& e = m->getEntries()[0]; auto& c = e->chunkChecksum; CPPUNIT_ASSERT(c); - CPPUNIT_ASSERT_EQUAL(1024, c->getPieceLength()); + CPPUNIT_ASSERT_EQUAL((int32_t)1_k, c->getPieceLength()); CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), c->getHashType()); } catch(Exception& e) { CPPUNIT_FAIL(e.stackTrace()); @@ -941,7 +941,7 @@ void MetalinkProcessorTest::testUnsupportedType_piece() auto& e = m->getEntries()[0]; auto& c = e->chunkChecksum; CPPUNIT_ASSERT(c); - CPPUNIT_ASSERT_EQUAL(1024, c->getPieceLength()); + CPPUNIT_ASSERT_EQUAL((int32_t)1_k, c->getPieceLength()); CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), c->getHashType()); } catch(Exception& e) { CPPUNIT_FAIL(e.stackTrace()); diff --git a/test/MultiFileAllocationIteratorTest.cc b/test/MultiFileAllocationIteratorTest.cc index c1507ede..49ca8453 100644 --- a/test/MultiFileAllocationIteratorTest.cc +++ b/test/MultiFileAllocationIteratorTest.cc @@ -68,7 +68,7 @@ void MultiFileAllocationIteratorTest::testMakeDiskWriterEntries() MultiDiskAdaptor diskAdaptor; diskAdaptor.setFileEntries(std::begin(fs), std::end(fs)); - diskAdaptor.setPieceLength(1024); + diskAdaptor.setPieceLength(1_k); diskAdaptor.openFile(); auto allocitr = diskAdaptor.fileAllocationIterator(); diff --git a/test/PeerConnectionTest.cc b/test/PeerConnectionTest.cc index 6e0bf9d2..90d27ccc 100644 --- a/test/PeerConnectionTest.cc +++ b/test/PeerConnectionTest.cc @@ -26,7 +26,7 @@ void PeerConnectionTest::testReserveBuffer() { CPPUNIT_ASSERT_EQUAL((size_t)MAX_BUFFER_CAPACITY, con.getBufferCapacity()); CPPUNIT_ASSERT_EQUAL((size_t)3, con.getBufferLength()); - size_t newLength = 32*1024; + constexpr size_t newLength = 32_k; con.reserveBuffer(newLength); CPPUNIT_ASSERT_EQUAL(newLength, con.getBufferCapacity()); diff --git a/test/PeerSessionResourceTest.cc b/test/PeerSessionResourceTest.cc index 8547e1dd..e43370cd 100644 --- a/test/PeerSessionResourceTest.cc +++ b/test/PeerSessionResourceTest.cc @@ -60,7 +60,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(PeerSessionResourceTest); void PeerSessionResourceTest::testPeerAllowedIndexSetContains() { - PeerSessionResource res(1024, 1024*1024); + PeerSessionResource res(1_k, 1_m); res.addPeerAllowedIndex(567); res.addPeerAllowedIndex(789); @@ -72,7 +72,7 @@ void PeerSessionResourceTest::testPeerAllowedIndexSetContains() void PeerSessionResourceTest::testAmAllowedIndexSetContains() { - PeerSessionResource res(1024, 1024*1024); + PeerSessionResource res(1_k, 1_m); res.addAmAllowedIndex(567); res.addAmAllowedIndex(789); @@ -84,7 +84,7 @@ void PeerSessionResourceTest::testAmAllowedIndexSetContains() void PeerSessionResourceTest::testHasAllPieces() { - PeerSessionResource res(1024, 1024*1024); + PeerSessionResource res(1_k, 1_m); CPPUNIT_ASSERT(!res.hasAllPieces()); res.markSeeder(); @@ -93,7 +93,7 @@ void PeerSessionResourceTest::testHasAllPieces() void PeerSessionResourceTest::testHasPiece() { - PeerSessionResource res(1024, 1024*1024); + PeerSessionResource res(1_k, 1_m); CPPUNIT_ASSERT(!res.hasPiece(300)); res.updateBitfield(300, 1); @@ -104,7 +104,7 @@ void PeerSessionResourceTest::testHasPiece() void PeerSessionResourceTest::testUpdateUploadLength() { - PeerSessionResource res(1024, 1024*1024); + PeerSessionResource res(1_k, 1_m); CPPUNIT_ASSERT_EQUAL((int64_t)0LL, res.uploadLength()); res.updateUploadLength(100); @@ -114,7 +114,7 @@ void PeerSessionResourceTest::testUpdateUploadLength() void PeerSessionResourceTest::testUpdateDownloadLength() { - PeerSessionResource res(1024, 1024*1024); + PeerSessionResource res(1_k, 1_m); CPPUNIT_ASSERT_EQUAL((int64_t)0LL, res.downloadLength()); res.updateDownloadLength(100); @@ -124,7 +124,7 @@ void PeerSessionResourceTest::testUpdateDownloadLength() void PeerSessionResourceTest::testExtendedMessageEnabled() { - PeerSessionResource res(1024, 1024*1024); + PeerSessionResource res(1_k, 1_m); CPPUNIT_ASSERT(!res.extendedMessagingEnabled()); res.extendedMessagingEnabled(true); @@ -135,7 +135,7 @@ void PeerSessionResourceTest::testExtendedMessageEnabled() void PeerSessionResourceTest::testGetExtensionMessageID() { - PeerSessionResource res(1024, 1024*1024); + PeerSessionResource res(1_k, 1_m); res.addExtension(ExtensionMessageRegistry::UT_PEX, 9); CPPUNIT_ASSERT_EQUAL((uint8_t)9, @@ -152,7 +152,7 @@ void PeerSessionResourceTest::testGetExtensionMessageID() void PeerSessionResourceTest::testFastExtensionEnabled() { - PeerSessionResource res(1024, 1024*1024); + PeerSessionResource res(1_k, 1_m); CPPUNIT_ASSERT(!res.fastExtensionEnabled()); res.fastExtensionEnabled(true); @@ -163,7 +163,7 @@ void PeerSessionResourceTest::testFastExtensionEnabled() void PeerSessionResourceTest::testSnubbing() { - PeerSessionResource res(1024, 1024*1024); + PeerSessionResource res(1_k, 1_m); CPPUNIT_ASSERT(!res.snubbing()); res.snubbing(true); @@ -174,7 +174,7 @@ void PeerSessionResourceTest::testSnubbing() void PeerSessionResourceTest::testAmChoking() { - PeerSessionResource res(1024, 1024*1024); + PeerSessionResource res(1_k, 1_m); CPPUNIT_ASSERT(res.amChoking()); res.amChoking(false); @@ -185,7 +185,7 @@ void PeerSessionResourceTest::testAmChoking() void PeerSessionResourceTest::testAmInterested() { - PeerSessionResource res(1024, 1024*1024); + PeerSessionResource res(1_k, 1_m); CPPUNIT_ASSERT(!res.amInterested()); res.amInterested(true); @@ -196,7 +196,7 @@ void PeerSessionResourceTest::testAmInterested() void PeerSessionResourceTest::testPeerChoking() { - PeerSessionResource res(1024, 1024*1024); + PeerSessionResource res(1_k, 1_m); CPPUNIT_ASSERT(res.peerChoking()); res.peerChoking(false); @@ -207,7 +207,7 @@ void PeerSessionResourceTest::testPeerChoking() void PeerSessionResourceTest::testPeerInterested() { - PeerSessionResource res(1024, 1024*1024); + PeerSessionResource res(1_k, 1_m); CPPUNIT_ASSERT(!res.peerInterested()); res.peerInterested(true); @@ -218,7 +218,7 @@ void PeerSessionResourceTest::testPeerInterested() void PeerSessionResourceTest::testChokingRequired() { - PeerSessionResource res(1024, 1024*1024); + PeerSessionResource res(1_k, 1_m); CPPUNIT_ASSERT(res.chokingRequired()); res.chokingRequired(false); @@ -229,7 +229,7 @@ void PeerSessionResourceTest::testChokingRequired() void PeerSessionResourceTest::testOptUnchoking() { - PeerSessionResource res(1024, 1024*1024); + PeerSessionResource res(1_k, 1_m); CPPUNIT_ASSERT(!res.optUnchoking()); res.optUnchoking(true); @@ -240,7 +240,7 @@ void PeerSessionResourceTest::testOptUnchoking() void PeerSessionResourceTest::testShouldBeChoking() { - PeerSessionResource res(1024, 1024*1024); + PeerSessionResource res(1_k, 1_m); CPPUNIT_ASSERT(res.shouldBeChoking()); res.chokingRequired(false); @@ -252,7 +252,7 @@ void PeerSessionResourceTest::testShouldBeChoking() void PeerSessionResourceTest::testCountOutstandingRequest() { - PeerSessionResource res(1024, 1024*1024); + PeerSessionResource res(1_k, 1_m); std::shared_ptr dispatcher (new MockBtMessageDispatcher()); res.setBtMessageDispatcher(dispatcher.get()); diff --git a/test/PeerTest.cc b/test/PeerTest.cc index dd86a945..bed51fae 100644 --- a/test/PeerTest.cc +++ b/test/PeerTest.cc @@ -15,7 +15,7 @@ private: public: void setUp() { peer.reset(new Peer("localhost", 6969)); - peer->allocateSessionResource(1024, 1024*1024); + peer->allocateSessionResource(1_k, 1_m); } void testPeerAllowedIndexSet(); @@ -48,7 +48,7 @@ void PeerTest::testCountSeeder() peers[4].reset(new Peer("192.168.0.5", 7000)); for(std::vector >::iterator i = peers.begin(); i != peers.end(); ++i) { - (*i)->allocateSessionResource(1024, 1024*8); + (*i)->allocateSessionResource(1_k, 8_k); } unsigned char bitfield[] = { 0xff }; peers[1]->setBitfield(bitfield, 1); diff --git a/test/PieceTest.cc b/test/PieceTest.cc index 5dd48f43..3684fd77 100644 --- a/test/PieceTest.cc +++ b/test/PieceTest.cc @@ -49,7 +49,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION( PieceTest ); void PieceTest::testCompleteBlock() { - size_t blockLength = 32*1024; + size_t blockLength = 32_k; Piece p(0, blockLength*10, blockLength); p.completeBlock(5); @@ -59,7 +59,7 @@ void PieceTest::testCompleteBlock() void PieceTest::testGetCompletedLength() { - int32_t blockLength = 16*1024; + int32_t blockLength = 16_k; Piece p(0, blockLength*10+100, blockLength); p.completeBlock(1); @@ -73,7 +73,7 @@ void PieceTest::testGetCompletedLength() void PieceTest::testFlushWrCache() { unsigned char* data; - Piece p(0, 1024); + Piece p(0, 1_k); WrDiskCache dc(64); p.initWrCache(&dc, adaptor_); data = new unsigned char[3]; @@ -99,8 +99,8 @@ void PieceTest::testFlushWrCache() void PieceTest::testAppendWrCache() { unsigned char* data; - Piece p(0, 1024); - WrDiskCache dc(1024); + Piece p(0, 1_k); + WrDiskCache dc(1_k); p.initWrCache(&dc, adaptor_); size_t capacity = 6; data = new unsigned char[capacity]; @@ -139,7 +139,7 @@ void PieceTest::testGetDigestWithWrCache() void PieceTest::testUpdateHash() { - Piece p(0, 16, 2*1024*1024); + Piece p(0, 16, 2_m); p.setHashType("sha-1"); std::string spam("SPAM!"); diff --git a/test/PriorityPieceSelectorTest.cc b/test/PriorityPieceSelectorTest.cc index ef0e7f33..e26a2c10 100644 --- a/test/PriorityPieceSelectorTest.cc +++ b/test/PriorityPieceSelectorTest.cc @@ -5,6 +5,7 @@ #include "array_fun.h" #include "BitfieldMan.h" #include "MockPieceSelector.h" +#include "a2functional.h" namespace aria2 { @@ -22,7 +23,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(PriorityPieceSelectorTest); void PriorityPieceSelectorTest::testSelect() { - size_t pieceLength = 1024; + constexpr size_t pieceLength = 1_k; size_t A[] = { 1,200}; BitfieldMan bf(pieceLength, pieceLength*256); for(auto i : A) { diff --git a/test/RarestPieceSelectorTest.cc b/test/RarestPieceSelectorTest.cc index a6b03b02..1e8bceb7 100644 --- a/test/RarestPieceSelectorTest.cc +++ b/test/RarestPieceSelectorTest.cc @@ -4,6 +4,7 @@ #include "BitfieldMan.h" #include "PieceStatMan.h" +#include "a2functional.h" namespace aria2 { @@ -31,7 +32,7 @@ void RarestPieceSelectorTest::testSelect() { std::shared_ptr pieceStatMan(new PieceStatMan(10, false)); RarestPieceSelector selector(pieceStatMan); - BitfieldMan bf(1024, 10*1024); + BitfieldMan bf(1_k, 10_k); bf.setBitRange(0, 2); size_t index; diff --git a/test/RequestGroupTest.cc b/test/RequestGroupTest.cc index f1c2683b..ab8b458f 100644 --- a/test/RequestGroupTest.cc +++ b/test/RequestGroupTest.cc @@ -34,7 +34,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION( RequestGroupTest ); void RequestGroupTest::testGetFirstFilePath() { std::shared_ptr ctx - (new DownloadContext(1024, 1024, "/tmp/myfile")); + (new DownloadContext(1_k, 1_k, "/tmp/myfile")); RequestGroup group(GroupId::create(), option_); group.setDownloadContext(ctx); @@ -49,7 +49,7 @@ void RequestGroupTest::testGetFirstFilePath() void RequestGroupTest::testCreateDownloadResult() { std::shared_ptr ctx - (new DownloadContext(1024, 1024*1024, "/tmp/myfile")); + (new DownloadContext(1_k, 1_m, "/tmp/myfile")); RequestGroup group(GroupId::create(), option_); group.setDownloadContext(ctx); group.initPieceStorage(); @@ -58,7 +58,7 @@ void RequestGroupTest::testCreateDownloadResult() CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile"), result->fileEntries[0]->getPath()); - CPPUNIT_ASSERT_EQUAL((int64_t)1024*1024, + CPPUNIT_ASSERT_EQUAL((int64_t)1_m, result->fileEntries.back()->getLastOffset()); CPPUNIT_ASSERT_EQUAL((uint64_t)0, result->sessionDownloadLength); CPPUNIT_ASSERT_EQUAL((int64_t)0, result->sessionTime.count()); diff --git a/test/RpcMethodTest.cc b/test/RpcMethodTest.cc index a85c0119..eddc1651 100644 --- a/test/RpcMethodTest.cc +++ b/test/RpcMethodTest.cc @@ -611,8 +611,7 @@ void RpcMethodTest::testChangeOption() auto option = group->getOption(); CPPUNIT_ASSERT_EQUAL(0, res.code); - CPPUNIT_ASSERT_EQUAL(100*1024, - group->getMaxDownloadSpeedLimit()); + CPPUNIT_ASSERT_EQUAL((int)100_k, group->getMaxDownloadSpeedLimit()); CPPUNIT_ASSERT_EQUAL(std::string("102400"), option->get(PREF_MAX_DOWNLOAD_LIMIT)); #ifdef ENABLE_BITTORRENT @@ -624,8 +623,7 @@ void RpcMethodTest::testChangeOption() e_->getBtRegistry()->get(group->getGID()) ->btRuntime->getMaxPeers()); - CPPUNIT_ASSERT_EQUAL(50*1024, - group->getMaxUploadSpeedLimit()); + CPPUNIT_ASSERT_EQUAL((int)50_k, group->getMaxUploadSpeedLimit()); CPPUNIT_ASSERT_EQUAL(std::string("51200"), option->get(PREF_MAX_UPLOAD_LIMIT)); #endif // ENABLE_BITTORRENT @@ -683,15 +681,13 @@ void RpcMethodTest::testChangeGlobalOption() auto res = m.execute(std::move(req), e_.get()); CPPUNIT_ASSERT_EQUAL(0, res.code); - CPPUNIT_ASSERT_EQUAL - (100*1024, - e_->getRequestGroupMan()->getMaxOverallDownloadSpeedLimit()); + CPPUNIT_ASSERT_EQUAL( + (int)100_k, e_->getRequestGroupMan()->getMaxOverallDownloadSpeedLimit()); CPPUNIT_ASSERT_EQUAL(std::string("102400"), e_->getOption()->get(PREF_MAX_OVERALL_DOWNLOAD_LIMIT)); #ifdef ENABLE_BITTORRENT - CPPUNIT_ASSERT_EQUAL - (50*1024, - e_->getRequestGroupMan()->getMaxOverallUploadSpeedLimit()); + CPPUNIT_ASSERT_EQUAL( + (int)50_k, e_->getRequestGroupMan()->getMaxOverallUploadSpeedLimit()); CPPUNIT_ASSERT_EQUAL(std::string("51200"), e_->getOption()->get(PREF_MAX_OVERALL_UPLOAD_LIMIT)); #endif // ENABLE_BITTORRENT diff --git a/test/SegmentManTest.cc b/test/SegmentManTest.cc index 30e38ad9..c1c89d06 100644 --- a/test/SegmentManTest.cc +++ b/test/SegmentManTest.cc @@ -32,8 +32,8 @@ private: public: void setUp() { - size_t pieceLength = 1024*1024; - uint64_t totalLength = 64*1024*1024; + size_t pieceLength = 1_m; + uint64_t totalLength = 64_m; option_.reset(new Option()); dctx_.reset (new DownloadContext(pieceLength, totalLength, "aria2.tar.bz2")); @@ -80,8 +80,8 @@ void SegmentManTest::testNullBitfield() void SegmentManTest::testCompleteSegment() { Option op; - size_t pieceLength = 1024*1024; - uint64_t totalLength = 64*1024*1024; + size_t pieceLength = 1_m; + uint64_t totalLength = 64_m; std::shared_ptr dctx (new DownloadContext(pieceLength, totalLength, "aria2.tar.bz2")); std::shared_ptr ps(new DefaultPieceStorage(dctx, &op)); diff --git a/test/SegmentTest.cc b/test/SegmentTest.cc index a2a1cfc6..2852913c 100644 --- a/test/SegmentTest.cc +++ b/test/SegmentTest.cc @@ -30,22 +30,22 @@ CPPUNIT_TEST_SUITE_REGISTRATION( SegmentTest ); void SegmentTest::testUpdateWrittenLength() { - std::shared_ptr p(new Piece(0, 16*1024*10)); - PiecedSegment s(16*1024*10, p); + std::shared_ptr p(new Piece(0, 160_k)); + PiecedSegment s(160_k, p); CPPUNIT_ASSERT_EQUAL((int64_t)0, s.getWrittenLength()); - s.updateWrittenLength(16*1024); + s.updateWrittenLength(16_k); CPPUNIT_ASSERT(p->hasBlock(0)); CPPUNIT_ASSERT(!p->hasBlock(1)); - s.updateWrittenLength(16*1024*9); + s.updateWrittenLength(16_k * 9); CPPUNIT_ASSERT(p->pieceComplete()); } void SegmentTest::testUpdateWrittenLength_lastPiece() { - std::shared_ptr p(new Piece(0, 16*1024*9+1)); - PiecedSegment s(16*1024*10, p); + std::shared_ptr p(new Piece(0, 16_k * 9 + 1)); + PiecedSegment s(160_k, p); s.updateWrittenLength(p->getLength()); CPPUNIT_ASSERT(p->pieceComplete()); @@ -53,10 +53,10 @@ void SegmentTest::testUpdateWrittenLength_lastPiece() void SegmentTest::testUpdateWrittenLength_incompleteLastPiece() { - std::shared_ptr p(new Piece(0, 16*1024*9+2)); - PiecedSegment s(16*1024*10, p); + std::shared_ptr p(new Piece(0, 16_k * 9 + 2)); + PiecedSegment s(160_k, p); - s.updateWrittenLength(16*1024*9+1); + s.updateWrittenLength(16_k * 9 + 1); CPPUNIT_ASSERT(!p->pieceComplete()); s.updateWrittenLength(1); CPPUNIT_ASSERT(p->pieceComplete()); @@ -64,10 +64,10 @@ void SegmentTest::testUpdateWrittenLength_incompleteLastPiece() void SegmentTest::testClear() { - std::shared_ptr p(new Piece(0, 16*1024*10)); - PiecedSegment s(16*1024*10, p); - s.updateWrittenLength(16*1024*10); - CPPUNIT_ASSERT_EQUAL((int64_t)16*1024*10, s.getWrittenLength()); + std::shared_ptr p(new Piece(0, 160_k)); + PiecedSegment s(160_k, p); + s.updateWrittenLength(160_k); + CPPUNIT_ASSERT_EQUAL((int64_t)160_k, s.getWrittenLength()); s.clear(nullptr); CPPUNIT_ASSERT_EQUAL((int64_t)0, s.getWrittenLength()); } diff --git a/test/ShareRatioSeedCriteriaTest.cc b/test/ShareRatioSeedCriteriaTest.cc index 45cbc9c9..9ca2471f 100644 --- a/test/ShareRatioSeedCriteriaTest.cc +++ b/test/ShareRatioSeedCriteriaTest.cc @@ -23,7 +23,7 @@ public: CPPUNIT_TEST_SUITE_REGISTRATION(ShareRatioSeedCriteriaTest); void ShareRatioSeedCriteriaTest::testEvaluate() { - std::shared_ptr dctx(new DownloadContext(1024*1024, 1000000)); + std::shared_ptr dctx(new DownloadContext(1_m, 1000000)); std::shared_ptr btRuntime(new BtRuntime()); btRuntime->setUploadLengthAtStartup(1000000); diff --git a/test/SingleFileAllocationIteratorTest.cc b/test/SingleFileAllocationIteratorTest.cc index ea6ca21a..8be43398 100644 --- a/test/SingleFileAllocationIteratorTest.cc +++ b/test/SingleFileAllocationIteratorTest.cc @@ -1,9 +1,11 @@ #include "SingleFileAllocationIterator.h" -#include "File.h" -#include "DefaultDiskWriter.h" #include #include +#include "File.h" +#include "DefaultDiskWriter.h" +#include "a2functional.h" + namespace aria2 { class SingleFileAllocationIteratorTest:public CppUnit::TestFixture { @@ -36,7 +38,7 @@ void SingleFileAllocationIteratorTest::testAllocate() DefaultDiskWriter writer(fn); int64_t offset = 10; - int64_t totalLength = 16*1024*2+8*1024; + int64_t totalLength = 32_k + 8_k; // we have to open file first. writer.openExistingFile(); @@ -47,7 +49,7 @@ void SingleFileAllocationIteratorTest::testAllocate() itr.allocateChunk(); } File f(fn); - CPPUNIT_ASSERT_EQUAL((int64_t)40960, f.size()); + CPPUNIT_ASSERT_EQUAL((int64_t)40_k, f.size()); } } // namespace aria2 diff --git a/test/TestUtil.cc b/test/TestUtil.cc index 11e6dd05..c6660933 100644 --- a/test/TestUtil.cc +++ b/test/TestUtil.cc @@ -37,7 +37,7 @@ std::string readFile(const std::string& path) { std::stringstream ss; std::ifstream in(path.c_str(), std::ios::binary); - char buf[4096]; + char buf[4_k]; while(1) { in.read(buf, sizeof(buf)); ss.write(buf, in.gcount()); diff --git a/test/UTPexExtensionMessageTest.cc b/test/UTPexExtensionMessageTest.cc index cdb4910a..61ab7ebd 100644 --- a/test/UTPexExtensionMessageTest.cc +++ b/test/UTPexExtensionMessageTest.cc @@ -71,7 +71,7 @@ void UTPexExtensionMessageTest::testGetBencodedData() { UTPexExtensionMessage msg(1); auto p1 = std::make_shared("192.168.0.1", 6881); - p1->allocateSessionResource(256*1024, 1024*1024); + p1->allocateSessionResource(256_k, 1_m); p1->setAllBitfield(); CPPUNIT_ASSERT(msg.addFreshPeer(p1));// added seeder, check add.f flag auto p2 = std::make_shared("10.1.1.2", 9999); @@ -120,7 +120,7 @@ void UTPexExtensionMessageTest::testToString() { UTPexExtensionMessage msg(1); std::shared_ptr p1(new Peer("192.168.0.1", 6881)); - p1->allocateSessionResource(256*1024, 1024*1024); + p1->allocateSessionResource(256_k, 1_m); p1->setAllBitfield(); msg.addFreshPeer(p1);// added seeder, check add.f flag std::shared_ptr p2(new Peer("10.1.1.2", 9999)); @@ -138,7 +138,7 @@ void UTPexExtensionMessageTest::testDoReceivedAction() { UTPexExtensionMessage msg(1); std::shared_ptr p1(new Peer("192.168.0.1", 6881)); - p1->allocateSessionResource(256*1024, 1024*1024); + p1->allocateSessionResource(256_k, 1_m); p1->setAllBitfield(); msg.addFreshPeer(p1);// added seeder, check add.f flag std::shared_ptr p2(new Peer("1002:1035:4527:3546:7854:1237:3247:3217", diff --git a/test/UtilTest1.cc b/test/UtilTest1.cc index e3a06df0..e0435089 100644 --- a/test/UtilTest1.cc +++ b/test/UtilTest1.cc @@ -805,7 +805,7 @@ void UtilTest1::testGetContentDispositionFilename() { } void UtilTest1::testParseContentDisposition1() { - char dest[1024]; + char dest[1_k]; size_t destlen = sizeof(dest); const char *cs; size_t cslen; @@ -1084,7 +1084,7 @@ void UtilTest1::testParseContentDisposition1() { } void UtilTest1::testParseContentDisposition2() { - char dest[1024]; + char dest[1_k]; size_t destlen = sizeof(dest); const char *cs; size_t cslen; diff --git a/test/UtilTest2.cc b/test/UtilTest2.cc index 4855811a..d783cc2b 100644 --- a/test/UtilTest2.cc +++ b/test/UtilTest2.cc @@ -185,10 +185,10 @@ void UtilTest2::testPercentDecode() { void UtilTest2::testGetRealSize() { - CPPUNIT_ASSERT_EQUAL((int64_t)4294967296LL, util::getRealSize("4096M")); - CPPUNIT_ASSERT_EQUAL((int64_t)1024, util::getRealSize("1K")); - CPPUNIT_ASSERT_EQUAL((int64_t)4294967296LL, util::getRealSize("4096m")); - CPPUNIT_ASSERT_EQUAL((int64_t)1024, util::getRealSize("1k")); + CPPUNIT_ASSERT_EQUAL((int64_t)4_g, util::getRealSize("4096M")); + CPPUNIT_ASSERT_EQUAL((int64_t)1_k, util::getRealSize("1K")); + CPPUNIT_ASSERT_EQUAL((int64_t)4_g, util::getRealSize("4096m")); + CPPUNIT_ASSERT_EQUAL((int64_t)1_k, util::getRealSize("1k")); try { util::getRealSize(""); CPPUNIT_FAIL("exception must be thrown."); @@ -225,8 +225,8 @@ void UtilTest2::testAbbrevSize() { CPPUNIT_ASSERT_EQUAL(std::string("8,589,934,591Gi"), util::abbrevSize(9223372036854775807LL)); - CPPUNIT_ASSERT_EQUAL(std::string("4.0Gi"), util::abbrevSize(4294967296LL)); - CPPUNIT_ASSERT_EQUAL(std::string("1.0Ki"), util::abbrevSize(1024)); + CPPUNIT_ASSERT_EQUAL(std::string("4.0Gi"), util::abbrevSize(4_g)); + CPPUNIT_ASSERT_EQUAL(std::string("1.0Ki"), util::abbrevSize(1_k)); CPPUNIT_ASSERT_EQUAL(std::string("0.9Ki"), util::abbrevSize(1023)); CPPUNIT_ASSERT_EQUAL(std::string("511"), util::abbrevSize(511)); CPPUNIT_ASSERT_EQUAL(std::string("0"), util::abbrevSize(0)); @@ -325,8 +325,8 @@ void UtilTest2::testMkdirs() void UtilTest2::testConvertBitfield() { - BitfieldMan srcBitfield(384*1024, 256*1024*256+1); - BitfieldMan destBitfield(512*1024, srcBitfield.getTotalLength()); + BitfieldMan srcBitfield(384_k, 256_k * 256 + 1); + BitfieldMan destBitfield(512_k, srcBitfield.getTotalLength()); srcBitfield.setAllBit(); srcBitfield.unsetBit(2);// <- range [768, 1152) // which corresponds to the index [1,2] in destBitfield @@ -458,7 +458,7 @@ void UtilTest2::testParseLLIntNoThrow() void UtilTest2::testToString_binaryStream() { std::shared_ptr dw(new ByteArrayDiskWriter()); - std::string data(16*1024+256, 'a'); + std::string data(16_k + 256, 'a'); dw->initAndOpenFile(); dw->writeData((const unsigned char*)data.c_str(), data.size(), 0); @@ -700,7 +700,7 @@ void UtilTest2::testParsePrioritizePieceRange() // file3 | // | | // file4 | - size_t pieceLength = 1024; + constexpr size_t pieceLength = 1_k; std::vector > entries(4, std::shared_ptr()); entries[0].reset(new FileEntry("file1", 1024, 0)); entries[1].reset(new FileEntry("file2",2560,entries[0]->getLastOffset())); @@ -727,7 +727,7 @@ void UtilTest2::testParsePrioritizePieceRange() CPPUNIT_ASSERT_EQUAL((size_t)3, result[2]); CPPUNIT_ASSERT_EQUAL((size_t)4, result[3]); result.clear(); - util::parsePrioritizePieceRange(result, "head", entries, pieceLength, 1024); + util::parsePrioritizePieceRange(result, "head", entries, pieceLength, 1_k); CPPUNIT_ASSERT_EQUAL((size_t)4, result.size()); CPPUNIT_ASSERT_EQUAL((size_t)0, result[0]); CPPUNIT_ASSERT_EQUAL((size_t)1, result[1]); @@ -741,7 +741,7 @@ void UtilTest2::testParsePrioritizePieceRange() CPPUNIT_ASSERT_EQUAL((size_t)3, result[2]); CPPUNIT_ASSERT_EQUAL((size_t)6, result[3]); result.clear(); - util::parsePrioritizePieceRange(result, "tail", entries, pieceLength, 1024); + util::parsePrioritizePieceRange(result, "tail", entries, pieceLength, 1_k); CPPUNIT_ASSERT_EQUAL((size_t)4, result.size()); CPPUNIT_ASSERT_EQUAL((size_t)0, result[0]); CPPUNIT_ASSERT_EQUAL((size_t)2, result[1]);