blob: cc202dc69e8dbacf19a065af1b1382c068387f04 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#include "BtPostDownloadHandler.h"
#include "BtContext.h"
#include "RequestGroup.h"
#include "Option.h"
#include "SingleFileDownloadContext.h"
#include "FileEntry.h"
#include <cppunit/extensions/HelperMacros.h>
namespace aria2 {
class BtPostDownloadHandlerTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(BtPostDownloadHandlerTest);
CPPUNIT_TEST(testCanHandle_extension);
CPPUNIT_TEST(testCanHandle_contentType);
CPPUNIT_TEST(testGetNextRequestGroups);
CPPUNIT_TEST_SUITE_END();
private:
public:
void setUp() {}
void testCanHandle_extension();
void testCanHandle_contentType();
void testGetNextRequestGroups();
};
CPPUNIT_TEST_SUITE_REGISTRATION( BtPostDownloadHandlerTest );
void BtPostDownloadHandlerTest::testCanHandle_extension()
{
Option op;
SharedHandle<SingleFileDownloadContext> dctx
(new SingleFileDownloadContext(0, 0, "test.torrent"));
RequestGroup rg(&op, std::deque<std::string>());
rg.setDownloadContext(dctx);
BtPostDownloadHandler handler;
CPPUNIT_ASSERT(handler.canHandle(&rg));
dctx->setFilename("test.torrent2");
CPPUNIT_ASSERT(!handler.canHandle(&rg));
}
void BtPostDownloadHandlerTest::testCanHandle_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);
BtPostDownloadHandler handler;
CPPUNIT_ASSERT(handler.canHandle(&rg));
dctx->setContentType("application/octet-stream");
CPPUNIT_ASSERT(!handler.canHandle(&rg));
}
void BtPostDownloadHandlerTest::testGetNextRequestGroups()
{
Option op;
SharedHandle<SingleFileDownloadContext> dctx
(new SingleFileDownloadContext(0, 0, "test.torrent"));
RequestGroup rg(&op, std::deque<std::string>());
rg.setDownloadContext(dctx);
rg.initPieceStorage();
BtPostDownloadHandler handler;
std::deque<SharedHandle<RequestGroup> > groups;
handler.getNextRequestGroups(groups, &rg);
CPPUNIT_ASSERT_EQUAL((size_t)1, groups.size());
SharedHandle<BtContext> btctx
(dynamic_pointer_cast<BtContext>(groups.front()->getDownloadContext()));
CPPUNIT_ASSERT(!btctx.isNull());
CPPUNIT_ASSERT_EQUAL(std::string("aria2-test"), btctx->getName());
}
} // namespace aria2
|