aria2/test/Metalink2RequestGroupTest.cc

227 lines
8.0 KiB
C++
Raw Normal View History

#include "Metalink2RequestGroup.h"
2009-06-28 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> Rewritten DownloadContext and removed SingleFileDownloadContext and BtContext and its derived classes. BitTorrent specific attributes are now set by DownloadContext::setAttribute() with key bittorrent::BITTORRENT. * src/AbstractBtMessage.cc * src/AbstractBtMessage.h * src/AbstractCommand.cc * src/AbstractCommand.h * src/AbstractProxyRequestCommand.cc * src/AbstractProxyResponseCommand.cc * src/ActivePeerConnectionCommand.cc * src/ActivePeerConnectionCommand.h * src/AnnounceList.cc * src/BtCheckIntegrityEntry.cc * src/BtConstants.h * src/BtContext.h: Removed * src/BtDependency.cc * src/BtExtendedMessage.cc * src/BtPieceMessage.cc * src/BtPieceMessage.h * src/BtPostDownloadHandler.cc * src/BtRegistry.cc * src/BtRegistry.h * src/BtSetup.cc * src/CheckIntegrityCommand.cc * src/CheckIntegrityEntry.cc * src/ChecksumCheckIntegrityEntry.cc * src/ConsoleStatCalc.cc * src/ContentTypeRequestGroupCriteria.cc * src/DHTGetPeersCommand.cc * src/DHTGetPeersCommand.h * src/DHTPeerLookupTask.cc * src/DHTPeerLookupTask.h * src/DHTTaskFactory.h * src/DHTTaskFactoryImpl.cc * src/DHTTaskFactoryImpl.h * src/DefaultBtAnnounce.cc * src/DefaultBtAnnounce.h * src/DefaultBtContext.cc: Removed * src/DefaultBtContext.h: Removed * src/DefaultBtInteractive.cc * src/DefaultBtInteractive.h * src/DefaultBtMessageDispatcher.cc * src/DefaultBtMessageDispatcher.h * src/DefaultBtMessageFactory.cc * src/DefaultBtMessageFactory.h * src/DefaultBtMessageReceiver.cc * src/DefaultBtMessageReceiver.h * src/DefaultBtProgressInfoFile.cc * src/DefaultBtRequestFactory.cc * src/DefaultBtRequestFactory.h * src/DefaultExtensionMessageFactory.cc * src/DefaultExtensionMessageFactory.h * src/DefaultPeerStorage.cc * src/DefaultPeerStorage.h * src/DefaultPieceStorage.cc * src/DefaultSegmentManFactory.cc * src/DiskAdaptor.cc * src/DiskAdaptor.h * src/DownloadContext.cc * src/DownloadContext.h * src/DownloadEngine.cc * src/DownloadEngineFactory.cc * src/DownloadHandler.cc * src/DownloadResult.h * src/FileAllocationCommand.cc * src/FileAllocationDispatcherCommand.cc * src/FileAllocationEntry.cc * src/FileEntry.h * src/FillRequestGroupCommand.cc * src/FtpDownloadCommand.cc * src/FtpFinishDownloadCommand.cc * src/FtpInitiateConnectionCommand.cc * src/FtpNegotiationCommand.cc * src/FtpTunnelRequestCommand.cc * src/FtpTunnelResponseCommand.cc * src/HandshakeExtensionMessage.cc * src/HandshakeExtensionMessage.h * src/HaveEraseCommand.cc * src/HttpDownloadCommand.cc * src/HttpInitiateConnectionCommand.cc * src/HttpProxyRequestCommand.cc * src/HttpProxyResponseCommand.cc * src/HttpRequest.cc * src/HttpRequest.h * src/HttpRequestCommand.cc * src/HttpResponseCommand.cc * src/HttpServerBodyCommand.cc * src/HttpServerCommand.cc * src/HttpSkipResponseCommand.cc * src/InitiateConnectionCommandFactory.cc * src/InitiatorMSEHandshakeCommand.cc * src/InitiatorMSEHandshakeCommand.h * src/IteratableChecksumValidator.cc * src/IteratableChecksumValidator.h * src/IteratableChunkChecksumValidator.cc * src/MSEHandshake.cc * src/MSEHandshake.h * src/Makefile.am * src/Makefile.in * src/Metalink2RequestGroup.cc * src/MetalinkPostDownloadHandler.cc * src/MultiDiskAdaptor.cc * src/MultiDiskAdaptor.h * src/MultiFileAllocationIterator.cc * src/MultiUrlRequestInfo.cc * src/PeerChokeCommand.cc * src/PeerChokeCommand.h * src/PeerInitiateConnectionCommand.cc * src/PeerInitiateConnectionCommand.h * src/PeerInteractionCommand.cc * src/PeerInteractionCommand.h * src/PeerReceiveHandshakeCommand.cc * src/PieceHashCheckIntegrityEntry.cc * src/RealtimeCommand.cc * src/ReceiverMSEHandshakeCommand.cc * src/RequestGroup.cc * src/RequestGroup.h * src/RequestGroupEntry.cc * src/RequestGroupMan.cc * src/SeedCheckCommand.cc * src/SeedCheckCommand.h * src/SegmentMan.cc * src/ShareRatioSeedCriteria.h * src/SingleFileDownloadContext.cc: Removed * src/SingleFileDownloadContext.h: Removed * src/SleepCommand.cc * src/StreamCheckIntegrityEntry.cc * src/TrackerWatcherCommand.cc * src/TrackerWatcherCommand.h * src/UnknownLengthPieceStorage.cc * src/Util.cc * src/Util.h * src/XmlRpcMethodImpl.cc * src/bittorrent_helper.cc * src/bittorrent_helper.h * src/download_helper.cc * src/main.cc * src/option_processing.cc * test/BitfieldManTest.cc * test/BittorrentHelperTest.cc * test/BtCancelMessageTest.cc * test/BtChokeMessageTest.cc * test/BtDependencyTest.cc * test/BtPieceMessageTest.cc * test/BtPostDownloadHandlerTest.cc * test/BtRegistryTest.cc * test/BtRejectMessageTest.cc * test/BtRequestMessageTest.cc * test/DHTPeerAnnounceStorageTest.cc * test/DefaultBtAnnounceTest.cc * test/DefaultBtContextTest.cc: Removed * test/DefaultBtMessageDispatcherTest.cc * test/DefaultBtMessageFactoryTest.cc * test/DefaultBtProgressInfoFileTest.cc * test/DefaultBtRequestFactoryTest.cc * test/DefaultExtensionMessageFactoryTest.cc * test/DefaultPeerStorageTest.cc * test/DefaultPieceStorageTest.cc * test/DirectDiskAdaptorTest.cc * test/DownloadContextTest.cc * test/DownloadHandlerFactoryTest.cc * test/DownloadHelperTest.cc * test/HandshakeExtensionMessageTest.cc * test/HttpRequestTest.cc * test/HttpResponseTest.cc * test/IteratableChecksumValidatorTest.cc * test/IteratableChunkChecksumValidatorTest.cc * test/MSEHandshakeTest.cc * test/Makefile.am * test/Makefile.in * test/Metalink2RequestGroupTest.cc * test/MetalinkPostDownloadHandlerTest.cc * test/MockBtContext.h: Removed * test/MockDHTTaskFactory.h * test/MockDownloadContext.h: Removed * test/MockPieceStorage.h * test/MultiDiskAdaptorTest.cc * test/MultiFileAllocationIteratorTest.cc * test/RequestGroupManTest.cc * test/RequestGroupTest.cc * test/SegmentManTest.cc * test/ShareRatioSeedCriteriaTest.cc * test/SingleFileDownloadContextTest.cc: Removed * test/UtilTest.cc * test/XmlRpcMethodTest.cc
2009-06-28 10:37:15 +00:00
#include <algorithm>
#include <cppunit/extensions/HelperMacros.h>
#include "DownloadContext.h"
#include "prefs.h"
#include "Option.h"
#include "RequestGroup.h"
#include "FileEntry.h"
#include "Signature.h"
namespace aria2 {
class Metalink2RequestGroupTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(Metalink2RequestGroupTest);
CPPUNIT_TEST(testGenerate);
CPPUNIT_TEST(testGenerate_groupByMetaurl);
CPPUNIT_TEST(testGenerate_dosDirTraversal);
CPPUNIT_TEST_SUITE_END();
private:
std::shared_ptr<Option> option_;
public:
void setUp()
{
option_.reset(new Option());
option_->put(PREF_SPLIT, "1");
}
void testGenerate();
void testGenerate_groupByMetaurl();
void testGenerate_dosDirTraversal();
};
CPPUNIT_TEST_SUITE_REGISTRATION( Metalink2RequestGroupTest );
void Metalink2RequestGroupTest::testGenerate()
{
std::vector<std::shared_ptr<RequestGroup> > groups;
option_->put(PREF_DIR, "/tmp");
Metalink2RequestGroup().generate(groups, A2_TEST_DIR"/test.xml", option_);
// first file
{
std::shared_ptr<RequestGroup> rg = groups[0];
std::vector<std::string> uris;
2009-06-29 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> Removed _uris from RequestGroup. All functions that refer to _uris were moved to FileEntry. Exit status code are now defined in DownloadResultCode.h. * src/AbstractCommand.cc * src/AdaptiveURISelector.cc * src/AdaptiveURISelector.h * src/AutoSaveCommand.cc * src/BtPostDownloadHandler.cc * src/CheckIntegrityDispatcherCommand.cc * src/CookieStorage.cc * src/DHTAutoSaveCommand.cc * src/DHTBucketRefreshCommand.cc * src/DHTEntryPointNameResolveCommand.cc * src/DHTInteractionCommand.cc * src/DHTPeerAnnounceCommand.cc * src/DHTTokenUpdateCommand.cc * src/DlAbortEx.h * src/DlRetryEx.h * src/DownloadCommand.cc * src/DownloadContext.h * src/DownloadFailureException.h * src/DownloadResult.h * src/DownloadResultCode.h * src/FeedbackURISelector.cc * src/FeedbackURISelector.h * src/FileEntry.cc * src/FileEntry.h * src/FtpNegotiationCommand.cc * src/HttpListenCommand.cc * src/HttpResponseCommand.cc * src/HttpServerResponseCommand.cc * src/HttpSkipResponseCommand.cc * src/InOrderURISelector.cc * src/InOrderURISelector.h * src/Makefile.am * src/Makefile.in * src/Metalink2RequestGroup.cc * src/MultiUrlRequestInfo.cc * src/MultiUrlRequestInfo.h * src/OptionHandlerFactory.cc * src/PeerListenCommand.cc * src/RecoverableException.h * src/RequestGroup.cc * src/RequestGroup.h * src/RequestGroupMan.cc * src/RequestGroupMan.h * src/TimedHaltCommand.cc * src/TrackerWatcherCommand.cc * src/URIResult.cc * src/URIResult.h * src/URISelector.h * src/XmlRpcMethodImpl.cc * src/bittorrent_helper.cc * src/bittorrent_helper.h * src/download_helper.cc * src/main.cc * src/option_processing.cc * test/BtDependencyTest.cc * test/BtPostDownloadHandlerTest.cc * test/CookieStorageTest.cc * test/DefaultBtMessageDispatcherTest.cc * test/DownloadHandlerFactoryTest.cc * test/DownloadHelperTest.cc * test/FeedbackURISelectorTest.cc * test/FileEntryTest.cc * test/InOrderURISelectorTest.cc * test/Metalink2RequestGroupTest.cc * test/MetalinkPostDownloadHandlerTest.cc * test/RequestGroupManTest.cc * test/RequestGroupTest.cc * test/XmlRpcMethodTest.cc
2009-06-29 08:42:58 +00:00
rg->getDownloadContext()->getFirstFileEntry()->getUris(uris);
std::sort(uris.begin(), uris.end());
CPPUNIT_ASSERT_EQUAL((size_t)2, uris.size());
CPPUNIT_ASSERT_EQUAL
(std::string("ftp://ftphost/aria2-0.5.2.tar.bz2"), uris[0]);
CPPUNIT_ASSERT_EQUAL
(std::string("http://httphost/aria2-0.5.2.tar.bz2"), uris[1]);
const std::shared_ptr<DownloadContext>& dctx = rg->getDownloadContext();
CPPUNIT_ASSERT(dctx);
CPPUNIT_ASSERT_EQUAL((int64_t)0LL, dctx->getTotalLength());
#ifdef ENABLE_MESSAGE_DIGEST
CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), dctx->getHashType());
CPPUNIT_ASSERT_EQUAL
(std::string("a96cf3f0266b91d87d5124cf94326422800b627d"),
util::toHex(dctx->getDigest()));
#endif // ENABLE_MESSAGE_DIGEST
CPPUNIT_ASSERT(dctx->getSignature());
CPPUNIT_ASSERT_EQUAL(std::string("pgp"), dctx->getSignature()->getType());
}
// second file
{
std::shared_ptr<RequestGroup> rg = groups[1];
std::vector<std::string> uris;
2009-06-29 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> Removed _uris from RequestGroup. All functions that refer to _uris were moved to FileEntry. Exit status code are now defined in DownloadResultCode.h. * src/AbstractCommand.cc * src/AdaptiveURISelector.cc * src/AdaptiveURISelector.h * src/AutoSaveCommand.cc * src/BtPostDownloadHandler.cc * src/CheckIntegrityDispatcherCommand.cc * src/CookieStorage.cc * src/DHTAutoSaveCommand.cc * src/DHTBucketRefreshCommand.cc * src/DHTEntryPointNameResolveCommand.cc * src/DHTInteractionCommand.cc * src/DHTPeerAnnounceCommand.cc * src/DHTTokenUpdateCommand.cc * src/DlAbortEx.h * src/DlRetryEx.h * src/DownloadCommand.cc * src/DownloadContext.h * src/DownloadFailureException.h * src/DownloadResult.h * src/DownloadResultCode.h * src/FeedbackURISelector.cc * src/FeedbackURISelector.h * src/FileEntry.cc * src/FileEntry.h * src/FtpNegotiationCommand.cc * src/HttpListenCommand.cc * src/HttpResponseCommand.cc * src/HttpServerResponseCommand.cc * src/HttpSkipResponseCommand.cc * src/InOrderURISelector.cc * src/InOrderURISelector.h * src/Makefile.am * src/Makefile.in * src/Metalink2RequestGroup.cc * src/MultiUrlRequestInfo.cc * src/MultiUrlRequestInfo.h * src/OptionHandlerFactory.cc * src/PeerListenCommand.cc * src/RecoverableException.h * src/RequestGroup.cc * src/RequestGroup.h * src/RequestGroupMan.cc * src/RequestGroupMan.h * src/TimedHaltCommand.cc * src/TrackerWatcherCommand.cc * src/URIResult.cc * src/URIResult.h * src/URISelector.h * src/XmlRpcMethodImpl.cc * src/bittorrent_helper.cc * src/bittorrent_helper.h * src/download_helper.cc * src/main.cc * src/option_processing.cc * test/BtDependencyTest.cc * test/BtPostDownloadHandlerTest.cc * test/CookieStorageTest.cc * test/DefaultBtMessageDispatcherTest.cc * test/DownloadHandlerFactoryTest.cc * test/DownloadHelperTest.cc * test/FeedbackURISelectorTest.cc * test/FileEntryTest.cc * test/InOrderURISelectorTest.cc * test/Metalink2RequestGroupTest.cc * test/MetalinkPostDownloadHandlerTest.cc * test/RequestGroupManTest.cc * test/RequestGroupTest.cc * test/XmlRpcMethodTest.cc
2009-06-29 08:42:58 +00:00
rg->getDownloadContext()->getFirstFileEntry()->getUris(uris);
CPPUNIT_ASSERT_EQUAL((size_t)2, uris.size());
const std::shared_ptr<DownloadContext>& dctx = rg->getDownloadContext();
CPPUNIT_ASSERT(dctx);
#ifdef ENABLE_MESSAGE_DIGEST
CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), dctx->getPieceHashType());
CPPUNIT_ASSERT_EQUAL((size_t)2, dctx->getPieceHashes().size());
CPPUNIT_ASSERT_EQUAL(262144, dctx->getPieceLength());
CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), dctx->getHashType());
CPPUNIT_ASSERT_EQUAL
(std::string("4c255b0ed130f5ea880f0aa061c3da0487e251cc"),
util::toHex(dctx->getDigest()));
#endif // ENABLE_MESSAGE_DIGEST
CPPUNIT_ASSERT(!dctx->getSignature());
}
#ifdef ENABLE_BITTORRENT
// fifth file <- downloading .torrent file
{
std::shared_ptr<RequestGroup> rg = groups[4];
std::vector<std::string> uris;
2009-06-29 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> Removed _uris from RequestGroup. All functions that refer to _uris were moved to FileEntry. Exit status code are now defined in DownloadResultCode.h. * src/AbstractCommand.cc * src/AdaptiveURISelector.cc * src/AdaptiveURISelector.h * src/AutoSaveCommand.cc * src/BtPostDownloadHandler.cc * src/CheckIntegrityDispatcherCommand.cc * src/CookieStorage.cc * src/DHTAutoSaveCommand.cc * src/DHTBucketRefreshCommand.cc * src/DHTEntryPointNameResolveCommand.cc * src/DHTInteractionCommand.cc * src/DHTPeerAnnounceCommand.cc * src/DHTTokenUpdateCommand.cc * src/DlAbortEx.h * src/DlRetryEx.h * src/DownloadCommand.cc * src/DownloadContext.h * src/DownloadFailureException.h * src/DownloadResult.h * src/DownloadResultCode.h * src/FeedbackURISelector.cc * src/FeedbackURISelector.h * src/FileEntry.cc * src/FileEntry.h * src/FtpNegotiationCommand.cc * src/HttpListenCommand.cc * src/HttpResponseCommand.cc * src/HttpServerResponseCommand.cc * src/HttpSkipResponseCommand.cc * src/InOrderURISelector.cc * src/InOrderURISelector.h * src/Makefile.am * src/Makefile.in * src/Metalink2RequestGroup.cc * src/MultiUrlRequestInfo.cc * src/MultiUrlRequestInfo.h * src/OptionHandlerFactory.cc * src/PeerListenCommand.cc * src/RecoverableException.h * src/RequestGroup.cc * src/RequestGroup.h * src/RequestGroupMan.cc * src/RequestGroupMan.h * src/TimedHaltCommand.cc * src/TrackerWatcherCommand.cc * src/URIResult.cc * src/URIResult.h * src/URISelector.h * src/XmlRpcMethodImpl.cc * src/bittorrent_helper.cc * src/bittorrent_helper.h * src/download_helper.cc * src/main.cc * src/option_processing.cc * test/BtDependencyTest.cc * test/BtPostDownloadHandlerTest.cc * test/CookieStorageTest.cc * test/DefaultBtMessageDispatcherTest.cc * test/DownloadHandlerFactoryTest.cc * test/DownloadHelperTest.cc * test/FeedbackURISelectorTest.cc * test/FileEntryTest.cc * test/InOrderURISelectorTest.cc * test/Metalink2RequestGroupTest.cc * test/MetalinkPostDownloadHandlerTest.cc * test/RequestGroupManTest.cc * test/RequestGroupTest.cc * test/XmlRpcMethodTest.cc
2009-06-29 08:42:58 +00:00
rg->getDownloadContext()->getFirstFileEntry()->getUris(uris);
CPPUNIT_ASSERT_EQUAL((size_t)1, uris.size());
CPPUNIT_ASSERT_EQUAL
(std::string("http://host/torrent-http.integrated.torrent"), uris[0]);
const std::shared_ptr<DownloadContext>& dctx = rg->getDownloadContext();
CPPUNIT_ASSERT(dctx);
CPPUNIT_ASSERT_EQUAL(groups[5]->getGID(), rg->belongsTo());
}
#endif // ENABLE_BITTORRENT
// sixth file <- depends on fifth file to download .torrent file.
{
#ifdef ENABLE_BITTORRENT
std::shared_ptr<RequestGroup> rg = groups[5];
#else
std::shared_ptr<RequestGroup> rg = groups[4];
#endif // ENABLE_BITTORRENT
std::vector<std::string> uris;
2009-06-29 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> Removed _uris from RequestGroup. All functions that refer to _uris were moved to FileEntry. Exit status code are now defined in DownloadResultCode.h. * src/AbstractCommand.cc * src/AdaptiveURISelector.cc * src/AdaptiveURISelector.h * src/AutoSaveCommand.cc * src/BtPostDownloadHandler.cc * src/CheckIntegrityDispatcherCommand.cc * src/CookieStorage.cc * src/DHTAutoSaveCommand.cc * src/DHTBucketRefreshCommand.cc * src/DHTEntryPointNameResolveCommand.cc * src/DHTInteractionCommand.cc * src/DHTPeerAnnounceCommand.cc * src/DHTTokenUpdateCommand.cc * src/DlAbortEx.h * src/DlRetryEx.h * src/DownloadCommand.cc * src/DownloadContext.h * src/DownloadFailureException.h * src/DownloadResult.h * src/DownloadResultCode.h * src/FeedbackURISelector.cc * src/FeedbackURISelector.h * src/FileEntry.cc * src/FileEntry.h * src/FtpNegotiationCommand.cc * src/HttpListenCommand.cc * src/HttpResponseCommand.cc * src/HttpServerResponseCommand.cc * src/HttpSkipResponseCommand.cc * src/InOrderURISelector.cc * src/InOrderURISelector.h * src/Makefile.am * src/Makefile.in * src/Metalink2RequestGroup.cc * src/MultiUrlRequestInfo.cc * src/MultiUrlRequestInfo.h * src/OptionHandlerFactory.cc * src/PeerListenCommand.cc * src/RecoverableException.h * src/RequestGroup.cc * src/RequestGroup.h * src/RequestGroupMan.cc * src/RequestGroupMan.h * src/TimedHaltCommand.cc * src/TrackerWatcherCommand.cc * src/URIResult.cc * src/URIResult.h * src/URISelector.h * src/XmlRpcMethodImpl.cc * src/bittorrent_helper.cc * src/bittorrent_helper.h * src/download_helper.cc * src/main.cc * src/option_processing.cc * test/BtDependencyTest.cc * test/BtPostDownloadHandlerTest.cc * test/CookieStorageTest.cc * test/DefaultBtMessageDispatcherTest.cc * test/DownloadHandlerFactoryTest.cc * test/DownloadHelperTest.cc * test/FeedbackURISelectorTest.cc * test/FileEntryTest.cc * test/InOrderURISelectorTest.cc * test/Metalink2RequestGroupTest.cc * test/MetalinkPostDownloadHandlerTest.cc * test/RequestGroupManTest.cc * test/RequestGroupTest.cc * test/XmlRpcMethodTest.cc
2009-06-29 08:42:58 +00:00
rg->getDownloadContext()->getFirstFileEntry()->getUris(uris);
CPPUNIT_ASSERT_EQUAL((size_t)1, uris.size());
CPPUNIT_ASSERT_EQUAL
(std::string("http://host/torrent-http.integrated"), uris[0]);
const std::shared_ptr<DownloadContext>& dctx = rg->getDownloadContext();
CPPUNIT_ASSERT(dctx);
}
}
void Metalink2RequestGroupTest::testGenerate_groupByMetaurl()
{
std::vector<std::shared_ptr<RequestGroup> > groups;
Metalink2RequestGroup().generate(groups,
A2_TEST_DIR"/metalink4-groupbymetaurl.xml",
option_);
CPPUNIT_ASSERT_EQUAL((size_t)3, groups.size());
#ifdef ENABLE_BITTORRENT
// first RequestGroup is torrent for second RequestGroup
{
std::shared_ptr<RequestGroup> rg = groups[0];
std::vector<std::string> uris;
rg->getDownloadContext()->getFirstFileEntry()->getUris(uris);
CPPUNIT_ASSERT_EQUAL((size_t)1, uris.size());
CPPUNIT_ASSERT_EQUAL(std::string("http://torrent"), uris[0]);
}
// second
{
std::shared_ptr<RequestGroup> rg = groups[1];
std::shared_ptr<DownloadContext> dctx = rg->getDownloadContext();
const std::vector<std::shared_ptr<FileEntry> >& fileEntries =
dctx->getFileEntries();
CPPUNIT_ASSERT_EQUAL((size_t)2, fileEntries.size());
CPPUNIT_ASSERT_EQUAL(std::string("./file1"), fileEntries[0]->getPath());
CPPUNIT_ASSERT_EQUAL(std::string("file1"), fileEntries[0]->getOriginalName());
CPPUNIT_ASSERT_EQUAL((size_t)1, fileEntries[0]->getRemainingUris().size());
CPPUNIT_ASSERT_EQUAL(std::string("http://file1p1"),
fileEntries[0]->getRemainingUris()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("./file3"), fileEntries[1]->getPath());
CPPUNIT_ASSERT_EQUAL(std::string("file3"), fileEntries[1]->getOriginalName());
CPPUNIT_ASSERT_EQUAL((size_t)1, fileEntries[1]->getRemainingUris().size());
CPPUNIT_ASSERT_EQUAL(std::string("http://file3p1"),
fileEntries[1]->getRemainingUris()[0]);
}
// third
{
std::shared_ptr<RequestGroup> rg = groups[2];
std::shared_ptr<DownloadContext> dctx = rg->getDownloadContext();
const std::vector<std::shared_ptr<FileEntry> >& fileEntries =
dctx->getFileEntries();
CPPUNIT_ASSERT_EQUAL((size_t)1, fileEntries.size());
CPPUNIT_ASSERT_EQUAL(std::string("./file2"), fileEntries[0]->getPath());
CPPUNIT_ASSERT_EQUAL((size_t)1, fileEntries[0]->getRemainingUris().size());
CPPUNIT_ASSERT_EQUAL(std::string("http://file2p1"),
fileEntries[0]->getRemainingUris()[0]);
}
#else // !ENABLE_BITTORRENT
{
std::shared_ptr<RequestGroup> rg = groups[0];
std::vector<std::string> uris;
rg->getDownloadContext()->getFirstFileEntry()->getUris(uris);
CPPUNIT_ASSERT_EQUAL((size_t)1, uris.size());
CPPUNIT_ASSERT_EQUAL(std::string("http://file1p1"), uris[0]);
}
{
std::shared_ptr<RequestGroup> rg = groups[1];
std::vector<std::string> uris;
rg->getDownloadContext()->getFirstFileEntry()->getUris(uris);
CPPUNIT_ASSERT_EQUAL((size_t)1, uris.size());
CPPUNIT_ASSERT_EQUAL(std::string("http://file2p1"), uris[0]);
}
{
std::shared_ptr<RequestGroup> rg = groups[2];
std::vector<std::string> uris;
rg->getDownloadContext()->getFirstFileEntry()->getUris(uris);
CPPUNIT_ASSERT_EQUAL((size_t)1, uris.size());
CPPUNIT_ASSERT_EQUAL(std::string("http://file3p1"), uris[0]);
}
2012-10-01 14:52:22 +00:00
#endif // !ENABLE_BITTORRENT
}
void Metalink2RequestGroupTest::testGenerate_dosDirTraversal()
{
#ifdef __MINGW32__
#ifdef ENABLE_BITTORRENT
std::vector<std::shared_ptr<RequestGroup> > groups;
option_->put(PREF_DIR, "/tmp");
Metalink2RequestGroup().generate
(groups, A2_TEST_DIR"/metalink4-dosdirtraversal.xml", option_);
CPPUNIT_ASSERT_EQUAL((size_t)3, groups.size());
std::shared_ptr<RequestGroup> rg = groups[0];
std::shared_ptr<FileEntry> file = rg->getDownloadContext()->getFirstFileEntry();
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/..%5C..%5Cexample.ext"),
file->getPath());
2012-10-01 14:52:22 +00:00
rg = groups[2];
file = rg->getDownloadContext()->getFileEntries()[0];
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/..%5C..%5Cfile1.ext"),
file->getPath());
file = rg->getDownloadContext()->getFileEntries()[1];
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/..%5C..%5Cfile2.ext"),
file->getPath());
#endif // ENABLE_BITTORRENT
#endif // __MINGW32__
}
} // namespace aria2