aria2/test/DownloadHandlerFactoryTest.cc
Tatsuhiro Tsujikawa e82f870fdc 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

115 lines
3.3 KiB
C++

#include "DownloadHandlerFactory.h"
#include <cppunit/extensions/HelperMacros.h>
#include "RequestGroup.h"
#include "Option.h"
#include "DownloadContext.h"
#include "MemoryBufferPreDownloadHandler.h"
#include "FileEntry.h"
namespace aria2 {
class DownloadHandlerFactoryTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(DownloadHandlerFactoryTest);
#ifdef ENABLE_METALINK
CPPUNIT_TEST(testGetMetalinkPreDownloadHandler_extension);
CPPUNIT_TEST(testGetMetalinkPreDownloadHandler_contentType);
#endif // ENABLE_METALINK
#ifdef ENABLE_BITTORRENT
CPPUNIT_TEST(testGetBtPreDownloadHandler_extension);
CPPUNIT_TEST(testGetBtPreDownloadHandler_contentType);
#endif // ENABLE_BITTORRENT
CPPUNIT_TEST_SUITE_END();
private:
SharedHandle<Option> _option;
public:
void setUp()
{
_option.reset(new Option());
}
#ifdef ENABLE_METALINK
void testGetMetalinkPreDownloadHandler_extension();
void testGetMetalinkPreDownloadHandler_contentType();
#endif // ENABLE_METALINK
#ifdef ENABLE_BITTORRENT
void testGetBtPreDownloadHandler_extension();
void testGetBtPreDownloadHandler_contentType();
#endif // ENABLE_BITTORRENT
};
CPPUNIT_TEST_SUITE_REGISTRATION( DownloadHandlerFactoryTest );
#ifdef ENABLE_METALINK
void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_extension()
{
SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0, "test.metalink"));
RequestGroup rg(_option);
rg.setDownloadContext(dctx);
SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler();
CPPUNIT_ASSERT(handler->canHandle(&rg));
dctx->getFirstFileEntry()->setPath("test.metalink2");
CPPUNIT_ASSERT(!handler->canHandle(&rg));
}
void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_contentType()
{
SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0, "test"));
dctx->getFirstFileEntry()->setContentType("application/metalink+xml");
RequestGroup rg(_option);
rg.setDownloadContext(dctx);
SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler();
CPPUNIT_ASSERT(handler->canHandle(&rg));
dctx->getFirstFileEntry()->setContentType("application/octet-stream");
CPPUNIT_ASSERT(!handler->canHandle(&rg));
}
#endif // ENABLE_METALINK
#ifdef ENABLE_BITTORRENT
void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_extension()
{
SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0, "test.torrent"));
RequestGroup rg(_option);
rg.setDownloadContext(dctx);
SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getBtPreDownloadHandler();
CPPUNIT_ASSERT(handler->canHandle(&rg));
dctx->getFirstFileEntry()->setPath("test.torrent2");
CPPUNIT_ASSERT(!handler->canHandle(&rg));
}
void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_contentType()
{
SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0, "test"));
dctx->getFirstFileEntry()->setContentType("application/x-bittorrent");
RequestGroup rg(_option);
rg.setDownloadContext(dctx);
SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getBtPreDownloadHandler();
CPPUNIT_ASSERT(handler->canHandle(&rg));
dctx->getFirstFileEntry()->setContentType("application/octet-stream");
CPPUNIT_ASSERT(!handler->canHandle(&rg));
}
#endif // ENABLE_BITTORRENT
} // namespace aria2