#include "Request.h" #include #include "Netrc.h" #include "DefaultAuthResolver.h" #include "NetrcAuthResolver.h" namespace aria2 { class RequestTest:public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(RequestTest); CPPUNIT_TEST(testSetUri1); CPPUNIT_TEST(testSetUri2); CPPUNIT_TEST(testSetUri3); CPPUNIT_TEST(testSetUri4); CPPUNIT_TEST(testSetUri5); CPPUNIT_TEST(testSetUri6); CPPUNIT_TEST(testSetUri7); CPPUNIT_TEST(testSetUri8); CPPUNIT_TEST(testSetUri9); CPPUNIT_TEST(testSetUri10); CPPUNIT_TEST(testSetUri11); CPPUNIT_TEST(testSetUri12); CPPUNIT_TEST(testSetUri13); CPPUNIT_TEST(testSetUri14); CPPUNIT_TEST(testSetUri15); CPPUNIT_TEST(testSetUri16); CPPUNIT_TEST(testSetUri17); CPPUNIT_TEST(testSetUri18); CPPUNIT_TEST(testSetUri19); CPPUNIT_TEST(testSetUri20); CPPUNIT_TEST(testSetUri_username); CPPUNIT_TEST(testSetUri_usernamePassword); CPPUNIT_TEST(testSetUri_zeroUsername); CPPUNIT_TEST(testSetUri_supportsPersistentConnection); CPPUNIT_TEST(testSetUri_ipv6); 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 testSetUri3(); void testSetUri4(); void testSetUri5(); void testSetUri6(); void testSetUri7(); void testSetUri8(); void testSetUri9(); void testSetUri10(); void testSetUri11(); void testSetUri12(); void testSetUri13(); void testSetUri14(); void testSetUri15(); void testSetUri16(); void testSetUri17(); void testSetUri18(); void testSetUri19(); void testSetUri20(); void testSetUri_username(); void testSetUri_usernamePassword(); void testSetUri_zeroUsername(); void testSetUri_supportsPersistentConnection(); void testSetUri_ipv6(); 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::testSetUri3() { Request req; bool v = req.setUri("http://aria.rednoah.com/aria2/index.html"); CPPUNIT_ASSERT(v); 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("/aria2"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string("index.html"), req.getFile()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery()); } void RequestTest::testSetUri4() { Request req; bool v = req.setUri("http://aria.rednoah.com/aria2/aria3/index.html"); CPPUNIT_ASSERT(v); 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("/aria2/aria3"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string("index.html"), req.getFile()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery()); } void RequestTest::testSetUri5() { Request req; bool v = req.setUri("http://aria.rednoah.com/aria2/aria3/"); CPPUNIT_ASSERT(v); 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("/aria2/aria3"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getFile()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery()); } void RequestTest::testSetUri6() { Request req; bool v = req.setUri("http://aria.rednoah.com/aria2/aria3"); CPPUNIT_ASSERT(v); 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("/aria2"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string("aria3"), req.getFile()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery()); } void RequestTest::testSetUri7() { Request req; bool v = req.setUri("http://"); CPPUNIT_ASSERT(!v); } void RequestTest::testSetUri8() { Request req; bool v = req.setUri("http:/aria.rednoah.com"); CPPUNIT_ASSERT(!v); } void RequestTest::testSetUri9() { Request req; bool v = req.setUri("h"); CPPUNIT_ASSERT(!v); } void RequestTest::testSetUri10() { Request req; bool v = req.setUri(""); CPPUNIT_ASSERT(!v); } void RequestTest::testSetUri11() { Request req; bool v = req.setUri("http://host?query/"); CPPUNIT_ASSERT(v); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("host"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("/"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getFile()); CPPUNIT_ASSERT_EQUAL(std::string("?query/"), req.getQuery()); } void RequestTest::testSetUri12() { Request req; bool v = req.setUri("http://host?query"); CPPUNIT_ASSERT(v); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("host"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("/"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getFile()); CPPUNIT_ASSERT_EQUAL(std::string("?query"), req.getQuery()); } void RequestTest::testSetUri13() { Request req; bool v = req.setUri("http://host/?query"); CPPUNIT_ASSERT(v); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("host"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("/"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getFile()); CPPUNIT_ASSERT_EQUAL(std::string("?query"), req.getQuery()); } void RequestTest::testSetUri14() { Request req; bool v = req.setUri("http://host:8080/abc?query"); CPPUNIT_ASSERT(v); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("host"), req.getHost()); CPPUNIT_ASSERT_EQUAL((uint16_t)8080, req.getPort()); CPPUNIT_ASSERT_EQUAL(std::string("/"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string("abc"), req.getFile()); CPPUNIT_ASSERT_EQUAL(std::string("?query"), req.getQuery()); } void RequestTest::testSetUri15() { Request req; // 2 slashes after host name and dir bool v = req.setUri("http://host//dir1/dir2//file"); CPPUNIT_ASSERT(v); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("host"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("/dir1/dir2"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string("file"), req.getFile()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery()); } void RequestTest::testSetUri16() { Request req; // 2 slashes before file bool v = req.setUri("http://host//file"); CPPUNIT_ASSERT(v); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("host"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("/"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string("file"), req.getFile()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery()); } void RequestTest::testSetUri17() { Request req; bool v = req.setUri("http://host:80/file