2007-06-03 14:24:37 +00:00
|
|
|
#include "RequestGroupMan.h"
|
2009-01-06 13:13:42 +00:00
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2007-07-09 13:30:45 +00:00
|
|
|
#include "prefs.h"
|
2009-06-28 10:37:15 +00:00
|
|
|
#include "DownloadContext.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "RequestGroup.h"
|
2007-10-30 12:48:01 +00:00
|
|
|
#include "Option.h"
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
#include "DownloadResult.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "FileEntry.h"
|
2008-08-04 17:06:47 +00:00
|
|
|
#include "ServerStatMan.h"
|
2008-08-23 15:42:06 +00:00
|
|
|
#include "ServerStat.h"
|
|
|
|
#include "File.h"
|
2007-06-03 14:24:37 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2007-06-03 14:24:37 +00:00
|
|
|
|
|
|
|
class RequestGroupManTest : public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(RequestGroupManTest);
|
|
|
|
CPPUNIT_TEST(testIsSameFileBeingDownloaded);
|
2007-07-09 13:30:45 +00:00
|
|
|
CPPUNIT_TEST(testGetInitialCommands);
|
2008-08-23 15:42:06 +00:00
|
|
|
CPPUNIT_TEST(testLoadServerStat);
|
|
|
|
CPPUNIT_TEST(testSaveServerStat);
|
2007-06-03 14:24:37 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
2009-05-08 16:41:21 +00:00
|
|
|
SharedHandle<Option> _option;
|
2007-06-03 14:24:37 +00:00
|
|
|
public:
|
2009-05-08 16:41:21 +00:00
|
|
|
void setUp()
|
|
|
|
{
|
|
|
|
_option.reset(new Option());
|
|
|
|
}
|
|
|
|
|
2007-06-03 14:24:37 +00:00
|
|
|
void testIsSameFileBeingDownloaded();
|
2007-07-09 13:30:45 +00:00
|
|
|
void testGetInitialCommands();
|
2008-08-23 15:42:06 +00:00
|
|
|
void testLoadServerStat();
|
|
|
|
void testSaveServerStat();
|
2007-06-03 14:24:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( RequestGroupManTest );
|
|
|
|
|
|
|
|
void RequestGroupManTest::testIsSameFileBeingDownloaded()
|
|
|
|
{
|
2009-06-29 08:42:58 +00:00
|
|
|
SharedHandle<RequestGroup> rg1(new RequestGroup(_option));
|
|
|
|
SharedHandle<RequestGroup> rg2(new RequestGroup(_option));
|
2007-06-03 14:24:37 +00:00
|
|
|
|
2009-06-28 10:37:15 +00:00
|
|
|
SharedHandle<DownloadContext> dctx1
|
|
|
|
(new DownloadContext(0, 0, "aria2.tar.bz2"));
|
|
|
|
SharedHandle<DownloadContext> dctx2
|
|
|
|
(new DownloadContext(0, 0, "aria2.tar.bz2"));
|
2007-06-03 14:24:37 +00:00
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
rg1->setDownloadContext(dctx1);
|
|
|
|
rg2->setDownloadContext(dctx2);
|
2007-06-03 14:24:37 +00:00
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
RequestGroups rgs;
|
|
|
|
rgs.push_back(rg1);
|
|
|
|
rgs.push_back(rg2);
|
2007-06-03 14:24:37 +00:00
|
|
|
|
2009-05-08 16:41:21 +00:00
|
|
|
RequestGroupMan gm(rgs, 1, _option.get());
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2007-06-03 14:24:37 +00:00
|
|
|
CPPUNIT_ASSERT(gm.isSameFileBeingDownloaded(rg1.get()));
|
|
|
|
|
2009-06-28 10:37:15 +00:00
|
|
|
dctx2->getFirstFileEntry()->setPath("aria2.tar.gz");
|
2007-06-03 14:24:37 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!gm.isSameFileBeingDownloaded(rg1.get()));
|
|
|
|
|
|
|
|
}
|
2007-07-09 13:30:45 +00:00
|
|
|
|
|
|
|
void RequestGroupManTest::testGetInitialCommands()
|
|
|
|
{
|
2007-10-11 16:58:24 +00:00
|
|
|
// TODO implement later
|
2007-07-09 13:30:45 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-08-23 15:42:06 +00:00
|
|
|
void RequestGroupManTest::testSaveServerStat()
|
|
|
|
{
|
2009-05-08 16:41:21 +00:00
|
|
|
RequestGroupMan rm(std::deque<SharedHandle<RequestGroup> >(),0,_option.get());
|
2008-08-23 15:42:06 +00:00
|
|
|
SharedHandle<ServerStat> ss_localhost(new ServerStat("localhost", "http"));
|
|
|
|
rm.addServerStat(ss_localhost);
|
|
|
|
File f("/tmp/aria2_RequestGroupManTest_testSaveServerStat");
|
|
|
|
if(f.exists()) {
|
|
|
|
f.remove();
|
|
|
|
}
|
|
|
|
CPPUNIT_ASSERT(rm.saveServerStat(f.getPath()));
|
|
|
|
CPPUNIT_ASSERT(f.isFile());
|
|
|
|
|
|
|
|
f.remove();
|
|
|
|
CPPUNIT_ASSERT(f.mkdirs());
|
|
|
|
CPPUNIT_ASSERT(!rm.saveServerStat(f.getPath()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestGroupManTest::testLoadServerStat()
|
|
|
|
{
|
|
|
|
File f("/tmp/aria2_RequestGroupManTest_testLoadServerStat");
|
2009-02-13 11:28:42 +00:00
|
|
|
std::ofstream o(f.getPath().c_str(), std::ios::binary);
|
2008-08-23 15:42:06 +00:00
|
|
|
o << "host=localhost, protocol=http, dl_speed=0, last_updated=1219505257,"
|
|
|
|
<< "status=OK";
|
|
|
|
o.close();
|
|
|
|
|
2009-05-08 16:41:21 +00:00
|
|
|
RequestGroupMan rm(std::deque<SharedHandle<RequestGroup> >(),0,_option.get());
|
2009-01-06 13:13:42 +00:00
|
|
|
std::cerr << "testLoadServerStat" << std::endl;
|
2008-08-23 15:42:06 +00:00
|
|
|
CPPUNIT_ASSERT(rm.loadServerStat(f.getPath()));
|
|
|
|
SharedHandle<ServerStat> ss_localhost = rm.findServerStat("localhost",
|
|
|
|
"http");
|
|
|
|
CPPUNIT_ASSERT(!ss_localhost.isNull());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), ss_localhost->getHostname());
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|