MockPieceStorage.h 3.3 KB

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