mirror of
https://github.com/aria2/aria2.git
synced 2025-04-06 14:07:37 +03:00
2010-06-21 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Changed naming standards for class member variable: now it looks like var_ instead of _var.
This commit is contained in:
parent
ae957baa98
commit
ca4940622c
550 changed files with 10253 additions and 10248 deletions
|
@ -24,18 +24,18 @@ class UTMetadataPostDownloadHandlerTest:public CppUnit::TestFixture {
|
|||
CPPUNIT_TEST(testGetNextRequestGroups);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
SharedHandle<Option> _option;
|
||||
SharedHandle<DownloadContext> _dctx;
|
||||
SharedHandle<RequestGroup> _requestGroup;
|
||||
SharedHandle<Option> option_;
|
||||
SharedHandle<DownloadContext> dctx_;
|
||||
SharedHandle<RequestGroup> requestGroup_;
|
||||
public:
|
||||
void setUp()
|
||||
{
|
||||
_option.reset(new Option());
|
||||
_option->put("HELLO", "WORLD");
|
||||
_option->put(PREF_DIR, ".");
|
||||
_dctx.reset(new DownloadContext(0, 0, "something"));
|
||||
_requestGroup.reset(new RequestGroup(_option));
|
||||
_requestGroup->setDownloadContext(_dctx);
|
||||
option_.reset(new Option());
|
||||
option_->put("HELLO", "WORLD");
|
||||
option_->put(PREF_DIR, ".");
|
||||
dctx_.reset(new DownloadContext(0, 0, "something"));
|
||||
requestGroup_.reset(new RequestGroup(option_));
|
||||
requestGroup_->setDownloadContext(dctx_);
|
||||
}
|
||||
|
||||
void testCanHandle();
|
||||
|
@ -49,17 +49,17 @@ void UTMetadataPostDownloadHandlerTest::testCanHandle()
|
|||
{
|
||||
UTMetadataPostDownloadHandler handler;
|
||||
|
||||
CPPUNIT_ASSERT(!handler.canHandle(_requestGroup.get()));
|
||||
CPPUNIT_ASSERT(!handler.canHandle(requestGroup_.get()));
|
||||
|
||||
SharedHandle<TorrentAttribute> attrs(new TorrentAttribute());
|
||||
_dctx->setAttribute(bittorrent::BITTORRENT, attrs);
|
||||
dctx_->setAttribute(bittorrent::BITTORRENT, attrs);
|
||||
|
||||
CPPUNIT_ASSERT(handler.canHandle(_requestGroup.get()));
|
||||
CPPUNIT_ASSERT(handler.canHandle(requestGroup_.get()));
|
||||
|
||||
// Only checks whether metadata is empty or not
|
||||
attrs->metadata = "metadata";
|
||||
|
||||
CPPUNIT_ASSERT(!handler.canHandle(_requestGroup.get()));
|
||||
CPPUNIT_ASSERT(!handler.canHandle(requestGroup_.get()));
|
||||
}
|
||||
|
||||
void UTMetadataPostDownloadHandlerTest::testGetNextRequestGroups()
|
||||
|
@ -75,7 +75,7 @@ void UTMetadataPostDownloadHandlerTest::testGetNextRequestGroups()
|
|||
MessageDigestHelper::digest
|
||||
(infoHash, sizeof(infoHash), MessageDigestContext::SHA1,
|
||||
reinterpret_cast<const unsigned char*>(metadata.data()), metadata.size());
|
||||
_dctx->getFirstFileEntry()->setLength(metadata.size());
|
||||
dctx_->getFirstFileEntry()->setLength(metadata.size());
|
||||
SharedHandle<TorrentAttribute> attrs(new TorrentAttribute());
|
||||
attrs->infoHash = std::string(&infoHash[0], &infoHash[20]);
|
||||
std::vector<std::vector<std::string> > announceList;
|
||||
|
@ -83,53 +83,53 @@ void UTMetadataPostDownloadHandlerTest::testGetNextRequestGroups()
|
|||
announceTier.push_back("http://tracker");
|
||||
announceList.push_back(announceTier);
|
||||
attrs->announceList = announceList;
|
||||
_dctx->setAttribute(bittorrent::BITTORRENT, attrs);
|
||||
_requestGroup->setDiskWriterFactory
|
||||
dctx_->setAttribute(bittorrent::BITTORRENT, attrs);
|
||||
requestGroup_->setDiskWriterFactory
|
||||
(SharedHandle<DiskWriterFactory>(new ByteArrayDiskWriterFactory()));
|
||||
_requestGroup->initPieceStorage();
|
||||
_requestGroup->getPieceStorage()->getDiskAdaptor()->writeData
|
||||
requestGroup_->initPieceStorage();
|
||||
requestGroup_->getPieceStorage()->getDiskAdaptor()->writeData
|
||||
(reinterpret_cast<const unsigned char*>(metadata.data()), metadata.size(),
|
||||
0);
|
||||
|
||||
UTMetadataPostDownloadHandler handler;
|
||||
std::vector<SharedHandle<RequestGroup> > results;
|
||||
handler.getNextRequestGroups(results, _requestGroup.get());
|
||||
handler.getNextRequestGroups(results, requestGroup_.get());
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, results.size());
|
||||
SharedHandle<RequestGroup> newRg = results.front();
|
||||
SharedHandle<DownloadContext> newDctx = newRg->getDownloadContext();
|
||||
SharedHandle<TorrentAttribute> newAttrs =
|
||||
bittorrent::getTorrentAttrs(newDctx);
|
||||
CPPUNIT_ASSERT_EQUAL(bittorrent::getInfoHashString(_dctx),
|
||||
CPPUNIT_ASSERT_EQUAL(bittorrent::getInfoHashString(dctx_),
|
||||
bittorrent::getInfoHashString(newDctx));
|
||||
const std::vector<std::vector<std::string> >& newAnnounceList =
|
||||
newAttrs->announceList;
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, newAnnounceList.size());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://tracker"), newAnnounceList[0][0]);
|
||||
CPPUNIT_ASSERT_EQUAL(_option->get("Hello"),
|
||||
CPPUNIT_ASSERT_EQUAL(option_->get("Hello"),
|
||||
newRg->getOption()->get("Hello"));
|
||||
CPPUNIT_ASSERT
|
||||
(std::find(_requestGroup->followedBy().begin(),
|
||||
_requestGroup->followedBy().end(),
|
||||
newRg->getGID()) != _requestGroup->followedBy().end());
|
||||
(std::find(requestGroup_->followedBy().begin(),
|
||||
requestGroup_->followedBy().end(),
|
||||
newRg->getGID()) != requestGroup_->followedBy().end());
|
||||
CPPUNIT_ASSERT(!trfile.exists());
|
||||
|
||||
results.clear();
|
||||
|
||||
_requestGroup->getOption()->put(PREF_BT_SAVE_METADATA, V_TRUE);
|
||||
handler.getNextRequestGroups(results, _requestGroup.get());
|
||||
requestGroup_->getOption()->put(PREF_BT_SAVE_METADATA, V_TRUE);
|
||||
handler.getNextRequestGroups(results, requestGroup_.get());
|
||||
CPPUNIT_ASSERT(trfile.exists());
|
||||
|
||||
results.clear();
|
||||
|
||||
// See failure with bad metadata
|
||||
metadata = "d6:lengthi384e4:name19:aria2-0.8.2.tar.bz212:piece lengthi128e";
|
||||
_requestGroup->initPieceStorage();
|
||||
_requestGroup->getPieceStorage()->getDiskAdaptor()->writeData
|
||||
requestGroup_->initPieceStorage();
|
||||
requestGroup_->getPieceStorage()->getDiskAdaptor()->writeData
|
||||
(reinterpret_cast<const unsigned char*>(metadata.data()), metadata.size(),
|
||||
0);
|
||||
try {
|
||||
handler.getNextRequestGroups(results, _requestGroup.get());
|
||||
handler.getNextRequestGroups(results, requestGroup_.get());
|
||||
CPPUNIT_FAIL("exception must be thrown.");
|
||||
} catch(RecoverableException& e) {
|
||||
// success
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue