summaryrefslogtreecommitdiff
path: root/test/MockPieceStorage.h
blob: 6d5edfea83cd646450c0914bcdde5edbbdd5e888 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#ifndef _D_MOCK_PIECE_STORAGE_H_
#define _D_MOCK_PIECE_STORAGE_H_

#include "PieceStorage.h"
#include "BitfieldMan.h"
#include "Piece.h"
#include "DiskAdaptor.h"

class MockPieceStorage : public PieceStorage {
private:
  int64_t totalLength;
  int64_t filteredTotalLength;
  int64_t completedLength;
  int64_t filteredCompletedLength;
  BitfieldMan* bitfieldMan;
  bool selectiveDownloadingMode;
  bool endGame;
  DiskAdaptorHandle diskAdaptor;
  Integers pieceLengthList;
  Pieces inFlightPieces;
  bool _allDownloadFinished;
public:
  MockPieceStorage():totalLength(0),
		     filteredTotalLength(0),
		     completedLength(0),
		     filteredCompletedLength(0),
		     bitfieldMan(0),
		     selectiveDownloadingMode(false),
		     endGame(false),
		     diskAdaptor(0),
		     _allDownloadFinished(false) {}

  virtual ~MockPieceStorage() {}

  virtual bool hasMissingPiece(const PeerHandle& peer) {
    return false;
  }

  virtual PieceHandle getMissingPiece(const PeerHandle& peer) {
    return new Piece();
  }

  virtual PieceHandle getMissingFastPiece(const PeerHandle& peer) {
    return new Piece();
  }

  virtual PieceHandle getMissingPiece()
  {
    return new Piece();
  }

  virtual PieceHandle getMissingPiece(int32_t index)
  {
    return new Piece();
  }

  virtual bool isPieceUsed(int32_t index)
  {
    return false;
  }

  virtual void markPieceMissing(int32_t index) {}

  virtual void markPiecesDone(int64_t) {}

  virtual PieceHandle getPiece(int32_t index) {
    return new Piece();
  }

  virtual void completePiece(const PieceHandle& piece) {}

  virtual void cancelPiece(const PieceHandle& piece) {}

  virtual bool hasPiece(int32_t index) {
    return false;
  }

  virtual int64_t getTotalLength() {
    return totalLength;
  }

  void setTotalLength(int64_t totalLength) {
    this->totalLength = totalLength;
  }

  virtual int64_t getFilteredTotalLength() {
    return filteredTotalLength;
  }

  void setFilteredTotalLength(int64_t totalLength) {
    this->filteredTotalLength = totalLength;
  }

  virtual int64_t getCompletedLength() {
    return completedLength;
  }

  void setCompletedLength(int64_t completedLength) {
    this->completedLength = completedLength;
  }

  virtual int64_t getFilteredCompletedLength() {
    return filteredCompletedLength;
  }

  void setFilteredCompletedLength(int64_t completedLength) {
    this->filteredCompletedLength = completedLength;
  }
  
  virtual void setFileFilter(const Strings& filePaths) {}

  virtual void setFileFilter(IntSequence seq) {}

  virtual void clearFileFilter() {}

  virtual bool downloadFinished() {
    return false;
  }

  virtual bool allDownloadFinished() {
    return _allDownloadFinished;
  }

  void setAllDownloadFinished(bool f)
  {
    _allDownloadFinished = f;
  }

  virtual void initStorage() {}

  virtual const unsigned char* getBitfield() {
    return bitfieldMan->getBitfield();
  }

  virtual void setBitfield(const unsigned char* bitfield,
			   int32_t bitfieldLength) {
    bitfieldMan->setBitfield(bitfield, bitfieldLength);
  }
  
  virtual int32_t getBitfieldLength() {
    return bitfieldMan->getBitfieldLength();
  }

  void setBitfield(BitfieldMan* bitfieldMan) {
    this->bitfieldMan = bitfieldMan;
  }

  virtual bool isSelectiveDownloadingMode() {
    return selectiveDownloadingMode;
  }

  void setSelectiveDownloadingMode(bool flag) {
    this->selectiveDownloadingMode = flag;
  }

  virtual void finishSelectiveDownloadingMode() {}

  virtual bool isEndGame() {
    return endGame;
  }

  void setEndGame(bool flag) {
    this->endGame = flag;
  }

  virtual DiskAdaptorHandle getDiskAdaptor() {
    return diskAdaptor;
  }

  void setDiskAdaptor(const DiskAdaptorHandle adaptor) {
    this->diskAdaptor = adaptor;
  }
  
  virtual int32_t getPieceLength(int32_t index) {
    return pieceLengthList.at(index);
  }

  void addPieceLengthList(int32_t length) {
    pieceLengthList.push_back(length);
  }

  virtual void advertisePiece(int32_t cuid, int32_t index) {}

  virtual Integers getAdvertisedPieceIndexes(int32_t myCuid,
					     const Time& lastCheckTime) {
    return Integers();
  }

  virtual void removeAdvertisedPiece(int32_t elapsed) {}

  virtual void markAllPiecesDone() {}

  virtual void addInFlightPiece(const Pieces& pieces)
  {
    copy(pieces.begin(), pieces.end(), back_inserter(inFlightPieces));
  }

  virtual int32_t countInFlightPiece()
  {
    return inFlightPieces.size();
  }

  virtual Pieces getInFlightPieces()
  {
    return inFlightPieces;
  }

};

typedef SharedHandle<MockPieceStorage> MockPieceStorageHandle;

#endif // _D_MOCK_PIECE_STORAGE_H_