#include <boost/test/included/unit_test.hpp>
#include <boost/filesystem/fstream.hpp>
#include <fc/filesystem.hpp>
#include <fc/exception/exception.hpp>
Go to the source code of this file.
◆ BOOST_TEST_MODULE
#define BOOST_TEST_MODULE fc_filesystem |
◆ BOOST_AUTO_TEST_CASE() [1/2]
BOOST_AUTO_TEST_CASE |
( |
dir_copy | | ) |
|
Definition at line 19 of file test_filesystem.cpp.
19 {
20
21
22
23 const string src_dir {"/tmp/fc_copy_test_src"};
26 }
27
29 const string test_file_name = "fc_copy_test_file";
30 if (!
fc::exists(src_dir +
"/" + test_file_name)) {
31 boost::filesystem::ofstream ofs { src_dir + "/" + test_file_name};
32 ofs << "This the test of fc system copy \n";
33 ofs.close();
34 }
35 BOOST_CHECK_EQUAL(
fc::exists(src_dir +
"/" + test_file_name),
true);
36
37 const string tgt_dir {"/tmp/fc_copy_test_tgt"};
40 }
42
45
46 BOOST_CHECK_EQUAL(
fc::exists(tgt_dir +
"/" + test_file_name),
false);
47
48
52 });
53
Used to generate a useful error report when an exception is thrown.
bool exists(const path &p)
void remove_all(const path &p)
void create_directories(const path &p)
void copy(const path &from, const path &to)
@ unspecified_exception_code
◆ BOOST_AUTO_TEST_CASE() [2/2]
BOOST_AUTO_TEST_CASE |
( |
file_copy | | ) |
|
Definition at line 56 of file test_filesystem.cpp.
56 {
57
58 const string src_dir {"/tmp/fc_copy_test_src"};
61 }
62
64 const string test_file_name = "fc_copy_test_file";
65 if (!
fc::exists(src_dir +
"/" + test_file_name)) {
66 boost::filesystem::ofstream ofs { src_dir + "/" + test_file_name};
67 ofs << "This the test of fc system copy \n";
68 ofs.close();
69 }
70 BOOST_CHECK_EQUAL(
fc::exists(src_dir +
"/" + test_file_name),
true);
71
72 const string tgt_dir {"/tmp/fc_copy_test_tgt"};
75 }
77 BOOST_CHECK_EQUAL(
fc::exists(tgt_dir +
"/" + test_file_name),
false);
78 fc::copy(src_dir +
"/" + test_file_name, tgt_dir +
"/" + test_file_name);
79 BOOST_CHECK_EQUAL(
fc::exists(tgt_dir +
"/" + test_file_name),
true);
80 const string src_file_content =
getFileContent(src_dir +
"/" + test_file_name);
81 BOOST_CHECK_EQUAL(src_file_content.empty(), false);
82 const string tgt_file_content =
getFileContent(tgt_dir +
"/" + test_file_name);
83 BOOST_CHECK_EQUAL(src_file_content, tgt_file_content);
84
85
86 BOOST_CHECK_EQUAL(
fc::exists(tgt_dir +
"/" + test_file_name),
true);
87 BOOST_CHECK_EXCEPTION(
fc::copy(src_dir +
"/" + test_file_name, tgt_dir +
"/" + test_file_name),
91 });
92
std::string getFileContent(const string &filename)
◆ FC_LOG_AND_RETHROW()
◆ getFileContent()
std::string getFileContent |
( |
const string & | filename | ) |
|
Definition at line 9 of file test_filesystem.cpp.
9 {
11 boost::filesystem::ifstream ifs { filename };
13 ifs.close();
15}