Explorar el Código

2008-05-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Fixed compile error when configured with --without-gnutls
	--without-openssl
	* src/main.cc
	* test/DefaultBtProgressInfoFileTest.cc
	* test/SegmentManTest.cc
Tatsuhiro Tsujikawa hace 17 años
padre
commit
a70a747c23
Se han modificado 4 ficheros con 126 adiciones y 106 borrados
  1. 9 1
      ChangeLog
  2. 1 0
      src/main.cc
  3. 114 100
      test/DefaultBtProgressInfoFileTest.cc
  4. 2 5
      test/SegmentManTest.cc

+ 9 - 1
ChangeLog

@@ -1,3 +1,11 @@
+2008-05-20  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Fixed compile error when configured with --without-gnutls
+	--without-openssl
+	* src/main.cc
+	* test/DefaultBtProgressInfoFileTest.cc
+	* test/SegmentManTest.cc
+
 2008-05-20  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Fixed compile error with OpenSSL.
@@ -10838,4 +10846,4 @@
 2006-02-17  Tatsuhiro Tsujikawa <tsujikawa at rednoah dot com>
 	
 	* Release 0.1.0
-	
+	

+ 1 - 0
src/main.cc

@@ -66,6 +66,7 @@
 #include "NullStatCalc.h"
 #include "StringFormat.h"
 #include "A2STR.h"
+#include "RecoverableException.h"
 #ifdef ENABLE_METALINK
 # include "MetalinkHelper.h"
 # include "Metalink2RequestGroup.h"

+ 114 - 100
test/DefaultBtProgressInfoFileTest.cc

@@ -2,7 +2,9 @@
 #include "Option.h"
 #include "Util.h"
 #include "Exception.h"
+#ifdef ENABLE_BITTORRENT
 #include "MockBtContext.h"
+#endif // ENABLE_BITTORRENT
 #include "MockPeerStorage.h"
 #include "MockPieceStorage.h"
 #include "BtRuntime.h"
@@ -19,15 +21,21 @@ namespace aria2 {
 class DefaultBtProgressInfoFileTest:public CppUnit::TestFixture {
 
   CPPUNIT_TEST_SUITE(DefaultBtProgressInfoFileTest);
+#ifdef ENABLE_BITTORRENT
   CPPUNIT_TEST(testSave);
-  CPPUNIT_TEST(testSave_nonBt);
   CPPUNIT_TEST(testLoad);
+#endif // ENABLE_BITTORRENT
+  CPPUNIT_TEST(testSave_nonBt);
   CPPUNIT_TEST(testLoad_nonBt);
   CPPUNIT_TEST(testLoad_nonBt_pieceLengthShorter);
   CPPUNIT_TEST(testUpdateFilename);
   CPPUNIT_TEST_SUITE_END();
 private:
+
+#ifdef ENABLE_BITTORRENT
   SharedHandle<MockBtContext> _btContext;
+#endif // ENABLE_BITTORRENT
+
   SharedHandle<MockPieceStorage> _pieceStorage;
   SharedHandle<Option> _option;
   SharedHandle<BitfieldMan> _bitfield;
@@ -38,22 +46,23 @@ public:
    
   void initializeMembers(int32_t pieceLength, int64_t totalLength)
   {
-    static unsigned char infoHash[] = {
-      0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa,
-      0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff,
-    };
-  
     _option.reset(new Option());
     _option->put(PREF_DIR, ".");
 
-    _btContext.reset(new MockBtContext());
-    _btContext->setInfoHash(infoHash);
-
     _bitfield.reset(new BitfieldMan(pieceLength, totalLength));
 
     _pieceStorage.reset(new MockPieceStorage());
     _pieceStorage->setBitfield(_bitfield.get());
 
+#ifdef ENABLE_BITTORRENT
+    static unsigned char infoHash[] = {
+      0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa,
+      0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff,
+    };
+  
+    _btContext.reset(new MockBtContext());
+    _btContext->setInfoHash(infoHash);
+
     SharedHandle<MockPeerStorage> peerStorage(new MockPeerStorage());
 
     SharedHandle<BtRuntime> btRuntime(new BtRuntime());
@@ -66,6 +75,7 @@ public:
 				    peerStorage);
     BtRegistry::registerBtRuntime(_btContext->getInfoHashAsString(),
 				  btRuntime);
+#endif // ENABLE_BITTORRENT
   }
 
   void tearDown()
@@ -86,6 +96,8 @@ public:
 
 CPPUNIT_TEST_SUITE_REGISTRATION(DefaultBtProgressInfoFileTest);
 
+#ifdef ENABLE_BITTORRENT
+
 void DefaultBtProgressInfoFileTest::testLoad()
 {
   initializeMembers(1024, 81920);
@@ -130,78 +142,19 @@ void DefaultBtProgressInfoFileTest::testLoad()
   CPPUNIT_ASSERT_EQUAL((size_t)512, piece2->getLength());
 }
 
-void DefaultBtProgressInfoFileTest::testLoad_nonBt()
-{
-  initializeMembers(1024, 81920);
-
-  SharedHandle<SingleFileDownloadContext> dctx
-    (new SingleFileDownloadContext(1024, 81920, "load-nonBt"));
-  
-  DefaultBtProgressInfoFile infoFile(dctx, _pieceStorage, _option.get());
-  CPPUNIT_ASSERT_EQUAL(std::string("./load-nonBt.aria2"), infoFile.getFilename());
-  infoFile.load();
-
-  // check the contents of objects
-
-  // bitfield
-  CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffe"),
-		       Util::toHex(_bitfield->getBitfield(), _bitfield->getBitfieldLength()));
-
-  // the number of in-flight pieces
-  CPPUNIT_ASSERT_EQUAL((size_t)2,
-		       _pieceStorage->countInFlightPiece());
-
-  // piece index 1
-  std::deque<SharedHandle<Piece> > inFlightPieces;
-  _pieceStorage->getInFlightPieces(inFlightPieces);
-
-  SharedHandle<Piece> piece1 = inFlightPieces[0];
-  CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getIndex());
-  CPPUNIT_ASSERT_EQUAL((size_t)1024, piece1->getLength());
-  CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getBitfieldLength());
-  CPPUNIT_ASSERT_EQUAL(std::string("00"), Util::toHex(piece1->getBitfield(),
-						 piece1->getBitfieldLength()));
-
-  // piece index 2
-  SharedHandle<Piece> piece2 = inFlightPieces[1];
-  CPPUNIT_ASSERT_EQUAL((size_t)2, piece2->getIndex());
-  CPPUNIT_ASSERT_EQUAL((size_t)512, piece2->getLength());
-
-}
-
-void DefaultBtProgressInfoFileTest::testLoad_nonBt_pieceLengthShorter()
-{
-  initializeMembers(512, 81920);
-  _option->put(PREF_ALLOW_PIECE_LENGTH_CHANGE, V_TRUE);
-
-  SharedHandle<SingleFileDownloadContext> dctx
-    (new SingleFileDownloadContext(512, 81920, "load-nonBt"));
-
-  DefaultBtProgressInfoFile infoFile(dctx, _pieceStorage, _option.get());
-  CPPUNIT_ASSERT_EQUAL(std::string("./load-nonBt.aria2"), infoFile.getFilename());
-  infoFile.load();
-
-  // check the contents of objects
-
-  // bitfield
-  CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffffffffffffffffffffffc"),
-		       Util::toHex(_bitfield->getBitfield(), _bitfield->getBitfieldLength()));
-
-  // the number of in-flight pieces
-  CPPUNIT_ASSERT_EQUAL((size_t)0,
-		       _pieceStorage->countInFlightPiece());
-}
-
-void DefaultBtProgressInfoFileTest::testSave_nonBt()
+void DefaultBtProgressInfoFileTest::testSave()
 {
   initializeMembers(1024, 81920);
 
-  SharedHandle<SingleFileDownloadContext> dctx
-    (new SingleFileDownloadContext(1024, 81920, "save-temp"));
-
+  _btContext->setName("save-temp");
+  _btContext->setPieceLength(1024);
+  _btContext->setTotalLength(81920);
   _bitfield->setAllBit();
   _bitfield->unsetBit(79);
   _pieceStorage->setCompletedLength(80896);
+  TransferStat stat;
+  stat.setAllTimeUploadLength(1024);
+  dynamic_pointer_cast<MockPeerStorage>(PEER_STORAGE(_btContext))->setStat(stat);
 
   SharedHandle<Piece> p1(new Piece(1, 1024));
   SharedHandle<Piece> p2(new Piece(2, 512));
@@ -210,11 +163,11 @@ void DefaultBtProgressInfoFileTest::testSave_nonBt()
   inFlightPieces.push_back(p2);
   _pieceStorage->addInFlightPiece(inFlightPieces);
   
-  DefaultBtProgressInfoFile infoFile(dctx, _pieceStorage, _option.get());
+  DefaultBtProgressInfoFile infoFile(_btContext, _pieceStorage, _option.get());
   CPPUNIT_ASSERT_EQUAL(std::string("./save-temp.aria2"), infoFile.getFilename());
 
   infoFile.save();
-  
+
   // read and validate
   std::ifstream in(infoFile.getFilename().c_str());
 
@@ -226,23 +179,28 @@ void DefaultBtProgressInfoFileTest::testSave_nonBt()
 
   unsigned char extension[4];
   in.read((char*)extension, sizeof(extension));
-  CPPUNIT_ASSERT_EQUAL(std::string("00000000"), Util::toHex(extension, sizeof(extension)));
+  CPPUNIT_ASSERT_EQUAL(std::string("00000001"), Util::toHex(extension, sizeof(extension)));
 
   uint32_t infoHashLength;
   in.read(reinterpret_cast<char*>(&infoHashLength), sizeof(infoHashLength));
-  CPPUNIT_ASSERT_EQUAL((uint32_t)0, infoHashLength);
+  CPPUNIT_ASSERT_EQUAL((uint32_t)20, infoHashLength);
+
+  unsigned char infoHashRead[20];
+  in.read((char*)infoHashRead, sizeof(infoHashRead));
+  CPPUNIT_ASSERT_EQUAL(std::string("112233445566778899aabbccddeeff00ffffffff"),
+		       Util::toHex(infoHashRead, sizeof(infoHashRead)));
 
   uint32_t pieceLength;
   in.read((char*)&pieceLength, sizeof(pieceLength));
   CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength);
-  
+
   uint64_t totalLength;
   in.read((char*)&totalLength, sizeof(totalLength));
   CPPUNIT_ASSERT_EQUAL((uint64_t)81920/* 80*1024 */, totalLength);
 
   uint64_t uploadLength;
   in.read((char*)&uploadLength, sizeof(uploadLength));
-  CPPUNIT_ASSERT_EQUAL((uint64_t)0, uploadLength);
+  CPPUNIT_ASSERT_EQUAL((uint64_t)1024, uploadLength);
 
   uint32_t bitfieldLength;
   in.read((char*)&bitfieldLength, sizeof(bitfieldLength));
@@ -284,21 +242,83 @@ void DefaultBtProgressInfoFileTest::testSave_nonBt()
   in.read((char*)&pieceLength2, sizeof(pieceLength2));
   CPPUNIT_ASSERT_EQUAL((uint32_t)512, pieceLength2);
 
+
 }
 
-void DefaultBtProgressInfoFileTest::testSave()
+#endif // ENABLE_BITTORRENT
+
+void DefaultBtProgressInfoFileTest::testLoad_nonBt()
 {
   initializeMembers(1024, 81920);
 
-  _btContext->setName("save-temp");
-  _btContext->setPieceLength(1024);
-  _btContext->setTotalLength(81920);
+  SharedHandle<SingleFileDownloadContext> dctx
+    (new SingleFileDownloadContext(1024, 81920, "load-nonBt"));
+  
+  DefaultBtProgressInfoFile infoFile(dctx, _pieceStorage, _option.get());
+  CPPUNIT_ASSERT_EQUAL(std::string("./load-nonBt.aria2"), infoFile.getFilename());
+  infoFile.load();
+
+  // check the contents of objects
+
+  // bitfield
+  CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffe"),
+		       Util::toHex(_bitfield->getBitfield(), _bitfield->getBitfieldLength()));
+
+  // the number of in-flight pieces
+  CPPUNIT_ASSERT_EQUAL((size_t)2,
+		       _pieceStorage->countInFlightPiece());
+
+  // piece index 1
+  std::deque<SharedHandle<Piece> > inFlightPieces;
+  _pieceStorage->getInFlightPieces(inFlightPieces);
+
+  SharedHandle<Piece> piece1 = inFlightPieces[0];
+  CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getIndex());
+  CPPUNIT_ASSERT_EQUAL((size_t)1024, piece1->getLength());
+  CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getBitfieldLength());
+  CPPUNIT_ASSERT_EQUAL(std::string("00"), Util::toHex(piece1->getBitfield(),
+						 piece1->getBitfieldLength()));
+
+  // piece index 2
+  SharedHandle<Piece> piece2 = inFlightPieces[1];
+  CPPUNIT_ASSERT_EQUAL((size_t)2, piece2->getIndex());
+  CPPUNIT_ASSERT_EQUAL((size_t)512, piece2->getLength());
+
+}
+
+void DefaultBtProgressInfoFileTest::testLoad_nonBt_pieceLengthShorter()
+{
+  initializeMembers(512, 81920);
+  _option->put(PREF_ALLOW_PIECE_LENGTH_CHANGE, V_TRUE);
+
+  SharedHandle<SingleFileDownloadContext> dctx
+    (new SingleFileDownloadContext(512, 81920, "load-nonBt"));
+
+  DefaultBtProgressInfoFile infoFile(dctx, _pieceStorage, _option.get());
+  CPPUNIT_ASSERT_EQUAL(std::string("./load-nonBt.aria2"), infoFile.getFilename());
+  infoFile.load();
+
+  // check the contents of objects
+
+  // bitfield
+  CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffffffffffffffffffffffc"),
+		       Util::toHex(_bitfield->getBitfield(), _bitfield->getBitfieldLength()));
+
+  // the number of in-flight pieces
+  CPPUNIT_ASSERT_EQUAL((size_t)0,
+		       _pieceStorage->countInFlightPiece());
+}
+
+void DefaultBtProgressInfoFileTest::testSave_nonBt()
+{
+  initializeMembers(1024, 81920);
+
+  SharedHandle<SingleFileDownloadContext> dctx
+    (new SingleFileDownloadContext(1024, 81920, "save-temp"));
+
   _bitfield->setAllBit();
   _bitfield->unsetBit(79);
   _pieceStorage->setCompletedLength(80896);
-  TransferStat stat;
-  stat.setAllTimeUploadLength(1024);
-  dynamic_pointer_cast<MockPeerStorage>(PEER_STORAGE(_btContext))->setStat(stat);
 
   SharedHandle<Piece> p1(new Piece(1, 1024));
   SharedHandle<Piece> p2(new Piece(2, 512));
@@ -307,11 +327,11 @@ void DefaultBtProgressInfoFileTest::testSave()
   inFlightPieces.push_back(p2);
   _pieceStorage->addInFlightPiece(inFlightPieces);
   
-  DefaultBtProgressInfoFile infoFile(_btContext, _pieceStorage, _option.get());
+  DefaultBtProgressInfoFile infoFile(dctx, _pieceStorage, _option.get());
   CPPUNIT_ASSERT_EQUAL(std::string("./save-temp.aria2"), infoFile.getFilename());
 
   infoFile.save();
-
+  
   // read and validate
   std::ifstream in(infoFile.getFilename().c_str());
 
@@ -323,28 +343,23 @@ void DefaultBtProgressInfoFileTest::testSave()
 
   unsigned char extension[4];
   in.read((char*)extension, sizeof(extension));
-  CPPUNIT_ASSERT_EQUAL(std::string("00000001"), Util::toHex(extension, sizeof(extension)));
+  CPPUNIT_ASSERT_EQUAL(std::string("00000000"), Util::toHex(extension, sizeof(extension)));
 
   uint32_t infoHashLength;
   in.read(reinterpret_cast<char*>(&infoHashLength), sizeof(infoHashLength));
-  CPPUNIT_ASSERT_EQUAL((uint32_t)20, infoHashLength);
-
-  unsigned char infoHashRead[20];
-  in.read((char*)infoHashRead, sizeof(infoHashRead));
-  CPPUNIT_ASSERT_EQUAL(std::string("112233445566778899aabbccddeeff00ffffffff"),
-		       Util::toHex(infoHashRead, sizeof(infoHashRead)));
+  CPPUNIT_ASSERT_EQUAL((uint32_t)0, infoHashLength);
 
   uint32_t pieceLength;
   in.read((char*)&pieceLength, sizeof(pieceLength));
   CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength);
-
+  
   uint64_t totalLength;
   in.read((char*)&totalLength, sizeof(totalLength));
   CPPUNIT_ASSERT_EQUAL((uint64_t)81920/* 80*1024 */, totalLength);
 
   uint64_t uploadLength;
   in.read((char*)&uploadLength, sizeof(uploadLength));
-  CPPUNIT_ASSERT_EQUAL((uint64_t)1024, uploadLength);
+  CPPUNIT_ASSERT_EQUAL((uint64_t)0, uploadLength);
 
   uint32_t bitfieldLength;
   in.read((char*)&bitfieldLength, sizeof(bitfieldLength));
@@ -386,7 +401,6 @@ void DefaultBtProgressInfoFileTest::testSave()
   in.read((char*)&pieceLength2, sizeof(pieceLength2));
   CPPUNIT_ASSERT_EQUAL((uint32_t)512, pieceLength2);
 
-
 }
 
 void DefaultBtProgressInfoFileTest::testUpdateFilename()

+ 2 - 5
test/SegmentManTest.cc

@@ -7,7 +7,6 @@
 #include "DefaultPieceStorage.h"
 #include "Segment.h"
 #include "Option.h"
-#include "MockBtContext.h"
 #include "FileEntry.h"
 #include <cppunit/extensions/HelperMacros.h>
 
@@ -62,10 +61,8 @@ void SegmentManTest::testCompleteSegment()
   Option op;
   size_t pieceLength = 1024*1024;
   uint64_t totalLength = 64*1024*1024;
-  SharedHandle<MockBtContext> dctx(new MockBtContext());
-  dctx->setPieceLength(pieceLength);
-  dctx->setTotalLength(totalLength);
-  dctx->setNumPieces((totalLength+pieceLength-1)/pieceLength);
+  SharedHandle<SingleFileDownloadContext> dctx
+    (new SingleFileDownloadContext(pieceLength, totalLength, "aria2.tar.bz2"));
   SharedHandle<DefaultPieceStorage> ps(new DefaultPieceStorage(dctx, &op));
 
   SegmentMan segmentMan(&op, dctx, ps);