| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 | #include "DownloadHandlerFactory.h"#include "RequestGroup.h"#include "Option.h"#include "SingleFileDownloadContext.h"#include "MemoryBufferPreDownloadHandler.h"#include "FileEntry.h"#include <cppunit/extensions/HelperMacros.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:public:  void setUp() {}#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_METALINKvoid DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_extension(){  Option op;  SharedHandle<SingleFileDownloadContext> dctx    (new SingleFileDownloadContext(0, 0, "test.metalink"));  RequestGroup rg(&op, std::deque<std::string>());  rg.setDownloadContext(dctx);  SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler();  CPPUNIT_ASSERT(handler->canHandle(&rg));  dctx->setFilename("test.metalink2");  CPPUNIT_ASSERT(!handler->canHandle(&rg));}void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_contentType(){  Option op;  SharedHandle<SingleFileDownloadContext> dctx    (new SingleFileDownloadContext(0, 0, "test"));  dctx->setContentType("application/metalink+xml");  RequestGroup rg(&op, std::deque<std::string>());  rg.setDownloadContext(dctx);  SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler();  CPPUNIT_ASSERT(handler->canHandle(&rg));  dctx->setContentType("application/octet-stream");  CPPUNIT_ASSERT(!handler->canHandle(&rg));}#endif // ENABLE_METALINK#ifdef ENABLE_BITTORRENTvoid DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_extension(){  Option op;  SharedHandle<SingleFileDownloadContext> dctx    (new SingleFileDownloadContext(0, 0, "test.torrent"));  RequestGroup rg(&op, std::deque<std::string>());  rg.setDownloadContext(dctx);  SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getBtPreDownloadHandler();  CPPUNIT_ASSERT(handler->canHandle(&rg));  dctx->setFilename("test.torrent2");  CPPUNIT_ASSERT(!handler->canHandle(&rg));}void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_contentType(){  Option op;  SharedHandle<SingleFileDownloadContext> dctx    (new SingleFileDownloadContext(0, 0, "test"));  dctx->setContentType("application/x-bittorrent");  RequestGroup rg(&op, std::deque<std::string>());  rg.setDownloadContext(dctx);  SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getBtPreDownloadHandler();  CPPUNIT_ASSERT(handler->canHandle(&rg));  dctx->setContentType("application/octet-stream");  CPPUNIT_ASSERT(!handler->canHandle(&rg));}#endif // ENABLE_BITTORRENT} // namespace aria2
 |