#include "HttpRequest.h" #include "prefs.h" #include "RequestFactory.h" #include using namespace std; class HttpRequestTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(HttpRequestTest); CPPUNIT_TEST(testGetStartByte); CPPUNIT_TEST(testGetEndByte); CPPUNIT_TEST(testCreateRequest); CPPUNIT_TEST(testCreateRequest_ftp); CPPUNIT_TEST(testCreateRequest_with_cookie); CPPUNIT_TEST(testCreateProxyRequest); CPPUNIT_TEST(testIsRangeSatisfied); CPPUNIT_TEST_SUITE_END(); private: public: void setUp() {} void testGetStartByte(); void testGetEndByte(); void testCreateRequest(); void testCreateRequest_ftp(); void testCreateRequest_with_cookie(); void testCreateProxyRequest(); void testIsRangeSatisfied(); }; CPPUNIT_TEST_SUITE_REGISTRATION( HttpRequestTest ); void HttpRequestTest::testGetStartByte() { HttpRequest httpRequest; SegmentHandle segment = new Segment(1, 1024*1024, 1024*1024, 0); CPPUNIT_ASSERT_EQUAL((int64_t)0, httpRequest.getStartByte()); httpRequest.setSegment(segment); CPPUNIT_ASSERT_EQUAL((int64_t)1024*1024, httpRequest.getStartByte()); } void HttpRequestTest::testGetEndByte() { int32_t index = 1; int32_t length = 1024*1024-1024; int32_t segmentLength = 1024*1024; int32_t writtenLength = 1024; HttpRequest httpRequest; SegmentHandle segment = new Segment(index, length, segmentLength, writtenLength); CPPUNIT_ASSERT_EQUAL((int64_t)0, httpRequest.getEndByte()); httpRequest.setSegment(segment); CPPUNIT_ASSERT_EQUAL((int64_t)0, httpRequest.getEndByte()); RequestHandle request = new Request(); request->setKeepAlive(true); httpRequest.setRequest(request); CPPUNIT_ASSERT_EQUAL((int64_t)segmentLength*index+length-1, httpRequest.getEndByte()); request->setKeepAlive(false); CPPUNIT_ASSERT_EQUAL((int64_t)0, httpRequest.getEndByte()); } void HttpRequestTest::testCreateRequest() { SharedHandle