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

Method testWriteData

test/MultiDiskAdaptorTest.cc:288–335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

286} // namespace
287
288void MultiDiskAdaptorTest::testWriteData()
289{
290 auto fileEntries = createEntries();
291 adaptor->setFileEntries(std::begin(fileEntries), std::end(fileEntries));
292
293 adaptor->openFile();
294 std::string msg = "12345";
295 adaptor->writeData((const unsigned char*)msg.c_str(), msg.size(), 0);
296 adaptor->closeFile();
297
298 CPPUNIT_ASSERT(File(A2_TEST_OUT_DIR "/file0.txt").isFile());
299 char buf[128];
300 readFile(A2_TEST_OUT_DIR "/file1.txt", buf, 5);
301 buf[5] = '\0';
302 CPPUNIT_ASSERT_EQUAL(msg, std::string(buf));
303
304 adaptor->openFile();
305 std::string msg2 = "67890ABCDEF";
306 adaptor->writeData((const unsigned char*)msg2.c_str(), msg2.size(), 5);
307 adaptor->closeFile();
308
309 readFile(A2_TEST_OUT_DIR "/file1.txt", buf, 15);
310 buf[15] = '\0';
311 CPPUNIT_ASSERT_EQUAL(std::string("1234567890ABCDE"), std::string(buf));
312 readFile(A2_TEST_OUT_DIR "/file2.txt", buf, 1);
313 buf[1] = '\0';
314 CPPUNIT_ASSERT_EQUAL(std::string("F"), std::string(buf));
315
316 adaptor->openFile();
317 std::string msg3 = "12345123456712";
318 adaptor->writeData((const unsigned char*)msg3.c_str(), msg3.size(), 10);
319 adaptor->closeFile();
320
321 readFile(A2_TEST_OUT_DIR "/file1.txt", buf, 15);
322 buf[15] = '\0';
323 CPPUNIT_ASSERT_EQUAL(std::string("123456789012345"), std::string(buf));
324 readFile(A2_TEST_OUT_DIR "/file2.txt", buf, 7);
325 buf[7] = '\0';
326 CPPUNIT_ASSERT_EQUAL(std::string("1234567"), std::string(buf));
327
328 CPPUNIT_ASSERT(File(A2_TEST_OUT_DIR "/file3.txt").isFile());
329
330 readFile(A2_TEST_OUT_DIR "/file4.txt", buf, 2);
331 buf[2] = '\0';
332 CPPUNIT_ASSERT_EQUAL(std::string("12"), std::string(buf));
333
334 CPPUNIT_ASSERT(File(A2_TEST_OUT_DIR "/file5.txt").isFile());
335}
336
337void MultiDiskAdaptorTest::testReadData()
338{

Callers

nothing calls this directly

Calls 9

createEntriesFunction · 0.85
FileClass · 0.85
isFileMethod · 0.80
readFileFunction · 0.70
setFileEntriesMethod · 0.45
openFileMethod · 0.45
writeDataMethod · 0.45
sizeMethod · 0.45
closeFileMethod · 0.45

Tested by

no test coverage detected