aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2022-02-13 17:35:51 +0200
committerHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2022-02-14 16:56:40 +0200
commitdc01cbc538765f64326bca30952c83e3862d0d54 (patch)
tree6f4fd881b202caeca74b872dd531d98090dac268 /src
parentd4999d40b9bd04dc20111aaaa6ed2d3db1a5caf9 (diff)
downloadbitcoin-dc01cbc538765f64326bca30952c83e3862d0d54.tar.xz
test: Add fs_tests/rename unit test
Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
Diffstat (limited to 'src')
-rw-r--r--src/test/fs_tests.cpp36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/test/fs_tests.cpp b/src/test/fs_tests.cpp
index 1256395849..4fb2c23d98 100644
--- a/src/test/fs_tests.cpp
+++ b/src/test/fs_tests.cpp
@@ -118,4 +118,38 @@ BOOST_AUTO_TEST_CASE(fsbridge_fstream)
}
}
-BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file
+BOOST_AUTO_TEST_CASE(rename)
+{
+ const fs::path tmpfolder{m_args.GetDataDirBase()};
+
+ const fs::path path1{GetUniquePath(tmpfolder)};
+ const fs::path path2{GetUniquePath(tmpfolder)};
+
+ const std::string path1_contents{"1111"};
+ const std::string path2_contents{"2222"};
+
+ {
+ std::ofstream file{path1};
+ file << path1_contents;
+ }
+
+ {
+ std::ofstream file{path2};
+ file << path2_contents;
+ }
+
+ // Rename path1 -> path2.
+ BOOST_CHECK(RenameOver(path1, path2));
+
+ BOOST_CHECK(!fs::exists(path1));
+
+ {
+ std::ifstream file{path2};
+ std::string contents;
+ file >> contents;
+ BOOST_CHECK_EQUAL(contents, path1_contents);
+ }
+ fs::remove(path2);
+}
+
+BOOST_AUTO_TEST_SUITE_END()