MockBtContext.h 3.0 KB

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