MockBtContext.h 2.5 KB

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