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

Method testAddTorrent

test/RpcMethodTest.cc:340–403  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

338} // namespace
339
340void RpcMethodTest::testAddTorrent()
341{
342 File(e_->getOption()->get(PREF_DIR) +
343 "/0a3893293e27ac0490424c06de4d09242215f0a6.torrent")
344 .remove();
345 AddTorrentRpcMethod m;
346 {
347 // Saving upload metadata is disabled by option.
348 auto res = m.execute(createAddTorrentReq(), e_.get());
349 CPPUNIT_ASSERT(!File(e_->getOption()->get(PREF_DIR) +
350 "/0a3893293e27ac0490424c06de4d09242215f0a6.torrent")
351 .exists());
352 CPPUNIT_ASSERT_EQUAL(0, res.code);
353 CPPUNIT_ASSERT_EQUAL(sizeof(a2_gid_t) * 2,
354 downcast<String>(res.param)->s().size());
355 }
356 e_->getOption()->put(PREF_RPC_SAVE_UPLOAD_METADATA, A2_V_TRUE);
357 {
358 auto res = m.execute(createAddTorrentReq(), e_.get());
359 CPPUNIT_ASSERT(File(e_->getOption()->get(PREF_DIR) +
360 "/0a3893293e27ac0490424c06de4d09242215f0a6.torrent")
361 .exists());
362 CPPUNIT_ASSERT_EQUAL(0, res.code);
363 a2_gid_t gid;
364 CPPUNIT_ASSERT_EQUAL(
365 0, GroupId::toNumericId(gid, downcast<String>(res.param)->s().c_str()));
366
367 auto group = findReservedGroup(e_->getRequestGroupMan().get(), gid);
368 CPPUNIT_ASSERT(group);
369 CPPUNIT_ASSERT_EQUAL(e_->getOption()->get(PREF_DIR) +
370 "/aria2-0.8.2.tar.bz2",
371 group->getFirstFilePath());
372 CPPUNIT_ASSERT_EQUAL((size_t)1, group->getDownloadContext()
373 ->getFirstFileEntry()
374 ->getRemainingUris()
375 .size());
376 CPPUNIT_ASSERT_EQUAL(std::string("http://localhost/aria2-0.8.2.tar.bz2"),
377 group->getDownloadContext()
378 ->getFirstFileEntry()
379 ->getRemainingUris()[0]);
380 }
381 {
382 auto req = createAddTorrentReq();
383 // with options
384 std::string dir = A2_TEST_OUT_DIR "/aria2_RpcMethodTest_testAddTorrent";
385 File(dir).mkdirs();
386 auto opt = Dict::g();
387 opt->put(PREF_DIR->k, dir);
388 File(dir + "/0a3893293e27ac0490424c06de4d09242215f0a6.torrent").remove();
389 req.params->append(std::move(opt));
390
391 auto res = m.execute(std::move(req), e_.get());
392 CPPUNIT_ASSERT_EQUAL(0, res.code);
393 a2_gid_t gid;
394 CPPUNIT_ASSERT_EQUAL(
395 0, GroupId::toNumericId(gid, downcast<String>(res.param)->s().c_str()));
396 CPPUNIT_ASSERT_EQUAL(dir + "/aria2-0.8.2.tar.bz2",
397 findReservedGroup(e_->getRequestGroupMan().get(), gid)

Callers

nothing calls this directly

Calls 14

FileClass · 0.85
createAddTorrentReqFunction · 0.85
findReservedGroupFunction · 0.85
getOptionMethod · 0.80
getRequestGroupManMethod · 0.80
getFirstFilePathMethod · 0.80
mkdirsMethod · 0.80
removeMethod · 0.45
getMethod · 0.45
executeMethod · 0.45
existsMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected