MockPieceStorage.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #ifndef _D_MOCK_PIECE_STORAGE_H_
  2. #define _D_MOCK_PIECE_STORAGE_H_
  3. #include "PieceStorage.h"
  4. #include "BitfieldMan.h"
  5. #include "Piece.h"
  6. #include "DiskAdaptor.h"
  7. class MockPieceStorage : public PieceStorage {
  8. private:
  9. int64_t totalLength;
  10. int64_t filteredTotalLength;
  11. int64_t completedLength;
  12. int64_t filteredCompletedLength;
  13. BitfieldMan* bitfieldMan;
  14. bool selectiveDownloadingMode;
  15. bool endGame;
  16. DiskAdaptorHandle diskAdaptor;
  17. Integers pieceLengthList;
  18. Pieces inFlightPieces;
  19. public:
  20. MockPieceStorage():diskAdaptor(0) {}
  21. virtual ~MockPieceStorage() {}
  22. virtual bool hasMissingPiece(const PeerHandle& peer) {
  23. return false;
  24. }
  25. virtual PieceHandle getMissingPiece(const PeerHandle& peer) {
  26. return new Piece();
  27. }
  28. virtual PieceHandle getMissingFastPiece(const PeerHandle& peer) {
  29. return new Piece();
  30. }
  31. virtual PieceHandle getMissingPiece()
  32. {
  33. return new Piece();
  34. }
  35. virtual PieceHandle getMissingPiece(int32_t index)
  36. {
  37. return new Piece();
  38. }
  39. virtual bool isPieceUsed(int32_t index)
  40. {
  41. return false;
  42. }
  43. virtual void markPieceMissing(int32_t index) {}
  44. virtual void markPiecesDone(int64_t) {}
  45. virtual PieceHandle getPiece(int32_t index) {
  46. return new Piece();
  47. }
  48. virtual void completePiece(const PieceHandle& piece) {}
  49. virtual void cancelPiece(const PieceHandle& piece) {}
  50. virtual bool hasPiece(int32_t index) {
  51. return false;
  52. }
  53. virtual int64_t getTotalLength() {
  54. return totalLength;
  55. }
  56. void setTotalLength(int64_t totalLength) {
  57. this->totalLength = totalLength;
  58. }
  59. virtual int64_t getFilteredTotalLength() {
  60. return filteredTotalLength;
  61. }
  62. void setFilteredTotalLength(int64_t totalLength) {
  63. this->filteredTotalLength = totalLength;
  64. }
  65. virtual int64_t getCompletedLength() {
  66. return completedLength;
  67. }
  68. void setCompletedLength(int64_t completedLength) {
  69. this->completedLength = completedLength;
  70. }
  71. virtual int64_t getFilteredCompletedLength() {
  72. return filteredCompletedLength;
  73. }
  74. void setFilteredCompletedLength(int64_t completedLength) {
  75. this->filteredCompletedLength = completedLength;
  76. }
  77. virtual void setFileFilter(const Strings& filePaths) {}
  78. virtual void setFileFilter(const Integers& fileIndexes) {}
  79. virtual void clearFileFilter() {}
  80. virtual bool downloadFinished() {
  81. return false;
  82. }
  83. virtual bool allDownloadFinished() {
  84. return false;
  85. }
  86. virtual void initStorage() {}
  87. virtual const unsigned char* getBitfield() {
  88. return bitfieldMan->getBitfield();
  89. }
  90. virtual void setBitfield(const unsigned char* bitfield,
  91. int32_t bitfieldLength) {
  92. bitfieldMan->setBitfield(bitfield, bitfieldLength);
  93. }
  94. virtual int32_t getBitfieldLength() {
  95. return bitfieldMan->getBitfieldLength();
  96. }
  97. void setBitfield(BitfieldMan* bitfieldMan) {
  98. this->bitfieldMan = bitfieldMan;
  99. }
  100. virtual bool isSelectiveDownloadingMode() {
  101. return selectiveDownloadingMode;
  102. }
  103. void setSelectiveDownloadingMode(bool flag) {
  104. this->selectiveDownloadingMode = flag;
  105. }
  106. virtual void finishSelectiveDownloadingMode() {}
  107. virtual bool isEndGame() {
  108. return endGame;
  109. }
  110. void setEndGame(bool flag) {
  111. this->endGame = flag;
  112. }
  113. virtual DiskAdaptorHandle getDiskAdaptor() {
  114. return diskAdaptor;
  115. }
  116. void setDiskAdaptor(const DiskAdaptorHandle adaptor) {
  117. this->diskAdaptor = adaptor;
  118. }
  119. virtual int32_t getPieceLength(int32_t index) {
  120. return pieceLengthList.at(index);
  121. }
  122. void addPieceLengthList(int32_t length) {
  123. pieceLengthList.push_back(length);
  124. }
  125. virtual void advertisePiece(int32_t cuid, int32_t index) {}
  126. virtual Integers getAdvertisedPieceIndexes(int32_t myCuid,
  127. const Time& lastCheckTime) {
  128. return Integers();
  129. }
  130. virtual void removeAdvertisedPiece(int32_t elapsed) {}
  131. virtual void markAllPiecesDone() {}
  132. virtual void addInFlightPiece(const Pieces& pieces)
  133. {
  134. copy(pieces.begin(), pieces.end(), back_inserter(inFlightPieces));
  135. }
  136. virtual int32_t countInFlightPiece()
  137. {
  138. return inFlightPieces.size();
  139. }
  140. virtual Pieces getInFlightPieces()
  141. {
  142. return inFlightPieces;
  143. }
  144. };
  145. typedef SharedHandle<MockPieceStorage> MockPieceStorageHandle;
  146. #endif // _D_MOCK_PIECE_STORAGE_H_