Remove vbegin and vend in favor of std::begin and std::end

pull/103/head
Tatsuhiro Tsujikawa 2013-06-24 21:46:42 +09:00
parent d2ec57057e
commit 10cdc59297
34 changed files with 202 additions and 248 deletions

View File

@ -273,11 +273,11 @@ const char* INTERESTING_HEADER_NAMES[] = {
int idInterestingHeader(const char* hdName)
{
const char** i = std::lower_bound(vbegin(INTERESTING_HEADER_NAMES),
vend(INTERESTING_HEADER_NAMES),
const char** i = std::lower_bound(std::begin(INTERESTING_HEADER_NAMES),
std::end(INTERESTING_HEADER_NAMES),
hdName, util::strless);
if(i != vend(INTERESTING_HEADER_NAMES) && strcmp(*i, hdName) == 0 ) {
return i - vbegin(INTERESTING_HEADER_NAMES);
if(i != std::end(INTERESTING_HEADER_NAMES) && strcmp(*i, hdName) == 0 ) {
return i - std::begin(INTERESTING_HEADER_NAMES);
} else {
return HttpHeader::MAX_INTERESTING_HEADER;
}

View File

@ -73,19 +73,22 @@ CHashFuncEntry hashFuncs[] = {
std::shared_ptr<MessageDigestImpl> MessageDigestImpl::create
(const std::string& hashType)
{
int hashFunc = getHashFunc(vbegin(hashFuncs), vend(hashFuncs), hashType);
int hashFunc = getHashFunc(std::begin(hashFuncs), std::end(hashFuncs),
hashType);
return std::shared_ptr<MessageDigestImpl>(new MessageDigestImpl(hashFunc));
}
bool MessageDigestImpl::supports(const std::string& hashType)
{
return vend(hashFuncs) != std::find_if(vbegin(hashFuncs), vend(hashFuncs),
CFindHashFunc(hashType));
return std::end(hashFuncs) != std::find_if(std::begin(hashFuncs),
std::end(hashFuncs),
CFindHashFunc(hashType));
}
size_t MessageDigestImpl::getDigestLength(const std::string& hashType)
{
int hashFunc = getHashFunc(vbegin(hashFuncs), vend(hashFuncs), hashType);
int hashFunc = getHashFunc(std::begin(hashFuncs), std::end(hashFuncs),
hashType);
return gcry_md_get_algo_dlen(hashFunc);
}

View File

@ -76,20 +76,21 @@ std::shared_ptr<MessageDigestImpl> MessageDigestImpl::create
(const std::string& hashType)
{
const nettle_hash* hashInfo =
getHashFunc(vbegin(hashFuncs), vend(hashFuncs), hashType);
getHashFunc(std::begin(hashFuncs), std::end(hashFuncs), hashType);
return std::shared_ptr<MessageDigestImpl>(new MessageDigestImpl(hashInfo));
}
bool MessageDigestImpl::supports(const std::string& hashType)
{
return vend(hashFuncs) != std::find_if(vbegin(hashFuncs), vend(hashFuncs),
CFindHashFunc(hashType));
return std::end(hashFuncs) != std::find_if(std::begin(hashFuncs),
std::end(hashFuncs),
CFindHashFunc(hashType));
}
size_t MessageDigestImpl::getDigestLength(const std::string& hashType)
{
const nettle_hash* hashInfo =
getHashFunc(vbegin(hashFuncs), vend(hashFuncs), hashType);
getHashFunc(std::begin(hashFuncs), std::end(hashFuncs), hashType);
return hashInfo->digest_size;
}

View File

@ -82,20 +82,23 @@ CHashFuncEntry hashFuncs[] = {
std::shared_ptr<MessageDigestImpl> MessageDigestImpl::create
(const std::string& hashType)
{
const EVP_MD* hashFunc = getHashFunc(vbegin(hashFuncs), vend(hashFuncs),
const EVP_MD* hashFunc = getHashFunc(std::begin(hashFuncs),
std::end(hashFuncs),
hashType);
return std::shared_ptr<MessageDigestImpl>(new MessageDigestImpl(hashFunc));
}
bool MessageDigestImpl::supports(const std::string& hashType)
{
return vend(hashFuncs) != std::find_if(vbegin(hashFuncs), vend(hashFuncs),
CFindHashFunc(hashType));
return std::end(hashFuncs) != std::find_if(std::begin(hashFuncs),
std::end(hashFuncs),
CFindHashFunc(hashType));
}
size_t MessageDigestImpl::getDigestLength(const std::string& hashType)
{
const EVP_MD* hashFunc = getHashFunc(vbegin(hashFuncs), vend(hashFuncs),
const EVP_MD* hashFunc = getHashFunc(std::begin(hashFuncs),
std::end(hashFuncs),
hashType);
return EVP_MD_size(hashFunc);
}

View File

@ -91,10 +91,9 @@ bool MessageDigest::supports(const std::string& hashType)
std::vector<std::string> MessageDigest::getSupportedHashTypes()
{
std::vector<std::string> rv;
for (HashTypeEntry *i = vbegin(hashTypes), *eoi = vend(hashTypes);
i != eoi; ++i) {
if (MessageDigestImpl::supports(i->hashType)) {
rv.push_back(i->hashType);
for (const auto& i : hashTypes) {
if (MessageDigestImpl::supports(i.hashType)) {
rv.push_back(i.hashType);
}
}
return rv;
@ -134,11 +133,13 @@ public:
bool MessageDigest::isStronger(const std::string& lhs, const std::string& rhs)
{
HashTypeEntry* lEntry = std::find_if(vbegin(hashTypes), vend(hashTypes),
HashTypeEntry* lEntry = std::find_if(std::begin(hashTypes),
std::end(hashTypes),
FindHashTypeEntry(lhs));
HashTypeEntry* rEntry = std::find_if(vbegin(hashTypes), vend(hashTypes),
HashTypeEntry* rEntry = std::find_if(std::begin(hashTypes),
std::end(hashTypes),
FindHashTypeEntry(rhs));
if(lEntry == vend(hashTypes) || rEntry == vend(hashTypes)) {
if(lEntry == std::end(hashTypes) || rEntry == std::end(hashTypes)) {
return false;
}
return lEntry->strength > rEntry->strength;

View File

@ -220,8 +220,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
(PREF_CONSOLE_LOG_LEVEL,
TEXT_CONSOLE_LOG_LEVEL,
V_NOTICE,
std::vector<std::string>
(vbegin(logLevels), vend(logLevels))));
{std::begin(logLevels), std::end(logLevels)}));
op->addTag(TAG_ADVANCED);
handlers.push_back(op);
}
@ -479,8 +478,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
(PREF_LOG_LEVEL,
TEXT_LOG_LEVEL,
V_DEBUG,
std::vector<std::string>
(vbegin(logLevels), vend(logLevels))));
{std::begin(logLevels), std::end(logLevels)}));
op->addTag(TAG_ADVANCED);
op->setChangeGlobalOption(true);
handlers.push_back(op);

View File

@ -226,9 +226,8 @@ Time Time::parseHTTPDate(const std::string& datetime)
&parseAsctime,
&parseRFC850Ext,
};
for(Time (**funcsp)(const std::string&) = &funcs[0];
funcsp != vend(funcs); ++funcsp) {
Time t = (*funcsp)(datetime);
for(auto func : funcs) {
Time t = func(datetime);
if(t.good()) {
return t;
}

View File

@ -53,18 +53,6 @@ char (&char_array_ref_fun(T (&)[0u]))[0u];
// To calculate size of array at compile time, we use macro here.
#define A2_ARRAY_LEN(X) sizeof(char_array_ref_fun(X))
template<typename T, size_t N>
T* vbegin(T (&a)[N])
{
return a;
}
template<typename T, size_t N>
T* vend(T (&a)[N])
{
return a+N;
}
template<typename T>
class array_ptr {
private:

View File

@ -71,11 +71,12 @@ const char* strHelpTag(uint32_t tag)
uint32_t idHelpTag(const char* tagName)
{
for(const char** p = vbegin(HELP_TAG_NAMES), ** eop = vend(HELP_TAG_NAMES);
p != eop; ++p) {
if(strcmp(*p, tagName) == 0) {
return p - vbegin(HELP_TAG_NAMES);
uint32_t id = 0;
for(auto p : HELP_TAG_NAMES) {
if(strcmp(p, tagName) == 0) {
return id;
}
++id;
}
return MAX_HELP_TAG;
}

View File

@ -295,14 +295,16 @@ bool inRFC3986ReservedChars(const char c)
':' , '/' , '?' , '#' , '[' , ']' , '@',
'!' , '$' , '&' , '\'' , '(' , ')',
'*' , '+' , ',' , ';' , '=' };
return std::find(vbegin(reserved), vend(reserved), c) != vend(reserved);
return std::find(std::begin(reserved), std::end(reserved), c)
!= std::end(reserved);
}
bool inRFC3986UnreservedChars(const char c)
{
static const char unreserved[] = { '-', '.', '_', '~' };
return isAlpha(c) || isDigit(c) ||
std::find(vbegin(unreserved), vend(unreserved), c) != vend(unreserved);
std::find(std::begin(unreserved), std::end(unreserved), c)
!= std::end(unreserved);
}
bool inRFC2978MIMECharset(const char c)
@ -313,7 +315,7 @@ bool inRFC2978MIMECharset(const char c)
'`', '{', '}', '~'
};
return isAlpha(c) || isDigit(c) ||
std::find(vbegin(chars), vend(chars), c) != vend(chars);
std::find(std::begin(chars), std::end(chars), c) != std::end(chars);
}
bool inRFC2616HttpToken(const char c)
@ -323,7 +325,7 @@ bool inRFC2616HttpToken(const char c)
'^', '_', '`', '|', '~'
};
return isAlpha(c) || isDigit(c) ||
std::find(vbegin(chars), vend(chars), c) != vend(chars);
std::find(std::begin(chars), std::end(chars), c) != std::end(chars);
}
bool inRFC5987AttrChar(const char c)
@ -1663,9 +1665,9 @@ std::string escapePath(const std::string& s)
unsigned char c = *i;
if(in(c, 0x00u, 0x1fu) || c == 0x7fu
#ifdef __MINGW32__
|| std::find(vbegin(WIN_INVALID_PATH_CHARS),
vend(WIN_INVALID_PATH_CHARS),
c) != vend(WIN_INVALID_PATH_CHARS)
|| std::find(std::begin(WIN_INVALID_PATH_CHARS),
std::end(WIN_INVALID_PATH_CHARS),
c) != std::end(WIN_INVALID_PATH_CHARS)
#endif // __MINGW32__
){
d += fmt("%%%02X", c);

View File

@ -322,16 +322,14 @@ void BittorrentHelperTest::testComputeFastSet()
std::vector<size_t> fastSet;
computeFastSet(fastSet, ipaddr, numPieces, infoHash, fastSetSize);
size_t ans[] = { 686, 459, 278, 200, 404, 834, 64, 203, 760, 950 };
std::vector<size_t> ansSet(vbegin(ans), vend(ans));
CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet.begin()));
CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), std::begin(ans)));
}
ipaddr = "10.0.0.1";
{
std::vector<size_t> fastSet;
computeFastSet(fastSet, ipaddr, numPieces, infoHash, fastSetSize);
size_t ans[] = { 568, 188, 466, 452, 550, 662, 109, 226, 398, 11 };
std::vector<size_t> ansSet(vbegin(ans), vend(ans));
CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet.begin()));
CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), std::begin(ans)));
}
// See when pieces < fastSetSize
numPieces = 9;
@ -339,8 +337,7 @@ void BittorrentHelperTest::testComputeFastSet()
std::vector<size_t> fastSet;
computeFastSet(fastSet, ipaddr, numPieces, infoHash, fastSetSize);
size_t ans[] = { 8, 6, 7, 5, 1, 4, 0, 2, 3 };
std::vector<size_t> ansSet(vbegin(ans), vend(ans));
CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet.begin()));
CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), std::begin(ans)));
}
}

View File

@ -39,14 +39,13 @@ void DHTRoutingTableDeserializerTest::testDeserialize()
{
std::shared_ptr<DHTNode> localNode(new DHTNode());
std::shared_ptr<DHTNode> nodesSrc[3];
for(size_t i = 0; i < A2_ARRAY_LEN(nodesSrc); ++i) {
nodesSrc[i].reset(new DHTNode());
nodesSrc[i]->setIPAddress("192.168.0."+util::uitos(i+1));
nodesSrc[i]->setPort(6881+i);
std::vector<std::shared_ptr<DHTNode> > nodes(3);
for(size_t i = 0; i < nodes.size(); ++i) {
nodes[i].reset(new DHTNode());
nodes[i]->setIPAddress("192.168.0."+util::uitos(i+1));
nodes[i]->setPort(6881+i);
}
nodesSrc[1]->setIPAddress("non-numerical-name");
std::vector<std::shared_ptr<DHTNode> > nodes(vbegin(nodesSrc), vend(nodesSrc));
nodes[1]->setIPAddress("non-numerical-name");
DHTRoutingTableSerializer s(AF_INET);
s.setLocalNode(localNode);
@ -77,14 +76,13 @@ void DHTRoutingTableDeserializerTest::testDeserialize6()
{
std::shared_ptr<DHTNode> localNode(new DHTNode());
std::shared_ptr<DHTNode> nodesSrc[3];
for(size_t i = 0; i < A2_ARRAY_LEN(nodesSrc); ++i) {
nodesSrc[i].reset(new DHTNode());
nodesSrc[i]->setIPAddress("2001::100"+util::uitos(i+1));
nodesSrc[i]->setPort(6881+i);
std::vector<std::shared_ptr<DHTNode>> nodes(3);
for(size_t i = 0; i < nodes.size(); ++i) {
nodes[i].reset(new DHTNode());
nodes[i]->setIPAddress("2001::100"+util::uitos(i+1));
nodes[i]->setPort(6881+i);
}
nodesSrc[1]->setIPAddress("non-numerical-name");
std::vector<std::shared_ptr<DHTNode> > nodes(vbegin(nodesSrc), vend(nodesSrc));
nodes[1]->setIPAddress("non-numerical-name");
DHTRoutingTableSerializer s(AF_INET6);
s.setLocalNode(localNode);

View File

@ -100,14 +100,13 @@ void DHTRoutingTableSerializerTest::testSerialize()
{
std::shared_ptr<DHTNode> localNode(new DHTNode());
std::shared_ptr<DHTNode> nodesSrc[3];
for(size_t i = 0; i < A2_ARRAY_LEN(nodesSrc); ++i) {
nodesSrc[i].reset(new DHTNode());
nodesSrc[i]->setIPAddress("192.168.0."+util::uitos(i+1));
nodesSrc[i]->setPort(6881+i);
std::vector<std::shared_ptr<DHTNode>> nodes(3);
for(size_t i = 0; i < nodes.size(); ++i) {
nodes[i].reset(new DHTNode());
nodes[i]->setIPAddress("192.168.0."+util::uitos(i+1));
nodes[i]->setPort(6881+i);
}
nodesSrc[1]->setIPAddress("non-numerical-name");
std::vector<std::shared_ptr<DHTNode> > nodes(vbegin(nodesSrc), vend(nodesSrc));
nodes[1]->setIPAddress("non-numerical-name");
DHTRoutingTableSerializer s(AF_INET);
s.setLocalNode(localNode);
@ -228,14 +227,13 @@ void DHTRoutingTableSerializerTest::testSerialize6()
{
std::shared_ptr<DHTNode> localNode(new DHTNode());
std::shared_ptr<DHTNode> nodesSrc[2];
for(size_t i = 0; i < A2_ARRAY_LEN(nodesSrc); ++i) {
nodesSrc[i].reset(new DHTNode());
nodesSrc[i]->setIPAddress("2001::100"+util::uitos(i+1));
nodesSrc[i]->setPort(6881+i);
std::vector<std::shared_ptr<DHTNode>> nodes(2);
for(size_t i = 0; i < nodes.size(); ++i) {
nodes[i].reset(new DHTNode());
nodes[i]->setIPAddress("2001::100"+util::uitos(i+1));
nodes[i]->setPort(6881+i);
}
nodesSrc[1]->setIPAddress("non-numerical-name");
std::vector<std::shared_ptr<DHTNode> > nodes(vbegin(nodesSrc), vend(nodesSrc));
nodes[1]->setIPAddress("non-numerical-name");
DHTRoutingTableSerializer s(AF_INET6);
s.setLocalNode(localNode);

View File

@ -63,7 +63,7 @@ public:
dctx_.reset(new DownloadContext(pieceLength, totalLength));
{
auto torrentAttrs = make_unique<TorrentAttribute>();
torrentAttrs->infoHash = std::string(vbegin(infoHash), vend(infoHash));
torrentAttrs->infoHash.assign(std::begin(infoHash), std::end(infoHash));
dctx_->setAttribute(CTX_ATTR_BT, std::move(torrentAttrs));
}
dctx_->getNetStat().updateDownloadLength(pieceLength*5);
@ -342,7 +342,7 @@ void DefaultBtAnnounceTest::testURLOrderInStoppedEvent()
"http://localhost2/announce" };
std::shared_ptr<List> announceList = List::g();
announceList->append(createAnnounceTier(vbegin(urls), vend(urls)));
announceList->append(createAnnounceTier(std::begin(urls), std::end(urls)));
setAnnounceList(dctx_, announceList);
DefaultBtAnnounce btAnnounce(dctx_.get(), option_);
@ -373,7 +373,7 @@ void DefaultBtAnnounceTest::testURLOrderInCompletedEvent()
"http://localhost2/announce" };
std::shared_ptr<List> announceList = List::g();
announceList->append(createAnnounceTier(vbegin(urls), vend(urls)));
announceList->append(createAnnounceTier(std::begin(urls), std::end(urls)));
setAnnounceList(dctx_, announceList);
DefaultBtAnnounce btAnnounce(dctx_.get(), option_);

View File

@ -72,13 +72,13 @@ public:
dctx_.reset(new DownloadContext());
{
auto torrentAttrs = make_unique<TorrentAttribute>();
torrentAttrs->infoHash = std::string(vbegin(infoHash), vend(infoHash));
torrentAttrs->infoHash.assign(std::begin(infoHash), std::end(infoHash));
dctx_->setAttribute(CTX_ATTR_BT, std::move(torrentAttrs));
}
const std::shared_ptr<FileEntry> fileEntries[] = {
std::shared_ptr<FileEntry>(new FileEntry("/path/to/file",totalLength,0))
};
dctx_->setFileEntries(vbegin(fileEntries), vend(fileEntries));
dctx_->setFileEntries(std::begin(fileEntries), std::end(fileEntries));
dctx_->setPieceLength(pieceLength);
peerStorage_.reset(new MockPeerStorage());
btRuntime_.reset(new BtRuntime());

View File

@ -41,7 +41,7 @@ void DownloadContextTest::testFindFileEntryByOffset()
std::shared_ptr<FileEntry>(new FileEntry("file5",3000,3000)),
std::shared_ptr<FileEntry>(new FileEntry("file6",0,6000))
};
ctx.setFileEntries(vbegin(fileEntries), vend(fileEntries));
ctx.setFileEntries(std::begin(fileEntries), std::end(fileEntries));
CPPUNIT_ASSERT_EQUAL(std::string("file1"),
ctx.findFileEntryByOffset(0)->getPath());

View File

@ -68,12 +68,11 @@ CPPUNIT_TEST_SUITE_REGISTRATION(DownloadHelperTest);
void DownloadHelperTest::testCreateRequestGroupForUri()
{
std::string array[] = {
std::vector<std::string> uris {
"http://alpha/file",
"http://bravo/file",
"http://charlie/file"
};
std::vector<std::string> uris(vbegin(array), vend(array));
option_->put(PREF_SPLIT, "7");
option_->put(PREF_MAX_CONNECTION_PER_SERVER, "2");
option_->put(PREF_DIR, "/tmp");
@ -87,7 +86,7 @@ void DownloadHelperTest::testCreateRequestGroupForUri()
group->getDownloadContext()->getFirstFileEntry()->getUris(xuris);
CPPUNIT_ASSERT_EQUAL((size_t)6, xuris.size());
for(size_t i = 0; i < 6; ++i) {
CPPUNIT_ASSERT_EQUAL(array[i%3], xuris[i]);
CPPUNIT_ASSERT_EQUAL(uris[i%3], xuris[i]);
}
CPPUNIT_ASSERT_EQUAL(7, group->getNumConcurrentCommand());
std::shared_ptr<DownloadContext> ctx = group->getDownloadContext();
@ -103,7 +102,7 @@ void DownloadHelperTest::testCreateRequestGroupForUri()
group->getDownloadContext()->getFirstFileEntry()->getUris(xuris);
CPPUNIT_ASSERT_EQUAL((size_t)5, xuris.size());
for(size_t i = 0; i < 5; ++i) {
CPPUNIT_ASSERT_EQUAL(array[i%3], xuris[i]);
CPPUNIT_ASSERT_EQUAL(uris[i%3], xuris[i]);
}
}
option_->put(PREF_SPLIT, "2");
@ -116,7 +115,7 @@ void DownloadHelperTest::testCreateRequestGroupForUri()
group->getDownloadContext()->getFirstFileEntry()->getUris(xuris);
CPPUNIT_ASSERT_EQUAL((size_t)3, xuris.size());
for(size_t i = 0; i < 3; ++i) {
CPPUNIT_ASSERT_EQUAL(array[i%3], xuris[i]);
CPPUNIT_ASSERT_EQUAL(uris[i%3], xuris[i]);
}
}
option_->put(PREF_FORCE_SEQUENTIAL, A2_V_TRUE);
@ -130,7 +129,7 @@ void DownloadHelperTest::testCreateRequestGroupForUri()
alphaGroup->getDownloadContext()->getFirstFileEntry()->getUris(alphaURIs);
CPPUNIT_ASSERT_EQUAL((size_t)2, alphaURIs.size());
for(size_t i = 0; i < 2; ++i) {
CPPUNIT_ASSERT_EQUAL(array[0], alphaURIs[i]);
CPPUNIT_ASSERT_EQUAL(uris[0], alphaURIs[i]);
}
CPPUNIT_ASSERT_EQUAL(2, alphaGroup->getNumConcurrentCommand());
std::shared_ptr<DownloadContext> alphaCtx = alphaGroup->getDownloadContext();
@ -141,11 +140,10 @@ void DownloadHelperTest::testCreateRequestGroupForUri()
void DownloadHelperTest::testCreateRequestGroupForUri_parameterized()
{
std::string array[] = {
std::vector<std::string> uris {
"http://{alpha, bravo}/file",
"http://charlie/file"
};
std::vector<std::string> uris(vbegin(array), vend(array));
option_->put(PREF_MAX_CONNECTION_PER_SERVER, "1");
option_->put(PREF_SPLIT, "3");
option_->put(PREF_DIR, "/tmp");
@ -175,13 +173,12 @@ void DownloadHelperTest::testCreateRequestGroupForUri_parameterized()
#ifdef ENABLE_BITTORRENT
void DownloadHelperTest::testCreateRequestGroupForUri_BitTorrent()
{
std::string array[] = {
std::vector<std::string> uris {
"http://alpha/file",
A2_TEST_DIR"/test.torrent",
A2_TEST_DIR "/test.torrent",
"http://bravo/file",
"http://charlie/file"
};
std::vector<std::string> uris(vbegin(array), vend(array));
option_->put(PREF_MAX_CONNECTION_PER_SERVER, "1");
option_->put(PREF_SPLIT, "3");
option_->put(PREF_DIR, "/tmp");
@ -197,9 +194,9 @@ void DownloadHelperTest::testCreateRequestGroupForUri_BitTorrent()
group->getDownloadContext()->getFirstFileEntry()->getUris(xuris);
CPPUNIT_ASSERT_EQUAL((size_t)3, xuris.size());
CPPUNIT_ASSERT_EQUAL(array[0], xuris[0]);
CPPUNIT_ASSERT_EQUAL(array[2], xuris[1]);
CPPUNIT_ASSERT_EQUAL(array[3], xuris[2]);
CPPUNIT_ASSERT_EQUAL(uris[0], xuris[0]);
CPPUNIT_ASSERT_EQUAL(uris[2], xuris[1]);
CPPUNIT_ASSERT_EQUAL(uris[3], xuris[2]);
CPPUNIT_ASSERT_EQUAL(3, group->getNumConcurrentCommand());
std::shared_ptr<DownloadContext> ctx = group->getDownloadContext();
@ -221,13 +218,12 @@ void DownloadHelperTest::testCreateRequestGroupForUri_BitTorrent()
#ifdef ENABLE_METALINK
void DownloadHelperTest::testCreateRequestGroupForUri_Metalink()
{
std::string array[] = {
std::vector<std::string> uris {
"http://alpha/file",
"http://bravo/file",
"http://charlie/file",
A2_TEST_DIR"/test.xml"
A2_TEST_DIR "/test.xml"
};
std::vector<std::string> uris(vbegin(array), vend(array));
option_->put(PREF_MAX_CONNECTION_PER_SERVER, "1");
option_->put(PREF_SPLIT, "2");
option_->put(PREF_DIR, "/tmp");
@ -250,7 +246,7 @@ void DownloadHelperTest::testCreateRequestGroupForUri_Metalink()
group->getDownloadContext()->getFirstFileEntry()->getUris(xuris);
CPPUNIT_ASSERT_EQUAL((size_t)3, xuris.size());
for(size_t i = 0; i < 3; ++i) {
CPPUNIT_ASSERT_EQUAL(array[i], xuris[i]);
CPPUNIT_ASSERT_EQUAL(uris[i], xuris[i]);
}
CPPUNIT_ASSERT_EQUAL(2, group->getNumConcurrentCommand());
std::shared_ptr<DownloadContext> ctx = group->getDownloadContext();
@ -305,13 +301,12 @@ void DownloadHelperTest::testCreateRequestGroupForUriList()
#ifdef ENABLE_BITTORRENT
void DownloadHelperTest::testCreateRequestGroupForBitTorrent()
{
std::string array[] = {
std::vector<std::string> auxURIs {
"http://alpha/file",
"http://bravo/file",
"http://charlie/file"
};
std::vector<std::string> auxURIs(vbegin(array), vend(array));
option_->put(PREF_MAX_CONNECTION_PER_SERVER, "2");
option_->put(PREF_SPLIT, "5");
option_->put(PREF_TORRENT_FILE, A2_TEST_DIR"/test.torrent");
@ -332,8 +327,8 @@ void DownloadHelperTest::testCreateRequestGroupForBitTorrent()
// See -s option is ignored. See processRootDictionary() in
// bittorrent_helper.cc
CPPUNIT_ASSERT_EQUAL((size_t)3, uris.size());
for(size_t i = 0; i < A2_ARRAY_LEN(array); ++i) {
CPPUNIT_ASSERT_EQUAL(array[i]+"/aria2-test/aria2/src/aria2c", uris[i]);
for(size_t i = 0; i < auxURIs.size(); ++i) {
CPPUNIT_ASSERT_EQUAL(auxURIs[i]+"/aria2-test/aria2/src/aria2c", uris[i]);
}
CPPUNIT_ASSERT_EQUAL(5, group->getNumConcurrentCommand());
auto attrs = bittorrent::getTorrentAttrs(group->getDownloadContext());

View File

@ -79,7 +79,8 @@ void FeatureConfigTest::testFeatureSummary() {
};
std::string featuresString = strjoin(vbegin(features), vend(features), ", ");
std::string featuresString = strjoin(std::begin(features),
std::end(features), ", ");
CPPUNIT_ASSERT_EQUAL(featuresString, featureSummary());
}

View File

@ -29,15 +29,11 @@ private:
public:
void setUp()
{
static const char* urisSrc[] = {
"http://alpha/file",
"ftp://alpha/file",
"http://bravo/file"
};
std::vector<std::string> uris;
uris.assign(vbegin(urisSrc), vend(urisSrc));
fileEntry_.setUris(uris);
fileEntry_.setUris({
"http://alpha/file",
"ftp://alpha/file",
"http://bravo/file"
});
ssm.reset(new ServerStatMan());
sel.reset(new FeedbackURISelector(ssm));

View File

@ -74,9 +74,8 @@ void GroupIdTest::testExpandUnique()
GroupId::import(0xff80000000020001LL),
GroupId::import(0xfff8000000030000LL)
};
for(std::shared_ptr<GroupId>* i = vbegin(ids), *eoi = vend(ids); i != eoi;
++i) {
CPPUNIT_ASSERT(*i);
for(const auto& i : ids) {
CPPUNIT_ASSERT(i);
}
CPPUNIT_ASSERT_EQUAL((int)GroupId::ERR_NOT_UNIQUE,

View File

@ -254,12 +254,12 @@ void IndexedListTest::testInsert_keyFunc()
};
size_t slen = sizeof(s)/sizeof(s[0]);
IndexedList<int, std::shared_ptr<std::string> > list;
list.insert(list.begin(), KeyFunc(0), vbegin(s), vend(s));
list.insert(list.begin(), KeyFunc(0), std::begin(s), std::end(s));
CPPUNIT_ASSERT_EQUAL((size_t)slen, list.size());
for(size_t i = 0; i < slen; ++i) {
CPPUNIT_ASSERT_EQUAL(*s[i], *list.get(i));
}
list.insert(list.begin()+2, KeyFunc(slen), vbegin(s), vend(s));
list.insert(list.begin()+2, KeyFunc(slen), std::begin(s), std::end(s));
CPPUNIT_ASSERT_EQUAL((size_t)slen*2, list.size());
for(size_t i = slen; i < slen*2; ++i) {
CPPUNIT_ASSERT_EQUAL(*s[i - slen], *list.get(i));
@ -275,7 +275,7 @@ void IndexedListTest::testInsert_keyFunc()
CPPUNIT_ASSERT_EQUAL(std::string("c"), *(*itr++));
CPPUNIT_ASSERT_EQUAL(std::string("d"), *(*itr++));
list.insert(list.begin(), KeyFunc(2*slen-1), vbegin(s), vend(s));
list.insert(list.begin(), KeyFunc(2*slen-1), std::begin(s), std::end(s));
CPPUNIT_ASSERT_EQUAL((size_t)slen*3-1, list.size());
itr = list.begin();
CPPUNIT_ASSERT_EQUAL(std::string("b"), *(*itr++));
@ -319,8 +319,8 @@ void IndexedListTest::testIterator()
IndexedList<int, int*> list;
IndexedList<int, int*>::iterator itr;
IndexedList<int, int*>::const_iterator citr;
for(int *i = vbegin(a); i < vend(a); ++i) {
CPPUNIT_ASSERT(list.push_back(*i, i));
for(auto& i : a) {
CPPUNIT_ASSERT(list.push_back(i, &i));
}
CPPUNIT_ASSERT(list.begin() == list.begin());
itr = list.begin();
@ -417,8 +417,8 @@ void IndexedListTest::testRemoveIf()
{
int a[] = {0,1,2,3,4,5,6,7,8,9};
IndexedList<int, int*> list;
for(int *i = vbegin(a); i < vend(a); ++i) {
CPPUNIT_ASSERT(list.push_back(*i, i));
for(auto& i : a) {
CPPUNIT_ASSERT(list.push_back(i, &i));
}
list.remove_if(RemoveOdd());
CPPUNIT_ASSERT_EQUAL((size_t)5, list.size());

View File

@ -22,15 +22,11 @@ private:
public:
void setUp()
{
static const char* urisSrc[] = {
fileEntry_.setUris({
"http://alpha/file",
"ftp://alpha/file",
"http://bravo/file"
};
std::vector<std::string> uris;
uris.assign(vbegin(urisSrc), vend(urisSrc));
fileEntry_.setUris(uris);
});
sel.reset(new InorderURISelector());
}

View File

@ -35,7 +35,7 @@ public:
memset(infoHash, 0, sizeof(infoHash));
{
auto torrentAttrs = make_unique<TorrentAttribute>();
torrentAttrs->infoHash = std::string(vbegin(infoHash), vend(infoHash));
torrentAttrs->infoHash.assign(std::begin(infoHash), std::end(infoHash));
dctx_->setAttribute(CTX_ATTR_BT, std::move(torrentAttrs));
}
}

View File

@ -47,17 +47,18 @@ public:
CPPUNIT_TEST_SUITE_REGISTRATION( MultiDiskAdaptorTest );
std::vector<std::shared_ptr<FileEntry> > createEntries() {
std::shared_ptr<FileEntry> array[] = {
std::shared_ptr<FileEntry>(new FileEntry(A2_TEST_OUT_DIR"/file0.txt", 0, 0)),
std::shared_ptr<FileEntry>(new FileEntry(A2_TEST_OUT_DIR"/file1.txt", 15, 0)),
std::shared_ptr<FileEntry>(new FileEntry(A2_TEST_OUT_DIR"/file2.txt", 7, 15)),
std::shared_ptr<FileEntry>(new FileEntry(A2_TEST_OUT_DIR"/file3.txt", 0, 22)),
std::shared_ptr<FileEntry>(new FileEntry(A2_TEST_OUT_DIR"/file4.txt", 2, 22)),
std::shared_ptr<FileEntry>(new FileEntry(A2_TEST_OUT_DIR"/file5.txt", 0, 24)),
std::shared_ptr<FileEntry>(new FileEntry(A2_TEST_OUT_DIR"/file6.txt", 3, 24)),
std::shared_ptr<FileEntry>(new FileEntry(A2_TEST_OUT_DIR"/file7.txt", 0, 27)),
std::shared_ptr<FileEntry>(new FileEntry(A2_TEST_OUT_DIR"/file8.txt", 2, 27)),
std::vector<std::shared_ptr<FileEntry> > createEntries()
{
std::vector<std::shared_ptr<FileEntry>> entries {
std::make_shared<FileEntry>(A2_TEST_OUT_DIR "/file0.txt", 0, 0),
std::make_shared<FileEntry>(A2_TEST_OUT_DIR "/file1.txt", 15, 0),
std::make_shared<FileEntry>(A2_TEST_OUT_DIR "/file2.txt", 7, 15),
std::make_shared<FileEntry>(A2_TEST_OUT_DIR "/file3.txt", 0, 22),
std::make_shared<FileEntry>(A2_TEST_OUT_DIR "/file4.txt", 2, 22),
std::make_shared<FileEntry>(A2_TEST_OUT_DIR "/file5.txt", 0, 24),
std::make_shared<FileEntry>(A2_TEST_OUT_DIR "/file6.txt", 3, 24),
std::make_shared<FileEntry>(A2_TEST_OUT_DIR "/file7.txt", 0, 27),
std::make_shared<FileEntry>(A2_TEST_OUT_DIR "/file8.txt", 2, 27),
};
// 1 1 2 2 3
// 0....5....0....5....0....5....0
@ -71,10 +72,8 @@ std::vector<std::shared_ptr<FileEntry> > createEntries() {
// *** file6
// |file7
// ** file8
std::vector<std::shared_ptr<FileEntry> > entries(vbegin(array), vend(array));
for(std::vector<std::shared_ptr<FileEntry> >::const_iterator i = entries.begin();
i != entries.end(); ++i) {
File((*i)->getPath()).remove();
for(const auto& i : entries) {
File(i->getPath()).remove();
}
return entries;
}
@ -339,14 +338,13 @@ void MultiDiskAdaptorTest::testWriteData() {
CPPUNIT_ASSERT(File(A2_TEST_OUT_DIR"/file5.txt").isFile());
}
void MultiDiskAdaptorTest::testReadData() {
std::shared_ptr<FileEntry> entry1(new FileEntry(A2_TEST_DIR"/file1r.txt", 15, 0));
std::shared_ptr<FileEntry> entry2(new FileEntry(A2_TEST_DIR"/file2r.txt", 7, 15));
std::shared_ptr<FileEntry> entry3(new FileEntry(A2_TEST_DIR"/file3r.txt", 3, 22));
std::vector<std::shared_ptr<FileEntry> > entries;
entries.push_back(entry1);
entries.push_back(entry2);
entries.push_back(entry3);
void MultiDiskAdaptorTest::testReadData()
{
std::vector<std::shared_ptr<FileEntry>> entries {
std::make_shared<FileEntry>(A2_TEST_DIR "/file1r.txt", 15, 0),
std::make_shared<FileEntry>(A2_TEST_DIR "/file2r.txt", 7, 15),
std::make_shared<FileEntry>(A2_TEST_DIR "/file3r.txt", 3, 22)
};
adaptor->setFileEntries(entries.begin(), entries.end());
adaptor->enableReadOnly();
@ -363,22 +361,21 @@ void MultiDiskAdaptorTest::testReadData() {
CPPUNIT_ASSERT_EQUAL(std::string("KLMN"), std::string((char*)buf));
adaptor->readData(buf, 25, 0);
buf[25] = '\0';
CPPUNIT_ASSERT_EQUAL(std::string("1234567890ABCDEFGHIJKLMNO"), std::string((char*)buf));
CPPUNIT_ASSERT_EQUAL(std::string("1234567890ABCDEFGHIJKLMNO"),
std::string((char*)buf));
}
void MultiDiskAdaptorTest::testCutTrailingGarbage()
{
std::string dir = A2_TEST_OUT_DIR;
std::string prefix = "aria2_MultiDiskAdaptorTest_testCutTrailingGarbage_";
std::shared_ptr<FileEntry> entries[] = {
std::shared_ptr<FileEntry>(new FileEntry(dir+"/"+prefix+"1", 256, 0)),
std::shared_ptr<FileEntry>(new FileEntry(dir+"/"+prefix+"2", 512, 256))
std::vector<std::shared_ptr<FileEntry> > fileEntries {
std::make_shared<FileEntry>(dir+"/"+prefix+"1", 256, 0),
std::make_shared<FileEntry>(dir+"/"+prefix+"2", 512, 256)
};
for(size_t i = 0; i < A2_ARRAY_LEN(entries); ++i) {
createFile(entries[i]->getPath(), entries[i]->getLength()+100);
for(const auto& i : fileEntries) {
createFile(i->getPath(), i->getLength()+100);
}
std::vector<std::shared_ptr<FileEntry> > fileEntries
(vbegin(entries), vend(entries));
MultiDiskAdaptor adaptor;
adaptor.setFileEntries(fileEntries.begin(), fileEntries.end());
@ -390,24 +387,22 @@ void MultiDiskAdaptorTest::testCutTrailingGarbage()
adaptor.cutTrailingGarbage();
CPPUNIT_ASSERT_EQUAL((int64_t)256,
File(entries[0]->getPath()).size());
File(fileEntries[0]->getPath()).size());
CPPUNIT_ASSERT_EQUAL((int64_t)512,
File(entries[1]->getPath()).size());
File(fileEntries[1]->getPath()).size());
}
void MultiDiskAdaptorTest::testSize()
{
std::string dir = A2_TEST_OUT_DIR;
std::string prefix = "aria2_MultiDiskAdaptorTest_testSize_";
std::shared_ptr<FileEntry> entries[] = {
std::shared_ptr<FileEntry>(new FileEntry(dir+"/"+prefix+"1", 1, 0)),
std::shared_ptr<FileEntry>(new FileEntry(dir+"/"+prefix+"2", 1, 1))
std::vector<std::shared_ptr<FileEntry>> fileEntries {
std::make_shared<FileEntry>(dir+"/"+prefix+"1", 1, 0),
std::make_shared<FileEntry>(dir+"/"+prefix+"2", 1, 1)
};
for(size_t i = 0; i < A2_ARRAY_LEN(entries); ++i) {
createFile(entries[i]->getPath(), entries[i]->getLength());
for(const auto& i : fileEntries) {
createFile(i->getPath(), i->getLength());
}
std::vector<std::shared_ptr<FileEntry> > fileEntries
(vbegin(entries), vend(entries));
MultiDiskAdaptor adaptor;
adaptor.setFileEntries(fileEntries.begin(), fileEntries.end());
@ -422,11 +417,11 @@ void MultiDiskAdaptorTest::testSize()
void MultiDiskAdaptorTest::testUtime()
{
std::string storeDir = A2_TEST_OUT_DIR"/aria2_MultiDiskAdaptorTest_testUtime";
std::shared_ptr<FileEntry> entries[] = {
std::shared_ptr<FileEntry>(new FileEntry(storeDir+"/requested", 0, 0)),
std::shared_ptr<FileEntry>(new FileEntry(storeDir+"/notFound", 0, 0)),
std::shared_ptr<FileEntry>(new FileEntry(storeDir+"/notRequested", 0, 0)),
std::shared_ptr<FileEntry>(new FileEntry(storeDir+"/anotherRequested", 0, 0)),
std::vector<std::shared_ptr<FileEntry> > entries {
std::make_shared<FileEntry>(storeDir+"/requested", 0, 0),
std::make_shared<FileEntry>(storeDir+"/notFound", 0, 0),
std::make_shared<FileEntry>(storeDir+"/notRequested", 0, 0),
std::make_shared<FileEntry>(storeDir+"/anotherRequested", 0, 0),
};
createFile(entries[0]->getPath(), entries[0]->getLength());
@ -436,10 +431,8 @@ void MultiDiskAdaptorTest::testUtime()
entries[2]->setRequested(false);
std::vector<std::shared_ptr<FileEntry> > fileEntries
(vbegin(entries), vend(entries));
MultiDiskAdaptor adaptor;
adaptor.setFileEntries(fileEntries.begin(), fileEntries.end());
adaptor.setFileEntries(entries.begin(), entries.end());
time_t atime = (time_t) 100000;
time_t mtime = (time_t) 200000;
@ -460,15 +453,15 @@ void MultiDiskAdaptorTest::testWriteCache()
{
std::string storeDir =
A2_TEST_OUT_DIR"/aria2_MultiDiskAdaptorTest_testWriteCache";
std::shared_ptr<FileEntry> entries[] = {
std::shared_ptr<FileEntry>(new FileEntry(storeDir+"/file1", 16385, 0)),
std::shared_ptr<FileEntry>(new FileEntry(storeDir+"/file2", 4098, 16385))
std::vector<std::shared_ptr<FileEntry>> entries {
std::make_shared<FileEntry>(storeDir+"/file1", 16385, 0),
std::make_shared<FileEntry>(storeDir+"/file2", 4098, 16385)
};
for(int i = 0; i < 2; ++i) {
File(entries[i]->getPath()).remove();
for(const auto& i : entries) {
File(i->getPath()).remove();
}
std::shared_ptr<MultiDiskAdaptor> adaptor(new MultiDiskAdaptor());
adaptor->setFileEntries(vbegin(entries), vend(entries));
adaptor->setFileEntries(std::begin(entries), std::end(entries));
WrDiskCacheEntry cache(adaptor);
std::string data1(16383, '1'), data2(100, '2'), data3(4000, '3');
cache.cacheData(createDataCell(0, data1.c_str()));

View File

@ -64,7 +64,7 @@ void MultiFileAllocationIteratorTest::testMakeDiskWriterEntries()
createFile(storeDir+std::string("/file4"), 0);
std::shared_ptr<MultiDiskAdaptor> diskAdaptor(new MultiDiskAdaptor());
diskAdaptor->setFileEntries(vbegin(fs), vend(fs));
diskAdaptor->setFileEntries(std::begin(fs), std::end(fs));
diskAdaptor->setPieceLength(1024);
diskAdaptor->openFile();

View File

@ -25,12 +25,12 @@ void PriorityPieceSelectorTest::testSelect()
size_t pieceLength = 1024;
size_t A[] = { 1,200};
BitfieldMan bf(pieceLength, pieceLength*256);
for(size_t i = 0; i < A2_ARRAY_LEN(A); ++i) {
bf.setBit(A[i]);
for(auto i : A) {
bf.setBit(i);
}
PriorityPieceSelector selector
(std::shared_ptr<PieceSelector>(new MockPieceSelector()));
selector.setPriorityPiece(vbegin(A), vend(A));
selector.setPriorityPiece(std::begin(A), std::end(A));
size_t index;
CPPUNIT_ASSERT(selector.select(index, bf.getBitfield(), bf.countBlock()));

View File

@ -143,18 +143,13 @@ void RequestGroupManTest::testLoadServerStat()
void RequestGroupManTest::testChangeReservedGroupPosition()
{
std::shared_ptr<RequestGroup> gs[] = {
std::shared_ptr<RequestGroup>(new RequestGroup(GroupId::create(),
util::copy(option_))),
std::shared_ptr<RequestGroup>(new RequestGroup(GroupId::create(),
util::copy(option_))),
std::shared_ptr<RequestGroup>(new RequestGroup(GroupId::create(),
util::copy(option_))),
std::shared_ptr<RequestGroup>(new RequestGroup(GroupId::create(),
util::copy(option_)))
std::vector<std::shared_ptr<RequestGroup>> gs {
std::make_shared<RequestGroup>(GroupId::create(), util::copy(option_)),
std::make_shared<RequestGroup>(GroupId::create(), util::copy(option_)),
std::make_shared<RequestGroup>(GroupId::create(), util::copy(option_)),
std::make_shared<RequestGroup>(GroupId::create(), util::copy(option_))
};
std::vector<std::shared_ptr<RequestGroup> > groups(vbegin(gs), vend(gs));
RequestGroupMan rm(groups, 0, option_.get());
RequestGroupMan rm(gs, 0, option_.get());
CPPUNIT_ASSERT_EQUAL
((size_t)0, rm.changeReservedGroupPosition(gs[0]->getGID(),
@ -228,8 +223,8 @@ void RequestGroupManTest::testFillRequestGroupFromReserver()
createRequestGroup(0, 0, "foo5", "http://host/foo5", util::copy(option_))
};
rgs[1]->setPauseRequested(true);
for(std::shared_ptr<RequestGroup>* i = vbegin(rgs); i != vend(rgs); ++i) {
rgman_->addReservedGroup(*i);
for(const auto& i : rgs) {
rgman_->addReservedGroup(i);
}
rgman_->fillRequestGroupFromReserver(e_.get());
@ -243,8 +238,8 @@ void RequestGroupManTest::testFillRequestGroupFromReserver_uriParser()
createRequestGroup(0, 0, "mem2", "http://mem2", util::copy(option_)),
};
rgs[0]->setPauseRequested(true);
for(std::shared_ptr<RequestGroup>* i = vbegin(rgs); i != vend(rgs); ++i) {
rgman_->addReservedGroup(*i);
for(const auto& i : rgs) {
rgman_->addReservedGroup(i);
}
std::shared_ptr<UriListParser> flp
@ -262,28 +257,26 @@ void RequestGroupManTest::testFillRequestGroupFromReserver_uriParser()
void RequestGroupManTest::testInsertReservedGroup()
{
std::shared_ptr<RequestGroup> rgs1[] = {
std::vector<std::shared_ptr<RequestGroup>> rgs1 {
std::shared_ptr<RequestGroup>(new RequestGroup(GroupId::create(),
util::copy(option_))),
std::shared_ptr<RequestGroup>(new RequestGroup(GroupId::create(),
util::copy(option_)))
};
std::shared_ptr<RequestGroup> rgs2[] = {
std::vector<std::shared_ptr<RequestGroup>> rgs2 {
std::shared_ptr<RequestGroup>(new RequestGroup(GroupId::create(),
util::copy(option_))),
std::shared_ptr<RequestGroup>(new RequestGroup(GroupId::create(),
util::copy(option_)))
};
std::vector<std::shared_ptr<RequestGroup> > groups(vbegin(rgs1), vend(rgs1));
rgman_->insertReservedGroup(0, groups);
rgman_->insertReservedGroup(0, rgs1);
CPPUNIT_ASSERT_EQUAL((size_t)2, rgman_->getReservedGroups().size());
RequestGroupList::const_iterator itr;
itr = rgman_->getReservedGroups().begin();
CPPUNIT_ASSERT_EQUAL(rgs1[0]->getGID(), (*itr++)->getGID());
CPPUNIT_ASSERT_EQUAL(rgs1[1]->getGID(), (*itr++)->getGID());
groups.assign(vbegin(rgs2), vend(rgs2));
rgman_->insertReservedGroup(1, groups);
rgman_->insertReservedGroup(1, rgs2);
CPPUNIT_ASSERT_EQUAL((size_t)4, rgman_->getReservedGroups().size());
itr = rgman_->getReservedGroups().begin();
++itr;

View File

@ -870,7 +870,7 @@ void RpcMethodTest::testGatherProgressCommon()
{
std::shared_ptr<DownloadContext> dctx(new DownloadContext(0, 0,"aria2.tar.bz2"));
std::string uris[] = { "http://localhost/aria2.tar.bz2" };
dctx->getFirstFileEntry()->addUris(vbegin(uris), vend(uris));
dctx->getFirstFileEntry()->addUris(std::begin(uris), std::end(uris));
std::shared_ptr<RequestGroup> group(new RequestGroup(GroupId::create(),
util::copy(option_)));
group->setDownloadContext(dctx);
@ -1144,12 +1144,11 @@ void RpcMethodTest::testGetSessionInfo()
void RpcMethodTest::testPause()
{
const std::string URIS[] = {
std::vector<std::string> uris {
"http://url1",
"http://url2",
"http://url3",
};
std::vector<std::string> uris(vbegin(URIS), vend(URIS));
option_->put(PREF_FORCE_SEQUENTIAL, A2_V_TRUE);
std::vector<std::shared_ptr<RequestGroup> > groups;
createRequestGroupForUri(groups, option_, uris);

View File

@ -35,13 +35,12 @@ CPPUNIT_TEST_SUITE_REGISTRATION(SessionSerializerTest);
void SessionSerializerTest::testSave()
{
#if defined(ENABLE_BITTORRENT) && defined(ENABLE_METALINK)
const std::string URIs[] =
{ "http://localhost/file",
"http://mirror/file",
A2_TEST_DIR"/test.torrent",
A2_TEST_DIR"/serialize_session.meta4",
"magnet:?xt=urn:btih:248D0A1CD08284299DE78D5C1ED359BB46717D8C"};
std::vector<std::string> uris(vbegin(URIs), vend(URIs));
std::vector<std::string> uris {
"http://localhost/file",
"http://mirror/file",
A2_TEST_DIR"/test.torrent",
A2_TEST_DIR"/serialize_session.meta4",
"magnet:?xt=urn:btih:248D0A1CD08284299DE78D5C1ED359BB46717D8C"};
std::vector<std::shared_ptr<RequestGroup> > result;
std::shared_ptr<Option> option(new Option());
option->put(PREF_DIR, "/tmp");

View File

@ -89,7 +89,7 @@ void Sqlite3CookieParserTest::testMozParse_fileNotFound()
// SUCCESS
const char A2_SQLITE_ERR[] = "SQLite3 database is not opened";
CPPUNIT_ASSERT(util::startsWith(e.what(), e.what()+strlen(e.what()),
A2_SQLITE_ERR, vend(A2_SQLITE_ERR)-1));
A2_SQLITE_ERR, std::end(A2_SQLITE_ERR)-1));
}
}

View File

@ -1891,28 +1891,31 @@ void UtilTest::testJoinPath()
const std::string dir1dir2file[] = { "dir1", "dir2", "file" };
CPPUNIT_ASSERT_EQUAL
(std::string("dir1/dir2/file"),
util::joinPath(vbegin(dir1dir2file), vend(dir1dir2file)));
util::joinPath(std::begin(dir1dir2file), std::end(dir1dir2file)));
const std::string dirparentfile[] = { "dir", "..", "file" };
CPPUNIT_ASSERT_EQUAL
(std::string("file"),
util::joinPath(vbegin(dirparentfile), vend(dirparentfile)));
util::joinPath(std::begin(dirparentfile), std::end(dirparentfile)));
const std::string dirparentparentfile[] = { "dir", "..", "..", "file" };
CPPUNIT_ASSERT_EQUAL
(std::string("file"),
util::joinPath(vbegin(dirparentparentfile), vend(dirparentparentfile)));
util::joinPath(std::begin(dirparentparentfile),
std::end(dirparentparentfile)));
const std::string dirdotfile[] = { "dir", ".", "file" };
CPPUNIT_ASSERT_EQUAL(std::string("dir/file"),
util::joinPath(vbegin(dirdotfile), vend(dirdotfile)));
util::joinPath(std::begin(dirdotfile),
std::end(dirdotfile)));
const std::string empty[] = {};
CPPUNIT_ASSERT_EQUAL(std::string(""), util::joinPath(&empty[0], &empty[0]));
const std::string parentdot[] = { "..", "." };
CPPUNIT_ASSERT_EQUAL(std::string(""),
util::joinPath(vbegin(parentdot), vend(parentdot)));
util::joinPath(std::begin(parentdot),
std::end(parentdot)));
}
void UtilTest::testParseIndexPath()

View File

@ -118,7 +118,7 @@ void ValueBaseJsonParserTest::testParseUpdate()
CPPUNIT_ASSERT(list);
const String* s = downcast<String>(list->get(0));
const unsigned char arr[] = { 0xF0u, 0xA4u, 0xADu, 0xA2u };
CPPUNIT_ASSERT_EQUAL(std::string(vbegin(arr), vend(arr)), s->s());
CPPUNIT_ASSERT_EQUAL(std::string(std::begin(arr), std::end(arr)), s->s());
}
{
// null

View File

@ -26,7 +26,7 @@ void a2algoTest::testSelect()
{
size_t A[] = { 1,2,3,4,7,10,11,12,13,14,15,100,112,113,114 };
std::pair<size_t*, size_t> p = max_sequence(vbegin(A), vend(A));
std::pair<size_t*, size_t> p = max_sequence(std::begin(A), std::end(A));
CPPUNIT_ASSERT_EQUAL(&A[5], p.first);
CPPUNIT_ASSERT_EQUAL((size_t)6, p.second);

View File

@ -13,7 +13,6 @@ class array_funTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testArrayLength);
CPPUNIT_TEST(testArrayPtr);
CPPUNIT_TEST(testArrayWrapper);
CPPUNIT_TEST(testVbeginVend);
CPPUNIT_TEST_SUITE_END();
public:
@ -24,7 +23,6 @@ public:
void testArrayLength();
void testArrayPtr();
void testArrayWrapper();
void testVbeginVend();
struct X{
int m;
@ -127,11 +125,4 @@ void array_funTest::testArrayWrapper()
arrayPtrConstCast(x1);
}
void array_funTest::testVbeginVend()
{
int a[] = {1,2,3};
CPPUNIT_ASSERT_EQUAL(&a[0], vbegin(a));
CPPUNIT_ASSERT_EQUAL(a+3, vend(a));
}
} // namespace aria2