summaryrefslogtreecommitdiff
path: root/test/DefaultBtAnnounceTest.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-01-04 12:31:49 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-01-04 12:31:49 +0000
commitda4d9092b28863d7592cae17f1e97161bda91064 (patch)
treefa26343a61f7747c2eab920c2158976c20afe015 /test/DefaultBtAnnounceTest.cc
parent853a8ef6aa33c8116fda5db7ad6fd4af4b82933e (diff)
2008-01-04 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Fixed segmentation fault when bad torrent metainfo is parsed. Added dynamic_cast properly to detect the misconfiguration of metainfo and then throw exception or skip it. * src/DefaultBtContext.{h, cc} * test/DefaultBtContextTest.cc * src/AnnounceList.cc * src/CompactPeerListProcessor.cc * src/message.h * src/DefaultBtAnnounce.{h, cc} * test/DefaultBtAnnounceTest.cc * src/BencodeVisitor.cc
Diffstat (limited to 'test/DefaultBtAnnounceTest.cc')
-rw-r--r--test/DefaultBtAnnounceTest.cc50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/DefaultBtAnnounceTest.cc b/test/DefaultBtAnnounceTest.cc
index e859ffcb..da07d0cf 100644
--- a/test/DefaultBtAnnounceTest.cc
+++ b/test/DefaultBtAnnounceTest.cc
@@ -21,6 +21,9 @@ class DefaultBtAnnounceTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testIsAllAnnounceFailed);
CPPUNIT_TEST(testURLOrderInStoppedEvent);
CPPUNIT_TEST(testURLOrderInCompletedEvent);
+ CPPUNIT_TEST(testProcessAnnounceResponse_malformed);
+ CPPUNIT_TEST(testProcessAnnounceResponse_failureReason);
+ CPPUNIT_TEST(testProcessAnnounceResponse);
CPPUNIT_TEST_SUITE_END();
private:
MockBtContextHandle _btContext;
@@ -78,6 +81,9 @@ public:
void testIsAllAnnounceFailed();
void testURLOrderInStoppedEvent();
void testURLOrderInCompletedEvent();
+ void testProcessAnnounceResponse_malformed();
+ void testProcessAnnounceResponse_failureReason();
+ void testProcessAnnounceResponse();
};
@@ -275,3 +281,47 @@ void DefaultBtAnnounceTest::testURLOrderInCompletedEvent()
btAnnounce.announceSuccess();
}
+
+void DefaultBtAnnounceTest::testProcessAnnounceResponse_malformed()
+{
+ try {
+ string res = "i123e";
+ DefaultBtAnnounce(new MockBtContext(), _option).processAnnounceResponse(res.c_str(), res.size());
+ CPPUNIT_FAIL("exception must be thrown.");
+ } catch(Exception* e) {
+ cerr << *e << endl;
+ delete e;
+ }
+}
+
+void DefaultBtAnnounceTest::testProcessAnnounceResponse_failureReason()
+{
+ try {
+ string res = "d14:failure reason11:hello worlde";
+ DefaultBtAnnounce(new MockBtContext(), _option).processAnnounceResponse(res.c_str(), res.size());
+ CPPUNIT_FAIL("exception must be thrown.");
+ } catch(Exception* e) {
+ cerr << *e << endl;
+ delete e;
+ }
+}
+
+void DefaultBtAnnounceTest::testProcessAnnounceResponse()
+{
+ string res = "d"
+ "15:warning message11:hello world"
+ "10:tracker id3:foo"
+ "8:intervali3000e"
+ "12:min intervali1800e"
+ "8:completei100e"
+ "10:incompletei200e"
+ "e";
+
+ DefaultBtAnnounce an(new MockBtContext(), _option);
+ an.processAnnounceResponse(res.c_str(), res.size());
+ CPPUNIT_ASSERT_EQUAL(string("foo"), an.getTrackerID());
+ CPPUNIT_ASSERT_EQUAL(3000, an.getInterval());
+ CPPUNIT_ASSERT_EQUAL(1800, an.getMinInterval());
+ CPPUNIT_ASSERT_EQUAL(100, an.getComplete());
+ CPPUNIT_ASSERT_EQUAL(200, an.getIncomplete());
+}