2008-08-07 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Fixed memory leak in test code
	* test/AnnounceListTest.cc
	* test/DefaultPeerListProcessorTest.cc
	* test/DefaultPeerStorageTest.cc
	* test/MetaFileUtilTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-08-07 14:21:50 +00:00
parent 817aee5dc8
commit fcb7254bf5
5 changed files with 45 additions and 22 deletions

View File

@ -1,3 +1,11 @@
2008-08-07 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Fixed memory leak in test code
* test/AnnounceListTest.cc
* test/DefaultPeerListProcessorTest.cc
* test/DefaultPeerStorageTest.cc
* test/MetaFileUtilTest.cc
2008-08-07 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> 2008-08-07 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Fixed wrong argument passing to BitfieldMan::isBitSet() Fixed wrong argument passing to BitfieldMan::isBitSet()

View File

@ -1,7 +1,7 @@
#include "AnnounceList.h" #include "AnnounceList.h"
#include "MetaFileUtil.h" #include "MetaFileUtil.h"
#include "Exception.h" #include "Exception.h"
#include "Dictionary.h" #include "List.h"
#include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/HelperMacros.h>
namespace aria2 { namespace aria2 {
@ -43,11 +43,12 @@ CPPUNIT_TEST_SUITE_REGISTRATION( AnnounceListTest );
void AnnounceListTest::testSingleElementList() { void AnnounceListTest::testSingleElementList() {
std::string peersString = "ll8:tracker1el8:tracker2el8:tracker3ee"; std::string peersString = "ll8:tracker1el8:tracker2el8:tracker3ee";
Dictionary* announces = (Dictionary*)MetaFileUtil::bdecoding(peersString); SharedHandle<List> announces
(dynamic_cast<List*>(MetaFileUtil::bdecoding(peersString)));
// ANNOUNCE_LIST // ANNOUNCE_LIST
// [ [ tracker1 ], [ tracker2 ], [ tracker3 ] ] // [ [ tracker1 ], [ tracker2 ], [ tracker3 ] ]
AnnounceList announceList(announces); AnnounceList announceList(announces.get());
CPPUNIT_ASSERT(!announceList.allTiersFailed()); CPPUNIT_ASSERT(!announceList.allTiersFailed());
std::string url = announceList.getAnnounce(); std::string url = announceList.getAnnounce();
@ -89,10 +90,12 @@ void AnnounceListTest::testSingleElementList() {
void AnnounceListTest::testMultiElementList() { void AnnounceListTest::testMultiElementList() {
std::string peersString = "ll8:tracker18:tracker28:tracker3ee"; std::string peersString = "ll8:tracker18:tracker28:tracker3ee";
Dictionary* announces = (Dictionary*)MetaFileUtil::bdecoding(peersString); SharedHandle<List> announces
(dynamic_cast<List*>(MetaFileUtil::bdecoding(peersString)));
// ANNOUNCE_LIST // ANNOUNCE_LIST
// [ [ tracker1, tracker2, tracker3 ] ] // [ [ tracker1, tracker2, tracker3 ] ]
AnnounceList announceList(announces); AnnounceList announceList(announces.get());
CPPUNIT_ASSERT(!announceList.allTiersFailed()); CPPUNIT_ASSERT(!announceList.allTiersFailed());
std::string url = announceList.getAnnounce(); std::string url = announceList.getAnnounce();
@ -121,11 +124,12 @@ void AnnounceListTest::testMultiElementList() {
void AnnounceListTest::testSingleAndMulti() { void AnnounceListTest::testSingleAndMulti() {
std::string peersString = "ll8:tracker18:tracker2el8:tracker3ee"; std::string peersString = "ll8:tracker18:tracker2el8:tracker3ee";
Dictionary* announces = (Dictionary*)MetaFileUtil::bdecoding(peersString); SharedHandle<List> announces
(dynamic_cast<List*>(MetaFileUtil::bdecoding(peersString)));
// ANNOUNCE_LIST // ANNOUNCE_LIST
// [ [ tracker1, tracker2 ], [ tracker3 ] ] // [ [ tracker1, tracker2 ], [ tracker3 ] ]
AnnounceList announceList(announces); AnnounceList announceList(announces.get());
std::string url = announceList.getAnnounce(); std::string url = announceList.getAnnounce();
CPPUNIT_ASSERT_EQUAL(std::string("tracker1"), url); CPPUNIT_ASSERT_EQUAL(std::string("tracker1"), url);
@ -147,20 +151,22 @@ void AnnounceListTest::testSingleAndMulti() {
void AnnounceListTest::testNoGroup() { void AnnounceListTest::testNoGroup() {
std::string peersString = "llee"; std::string peersString = "llee";
Dictionary* announces = (Dictionary*)MetaFileUtil::bdecoding(peersString); SharedHandle<List> announces
(dynamic_cast<List*>(MetaFileUtil::bdecoding(peersString)));
AnnounceList announceList(announces); AnnounceList announceList(announces.get());
CPPUNIT_ASSERT(announceList.countTier() == 0); CPPUNIT_ASSERT(announceList.countTier() == 0);
} }
void AnnounceListTest::testNextEventIfAfterStarted() { void AnnounceListTest::testNextEventIfAfterStarted() {
std::string peersString = "ll8:tracker1ee"; std::string peersString = "ll8:tracker1ee";
Dictionary* announces = (Dictionary*)MetaFileUtil::bdecoding(peersString); SharedHandle<List> announces
(dynamic_cast<List*>(MetaFileUtil::bdecoding(peersString)));
// ANNOUNCE_LIST // ANNOUNCE_LIST
// [ [ tracker1 ] ] // [ [ tracker1 ] ]
AnnounceList announceList(announces); AnnounceList announceList(announces.get());
announceList.setEvent(AnnounceTier::STOPPED); announceList.setEvent(AnnounceTier::STOPPED);
announceList.announceFailure(); announceList.announceFailure();
announceList.resetTier(); announceList.resetTier();
@ -176,11 +182,12 @@ void AnnounceListTest::testNextEventIfAfterStarted() {
void AnnounceListTest::testEvent() { void AnnounceListTest::testEvent() {
std::string peersString = "ll8:tracker1el8:tracker2el8:tracker3ee"; std::string peersString = "ll8:tracker1el8:tracker2el8:tracker3ee";
Dictionary* announces = (Dictionary*)MetaFileUtil::bdecoding(peersString); SharedHandle<List> announces
(dynamic_cast<List*>(MetaFileUtil::bdecoding(peersString)));
// ANNOUNCE_LIST // ANNOUNCE_LIST
// [ [ tracker1 ], [ tracker2 ], [ tracker3 ] ] // [ [ tracker1 ], [ tracker2 ], [ tracker3 ] ]
AnnounceList announceList(announces); AnnounceList announceList(announces.get());
announceList.setEvent(AnnounceTier::STOPPED); announceList.setEvent(AnnounceTier::STOPPED);
announceList.announceSuccess(); announceList.announceSuccess();
@ -200,11 +207,12 @@ void AnnounceListTest::testEvent() {
void AnnounceListTest::testCountStoppedAllowedTier() { void AnnounceListTest::testCountStoppedAllowedTier() {
std::string peersString = "ll8:tracker1el8:tracker2el8:tracker3ee"; std::string peersString = "ll8:tracker1el8:tracker2el8:tracker3ee";
Dictionary* announces = (Dictionary*)MetaFileUtil::bdecoding(peersString); SharedHandle<List> announces
(dynamic_cast<List*>(MetaFileUtil::bdecoding(peersString)));
// ANNOUNCE_LIST // ANNOUNCE_LIST
// [ [ tracker1 ], [ tracker2 ], [ tracker3 ] ] // [ [ tracker1 ], [ tracker2 ], [ tracker3 ] ]
AnnounceList announceList(announces); AnnounceList announceList(announces.get());
CPPUNIT_ASSERT_EQUAL((size_t)0, announceList.countStoppedAllowedTier()); CPPUNIT_ASSERT_EQUAL((size_t)0, announceList.countStoppedAllowedTier());
announceList.setEvent(AnnounceTier::STARTED); announceList.setEvent(AnnounceTier::STARTED);
@ -227,11 +235,12 @@ void AnnounceListTest::testCountStoppedAllowedTier() {
void AnnounceListTest::testCountCompletedAllowedTier() { void AnnounceListTest::testCountCompletedAllowedTier() {
std::string peersString = "ll8:tracker1el8:tracker2el8:tracker3ee"; std::string peersString = "ll8:tracker1el8:tracker2el8:tracker3ee";
Dictionary* announces = (Dictionary*)MetaFileUtil::bdecoding(peersString); SharedHandle<List> announces
(dynamic_cast<List*>(MetaFileUtil::bdecoding(peersString)));
// ANNOUNCE_LIST // ANNOUNCE_LIST
// [ [ tracker1 ], [ tracker2 ], [ tracker3 ] ] // [ [ tracker1 ], [ tracker2 ], [ tracker3 ] ]
AnnounceList announceList(announces); AnnounceList announceList(announces.get());
CPPUNIT_ASSERT_EQUAL((size_t)0, announceList.countCompletedAllowedTier()); CPPUNIT_ASSERT_EQUAL((size_t)0, announceList.countCompletedAllowedTier());
announceList.setEvent(AnnounceTier::STARTED); announceList.setEvent(AnnounceTier::STARTED);

View File

@ -30,7 +30,8 @@ void DefaultPeerListProcessorTest::testExtractPeer() {
DefaultPeerListProcessor proc; DefaultPeerListProcessor proc;
std::string peersString = "d5:peersld2:ip11:192.168.0.17:peer id20:aria2-000000000000004:porti2006eeee"; std::string peersString = "d5:peersld2:ip11:192.168.0.17:peer id20:aria2-000000000000004:porti2006eeee";
Dictionary* dic = (Dictionary*)MetaFileUtil::bdecoding(peersString); SharedHandle<Dictionary> dic
(dynamic_cast<Dictionary*>(MetaFileUtil::bdecoding(peersString)));
CPPUNIT_ASSERT(proc.canHandle(dic->get("peers"))); CPPUNIT_ASSERT(proc.canHandle(dic->get("peers")));
@ -46,7 +47,8 @@ void DefaultPeerListProcessorTest::testExtract2Peers() {
DefaultPeerListProcessor proc; DefaultPeerListProcessor proc;
std::string peersString = "d5:peersld2:ip11:192.168.0.17:peer id20:aria2-000000000000004:porti2006eed2:ip11:192.168.0.27:peer id20:aria2-000000000000004:porti2007eeee"; std::string peersString = "d5:peersld2:ip11:192.168.0.17:peer id20:aria2-000000000000004:porti2006eed2:ip11:192.168.0.27:peer id20:aria2-000000000000004:porti2007eeee";
Dictionary* dic = (Dictionary*)MetaFileUtil::bdecoding(peersString); SharedHandle<Dictionary> dic
(dynamic_cast<Dictionary*>(MetaFileUtil::bdecoding(peersString)));
std::deque<SharedHandle<Peer> > peers; std::deque<SharedHandle<Peer> > peers;
proc.extractPeer(peers, dic->get("peers")); proc.extractPeer(peers, dic->get("peers"));

View File

@ -35,6 +35,10 @@ public:
btRuntime.reset(new BtRuntime()); btRuntime.reset(new BtRuntime());
} }
void tearDown() {
delete option;
}
void testCountPeer(); void testCountPeer();
void testDeleteUnusedPeer(); void testDeleteUnusedPeer();
void testAddPeer(); void testAddPeer();

View File

@ -28,9 +28,9 @@ public:
CPPUNIT_TEST_SUITE_REGISTRATION( MetaFileUtilTest ); CPPUNIT_TEST_SUITE_REGISTRATION( MetaFileUtilTest );
void MetaFileUtilTest::testParseMetaFile() { void MetaFileUtilTest::testParseMetaFile() {
MetaEntry* entry = MetaFileUtil::parseMetaFile("test.torrent"); SharedHandle<MetaEntry> entry(MetaFileUtil::parseMetaFile("test.torrent"));
Dictionary* d = dynamic_cast<Dictionary*>(entry); SharedHandle<Dictionary> d = dynamic_pointer_cast<Dictionary>(entry);
CPPUNIT_ASSERT(d != NULL); CPPUNIT_ASSERT(!d.isNull());
} }
void MetaFileUtilTest::testBdecoding() { void MetaFileUtilTest::testBdecoding() {