diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-11-25 15:49:20 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-11-25 15:49:20 +0000 |
| commit | 46d9f2de6373007895e84f577aa8ae413cd4e861 (patch) | |
| tree | 5ab170329d937cb4fea2f04c76675062b832d0f5 /test | |
| parent | a26a44cb8ed28d59930bfaa4553fbd1fa7fbcb4d (diff) | |
2009-11-26 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed the bug which causes segmentation fault with tellWaiting
XML-RPC method when BitTorrent download is waiting. The key of
BtRegistry is changed from info hash to GID, because it is
registered per RequestGroup, not info hash.
* src/BtRegistry.cc
* src/BtRegistry.h
* src/BtSetup.cc
* src/ConsoleStatCalc.cc
* src/InitiatorMSEHandshakeCommand.cc
* src/PeerInitiateConnectionCommand.cc
* src/PeerInteractionCommand.cc
* src/PeerInteractionCommand.h
* src/PeerReceiveHandshakeCommand.cc
* src/RequestGroup.cc
* src/XmlRpcMethodImpl.cc
* test/BtRegistryTest.cc
* test/XmlRpcMethodTest.cc
Diffstat (limited to 'test')
| -rw-r--r-- | test/BtRegistryTest.cc | 42 | ||||
| -rw-r--r-- | test/XmlRpcMethodTest.cc | 11 |
2 files changed, 42 insertions, 11 deletions
diff --git a/test/BtRegistryTest.cc b/test/BtRegistryTest.cc index cbb19f68..79912913 100644 --- a/test/BtRegistryTest.cc +++ b/test/BtRegistryTest.cc @@ -10,6 +10,7 @@ #include "MockBtProgressInfoFile.h" #include "BtRuntime.h" #include "FileEntry.h" +#include "bittorrent_helper.h" namespace aria2 { @@ -17,6 +18,7 @@ class BtRegistryTest:public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(BtRegistryTest); CPPUNIT_TEST(testGetDownloadContext); + CPPUNIT_TEST(testGetDownloadContext_infoHash); CPPUNIT_TEST(testGetAllDownloadContext); CPPUNIT_TEST(testRemove); CPPUNIT_TEST(testRemoveAll); @@ -25,6 +27,7 @@ private: public: void testGetDownloadContext(); + void testGetDownloadContext_infoHash(); void testGetAllDownloadContext(); void testRemove(); void testRemoveAll(); @@ -36,12 +39,12 @@ CPPUNIT_TEST_SUITE_REGISTRATION( BtRegistryTest ); void BtRegistryTest::testGetDownloadContext() { BtRegistry btRegistry; - CPPUNIT_ASSERT(btRegistry.getDownloadContext("test").isNull()); + CPPUNIT_ASSERT(btRegistry.getDownloadContext(1).isNull()); SharedHandle<DownloadContext> dctx(new DownloadContext()); BtObject btObject; btObject._downloadContext = dctx; - btRegistry.put("test", btObject); - CPPUNIT_ASSERT_EQUAL(dctx.get(), btRegistry.getDownloadContext("test").get()); + btRegistry.put(1, btObject); + CPPUNIT_ASSERT_EQUAL(dctx.get(), btRegistry.getDownloadContext(1).get()); } static void addTwoDownloadContext(BtRegistry& btRegistry) @@ -52,8 +55,27 @@ static void addTwoDownloadContext(BtRegistry& btRegistry) btObject1._downloadContext = dctx1; BtObject btObject2; btObject2._downloadContext = dctx2; - btRegistry.put("ctx1", btObject1); - btRegistry.put("ctx2", btObject2); + btRegistry.put(1, btObject1); + btRegistry.put(2, btObject2); +} + +void BtRegistryTest::testGetDownloadContext_infoHash() +{ + BtRegistry btRegistry; + addTwoDownloadContext(btRegistry); + BDE attrs1 = BDE::dict(); + attrs1[bittorrent::INFO_HASH] = std::string("hash1"); + BDE attrs2 = BDE::dict(); + attrs2[bittorrent::INFO_HASH] = std::string("hash2"); + btRegistry.getDownloadContext(1)->setAttribute + (bittorrent::BITTORRENT, attrs1); + btRegistry.getDownloadContext(2)->setAttribute + (bittorrent::BITTORRENT, attrs2); + + CPPUNIT_ASSERT(!btRegistry.getDownloadContext("hash1").isNull()); + CPPUNIT_ASSERT(btRegistry.getDownloadContext("hash1").get() == + btRegistry.getDownloadContext(1).get()); + CPPUNIT_ASSERT(btRegistry.getDownloadContext("not exists").isNull()); } void BtRegistryTest::testGetAllDownloadContext() @@ -70,9 +92,9 @@ void BtRegistryTest::testRemove() { BtRegistry btRegistry; addTwoDownloadContext(btRegistry); - CPPUNIT_ASSERT(btRegistry.remove("ctx1")); - CPPUNIT_ASSERT(btRegistry.get("ctx1").isNull()); - CPPUNIT_ASSERT(!btRegistry.get("ctx2").isNull()); + CPPUNIT_ASSERT(btRegistry.remove(1)); + CPPUNIT_ASSERT(btRegistry.get(1).isNull()); + CPPUNIT_ASSERT(!btRegistry.get(2).isNull()); } void BtRegistryTest::testRemoveAll() @@ -80,8 +102,8 @@ void BtRegistryTest::testRemoveAll() BtRegistry btRegistry; addTwoDownloadContext(btRegistry); btRegistry.removeAll(); - CPPUNIT_ASSERT(btRegistry.get("ctx1").isNull()); - CPPUNIT_ASSERT(btRegistry.get("ctx2").isNull()); + CPPUNIT_ASSERT(btRegistry.get(1).isNull()); + CPPUNIT_ASSERT(btRegistry.get(2).isNull()); } } // namespace aria2 diff --git a/test/XmlRpcMethodTest.cc b/test/XmlRpcMethodTest.cc index 39461a2e..b923d069 100644 --- a/test/XmlRpcMethodTest.cc +++ b/test/XmlRpcMethodTest.cc @@ -515,12 +515,21 @@ static void addUri(const std::string& uri, CPPUNIT_ASSERT_EQUAL(0, m.execute(req, e.get())._code); } +static void addTorrent +(const std::string& torrentFile, const SharedHandle<DownloadEngine>& e) +{ + AddTorrentXmlRpcMethod m; + XmlRpcRequest req("aria2.addTorrent", BDE::list()); + req._params << BDE(readFile(torrentFile)); + XmlRpcResponse res = m.execute(req, e.get()); +} + void XmlRpcMethodTest::testTellWaiting() { addUri("http://1/", _e); addUri("http://2/", _e); addUri("http://3/", _e); - addUri("http://4/", _e); + addTorrent("single.torrent", _e); TellWaitingXmlRpcMethod m; XmlRpcRequest req("aria2.tellWaiting", BDE::list()); |
