MCPcopy Create free account
hub / github.com/aria2/aria2 / testAllocate

Method testAllocate

test/MultiFileAllocationIteratorTest.cc:136–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134}
135
136void MultiFileAllocationIteratorTest::testAllocate()
137{
138 std::string storeDir =
139 A2_TEST_OUT_DIR "/aria2_MultiFileAllocationIteratorTest_testAllocate";
140
141 std::string fname1 = "file1";
142 std::string fname2 = "file2";
143 std::string fname3 = "file3";
144 std::string fname4 = "file4";
145 std::string fname5 = "file5";
146 std::string fname6 = "file6";
147 int64_t length1 = 32769;
148 int64_t length2 = 0;
149 int64_t length3 = 8;
150 int64_t length4 = 10;
151 int64_t length5 = 20;
152 int64_t length6 = 30;
153
154 try {
155 MultiDiskAdaptor diskAdaptor;
156 diskAdaptor.setPieceLength(1);
157
158 int64_t offset = 0;
159 auto fileEntry1 =
160 std::make_shared<FileEntry>(storeDir + "/" + fname1, length1, offset);
161 offset += length1;
162 auto fileEntry2 =
163 std::make_shared<FileEntry>(storeDir + "/" + fname2, length2, offset);
164 offset += length2;
165 auto fileEntry3 =
166 std::make_shared<FileEntry>(storeDir + "/" + fname3, length3, offset);
167
168 offset += length3;
169 auto fileEntry4 =
170 std::make_shared<FileEntry>(storeDir + "/" + fname4, length4, offset);
171 fileEntry4->setRequested(false);
172 offset += length4;
173 auto fileEntry5 =
174 std::make_shared<FileEntry>(storeDir + "/" + fname5, length5, offset);
175 offset += length5;
176 auto fileEntry6 =
177 std::make_shared<FileEntry>(storeDir + "/" + fname6, length6, offset);
178 fileEntry6->setRequested(false);
179
180 auto fs = std::vector<std::shared_ptr<FileEntry>>{
181 fileEntry1, fileEntry2, fileEntry3, fileEntry4, fileEntry5, fileEntry6};
182 diskAdaptor.setFileEntries(std::begin(fs), std::end(fs));
183
184 for (auto& fe : fs) {
185 File{fe->getPath()}.remove();
186 }
187
188 // we have to open file first.
189 diskAdaptor.initAndOpenFile();
190 auto allocitr = diskAdaptor.fileAllocationIterator();
191 auto itr = dynamic_cast<MultiFileAllocationIterator*>(allocitr.get());
192 while (!itr->finished()) {
193 itr->allocateChunk();

Callers

nothing calls this directly

Calls 14

FileClass · 0.85
setRequestedMethod · 0.80
getPathMethod · 0.80
isFileMethod · 0.80
stackTraceMethod · 0.80
setPieceLengthMethod · 0.45
setFileEntriesMethod · 0.45
removeMethod · 0.45
initAndOpenFileMethod · 0.45
getMethod · 0.45
finishedMethod · 0.45

Tested by

no test coverage detected