diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index 4f046fce..33a4ea43 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -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; } diff --git a/src/LibgcryptMessageDigestImpl.cc b/src/LibgcryptMessageDigestImpl.cc index 23ae1389..4460c684 100644 --- a/src/LibgcryptMessageDigestImpl.cc +++ b/src/LibgcryptMessageDigestImpl.cc @@ -73,19 +73,22 @@ CHashFuncEntry hashFuncs[] = { std::shared_ptr 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(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); } diff --git a/src/LibnettleMessageDigestImpl.cc b/src/LibnettleMessageDigestImpl.cc index 5f49648d..9919ffcd 100644 --- a/src/LibnettleMessageDigestImpl.cc +++ b/src/LibnettleMessageDigestImpl.cc @@ -76,20 +76,21 @@ std::shared_ptr 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(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; } diff --git a/src/LibsslMessageDigestImpl.cc b/src/LibsslMessageDigestImpl.cc index 8a024041..00f7f596 100644 --- a/src/LibsslMessageDigestImpl.cc +++ b/src/LibsslMessageDigestImpl.cc @@ -82,20 +82,23 @@ CHashFuncEntry hashFuncs[] = { std::shared_ptr 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(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); } diff --git a/src/MessageDigest.cc b/src/MessageDigest.cc index 1acb0b8b..e4557f8c 100644 --- a/src/MessageDigest.cc +++ b/src/MessageDigest.cc @@ -91,10 +91,9 @@ bool MessageDigest::supports(const std::string& hashType) std::vector MessageDigest::getSupportedHashTypes() { std::vector 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; diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index 57b052d1..aa4809fb 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -220,8 +220,7 @@ std::vector OptionHandlerFactory::createOptionHandlers() (PREF_CONSOLE_LOG_LEVEL, TEXT_CONSOLE_LOG_LEVEL, V_NOTICE, - std::vector - (vbegin(logLevels), vend(logLevels)))); + {std::begin(logLevels), std::end(logLevels)})); op->addTag(TAG_ADVANCED); handlers.push_back(op); } @@ -479,8 +478,7 @@ std::vector OptionHandlerFactory::createOptionHandlers() (PREF_LOG_LEVEL, TEXT_LOG_LEVEL, V_DEBUG, - std::vector - (vbegin(logLevels), vend(logLevels)))); + {std::begin(logLevels), std::end(logLevels)})); op->addTag(TAG_ADVANCED); op->setChangeGlobalOption(true); handlers.push_back(op); diff --git a/src/TimeA2.cc b/src/TimeA2.cc index 0410cb5d..836b7e58 100644 --- a/src/TimeA2.cc +++ b/src/TimeA2.cc @@ -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; } diff --git a/src/array_fun.h b/src/array_fun.h index b2b1cb7c..ed562ed8 100644 --- a/src/array_fun.h +++ b/src/array_fun.h @@ -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 -T* vbegin(T (&a)[N]) -{ - return a; -} - -template -T* vend(T (&a)[N]) -{ - return a+N; -} - template class array_ptr { private: diff --git a/src/help_tags.cc b/src/help_tags.cc index 9b32729f..e61e79b5 100644 --- a/src/help_tags.cc +++ b/src/help_tags.cc @@ -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; } diff --git a/src/util.cc b/src/util.cc index ae348fef..d5a3463f 100644 --- a/src/util.cc +++ b/src/util.cc @@ -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); diff --git a/test/BittorrentHelperTest.cc b/test/BittorrentHelperTest.cc index 1fa7717d..263bef89 100644 --- a/test/BittorrentHelperTest.cc +++ b/test/BittorrentHelperTest.cc @@ -322,16 +322,14 @@ void BittorrentHelperTest::testComputeFastSet() std::vector fastSet; computeFastSet(fastSet, ipaddr, numPieces, infoHash, fastSetSize); size_t ans[] = { 686, 459, 278, 200, 404, 834, 64, 203, 760, 950 }; - std::vector 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 fastSet; computeFastSet(fastSet, ipaddr, numPieces, infoHash, fastSetSize); size_t ans[] = { 568, 188, 466, 452, 550, 662, 109, 226, 398, 11 }; - std::vector 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 fastSet; computeFastSet(fastSet, ipaddr, numPieces, infoHash, fastSetSize); size_t ans[] = { 8, 6, 7, 5, 1, 4, 0, 2, 3 }; - std::vector 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))); } } diff --git a/test/DHTRoutingTableDeserializerTest.cc b/test/DHTRoutingTableDeserializerTest.cc index ae7ddc3a..3a6ec170 100644 --- a/test/DHTRoutingTableDeserializerTest.cc +++ b/test/DHTRoutingTableDeserializerTest.cc @@ -39,14 +39,13 @@ void DHTRoutingTableDeserializerTest::testDeserialize() { std::shared_ptr localNode(new DHTNode()); - std::shared_ptr 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 > 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 > 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 localNode(new DHTNode()); - std::shared_ptr 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> 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 > nodes(vbegin(nodesSrc), vend(nodesSrc)); + nodes[1]->setIPAddress("non-numerical-name"); DHTRoutingTableSerializer s(AF_INET6); s.setLocalNode(localNode); diff --git a/test/DHTRoutingTableSerializerTest.cc b/test/DHTRoutingTableSerializerTest.cc index f4b2d480..22d30093 100644 --- a/test/DHTRoutingTableSerializerTest.cc +++ b/test/DHTRoutingTableSerializerTest.cc @@ -100,14 +100,13 @@ void DHTRoutingTableSerializerTest::testSerialize() { std::shared_ptr localNode(new DHTNode()); - std::shared_ptr 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> 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 > 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 localNode(new DHTNode()); - std::shared_ptr 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> 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 > nodes(vbegin(nodesSrc), vend(nodesSrc)); + nodes[1]->setIPAddress("non-numerical-name"); DHTRoutingTableSerializer s(AF_INET6); s.setLocalNode(localNode); diff --git a/test/DefaultBtAnnounceTest.cc b/test/DefaultBtAnnounceTest.cc index 1ccab552..63abbd6a 100644 --- a/test/DefaultBtAnnounceTest.cc +++ b/test/DefaultBtAnnounceTest.cc @@ -63,7 +63,7 @@ public: dctx_.reset(new DownloadContext(pieceLength, totalLength)); { auto torrentAttrs = make_unique(); - 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 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 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_); diff --git a/test/DefaultBtProgressInfoFileTest.cc b/test/DefaultBtProgressInfoFileTest.cc index fdbf0e88..9fefb8e4 100644 --- a/test/DefaultBtProgressInfoFileTest.cc +++ b/test/DefaultBtProgressInfoFileTest.cc @@ -72,13 +72,13 @@ public: dctx_.reset(new DownloadContext()); { auto torrentAttrs = make_unique(); - 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 fileEntries[] = { std::shared_ptr(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()); diff --git a/test/DownloadContextTest.cc b/test/DownloadContextTest.cc index 306bfbda..9e0ffee4 100644 --- a/test/DownloadContextTest.cc +++ b/test/DownloadContextTest.cc @@ -41,7 +41,7 @@ void DownloadContextTest::testFindFileEntryByOffset() std::shared_ptr(new FileEntry("file5",3000,3000)), std::shared_ptr(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()); diff --git a/test/DownloadHelperTest.cc b/test/DownloadHelperTest.cc index 293491ab..3a7a3f29 100644 --- a/test/DownloadHelperTest.cc +++ b/test/DownloadHelperTest.cc @@ -68,12 +68,11 @@ CPPUNIT_TEST_SUITE_REGISTRATION(DownloadHelperTest); void DownloadHelperTest::testCreateRequestGroupForUri() { - std::string array[] = { + std::vector uris { "http://alpha/file", "http://bravo/file", "http://charlie/file" }; - std::vector 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 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 alphaCtx = alphaGroup->getDownloadContext(); @@ -141,11 +140,10 @@ void DownloadHelperTest::testCreateRequestGroupForUri() void DownloadHelperTest::testCreateRequestGroupForUri_parameterized() { - std::string array[] = { + std::vector uris { "http://{alpha, bravo}/file", "http://charlie/file" }; - std::vector 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 uris { "http://alpha/file", - A2_TEST_DIR"/test.torrent", + A2_TEST_DIR "/test.torrent", "http://bravo/file", "http://charlie/file" }; - std::vector 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 ctx = group->getDownloadContext(); @@ -221,13 +218,12 @@ void DownloadHelperTest::testCreateRequestGroupForUri_BitTorrent() #ifdef ENABLE_METALINK void DownloadHelperTest::testCreateRequestGroupForUri_Metalink() { - std::string array[] = { + std::vector uris { "http://alpha/file", "http://bravo/file", "http://charlie/file", - A2_TEST_DIR"/test.xml" + A2_TEST_DIR "/test.xml" }; - std::vector 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 ctx = group->getDownloadContext(); @@ -305,13 +301,12 @@ void DownloadHelperTest::testCreateRequestGroupForUriList() #ifdef ENABLE_BITTORRENT void DownloadHelperTest::testCreateRequestGroupForBitTorrent() { - std::string array[] = { + std::vector auxURIs { "http://alpha/file", "http://bravo/file", "http://charlie/file" }; - std::vector 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()); diff --git a/test/FeatureConfigTest.cc b/test/FeatureConfigTest.cc index 7ee2a26b..876e78a3 100644 --- a/test/FeatureConfigTest.cc +++ b/test/FeatureConfigTest.cc @@ -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()); } diff --git a/test/FeedbackURISelectorTest.cc b/test/FeedbackURISelectorTest.cc index 4bc29574..5f045021 100644 --- a/test/FeedbackURISelectorTest.cc +++ b/test/FeedbackURISelectorTest.cc @@ -29,15 +29,11 @@ private: public: void setUp() { - static const char* urisSrc[] = { - "http://alpha/file", - "ftp://alpha/file", - "http://bravo/file" - }; - std::vector 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)); diff --git a/test/GroupIdTest.cc b/test/GroupIdTest.cc index fb36eaf5..7d3db96e 100644 --- a/test/GroupIdTest.cc +++ b/test/GroupIdTest.cc @@ -74,9 +74,8 @@ void GroupIdTest::testExpandUnique() GroupId::import(0xff80000000020001LL), GroupId::import(0xfff8000000030000LL) }; - for(std::shared_ptr* 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, diff --git a/test/IndexedListTest.cc b/test/IndexedListTest.cc index 1f28b588..e208005b 100644 --- a/test/IndexedListTest.cc +++ b/test/IndexedListTest.cc @@ -254,12 +254,12 @@ void IndexedListTest::testInsert_keyFunc() }; size_t slen = sizeof(s)/sizeof(s[0]); IndexedList > 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 list; IndexedList::iterator itr; IndexedList::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 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()); diff --git a/test/InorderURISelectorTest.cc b/test/InorderURISelectorTest.cc index f607471e..62091dfe 100644 --- a/test/InorderURISelectorTest.cc +++ b/test/InorderURISelectorTest.cc @@ -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 uris; - uris.assign(vbegin(urisSrc), vend(urisSrc)); - - fileEntry_.setUris(uris); + }); sel.reset(new InorderURISelector()); } diff --git a/test/MSEHandshakeTest.cc b/test/MSEHandshakeTest.cc index a6b02126..fb63c274 100644 --- a/test/MSEHandshakeTest.cc +++ b/test/MSEHandshakeTest.cc @@ -35,7 +35,7 @@ public: memset(infoHash, 0, sizeof(infoHash)); { auto torrentAttrs = make_unique(); - 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)); } } diff --git a/test/MultiDiskAdaptorTest.cc b/test/MultiDiskAdaptorTest.cc index 8d66130c..a35f105d 100644 --- a/test/MultiDiskAdaptorTest.cc +++ b/test/MultiDiskAdaptorTest.cc @@ -47,17 +47,18 @@ public: CPPUNIT_TEST_SUITE_REGISTRATION( MultiDiskAdaptorTest ); -std::vector > createEntries() { - std::shared_ptr array[] = { - std::shared_ptr(new FileEntry(A2_TEST_OUT_DIR"/file0.txt", 0, 0)), - std::shared_ptr(new FileEntry(A2_TEST_OUT_DIR"/file1.txt", 15, 0)), - std::shared_ptr(new FileEntry(A2_TEST_OUT_DIR"/file2.txt", 7, 15)), - std::shared_ptr(new FileEntry(A2_TEST_OUT_DIR"/file3.txt", 0, 22)), - std::shared_ptr(new FileEntry(A2_TEST_OUT_DIR"/file4.txt", 2, 22)), - std::shared_ptr(new FileEntry(A2_TEST_OUT_DIR"/file5.txt", 0, 24)), - std::shared_ptr(new FileEntry(A2_TEST_OUT_DIR"/file6.txt", 3, 24)), - std::shared_ptr(new FileEntry(A2_TEST_OUT_DIR"/file7.txt", 0, 27)), - std::shared_ptr(new FileEntry(A2_TEST_OUT_DIR"/file8.txt", 2, 27)), +std::vector > createEntries() +{ + std::vector> entries { + std::make_shared(A2_TEST_OUT_DIR "/file0.txt", 0, 0), + std::make_shared(A2_TEST_OUT_DIR "/file1.txt", 15, 0), + std::make_shared(A2_TEST_OUT_DIR "/file2.txt", 7, 15), + std::make_shared(A2_TEST_OUT_DIR "/file3.txt", 0, 22), + std::make_shared(A2_TEST_OUT_DIR "/file4.txt", 2, 22), + std::make_shared(A2_TEST_OUT_DIR "/file5.txt", 0, 24), + std::make_shared(A2_TEST_OUT_DIR "/file6.txt", 3, 24), + std::make_shared(A2_TEST_OUT_DIR "/file7.txt", 0, 27), + std::make_shared(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 > createEntries() { // *** file6 // |file7 // ** file8 - std::vector > entries(vbegin(array), vend(array)); - for(std::vector >::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 entry1(new FileEntry(A2_TEST_DIR"/file1r.txt", 15, 0)); - std::shared_ptr entry2(new FileEntry(A2_TEST_DIR"/file2r.txt", 7, 15)); - std::shared_ptr entry3(new FileEntry(A2_TEST_DIR"/file3r.txt", 3, 22)); - std::vector > entries; - entries.push_back(entry1); - entries.push_back(entry2); - entries.push_back(entry3); +void MultiDiskAdaptorTest::testReadData() +{ + std::vector> entries { + std::make_shared(A2_TEST_DIR "/file1r.txt", 15, 0), + std::make_shared(A2_TEST_DIR "/file2r.txt", 7, 15), + std::make_shared(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 entries[] = { - std::shared_ptr(new FileEntry(dir+"/"+prefix+"1", 256, 0)), - std::shared_ptr(new FileEntry(dir+"/"+prefix+"2", 512, 256)) + std::vector > fileEntries { + std::make_shared(dir+"/"+prefix+"1", 256, 0), + std::make_shared(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 > 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 entries[] = { - std::shared_ptr(new FileEntry(dir+"/"+prefix+"1", 1, 0)), - std::shared_ptr(new FileEntry(dir+"/"+prefix+"2", 1, 1)) + std::vector> fileEntries { + std::make_shared(dir+"/"+prefix+"1", 1, 0), + std::make_shared(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 > 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 entries[] = { - std::shared_ptr(new FileEntry(storeDir+"/requested", 0, 0)), - std::shared_ptr(new FileEntry(storeDir+"/notFound", 0, 0)), - std::shared_ptr(new FileEntry(storeDir+"/notRequested", 0, 0)), - std::shared_ptr(new FileEntry(storeDir+"/anotherRequested", 0, 0)), + std::vector > entries { + std::make_shared(storeDir+"/requested", 0, 0), + std::make_shared(storeDir+"/notFound", 0, 0), + std::make_shared(storeDir+"/notRequested", 0, 0), + std::make_shared(storeDir+"/anotherRequested", 0, 0), }; createFile(entries[0]->getPath(), entries[0]->getLength()); @@ -436,10 +431,8 @@ void MultiDiskAdaptorTest::testUtime() entries[2]->setRequested(false); - std::vector > 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 entries[] = { - std::shared_ptr(new FileEntry(storeDir+"/file1", 16385, 0)), - std::shared_ptr(new FileEntry(storeDir+"/file2", 4098, 16385)) + std::vector> entries { + std::make_shared(storeDir+"/file1", 16385, 0), + std::make_shared(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 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())); diff --git a/test/MultiFileAllocationIteratorTest.cc b/test/MultiFileAllocationIteratorTest.cc index 498f347d..e061fab5 100644 --- a/test/MultiFileAllocationIteratorTest.cc +++ b/test/MultiFileAllocationIteratorTest.cc @@ -64,7 +64,7 @@ void MultiFileAllocationIteratorTest::testMakeDiskWriterEntries() createFile(storeDir+std::string("/file4"), 0); std::shared_ptr diskAdaptor(new MultiDiskAdaptor()); - diskAdaptor->setFileEntries(vbegin(fs), vend(fs)); + diskAdaptor->setFileEntries(std::begin(fs), std::end(fs)); diskAdaptor->setPieceLength(1024); diskAdaptor->openFile(); diff --git a/test/PriorityPieceSelectorTest.cc b/test/PriorityPieceSelectorTest.cc index 714cf573..ef0e7f33 100644 --- a/test/PriorityPieceSelectorTest.cc +++ b/test/PriorityPieceSelectorTest.cc @@ -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(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())); diff --git a/test/RequestGroupManTest.cc b/test/RequestGroupManTest.cc index 241ab49a..b64c0390 100644 --- a/test/RequestGroupManTest.cc +++ b/test/RequestGroupManTest.cc @@ -143,18 +143,13 @@ void RequestGroupManTest::testLoadServerStat() void RequestGroupManTest::testChangeReservedGroupPosition() { - std::shared_ptr gs[] = { - std::shared_ptr(new RequestGroup(GroupId::create(), - util::copy(option_))), - std::shared_ptr(new RequestGroup(GroupId::create(), - util::copy(option_))), - std::shared_ptr(new RequestGroup(GroupId::create(), - util::copy(option_))), - std::shared_ptr(new RequestGroup(GroupId::create(), - util::copy(option_))) + std::vector> gs { + std::make_shared(GroupId::create(), util::copy(option_)), + std::make_shared(GroupId::create(), util::copy(option_)), + std::make_shared(GroupId::create(), util::copy(option_)), + std::make_shared(GroupId::create(), util::copy(option_)) }; - std::vector > 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* 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* i = vbegin(rgs); i != vend(rgs); ++i) { - rgman_->addReservedGroup(*i); + for(const auto& i : rgs) { + rgman_->addReservedGroup(i); } std::shared_ptr flp @@ -262,28 +257,26 @@ void RequestGroupManTest::testFillRequestGroupFromReserver_uriParser() void RequestGroupManTest::testInsertReservedGroup() { - std::shared_ptr rgs1[] = { + std::vector> rgs1 { std::shared_ptr(new RequestGroup(GroupId::create(), util::copy(option_))), std::shared_ptr(new RequestGroup(GroupId::create(), util::copy(option_))) }; - std::shared_ptr rgs2[] = { + std::vector> rgs2 { std::shared_ptr(new RequestGroup(GroupId::create(), util::copy(option_))), std::shared_ptr(new RequestGroup(GroupId::create(), util::copy(option_))) }; - std::vector > 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; diff --git a/test/RpcMethodTest.cc b/test/RpcMethodTest.cc index 570301a2..c56f55fd 100644 --- a/test/RpcMethodTest.cc +++ b/test/RpcMethodTest.cc @@ -870,7 +870,7 @@ void RpcMethodTest::testGatherProgressCommon() { std::shared_ptr 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 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 uris { "http://url1", "http://url2", "http://url3", }; - std::vector uris(vbegin(URIS), vend(URIS)); option_->put(PREF_FORCE_SEQUENTIAL, A2_V_TRUE); std::vector > groups; createRequestGroupForUri(groups, option_, uris); diff --git a/test/SessionSerializerTest.cc b/test/SessionSerializerTest.cc index 00442f68..c67b8156 100644 --- a/test/SessionSerializerTest.cc +++ b/test/SessionSerializerTest.cc @@ -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 uris(vbegin(URIs), vend(URIs)); + std::vector 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 > result; std::shared_ptr