aria2/test/CookieBoxTest.cc
Tatsuhiro Tsujikawa 9a52be6a29 2006-04-06 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To print ETA:

	* src/TorrentDownloadEngine.cc (afterEachIteration): Added 
download
	completion handling when dealing with
	TorrentMan::isPartialDownloadingMode() == true.
	* src/TorrentDownloadEngine.h (onPartialDownloadingCompletes):
	New function.
	* src/TorrentConsoleDownloadEngine.h (startup): New variable.
	(sessionDownloadLength): New variable.
	(avgSpeed): New variable.
	(eta): New variable.
	* src/TorrentConsoleDownloadEngine.cc (initStatistics): 
Initialized
	new variables: eta, avgSpeed, startup.
	(calculateSpeed): Calculate average speed and ETA.
	(printStatistics): Added ETA.

	* src/Util.h (secfmt): New function.
	* src/Util.cc (secfmt): New function.
	
2006-04-05  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>

	To detect "keep alive" flooding:

	* src/PeerInteractionCommand.h (keepAliveCount): New variable
	* src/PeerInteractionCommand.cc (Constructor): Initialized new
	variable: keepAliveCount.
	(detectMessageFlooding): Added "keep alive" flooding detection.
	(receiveMessage): Increase keepAliveCount when "keep alive" 
message
	received.
	
	To add the ability to download only specified files in 
multi-file
	torrent:

	* src/BitfieldMan.h (filterBitfield): New variable.
	(filterEnabled): New variable.
	(setFilterBit): New function.
	(enableFilter): New function.
	(disableFilter): New function.
	(isFilterEnabled): New function.
	(getFilteredTotalLength): New function.
	(getCompletedLength): New function.
	* src/BitfieldMan.cc (Constructor): Initialized new variable:
	filterBitfield, filterEnabled.
	(CopyConstructor): Added filterBitfield and filterEnabled.
	(operator==): Added filterBitfield and filterEnabled.
	(Destructor): Added filterBitfield.
	(getMissingIndex): Use filterBitfield.
	(getMissingUnusedIndex): Use filterBitfield.
	(getFirstMissingUnusedIndex): Use filterBitfield.
	(getFirstMissingUnusedIndex): Use filterBitfield.
	(getAllMissingIndexes): Use filterBitfield.
	(countMissingBlock): Use filterBitfield.
	(countBlock): Use filterBitfield.
	(setBitInternal): Added new argument on.
	(setUseBit): Use setBitInternal.
	(unsetUseBit): Use setBitInternal.
	(setBit): Use setBitInternal.
	(unsetBit): Use setBitInternal.
	(isAllBitSet): Use filterBitfield.
	(setFilterBit): New function.
	(addFilter): New function.
	(enableFilter): New function.
	(disableFilter): New function.
	(clearFilter): New function.
	(isFilterEnabled): New function.
	(getFilteredTotalLength): New function.
	(getCompletedLength): New function.

	* src/TorrentMan.h [FileEntry](Constructor): Updated signature.
	Initalized newly added variables.
	[FileEntry](offset): New variable.
	[FileEntry](extracted): New variable.
	[FileEntry](requested): New variable.
	(readFileEntry): New function.
	(option): New variable.
	(splitMultiFile): Removed const qualifier.
	(fixFilename): Removed const qualifier.
	(readFileEntryFromMetaInfoFile): New function.
	(finishPartialDownloadingMode): New function.
	(isPartialDownloadingMode): New function.
	(setFileEntriesToDownload): New function.
	(getCompletedLength): New function.
	(getPartialTotalLength): New function.
	* src/TorrentMan.cc (readFileEntry): New function.
	(setup): Use readFileEntry. If no-preallocation option is 
specified,
	use DefaultDiskWriter.
	(readFileEntryFromMetaInfoFile): New function.
	(fixFilename): Removed const qualifier.
	(splitMultiFile): Removed const qualifier.
	(setFileEntriesToDownload): New function.
	(isPartialDownloadingMode): New function.
	(finishPartialDownloadingMode): New function.
	(getCompletedLength): New function.
	(getPartialTotalLength): New function.
	
	* src/TorrentConsoleDownloadEngine.h 
(partialDownloadLengthDiff):
	New variable.
	(partialTotalLength): New variable.
	(downloadLength): New variable.
	(totalLength): New variable.
	* src/TorrentConsoleDownloadEngine.cc 
(onPartialDownloadingCompletes):
	Added log.
	(initStatistics): Initialized new variables: 
partialDownloadLengthDiff,
	partialTotalLength, downloadLength, totalLength.
	(calculate): Calculate downloadLength and totalLength.
	
	* src/prefs.h :New definition PREF_NO_PREALLOCATION

	* src/main.cc (addCommand): Changed argument signature.
	(main): Added new variable: args. Added new option 
"torrent-show-files"
	"no-preallocation". Usage is not updated yet.
	
2006-04-02  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>

	* src/PeerMessage.cc (setBitfield): Fixed invalid memory 
de-allocation.
2006-04-06 12:52:16 +00:00

91 lines
2.6 KiB
C++

#include "CookieBox.h"
#include <string>
#include <cppunit/extensions/HelperMacros.h>
using namespace std;
class CookieBoxTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(CookieBoxTest);
CPPUNIT_TEST(testParse);
CPPUNIT_TEST(testCriteriaFind);
CPPUNIT_TEST_SUITE_END();
private:
public:
void setUp() {
}
void testParse();
void testCriteriaFind();
};
CPPUNIT_TEST_SUITE_REGISTRATION( CookieBoxTest );
void CookieBoxTest::testParse() {
CookieBox box;
string str = "JSESSIONID=123456789; expires=Sat, 16-02-2006 19:38:00 JST; path=/; domain=localhost; secure";
Cookie c;
box.parse(c, str);
CPPUNIT_ASSERT_EQUAL(string("JSESSIONID"), c.name);
CPPUNIT_ASSERT_EQUAL(string("123456789"), c.value);
CPPUNIT_ASSERT_EQUAL(string("Sat, 16-02-2006 19:38:00 JST"), c.expires);
CPPUNIT_ASSERT_EQUAL(string("/"), c.path);
CPPUNIT_ASSERT_EQUAL(string("localhost"), c.domain);
CPPUNIT_ASSERT_EQUAL(true, c.secure);
string str2 = "JSESSIONID=123456789";
box.parse(c, str2);
CPPUNIT_ASSERT_EQUAL(string("JSESSIONID"), c.name);
CPPUNIT_ASSERT_EQUAL(string("123456789"), c.value);
CPPUNIT_ASSERT_EQUAL(string(""), c.expires);
CPPUNIT_ASSERT_EQUAL(string(""), c.path);
CPPUNIT_ASSERT_EQUAL(string(""), c.domain);
CPPUNIT_ASSERT_EQUAL(false, c.secure);
}
void CookieBoxTest::testCriteriaFind() {
Cookie c1("SESSIONID1", "1", "", "/downloads", "rednoah.com", false);
Cookie c2("SESSIONID2", "2", "", "/downloads", "rednoah.com", false);
Cookie c3("USER", "user", "", "/home", "aria.rednoah.com", false);
Cookie c4("PASS", "pass", "", "/downloads", "rednoah.com", true);
CookieBox box;
box.add(c1);
box.add(c2);
box.add(c3);
box.add(c4);
Cookies result1 = box.criteriaFind("rednoah.com", "/downloads", false);
CPPUNIT_ASSERT_EQUAL(2, (int)result1.size());
Cookies::iterator itr = result1.begin();
CPPUNIT_ASSERT_EQUAL(string("SESSIONID1=1"), (*itr).toString());
itr++;
CPPUNIT_ASSERT_EQUAL(string("SESSIONID2=2"), (*itr).toString());
result1 = box.criteriaFind("rednoah.com", "/downloads", true);
CPPUNIT_ASSERT_EQUAL(3, (int)result1.size());
itr = result1.begin();
CPPUNIT_ASSERT_EQUAL(string("SESSIONID1=1"), (*itr).toString());
itr++;
CPPUNIT_ASSERT_EQUAL(string("SESSIONID2=2"), (*itr).toString());
itr++;
CPPUNIT_ASSERT_EQUAL(string("PASS=pass"), (*itr).toString());
result1 = box.criteriaFind("aria.rednoah.com", "/", false);
CPPUNIT_ASSERT_EQUAL(0, (int)result1.size());
result1 = box.criteriaFind("aria.rednoah.com", "/home", false);
CPPUNIT_ASSERT_EQUAL(1, (int)result1.size());
itr = result1.begin();
CPPUNIT_ASSERT_EQUAL(string("USER=user"), (*itr).toString());
}