2008-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Fixed compilation error with g++-4.3
pull/1/head
Tatsuhiro Tsujikawa 2008-03-15 04:19:46 +00:00
parent 8dacfe45b8
commit 538a8fcfe7
58 changed files with 196 additions and 86 deletions

View File

@ -1,3 +1,7 @@
2008-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Fixed compilation error with g++-4.3
2008-03-13 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added missing include files for MinGW

View File

@ -110,12 +110,12 @@ bool AbstractCommand::execute() {
return true;
}
}
if(checkSocketIsReadable && readCheckTarget->isReadable(0) ||
checkSocketIsWritable && writeCheckTarget->isWritable(0) ||
if((checkSocketIsReadable && readCheckTarget->isReadable(0)) ||
(checkSocketIsWritable && writeCheckTarget->isWritable(0)) ||
#ifdef ENABLE_ASYNC_DNS
nameResolverCheck && nameResolveFinished() ||
(nameResolverCheck && nameResolveFinished()) ||
#endif // ENABLE_ASYNC_DNS
!checkSocketIsReadable && !checkSocketIsWritable && !nameResolverCheck) {
(!checkSocketIsReadable && !checkSocketIsWritable && !nameResolverCheck)) {
checkPoint.reset();
if(!_requestGroup->getPieceStorage().isNull()) {
_segments = _requestGroup->getSegmentMan()->getInFlightSegment(cuid);

View File

@ -41,6 +41,7 @@
#include "DlAbortEx.h"
#include "a2io.h"
#include <cerrno>
#include <cstring>
#include <cassert>
namespace aria2 {

View File

@ -37,6 +37,7 @@
#include "NumberDecorator.h"
#include "DlAbortEx.h"
#include <algorithm>
namespace aria2 {

View File

@ -37,6 +37,7 @@
#include "common.h"
#include "SharedHandle.h"
#include <unistd.h>
namespace aria2 {

View File

@ -37,6 +37,7 @@
#include "common.h"
#include <map>
#include <string>
typedef std::map<std::string, uint8_t> Extensions;

View File

@ -33,6 +33,7 @@
*/
/* copyright --> */
#include "BtKeepAliveMessage.h"
#include <cstring>
namespace aria2 {

View File

@ -65,7 +65,7 @@ BtRequestMessageHandle BtRequestMessage::create(const unsigned char* data, size_
void BtRequestMessage::doReceivedAction() {
if(pieceStorage->hasPiece(index) &&
(!peer->amChoking() ||
peer->amChoking() && peer->isInAmAllowedIndexSet(index))) {
(peer->amChoking() && peer->isInAmAllowedIndexSet(index)))) {
BtMessageHandle msg = messageFactory->createPieceMessage(index,
begin,
length);

View File

@ -36,6 +36,7 @@
#define _D_COMMAND_H_
#include "common.h"
#include <stdint.h>
#include <deque>
namespace aria2 {

View File

@ -86,10 +86,10 @@ bool Cookie::good() const
bool Cookie::match(const std::string& host, const std::string& dir, time_t date, bool secure) const
{
if((secure || !this->secure && !secure) &&
if((secure || (!this->secure && !secure)) &&
Util::endsWith("."+host, this->domain) &&
Util::startsWith(dir, this->path) &&
(this->onetime || date < this->expires)) {
(this->onetime || (date < this->expires))) {
return true;
} else {
return false;

View File

@ -34,6 +34,7 @@
/* copyright --> */
#include "CookieParser.h"
#include "Util.h"
#include <strings.h>
#include <utility>
#include <istream>

View File

@ -48,6 +48,7 @@
#include "Logger.h"
#include <cerrno>
#include <fstream>
#include <cstring>
namespace aria2 {

View File

@ -72,7 +72,7 @@ bool DHTGetPeersCommand::execute()
return true;
}
if(_task.isNull() &&
(_numRetry > 0 && _lastGetPeerTime.elapsed(RETRY_INTERVAL) ||
((_numRetry > 0 && _lastGetPeerTime.elapsed(RETRY_INTERVAL)) ||
_lastGetPeerTime.elapsed(GET_PEER_INTERVAL))) {
logger->debug("Issuing PeerLookup for infoHash=%s",
btContext->getInfoHashAsString().c_str());

View File

@ -116,4 +116,9 @@ std::string DHTNode::toString() const
", RTT="+Util::uitos(_rtt);
}
void DHTNode::setID(const unsigned char* id)
{
memcpy(_id, id, DHT_ID_LENGTH);
}
} // namespace aria2

View File

@ -87,10 +87,7 @@ public:
_ipaddr = ipaddr;
}
void setID(const unsigned char* id)
{
memcpy(_id, id, DHT_ID_LENGTH);
}
void setID(const unsigned char* id);
uint16_t getPort() const
{

View File

@ -35,6 +35,7 @@
#include "Data.h"
#include "MetaEntryVisitor.h"
#include <cstring>
#include <cstdlib> // <-- TODO remove this if strtoll is replaced with Util::parseLLInt()
namespace aria2 {

View File

@ -456,4 +456,9 @@ DefaultBtContext::getNodes()
return _nodes;
}
void DefaultBtContext::setInfoHash(const unsigned char* infoHash)
{
memcpy(this->infoHash, infoHash, sizeof(this->infoHash));
}
} // namespace aria2

View File

@ -160,10 +160,7 @@ private:
}
// for unit test
void setInfoHash(const unsigned char* infoHash)
{
memcpy(this->infoHash, infoHash, sizeof(this->infoHash));
}
void setInfoHash(const unsigned char* infoHash);
void setNumPieces(size_t numPieces)
{

View File

@ -53,6 +53,7 @@
#include "DownloadFailureException.h"
#include <fstream>
#include <cerrno>
#include <cstring>
namespace aria2 {
@ -182,7 +183,7 @@ void DefaultBtProgressInfoFile::load()
uint32_t infoHashLength;
in.read(reinterpret_cast<char*>(&infoHashLength), sizeof(infoHashLength));
if(infoHashLength < 0 || infoHashLength == 0 && infoHashCheckEnabled) {
if((infoHashLength < 0) || ((infoHashLength == 0) && infoHashCheckEnabled)) {
throw new DlAbortEx("Invalid info hash length: %d", infoHashLength);
}
if(infoHashLength > 0) {

View File

@ -66,8 +66,8 @@ public:
FindIdenticalPeer(const PeerHandle& peer):_peer(peer) {}
bool operator()(const PeerHandle& peer) const {
return _peer == peer ||
_peer->ipaddr == peer->ipaddr && _peer->port == peer->port;
return (_peer == peer) ||
((_peer->ipaddr == peer->ipaddr) && (_peer->port == peer->port));
}
};

View File

@ -34,6 +34,7 @@
/* copyright --> */
#include "Dictionary.h"
#include "MetaEntryVisitor.h"
#include <algorithm>
namespace aria2 {

View File

@ -142,8 +142,8 @@ bool DownloadCommand::executeInternal() {
if(_requestGroup->getTotalLength() != 0 && bufSize == 0) {
throw new DlRetryEx(EX_GOT_EOF);
}
if(!transferDecoder.isNull() && transferDecoder->finished()
|| transferDecoder.isNull() && segment->complete()
if((!transferDecoder.isNull() && transferDecoder->finished())
|| (transferDecoder.isNull() && segment->complete())
|| bufSize == 0) {
if(!transferDecoder.isNull()) transferDecoder->end();
logger->info(MSG_SEGMENT_DOWNLOAD_COMPLETED, cuid);

View File

@ -34,10 +34,12 @@
/* copyright --> */
#include "File.h"
#include "Util.h"
#define basename posix_basename
#include <libgen.h>
// use GNU version basename
#undef basename
#include <cstring>
#include <stdlib.h>
#include <deque>
namespace aria2 {

View File

@ -37,6 +37,7 @@
#include "common.h"
#include "SharedHandle.h"
#include <unistd.h>
namespace aria2 {

View File

@ -73,7 +73,7 @@ uint64_t HttpHeader::getFirstAsULLInt(const std::string& name) const {
if(value == "") {
return 0;
} else {
return strtoull(value.c_str(), 0, 10);
return Util::parseULLInt(value);
}
}
@ -85,7 +85,7 @@ RangeHandle HttpHeader::getRange() const
if(contentLengthStr == "") {
return new Range(0, 0, 0);
} else {
uint64_t contentLength = strtoull(contentLengthStr.c_str(), 0, 10);
uint64_t contentLength = Util::parseULLInt(contentLengthStr);
if(contentLength == 0) {
return new Range(0, 0, 0);
} else {
@ -102,9 +102,9 @@ RangeHandle HttpHeader::getRange() const
std::pair<std::string, std::string> startEndBytePair;
Util::split(startEndBytePair, rangePair.first, '-');
uint64_t startByte = STRTOULL(startEndBytePair.first.c_str());
uint64_t endByte = STRTOULL(startEndBytePair.second.c_str());
uint64_t entityLength = STRTOULL(rangePair.second.c_str());
off_t startByte = Util::parseLLInt(startEndBytePair.first);
off_t endByte = Util::parseLLInt(startEndBytePair.second);
uint64_t entityLength = Util::parseULLInt(rangePair.second);
return new Range(startByte, endByte, entityLength);
}

View File

@ -115,11 +115,11 @@ bool HttpRequest::isRangeSatisfied(const RangeHandle& range) const
if(segment.isNull()) {
return true;
}
if(getStartByte() == range->getStartByte() &&
(getEndByte() == 0 ||
getEndByte() > 0 && getEndByte() == range->getEndByte()) &&
(entityLength == 0 ||
entityLength > 0 && entityLength == range->getEntityLength())) {
if((getStartByte() == range->getStartByte()) &&
((getEndByte() == 0) ||
((getEndByte() > 0) && (getEndByte() == range->getEndByte()))) &&
((entityLength == 0) ||
((entityLength > 0) && (entityLength == range->getEntityLength())))) {
return true;
} else {
return false;

View File

@ -37,6 +37,7 @@
#include "common.h"
#include "SharedHandle.h"
#include <unistd.h>
namespace aria2 {

View File

@ -40,6 +40,7 @@
#include "DlAbortEx.h"
#include "message.h"
#include <cstring>
#include <cstdlib> // <-- TODO remove this if strtoul is replaced with Util::parseUInt()
namespace aria2 {

View File

@ -37,6 +37,7 @@
#include "common.h"
#include <map>
#include <string>
namespace aria2 {

View File

@ -37,6 +37,7 @@
#include "OptionHandler.h"
#include "DlAbortEx.h"
#include <strings.h>
namespace aria2 {

View File

@ -83,8 +83,8 @@ bool PeerAbstractCommand::execute() {
uploadLimitCheck && (uploadLimit == 0 ||
e->getUploadSpeed() <= uploadLimit*1024) ||
*/
checkSocketIsReadable && readCheckTarget->isReadable(0) ||
checkSocketIsWritable && writeCheckTarget->isWritable(0)) {
(checkSocketIsReadable && readCheckTarget->isReadable(0)) ||
(checkSocketIsWritable && writeCheckTarget->isWritable(0))) {
checkPoint.reset();
}
if(checkPoint.elapsed(timeout)) {

View File

@ -37,6 +37,7 @@
#include "common.h"
#include "SharedHandle.h"
#include <unistd.h>
namespace aria2 {

View File

@ -218,8 +218,8 @@ bool PeerInteractionCommand::executeInternal() {
if(btInteractive->countReceivedMessageInIteration() > 0) {
updateKeepAlive();
}
if(peer->amInterested() && !peer->peerChoking() && peer->getLatency() < 1500 ||
peer->peerInterested() && !peer->amChoking()) {
if((peer->amInterested() && !peer->peerChoking() && (peer->getLatency() < 1500)) ||
(peer->peerInterested() && !peer->amChoking())) {
if(maxDownloadSpeedLimit > 0) {
TransferStat stat = peerStorage->calculateStat();
if(maxDownloadSpeedLimit < stat.downloadSpeed) {

View File

@ -38,6 +38,7 @@
#include "common.h"
#include "SharedHandle.h"
#include <stdint.h>
#include <unistd.h>
namespace aria2 {

View File

@ -154,7 +154,7 @@ bool Request::parseUrl(const std::string& url) {
bool Request::isHexNumber(const char c) const
{
return '0' <= c && c <= '9' || 'A' <= c && c <= 'F' || 'a' <= c && c <= 'f';
return ('0' <= c && c <= '9') || ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f');
}
std::string Request::urlencode(const std::string& src) const

View File

@ -321,9 +321,9 @@ bool RequestGroup::downloadFinishedByFileLength()
{
// assuming that a control file doesn't exist.
if(!isPreLocalFileCheckEnabled() ||
_option->get(PREF_ALLOW_OVERWRITE) == V_TRUE ||
_option->get(PREF_CHECK_INTEGRITY) == V_TRUE &&
!_downloadContext->getPieceHashes().empty()) {
(_option->get(PREF_ALLOW_OVERWRITE) == V_TRUE) ||
((_option->get(PREF_CHECK_INTEGRITY) == V_TRUE) &&
!_downloadContext->getPieceHashes().empty())) {
return false;
}
// TODO consider the case when the getFilePath() returns dir path.
@ -882,8 +882,8 @@ void RequestGroup::removeURIWhoseHostnameIs(const std::string& hostname)
std::deque<std::string> newURIs;
Request req;
for(std::deque<std::string>::const_iterator itr = _uris.begin(); itr != _uris.end(); ++itr) {
if((*itr).find(hostname) == std::string::npos ||
req.setUrl(*itr) && req.getHost() != hostname) {
if(((*itr).find(hostname) == std::string::npos) ||
(req.setUrl(*itr) && (req.getHost() != hostname))) {
newURIs.push_back(*itr);
}
}

View File

@ -37,6 +37,7 @@
#include "common.h"
#include "SharedHandle.h"
#include <unistd.h>
#include <stdint.h>
#include <deque>

View File

@ -45,6 +45,7 @@
#include "Option.h"
#include "DownloadContext.h"
#include "Piece.h"
#include <algorithm>
namespace aria2 {

View File

@ -40,6 +40,7 @@
#include "a2time.h"
#include <cstdarg>
#include <cerrno>
#include <cstring>
namespace aria2 {

View File

@ -36,6 +36,7 @@
#include "BinaryStream.h"
#include "Util.h"
#include "a2io.h"
#include <cstring>
namespace aria2 {

View File

@ -38,6 +38,7 @@
#include "common.h"
#include "a2netcompat.h"
#include "a2time.h"
#include <cstdlib>
#include <string>
#include <utility>

View File

@ -40,6 +40,7 @@
#include "DownloadContext.h"
#include "Piece.h"
#include "FileEntry.h"
#include <stdlib.h>
namespace aria2 {
@ -70,6 +71,21 @@ void UnknownLengthPieceStorage::initStorage()
_diskAdaptor->setFileEntries(_downloadContext->getFileEntries());
}
bool UnknownLengthPieceStorage::hasMissingPiece(const SharedHandle<Peer>& peer)
{
abort();
}
SharedHandle<Piece> UnknownLengthPieceStorage::getMissingPiece(const SharedHandle<Peer>& peer)
{
abort();
}
SharedHandle<Piece> UnknownLengthPieceStorage::getMissingFastPiece(const SharedHandle<Peer>& peer)
{
abort();
}
PieceHandle UnknownLengthPieceStorage::getMissingPiece()
{
if(_downloadFinished) {
@ -163,6 +179,18 @@ void UnknownLengthPieceStorage::markAllPiecesDone()
_downloadFinished = true;
}
void UnknownLengthPieceStorage::markPiecesDone(uint64_t length)
{
// TODO not implemented yet
abort();
}
void UnknownLengthPieceStorage::markPieceMissing(size_t index)
{
// TODO not implemented yet
abort();
}
Pieces UnknownLengthPieceStorage::getInFlightPieces()
{
return Pieces();

View File

@ -69,10 +69,7 @@ public:
* Returns true if the peer has a piece that localhost doesn't have.
* Otherwise returns false.
*/
virtual bool hasMissingPiece(const SharedHandle<Peer>& peer)
{
abort();
}
virtual bool hasMissingPiece(const SharedHandle<Peer>& peer);
/**
* Returns a piece that the peer has but localhost doesn't.
@ -80,10 +77,8 @@ public:
* from get the same piece. But in end game mode, same piece may be returned
* to several commands.
*/
virtual SharedHandle<Piece> getMissingPiece(const SharedHandle<Peer>& peer)
{
abort();
}
virtual SharedHandle<Piece> getMissingPiece(const SharedHandle<Peer>& peer);
/**
* Returns a piece that the peer has but localhost doesn't.
* Only pieces that declared as "fast" are returned.
@ -91,10 +86,8 @@ public:
* from get the same piece. But in end game mode, same piece may be returned
* to several commands.
*/
virtual SharedHandle<Piece> getMissingFastPiece(const SharedHandle<Peer>& peer)
{
abort();
}
virtual SharedHandle<Piece> getMissingFastPiece(const SharedHandle<Peer>& peer);
/**
* Returns a missing piece if available. Otherwise returns 0;
*/
@ -240,17 +233,9 @@ public:
*/
virtual void markAllPiecesDone();
virtual void markPiecesDone(uint64_t length)
{
// TODO not implemented yet
abort();
}
virtual void markPiecesDone(uint64_t length);
virtual void markPieceMissing(size_t index)
{
// TODO not implemented yet
abort();
}
virtual void markPieceMissing(size_t index);
/**
* Do nothing because loading in-flight piece is not supported for this

View File

@ -100,7 +100,8 @@ std::pair<std::string, std::string> Util::split(const std::string& src, const st
}
int64_t Util::difftv(struct timeval tv1, struct timeval tv2) {
if(tv1.tv_sec < tv2.tv_sec || tv1.tv_sec == tv2.tv_sec && tv1.tv_usec < tv2.tv_usec) {
if((tv1.tv_sec < tv2.tv_sec) ||
((tv1.tv_sec == tv2.tv_sec) && (tv1.tv_usec < tv2.tv_usec))) {
return 0;
}
return ((int64_t)(tv1.tv_sec-tv2.tv_sec)*1000000+
@ -187,9 +188,9 @@ std::string Util::replace(const std::string& target, const std::string& oldstr,
bool Util::shouldUrlencode(const char c)
{
return !(// ALPHA
'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' ||
('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') ||
// DIGIT
'0' <= c && c <= '9' ||
('0' <= c && c <= '9') ||
// safe
'$' == c || '-' == c || '_' == c || '.' == c ||
// extra
@ -218,9 +219,9 @@ std::string Util::urlencode(const unsigned char* target, size_t len) {
std::string Util::torrentUrlencode(const unsigned char* target, size_t len) {
std::string dest;
for(size_t i = 0; i < len; i++) {
if('0' <= target[i] && target[i] <= '9' ||
'A' <= target[i] && target[i] <= 'Z' ||
'a' <= target[i] && target[i] <= 'z') {
if(('0' <= target[i] && target[i] <= '9') ||
('A' <= target[i] && target[i] <= 'Z') ||
('a' <= target[i] && target[i] <= 'z')) {
dest += target[i];
} else {
char temp[4];
@ -409,7 +410,9 @@ int32_t Util::parseInt(const std::string& s, int32_t base)
if(*stop != '\0') {
throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE,
trimed.c_str());
} else if((v == LONG_MIN || v == LONG_MAX) && errno == ERANGE || v > INT32_MAX || v < INT32_MIN) {
} else if((((v == LONG_MIN) || (v == LONG_MAX)) && (errno == ERANGE)) ||
(v > INT32_MAX) ||
(v < INT32_MIN)) {
throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE,
trimed.c_str());
}
@ -434,7 +437,7 @@ uint32_t Util::parseUInt(const std::string& s, int base)
if(*stop != '\0') {
throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE,
trimed.c_str());
} else if((v == ULONG_MAX) && errno == ERANGE || v > UINT32_MAX) {
} else if(((v == ULONG_MAX) && (errno == ERANGE)) || (v > UINT32_MAX)) {
throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE,
trimed.c_str());
}
@ -454,7 +457,32 @@ int64_t Util::parseLLInt(const std::string& s, int32_t base)
if(*stop != '\0') {
throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE,
trimed.c_str());
} else if((v == INT64_MIN || v == INT64_MAX) && errno == ERANGE) {
} else if(((v == INT64_MIN) || (v == INT64_MAX)) && (errno == ERANGE)) {
throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE,
trimed.c_str());
}
return v;
}
uint64_t Util::parseULLInt(const std::string& s, int base)
{
std::string trimed = Util::trim(s);
if(trimed.empty()) {
throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE,
"empty string");
}
// We don't allow negative number.
if(trimed[0] == '-') {
throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE,
trimed.c_str());
}
char* stop;
errno = 0;
uint64_t v = strtoull(trimed.c_str(), &stop, base);
if(*stop != '\0') {
throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE,
trimed.c_str());
} else if((v == ULLONG_MAX) && (errno == ERANGE)) {
throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE,
trimed.c_str());
}
@ -621,7 +649,7 @@ int64_t Util::getRealSize(const std::string& sizeWithUnit)
if(v < 0) {
throw new DlAbortEx("Negative value detected: %s", sizeWithUnit.c_str());
} else if(v*mult < 0) {
} else if(INT64_MAX/mult < v) {
throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE,
"overflow/underflow");
}

View File

@ -168,10 +168,12 @@ public:
static int32_t parseInt(const std::string& s, int32_t base = 10);
static unsigned int parseUInt(const std::string& s, int base = 10);
static uint32_t parseUInt(const std::string& s, int base = 10);
static int64_t parseLLInt(const std::string& s, int32_t base = 10);
static uint64_t parseULLInt(const std::string& s, int base = 10);
static IntSequence parseIntRange(const std::string& src);
// this function temporarily put here

View File

@ -35,6 +35,7 @@
#ifndef _D_ARRAY_FUN_H_
#define _D_ARRAY_FUN_H_
#include <cstdlib>
#include <functional>
namespace aria2 {
@ -62,7 +63,7 @@ class array_function_base {
public:
virtual ~array_function_base() {}
virtual R operator[](std::size_t index) const = 0;
virtual R operator[](size_t index) const = 0;
virtual array_function_base* clone() const = 0;
};
@ -75,7 +76,7 @@ private:
public:
array_unary_function(A a, F f):_a(a), _f(f) {}
virtual typename F::result_type operator[](std::size_t index) const
virtual typename F::result_type operator[](size_t index) const
{
return _f(_a[index]);
}
@ -95,7 +96,7 @@ private:
public:
array_binary_function(A a, B b, F f):_a(a), _b(b), _f(f) {}
virtual typename F::result_type operator[](std::size_t index) const
virtual typename F::result_type operator[](size_t index) const
{
return _f(_a[index], _b[index]);
}
@ -133,7 +134,7 @@ public:
return *this;
}
R operator[](std::size_t index) const
R operator[](size_t index) const
{
return (*_p)[index];
}
@ -199,19 +200,17 @@ array_and(A a, B b)
// calculate length of array
template<typename T, std::size_t N>
template<typename T, size_t N>
char (&char_array_ref(T (&)[N]))[N];
template<typename T, std::size_t N>
std::size_t
arrayLength(T (&a)[N])
template<typename T, size_t N>
size_t arrayLength(T (&a)[N])
{
return sizeof(char_array_ref(a));
}
template<typename T>
std::size_t
arrayLength(T (&a)[0u])
size_t arrayLength(T (&a)[0u])
{
return 0;
}

View File

@ -44,6 +44,7 @@
#include "a2io.h"
#include "help_tags.h"
#include "File.h"
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <iostream>

View File

@ -4,6 +4,7 @@
#include "DHTUtil.h"
#include "Exception.h"
#include "Util.h"
#include <cstring>
#include <cppunit/extensions/HelperMacros.h>
namespace aria2 {

View File

@ -1,5 +1,6 @@
#include "BitfieldMan.h"
#include "FixedNumberRandomizer.h"
#include <cstring>
#include <cppunit/extensions/HelperMacros.h>
namespace aria2 {

View File

@ -2,6 +2,8 @@
#include "DHTNode.h"
#include "Exception.h"
#include "Util.h"
#include <cstring>
#include <algorithm>
#include <cppunit/extensions/HelperMacros.h>
namespace aria2 {

View File

@ -3,6 +3,7 @@
#include "DHTIDCloser.h"
#include "Exception.h"
#include "Util.h"
#include <cstring>
#include <algorithm>
#include <cppunit/extensions/HelperMacros.h>

View File

@ -17,6 +17,7 @@
#include "DHTGetPeersReplyMessage.h"
#include "DHTAnnouncePeerMessage.h"
#include "DHTAnnouncePeerReplyMessage.h"
#include <cstring>
#include <iostream>
#include <cppunit/extensions/HelperMacros.h>

View File

@ -1,6 +1,7 @@
#include "DHTUtil.h"
#include "Exception.h"
#include "Util.h"
#include <cstring>
#include <cppunit/extensions/HelperMacros.h>
namespace aria2 {

View File

@ -4,6 +4,7 @@
#include "AnnounceTier.h"
#include "FixedNumberRandomizer.h"
#include "FileEntry.h"
#include <cstring>
#include <iostream>
#include <cppunit/extensions/HelperMacros.h>

View File

@ -2,6 +2,7 @@
#define _D_FIXED_NUMBER_RANDOMIZER_H_
#include "Randomizer.h"
#include <cstdlib>
namespace aria2 {

View File

@ -4,6 +4,7 @@
#include "BtContext.h"
#include "Util.h"
#include "AnnounceTier.h"
#include <cstring>
namespace aria2 {

View File

@ -2,6 +2,8 @@
#include "FileEntry.h"
#include "Exception.h"
#include <string>
#include <cerrno>
#include <cstring>
#include <cppunit/extensions/HelperMacros.h>
namespace aria2 {
@ -48,12 +50,12 @@ std::deque<SharedHandle<FileEntry> > createEntries() {
void readFile(const std::string& filename, char* buf, int bufLength) {
FILE* f = fopen(filename.c_str(), "r");
if(f == NULL) {
abort();
CPPUNIT_FAIL(strerror(errno));
}
int retval = fread(buf, bufLength, 1, f);
fclose(f);
if(retval != 1) {
abort();
CPPUNIT_FAIL("return value is not 1");
}
}

View File

@ -41,6 +41,7 @@ class UtilTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testParseInt);
CPPUNIT_TEST(testParseUInt);
CPPUNIT_TEST(testParseLLInt);
CPPUNIT_TEST(testParseULLInt);
CPPUNIT_TEST(testToString_binaryStream);
CPPUNIT_TEST(testItos);
CPPUNIT_TEST(testUitos);
@ -78,6 +79,7 @@ public:
void testParseInt();
void testParseUInt();
void testParseLLInt();
void testParseULLInt();
void testToString_binaryStream();
void testItos();
void testUitos();
@ -612,6 +614,26 @@ void UtilTest::testParseLLInt()
}
}
void UtilTest::testParseULLInt()
{
CPPUNIT_ASSERT_EQUAL(18446744073709551615ULL,
Util::parseULLInt("18446744073709551615"));
try {
Util::parseUInt("-1");
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception* e) {
std::cerr << *e;
delete e;
}
try {
Util::parseLLInt("18446744073709551616");
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception* e) {
std::cerr << *e;
delete e;
}
}
void UtilTest::testToString_binaryStream()
{
SharedHandle<DiskWriter> dw = new ByteArrayDiskWriter();