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

Method testTryAutoFileRenaming

test/RequestGroupTest.cc:49–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47}
48
49void RequestGroupTest::testTryAutoFileRenaming()
50{
51 std::shared_ptr<DownloadContext> ctx(
52 new DownloadContext(1_k, 1_k, "/tmp/myfile"));
53
54 RequestGroup group(GroupId::create(), option_);
55 group.setDownloadContext(ctx);
56
57 option_->put(PREF_AUTO_FILE_RENAMING, "false");
58 try {
59 group.tryAutoFileRenaming();
60 }
61 catch (const Exception& ex) {
62 CPPUNIT_ASSERT_EQUAL(error_code::FILE_ALREADY_EXISTS, ex.getErrorCode());
63 }
64
65 option_->put(PREF_AUTO_FILE_RENAMING, "true");
66 group.tryAutoFileRenaming();
67 CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile.1"), group.getFirstFilePath());
68
69 ctx->getFirstFileEntry()->setPath("/tmp/myfile.txt");
70 group.tryAutoFileRenaming();
71 CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile.1.txt"),
72 group.getFirstFilePath());
73
74 ctx->getFirstFileEntry()->setPath("/tmp.txt/myfile");
75 group.tryAutoFileRenaming();
76 CPPUNIT_ASSERT_EQUAL(std::string("/tmp.txt/myfile.1"),
77 group.getFirstFilePath());
78
79 ctx->getFirstFileEntry()->setPath("/tmp.txt/myfile.txt");
80 group.tryAutoFileRenaming();
81 CPPUNIT_ASSERT_EQUAL(std::string("/tmp.txt/myfile.1.txt"),
82 group.getFirstFilePath());
83
84 ctx->getFirstFileEntry()->setPath(".bashrc");
85 group.tryAutoFileRenaming();
86 CPPUNIT_ASSERT_EQUAL(std::string(".bashrc.1"), group.getFirstFilePath());
87
88 ctx->getFirstFileEntry()->setPath(".bashrc.txt");
89 group.tryAutoFileRenaming();
90 CPPUNIT_ASSERT_EQUAL(std::string(".bashrc.1.txt"), group.getFirstFilePath());
91
92 ctx->getFirstFileEntry()->setPath("/tmp.txt/.bashrc");
93 group.tryAutoFileRenaming();
94 CPPUNIT_ASSERT_EQUAL(std::string("/tmp.txt/.bashrc.1"),
95 group.getFirstFilePath());
96
97 ctx->getFirstFileEntry()->setPath("/tmp.txt/.bashrc.txt");
98 group.tryAutoFileRenaming();
99 CPPUNIT_ASSERT_EQUAL(std::string("/tmp.txt/.bashrc.1.txt"),
100 group.getFirstFilePath());
101}
102
103void RequestGroupTest::testCreateDownloadResult()
104{

Callers

nothing calls this directly

Calls 7

createFunction · 0.85
tryAutoFileRenamingMethod · 0.80
getFirstFilePathMethod · 0.80
setDownloadContextMethod · 0.45
putMethod · 0.45
getErrorCodeMethod · 0.45
setPathMethod · 0.45

Tested by

no test coverage detected