MockBtContext.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #ifndef _D_MOCK_BT_CONTEXT_H_
  2. #define _D_MOCK_BT_CONTEXT_H_
  3. #include "BtContext.h"
  4. #include "Util.h"
  5. class MockBtContext : public BtContext {
  6. private:
  7. unsigned char infoHash[20];
  8. Strings pieceHashes;
  9. int64_t totalLength;
  10. FILE_MODE fileMode;
  11. string name;
  12. int32_t pieceLength;
  13. int32_t numPieces;
  14. unsigned char peerId[20];
  15. FileEntries fileEntries;
  16. AnnounceTiers announceTiers;
  17. Integers fastSet;
  18. public:
  19. MockBtContext():totalLength(0),
  20. pieceLength(0),
  21. numPieces(0) {}
  22. virtual ~MockBtContext() {}
  23. virtual const unsigned char* getInfoHash() const {
  24. return infoHash;
  25. }
  26. void setInfoHash(const unsigned char* infoHash) {
  27. memcpy(this->infoHash, infoHash, sizeof(this->infoHash));
  28. }
  29. virtual int32_t getInfoHashLength() const {
  30. return sizeof(infoHash);
  31. }
  32. virtual string getInfoHashAsString() const {
  33. return Util::toHex(infoHash, sizeof(infoHash));
  34. }
  35. virtual string getPieceHash(int32_t index) const {
  36. return pieceHashes.at(index);
  37. }
  38. virtual const Strings& getPieceHashes() const {
  39. return pieceHashes;
  40. }
  41. void addPieceHash(const string pieceHash) {
  42. pieceHashes.push_back(pieceHash);
  43. }
  44. virtual int64_t getTotalLength() const {
  45. return totalLength;
  46. }
  47. void setTotalLength(int64_t length) {
  48. this->totalLength = length;
  49. }
  50. virtual FILE_MODE getFileMode() const {
  51. return fileMode;
  52. }
  53. void setFileMode(FILE_MODE fileMode) {
  54. this->fileMode = fileMode;
  55. }
  56. virtual FileEntries getFileEntries() const {
  57. return fileEntries;
  58. }
  59. void addFileEntry(const FileEntryHandle& fileEntry) {
  60. fileEntries.push_back(fileEntry);
  61. }
  62. virtual AnnounceTiers getAnnounceTiers() const {
  63. return announceTiers;
  64. }
  65. void addAnnounceTier(const AnnounceTierHandle& announceTier) {
  66. announceTiers.push_back(announceTier);
  67. }
  68. virtual void load(const string& torrentFile) {}
  69. virtual string getName() const {
  70. return name;
  71. }
  72. void setName(const string& name) {
  73. this->name = name;
  74. }
  75. virtual int32_t getPieceLength() const {
  76. return pieceLength;
  77. }
  78. void setPieceLength(int32_t pieceLength) {
  79. this->pieceLength = pieceLength;
  80. }
  81. virtual int32_t getNumPieces() const {
  82. return numPieces;
  83. }
  84. void setNumPieces(int32_t numPieces) {
  85. this->numPieces = numPieces;
  86. }
  87. virtual const unsigned char* getPeerId() {
  88. return peerId;
  89. }
  90. void setPeerId(const unsigned char* peerId) {
  91. memcpy(this->peerId, peerId, sizeof(this->peerId));
  92. }
  93. virtual Integers computeFastSet(const string& ipaddr, int32_t fastSetSize)
  94. {
  95. return fastSet;
  96. }
  97. void setFastSet(const Integers& fastSet)
  98. {
  99. this->fastSet = fastSet;
  100. }
  101. };
  102. typedef SharedHandle<MockBtContext> MockBtContextHandle;
  103. #endif // _D_MOCK_BT_CONTEXT_H_