MockBtContext.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. void addPieceHash(const string pieceHash) {
  38. pieceHashes.push_back(pieceHash);
  39. }
  40. virtual long long int getTotalLength() const {
  41. return totalLength;
  42. }
  43. void setTotalLength(long long int length) {
  44. this->totalLength = length;
  45. }
  46. virtual FILE_MODE getFileMode() const {
  47. return fileMode;
  48. }
  49. void setFileMode(FILE_MODE fileMode) {
  50. this->fileMode = fileMode;
  51. }
  52. virtual FileEntries getFileEntries() const {
  53. return fileEntries;
  54. }
  55. void addFileEntry(const FileEntryHandle& fileEntry) {
  56. fileEntries.push_back(fileEntry);
  57. }
  58. virtual AnnounceTiers getAnnounceTiers() const {
  59. return announceTiers;
  60. }
  61. void addAnnounceTier(const AnnounceTierHandle& announceTier) {
  62. announceTiers.push_back(announceTier);
  63. }
  64. virtual void load(const string& torrentFile) {}
  65. virtual string getName() const {
  66. return name;
  67. }
  68. void setName(const string& name) {
  69. this->name = name;
  70. }
  71. virtual int getPieceLength() const {
  72. return pieceLength;
  73. }
  74. void setPieceLength(int pieceLength) {
  75. this->pieceLength = pieceLength;
  76. }
  77. virtual int getNumPieces() const {
  78. return numPieces;
  79. }
  80. void setNumPieces(int numPieces) {
  81. this->numPieces = numPieces;
  82. }
  83. virtual const unsigned char* getPeerId() {
  84. return peerId;
  85. }
  86. void setPeerId(const unsigned char* peerId) {
  87. memcpy(this->peerId, peerId, sizeof(this->peerId));
  88. }
  89. };
  90. typedef SharedHandle<MockBtContext> MockBtContextHandle;
  91. #endif // _D_MOCK_BT_CONTEXT_H_