aria2/test/RequestGroupManTest.cc
Tatsuhiro Tsujikawa 4cb5468662 2009-05-09 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Now RequestGroup has its own copy of Option object. This will help
	to give custom option for each RequestGroup.
	addTorrentFile command now takes options.
	* src/AbstractCommand.cc
	* src/AbstractCommand.h
	* src/AbstractProxyRequestCommand.cc
	* src/ActivePeerConnectionCommand.cc
	* src/ActivePeerConnectionCommand.h
	* src/AdaptiveURISelector.cc
	* src/BtCheckIntegrityEntry.cc
	* src/BtDependency.cc
	* src/BtDependency.h
	* src/BtFileAllocationEntry.cc
	* src/BtPostDownloadHandler.cc
	* src/CheckIntegrityEntry.cc
	* src/DownloadCommand.cc
	* src/FtpDownloadCommand.cc
	* src/FtpFinishDownloadCommand.cc
	* src/FtpInitiateConnectionCommand.cc
	* src/FtpNegotiationCommand.cc
	* src/HttpInitiateConnectionCommand.cc
	* src/HttpRequestCommand.cc
	* src/HttpResponseCommand.cc
	* src/HttpSkipResponseCommand.cc
	* src/InitiateConnectionCommand.cc
	* src/InitiateConnectionCommandFactory.cc
	* src/InitiatorMSEHandshakeCommand.cc
	* src/InitiatorMSEHandshakeCommand.h
	* src/Metalink2RequestGroup.cc
	* src/Metalink2RequestGroup.h
	* src/MetalinkPostDownloadHandler.cc
	* src/MultiUrlRequestInfo.cc
	* src/MultiUrlRequestInfo.h
	* src/PeerAbstractCommand.cc
	* src/PeerInteractionCommand.cc
	* src/PeerInteractionCommand.h
	* src/PeerReceiveHandshakeCommand.cc
	* src/PeerReceiveHandshakeCommand.h
	* src/RequestGroup.cc
	* src/RequestGroup.h
	* src/TrackerWatcherCommand.cc
	* src/TrackerWatcherCommand.h
	* src/XmlRpcMethod.cc
	* src/XmlRpcMethod.h
	* src/XmlRpcMethodImpl.cc
	* src/download_helper.cc
	* src/download_helper.h
	* src/main.cc
	* test/BtDependencyTest.cc
	* test/BtPostDownloadHandlerTest.cc
	* test/DefaultBtMessageDispatcherTest.cc
	* test/DownloadHandlerFactoryTest.cc
	* test/DownloadHelperTest.cc
	* test/Metalink2RequestGroupTest.cc
	* test/MetalinkPostDownloadHandlerTest.cc
	* test/RequestGroupManTest.cc
	* test/RequestGroupTest.cc
2009-05-08 16:41:21 +00:00

112 lines
3 KiB
C++

#include "RequestGroupMan.h"
#include <fstream>
#include <cppunit/extensions/HelperMacros.h>
#include "prefs.h"
#include "SingleFileDownloadContext.h"
#include "RequestGroup.h"
#include "Option.h"
#include "DownloadResult.h"
#include "FileEntry.h"
#include "ServerStatMan.h"
#include "ServerStat.h"
#include "File.h"
namespace aria2 {
class RequestGroupManTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(RequestGroupManTest);
CPPUNIT_TEST(testIsSameFileBeingDownloaded);
CPPUNIT_TEST(testGetInitialCommands);
CPPUNIT_TEST(testLoadServerStat);
CPPUNIT_TEST(testSaveServerStat);
CPPUNIT_TEST_SUITE_END();
private:
SharedHandle<Option> _option;
public:
void setUp()
{
_option.reset(new Option());
}
void testIsSameFileBeingDownloaded();
void testGetInitialCommands();
void testLoadServerStat();
void testSaveServerStat();
};
CPPUNIT_TEST_SUITE_REGISTRATION( RequestGroupManTest );
void RequestGroupManTest::testIsSameFileBeingDownloaded()
{
std::deque<std::string> uris;
uris.push_back("http://localhost/aria2.tar.bz2");
SharedHandle<RequestGroup> rg1(new RequestGroup(_option, uris));
SharedHandle<RequestGroup> rg2(new RequestGroup(_option, uris));
SharedHandle<SingleFileDownloadContext> dctx1
(new SingleFileDownloadContext(0, 0, "aria2.tar.bz2"));
SharedHandle<SingleFileDownloadContext> dctx2
(new SingleFileDownloadContext(0, 0, "aria2.tar.bz2"));
rg1->setDownloadContext(dctx1);
rg2->setDownloadContext(dctx2);
RequestGroups rgs;
rgs.push_back(rg1);
rgs.push_back(rg2);
RequestGroupMan gm(rgs, 1, _option.get());
CPPUNIT_ASSERT(gm.isSameFileBeingDownloaded(rg1.get()));
dctx2->setFilename("aria2.tar.gz");
CPPUNIT_ASSERT(!gm.isSameFileBeingDownloaded(rg1.get()));
}
void RequestGroupManTest::testGetInitialCommands()
{
// TODO implement later
}
void RequestGroupManTest::testSaveServerStat()
{
RequestGroupMan rm(std::deque<SharedHandle<RequestGroup> >(),0,_option.get());
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");
std::ofstream o(f.getPath().c_str(), std::ios::binary);
o << "host=localhost, protocol=http, dl_speed=0, last_updated=1219505257,"
<< "status=OK";
o.close();
RequestGroupMan rm(std::deque<SharedHandle<RequestGroup> >(),0,_option.get());
std::cerr << "testLoadServerStat" << std::endl;
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());
}
} // namespace aria2