diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2007-11-27 12:27:10 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2007-11-27 12:27:10 +0000 |
| commit | 506bc3db13f6130aca37c1df216a3e8a7967bf99 (patch) | |
| tree | 09f6c0fcd703ad78e3d45eb38810582e8691b276 /test | |
| parent | 9d66150a8396d91d19bbee524243a5f371704929 (diff) | |
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
Diffstat (limited to 'test')
| -rw-r--r-- | test/BtPostDownloadHandlerTest.cc | 47 | ||||
| -rw-r--r-- | test/ByteArrayDiskWriterTest.cc | 45 | ||||
| -rw-r--r-- | test/DefaultBtContextTest.cc | 16 | ||||
| -rw-r--r-- | test/DownloadHandlerFactoryTest.cc | 90 | ||||
| -rw-r--r-- | test/Makefile.am | 1 | ||||
| -rw-r--r-- | test/Makefile.in | 7 | ||||
| -rw-r--r-- | test/MetalinkPostDownloadHandlerTest.cc | 47 | ||||
| -rw-r--r-- | test/RequestGroupManTest.cc | 1 | ||||
| -rw-r--r-- | test/UtilTest.cc | 15 | ||||
| -rw-r--r-- | test/Xml2MetalinkProcessorTest.cc | 24 | ||||
| -rw-r--r-- | test/a2functionalTest.cc | 11 |
11 files changed, 261 insertions, 43 deletions
diff --git a/test/BtPostDownloadHandlerTest.cc b/test/BtPostDownloadHandlerTest.cc index b4228ee2..ec469ee4 100644 --- a/test/BtPostDownloadHandlerTest.cc +++ b/test/BtPostDownloadHandlerTest.cc @@ -2,12 +2,14 @@ #include "BtContext.h" #include "RequestGroup.h" #include "Option.h" +#include "SingleFileDownloadContext.h" #include <cppunit/extensions/HelperMacros.h> class BtPostDownloadHandlerTest:public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(BtPostDownloadHandlerTest); - CPPUNIT_TEST(testCanHandle); + CPPUNIT_TEST(testCanHandle_extension); + CPPUNIT_TEST(testCanHandle_contentType); CPPUNIT_TEST(testGetNextRequestGroups); CPPUNIT_TEST_SUITE_END(); private: @@ -15,26 +17,55 @@ private: public: void setUp() {} - void testCanHandle(); + void testCanHandle_extension(); + void testCanHandle_contentType(); void testGetNextRequestGroups(); }; CPPUNIT_TEST_SUITE_REGISTRATION( BtPostDownloadHandlerTest ); -void BtPostDownloadHandlerTest::testCanHandle() +void BtPostDownloadHandlerTest::testCanHandle_extension() { Option op; - BtPostDownloadHandler handler(&op); - CPPUNIT_ASSERT(!handler.canHandle(".torrent!!")); - CPPUNIT_ASSERT(handler.canHandle(".torrent")); + SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "test.torrent"); + RequestGroup rg(&op, Strings()); + rg.setDownloadContext(dctx); + + BtPostDownloadHandler handler; + + CPPUNIT_ASSERT(handler.canHandle(&rg)); + + dctx->setFilename("test.torrent2"); + CPPUNIT_ASSERT(!handler.canHandle(&rg)); +} + +void BtPostDownloadHandlerTest::testCanHandle_contentType() +{ + Option op; + SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "test"); + dctx->setContentType("application/x-bittorrent"); + RequestGroup rg(&op, Strings()); + rg.setDownloadContext(dctx); + + BtPostDownloadHandler handler; + + CPPUNIT_ASSERT(handler.canHandle(&rg)); + + dctx->setContentType("application/octet-stream"); + CPPUNIT_ASSERT(!handler.canHandle(&rg)); } void BtPostDownloadHandlerTest::testGetNextRequestGroups() { Option op; - BtPostDownloadHandler handler(&op); - RequestGroups groups = handler.getNextRequestGroups("test.torrent"); + SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "test.torrent"); + RequestGroup rg(&op, Strings()); + rg.setDownloadContext(dctx); + rg.initPieceStorage(); + + BtPostDownloadHandler handler; + RequestGroups groups = handler.getNextRequestGroups(&rg); CPPUNIT_ASSERT_EQUAL((size_t)1, groups.size()); BtContextHandle btctx = groups.front()->getDownloadContext(); CPPUNIT_ASSERT(!btctx.isNull()); diff --git a/test/ByteArrayDiskWriterTest.cc b/test/ByteArrayDiskWriterTest.cc index 18ea5e0d..6e12417e 100644 --- a/test/ByteArrayDiskWriterTest.cc +++ b/test/ByteArrayDiskWriterTest.cc @@ -26,41 +26,36 @@ CPPUNIT_TEST_SUITE_REGISTRATION( ByteArrayDiskWriterTest ); void ByteArrayDiskWriterTest::testWriteAndRead() { ByteArrayDiskWriter bw; - string msg1 = "Hello world!"; + string msg1 = "Hello"; bw.writeData((const unsigned char*)msg1.c_str(), msg1.size(), 0); - - char buf[100]; - int32_t c = bw.readData((unsigned char*)buf, sizeof(buf), 0); - buf[c] = '\0'; - - CPPUNIT_ASSERT_EQUAL(msg1, string(buf)); + // write at the end of stream + string msg2 = " World"; + bw.writeData((const unsigned char*)msg2.c_str(), msg2.size(), 5); + // write at the end of stream +1 + string msg3 = "!!"; + bw.writeData((const unsigned char*)msg3.c_str(), msg3.size(), 12); + // write space at the 'hole' + string msg4 = " "; + bw.writeData((const unsigned char*)msg4.c_str(), msg4.size(), 11); - // second call - memset(buf, '\0', sizeof(buf)); - - c = bw.readData((unsigned char*)buf, sizeof(buf), 0); + char buf[100]; + int32_t c = bw.readData((unsigned char*)buf, sizeof(buf), 1); buf[c] = '\0'; - CPPUNIT_ASSERT_EQUAL(msg1, string(buf)); + CPPUNIT_ASSERT_EQUAL(string("ello World !!"), string(buf)); } void ByteArrayDiskWriterTest::testWriteAndRead2() { ByteArrayDiskWriter bw; - string msg1 = "Hello world!"; - bw.writeData((const unsigned char*)msg1.c_str(), msg1.size(), 16); - - char buf[100]; - int32_t c = bw.readData((unsigned char*)buf, sizeof(buf), 16); - buf[c] = '\0'; - - CPPUNIT_ASSERT_EQUAL(msg1, string(buf)); - - // second call - memset(buf, '\0', sizeof(buf)); + string msg1 = "Hello World"; + bw.writeData((const unsigned char*)msg1.c_str(), msg1.size(), 0); + string msg2 = "From Mars"; + bw.writeData((const unsigned char*)msg2.c_str(), msg2.size(), 6); - c = bw.readData((unsigned char*)buf, sizeof(buf), 16); + char buf[100]; + int32_t c = bw.readData((unsigned char*)buf, sizeof(buf), 0); buf[c] = '\0'; - CPPUNIT_ASSERT_EQUAL(msg1, string(buf)); + CPPUNIT_ASSERT_EQUAL(string("Hello From Mars"), string(buf)); } diff --git a/test/DefaultBtContextTest.cc b/test/DefaultBtContextTest.cc index 0a77fb42..41694c17 100644 --- a/test/DefaultBtContextTest.cc +++ b/test/DefaultBtContextTest.cc @@ -28,6 +28,7 @@ class DefaultBtContextTest:public CppUnit::TestFixture { CPPUNIT_TEST(testComputeFastSet); CPPUNIT_TEST(testGetFileEntries_multiFileUrlList); CPPUNIT_TEST(testGetFileEntries_singleFileUrlList); + CPPUNIT_TEST(testLoadFromMemory); CPPUNIT_TEST_SUITE_END(); public: void setUp() { @@ -51,6 +52,7 @@ public: void testComputeFastSet(); void testGetFileEntries_multiFileUrlList(); void testGetFileEntries_singleFileUrlList(); + void testLoadFromMemory(); }; @@ -309,3 +311,17 @@ void DefaultBtContextTest::testGetFileEntries_singleFileUrlList() { CPPUNIT_ASSERT_EQUAL(string("http://localhost/dist/aria2.tar.bz2"), uris1[0]); } + +void DefaultBtContextTest::testLoadFromMemory() +{ + string memory = "d8:announce36:http://aria.rednoah.com/announce.php13:announce-listll16:http://tracker1 el15:http://tracker2el15:http://tracker3ee7:comment17:REDNOAH.COM RULES13:creation datei1123456789e4:infod5:filesld6:lengthi284e4:pathl5:aria23:src6:aria2ceed6:lengthi100e4:pathl19:aria2-0.2.2.tar.bz2eee4:name10:aria2-test12:piece lengthi128e6:pieces60:AAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCee"; + + DefaultBtContext btContext; + btContext.loadFromMemory(memory.c_str(), memory.size(), "default"); + + string correctHash = "248d0a1cd08284299de78d5c1ed359bb46717d8c"; + + CPPUNIT_ASSERT_EQUAL((int32_t)20, btContext.getInfoHashLength()); + CPPUNIT_ASSERT_EQUAL(correctHash, Util::toHex(btContext.getInfoHash(), + btContext.getInfoHashLength())); +} diff --git a/test/DownloadHandlerFactoryTest.cc b/test/DownloadHandlerFactoryTest.cc new file mode 100644 index 00000000..5039045c --- /dev/null +++ b/test/DownloadHandlerFactoryTest.cc @@ -0,0 +1,90 @@ +#include "DownloadHandlerFactory.h" +#include "RequestGroup.h" +#include "Option.h" +#include "SingleFileDownloadContext.h" +#include "MemoryBufferPreDownloadHandler.h" +#include <cppunit/extensions/HelperMacros.h> + +class DownloadHandlerFactoryTest:public CppUnit::TestFixture { + + CPPUNIT_TEST_SUITE(DownloadHandlerFactoryTest); + CPPUNIT_TEST(testGetMetalinkPreDownloadHandler_extension); + CPPUNIT_TEST(testGetMetalinkPreDownloadHandler_contentType); + CPPUNIT_TEST(testGetBtPreDownloadHandler_extension); + CPPUNIT_TEST(testGetBtPreDownloadHandler_contentType); + CPPUNIT_TEST_SUITE_END(); +private: + +public: + void setUp() {} + + void testGetMetalinkPreDownloadHandler_extension(); + void testGetMetalinkPreDownloadHandler_contentType(); + void testGetBtPreDownloadHandler_extension(); + void testGetBtPreDownloadHandler_contentType(); +}; + + +CPPUNIT_TEST_SUITE_REGISTRATION( DownloadHandlerFactoryTest ); + +void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_extension() +{ + Option op; + SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "test.metalink"); + RequestGroup rg(&op, Strings()); + rg.setDownloadContext(dctx); + + PreDownloadHandlerHandle handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler(); + + CPPUNIT_ASSERT(handler->canHandle(&rg)); + + dctx->setFilename("test.metalink2"); + CPPUNIT_ASSERT(!handler->canHandle(&rg)); +} + +void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_contentType() +{ + Option op; + SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "test"); + dctx->setContentType("application/metalink+xml"); + RequestGroup rg(&op, Strings()); + rg.setDownloadContext(dctx); + + PreDownloadHandlerHandle handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler(); + + CPPUNIT_ASSERT(handler->canHandle(&rg)); + + dctx->setContentType("application/octet-stream"); + CPPUNIT_ASSERT(!handler->canHandle(&rg)); +} + +void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_extension() +{ + Option op; + SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "test.torrent"); + RequestGroup rg(&op, Strings()); + rg.setDownloadContext(dctx); + + PreDownloadHandlerHandle handler = DownloadHandlerFactory::getBtPreDownloadHandler(); + + CPPUNIT_ASSERT(handler->canHandle(&rg)); + + dctx->setFilename("test.torrent2"); + CPPUNIT_ASSERT(!handler->canHandle(&rg)); +} + +void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_contentType() +{ + Option op; + SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "test"); + dctx->setContentType("application/x-bittorrent"); + RequestGroup rg(&op, Strings()); + rg.setDownloadContext(dctx); + + PreDownloadHandlerHandle handler = DownloadHandlerFactory::getBtPreDownloadHandler(); + + CPPUNIT_ASSERT(handler->canHandle(&rg)); + + dctx->setContentType("application/octet-stream"); + CPPUNIT_ASSERT(!handler->canHandle(&rg)); +} diff --git a/test/Makefile.am b/test/Makefile.am index a8cf166f..603c350f 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -94,6 +94,7 @@ aria2c_SOURCES += BtAllowedFastMessageTest.cc\ BtRegistryTest.cc\ BtDependencyTest.cc\ BtPostDownloadHandlerTest.cc\ + DownloadHandlerFactoryTest.cc\ TimeSeedCriteriaTest.cc endif # ENABLE_BITTORRENT diff --git a/test/Makefile.in b/test/Makefile.in index 16b05206..012b343a 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -82,6 +82,7 @@ check_PROGRAMS = $(am__EXEEXT_1) @ENABLE_BITTORRENT_TRUE@ BtRegistryTest.cc\ @ENABLE_BITTORRENT_TRUE@ BtDependencyTest.cc\ @ENABLE_BITTORRENT_TRUE@ BtPostDownloadHandlerTest.cc\ +@ENABLE_BITTORRENT_TRUE@ DownloadHandlerFactoryTest.cc\ @ENABLE_BITTORRENT_TRUE@ TimeSeedCriteriaTest.cc @ENABLE_METALINK_TRUE@am__append_3 = MetalinkerTest.cc\ @@ -152,8 +153,8 @@ am__aria2c_SOURCES_DIST = AllTest.cc SequenceTest.cc \ MetaFileUtilTest.cc ByteArrayDiskWriterTest.cc PeerTest.cc \ PeerMessageUtilTest.cc ShareRatioSeedCriteriaTest.cc \ BtRegistryTest.cc BtDependencyTest.cc \ - BtPostDownloadHandlerTest.cc TimeSeedCriteriaTest.cc \ - MetalinkerTest.cc MetalinkEntryTest.cc \ + BtPostDownloadHandlerTest.cc DownloadHandlerFactoryTest.cc \ + TimeSeedCriteriaTest.cc MetalinkerTest.cc MetalinkEntryTest.cc \ Xml2MetalinkProcessorTest.cc Metalink2RequestGroupTest.cc \ MetalinkPostDownloadHandlerTest.cc MetalinkHelperTest.cc @ENABLE_MESSAGE_DIGEST_TRUE@am__objects_1 = \ @@ -198,6 +199,7 @@ am__aria2c_SOURCES_DIST = AllTest.cc SequenceTest.cc \ @ENABLE_BITTORRENT_TRUE@ BtRegistryTest.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ BtDependencyTest.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ BtPostDownloadHandlerTest.$(OBJEXT) \ +@ENABLE_BITTORRENT_TRUE@ DownloadHandlerFactoryTest.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ TimeSeedCriteriaTest.$(OBJEXT) @ENABLE_METALINK_TRUE@am__objects_3 = MetalinkerTest.$(OBJEXT) \ @ENABLE_METALINK_TRUE@ MetalinkEntryTest.$(OBJEXT) \ @@ -544,6 +546,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultPeerStorageTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultPieceStorageTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DictionaryTest.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DownloadHandlerFactoryTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FeatureConfigTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FileEntryTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FileTest.Po@am__quote@ diff --git a/test/MetalinkPostDownloadHandlerTest.cc b/test/MetalinkPostDownloadHandlerTest.cc index 2c711cf1..69caf68b 100644 --- a/test/MetalinkPostDownloadHandlerTest.cc +++ b/test/MetalinkPostDownloadHandlerTest.cc @@ -1,12 +1,14 @@ #include "MetalinkPostDownloadHandler.h" #include "RequestGroup.h" #include "Option.h" +#include "SingleFileDownloadContext.h" #include <cppunit/extensions/HelperMacros.h> class MetalinkPostDownloadHandlerTest:public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(MetalinkPostDownloadHandlerTest); - CPPUNIT_TEST(testCanHandle); + CPPUNIT_TEST(testCanHandle_extension); + CPPUNIT_TEST(testCanHandle_contentType); CPPUNIT_TEST(testGetNextRequestGroups); CPPUNIT_TEST_SUITE_END(); private: @@ -14,26 +16,55 @@ private: public: void setUp() {} - void testCanHandle(); + void testCanHandle_extension(); + void testCanHandle_contentType(); void testGetNextRequestGroups(); }; CPPUNIT_TEST_SUITE_REGISTRATION( MetalinkPostDownloadHandlerTest ); -void MetalinkPostDownloadHandlerTest::testCanHandle() +void MetalinkPostDownloadHandlerTest::testCanHandle_extension() { Option op; - MetalinkPostDownloadHandler handler(&op); - CPPUNIT_ASSERT(!handler.canHandle(".metalink!!")); - CPPUNIT_ASSERT(handler.canHandle(".metalink")); + SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "test.metalink"); + RequestGroup rg(&op, Strings()); + rg.setDownloadContext(dctx); + + MetalinkPostDownloadHandler handler; + + CPPUNIT_ASSERT(handler.canHandle(&rg)); + + dctx->setFilename("test.metalink2"); + CPPUNIT_ASSERT(!handler.canHandle(&rg)); +} + +void MetalinkPostDownloadHandlerTest::testCanHandle_contentType() +{ + Option op; + SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "test"); + dctx->setContentType("application/metalink+xml"); + RequestGroup rg(&op, Strings()); + rg.setDownloadContext(dctx); + + MetalinkPostDownloadHandler handler; + + CPPUNIT_ASSERT(handler.canHandle(&rg)); + + dctx->setContentType("application/octet-stream"); + CPPUNIT_ASSERT(!handler.canHandle(&rg)); } void MetalinkPostDownloadHandlerTest::testGetNextRequestGroups() { Option op; - MetalinkPostDownloadHandler handler(&op); - RequestGroups groups = handler.getNextRequestGroups("test.xml"); + SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "test.xml"); + RequestGroup rg(&op, Strings()); + rg.setDownloadContext(dctx); + rg.initPieceStorage(); + + MetalinkPostDownloadHandler handler; + RequestGroups groups = handler.getNextRequestGroups(&rg); #ifdef ENABLE_BITTORRENT CPPUNIT_ASSERT_EQUAL((size_t)6/* 5 + 1 torrent file download */, groups.size()); #else diff --git a/test/RequestGroupManTest.cc b/test/RequestGroupManTest.cc index 6b88e63b..ef7eb707 100644 --- a/test/RequestGroupManTest.cc +++ b/test/RequestGroupManTest.cc @@ -4,6 +4,7 @@ #include "SingleFileDownloadContext.h" #include "RequestGroup.h" #include "Option.h" +#include "DownloadResult.h" #include <cppunit/extensions/HelperMacros.h> using namespace std; diff --git a/test/UtilTest.cc b/test/UtilTest.cc index 7a92b9e7..4a50ccac 100644 --- a/test/UtilTest.cc +++ b/test/UtilTest.cc @@ -2,6 +2,7 @@ #include "FixedNumberRandomizer.h" #include "DlAbortEx.h" #include "BitfieldMan.h" +#include "ByteArrayDiskWriter.h" #include <string> #include <cppunit/extensions/HelperMacros.h> @@ -36,6 +37,7 @@ class UtilTest:public CppUnit::TestFixture { CPPUNIT_TEST(testParseIntRange_invalidRange); CPPUNIT_TEST(testParseInt); CPPUNIT_TEST(testParseLLInt); + CPPUNIT_TEST(testToString_binaryStream); CPPUNIT_TEST_SUITE_END(); private: @@ -69,6 +71,7 @@ public: void testParseIntRange_invalidRange(); void testParseInt(); void testParseLLInt(); + void testToString_binaryStream(); }; @@ -580,3 +583,15 @@ void UtilTest::testParseLLInt() delete e; } } + +void UtilTest::testToString_binaryStream() +{ + DiskWriterHandle dw = new ByteArrayDiskWriter(); + string data = string(16*1024+256, 'a'); + dw->initAndOpenFile("dummy"); + dw->writeData((const unsigned char*)data.c_str(), data.size(), 0); + + string readData = Util::toString(dw); + + CPPUNIT_ASSERT_EQUAL(data, readData); +} diff --git a/test/Xml2MetalinkProcessorTest.cc b/test/Xml2MetalinkProcessorTest.cc index ddafb861..8e4d0444 100644 --- a/test/Xml2MetalinkProcessorTest.cc +++ b/test/Xml2MetalinkProcessorTest.cc @@ -1,5 +1,6 @@ #include "Xml2MetalinkProcessor.h" #include "Exception.h" +#include "DefaultDiskWriter.h" #include <cppunit/extensions/HelperMacros.h> using namespace std; @@ -8,6 +9,7 @@ class Xml2MetalinkProcessorTest:public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(Xml2MetalinkProcessorTest); CPPUNIT_TEST(testParseFile); + CPPUNIT_TEST(testParseFromBinaryStream); CPPUNIT_TEST_SUITE_END(); private: @@ -20,6 +22,7 @@ public: } void testParseFile(); + void testParseFromBinaryStream(); }; @@ -112,3 +115,24 @@ void Xml2MetalinkProcessorTest::testParseFile() { delete e; } } + +void Xml2MetalinkProcessorTest::testParseFromBinaryStream() { + Xml2MetalinkProcessor proc; + try { + DefaultDiskWriterHandle dw = new DefaultDiskWriter(); + dw->openExistingFile("test.xml"); + + MetalinkerHandle metalinker = proc.parseFromBinaryStream(dw); + + dw->closeFile(); + + MetalinkEntries::iterator entryItr = metalinker->entries.begin(); + MetalinkEntryHandle entry1 = *entryItr; + CPPUNIT_ASSERT_EQUAL(string("aria2-0.5.2.tar.bz2"), entry1->getPath()); + } catch(Exception* e) { + cerr << *e; + CPPUNIT_FAIL(e->getMsg()); + delete e; + throw; + } +} diff --git a/test/a2functionalTest.cc b/test/a2functionalTest.cc index 0a936e82..c021b1a2 100644 --- a/test/a2functionalTest.cc +++ b/test/a2functionalTest.cc @@ -10,10 +10,12 @@ class a2functionalTest:public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(a2functionalTest); CPPUNIT_TEST(testMemFunSh); CPPUNIT_TEST(testAdopt2nd); + CPPUNIT_TEST(testArrayLength); CPPUNIT_TEST_SUITE_END(); public: void testMemFunSh(); void testAdopt2nd(); + void testArrayLength(); class Greeting { public: @@ -62,3 +64,12 @@ void a2functionalTest::testAdopt2nd() CPPUNIT_ASSERT_EQUAL(string("A Japanese said:HAROO WAARUDO"), adopt2nd(plus<string>(), mem_fun_sh(&Greeting::sayGreeting))("A Japanese said:", greeting)); } + +void a2functionalTest::testArrayLength() +{ + int64_t ia[] = { 1, 2, 3, 4, 5 }; + int64_t zeroLengthArray[] = {}; + + CPPUNIT_ASSERT_EQUAL((size_t)5, arrayLength(ia)); + CPPUNIT_ASSERT_EQUAL((size_t)0, arrayLength(zeroLengthArray)); +} |
