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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
#include "HttpHeader.h"
#include <sstream>
#include <cppunit/extensions/HelperMacros.h>
#include "Range.h"
namespace aria2 {
class HttpHeaderTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(HttpHeaderTest);
CPPUNIT_TEST(testGetRange);
CPPUNIT_TEST(testGet);
CPPUNIT_TEST(testClearField);
CPPUNIT_TEST(testFill);
CPPUNIT_TEST_SUITE_END();
public:
void testGetRange();
void testGet();
void testClearField();
void testFill();
};
CPPUNIT_TEST_SUITE_REGISTRATION( HttpHeaderTest );
void HttpHeaderTest::testGetRange()
{
{
HttpHeader httpHeader;
httpHeader.put("Content-Range",
"9223372036854775800-9223372036854775801/9223372036854775807");
SharedHandle<Range> range = httpHeader.getRange();
CPPUNIT_ASSERT_EQUAL((off_t)9223372036854775800LL, range->getStartByte());
CPPUNIT_ASSERT_EQUAL((off_t)9223372036854775801LL, range->getEndByte());
CPPUNIT_ASSERT_EQUAL((uint64_t)9223372036854775807ULL, range->getEntityLength());
}
{
HttpHeader httpHeader;
httpHeader.put("Content-Range",
"9223372036854775800-9223372036854775801/9223372036854775807");
SharedHandle<Range> range = httpHeader.getRange();
CPPUNIT_ASSERT_EQUAL((off_t)9223372036854775800LL, range->getStartByte());
CPPUNIT_ASSERT_EQUAL((off_t)9223372036854775801LL, range->getEndByte());
CPPUNIT_ASSERT_EQUAL((uint64_t)9223372036854775807ULL, range->getEntityLength());
}
{
HttpHeader httpHeader;
httpHeader.put("Content-Range", "bytes */1024");
SharedHandle<Range> range = httpHeader.getRange();
CPPUNIT_ASSERT_EQUAL((off_t)0, range->getStartByte());
CPPUNIT_ASSERT_EQUAL((off_t)0, range->getEndByte());
CPPUNIT_ASSERT_EQUAL((uint64_t)0, range->getEntityLength());
}
{
HttpHeader httpHeader;
httpHeader.put("Content-Range", "bytes 0-9/*");
SharedHandle<Range> range = httpHeader.getRange();
CPPUNIT_ASSERT_EQUAL((off_t)0, range->getStartByte());
CPPUNIT_ASSERT_EQUAL((off_t)0, range->getEndByte());
CPPUNIT_ASSERT_EQUAL((uint64_t)0, range->getEntityLength());
}
}
void HttpHeaderTest::testGet()
{
HttpHeader h;
h.put("A", "100");
h.put("a", "101");
h.put("B", "200");
std::vector<std::string> r(h.get("A"));
CPPUNIT_ASSERT_EQUAL((size_t)2, r.size());
CPPUNIT_ASSERT_EQUAL(std::string("100"), r[0]);
CPPUNIT_ASSERT_EQUAL(std::string("101"), r[1]);
}
void HttpHeaderTest::testClearField()
{
HttpHeader h;
h.setStatusCode(200);
h.setVersion(HttpHeader::HTTP_1_1);
h.put("Foo", "Bar");
CPPUNIT_ASSERT_EQUAL(std::string("Bar"), h.getFirst("Foo"));
h.clearField();
CPPUNIT_ASSERT_EQUAL(std::string(""), h.getFirst("Foo"));
CPPUNIT_ASSERT_EQUAL(200, h.getStatusCode());
CPPUNIT_ASSERT_EQUAL(std::string(HttpHeader::HTTP_1_1), h.getVersion());
}
void HttpHeaderTest::testFill()
{
std::stringstream ss;
ss << "Host: aria2.sourceforge.net\r\n"
<< "Connection: close \r\n" // trailing white space
<< "Multi-Line: text1\r\n"
<< " text2\r\n"
<< " text3\r\n"
<< "Duplicate: foo\r\n"
<< "Duplicate: bar\r\n";
HttpHeader h;
h.fill(ss);
CPPUNIT_ASSERT_EQUAL(std::string("aria2.sourceforge.net"),
h.getFirst("Host"));
CPPUNIT_ASSERT_EQUAL(std::string("close"),
h.getFirst("Connection"));
CPPUNIT_ASSERT_EQUAL(std::string("text1 text2 text3"),
h.getFirst("Multi-Line"));
CPPUNIT_ASSERT_EQUAL(std::string("foo"),
h.get("Duplicate")[0]);
CPPUNIT_ASSERT_EQUAL(std::string("bar"),
h.get("Duplicate")[1]);
}
} // namespace aria2
|