diff options
Diffstat (limited to 'src/test/fs_tests.cpp')
-rw-r--r-- | src/test/fs_tests.cpp | 78 |
1 files changed, 70 insertions, 8 deletions
diff --git a/src/test/fs_tests.cpp b/src/test/fs_tests.cpp index d3389c30eb..313064b294 100644 --- a/src/test/fs_tests.cpp +++ b/src/test/fs_tests.cpp @@ -9,6 +9,10 @@ #include <boost/test/unit_test.hpp> +#include <fstream> +#include <ios> +#include <string> + BOOST_FIXTURE_TEST_SUITE(fs_tests, BasicTestingSetup) BOOST_AUTO_TEST_CASE(fsbridge_pathtostring) @@ -45,37 +49,37 @@ BOOST_AUTO_TEST_CASE(fsbridge_fstream) fs::path tmpfile1 = tmpfolder / "fs_tests_₿_🏃"; fs::path tmpfile2 = tmpfolder / "fs_tests_₿_🏃"; { - fsbridge::ofstream file(tmpfile1); + std::ofstream file{tmpfile1}; file << "bitcoin"; } { - fsbridge::ifstream file(tmpfile2); + std::ifstream file{tmpfile2}; std::string input_buffer; file >> input_buffer; BOOST_CHECK_EQUAL(input_buffer, "bitcoin"); } { - fsbridge::ifstream file(tmpfile1, std::ios_base::in | std::ios_base::ate); + std::ifstream file{tmpfile1, std::ios_base::in | std::ios_base::ate}; std::string input_buffer; file >> input_buffer; BOOST_CHECK_EQUAL(input_buffer, ""); } { - fsbridge::ofstream file(tmpfile2, std::ios_base::out | std::ios_base::app); + std::ofstream file{tmpfile2, std::ios_base::out | std::ios_base::app}; file << "tests"; } { - fsbridge::ifstream file(tmpfile1); + std::ifstream file{tmpfile1}; std::string input_buffer; file >> input_buffer; BOOST_CHECK_EQUAL(input_buffer, "bitcointests"); } { - fsbridge::ofstream file(tmpfile2, std::ios_base::out | std::ios_base::trunc); + std::ofstream file{tmpfile2, std::ios_base::out | std::ios_base::trunc}; file << "bitcoin"; } { - fsbridge::ifstream file(tmpfile1); + std::ifstream file{tmpfile1}; std::string input_buffer; file >> input_buffer; BOOST_CHECK_EQUAL(input_buffer, "bitcoin"); @@ -114,4 +118,62 @@ 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); +} + +#ifndef WIN32 +BOOST_AUTO_TEST_CASE(create_directories) +{ + // Test fs::create_directories workaround. + const fs::path tmpfolder{m_args.GetDataDirBase()}; + + const fs::path dir{GetUniquePath(tmpfolder)}; + fs::create_directory(dir); + BOOST_CHECK(fs::exists(dir)); + BOOST_CHECK(fs::is_directory(dir)); + BOOST_CHECK(!fs::create_directories(dir)); + + const fs::path symlink{GetUniquePath(tmpfolder)}; + fs::create_directory_symlink(dir, symlink); + BOOST_CHECK(fs::exists(symlink)); + BOOST_CHECK(fs::is_symlink(symlink)); + BOOST_CHECK(fs::is_directory(symlink)); + BOOST_CHECK(!fs::create_directories(symlink)); + + fs::remove(symlink); + fs::remove(dir); +} +#endif // WIN32 + +BOOST_AUTO_TEST_SUITE_END() |