MockPieceStorage.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. 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 long long int getTotalLength() {
  37. return totalLength;
  38. }
  39. void setTotalLength(long long int totalLength) {
  40. this->totalLength = totalLength;
  41. }
  42. virtual long long int getFilteredTotalLength() {
  43. return filteredTotalLength;
  44. }
  45. void setFilteredTotalLength(long long int totalLength) {
  46. this->filteredTotalLength = totalLength;
  47. }
  48. virtual long long int getCompletedLength() {
  49. return completedLength;
  50. }
  51. void setCompletedLength(long long int completedLength) {
  52. this->completedLength = completedLength;
  53. }
  54. virtual long long int getFilteredCompletedLength() {
  55. return filteredCompletedLength;
  56. }
  57. void setFilteredCompletedLength(long long int 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 void initStorage() {}
  67. virtual const unsigned char* getBitfield() {
  68. return bitfieldMan->getBitfield();
  69. }
  70. virtual void setBitfield(const unsigned char* bitfield,
  71. int bitfieldLength) {
  72. bitfieldMan->setBitfield(bitfield, bitfieldLength);
  73. }
  74. virtual int getBitfieldLength() {
  75. return bitfieldMan->getBitfieldLength();
  76. }
  77. void setBitfield(BitfieldMan* bitfieldMan) {
  78. this->bitfieldMan = bitfieldMan;
  79. }
  80. virtual bool isSelectiveDownloadingMode() {
  81. return selectiveDownloadingMode;
  82. }
  83. void setSelectiveDownloadingMode(bool flag) {
  84. this->selectiveDownloadingMode = flag;
  85. }
  86. virtual void finishSelectiveDownloadingMode() {}
  87. virtual bool isEndGame() {
  88. return endGame;
  89. }
  90. void setEndGame(bool flag) {
  91. this->endGame = flag;
  92. }
  93. virtual DiskAdaptorHandle getDiskAdaptor() {
  94. return diskAdaptor;
  95. }
  96. void setDiskAdaptor(const DiskAdaptorHandle adaptor) {
  97. this->diskAdaptor = adaptor;
  98. }
  99. virtual int getPieceLength(int index) {
  100. return pieceLengthList.at(index);
  101. }
  102. void addPieceLengthList(int length) {
  103. pieceLengthList.push_back(length);
  104. }
  105. virtual void advertisePiece(int cuid, int index) {}
  106. virtual Integers getAdvertisedPieceIndexes(int myCuid,
  107. const Time& lastCheckTime) {
  108. return Integers();
  109. }
  110. virtual void removeAdvertisedPiece(int elapsed) {}
  111. virtual void markAllPiecesDone() {}
  112. virtual void checkIntegrity() {}
  113. };
  114. typedef SharedHandle<MockPieceStorage> MockPieceStorageHandle;
  115. #endif // _D_MOCK_PIECE_STORAGE_H_