#include "Request.h" #include #include "Netrc.h" #include "DefaultAuthResolver.h" #include "NetrcAuthResolver.h" #include "uri.h" namespace aria2 { class RequestTest:public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(RequestTest); CPPUNIT_TEST(testSetUri1); CPPUNIT_TEST(testSetUri2); CPPUNIT_TEST(testSetUri7); CPPUNIT_TEST(testSetUri17); CPPUNIT_TEST(testSetUri_supportsPersistentConnection); CPPUNIT_TEST(testRedirectUri); CPPUNIT_TEST(testRedirectUri2); CPPUNIT_TEST(testRedirectUri_supportsPersistentConnection); CPPUNIT_TEST(testResetUri); CPPUNIT_TEST(testResetUri_supportsPersistentConnection); CPPUNIT_TEST(testInnerLink); CPPUNIT_TEST(testInnerLinkInReferer); CPPUNIT_TEST(testGetURIHost); CPPUNIT_TEST_SUITE_END(); public: void testSetUri1(); void testSetUri2(); void testSetUri7(); void testSetUri17(); void testSetUri_supportsPersistentConnection(); void testRedirectUri(); void testRedirectUri2(); void testRedirectUri_supportsPersistentConnection(); void testResetUri(); void testResetUri_supportsPersistentConnection(); void testInnerLink(); void testInnerLinkInReferer(); void testGetURIHost(); }; CPPUNIT_TEST_SUITE_REGISTRATION( RequestTest ); void RequestTest::testSetUri1() { Request req; bool v = req.setUri("http://aria.rednoah.com/"); CPPUNIT_ASSERT(v); CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/"), req.getUri()); CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/"), req.getCurrentUri()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPreviousUri()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL((uint16_t)80, req.getPort()); CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("/"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getFile()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getUsername()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPassword()); CPPUNIT_ASSERT(!req.isIPv6LiteralAddress()); } void RequestTest::testSetUri2() { Request req; bool v = req.setUri("http://aria.rednoah.com:8080/index.html"); req.setReferer("http://aria.rednoah.com:8080"); CPPUNIT_ASSERT(v); // referer is unchaged CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com:8080"), req.getReferer()); // previousUri must equal to referer; CPPUNIT_ASSERT_EQUAL(req.getReferer(), req.getPreviousUri()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL((uint16_t)8080, req.getPort()); CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("/"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string("index.html"), req.getFile()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery()); } void RequestTest::testSetUri7() { Request req; bool v = req.setUri("http://"); CPPUNIT_ASSERT(!v); } void RequestTest::testSetUri17() { Request req; bool v = req.setUri("http://host:80/file