AbstractCommandTest.cc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "AbstractCommand.h"
  2. #include <iostream>
  3. #include <cppunit/extensions/HelperMacros.h>
  4. #include "Option.h"
  5. #include "prefs.h"
  6. #include "SocketCore.h"
  7. #include "SocketRecvBuffer.h"
  8. namespace aria2 {
  9. class AbstractCommandTest:public CppUnit::TestFixture {
  10. CPPUNIT_TEST_SUITE(AbstractCommandTest);
  11. CPPUNIT_TEST(testGetProxyUri);
  12. CPPUNIT_TEST_SUITE_END();
  13. public:
  14. void setUp() {}
  15. void tearDown() {}
  16. void testGetProxyUri();
  17. };
  18. CPPUNIT_TEST_SUITE_REGISTRATION(AbstractCommandTest);
  19. void AbstractCommandTest::testGetProxyUri()
  20. {
  21. Option op;
  22. CPPUNIT_ASSERT_EQUAL(std::string(), getProxyUri("http", &op));
  23. op.put(PREF_HTTP_PROXY, "http://hu:hp@httpproxy/");
  24. op.put(PREF_FTP_PROXY, "ftp://fu:fp@ftpproxy/");
  25. CPPUNIT_ASSERT_EQUAL(std::string("http://hu:hp@httpproxy/"),
  26. getProxyUri("http", &op));
  27. CPPUNIT_ASSERT_EQUAL(std::string("ftp://fu:fp@ftpproxy/"),
  28. getProxyUri("ftp", &op));
  29. op.put(PREF_ALL_PROXY, "http://au:ap@allproxy/");
  30. CPPUNIT_ASSERT_EQUAL(std::string("http://au:ap@allproxy/"),
  31. getProxyUri("https", &op));
  32. op.put(PREF_ALL_PROXY_USER, "aunew");
  33. op.put(PREF_ALL_PROXY_PASSWD, "apnew");
  34. CPPUNIT_ASSERT_EQUAL(std::string("http://aunew:apnew@allproxy/"),
  35. getProxyUri("https", &op));
  36. op.put(PREF_HTTPS_PROXY, "http://hsu:hsp@httpsproxy/");
  37. CPPUNIT_ASSERT_EQUAL(std::string("http://hsu:hsp@httpsproxy/"),
  38. getProxyUri("https", &op));
  39. CPPUNIT_ASSERT_EQUAL(std::string(), getProxyUri("unknown", &op));
  40. op.put(PREF_HTTP_PROXY_USER, "hunew");
  41. CPPUNIT_ASSERT_EQUAL(std::string("http://hunew:hp@httpproxy/"),
  42. getProxyUri("http", &op));
  43. op.put(PREF_HTTP_PROXY_PASSWD, "hpnew");
  44. CPPUNIT_ASSERT_EQUAL(std::string("http://hunew:hpnew@httpproxy/"),
  45. getProxyUri("http", &op));
  46. op.put(PREF_HTTP_PROXY_USER, "");
  47. CPPUNIT_ASSERT_EQUAL(std::string("http://httpproxy/"),
  48. getProxyUri("http", &op));
  49. }
  50. } // namespace aria2