aria2/test/CookieParserTest.cc
Tatsuhiro Tsujikawa d5bb035642 2007-06-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* src/AbstractCommand.cc
	(execute): Changed log level of MSG_RESTARTING_DOWNLOAD and
	MSG_MAX_TRY from error to info.
	Added MSG_DOWNLOAD_ABORTED after MSG_MAX_TRY.

	* src/message.h
	(MSG_TORRENT_DOWNLOAD_ABORTED): New definition.
	(MSG_DOWNLOAD_ABORTED): Added %s.
	(MSG_RESTARTING_DOWNLOAD): Added %s.
	(MSG_DOWNLOAD_ALREADY_COMPLETED): Updated.
	
	* src/PeerAbstractCommand.cc
	(execute): MSG_DOWNLOAD_ABORTED -> MSG_TORRENT_DOWNLOAD_ABORTED
	
	* src/Request.h
	(cookieBox): Made ShardHandle.
	
	* src/RequestGroup.h, src/RequestGroup.cc
	(createNextCommandWithAdj): New function.
	* src/FileAllocationCommand.cc
	(executeInternal): Use createNextCommandWithAdj().
	* src/CheckIntegrityCommand.cc
	(executeInternal): Use createNextCommandWithAdj().

	Added --load-cookies command-option.
	* src/OptionHandlerFactory.cc
	(createOptionHandlers): Added PREF_LOAD_COOKIES.
	* src/CookieBox.h, src/CookieBox.cc: Rwritten using CookieParser.
	Now aria2 can handle cookie's expiration date.
	* src/Cookie.h (expires): Changed its type to time_t.
	* src/main.cc: Added --load-cookies command-line option.
	* src/prefs.h (PREF_LOAD_COOKIES): New definition.
	* src/Util.h, src/Util.cc (httpGMT): New function.
	* src/Request.cc (Request): Initialize cookieBox using
	CookieBoxFactory.
	* src/CookieBoxFactory.h, src/CookieBoxFactory.cc: New class.
	* src/CookieParser.h, src/CookieParser.cc: New class.
	
	* src/main.cc: Chagned the default value of --metalink-servers to 5.

	* src/HttpResponseCommand.cc
	(handleOtherEncoding): Call RequestGroup::shouldCancelDownloadForSafety
2007-06-10 07:55:43 +00:00

76 lines
2.0 KiB
C++

#include "CookieParser.h"
#include <fstream>
#include <cppunit/extensions/HelperMacros.h>
using namespace std;
class CookieParserTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(CookieParserTest);
CPPUNIT_TEST(testParse);
CPPUNIT_TEST(testParse_file);
CPPUNIT_TEST_SUITE_END();
private:
public:
void setUp() {
}
void testParse();
void testParse_file();
};
CPPUNIT_TEST_SUITE_REGISTRATION( CookieParserTest );
void CookieParserTest::testParse()
{
string str = "JSESSIONID=123456789; expires=Sun, 2007-06-10 11:00:00 GMT; path=/; domain=localhost; secure";
Cookie c = CookieParser().parse(str);
CPPUNIT_ASSERT(c.good());
CPPUNIT_ASSERT_EQUAL(string("JSESSIONID"), c.name);
CPPUNIT_ASSERT_EQUAL(string("123456789"), c.value);
CPPUNIT_ASSERT_EQUAL((time_t)1181473200, c.expires);
CPPUNIT_ASSERT_EQUAL(string("/"), c.path);
CPPUNIT_ASSERT_EQUAL(string("localhost"), c.domain);
CPPUNIT_ASSERT_EQUAL(true, c.secure);
CPPUNIT_ASSERT_EQUAL(false, c.onetime);
string str2 = "JSESSIONID=123456789";
c = CookieParser().parse(str2);
CPPUNIT_ASSERT(c.good());
CPPUNIT_ASSERT_EQUAL(string("JSESSIONID"), c.name);
CPPUNIT_ASSERT_EQUAL(string("123456789"), c.value);
CPPUNIT_ASSERT_EQUAL((time_t)0, c.expires);
CPPUNIT_ASSERT_EQUAL(string(""), c.path);
CPPUNIT_ASSERT_EQUAL(string(""), c.domain);
CPPUNIT_ASSERT_EQUAL(false, c.secure);
CPPUNIT_ASSERT_EQUAL(true, c.onetime);
string str3 = "";
c = CookieParser().parse(str3);
CPPUNIT_ASSERT(!c.good());
}
void CookieParserTest::testParse_file()
{
ifstream f("cookietest.txt");
Cookies cookies = CookieParser().parse(f);
CPPUNIT_ASSERT_EQUAL(3, (int32_t)cookies.size());
Cookie c = cookies[0];
CPPUNIT_ASSERT_EQUAL(string("JSESSIONID"), c.name);
CPPUNIT_ASSERT_EQUAL(string("123456789"), c.value);
c = cookies[1];
CPPUNIT_ASSERT_EQUAL(string("user"), c.name);
CPPUNIT_ASSERT_EQUAL(string("me"), c.value);
c = cookies[2];
CPPUNIT_ASSERT_EQUAL(string("passwd"), c.name);
CPPUNIT_ASSERT_EQUAL(string("secret"), c.value);
}