| 338 | } // namespace |
| 339 | |
| 340 | void 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) |
nothing calls this directly
no test coverage detected