mirror of
https://github.com/aria2/aria2.git
synced 2025-02-26 08:22:11 +00:00
Rewritten SharedHandle. Now copy constructor taking raw pointer has keyword explicit and SharedHandle's default constructor initializes its internal obj to null, old implementation initializes it using obj's default constructor. To assign null, write SharedHandle<T> x(...); x.reset(); TODO: test/SharedHandleTest.cc needs more tests. * src/SharedHandle.h
103 lines
3.4 KiB
C++
103 lines
3.4 KiB
C++
#include "Metalink2RequestGroup.h"
|
|
#include "SingleFileDownloadContext.h"
|
|
#include "prefs.h"
|
|
#include "Option.h"
|
|
#include "RequestGroup.h"
|
|
#include "FileEntry.h"
|
|
#include <algorithm>
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
namespace aria2 {
|
|
|
|
class Metalink2RequestGroupTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(Metalink2RequestGroupTest);
|
|
CPPUNIT_TEST(testGenerate);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
private:
|
|
SharedHandle<Option> _option;
|
|
|
|
public:
|
|
void setUp()
|
|
{
|
|
_option.reset(new Option());
|
|
_option->put(PREF_SPLIT, "1");
|
|
}
|
|
|
|
void testGenerate();
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( Metalink2RequestGroupTest );
|
|
|
|
void Metalink2RequestGroupTest::testGenerate()
|
|
{
|
|
std::deque<SharedHandle<RequestGroup> > groups =
|
|
Metalink2RequestGroup(_option.get()).generate("test.xml");
|
|
// first file
|
|
{
|
|
SharedHandle<RequestGroup> rg = groups[0];
|
|
std::deque<std::string> uris = rg->getUris();
|
|
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]);
|
|
SharedHandle<SingleFileDownloadContext> dctx
|
|
(dynamic_pointer_cast<SingleFileDownloadContext>(rg->getDownloadContext()));
|
|
CPPUNIT_ASSERT(!dctx.isNull());
|
|
CPPUNIT_ASSERT_EQUAL(0ULL, dctx->getTotalLength());
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
|
CPPUNIT_ASSERT_EQUAL(std::string("sha1"), dctx->getChecksumHashAlgo());
|
|
CPPUNIT_ASSERT_EQUAL(std::string("a96cf3f0266b91d87d5124cf94326422800b627d"),
|
|
dctx->getChecksum());
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
|
}
|
|
// second file
|
|
{
|
|
SharedHandle<RequestGroup> rg = groups[1];
|
|
std::deque<std::string> uris = rg->getUris();
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, uris.size());
|
|
SharedHandle<SingleFileDownloadContext> dctx
|
|
(dynamic_pointer_cast<SingleFileDownloadContext>(rg->getDownloadContext()));
|
|
CPPUNIT_ASSERT(!dctx.isNull());
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
|
CPPUNIT_ASSERT_EQUAL(std::string("sha1"), dctx->getPieceHashAlgo());
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, dctx->getPieceHashes().size());
|
|
CPPUNIT_ASSERT_EQUAL((size_t)262144, dctx->getPieceLength());
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), dctx->getChecksumHashAlgo());
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), dctx->getChecksum());
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
|
}
|
|
|
|
#ifdef ENABLE_BITTORRENT
|
|
// fifth file <- downloading .torrent file
|
|
{
|
|
SharedHandle<RequestGroup> rg = groups[4];
|
|
std::deque<std::string> uris = rg->getUris();
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, uris.size());
|
|
CPPUNIT_ASSERT_EQUAL(std::string("http://host/torrent-http.integrated.torrent"),
|
|
uris[0]);
|
|
SharedHandle<SingleFileDownloadContext> dctx
|
|
(dynamic_pointer_cast<SingleFileDownloadContext>(rg->getDownloadContext()));
|
|
CPPUNIT_ASSERT(!dctx.isNull());
|
|
}
|
|
#endif // ENABLE_BITTORRENT
|
|
|
|
// sixth file <- depends on thrid file
|
|
{
|
|
#ifdef ENABLE_BITTORRENT
|
|
SharedHandle<RequestGroup> rg = groups[5];
|
|
#else
|
|
SharedHandle<RequestGroup> rg = groups[4];
|
|
#endif // ENABLE_BITTORRENT
|
|
std::deque<std::string> uris = rg->getUris();
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, uris.size());
|
|
CPPUNIT_ASSERT_EQUAL(std::string("http://host/torrent-http.integrated"), uris[0]);
|
|
SharedHandle<SingleFileDownloadContext> dctx
|
|
(dynamic_pointer_cast<SingleFileDownloadContext>(rg->getDownloadContext()));
|
|
CPPUNIT_ASSERT(!dctx.isNull());
|
|
}
|
|
}
|
|
|
|
} // namespace aria2
|