MockPieceStorage.h 3.5 KB

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