2007-03-26 12:16:57 +00:00
|
|
|
#include "OptionHandlerImpl.h"
|
2009-02-07 11:00:34 +00:00
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2007-03-26 12:16:57 +00:00
|
|
|
#include "prefs.h"
|
|
|
|
#include "Exception.h"
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
|
|
|
|
2007-03-26 12:16:57 +00:00
|
|
|
class OptionHandlerTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(OptionHandlerTest);
|
|
|
|
CPPUNIT_TEST(testNullOptionHandler);
|
|
|
|
CPPUNIT_TEST(testBooleanOptionHandler);
|
|
|
|
CPPUNIT_TEST(testNumberOptionHandler);
|
|
|
|
CPPUNIT_TEST(testNumberOptionHandler_min);
|
|
|
|
CPPUNIT_TEST(testNumberOptionHandler_max);
|
|
|
|
CPPUNIT_TEST(testNumberOptionHandler_min_max);
|
|
|
|
CPPUNIT_TEST(testUnitNumberOptionHandler);
|
|
|
|
CPPUNIT_TEST(testParameterOptionHandler_1argInit);
|
|
|
|
CPPUNIT_TEST(testParameterOptionHandler_2argsInit);
|
|
|
|
CPPUNIT_TEST(testParameterOptionHandler_listInit);
|
|
|
|
CPPUNIT_TEST(testDefaultOptionHandler);
|
|
|
|
CPPUNIT_TEST(testFloatNumberOptionHandler);
|
|
|
|
CPPUNIT_TEST(testFloatNumberOptionHandler_min);
|
|
|
|
CPPUNIT_TEST(testFloatNumberOptionHandler_max);
|
|
|
|
CPPUNIT_TEST(testFloatNumberOptionHandler_min_max);
|
|
|
|
CPPUNIT_TEST(testHttpProxyOptionHandler);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void testNullOptionHandler();
|
|
|
|
void testBooleanOptionHandler();
|
|
|
|
void testNumberOptionHandler();
|
|
|
|
void testNumberOptionHandler_min();
|
|
|
|
void testNumberOptionHandler_max();
|
|
|
|
void testNumberOptionHandler_min_max();
|
|
|
|
void testUnitNumberOptionHandler();
|
|
|
|
void testParameterOptionHandler_1argInit();
|
|
|
|
void testParameterOptionHandler_2argsInit();
|
|
|
|
void testParameterOptionHandler_listInit();
|
|
|
|
void testDefaultOptionHandler();
|
|
|
|
void testFloatNumberOptionHandler();
|
|
|
|
void testFloatNumberOptionHandler_min();
|
|
|
|
void testFloatNumberOptionHandler_max();
|
|
|
|
void testFloatNumberOptionHandler_min_max();
|
|
|
|
void testHttpProxyOptionHandler();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( OptionHandlerTest );
|
|
|
|
|
|
|
|
void OptionHandlerTest::testNullOptionHandler()
|
|
|
|
{
|
|
|
|
NullOptionHandler handler;
|
|
|
|
CPPUNIT_ASSERT(handler.canHandle("foo"));
|
2009-02-07 11:00:34 +00:00
|
|
|
Option option;
|
|
|
|
handler.parse(option, "bar");
|
|
|
|
CPPUNIT_ASSERT(!option.defined("bar"));
|
2007-03-26 12:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OptionHandlerTest::testBooleanOptionHandler()
|
|
|
|
{
|
|
|
|
BooleanOptionHandler handler("foo");
|
|
|
|
CPPUNIT_ASSERT(handler.canHandle("foo"));
|
|
|
|
CPPUNIT_ASSERT(!handler.canHandle("foobar"));
|
|
|
|
Option option;
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, V_TRUE);
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(V_TRUE), option.get("foo"));
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, V_FALSE);
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(V_FALSE), option.get("foo"));
|
2007-03-26 12:16:57 +00:00
|
|
|
try {
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "hello");
|
2007-08-09 14:54:36 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2009-02-07 11:00:34 +00:00
|
|
|
} catch(Exception& e) {}
|
2008-09-22 09:26:57 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("true,false"),
|
2010-01-05 16:01:46 +00:00
|
|
|
handler.createPossibleValuesString());
|
2007-03-26 12:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OptionHandlerTest::testNumberOptionHandler()
|
|
|
|
{
|
|
|
|
NumberOptionHandler handler("foo");
|
|
|
|
CPPUNIT_ASSERT(handler.canHandle("foo"));
|
|
|
|
CPPUNIT_ASSERT(!handler.canHandle("foobar"));
|
|
|
|
Option option;
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "0");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("0"), option.get("foo"));
|
2008-09-22 09:26:57 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("*-*"),
|
2010-01-05 16:01:46 +00:00
|
|
|
handler.createPossibleValuesString());
|
2007-03-26 12:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OptionHandlerTest::testNumberOptionHandler_min()
|
|
|
|
{
|
2008-09-22 09:26:57 +00:00
|
|
|
NumberOptionHandler handler("foo", "", "", 1);
|
2007-03-26 12:16:57 +00:00
|
|
|
Option option;
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "1");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("1"), option.get("foo"));
|
2007-03-26 12:16:57 +00:00
|
|
|
try {
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "0");
|
2007-08-09 14:54:36 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2009-02-07 11:00:34 +00:00
|
|
|
} catch(Exception& e) {}
|
2008-09-22 09:26:57 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("1-*"),
|
2010-01-05 16:01:46 +00:00
|
|
|
handler.createPossibleValuesString());
|
2007-03-26 12:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OptionHandlerTest::testNumberOptionHandler_max()
|
|
|
|
{
|
2008-09-22 09:26:57 +00:00
|
|
|
NumberOptionHandler handler("foo", "", "", -1, 100);
|
2007-03-26 12:16:57 +00:00
|
|
|
Option option;
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "100");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("100"), option.get("foo"));
|
2007-03-26 12:16:57 +00:00
|
|
|
try {
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "101");
|
2007-08-09 14:54:36 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2009-02-07 11:00:34 +00:00
|
|
|
} catch(Exception& e) {}
|
2008-09-22 09:26:57 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("*-100"),
|
2010-01-05 16:01:46 +00:00
|
|
|
handler.createPossibleValuesString());
|
2007-03-26 12:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OptionHandlerTest::testNumberOptionHandler_min_max()
|
|
|
|
{
|
2008-09-22 09:26:57 +00:00
|
|
|
NumberOptionHandler handler("foo", "", "", 1, 100);
|
2007-03-26 12:16:57 +00:00
|
|
|
Option option;
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "1");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("1"), option.get("foo"));
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "100");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("100"), option.get("foo"));
|
2007-03-26 12:16:57 +00:00
|
|
|
try {
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "0");
|
2007-08-09 14:54:36 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2009-02-07 11:00:34 +00:00
|
|
|
} catch(Exception& e) {}
|
2007-03-26 12:16:57 +00:00
|
|
|
try {
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "101");
|
2007-08-09 14:54:36 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2009-02-07 11:00:34 +00:00
|
|
|
} catch(Exception& e) {}
|
2008-09-22 09:26:57 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("1-100"),
|
2010-01-05 16:01:46 +00:00
|
|
|
handler.createPossibleValuesString());
|
2007-03-26 12:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OptionHandlerTest::testUnitNumberOptionHandler()
|
|
|
|
{
|
|
|
|
UnitNumberOptionHandler handler("foo");
|
|
|
|
CPPUNIT_ASSERT(handler.canHandle("foo"));
|
|
|
|
CPPUNIT_ASSERT(!handler.canHandle("foobar"));
|
|
|
|
Option option;
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "4294967296");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("4294967296"), option.get("foo"));
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "4096M");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("4294967296"), option.get("foo"));
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "4096K");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("4194304"), option.get("foo"));
|
2007-11-22 11:17:35 +00:00
|
|
|
try {
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "K");
|
2007-11-22 11:17:35 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2009-02-07 11:00:34 +00:00
|
|
|
} catch(Exception& e) {}
|
2007-11-22 11:17:35 +00:00
|
|
|
try {
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "M");
|
|
|
|
} catch(Exception& e) {}
|
2007-11-22 11:17:35 +00:00
|
|
|
try {
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "");
|
2007-11-22 11:17:35 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2009-02-07 11:00:34 +00:00
|
|
|
} catch(Exception& e) {}
|
2007-03-26 12:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OptionHandlerTest::testParameterOptionHandler_1argInit()
|
|
|
|
{
|
2008-09-22 09:26:57 +00:00
|
|
|
ParameterOptionHandler handler("foo", "", "", "value1");
|
2007-03-26 12:16:57 +00:00
|
|
|
CPPUNIT_ASSERT(handler.canHandle("foo"));
|
|
|
|
CPPUNIT_ASSERT(!handler.canHandle("foobar"));
|
|
|
|
Option option;
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "value1");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("value1"), option.get("foo"));
|
2007-03-26 12:16:57 +00:00
|
|
|
try {
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "value3");
|
2007-08-09 14:54:36 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2009-02-07 11:00:34 +00:00
|
|
|
} catch(Exception& e) {}
|
2008-09-22 09:26:57 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("value1"),
|
2010-01-05 16:01:46 +00:00
|
|
|
handler.createPossibleValuesString());
|
2007-03-26 12:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OptionHandlerTest::testParameterOptionHandler_2argsInit()
|
|
|
|
{
|
2008-09-22 09:26:57 +00:00
|
|
|
ParameterOptionHandler handler("foo", "", "", "value1", "value2");
|
2007-03-26 12:16:57 +00:00
|
|
|
CPPUNIT_ASSERT(handler.canHandle("foo"));
|
|
|
|
CPPUNIT_ASSERT(!handler.canHandle("foobar"));
|
|
|
|
Option option;
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "value1");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("value1"), option.get("foo"));
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "value2");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("value2"), option.get("foo"));
|
2007-03-26 12:16:57 +00:00
|
|
|
try {
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "value3");
|
2007-08-09 14:54:36 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2009-02-07 11:00:34 +00:00
|
|
|
} catch(Exception& e) {}
|
2008-09-22 09:26:57 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("value1,value2"),
|
2010-01-05 16:01:46 +00:00
|
|
|
handler.createPossibleValuesString());
|
2007-03-26 12:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OptionHandlerTest::testParameterOptionHandler_listInit()
|
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<std::string> validValues;
|
2007-03-26 12:16:57 +00:00
|
|
|
validValues.push_back("value1");
|
|
|
|
validValues.push_back("value2");
|
|
|
|
|
2008-09-22 09:26:57 +00:00
|
|
|
ParameterOptionHandler handler("foo", "", "", validValues);
|
2007-03-26 12:16:57 +00:00
|
|
|
CPPUNIT_ASSERT(handler.canHandle("foo"));
|
|
|
|
CPPUNIT_ASSERT(!handler.canHandle("foobar"));
|
|
|
|
Option option;
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "value1");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("value1"), option.get("foo"));
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "value2");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("value2"), option.get("foo"));
|
2007-03-26 12:16:57 +00:00
|
|
|
try {
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "value3");
|
2007-08-09 14:54:36 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2009-02-07 11:00:34 +00:00
|
|
|
} catch(Exception& e) {}
|
2008-09-22 09:26:57 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("value1,value2"),
|
2010-01-05 16:01:46 +00:00
|
|
|
handler.createPossibleValuesString());
|
2007-03-26 12:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OptionHandlerTest::testDefaultOptionHandler()
|
|
|
|
{
|
|
|
|
DefaultOptionHandler handler("foo");
|
|
|
|
CPPUNIT_ASSERT(handler.canHandle("foo"));
|
|
|
|
CPPUNIT_ASSERT(!handler.canHandle("foobar"));
|
|
|
|
Option option;
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "bar");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("bar"), option.get("foo"));
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), option.get("foo"));
|
2008-09-22 09:26:57 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), handler.createPossibleValuesString());
|
|
|
|
|
|
|
|
handler.addTag("apple");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("apple"), handler.toTagString());
|
|
|
|
handler.addTag("orange");
|
2010-01-17 13:58:42 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("apple, orange"), handler.toTagString());
|
2008-09-22 09:26:57 +00:00
|
|
|
CPPUNIT_ASSERT(handler.hasTag("apple"));
|
|
|
|
CPPUNIT_ASSERT(handler.hasTag("orange"));
|
|
|
|
CPPUNIT_ASSERT(!handler.hasTag("pineapple"));
|
2007-03-26 12:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OptionHandlerTest::testFloatNumberOptionHandler()
|
|
|
|
{
|
|
|
|
FloatNumberOptionHandler handler("foo");
|
|
|
|
CPPUNIT_ASSERT(handler.canHandle("foo"));
|
|
|
|
CPPUNIT_ASSERT(!handler.canHandle("foobar"));
|
|
|
|
Option option;
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "1.0");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("1.0"), option.get("foo"));
|
2008-09-22 09:26:57 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("*-*"),
|
2010-01-05 16:01:46 +00:00
|
|
|
handler.createPossibleValuesString());
|
2007-03-26 12:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OptionHandlerTest::testFloatNumberOptionHandler_min()
|
|
|
|
{
|
2008-09-22 09:26:57 +00:00
|
|
|
FloatNumberOptionHandler handler("foo", "", "", 0.0);
|
2007-03-26 12:16:57 +00:00
|
|
|
Option option;
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "0.0");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("0.0"), option.get("foo"));
|
2007-03-26 12:16:57 +00:00
|
|
|
try {
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "-0.1");
|
2007-08-09 14:54:36 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2009-02-07 11:00:34 +00:00
|
|
|
} catch(Exception& e) {}
|
2008-09-22 09:26:57 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("0.0-*"),
|
2010-01-05 16:01:46 +00:00
|
|
|
handler.createPossibleValuesString());
|
2007-03-26 12:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OptionHandlerTest::testFloatNumberOptionHandler_max()
|
|
|
|
{
|
2008-09-22 09:26:57 +00:00
|
|
|
FloatNumberOptionHandler handler("foo", "", "", -1, 10.0);
|
2007-03-26 12:16:57 +00:00
|
|
|
Option option;
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "10.0");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("10.0"), option.get("foo"));
|
2007-03-26 12:16:57 +00:00
|
|
|
try {
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "10.1");
|
2007-08-09 14:54:36 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2009-02-07 11:00:34 +00:00
|
|
|
} catch(Exception& e) {}
|
2008-09-22 09:26:57 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("*-10.0"),
|
2010-01-05 16:01:46 +00:00
|
|
|
handler.createPossibleValuesString());
|
2007-03-26 12:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OptionHandlerTest::testFloatNumberOptionHandler_min_max()
|
|
|
|
{
|
2008-09-22 09:26:57 +00:00
|
|
|
FloatNumberOptionHandler handler("foo", "", "", 0.0, 10.0);
|
2007-03-26 12:16:57 +00:00
|
|
|
Option option;
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "0.0");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("0.0"), option.get("foo"));
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "10.0");
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("10.0"), option.get("foo"));
|
2007-03-26 12:16:57 +00:00
|
|
|
try {
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "-0.1");
|
2007-08-09 14:54:36 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2009-02-07 11:00:34 +00:00
|
|
|
} catch(Exception& e) {}
|
2007-03-26 12:16:57 +00:00
|
|
|
try {
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "10.1");
|
2007-08-09 14:54:36 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2009-02-07 11:00:34 +00:00
|
|
|
} catch(Exception& e) {}
|
2008-09-22 09:26:57 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("0.0-10.0"),
|
2010-01-05 16:01:46 +00:00
|
|
|
handler.createPossibleValuesString());
|
2007-03-26 12:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OptionHandlerTest::testHttpProxyOptionHandler()
|
|
|
|
{
|
2008-11-04 14:08:26 +00:00
|
|
|
HttpProxyOptionHandler handler(PREF_HTTP_PROXY, "", "");
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
CPPUNIT_ASSERT(handler.canHandle(PREF_HTTP_PROXY));
|
2007-03-26 12:16:57 +00:00
|
|
|
CPPUNIT_ASSERT(!handler.canHandle("foobar"));
|
|
|
|
Option option;
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "proxy:65535");
|
2008-11-04 14:08:26 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("http://proxy:65535"),
|
2010-01-05 16:01:46 +00:00
|
|
|
option.get(PREF_HTTP_PROXY));
|
2008-11-04 14:08:26 +00:00
|
|
|
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "http://proxy:8080");
|
2008-11-04 14:08:26 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("http://proxy:8080"),
|
2010-01-05 16:01:46 +00:00
|
|
|
option.get(PREF_HTTP_PROXY));
|
2007-03-26 12:16:57 +00:00
|
|
|
|
2010-01-15 09:04:47 +00:00
|
|
|
handler.parse(option, "");
|
|
|
|
CPPUNIT_ASSERT(option.defined(PREF_HTTP_PROXY));
|
|
|
|
CPPUNIT_ASSERT(option.blank(PREF_HTTP_PROXY));
|
|
|
|
|
2007-03-26 12:16:57 +00:00
|
|
|
try {
|
2009-02-07 11:00:34 +00:00
|
|
|
handler.parse(option, "http://bar:65536");
|
2007-08-09 14:54:36 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2009-02-07 11:00:34 +00:00
|
|
|
} catch(Exception& e) {}
|
2008-11-04 14:08:26 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("[http://][USER:PASSWORD@]HOST[:PORT]"),
|
2010-01-05 16:01:46 +00:00
|
|
|
handler.createPossibleValuesString());
|
2007-03-26 12:16:57 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|