2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2008-11-27 15:29:15 +00:00
|
|
|
|
2009-10-22 14:43:42 +00:00
|
|
|
#include <cstring>
|
2008-11-27 15:29:15 +00:00
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2007-11-04 12:26:12 +00:00
|
|
|
#include "FixedNumberRandomizer.h"
|
2007-11-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Don't connect server before checking file integrity at startup,
if
filesize and output file path are known.
* src/AbstractCommand.cc
* src/StreamFileAllocationEntry.cc
* src/Metalink2RequestGroup.cc
* src/RequestGroup.{h, cc}
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
Added DownloadFailureException. If it is thrown, RequestGroup
should
halt.
* src/AbstractCommand.cc
* src/DownloadFailureException.h
* src/RequestGroup.cc
Catch RecoverableException, instead of DlAbortEx.
* src/RequestGroupMan.cc
* src/FillRequestGroupCommand.cc
* src/MetaFileUtil.cc
* src/IteratableChunkChecksumValidator.cc
Now first parameter of MSG_DOWNLOAD_ABORTED is
gid(RequestGroup::
getGID())
* src/CheckIntegrityCommand.cc
* src/message.h
Print gid instead of idx.
* src/RequestGroupMan.cc
Removed exception throwers declaration.
* src/DirectDiskAdaptor.{h, cc}
* src/SocketCore.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpConnection.{h, cc}
* src/HttpResponse.{h, cc}
* src/DiskAdaptor.{h, cc}
* src/CopyDiskAdaptor.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpHeaderProcessor.{h, cc}
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/Util.{h, cc}
* test/UtilTest.cc
* src/DefaultDiskWriter.{h, cc}
* src/FtpConnection.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Removed duplicate code.
* src/StreamCheckIntegrityEntry.cc
Removed unnecessary include.
* src/DiskWriter.h
Included Exception.h
* src/option_processing.cc
Included 2 files and added doc
* src/TrackerWatcherCommand.cc
* src/SocketCore.cc (writeData): Fixed send error with GnuTLS.
2007-11-09 18:01:12 +00:00
|
|
|
#include "DlAbortEx.h"
|
2007-11-13 10:10:11 +00:00
|
|
|
#include "BitfieldMan.h"
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
#include "ByteArrayDiskWriter.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "FileEntry.h"
|
|
|
|
#include "File.h"
|
2009-03-04 15:53:56 +00:00
|
|
|
#include "array_fun.h"
|
2011-08-09 14:33:55 +00:00
|
|
|
#include "BufferedFile.h"
|
|
|
|
#include "TestUtil.h"
|
2011-10-19 14:14:13 +00:00
|
|
|
#include "SocketCore.h"
|
2006-02-17 13:35:04 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2006-02-17 13:35:04 +00:00
|
|
|
|
|
|
|
class UtilTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(UtilTest);
|
2010-10-09 16:22:56 +00:00
|
|
|
CPPUNIT_TEST(testStrip);
|
2011-11-03 09:51:31 +00:00
|
|
|
CPPUNIT_TEST(testStripIter);
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_TEST(testLstripIter);
|
|
|
|
CPPUNIT_TEST(testLstripIter_char);
|
2010-10-10 03:39:00 +00:00
|
|
|
CPPUNIT_TEST(testDivide);
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_TEST(testSplit);
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_TEST(testSplitIter);
|
|
|
|
CPPUNIT_TEST(testSplitIterM);
|
|
|
|
CPPUNIT_TEST(testStreq);
|
|
|
|
CPPUNIT_TEST(testStrieq);
|
2011-11-11 13:50:18 +00:00
|
|
|
CPPUNIT_TEST(testStrifind);
|
2006-02-21 12:27:17 +00:00
|
|
|
CPPUNIT_TEST(testEndsWith);
|
2011-11-04 15:25:24 +00:00
|
|
|
CPPUNIT_TEST(testIendsWith);
|
2006-02-21 15:01:05 +00:00
|
|
|
CPPUNIT_TEST(testReplace);
|
2006-02-28 02:25:45 +00:00
|
|
|
CPPUNIT_TEST(testStartsWith);
|
2011-11-04 15:33:35 +00:00
|
|
|
CPPUNIT_TEST(testIstartsWith);
|
2006-05-09 15:54:14 +00:00
|
|
|
// may be moved to other helper class in the future.
|
|
|
|
CPPUNIT_TEST(testGetContentDispositionFilename);
|
2012-10-27 02:41:56 +00:00
|
|
|
CPPUNIT_TEST(testParseContentDisposition);
|
2006-07-03 14:19:23 +00:00
|
|
|
CPPUNIT_TEST(testToUpper);
|
|
|
|
CPPUNIT_TEST(testToLower);
|
2010-10-10 02:51:38 +00:00
|
|
|
CPPUNIT_TEST(testUppercase);
|
|
|
|
CPPUNIT_TEST(testLowercase);
|
2010-03-07 14:29:40 +00:00
|
|
|
CPPUNIT_TEST(testPercentDecode);
|
2007-03-26 12:16:57 +00:00
|
|
|
CPPUNIT_TEST(testGetRealSize);
|
2007-06-05 11:37:25 +00:00
|
|
|
CPPUNIT_TEST(testAbbrevSize);
|
2007-07-01 10:40:30 +00:00
|
|
|
CPPUNIT_TEST(testToStream);
|
2007-08-28 11:51:20 +00:00
|
|
|
CPPUNIT_TEST(testIsNumber);
|
|
|
|
CPPUNIT_TEST(testIsLowercase);
|
|
|
|
CPPUNIT_TEST(testIsUppercase);
|
2007-11-05 15:13:55 +00:00
|
|
|
CPPUNIT_TEST(testMkdirs);
|
2007-11-13 10:10:11 +00:00
|
|
|
CPPUNIT_TEST(testConvertBitfield);
|
2011-10-29 14:33:48 +00:00
|
|
|
CPPUNIT_TEST(testParseIntSegments);
|
|
|
|
CPPUNIT_TEST(testParseIntSegments_invalidRange);
|
2010-11-15 12:52:03 +00:00
|
|
|
CPPUNIT_TEST(testParseIntNoThrow);
|
2010-10-09 16:58:58 +00:00
|
|
|
CPPUNIT_TEST(testParseUIntNoThrow);
|
|
|
|
CPPUNIT_TEST(testParseLLIntNoThrow);
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
CPPUNIT_TEST(testToString_binaryStream);
|
2008-02-24 09:43:31 +00:00
|
|
|
CPPUNIT_TEST(testItos);
|
|
|
|
CPPUNIT_TEST(testUitos);
|
2008-08-24 07:55:34 +00:00
|
|
|
CPPUNIT_TEST(testNtoh64);
|
2010-03-07 14:24:21 +00:00
|
|
|
CPPUNIT_TEST(testPercentEncode);
|
2009-01-25 09:58:40 +00:00
|
|
|
CPPUNIT_TEST(testHtmlEscape);
|
2009-03-04 15:53:56 +00:00
|
|
|
CPPUNIT_TEST(testJoinPath);
|
2009-03-07 03:10:53 +00:00
|
|
|
CPPUNIT_TEST(testParseIndexPath);
|
2011-11-01 15:18:39 +00:00
|
|
|
CPPUNIT_TEST(testCreateIndexPaths);
|
2009-10-22 14:43:42 +00:00
|
|
|
CPPUNIT_TEST(testGenerateRandomData);
|
2009-11-22 14:30:51 +00:00
|
|
|
CPPUNIT_TEST(testFromHex);
|
2009-11-29 06:43:38 +00:00
|
|
|
CPPUNIT_TEST(testParsePrioritizePieceRange);
|
2010-01-11 14:01:20 +00:00
|
|
|
CPPUNIT_TEST(testApplyDir);
|
2010-01-11 14:32:20 +00:00
|
|
|
CPPUNIT_TEST(testFixTaintedBasename);
|
2010-01-28 14:25:16 +00:00
|
|
|
CPPUNIT_TEST(testIsNumericHost);
|
2010-02-25 14:40:18 +00:00
|
|
|
CPPUNIT_TEST(testDetectDirTraversal);
|
2010-02-27 10:06:40 +00:00
|
|
|
CPPUNIT_TEST(testEscapePath);
|
2010-03-19 08:56:17 +00:00
|
|
|
CPPUNIT_TEST(testInSameCidrBlock);
|
2010-10-02 07:54:43 +00:00
|
|
|
CPPUNIT_TEST(testIsUtf8String);
|
2011-07-26 14:41:21 +00:00
|
|
|
CPPUNIT_TEST(testNextParam);
|
2011-10-28 15:16:46 +00:00
|
|
|
CPPUNIT_TEST(testNoProxyDomainMatch);
|
2011-11-12 12:27:24 +00:00
|
|
|
CPPUNIT_TEST(testInPrivateAddress);
|
2011-11-13 11:59:15 +00:00
|
|
|
CPPUNIT_TEST(testSecfmt);
|
2012-03-28 14:28:22 +00:00
|
|
|
CPPUNIT_TEST(testTlsHostnameMatch);
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp() {
|
|
|
|
}
|
|
|
|
|
2010-10-09 16:22:56 +00:00
|
|
|
void testStrip();
|
2011-11-03 09:51:31 +00:00
|
|
|
void testStripIter();
|
2011-11-04 13:27:58 +00:00
|
|
|
void testLstripIter();
|
|
|
|
void testLstripIter_char();
|
2010-10-10 03:39:00 +00:00
|
|
|
void testDivide();
|
2006-02-17 13:35:04 +00:00
|
|
|
void testSplit();
|
2011-11-04 13:27:58 +00:00
|
|
|
void testSplitIter();
|
|
|
|
void testSplitIterM();
|
|
|
|
void testStreq();
|
|
|
|
void testStrieq();
|
2011-11-11 13:50:18 +00:00
|
|
|
void testStrifind();
|
2006-02-21 12:27:17 +00:00
|
|
|
void testEndsWith();
|
2011-11-04 15:25:24 +00:00
|
|
|
void testIendsWith();
|
2006-02-21 15:01:05 +00:00
|
|
|
void testReplace();
|
2006-02-28 02:25:45 +00:00
|
|
|
void testStartsWith();
|
2011-11-04 15:33:35 +00:00
|
|
|
void testIstartsWith();
|
2006-05-09 15:54:14 +00:00
|
|
|
// may be moved to other helper class in the future.
|
|
|
|
void testGetContentDispositionFilename();
|
2012-10-27 02:41:56 +00:00
|
|
|
void testParseContentDisposition();
|
2006-07-03 14:19:23 +00:00
|
|
|
void testToUpper();
|
|
|
|
void testToLower();
|
2010-10-10 02:51:38 +00:00
|
|
|
void testUppercase();
|
|
|
|
void testLowercase();
|
2010-03-07 14:29:40 +00:00
|
|
|
void testPercentDecode();
|
2007-03-26 12:16:57 +00:00
|
|
|
void testGetRealSize();
|
2007-06-05 11:37:25 +00:00
|
|
|
void testAbbrevSize();
|
2007-07-01 10:40:30 +00:00
|
|
|
void testToStream();
|
2007-08-28 11:51:20 +00:00
|
|
|
void testIsNumber();
|
|
|
|
void testIsLowercase();
|
|
|
|
void testIsUppercase();
|
2007-11-05 15:13:55 +00:00
|
|
|
void testMkdirs();
|
2007-11-13 10:10:11 +00:00
|
|
|
void testConvertBitfield();
|
2011-10-29 14:33:48 +00:00
|
|
|
void testParseIntSegments();
|
|
|
|
void testParseIntSegments_invalidRange();
|
2010-11-15 12:52:03 +00:00
|
|
|
void testParseIntNoThrow();
|
2010-10-09 16:58:58 +00:00
|
|
|
void testParseUIntNoThrow();
|
|
|
|
void testParseLLIntNoThrow();
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
void testToString_binaryStream();
|
2008-02-24 09:43:31 +00:00
|
|
|
void testItos();
|
|
|
|
void testUitos();
|
2008-08-24 07:55:34 +00:00
|
|
|
void testNtoh64();
|
2010-03-07 14:24:21 +00:00
|
|
|
void testPercentEncode();
|
2009-01-25 09:58:40 +00:00
|
|
|
void testHtmlEscape();
|
2009-03-04 15:53:56 +00:00
|
|
|
void testJoinPath();
|
2009-03-07 03:10:53 +00:00
|
|
|
void testParseIndexPath();
|
2011-11-01 15:18:39 +00:00
|
|
|
void testCreateIndexPaths();
|
2009-10-22 14:43:42 +00:00
|
|
|
void testGenerateRandomData();
|
2009-11-22 14:30:51 +00:00
|
|
|
void testFromHex();
|
2009-11-29 06:43:38 +00:00
|
|
|
void testParsePrioritizePieceRange();
|
2010-01-11 14:01:20 +00:00
|
|
|
void testApplyDir();
|
2010-01-11 14:32:20 +00:00
|
|
|
void testFixTaintedBasename();
|
2010-01-28 14:25:16 +00:00
|
|
|
void testIsNumericHost();
|
2010-02-25 14:40:18 +00:00
|
|
|
void testDetectDirTraversal();
|
2010-02-27 10:06:40 +00:00
|
|
|
void testEscapePath();
|
2010-03-19 08:56:17 +00:00
|
|
|
void testInSameCidrBlock();
|
2010-10-02 07:54:43 +00:00
|
|
|
void testIsUtf8String();
|
2011-07-26 14:41:21 +00:00
|
|
|
void testNextParam();
|
2011-10-28 15:16:46 +00:00
|
|
|
void testNoProxyDomainMatch();
|
2011-11-12 12:27:24 +00:00
|
|
|
void testInPrivateAddress();
|
2011-11-13 11:59:15 +00:00
|
|
|
void testSecfmt();
|
2012-03-28 14:28:22 +00:00
|
|
|
void testTlsHostnameMatch();
|
2006-02-17 13:35:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( UtilTest );
|
|
|
|
|
2010-10-09 16:22:56 +00:00
|
|
|
void UtilTest::testStrip()
|
|
|
|
{
|
|
|
|
std::string str1 = "aria2";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str1, util::strip("aria2"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str1, util::strip(" aria2"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str1, util::strip("aria2 "));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str1, util::strip(" aria2 "));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str1, util::strip(" aria2 "));
|
|
|
|
std::string str2 = "aria2 debut";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str2, util::strip("aria2 debut"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str2, util::strip(" aria2 debut "));
|
|
|
|
std::string str3 = "";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str3, util::strip(""));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str3, util::strip(" "));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str3, util::strip(" "));
|
|
|
|
std::string str4 = "A";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str4, util::strip("A"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str4, util::strip(" A "));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str4, util::strip(" A "));
|
|
|
|
}
|
|
|
|
|
2011-11-03 09:51:31 +00:00
|
|
|
void UtilTest::testStripIter()
|
|
|
|
{
|
|
|
|
Scip p;
|
|
|
|
std::string str1 = "aria2";
|
|
|
|
std::string s = "aria2";
|
|
|
|
p = util::stripIter(s.begin(), s.end());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str1, std::string(p.first, p.second));
|
|
|
|
s = " aria2";
|
|
|
|
p = util::stripIter(s.begin(), s.end());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str1, std::string(p.first, p.second));
|
|
|
|
s = "aria2 ";
|
|
|
|
p = util::stripIter(s.begin(), s.end());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str1, std::string(p.first, p.second));
|
|
|
|
s = " aria2 ";
|
|
|
|
p = util::stripIter(s.begin(), s.end());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str1, std::string(p.first, p.second));
|
|
|
|
s = " aria2 ";
|
|
|
|
p = util::stripIter(s.begin(), s.end());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str1, std::string(p.first, p.second));
|
|
|
|
std::string str2 = "aria2 debut";
|
|
|
|
s = "aria2 debut";
|
|
|
|
p = util::stripIter(s.begin(), s.end());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str2, std::string(p.first, p.second));
|
|
|
|
s = " aria2 debut ";
|
|
|
|
p = util::stripIter(s.begin(), s.end());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str2, std::string(p.first, p.second));
|
|
|
|
std::string str3 = "";
|
|
|
|
s = "";
|
|
|
|
p = util::stripIter(s.begin(), s.end());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str3, std::string(p.first, p.second));
|
|
|
|
s = " ";
|
|
|
|
p = util::stripIter(s.begin(), s.end());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str3, std::string(p.first, p.second));
|
|
|
|
s = " ";
|
|
|
|
p = util::stripIter(s.begin(), s.end());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str3, std::string(p.first, p.second));
|
|
|
|
std::string str4 = "A";
|
|
|
|
s = "A";
|
|
|
|
p = util::stripIter(s.begin(), s.end());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str4, std::string(p.first, p.second));
|
|
|
|
s = " A ";
|
|
|
|
p = util::stripIter(s.begin(), s.end());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str4, std::string(p.first, p.second));
|
|
|
|
s = " A ";
|
|
|
|
p = util::stripIter(s.begin(), s.end());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str4, std::string(p.first, p.second));
|
|
|
|
}
|
|
|
|
|
2011-11-04 13:27:58 +00:00
|
|
|
void UtilTest::testLstripIter()
|
|
|
|
{
|
|
|
|
std::string::iterator r;
|
|
|
|
std::string s = "foo";
|
|
|
|
r = util::lstripIter(s.begin(), s.end());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo"), std::string(r, s.end()));
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2011-11-04 13:27:58 +00:00
|
|
|
s = " foo bar ";
|
|
|
|
r = util::lstripIter(s.begin(), s.end());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo bar "), std::string(r, s.end()));
|
|
|
|
|
|
|
|
s = "f";
|
|
|
|
r = util::lstripIter(s.begin(), s.end());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("f"), std::string(r, s.end()));
|
|
|
|
|
|
|
|
s = "foo ";
|
|
|
|
r = util::lstripIter(s.begin(), s.end());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo "), std::string(r, s.end()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UtilTest::testLstripIter_char()
|
|
|
|
{
|
|
|
|
std::string::iterator r;
|
|
|
|
std::string s = "foo";
|
|
|
|
r = util::lstripIter(s.begin(), s.end(), '$');
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo"), std::string(r, s.end()));
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2011-11-04 13:27:58 +00:00
|
|
|
s = "$$foo$bar$$";
|
|
|
|
r = util::lstripIter(s.begin(), s.end(), '$');
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo$bar$$"), std::string(r, s.end()));
|
|
|
|
|
|
|
|
s = "f";
|
|
|
|
r = util::lstripIter(s.begin(), s.end(), '$');
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("f"), std::string(r, s.end()));
|
|
|
|
|
|
|
|
s = "foo$$";
|
|
|
|
r = util::lstripIter(s.begin(), s.end(), '$');
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo$$"), std::string(r, s.end()));
|
|
|
|
}
|
|
|
|
|
2010-10-10 03:39:00 +00:00
|
|
|
void UtilTest::testDivide() {
|
2011-11-05 03:01:57 +00:00
|
|
|
std::pair<Sip, Sip> p1;
|
2011-11-03 14:09:03 +00:00
|
|
|
std::string s = "name=value";
|
|
|
|
util::divide(p1, s.begin(), s.end(), '=');
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("name"),
|
|
|
|
std::string(p1.first.first, p1.first.second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("value"),
|
|
|
|
std::string(p1.second.first, p1.second.second));
|
|
|
|
s = " name = value ";
|
|
|
|
util::divide(p1, s.begin(), s.end(), '=');
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("name"),
|
|
|
|
std::string(p1.first.first, p1.first.second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("value"),
|
|
|
|
std::string(p1.second.first, p1.second.second));
|
|
|
|
s = "=value";
|
|
|
|
util::divide(p1, s.begin(), s.end(), '=');
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""),
|
|
|
|
std::string(p1.first.first, p1.first.second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("value"),
|
|
|
|
std::string(p1.second.first, p1.second.second));
|
|
|
|
s = "name=";
|
|
|
|
util::divide(p1, s.begin(), s.end(), '=');
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("name"),
|
|
|
|
std::string(p1.first.first, p1.first.second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""),
|
|
|
|
std::string(p1.second.first, p1.second.second));
|
|
|
|
s = "name";
|
|
|
|
util::divide(p1, s.begin(), s.end(), '=');
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("name"),
|
|
|
|
std::string(p1.first.first, p1.first.second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""),
|
|
|
|
std::string(p1.second.first, p1.second.second));
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
|
|
|
|
2010-10-10 03:39:00 +00:00
|
|
|
void UtilTest::testSplit() {
|
2010-10-10 06:58:31 +00:00
|
|
|
std::vector<std::string> v;
|
2011-11-04 13:27:58 +00:00
|
|
|
std::string s = "k1; k2;; k3";
|
|
|
|
util::split(s.begin(), s.end(), std::back_inserter(v), ';', true);
|
2010-10-10 06:58:31 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, v.size());
|
|
|
|
std::vector<std::string>::iterator itr = v.begin();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k1"), *itr++);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k2"), *itr++);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k3"), *itr++);
|
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
|
2010-10-10 06:58:31 +00:00
|
|
|
v.clear();
|
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
|
2011-11-04 13:27:58 +00:00
|
|
|
s = "k1; k2; k3";
|
|
|
|
util::split(s.begin(), s.end(), std::back_inserter(v), ';');
|
2010-10-10 06:58:31 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, v.size());
|
|
|
|
itr = v.begin();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k1"), *itr++);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(" k2"), *itr++);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(" k3"), *itr++);
|
2010-02-17 16:09:19 +00:00
|
|
|
|
2010-10-10 06:58:31 +00:00
|
|
|
v.clear();
|
2010-02-17 16:09:19 +00:00
|
|
|
|
2011-11-04 13:27:58 +00:00
|
|
|
s = "k=v";
|
|
|
|
util::split(s.begin(), s.end(), std::back_inserter(v), ';', false, true);
|
2010-10-10 06:58:31 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
|
|
|
|
itr = v.begin();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k=v"), *itr++);
|
2010-02-17 16:09:19 +00:00
|
|
|
|
2010-10-10 06:58:31 +00:00
|
|
|
v.clear();
|
2010-02-17 16:09:19 +00:00
|
|
|
|
2011-11-04 13:27:58 +00:00
|
|
|
s = ";;k1;;k2;";
|
|
|
|
util::split(s.begin(), s.end(), std::back_inserter(v), ';', false, true);
|
2010-10-10 06:58:31 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)6, v.size());
|
|
|
|
itr = v.begin();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), *itr++);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), *itr++);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k1"), *itr++);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), *itr++);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k2"), *itr++);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), *itr++);
|
2010-02-17 16:09:19 +00:00
|
|
|
|
2010-10-10 06:58:31 +00:00
|
|
|
v.clear();
|
2010-02-17 16:09:19 +00:00
|
|
|
|
2011-11-04 13:27:58 +00:00
|
|
|
s = ";;k1;;k2;";
|
|
|
|
util::split(s.begin(), s.end(), std::back_inserter(v), ';');
|
2010-10-10 06:58:31 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, v.size());
|
|
|
|
itr = v.begin();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k1"), *itr++);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k2"), *itr++);
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
2011-11-04 13:27:58 +00:00
|
|
|
s = "k; ";
|
|
|
|
util::split(s.begin(), s.end(), std::back_inserter(v), ';');
|
2010-10-10 06:58:31 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, v.size());
|
|
|
|
itr = v.begin();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k"), *itr++);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(" "), *itr++);
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
2011-11-04 13:27:58 +00:00
|
|
|
s = " ";
|
|
|
|
util::split(s.begin(), s.end(), std::back_inserter(v), ';', true, true);
|
2010-10-10 06:58:31 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), v[0]);
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
2011-11-04 13:27:58 +00:00
|
|
|
s = " ";
|
|
|
|
util::split(s.begin(), s.end(), std::back_inserter(v), ';', true);
|
2010-10-10 06:58:31 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, v.size());
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
2011-11-04 13:27:58 +00:00
|
|
|
s = " ";
|
|
|
|
util::split(s.begin(), s.end(), std::back_inserter(v), ';');
|
2010-10-10 06:58:31 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(" "), v[0]);
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
2011-11-04 13:27:58 +00:00
|
|
|
s = ";";
|
|
|
|
util::split(s.begin(), s.end(), std::back_inserter(v), ';');
|
2010-10-10 06:58:31 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, v.size());
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
2011-11-04 13:27:58 +00:00
|
|
|
s = ";";
|
|
|
|
util::split(s.begin(), s.end(), std::back_inserter(v), ';', false, true);
|
2010-10-10 06:58:31 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, v.size());
|
|
|
|
itr = v.begin();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), *itr++);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), *itr++);
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
2011-11-04 13:27:58 +00:00
|
|
|
s = "";
|
|
|
|
util::split(s.begin(), s.end(), std::back_inserter(v), ';', false, true);
|
2010-10-10 06:58:31 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), v[0]);
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
2006-02-21 12:27:17 +00:00
|
|
|
|
2011-11-04 13:27:58 +00:00
|
|
|
void UtilTest::testSplitIter() {
|
|
|
|
std::vector<Scip> v;
|
|
|
|
std::string s = "k1; k2;; k3";
|
|
|
|
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';', true);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k1"), std::string(v[0].first, v[0].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k2"), std::string(v[1].first, v[1].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k3"), std::string(v[2].first, v[2].second));
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = "k1; k2; k3";
|
|
|
|
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';');
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k1"), std::string(v[0].first, v[0].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(" k2"),
|
|
|
|
std::string(v[1].first, v[1].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(" k3"),
|
|
|
|
std::string(v[2].first, v[2].second));
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = "k=v";
|
|
|
|
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';', false, true);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k=v"),
|
|
|
|
std::string(v[0].first, v[0].second));
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = ";;k1;;k2;";
|
|
|
|
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';', false, true);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)6, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[0].first, v[0].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[1].first, v[1].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k1"), std::string(v[2].first, v[2].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[3].first, v[3].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k2"), std::string(v[4].first, v[4].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[5].first, v[5].second));
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = ";;k1;;k2;";
|
|
|
|
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';');
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k1"), std::string(v[0].first, v[0].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k2"), std::string(v[1].first, v[1].second));
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = "k; ";
|
|
|
|
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';');
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k"), std::string(v[0].first, v[0].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(" "), std::string(v[1].first, v[1].second));
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = " ";
|
|
|
|
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';', true, true);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[0].first, v[0].second));
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = " ";
|
|
|
|
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';', true);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, v.size());
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = " ";
|
|
|
|
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';');
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(" "), std::string(v[0].first, v[0].second));
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = ";";
|
|
|
|
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';');
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, v.size());
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = ";";
|
|
|
|
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';', false, true);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[0].first, v[0].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[1].first, v[1].second));
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = "";
|
|
|
|
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';', false, true);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[0].first, v[0].second));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UtilTest::testSplitIterM() {
|
2012-01-10 16:03:38 +00:00
|
|
|
const char d[] = ";";
|
|
|
|
const char md[] = "; ";
|
2011-11-04 13:27:58 +00:00
|
|
|
std::vector<Scip> v;
|
|
|
|
std::string s = "k1; k2;; k3";
|
2012-01-10 16:03:38 +00:00
|
|
|
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d, true);
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k1"), std::string(v[0].first, v[0].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k2"), std::string(v[1].first, v[1].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k3"), std::string(v[2].first, v[2].second));
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = "k1; k2; k3";
|
2012-01-10 16:03:38 +00:00
|
|
|
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d);
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k1"), std::string(v[0].first, v[0].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(" k2"),
|
|
|
|
std::string(v[1].first, v[1].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(" k3"),
|
|
|
|
std::string(v[2].first, v[2].second));
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = "k1; k2; k3";
|
2012-01-10 16:03:38 +00:00
|
|
|
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), md);
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k1"), std::string(v[0].first, v[0].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k2"), std::string(v[1].first, v[1].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k3"), std::string(v[2].first, v[2].second));
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = "k1; k2; k3;";
|
2012-01-10 16:03:38 +00:00
|
|
|
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), md, false, true);
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)6, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k1"), std::string(v[0].first, v[0].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[1].first, v[1].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k2"), std::string(v[2].first, v[2].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[3].first, v[3].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k3"), std::string(v[4].first, v[4].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[5].first, v[5].second));
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = "k=v";
|
2012-01-10 16:03:38 +00:00
|
|
|
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d, false, true);
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k=v"),
|
|
|
|
std::string(v[0].first, v[0].second));
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = ";;k1;;k2;";
|
2012-01-10 16:03:38 +00:00
|
|
|
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d, false, true);
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)6, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[0].first, v[0].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[1].first, v[1].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k1"), std::string(v[2].first, v[2].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[3].first, v[3].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k2"), std::string(v[4].first, v[4].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[5].first, v[5].second));
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = ";;k1;;k2;";
|
2012-01-10 16:03:38 +00:00
|
|
|
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d);
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k1"), std::string(v[0].first, v[0].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k2"), std::string(v[1].first, v[1].second));
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = "k; ";
|
2012-01-10 16:03:38 +00:00
|
|
|
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d);
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("k"), std::string(v[0].first, v[0].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(" "), std::string(v[1].first, v[1].second));
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = " ";
|
2012-01-10 16:03:38 +00:00
|
|
|
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d, true, true);
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[0].first, v[0].second));
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = " ";
|
2012-01-10 16:03:38 +00:00
|
|
|
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d, true);
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, v.size());
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = " ";
|
2012-01-10 16:03:38 +00:00
|
|
|
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d);
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(" "), std::string(v[0].first, v[0].second));
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = ";";
|
2012-01-10 16:03:38 +00:00
|
|
|
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d);
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, v.size());
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = ";";
|
2012-01-10 16:03:38 +00:00
|
|
|
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d, false, true);
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[0].first, v[0].second));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[1].first, v[1].second));
|
|
|
|
|
|
|
|
v.clear();
|
|
|
|
|
|
|
|
s = "";
|
2012-01-10 16:03:38 +00:00
|
|
|
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d, false, true);
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[0].first, v[0].second));
|
|
|
|
}
|
|
|
|
|
2006-02-21 12:27:17 +00:00
|
|
|
void UtilTest::testEndsWith() {
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string target = "abcdefg";
|
|
|
|
std::string part = "fg";
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT(util::endsWith(target.begin(), target.end(),
|
|
|
|
part.begin(), part.end()));
|
2006-02-21 12:27:17 +00:00
|
|
|
|
|
|
|
target = "abdefg";
|
|
|
|
part = "g";
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT(util::endsWith(target.begin(), target.end(),
|
|
|
|
part.begin(), part.end()));
|
2006-02-21 12:27:17 +00:00
|
|
|
|
|
|
|
target = "abdefg";
|
|
|
|
part = "eg";
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT(!util::endsWith(target.begin(), target.end(),
|
|
|
|
part.begin(), part.end()));
|
2006-02-21 12:27:17 +00:00
|
|
|
|
|
|
|
target = "g";
|
|
|
|
part = "eg";
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT(!util::endsWith(target.begin(), target.end(),
|
|
|
|
part.begin(), part.end()));
|
2006-02-21 12:27:17 +00:00
|
|
|
|
|
|
|
target = "g";
|
|
|
|
part = "g";
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT(util::endsWith(target.begin(), target.end(),
|
|
|
|
part.begin(), part.end()));
|
2006-02-21 12:27:17 +00:00
|
|
|
|
|
|
|
target = "g";
|
|
|
|
part = "";
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT(util::endsWith(target.begin(), target.end(),
|
|
|
|
part.begin(), part.end()));
|
2006-02-21 12:27:17 +00:00
|
|
|
|
|
|
|
target = "";
|
|
|
|
part = "";
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT(util::endsWith(target.begin(), target.end(),
|
|
|
|
part.begin(), part.end()));
|
2006-02-21 12:27:17 +00:00
|
|
|
|
|
|
|
target = "";
|
|
|
|
part = "g";
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT(!util::endsWith(target.begin(), target.end(),
|
|
|
|
part.begin(), part.end()));
|
|
|
|
}
|
|
|
|
|
2011-11-04 15:25:24 +00:00
|
|
|
void UtilTest::testIendsWith() {
|
|
|
|
std::string target = "abcdefg";
|
|
|
|
std::string part = "Fg";
|
|
|
|
CPPUNIT_ASSERT(util::iendsWith(target.begin(), target.end(),
|
|
|
|
part.begin(), part.end()));
|
|
|
|
|
|
|
|
target = "abdefg";
|
|
|
|
part = "ef";
|
|
|
|
CPPUNIT_ASSERT(!util::iendsWith(target.begin(), target.end(),
|
|
|
|
part.begin(), part.end()));
|
|
|
|
}
|
|
|
|
|
2011-11-04 13:27:58 +00:00
|
|
|
void UtilTest::testStreq()
|
|
|
|
{
|
|
|
|
std::string s1, s2;
|
|
|
|
s1 = "foo";
|
|
|
|
s2 = "foo";
|
|
|
|
CPPUNIT_ASSERT(util::streq(s1.begin(), s1.end(), s2.begin(), s2.end()));
|
2012-01-10 16:50:35 +00:00
|
|
|
CPPUNIT_ASSERT(util::streq(s1.begin(), s1.end(), s2.c_str()));
|
2011-11-04 13:27:58 +00:00
|
|
|
|
|
|
|
s2 = "fooo";
|
|
|
|
CPPUNIT_ASSERT(!util::streq(s1.begin(), s1.end(), s2.begin(), s2.end()));
|
2012-01-10 16:50:35 +00:00
|
|
|
CPPUNIT_ASSERT(!util::streq(s1.begin(), s1.end(), s2.c_str()));
|
2011-11-04 13:27:58 +00:00
|
|
|
|
|
|
|
s2 = "fo";
|
|
|
|
CPPUNIT_ASSERT(!util::streq(s1.begin(), s1.end(), s2.begin(), s2.end()));
|
2012-01-10 16:50:35 +00:00
|
|
|
CPPUNIT_ASSERT(!util::streq(s1.begin(), s1.end(), s2.c_str()));
|
2011-11-04 13:27:58 +00:00
|
|
|
|
|
|
|
s2 = "";
|
|
|
|
CPPUNIT_ASSERT(!util::streq(s1.begin(), s1.end(), s2.begin(), s2.end()));
|
2012-01-10 16:50:35 +00:00
|
|
|
CPPUNIT_ASSERT(!util::streq(s1.begin(), s1.end(), s2.c_str()));
|
2011-11-04 13:27:58 +00:00
|
|
|
|
|
|
|
s1 = "";
|
|
|
|
CPPUNIT_ASSERT(util::streq(s1.begin(), s1.end(), s2.begin(), s2.end()));
|
2012-01-10 16:50:35 +00:00
|
|
|
CPPUNIT_ASSERT(util::streq(s1.begin(), s1.end(), s2.c_str()));
|
2011-11-04 13:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UtilTest::testStrieq()
|
|
|
|
{
|
|
|
|
std::string s1, s2;
|
|
|
|
s1 = "foo";
|
|
|
|
s2 = "foo";
|
|
|
|
CPPUNIT_ASSERT(util::strieq(s1.begin(), s1.end(), s2.begin(), s2.end()));
|
2012-01-10 16:50:35 +00:00
|
|
|
CPPUNIT_ASSERT(util::strieq(s1.begin(), s1.end(), s2.c_str()));
|
2011-11-04 13:27:58 +00:00
|
|
|
|
|
|
|
s1 = "FoO";
|
|
|
|
s2 = "fOo";
|
|
|
|
CPPUNIT_ASSERT(util::strieq(s1.begin(), s1.end(), s2.begin(), s2.end()));
|
2012-01-10 16:50:35 +00:00
|
|
|
CPPUNIT_ASSERT(util::strieq(s1.begin(), s1.end(), s2.c_str()));
|
2011-11-04 13:27:58 +00:00
|
|
|
|
|
|
|
s2 = "fooo";
|
|
|
|
CPPUNIT_ASSERT(!util::strieq(s1.begin(), s1.end(), s2.begin(), s2.end()));
|
2012-01-10 16:50:35 +00:00
|
|
|
CPPUNIT_ASSERT(!util::strieq(s1.begin(), s1.end(), s2.c_str()));
|
2011-11-04 13:27:58 +00:00
|
|
|
|
|
|
|
s2 = "fo";
|
|
|
|
CPPUNIT_ASSERT(!util::strieq(s1.begin(), s1.end(), s2.begin(), s2.end()));
|
2012-01-10 16:50:35 +00:00
|
|
|
CPPUNIT_ASSERT(!util::strieq(s1.begin(), s1.end(), s2.c_str()));
|
2011-11-04 13:27:58 +00:00
|
|
|
|
|
|
|
s2 = "";
|
|
|
|
CPPUNIT_ASSERT(!util::strieq(s1.begin(), s1.end(), s2.begin(), s2.end()));
|
2012-01-10 16:50:35 +00:00
|
|
|
CPPUNIT_ASSERT(!util::strieq(s1.begin(), s1.end(), s2.c_str()));
|
2011-11-04 13:27:58 +00:00
|
|
|
|
|
|
|
s1 = "";
|
|
|
|
CPPUNIT_ASSERT(util::strieq(s1.begin(), s1.end(), s2.begin(), s2.end()));
|
2012-01-10 16:50:35 +00:00
|
|
|
CPPUNIT_ASSERT(util::strieq(s1.begin(), s1.end(), s2.c_str()));
|
2006-02-21 12:27:17 +00:00
|
|
|
}
|
2006-02-21 15:01:05 +00:00
|
|
|
|
2011-11-11 13:50:18 +00:00
|
|
|
void UtilTest::testStrifind()
|
|
|
|
{
|
|
|
|
std::string s1, s2;
|
|
|
|
s1 = "yamagakani mukashi wo toheba hARU no tuki";
|
|
|
|
s2 = "HaRu";
|
|
|
|
CPPUNIT_ASSERT(util::strifind(s1.begin(), s1.end(), s2.begin(), s2.end())
|
|
|
|
!= s1.end());
|
|
|
|
s2 = "aki";
|
|
|
|
CPPUNIT_ASSERT(util::strifind(s1.begin(), s1.end(), s2.begin(), s2.end())
|
|
|
|
== s1.end());
|
|
|
|
s1 = "h";
|
|
|
|
s2 = "HH";
|
|
|
|
CPPUNIT_ASSERT(util::strifind(s1.begin(), s1.end(), s2.begin(), s2.end())
|
|
|
|
== s1.end());
|
|
|
|
}
|
|
|
|
|
2006-02-21 15:01:05 +00:00
|
|
|
void UtilTest::testReplace() {
|
2009-10-22 15:09:00 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("abc\n"), util::replace("abc\r\n", "\r", ""));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("abc"), util::replace("abc\r\n", "\r\n", ""));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), util::replace("", "\r\n", ""));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("abc"), util::replace("abc", "", "a"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("xbc"), util::replace("abc", "a", "x"));
|
2006-02-21 15:01:05 +00:00
|
|
|
}
|
2006-02-28 02:25:45 +00:00
|
|
|
|
|
|
|
void UtilTest::testStartsWith() {
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string target;
|
|
|
|
std::string part;
|
2006-02-28 02:25:45 +00:00
|
|
|
|
|
|
|
target = "abcdefg";
|
|
|
|
part = "abc";
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT(util::startsWith(target.begin(), target.end(),
|
|
|
|
part.begin(), part.end()));
|
2012-01-10 16:50:35 +00:00
|
|
|
CPPUNIT_ASSERT(util::startsWith(target.begin(), target.end(), part.c_str()));
|
2006-02-28 02:25:45 +00:00
|
|
|
|
|
|
|
target = "abcdefg";
|
|
|
|
part = "abx";
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT(!util::startsWith(target.begin(), target.end(),
|
|
|
|
part.begin(), part.end()));
|
2012-01-10 16:50:35 +00:00
|
|
|
CPPUNIT_ASSERT(!util::startsWith(target.begin(), target.end(), part.c_str()));
|
2006-02-28 02:25:45 +00:00
|
|
|
|
|
|
|
target = "abcdefg";
|
|
|
|
part = "bcd";
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT(!util::startsWith(target.begin(), target.end(),
|
|
|
|
part.begin(), part.end()));
|
2012-01-10 16:50:35 +00:00
|
|
|
CPPUNIT_ASSERT(!util::startsWith(target.begin(), target.end(), part.c_str()));
|
2006-02-28 02:25:45 +00:00
|
|
|
|
|
|
|
target = "";
|
|
|
|
part = "a";
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT(!util::startsWith(target.begin(), target.end(),
|
|
|
|
part.begin(), part.end()));
|
2012-01-10 16:50:35 +00:00
|
|
|
CPPUNIT_ASSERT(!util::startsWith(target.begin(), target.end(), part.c_str()));
|
2006-02-28 02:25:45 +00:00
|
|
|
|
|
|
|
target = "";
|
|
|
|
part = "";
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT(util::startsWith(target.begin(), target.end(),
|
|
|
|
part.begin(), part.end()));
|
2012-01-10 16:50:35 +00:00
|
|
|
CPPUNIT_ASSERT(util::startsWith(target.begin(), target.end(), part.c_str()));
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2006-02-28 02:25:45 +00:00
|
|
|
target = "a";
|
|
|
|
part = "";
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT(util::startsWith(target.begin(), target.end(),
|
|
|
|
part.begin(), part.end()));
|
2012-01-10 16:50:35 +00:00
|
|
|
CPPUNIT_ASSERT(util::startsWith(target.begin(), target.end(), part.c_str()));
|
2006-02-28 02:25:45 +00:00
|
|
|
|
|
|
|
target = "a";
|
|
|
|
part = "a";
|
2011-11-04 13:27:58 +00:00
|
|
|
CPPUNIT_ASSERT(util::startsWith(target.begin(), target.end(),
|
|
|
|
part.begin(), part.end()));
|
2012-01-10 16:50:35 +00:00
|
|
|
CPPUNIT_ASSERT(util::startsWith(target.begin(), target.end(), part.c_str()));
|
2006-02-28 02:25:45 +00:00
|
|
|
}
|
2006-05-09 15:54:14 +00:00
|
|
|
|
2011-11-04 15:33:35 +00:00
|
|
|
void UtilTest::testIstartsWith() {
|
|
|
|
std::string target;
|
|
|
|
std::string part;
|
|
|
|
|
|
|
|
target = "abcdefg";
|
|
|
|
part = "aBc";
|
|
|
|
CPPUNIT_ASSERT(util::istartsWith(target.begin(), target.end(),
|
|
|
|
part.begin(), part.end()));
|
2012-01-10 16:50:35 +00:00
|
|
|
CPPUNIT_ASSERT(util::istartsWith(target.begin(), target.end(), part.c_str()));
|
2011-11-04 15:33:35 +00:00
|
|
|
|
|
|
|
target = "abcdefg";
|
|
|
|
part = "abx";
|
|
|
|
CPPUNIT_ASSERT(!util::istartsWith(target.begin(), target.end(),
|
|
|
|
part.begin(), part.end()));
|
2012-01-10 16:50:35 +00:00
|
|
|
CPPUNIT_ASSERT(!util::istartsWith(target.begin(), target.end(), part.c_str()));
|
2011-11-04 15:33:35 +00:00
|
|
|
}
|
|
|
|
|
2006-05-09 15:54:14 +00:00
|
|
|
void UtilTest::testGetContentDispositionFilename() {
|
2012-10-27 02:41:56 +00:00
|
|
|
std::string val;
|
2006-05-09 15:54:14 +00:00
|
|
|
|
2012-10-27 02:41:56 +00:00
|
|
|
val = "attachment; filename=\"aria2.tar.bz2\"";
|
2011-11-03 14:09:03 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2.tar.bz2"),
|
2012-10-27 02:41:56 +00:00
|
|
|
util::getContentDispositionFilename(val));
|
2011-11-03 14:09:03 +00:00
|
|
|
|
2012-10-27 02:41:56 +00:00
|
|
|
val = "attachment; filename=\"\"";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""),
|
|
|
|
util::getContentDispositionFilename(val));
|
2007-07-18 11:36:41 +00:00
|
|
|
|
2012-10-27 02:41:56 +00:00
|
|
|
val = "attachment; filename=\"";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""),
|
|
|
|
util::getContentDispositionFilename(val));
|
2007-07-18 11:36:41 +00:00
|
|
|
|
2012-10-27 02:41:56 +00:00
|
|
|
val = "attachment; filename= \" aria2.tar.bz2 \"";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(" aria2.tar.bz2 "),
|
|
|
|
util::getContentDispositionFilename(val));
|
2007-07-18 11:36:41 +00:00
|
|
|
|
2012-10-27 02:41:56 +00:00
|
|
|
val = "attachment; filename=dir/file";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""),
|
|
|
|
util::getContentDispositionFilename(val));
|
2007-07-18 11:36:41 +00:00
|
|
|
|
2012-10-27 02:41:56 +00:00
|
|
|
val = "attachment; filename=dir\\file";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""),
|
|
|
|
util::getContentDispositionFilename(val));
|
2007-07-18 11:36:41 +00:00
|
|
|
|
2012-10-27 02:41:56 +00:00
|
|
|
val = "attachment; filename=\"dir/file\"";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""),
|
|
|
|
util::getContentDispositionFilename(val));
|
2007-07-18 11:36:41 +00:00
|
|
|
|
2012-10-27 02:41:56 +00:00
|
|
|
val = "attachment; filename=\"dir\\\\file\"";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""),
|
|
|
|
util::getContentDispositionFilename(val));
|
2007-07-18 11:36:41 +00:00
|
|
|
|
2012-10-27 02:41:56 +00:00
|
|
|
val = "attachment; filename=\"/etc/passwd\"";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""),
|
|
|
|
util::getContentDispositionFilename(val));
|
2007-07-18 11:36:41 +00:00
|
|
|
|
2012-10-27 02:41:56 +00:00
|
|
|
val = "attachment; filename=\"..\"";
|
2010-03-07 15:06:48 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""),
|
2012-10-27 02:41:56 +00:00
|
|
|
util::getContentDispositionFilename(val));
|
2010-05-06 12:49:50 +00:00
|
|
|
|
2012-10-27 02:41:56 +00:00
|
|
|
val = "attachment; filename=..";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""),
|
|
|
|
util::getContentDispositionFilename(val));
|
2010-05-06 12:49:50 +00:00
|
|
|
|
2012-06-28 14:18:50 +00:00
|
|
|
// Unescaping %2E%2E%2F produces "../". But since we won't unescape,
|
|
|
|
// we just accept it as is.
|
2012-10-27 02:41:56 +00:00
|
|
|
val = "attachment; filename=\"%2E%2E%2Ffoo.html\"";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("%2E%2E%2Ffoo.html"),
|
|
|
|
util::getContentDispositionFilename(val));
|
|
|
|
|
|
|
|
// iso-8859-1 string will be converted to utf-8.
|
|
|
|
val = "attachment; filename*=iso-8859-1''foo-%E4.html";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
|
|
|
|
util::getContentDispositionFilename(val));
|
|
|
|
|
|
|
|
val = "attachment; filename*= UTF-8''foo-%c3%a4.html";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
|
|
|
|
util::getContentDispositionFilename(val));
|
|
|
|
|
|
|
|
// iso-8859-1 string will be converted to utf-8.
|
|
|
|
val = "attachment; filename=\"foo-%E4.html\"";
|
|
|
|
val = util::percentDecode(val.begin(), val.end());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
|
|
|
|
util::getContentDispositionFilename(val));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UtilTest::testParseContentDisposition() {
|
|
|
|
char dest[1024];
|
|
|
|
size_t destlen = sizeof(dest);
|
|
|
|
const char *cs;
|
|
|
|
size_t cslen;
|
|
|
|
std::string val;
|
|
|
|
|
|
|
|
// test cases from http://greenbytes.de/tech/tc2231/
|
|
|
|
// inlonly
|
|
|
|
val = "inline";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// inlonlyquoted
|
|
|
|
val = "\"inline\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// inlwithasciifilename
|
|
|
|
val = "inline; filename=\"foo.html\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
|
|
|
std::string(&dest[0], &dest[8]));
|
|
|
|
|
|
|
|
// inlwithfnattach
|
|
|
|
val = "inline; filename=\"Not an attachment!\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)18, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("Not an attachment!"),
|
|
|
|
std::string(&dest[0], &dest[18]));
|
|
|
|
|
|
|
|
// inlwithasciifilenamepdf
|
|
|
|
val = "inline; filename=\"foo.pdf\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)7, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo.pdf"),
|
|
|
|
std::string(&dest[0], &dest[7]));
|
|
|
|
|
|
|
|
// attwithasciifilename25
|
|
|
|
val = "attachment; filename=\"0000000000111111111122222\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)25, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("0000000000111111111122222"),
|
|
|
|
std::string(&dest[0], &dest[25]));
|
|
|
|
|
|
|
|
// attwithasciifilename35
|
|
|
|
val = "attachment; filename=\"00000000001111111111222222222233333\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)35, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("00000000001111111111222222222233333"),
|
|
|
|
std::string(&dest[0], &dest[35]));
|
|
|
|
|
2010-02-19 10:54:40 +00:00
|
|
|
// attwithasciifnescapedchar
|
2012-10-27 02:41:56 +00:00
|
|
|
val = "attachment; filename=\"f\\oo.html\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
|
|
|
std::string(&dest[0], &dest[8]));
|
|
|
|
|
|
|
|
// attwithasciifnescapedquote
|
|
|
|
val = "attachment; filename=\"\\\"quoting\\\" tested.html\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)21, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("\"quoting\" tested.html"),
|
|
|
|
std::string(&dest[0], &dest[21]));
|
|
|
|
|
|
|
|
// attwithquotedsemicolon
|
|
|
|
val = "attachment; filename=\"Here's a semicolon;.html\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)24, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("Here's a semicolon;.html"),
|
|
|
|
std::string(&dest[0], &dest[24]));
|
|
|
|
|
|
|
|
// attwithfilenameandextparam
|
|
|
|
val = "attachment; foo=\"bar\"; filename=\"foo.html\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
|
|
|
std::string(&dest[0], &dest[8]));
|
|
|
|
|
|
|
|
// attwithfilenameandextparamescaped
|
|
|
|
val = "attachment; foo=\"\\\"\\\\\";filename=\"foo.html\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
|
|
|
std::string(&dest[0], &dest[8]));
|
|
|
|
|
2010-02-19 10:54:40 +00:00
|
|
|
// attwithasciifilenameucase
|
2012-10-27 02:41:56 +00:00
|
|
|
val = "attachment; FILENAME=\"foo.html\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
|
|
|
std::string(&dest[0], &dest[8]));
|
|
|
|
|
|
|
|
// attwithasciifilenamenq
|
|
|
|
val = "attachment; filename=foo.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
|
|
|
std::string(&dest[0], &dest[8]));
|
|
|
|
|
|
|
|
// attwithtokfncommanq
|
|
|
|
val = "attachment; filename=foo,bar.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attwithasciifilenamenqs
|
|
|
|
val = "attachment; filename=foo.html ;";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attemptyparam
|
|
|
|
val = "attachment; ;filename=foo";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attwithasciifilenamenqws
|
|
|
|
val = "attachment; filename=foo bar.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attwithfntokensq
|
|
|
|
val = "attachment; filename='foo.bar'";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)9, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("'foo.bar'"),
|
|
|
|
std::string(&dest[0], &dest[9]));
|
|
|
|
|
|
|
|
// attwithisofnplain
|
|
|
|
// attachment; filename="foo-ä.html"
|
|
|
|
val = "attachment; filename=\"foo-%E4.html\"";
|
|
|
|
val = util::percentDecode(val.begin(), val.end());
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)10, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
|
|
|
|
util::iso8859p1ToUtf8(std::string(&dest[0], &dest[10])));
|
|
|
|
|
|
|
|
// attwithutf8fnplain
|
|
|
|
// attachment; filename="foo-ä.html"
|
|
|
|
val = "attachment; filename=\"foo-%C3%A4.html\"";
|
|
|
|
val = util::percentDecode(val.begin(), val.end());
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)11, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
|
|
|
|
util::iso8859p1ToUtf8(std::string(&dest[0], &dest[11])));
|
|
|
|
|
|
|
|
// attwithfnrawpctenca
|
|
|
|
val = "attachment; filename=\"foo-%41.html\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)12, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo-%41.html"),
|
|
|
|
std::string(&dest[0], &dest[12]));
|
|
|
|
|
|
|
|
// attwithfnusingpct
|
|
|
|
val = "attachment; filename=\"50%.html\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("50%.html"),
|
|
|
|
std::string(&dest[0], &dest[8]));
|
|
|
|
|
|
|
|
// attwithfnrawpctencaq
|
|
|
|
val = "attachment; filename=\"foo-%\\41.html\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)12, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo-%41.html"),
|
|
|
|
std::string(&dest[0], &dest[12]));
|
|
|
|
|
|
|
|
// attwithnamepct
|
|
|
|
val = "attachment; name=\"foo-%41.html\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attwithfilenamepctandiso
|
|
|
|
// attachment; filename="ä-%41.html"
|
|
|
|
val = "attachment; filename=\"%E4-%2541.html\"";
|
|
|
|
val = util::percentDecode(val.begin(), val.end());
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)10, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("ä-%41.html"),
|
|
|
|
util::iso8859p1ToUtf8(std::string(&dest[0], &dest[10])));
|
|
|
|
|
|
|
|
// attwithfnrawpctenclong
|
|
|
|
val = "attachment; filename=\"foo-%c3%a4-%e2%82%ac.html\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)25, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo-%c3%a4-%e2%82%ac.html"),
|
|
|
|
std::string(&dest[0], &dest[25]));
|
|
|
|
|
|
|
|
// attwithasciifilenamews1
|
|
|
|
val = "attachment; filename =\"foo.html\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
|
|
|
std::string(&dest[0], &dest[8]));
|
|
|
|
|
|
|
|
// attwith2filenames
|
|
|
|
val = "attachment; filename=\"foo.html\"; filename=\"bar.html\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attfnbrokentoken
|
|
|
|
val = "attachment; filename=foo[1](2).html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attfnbrokentokeniso
|
|
|
|
val = "attachment; filename=foo-%E4.html";
|
|
|
|
val = util::percentDecode(val.begin(), val.end());
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attfnbrokentokenutf
|
|
|
|
// attachment; filename=foo-ä.html
|
|
|
|
val = "attachment; filename=foo-ä.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attmissingdisposition
|
|
|
|
val = "filename=foo.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attmissingdisposition2
|
|
|
|
val = "x=y; filename=foo.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attmissingdisposition3
|
|
|
|
val = "\"foo; filename=bar;baz\"; filename=qux";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attmissingdisposition4
|
|
|
|
val = "filename=foo.html, filename=bar.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// emptydisposition
|
|
|
|
val = "; filename=foo.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// doublecolon
|
|
|
|
val = ": inline; attachment; filename=foo.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attandinline
|
|
|
|
val = "inline; attachment; filename=foo.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attandinline2
|
|
|
|
val = "attachment; inline; filename=foo.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attbrokenquotedfn
|
|
|
|
val = "attachment; filename=\"foo.html\".txt";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attbrokenquotedfn2
|
|
|
|
val = "attachment; filename=\"bar";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attbrokenquotedfn3
|
|
|
|
val = "attachment; filename=foo\"bar;baz\"qux";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attmultinstances
|
|
|
|
val = "attachment; filename=foo.html, attachment; filename=bar.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attmissingdelim
|
|
|
|
val = "attachment; foo=foo filename=bar";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attmissingdelim2
|
|
|
|
val = "attachment; filename=bar foo=foo ";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attmissingdelim3
|
|
|
|
val = "attachment filename=bar";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attreversed
|
|
|
|
val = "filename=foo.html; attachment";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attconfusedparam
|
|
|
|
val = "attachment; xfilename=foo.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attabspath
|
|
|
|
val = "attachment; filename=\"/foo.html\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)9, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/foo.html"),
|
|
|
|
std::string(&dest[0], &dest[9]));
|
|
|
|
|
|
|
|
// attabspathwin
|
|
|
|
val = "attachment; filename=\"\\\\foo.html\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)9, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("\\foo.html"),
|
|
|
|
std::string(&dest[0], &dest[9]));
|
|
|
|
|
|
|
|
// attcdate
|
|
|
|
val = "attachment; creation-date=\"Wed, 12 Feb 1997 16:29:51 -0500\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// dispext
|
|
|
|
val = "foobar";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// dispextbadfn
|
|
|
|
val = "attachment; example=\"filename=example.txt\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
2010-02-19 10:54:40 +00:00
|
|
|
// attwithisofn2231iso
|
2012-10-27 02:41:56 +00:00
|
|
|
val = "attachment; filename*=iso-8859-1''foo-%E4.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)10, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("iso-8859-1"), std::string(cs, cslen));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
|
|
|
|
util::iso8859p1ToUtf8(std::string(&dest[0], &dest[10])));
|
|
|
|
|
2010-02-19 10:54:40 +00:00
|
|
|
// attwithfn2231utf8
|
2012-10-27 02:41:56 +00:00
|
|
|
val = "attachment; filename*=UTF-8''foo-%c3%a4-%e2%82%ac.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)15, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("UTF-8"), std::string(cs, cslen));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä-€.html"),
|
|
|
|
std::string(&dest[0], &dest[15]));
|
|
|
|
|
|
|
|
// attwithfn2231noc
|
|
|
|
val = "attachment; filename*=''foo-%c3%a4-%e2%82%ac.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attwithfn2231utf8comp
|
|
|
|
val = "attachment; filename*=UTF-8''foo-a%cc%88.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)12, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
val = "foo-a%cc%88.html";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(util::percentDecode(val.begin(),
|
|
|
|
val.end())),
|
|
|
|
std::string(&dest[0], &dest[12]));
|
|
|
|
|
2010-02-19 10:54:40 +00:00
|
|
|
// attwithfn2231utf8-bad
|
2012-10-27 02:41:56 +00:00
|
|
|
val = "attachment; filename*=iso-8859-1''foo-%c3%a4-%e2%82%ac.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attwithfn2231iso-bad
|
|
|
|
val = "attachment; filename*=utf-8''foo-%E4.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
2010-02-19 10:54:40 +00:00
|
|
|
// attwithfn2231ws1
|
2012-10-27 02:41:56 +00:00
|
|
|
val = "attachment; filename *=UTF-8''foo-%c3%a4.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
2010-02-19 10:54:40 +00:00
|
|
|
// attwithfn2231ws2
|
2012-10-27 02:41:56 +00:00
|
|
|
val = "attachment; filename*= UTF-8''foo-%c3%a4.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)11, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
|
|
|
|
std::string(&dest[0], &dest[11]));
|
|
|
|
|
2010-02-19 10:54:40 +00:00
|
|
|
// attwithfn2231ws3
|
2012-10-27 02:41:56 +00:00
|
|
|
val = "attachment; filename* =UTF-8''foo-%c3%a4.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)11, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
|
|
|
|
std::string(&dest[0], &dest[11]));
|
|
|
|
|
2010-02-19 10:54:40 +00:00
|
|
|
// attwithfn2231quot
|
2012-10-27 02:41:56 +00:00
|
|
|
val = "attachment; filename*=\"UTF-8''foo-%c3%a4.html\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attwithfn2231quot2
|
|
|
|
val = "attachment; filename*=\"foo%20bar.html\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attwithfn2231singleqmissing
|
|
|
|
val = "attachment; filename*=UTF-8'foo-%c3%a4.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attwithfn2231nbadpct1
|
|
|
|
val = "attachment; filename*=UTF-8''foo%";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attwithfn2231nbadpct2
|
|
|
|
val = "attachment; filename*=UTF-8''f%oo.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attwithfn2231dpct
|
|
|
|
val = "attachment; filename*=UTF-8''A-%2541.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)10, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("A-%41.html"),
|
|
|
|
std::string(&dest[0], &dest[10]));
|
|
|
|
|
|
|
|
// attwithfn2231abspathdisguised
|
|
|
|
val = "attachment; filename*=UTF-8''%5cfoo.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)9, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("\\foo.html"),
|
|
|
|
std::string(&dest[0], &dest[9]));
|
|
|
|
|
|
|
|
// attfnboth
|
|
|
|
val = "attachment; filename=\"foo-ae.html\"; filename*=UTF-8''foo-%c3%a4.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)11, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
|
|
|
|
std::string(&dest[0], &dest[11]));
|
|
|
|
|
|
|
|
// attfnboth2
|
|
|
|
val = "attachment; filename*=UTF-8''foo-%c3%a4.html; filename=\"foo-ae.html\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)11, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
|
|
|
|
std::string(&dest[0], &dest[11]));
|
|
|
|
|
|
|
|
// attfnboth3
|
|
|
|
val = "attachment; filename*0*=ISO-8859-15''euro-sign%3d%a4; filename*=ISO-8859-1''currency-sign%3d%a4";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)15, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("ISO-8859-1"), std::string(cs, cslen));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("currency-sign=¤"),
|
|
|
|
util::iso8859p1ToUtf8(std::string(&dest[0], &dest[15])));
|
|
|
|
|
|
|
|
// attnewandfn
|
|
|
|
val = "attachment; foobar=x; filename=\"foo.html\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
|
|
|
std::string(&dest[0], &dest[8]));
|
|
|
|
|
|
|
|
// attrfc2047token
|
|
|
|
val = "attachment; filename==?ISO-8859-1?Q?foo-=E4.html?=";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// attrfc2047quoted
|
|
|
|
val = "attachment; filename=\"=?ISO-8859-1?Q?foo-=E4.html?=\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)29, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("=?ISO-8859-1?Q?foo-=E4.html?="),
|
|
|
|
std::string(&dest[0], &dest[29]));
|
|
|
|
|
|
|
|
// aria2 original testcases
|
|
|
|
|
|
|
|
// zero-length filename. token cannot be empty, so this is invalid.
|
|
|
|
val = "attachment; filename=";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// zero-length filename. quoted-string can be empty string, so this
|
|
|
|
// is ok.
|
|
|
|
val = "attachment; filename=\"\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// empty value is not allowed
|
|
|
|
val = "attachment; filename=;";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// / is not valid char in token.
|
|
|
|
val = "attachment; filename=dir/file";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
|
|
|
|
// value-chars is *(pct-encoded / attr-char), so empty string is
|
|
|
|
// allowed.
|
|
|
|
val = "attachment; filename*=UTF-8''";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("UTF-8"), std::string(cs, cslen));
|
|
|
|
|
|
|
|
val = "attachment; filename*=UTF-8''; filename=foo";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("UTF-8"), std::string(cs, cslen));
|
|
|
|
|
|
|
|
val = "attachment; filename*=UTF-8'' ; filename=foo";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("UTF-8"), std::string(cs, cslen));
|
|
|
|
|
|
|
|
// with language
|
|
|
|
val = "attachment; filename*=UTF-8'japanese'konnichiwa";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)10, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("konnichiwa"),
|
|
|
|
std::string(&dest[0], &dest[10]));
|
|
|
|
|
|
|
|
// lws before and after "="
|
|
|
|
val = "attachment; filename = foo.html";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
|
|
|
std::string(&dest[0], &dest[8]));
|
|
|
|
|
|
|
|
// lws before and after "=" with quoted-string
|
|
|
|
val = "attachment; filename = \"foo.html\"";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
|
|
|
std::string(&dest[0], &dest[8]));
|
|
|
|
|
|
|
|
// lws after parm
|
|
|
|
val = "attachment; filename=foo.html ";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
|
|
|
std::string(&dest[0], &dest[8]));
|
|
|
|
|
|
|
|
val = "attachment; filename=foo.html ; hello=world";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
|
|
|
std::string(&dest[0], &dest[8]));
|
|
|
|
|
|
|
|
val = "attachment; filename=\"foo.html\" ";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
|
|
|
std::string(&dest[0], &dest[8]));
|
|
|
|
|
|
|
|
val = "attachment; filename=\"foo.html\" ; hello=world";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
|
|
|
std::string(&dest[0], &dest[8]));
|
|
|
|
|
|
|
|
val = "attachment; filename*=UTF-8''foo.html ; hello=world";
|
2012-11-01 13:54:32 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
2012-10-27 02:41:56 +00:00
|
|
|
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
|
|
|
std::string(&dest[0], &dest[8]));
|
2006-05-09 15:54:14 +00:00
|
|
|
}
|
2006-05-18 17:08:29 +00:00
|
|
|
|
|
|
|
class Printer {
|
|
|
|
public:
|
|
|
|
template<class T>
|
|
|
|
void operator()(T t) {
|
2008-02-08 15:53:45 +00:00
|
|
|
std::cerr << t << ", ";
|
2006-05-18 17:08:29 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-07-03 14:19:23 +00:00
|
|
|
void UtilTest::testToUpper() {
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string src = "608cabc0f2fa18c260cafd974516865c772363d5";
|
|
|
|
std::string upp = "608CABC0F2FA18C260CAFD974516865C772363D5";
|
2006-07-03 14:19:23 +00:00
|
|
|
|
2009-10-22 15:09:00 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(upp, util::toUpper(src));
|
2006-07-03 14:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UtilTest::testToLower() {
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string src = "608CABC0F2FA18C260CAFD974516865C772363D5";
|
|
|
|
std::string upp = "608cabc0f2fa18c260cafd974516865c772363d5";
|
2006-07-03 14:19:23 +00:00
|
|
|
|
2009-10-22 15:09:00 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(upp, util::toLower(src));
|
2006-07-03 14:19:23 +00:00
|
|
|
}
|
2006-08-28 12:40:41 +00:00
|
|
|
|
2010-10-10 02:51:38 +00:00
|
|
|
void UtilTest::testUppercase() {
|
|
|
|
std::string src = "608cabc0f2fa18c260cafd974516865c772363d5";
|
|
|
|
std::string ans = "608CABC0F2FA18C260CAFD974516865C772363D5";
|
|
|
|
util::uppercase(src);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ans, src);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UtilTest::testLowercase() {
|
|
|
|
std::string src = "608CABC0F2FA18C260CAFD974516865C772363D5";
|
|
|
|
std::string ans = "608cabc0f2fa18c260cafd974516865c772363d5";
|
|
|
|
util::lowercase(src);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ans, src);
|
|
|
|
}
|
|
|
|
|
2010-03-07 14:29:40 +00:00
|
|
|
void UtilTest::testPercentDecode() {
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string src = "http://aria2.sourceforge.net/aria2%200.7.0%20docs.html";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("http://aria2.sourceforge.net/aria2 0.7.0 docs.html"),
|
2011-11-03 10:27:29 +00:00
|
|
|
util::percentDecode(src.begin(), src.end()));
|
2006-08-28 12:40:41 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string src2 = "aria2+aria2";
|
2011-11-03 10:27:29 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2+aria2"),
|
|
|
|
util::percentDecode(src2.begin(), src2.end()));
|
2006-08-28 12:40:41 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string src3 = "%5t%20";
|
2011-11-03 10:27:29 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("%5t "),
|
|
|
|
util::percentDecode(src3.begin(), src3.end()));
|
2006-08-28 12:40:41 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string src4 = "%";
|
2011-11-03 10:27:29 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("%"),
|
|
|
|
util::percentDecode(src4.begin(), src4.end()));
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string src5 = "%3";
|
2011-11-03 10:27:29 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("%3"),
|
|
|
|
util::percentDecode(src5.begin(), src5.end()));
|
2006-08-28 12:40:41 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string src6 = "%2f";
|
2011-11-03 10:27:29 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/"),
|
|
|
|
util::percentDecode(src6.begin(), src6.end()));
|
2006-08-28 12:40:41 +00:00
|
|
|
}
|
2007-01-28 14:18:35 +00:00
|
|
|
|
2007-03-26 12:16:57 +00:00
|
|
|
void UtilTest::testGetRealSize()
|
|
|
|
{
|
2009-10-22 15:09:00 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)4294967296LL, util::getRealSize("4096M"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)1024, util::getRealSize("1K"));
|
2007-11-22 11:17:35 +00:00
|
|
|
try {
|
2009-10-22 15:09:00 +00:00
|
|
|
util::getRealSize("");
|
2007-11-22 11:17:35 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(Exception& e) {
|
|
|
|
std::cerr << e.stackTrace();
|
2007-11-22 11:17:35 +00:00
|
|
|
}
|
|
|
|
try {
|
2009-10-22 15:09:00 +00:00
|
|
|
util::getRealSize("foo");
|
2007-11-22 11:17:35 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(Exception& e) {
|
|
|
|
std::cerr << e.stackTrace();
|
2007-11-22 11:17:35 +00:00
|
|
|
}
|
|
|
|
try {
|
2009-10-22 15:09:00 +00:00
|
|
|
util::getRealSize("-1");
|
2007-11-22 11:17:35 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(Exception& e) {
|
|
|
|
std::cerr << e.stackTrace();
|
2007-11-22 11:17:35 +00:00
|
|
|
}
|
|
|
|
try {
|
2009-10-22 15:09:00 +00:00
|
|
|
util::getRealSize("9223372036854775807K");
|
2007-11-22 11:17:35 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(Exception& e) {
|
|
|
|
std::cerr << e.stackTrace();
|
2007-11-22 11:17:35 +00:00
|
|
|
}
|
|
|
|
try {
|
2009-10-22 15:09:00 +00:00
|
|
|
util::getRealSize("9223372036854775807M");
|
2007-11-22 11:17:35 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(Exception& e) {
|
|
|
|
std::cerr << e.stackTrace();
|
2007-11-22 11:17:35 +00:00
|
|
|
}
|
2007-03-26 12:16:57 +00:00
|
|
|
}
|
2007-06-05 11:37:25 +00:00
|
|
|
|
|
|
|
void UtilTest::testAbbrevSize()
|
|
|
|
{
|
2009-10-22 15:09:00 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("4,096.0Mi"), util::abbrevSize(4294967296LL));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("1.0Ki"), util::abbrevSize(1024));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("1,023"), util::abbrevSize(1023));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("0"), util::abbrevSize(0));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("1.1Ki"), util::abbrevSize(1127));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("1.5Mi"), util::abbrevSize(1572864));
|
2007-06-10 12:01:32 +00:00
|
|
|
|
2007-06-05 11:37:25 +00:00
|
|
|
}
|
2007-07-01 10:40:30 +00:00
|
|
|
|
|
|
|
void UtilTest::testToStream()
|
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
std::ostringstream os;
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<FileEntry> f1(new FileEntry("aria2.tar.bz2", 12300, 0));
|
|
|
|
SharedHandle<FileEntry> f2(new FileEntry("aria2.txt", 556, 0));
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<SharedHandle<FileEntry> > entries;
|
2007-07-01 10:40:30 +00:00
|
|
|
entries.push_back(f1);
|
|
|
|
entries.push_back(f2);
|
2012-09-25 14:44:41 +00:00
|
|
|
const char* filename = A2_TEST_OUT_DIR"/aria2_UtilTest_testToStream";
|
2011-08-09 14:33:55 +00:00
|
|
|
BufferedFile fp(filename, BufferedFile::WRITE);
|
|
|
|
util::toStream(entries.begin(), entries.end(), fp);
|
|
|
|
fp.close();
|
2007-07-01 10:40:30 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(
|
2010-01-05 16:01:46 +00:00
|
|
|
std::string("Files:\n"
|
|
|
|
"idx|path/length\n"
|
|
|
|
"===+===========================================================================\n"
|
|
|
|
" 1|aria2.tar.bz2\n"
|
|
|
|
" |12.0KiB (12,300)\n"
|
|
|
|
"---+---------------------------------------------------------------------------\n"
|
|
|
|
" 2|aria2.txt\n"
|
|
|
|
" |556B (556)\n"
|
|
|
|
"---+---------------------------------------------------------------------------\n"),
|
2011-08-09 14:33:55 +00:00
|
|
|
readFile(filename));
|
2007-07-01 10:40:30 +00:00
|
|
|
}
|
2007-08-28 11:51:20 +00:00
|
|
|
|
|
|
|
void UtilTest::testIsNumber()
|
|
|
|
{
|
2011-11-06 07:37:02 +00:00
|
|
|
std::string s = "000";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, util::isNumber(s.begin(),s.end()));
|
|
|
|
s = "a";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, util::isNumber(s.begin(), s.end()));
|
|
|
|
s = "0a";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, util::isNumber(s.begin(), s.end()));
|
|
|
|
s = "";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, util::isNumber(s.begin(), s.end()));
|
|
|
|
s = " ";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, util::isNumber(s.begin(), s.end()));
|
2007-08-28 11:51:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UtilTest::testIsLowercase()
|
|
|
|
{
|
2011-11-06 07:37:02 +00:00
|
|
|
std::string s = "alpha";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, util::isLowercase(s.begin(), s.end()));
|
|
|
|
s = "Alpha";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, util::isLowercase(s.begin(), s.end()));
|
|
|
|
s = "1alpha";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, util::isLowercase(s.begin(), s.end()));
|
|
|
|
s = "";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, util::isLowercase(s.begin(), s.end()));
|
|
|
|
s = " ";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, util::isLowercase(s.begin(), s.end()));
|
2007-08-28 11:51:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UtilTest::testIsUppercase()
|
|
|
|
{
|
2011-11-06 07:37:02 +00:00
|
|
|
std::string s = "ALPHA";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, util::isUppercase(s.begin(), s.end()));
|
|
|
|
s = "Alpha";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, util::isUppercase(s.begin(), s.end()));
|
|
|
|
s = "1ALPHA";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, util::isUppercase(s.begin(), s.end()));
|
|
|
|
s = "";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, util::isUppercase(s.begin(), s.end()));
|
|
|
|
s = " ";
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, util::isUppercase(s.begin(), s.end()));
|
2007-08-28 11:51:20 +00:00
|
|
|
}
|
|
|
|
|
2007-11-05 15:13:55 +00:00
|
|
|
void UtilTest::testMkdirs()
|
|
|
|
{
|
2011-08-24 15:26:36 +00:00
|
|
|
std::string dir = A2_TEST_OUT_DIR"/aria2-UtilTest-testMkdirs";
|
2007-11-05 15:13:55 +00:00
|
|
|
File d(dir);
|
|
|
|
if(d.exists()) {
|
|
|
|
CPPUNIT_ASSERT(d.remove());
|
|
|
|
}
|
|
|
|
CPPUNIT_ASSERT(!d.exists());
|
2009-10-22 15:09:00 +00:00
|
|
|
util::mkdirs(dir);
|
2007-11-05 15:13:55 +00:00
|
|
|
CPPUNIT_ASSERT(d.isDir());
|
|
|
|
|
2010-12-02 13:38:36 +00:00
|
|
|
std::string file = A2_TEST_DIR"/UtilTest.cc";
|
2007-11-05 15:13:55 +00:00
|
|
|
File f(file);
|
|
|
|
CPPUNIT_ASSERT(f.isFile());
|
|
|
|
try {
|
2009-10-22 15:09:00 +00:00
|
|
|
util::mkdirs(file);
|
2007-11-05 15:13:55 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(DlAbortEx& ex) {
|
|
|
|
std::cerr << ex.stackTrace() << std::endl;
|
2007-11-05 15:13:55 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-13 10:10:11 +00:00
|
|
|
|
|
|
|
void UtilTest::testConvertBitfield()
|
|
|
|
{
|
|
|
|
BitfieldMan srcBitfield(384*1024, 256*1024*256+1);
|
|
|
|
BitfieldMan destBitfield(512*1024, srcBitfield.getTotalLength());
|
|
|
|
srcBitfield.setAllBit();
|
|
|
|
srcBitfield.unsetBit(2);// <- range [768, 1152)
|
|
|
|
// which corresponds to the index [1,2] in destBitfield
|
2009-10-22 15:09:00 +00:00
|
|
|
util::convertBitfield(&destBitfield, &srcBitfield);
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("9fffffffffffffffffffffffffffffff80"),
|
2010-01-05 16:01:46 +00:00
|
|
|
util::toHex(destBitfield.getBitfield(),
|
|
|
|
destBitfield.getBitfieldLength()));
|
2007-11-13 10:10:11 +00:00
|
|
|
}
|
2007-11-21 16:14:40 +00:00
|
|
|
|
2011-10-29 14:33:48 +00:00
|
|
|
void UtilTest::testParseIntSegments()
|
|
|
|
{
|
|
|
|
SegList<int> sgl;
|
|
|
|
util::parseIntSegments(sgl, "1,3-8,10");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(sgl.hasNext());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, sgl.next());
|
|
|
|
CPPUNIT_ASSERT(sgl.hasNext());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(3, sgl.next());
|
|
|
|
CPPUNIT_ASSERT(sgl.hasNext());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(4, sgl.next());
|
|
|
|
CPPUNIT_ASSERT(sgl.hasNext());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(5, sgl.next());
|
|
|
|
CPPUNIT_ASSERT(sgl.hasNext());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(6, sgl.next());
|
|
|
|
CPPUNIT_ASSERT(sgl.hasNext());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(7, sgl.next());
|
|
|
|
CPPUNIT_ASSERT(sgl.hasNext());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(8, sgl.next());
|
|
|
|
CPPUNIT_ASSERT(sgl.hasNext());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(10, sgl.next());
|
|
|
|
CPPUNIT_ASSERT(!sgl.hasNext());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, sgl.next());
|
|
|
|
|
|
|
|
sgl.clear();
|
|
|
|
util::parseIntSegments(sgl, ",,,1,,,3,,,");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, sgl.next());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(3, sgl.next());
|
|
|
|
CPPUNIT_ASSERT(!sgl.hasNext());
|
|
|
|
}
|
|
|
|
|
|
|
|
void UtilTest::testParseIntSegments_invalidRange()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
SegList<int> sgl;
|
|
|
|
util::parseIntSegments(sgl, "-1");
|
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(Exception& e) {
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
SegList<int> sgl;
|
|
|
|
util::parseIntSegments(sgl, "1-");
|
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(Exception& e) {
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
SegList<int> sgl;
|
|
|
|
util::parseIntSegments(sgl, "2147483648");
|
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(Exception& e) {
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
SegList<int> sgl;
|
|
|
|
util::parseIntSegments(sgl, "2147483647-2147483648");
|
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(Exception& e) {
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
SegList<int> sgl;
|
|
|
|
util::parseIntSegments(sgl, "1-2x");
|
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(Exception& e) {
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
SegList<int> sgl;
|
|
|
|
util::parseIntSegments(sgl, "3x-4");
|
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(Exception& e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-15 12:52:03 +00:00
|
|
|
void UtilTest::testParseIntNoThrow()
|
|
|
|
{
|
2011-11-03 09:51:31 +00:00
|
|
|
std::string s;
|
2010-11-15 12:52:03 +00:00
|
|
|
int32_t n;
|
2011-11-03 09:51:31 +00:00
|
|
|
s = " -1 ";
|
2011-11-11 16:06:52 +00:00
|
|
|
CPPUNIT_ASSERT(util::parseIntNoThrow(n, s));
|
2010-11-15 12:52:03 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)-1, n);
|
|
|
|
|
2011-11-03 09:51:31 +00:00
|
|
|
s = "2147483647";
|
2011-11-11 16:06:52 +00:00
|
|
|
CPPUNIT_ASSERT(util::parseIntNoThrow(n, s));
|
2010-11-15 12:52:03 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)2147483647, n);
|
|
|
|
|
2011-11-03 09:51:31 +00:00
|
|
|
s = "2147483648";
|
2011-11-11 16:06:52 +00:00
|
|
|
CPPUNIT_ASSERT(!util::parseIntNoThrow(n, s));
|
2011-11-03 09:51:31 +00:00
|
|
|
s = "-2147483649";
|
2011-11-11 16:06:52 +00:00
|
|
|
CPPUNIT_ASSERT(!util::parseIntNoThrow(n, s));
|
2010-11-15 12:52:03 +00:00
|
|
|
|
2011-11-03 09:51:31 +00:00
|
|
|
s = "12x";
|
2011-11-11 16:06:52 +00:00
|
|
|
CPPUNIT_ASSERT(!util::parseIntNoThrow(n, s));
|
2011-11-03 09:51:31 +00:00
|
|
|
s = "";
|
2011-11-11 16:06:52 +00:00
|
|
|
CPPUNIT_ASSERT(!util::parseIntNoThrow(n, s));
|
2010-11-15 12:52:03 +00:00
|
|
|
}
|
|
|
|
|
2010-10-09 16:58:58 +00:00
|
|
|
void UtilTest::testParseUIntNoThrow()
|
|
|
|
{
|
2011-11-03 09:51:31 +00:00
|
|
|
std::string s;
|
2010-10-09 16:58:58 +00:00
|
|
|
uint32_t n;
|
2011-11-11 16:06:52 +00:00
|
|
|
s = " 2147483647 ";
|
|
|
|
CPPUNIT_ASSERT(util::parseUIntNoThrow(n, s));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((uint32_t)INT32_MAX, n);
|
|
|
|
s = "2147483648";
|
|
|
|
CPPUNIT_ASSERT(!util::parseUIntNoThrow(n, s));
|
2011-11-03 09:51:31 +00:00
|
|
|
s = "-1";
|
2011-11-11 16:06:52 +00:00
|
|
|
CPPUNIT_ASSERT(!util::parseUIntNoThrow(n, s));
|
2010-10-09 16:58:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UtilTest::testParseLLIntNoThrow()
|
|
|
|
{
|
2011-11-03 09:51:31 +00:00
|
|
|
std::string s;
|
2010-10-09 16:58:58 +00:00
|
|
|
int64_t n;
|
2011-11-03 09:51:31 +00:00
|
|
|
s = " 9223372036854775807 ";
|
2011-11-11 16:06:52 +00:00
|
|
|
CPPUNIT_ASSERT(util::parseLLIntNoThrow(n, s));
|
2010-10-09 16:58:58 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)INT64_MAX, n);
|
2011-11-03 09:51:31 +00:00
|
|
|
s = "9223372036854775808";
|
2011-11-11 16:06:52 +00:00
|
|
|
CPPUNIT_ASSERT(!util::parseLLIntNoThrow(n, s));
|
2011-11-03 09:51:31 +00:00
|
|
|
s = "-9223372036854775808";
|
2011-11-11 16:06:52 +00:00
|
|
|
CPPUNIT_ASSERT(util::parseLLIntNoThrow(n, s));
|
2010-10-09 16:58:58 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)INT64_MIN, n);
|
2011-11-03 09:51:31 +00:00
|
|
|
s = "-9223372036854775809";
|
2011-11-11 16:06:52 +00:00
|
|
|
CPPUNIT_ASSERT(!util::parseLLIntNoThrow(n, s));
|
2010-10-09 16:58:58 +00:00
|
|
|
}
|
|
|
|
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
void UtilTest::testToString_binaryStream()
|
|
|
|
{
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<DiskWriter> dw(new ByteArrayDiskWriter());
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string data(16*1024+256, 'a');
|
2009-05-04 07:50:38 +00:00
|
|
|
dw->initAndOpenFile();
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
dw->writeData((const unsigned char*)data.c_str(), data.size(), 0);
|
|
|
|
|
2009-10-22 15:09:00 +00:00
|
|
|
std::string readData = util::toString(dw);
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(data, readData);
|
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-02-24 09:43:31 +00:00
|
|
|
void UtilTest::testItos()
|
|
|
|
{
|
|
|
|
{
|
2008-03-09 12:24:01 +00:00
|
|
|
int i = 0;
|
2009-10-22 15:09:00 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("0"), util::itos(i));
|
2008-02-24 09:43:31 +00:00
|
|
|
}
|
|
|
|
{
|
2008-03-09 12:24:01 +00:00
|
|
|
int i = 100;
|
2009-10-22 15:09:00 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("100"), util::itos(i, true));
|
2008-02-24 09:43:31 +00:00
|
|
|
}
|
|
|
|
{
|
2008-03-09 12:24:01 +00:00
|
|
|
int i = 100;
|
2009-10-22 15:09:00 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("100"), util::itos(i));
|
2008-02-24 09:43:31 +00:00
|
|
|
}
|
|
|
|
{
|
2008-03-09 12:24:01 +00:00
|
|
|
int i = 12345;
|
2009-10-22 15:09:00 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("12,345"), util::itos(i, true));
|
2008-02-24 09:43:31 +00:00
|
|
|
}
|
|
|
|
{
|
2008-03-09 12:24:01 +00:00
|
|
|
int i = 12345;
|
2009-10-22 15:09:00 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("12345"), util::itos(i));
|
2008-02-24 09:43:31 +00:00
|
|
|
}
|
|
|
|
{
|
2008-03-09 12:24:01 +00:00
|
|
|
int i = -12345;
|
2009-10-22 15:09:00 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("-12,345"), util::itos(i, true));
|
2008-02-24 09:43:31 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
int64_t i = INT64_MAX;
|
2010-03-05 14:38:49 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("9,223,372,036,854,775,807"),
|
|
|
|
util::itos(i, true));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
int64_t i = INT64_MIN;
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("-9,223,372,036,854,775,808"),
|
|
|
|
util::itos(i, true));
|
|
|
|
}
|
2008-02-24 09:43:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UtilTest::testUitos()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint16_t i = 12345;
|
2009-10-22 15:09:00 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("12345"), util::uitos(i));
|
2008-02-24 09:43:31 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
int16_t i = -12345;
|
2009-10-22 15:09:00 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/.-,+"), util::uitos(i));
|
2008-02-24 09:43:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-24 07:55:34 +00:00
|
|
|
void UtilTest::testNtoh64()
|
|
|
|
{
|
|
|
|
uint64_t x = 0xff00ff00ee00ee00LL;
|
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
CPPUNIT_ASSERT_EQUAL(x, ntoh64(x));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(x, hton64(x));
|
|
|
|
#else // !WORDS_BIGENDIAN
|
|
|
|
uint64_t y = 0x00ee00ee00ff00ffLL;
|
|
|
|
CPPUNIT_ASSERT_EQUAL(y, ntoh64(x));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(x, hton64(y));
|
|
|
|
#endif // !WORDS_BIGENDIAN
|
|
|
|
}
|
|
|
|
|
2010-03-07 14:24:21 +00:00
|
|
|
void UtilTest::testPercentEncode()
|
2008-11-27 15:29:15 +00:00
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT_EQUAL
|
|
|
|
(std::string("%3A%2F%3F%23%5B%5D%40%21%25%26%27%28%29%2A%2B%2C%3B%3D"),
|
2010-03-07 14:24:21 +00:00
|
|
|
util::percentEncode(":/?#[]@!%&'()*+,;="));
|
2008-11-27 15:29:15 +00:00
|
|
|
|
|
|
|
std::string unreserved =
|
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
"abcdefghijklmnopqrstuvwxyz"
|
|
|
|
"0123456789"
|
|
|
|
"-._~";
|
2010-03-07 14:24:21 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(unreserved, util::percentEncode(unreserved));
|
2008-11-27 15:29:15 +00:00
|
|
|
|
2010-03-07 14:24:21 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("1%5EA%20"), util::percentEncode("1^A "));
|
2008-11-27 15:29:15 +00:00
|
|
|
}
|
|
|
|
|
2009-01-25 09:58:40 +00:00
|
|
|
void UtilTest::testHtmlEscape()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2<>"'util"),
|
2010-01-05 16:01:46 +00:00
|
|
|
util::htmlEscape("aria2<>\"'util"));
|
2009-01-25 09:58:40 +00:00
|
|
|
}
|
|
|
|
|
2009-03-04 15:53:56 +00:00
|
|
|
void UtilTest::testJoinPath()
|
|
|
|
{
|
|
|
|
const std::string dir1dir2file[] = { "dir1", "dir2", "file" };
|
|
|
|
CPPUNIT_ASSERT_EQUAL
|
|
|
|
(std::string("dir1/dir2/file"),
|
2010-03-25 13:51:10 +00:00
|
|
|
util::joinPath(vbegin(dir1dir2file), vend(dir1dir2file)));
|
2009-03-04 15:53:56 +00:00
|
|
|
|
|
|
|
const std::string dirparentfile[] = { "dir", "..", "file" };
|
|
|
|
CPPUNIT_ASSERT_EQUAL
|
|
|
|
(std::string("file"),
|
2010-03-25 13:51:10 +00:00
|
|
|
util::joinPath(vbegin(dirparentfile), vend(dirparentfile)));
|
2009-03-04 15:53:56 +00:00
|
|
|
|
|
|
|
const std::string dirparentparentfile[] = { "dir", "..", "..", "file" };
|
|
|
|
CPPUNIT_ASSERT_EQUAL
|
|
|
|
(std::string("file"),
|
2010-03-25 13:51:10 +00:00
|
|
|
util::joinPath(vbegin(dirparentparentfile), vend(dirparentparentfile)));
|
2009-03-04 15:53:56 +00:00
|
|
|
|
|
|
|
const std::string dirdotfile[] = { "dir", ".", "file" };
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("dir/file"),
|
2010-03-25 13:51:10 +00:00
|
|
|
util::joinPath(vbegin(dirdotfile), vend(dirdotfile)));
|
2009-03-04 15:53:56 +00:00
|
|
|
|
|
|
|
const std::string empty[] = {};
|
2009-10-22 15:09:00 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), util::joinPath(&empty[0], &empty[0]));
|
2009-03-04 15:53:56 +00:00
|
|
|
|
|
|
|
const std::string parentdot[] = { "..", "." };
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""),
|
2010-03-25 13:51:10 +00:00
|
|
|
util::joinPath(vbegin(parentdot), vend(parentdot)));
|
2009-03-04 15:53:56 +00:00
|
|
|
}
|
|
|
|
|
2009-03-07 03:10:53 +00:00
|
|
|
void UtilTest::testParseIndexPath()
|
|
|
|
{
|
2011-11-01 15:18:39 +00:00
|
|
|
std::pair<size_t, std::string> p = util::parseIndexPath("1=foo");
|
2009-03-07 03:10:53 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, p.first);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo"), p.second);
|
|
|
|
try {
|
2009-10-22 15:09:00 +00:00
|
|
|
util::parseIndexPath("1X=foo");
|
2009-03-07 03:10:53 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(Exception& e) {
|
|
|
|
// success
|
|
|
|
}
|
|
|
|
try {
|
2009-10-22 15:09:00 +00:00
|
|
|
util::parseIndexPath("1=");
|
2009-03-07 03:10:53 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(Exception& e) {
|
|
|
|
// success
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-01 15:18:39 +00:00
|
|
|
void UtilTest::testCreateIndexPaths()
|
2009-03-07 03:10:53 +00:00
|
|
|
{
|
|
|
|
std::stringstream in
|
|
|
|
("1=/tmp/myfile\n"
|
|
|
|
"100=/myhome/mypicture.png\n");
|
2011-11-01 15:18:39 +00:00
|
|
|
std::vector<std::pair<size_t, std::string> > m = util::createIndexPaths(in);
|
2009-03-07 03:10:53 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, m.size());
|
2011-11-01 15:18:39 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, m[0].first);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile"), m[0].second);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)100, m[1].first);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/myhome/mypicture.png"), m[1].second);
|
2009-03-07 03:10:53 +00:00
|
|
|
}
|
|
|
|
|
2009-10-22 14:43:42 +00:00
|
|
|
void UtilTest::testGenerateRandomData()
|
|
|
|
{
|
|
|
|
unsigned char data1[20];
|
|
|
|
util::generateRandomData(data1, sizeof(data1));
|
|
|
|
unsigned char data2[20];
|
|
|
|
util::generateRandomData(data2, sizeof(data2));
|
|
|
|
CPPUNIT_ASSERT(memcmp(data1, data2, sizeof(data1)) != 0);
|
|
|
|
}
|
|
|
|
|
2009-11-22 14:30:51 +00:00
|
|
|
void UtilTest::testFromHex()
|
|
|
|
{
|
|
|
|
std::string src;
|
|
|
|
std::string dest;
|
|
|
|
|
|
|
|
src = "0011fF";
|
2011-11-05 09:05:23 +00:00
|
|
|
dest = util::fromHex(src.begin(), src.end());
|
2009-11-22 14:30:51 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, dest.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((char)0x00, dest[0]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((char)0x11, dest[1]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((char)0xff, dest[2]);
|
|
|
|
|
|
|
|
src = "0011f";
|
2011-11-05 09:05:23 +00:00
|
|
|
CPPUNIT_ASSERT(util::fromHex(src.begin(), src.end()).empty());
|
2009-11-22 14:30:51 +00:00
|
|
|
|
|
|
|
src = "001g";
|
2011-11-05 09:05:23 +00:00
|
|
|
CPPUNIT_ASSERT(util::fromHex(src.begin(), src.end()).empty());
|
2009-11-22 14:30:51 +00:00
|
|
|
}
|
|
|
|
|
2009-11-29 06:43:38 +00:00
|
|
|
void UtilTest::testParsePrioritizePieceRange()
|
|
|
|
{
|
|
|
|
// piece index
|
|
|
|
// 0 1 2 3 4 5 6 7
|
|
|
|
// | | | |
|
|
|
|
// file1 | | |
|
|
|
|
// | | |
|
|
|
|
// file2 | |
|
|
|
|
// file3 |
|
|
|
|
// | |
|
|
|
|
// file4 |
|
|
|
|
size_t pieceLength = 1024;
|
|
|
|
std::vector<SharedHandle<FileEntry> > entries(4, SharedHandle<FileEntry>());
|
|
|
|
entries[0].reset(new FileEntry("file1", 1024, 0));
|
|
|
|
entries[1].reset(new FileEntry("file2",2560,entries[0]->getLastOffset()));
|
|
|
|
entries[2].reset(new FileEntry("file3",0,entries[1]->getLastOffset()));
|
|
|
|
entries[3].reset(new FileEntry("file4",3584,entries[2]->getLastOffset()));
|
|
|
|
|
|
|
|
std::vector<size_t> result;
|
2009-12-06 11:35:45 +00:00
|
|
|
util::parsePrioritizePieceRange(result, "head=1", entries, pieceLength);
|
2009-11-29 06:43:38 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, result.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, result[0]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, result[1]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, result[2]);
|
|
|
|
result.clear();
|
2009-12-06 11:35:45 +00:00
|
|
|
util::parsePrioritizePieceRange(result, "tail=1", entries, pieceLength);
|
2009-11-29 06:43:38 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, result.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, result[0]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, result[1]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)6, result[2]);
|
|
|
|
result.clear();
|
|
|
|
util::parsePrioritizePieceRange(result, "head=1K", entries, pieceLength);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)4, result.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, result[0]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, result[1]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, result[2]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)4, result[3]);
|
|
|
|
result.clear();
|
2009-12-07 12:49:19 +00:00
|
|
|
util::parsePrioritizePieceRange(result, "head", entries, pieceLength, 1024);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)4, result.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, result[0]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, result[1]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, result[2]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)4, result[3]);
|
|
|
|
result.clear();
|
2009-11-29 06:43:38 +00:00
|
|
|
util::parsePrioritizePieceRange(result, "tail=1K", entries, pieceLength);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)4, result.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, result[0]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, result[1]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, result[2]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)6, result[3]);
|
|
|
|
result.clear();
|
2009-12-07 12:49:19 +00:00
|
|
|
util::parsePrioritizePieceRange(result, "tail", entries, pieceLength, 1024);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)4, result.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, result[0]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, result[1]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, result[2]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)6, result[3]);
|
|
|
|
result.clear();
|
2009-12-06 11:35:45 +00:00
|
|
|
util::parsePrioritizePieceRange(result, "head=1,tail=1", entries, pieceLength);
|
2009-11-29 06:43:38 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)4, result.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, result[0]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, result[1]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, result[2]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)6, result[3]);
|
|
|
|
result.clear();
|
2009-12-07 12:49:19 +00:00
|
|
|
util::parsePrioritizePieceRange(result, "head=300M,tail=300M",
|
2010-01-05 16:01:46 +00:00
|
|
|
entries, pieceLength);
|
2009-11-29 06:43:38 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)7, result.size());
|
|
|
|
for(size_t i = 0; i < 7; ++i) {
|
|
|
|
CPPUNIT_ASSERT_EQUAL(i, result[i]);
|
|
|
|
}
|
|
|
|
result.clear();
|
|
|
|
util::parsePrioritizePieceRange(result, "", entries, pieceLength);
|
|
|
|
CPPUNIT_ASSERT(result.empty());
|
|
|
|
}
|
|
|
|
|
2010-01-11 14:01:20 +00:00
|
|
|
void UtilTest::testApplyDir()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("./pred"), util::applyDir("", "pred"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/pred"), util::applyDir("/", "pred"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("./pred"), util::applyDir(".", "pred"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/dl/pred"), util::applyDir("/dl", "pred"));
|
|
|
|
}
|
|
|
|
|
2010-01-11 14:32:20 +00:00
|
|
|
void UtilTest::testFixTaintedBasename()
|
|
|
|
{
|
2010-10-02 08:20:10 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("a%2Fb"), util::fixTaintedBasename("a/b"));
|
2010-02-27 10:06:40 +00:00
|
|
|
#ifdef __MINGW32__
|
2010-10-02 08:20:10 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("a%5Cb"), util::fixTaintedBasename("a\\b"));
|
2010-02-27 10:06:40 +00:00
|
|
|
#else // !__MINGW32__
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("a\\b"), util::fixTaintedBasename("a\\b"));
|
|
|
|
#endif // !__MINGW32__
|
2010-01-11 14:32:20 +00:00
|
|
|
}
|
|
|
|
|
2010-01-28 14:25:16 +00:00
|
|
|
void UtilTest::testIsNumericHost()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT(util::isNumericHost("192.168.0.1"));
|
|
|
|
CPPUNIT_ASSERT(!util::isNumericHost("aria2.sf.net"));
|
|
|
|
CPPUNIT_ASSERT(util::isNumericHost("::1"));
|
|
|
|
}
|
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void UtilTest::testDetectDirTraversal()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT(util::detectDirTraversal("/foo"));
|
|
|
|
CPPUNIT_ASSERT(util::detectDirTraversal("./foo"));
|
|
|
|
CPPUNIT_ASSERT(util::detectDirTraversal("../foo"));
|
|
|
|
CPPUNIT_ASSERT(util::detectDirTraversal("foo/../bar"));
|
|
|
|
CPPUNIT_ASSERT(util::detectDirTraversal("foo/./bar"));
|
|
|
|
CPPUNIT_ASSERT(util::detectDirTraversal("foo/."));
|
|
|
|
CPPUNIT_ASSERT(util::detectDirTraversal("foo/.."));
|
|
|
|
CPPUNIT_ASSERT(util::detectDirTraversal("."));
|
|
|
|
CPPUNIT_ASSERT(util::detectDirTraversal(".."));
|
|
|
|
CPPUNIT_ASSERT(util::detectDirTraversal("/"));
|
|
|
|
CPPUNIT_ASSERT(util::detectDirTraversal("foo/"));
|
2010-02-27 10:06:40 +00:00
|
|
|
CPPUNIT_ASSERT(util::detectDirTraversal("\t"));
|
2010-02-25 14:40:18 +00:00
|
|
|
CPPUNIT_ASSERT(!util::detectDirTraversal("foo/bar"));
|
|
|
|
CPPUNIT_ASSERT(!util::detectDirTraversal("foo"));
|
|
|
|
}
|
|
|
|
|
2010-02-27 10:06:40 +00:00
|
|
|
void UtilTest::testEscapePath()
|
|
|
|
{
|
2010-10-02 08:20:10 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo%00bar%00%01"),
|
2010-02-27 10:06:40 +00:00
|
|
|
util::escapePath(std::string("foo")+(char)0x00+
|
|
|
|
std::string("bar")+(char)0x00+
|
|
|
|
(char)0x01));
|
|
|
|
#ifdef __MINGW32__
|
2010-10-02 08:20:10 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo%5Cbar"), util::escapePath("foo\\bar"));
|
2010-02-27 10:06:40 +00:00
|
|
|
#else // !__MINGW32__
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("foo\\bar"), util::escapePath("foo\\bar"));
|
|
|
|
#endif // !__MINGW32__
|
|
|
|
}
|
|
|
|
|
2011-10-19 14:14:13 +00:00
|
|
|
void UtilTest::testInSameCidrBlock()
|
2010-03-19 08:56:17 +00:00
|
|
|
{
|
2011-10-19 14:14:13 +00:00
|
|
|
CPPUNIT_ASSERT(util::inSameCidrBlock("192.168.128.1", "192.168.0.1", 16));
|
|
|
|
CPPUNIT_ASSERT(!util::inSameCidrBlock("192.168.128.1", "192.168.0.1", 17));
|
2010-03-19 08:56:17 +00:00
|
|
|
|
2011-10-19 14:14:13 +00:00
|
|
|
CPPUNIT_ASSERT(util::inSameCidrBlock("192.168.0.1", "192.168.0.1", 32));
|
|
|
|
CPPUNIT_ASSERT(!util::inSameCidrBlock("192.168.0.1", "192.168.0.0", 32));
|
2010-03-19 08:56:17 +00:00
|
|
|
|
2011-10-19 14:14:13 +00:00
|
|
|
CPPUNIT_ASSERT(util::inSameCidrBlock("192.168.0.1", "10.0.0.1", 0));
|
2010-03-19 08:56:17 +00:00
|
|
|
|
2011-10-19 14:14:13 +00:00
|
|
|
CPPUNIT_ASSERT(util::inSameCidrBlock("2001:db8::2:1", "2001:db0::2:2", 28));
|
|
|
|
CPPUNIT_ASSERT(!util::inSameCidrBlock("2001:db8::2:1", "2001:db0::2:2", 29));
|
2010-03-19 08:56:17 +00:00
|
|
|
|
2011-10-19 14:14:13 +00:00
|
|
|
CPPUNIT_ASSERT(!util::inSameCidrBlock("2001:db8::2:1", "192.168.0.1", 8));
|
2010-03-19 08:56:17 +00:00
|
|
|
}
|
|
|
|
|
2010-10-02 07:54:43 +00:00
|
|
|
void UtilTest::testIsUtf8String()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT(util::isUtf8("ascii"));
|
|
|
|
// "Hello World" in Japanese UTF-8
|
|
|
|
CPPUNIT_ASSERT(util::isUtf8
|
2011-11-05 09:05:23 +00:00
|
|
|
(fromHex("e38193e38293e381abe381a1e381afe4b896e7958c")));
|
2010-10-02 07:54:43 +00:00
|
|
|
// "World" in Shift_JIS
|
2011-11-05 09:05:23 +00:00
|
|
|
CPPUNIT_ASSERT(!util::isUtf8(fromHex("90a28a")+"E"));
|
2010-10-02 07:54:43 +00:00
|
|
|
// UTF8-2
|
2011-11-05 09:05:23 +00:00
|
|
|
CPPUNIT_ASSERT(util::isUtf8(fromHex("c280")));
|
|
|
|
CPPUNIT_ASSERT(util::isUtf8(fromHex("dfbf")));
|
2010-10-02 07:54:43 +00:00
|
|
|
// UTF8-3
|
2011-11-05 09:05:23 +00:00
|
|
|
CPPUNIT_ASSERT(util::isUtf8(fromHex("e0a080")));
|
|
|
|
CPPUNIT_ASSERT(util::isUtf8(fromHex("e0bf80")));
|
|
|
|
CPPUNIT_ASSERT(util::isUtf8(fromHex("e18080")));
|
|
|
|
CPPUNIT_ASSERT(util::isUtf8(fromHex("ec8080")));
|
|
|
|
CPPUNIT_ASSERT(util::isUtf8(fromHex("ed8080")));
|
|
|
|
CPPUNIT_ASSERT(util::isUtf8(fromHex("ed9f80")));
|
|
|
|
CPPUNIT_ASSERT(util::isUtf8(fromHex("ee8080")));
|
|
|
|
CPPUNIT_ASSERT(util::isUtf8(fromHex("ef8080")));
|
2010-10-02 07:54:43 +00:00
|
|
|
// UTF8-4
|
2011-11-05 09:05:23 +00:00
|
|
|
CPPUNIT_ASSERT(util::isUtf8(fromHex("f0908080")));
|
|
|
|
CPPUNIT_ASSERT(util::isUtf8(fromHex("f0bf8080")));
|
|
|
|
CPPUNIT_ASSERT(util::isUtf8(fromHex("f1808080")));
|
|
|
|
CPPUNIT_ASSERT(util::isUtf8(fromHex("f3808080")));
|
|
|
|
CPPUNIT_ASSERT(util::isUtf8(fromHex("f4808080")));
|
|
|
|
CPPUNIT_ASSERT(util::isUtf8(fromHex("f48f8080")));
|
2010-10-02 07:54:43 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT(util::isUtf8(""));
|
2011-11-05 09:05:23 +00:00
|
|
|
CPPUNIT_ASSERT(!util::isUtf8(fromHex("00")));
|
2010-10-02 07:54:43 +00:00
|
|
|
}
|
|
|
|
|
2011-07-26 14:41:21 +00:00
|
|
|
void UtilTest::testNextParam()
|
|
|
|
{
|
|
|
|
std::string s1 = " :a : b=c :d=b::::g::";
|
|
|
|
std::pair<std::string::iterator, bool> r;
|
|
|
|
std::string name, value;
|
|
|
|
r = util::nextParam(name, value, s1.begin(), s1.end(), ':');
|
|
|
|
CPPUNIT_ASSERT(r.second);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("a"), name);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(), value);
|
|
|
|
|
|
|
|
r = util::nextParam(name, value, r.first, s1.end(), ':');
|
|
|
|
CPPUNIT_ASSERT(r.second);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("b"), name);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("c"), value);
|
|
|
|
|
|
|
|
r = util::nextParam(name, value, r.first, s1.end(), ':');
|
|
|
|
CPPUNIT_ASSERT(r.second);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("d"), name);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("b"), value);
|
|
|
|
|
|
|
|
r = util::nextParam(name, value, r.first, s1.end(), ':');
|
|
|
|
CPPUNIT_ASSERT(r.second);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("g"), name);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(), value);
|
|
|
|
|
|
|
|
std::string s2 = "";
|
|
|
|
r = util::nextParam(name, value, s2.begin(), s2.end(), ':');
|
|
|
|
CPPUNIT_ASSERT(!r.second);
|
|
|
|
|
|
|
|
std::string s3 = " ";
|
|
|
|
r = util::nextParam(name, value, s3.begin(), s3.end(), ':');
|
|
|
|
CPPUNIT_ASSERT(!r.second);
|
|
|
|
|
|
|
|
std::string s4 = ":::";
|
|
|
|
r = util::nextParam(name, value, s4.begin(), s4.end(), ':');
|
|
|
|
CPPUNIT_ASSERT(!r.second);
|
|
|
|
}
|
|
|
|
|
2011-10-28 15:16:46 +00:00
|
|
|
void UtilTest::testNoProxyDomainMatch()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT(util::noProxyDomainMatch("localhost", "localhost"));
|
|
|
|
CPPUNIT_ASSERT(util::noProxyDomainMatch("192.168.0.1", "192.168.0.1"));
|
|
|
|
CPPUNIT_ASSERT(util::noProxyDomainMatch("www.example.org", ".example.org"));
|
|
|
|
CPPUNIT_ASSERT(!util::noProxyDomainMatch("www.example.org", "example.org"));
|
|
|
|
CPPUNIT_ASSERT(!util::noProxyDomainMatch("192.168.0.1", "0.1"));
|
|
|
|
CPPUNIT_ASSERT(!util::noProxyDomainMatch("example.org", "example.com"));
|
|
|
|
CPPUNIT_ASSERT(!util::noProxyDomainMatch("example.org", "www.example.org"));
|
|
|
|
}
|
|
|
|
|
2011-11-12 12:27:24 +00:00
|
|
|
void UtilTest::testInPrivateAddress()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT(!util::inPrivateAddress("localhost"));
|
|
|
|
CPPUNIT_ASSERT(util::inPrivateAddress("192.168.0.1"));
|
|
|
|
// Only checks prefix..
|
|
|
|
CPPUNIT_ASSERT(util::inPrivateAddress("10."));
|
|
|
|
CPPUNIT_ASSERT(!util::inPrivateAddress("172."));
|
|
|
|
CPPUNIT_ASSERT(!util::inPrivateAddress("172.15.0.0"));
|
|
|
|
CPPUNIT_ASSERT(util::inPrivateAddress("172.16.0.0"));
|
|
|
|
CPPUNIT_ASSERT(util::inPrivateAddress("172.31.0.0"));
|
|
|
|
CPPUNIT_ASSERT(!util::inPrivateAddress("172.32.0.0"));
|
|
|
|
}
|
|
|
|
|
2011-11-13 11:59:15 +00:00
|
|
|
void UtilTest::testSecfmt()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("0s"), util::secfmt(0));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("1s"), util::secfmt(1));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("9s"), util::secfmt(9));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("10s"), util::secfmt(10));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("1m"), util::secfmt(60));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("1m59s"), util::secfmt(119));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("2m"), util::secfmt(120));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("59m59s"), util::secfmt(3599));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("1h"), util::secfmt(3600));
|
|
|
|
}
|
|
|
|
|
2012-03-28 14:28:22 +00:00
|
|
|
void UtilTest::testTlsHostnameMatch()
|
|
|
|
{
|
2012-03-30 14:49:14 +00:00
|
|
|
CPPUNIT_ASSERT(util::tlsHostnameMatch("Foo.com", "foo.com"));
|
2012-03-28 14:28:22 +00:00
|
|
|
CPPUNIT_ASSERT(util::tlsHostnameMatch("*.a.com", "foo.a.com"));
|
|
|
|
CPPUNIT_ASSERT(!util::tlsHostnameMatch("*.a.com", "bar.foo.a.com"));
|
2012-03-30 14:49:14 +00:00
|
|
|
CPPUNIT_ASSERT(!util::tlsHostnameMatch("f*.com", "foo.com"));
|
|
|
|
CPPUNIT_ASSERT(!util::tlsHostnameMatch("*.com", "bar.com"));
|
|
|
|
CPPUNIT_ASSERT(util::tlsHostnameMatch("com", "com"));
|
|
|
|
CPPUNIT_ASSERT(!util::tlsHostnameMatch("foo.*", "foo.com"));
|
|
|
|
CPPUNIT_ASSERT(util::tlsHostnameMatch("a.foo.com", "A.foo.com"));
|
|
|
|
CPPUNIT_ASSERT(!util::tlsHostnameMatch("a.foo.com", "b.foo.com"));
|
|
|
|
CPPUNIT_ASSERT(!util::tlsHostnameMatch("*a.foo.com", "a.foo.com"));
|
|
|
|
CPPUNIT_ASSERT(util::tlsHostnameMatch("*a.foo.com", "ba.foo.com"));
|
|
|
|
CPPUNIT_ASSERT(!util::tlsHostnameMatch("a*.foo.com", "a.foo.com"));
|
|
|
|
CPPUNIT_ASSERT(util::tlsHostnameMatch("a*.foo.com", "ab.foo.com"));
|
|
|
|
CPPUNIT_ASSERT(!util::tlsHostnameMatch("foo.b*z.foo.com", "foo.baz.foo.com"));
|
|
|
|
CPPUNIT_ASSERT(util::tlsHostnameMatch("B*z.foo.com", "bAZ.Foo.com"));
|
|
|
|
CPPUNIT_ASSERT(!util::tlsHostnameMatch("b*z.foo.com", "bz.foo.com"));
|
|
|
|
CPPUNIT_ASSERT(!util::tlsHostnameMatch("*", "foo"));
|
|
|
|
CPPUNIT_ASSERT(!util::tlsHostnameMatch("*", ""));
|
2012-03-28 14:28:22 +00:00
|
|
|
CPPUNIT_ASSERT(util::tlsHostnameMatch("", ""));
|
2012-03-30 14:49:14 +00:00
|
|
|
CPPUNIT_ASSERT(!util::tlsHostnameMatch("xn--*.a.b", "xn--c.a.b"));
|
2012-03-28 14:28:22 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|