4 #include <glib/gstdio.h>
9 #include <glibmm/miscutils.h>
10 #include <glibmm/fileutils.h>
28 PwdReset(
const string& new_pwd)
29 : m_old_pwd(
Glib::get_current_dir()) {
30 CPPUNIT_ASSERT (g_chdir (new_pwd.c_str()) == 0);
35 CPPUNIT_ASSERT (g_chdir (m_old_pwd.c_str()) == 0);
49 #ifndef PLATFORM_WINDOWS
51 PwdReset pwd_reset(output_path);
53 CPPUNIT_ASSERT (g_mkdir_with_parents (
"foo/bar/baz", 0755) == 0);
55 CPPUNIT_ASSERT (
PBD::path_is_within (Glib::build_filename(output_path,
"foo/bar/baz"), Glib::build_filename(output_path,
"foo/bar/baz")));
56 CPPUNIT_ASSERT (
PBD::path_is_within (Glib::build_filename(output_path,
"foo/bar"), Glib::build_filename(output_path,
"foo/bar/baz")));
57 CPPUNIT_ASSERT (
PBD::path_is_within (Glib::build_filename(output_path,
"foo"), Glib::build_filename(output_path,
"foo/bar/baz")));
58 CPPUNIT_ASSERT (
PBD::path_is_within (Glib::build_filename(output_path,
"foo/bar"), Glib::build_filename(output_path,
"foo/bar/baz")));
59 CPPUNIT_ASSERT (
PBD::path_is_within (Glib::build_filename(output_path,
"foo/bar"), Glib::build_filename(output_path,
"foo/bar")));
61 CPPUNIT_ASSERT (
PBD::path_is_within (Glib::build_filename(output_path,
"foo/bar/baz"), Glib::build_filename(output_path,
"frobozz")) ==
false);
63 int const r = symlink (
"bar",
"foo/jim");
64 CPPUNIT_ASSERT (r == 0);
66 CPPUNIT_ASSERT (
PBD::path_is_within (Glib::build_filename(output_path,
"foo/jim/baz"), Glib::build_filename(output_path,
"foo/bar/baz")));
67 CPPUNIT_ASSERT (
PBD::path_is_within (Glib::build_filename(output_path,
"foo/jim"), Glib::build_filename(output_path,
"foo/bar/baz")));
68 CPPUNIT_ASSERT (
PBD::path_is_within (Glib::build_filename(output_path,
"foo"), Glib::build_filename(output_path,
"foo/bar/baz")));
69 CPPUNIT_ASSERT (
PBD::path_is_within (Glib::build_filename(output_path,
"foo/jim"), Glib::build_filename(output_path,
"foo/bar/baz")));
70 CPPUNIT_ASSERT (
PBD::path_is_within (Glib::build_filename(output_path,
"foo/jim"), Glib::build_filename(output_path,
"foo/bar")));
72 CPPUNIT_ASSERT (
PBD::path_is_within (Glib::build_filename(output_path,
"foo/jim/baz"), Glib::build_filename(output_path,
"frobozz")) ==
false);
84 output_path = Glib::build_filename (output_path,
"RosegardenPatchFile.xml");
87 cerr <<
"CopyFile test output path: " << output_path << endl;
95 vector<string> i18n_files;
102 CPPUNIT_ASSERT (i18n_files.size() == 8);
105 cerr <<
"Copying " << i18n_files.size() <<
" test files from: "
108 for (vector<string>::iterator i = i18n_files.begin(); i != i18n_files.end(); ++i) {
109 string input_path = *i;
110 string output_file = Glib::path_get_basename(*i);
112 output_path = Glib::build_filename (output_path, output_file);
114 cerr <<
"Copying test file: " << input_path
115 <<
" To " << output_path << endl;
124 vector<string> patch_files;
130 CPPUNIT_ASSERT(patch_files.size() == 2);
136 vector<string> test_files;
137 vector<string> i18n_files;
153 cerr <<
"Copying " << test_files.size() <<
" test files from: "
154 << test_dir_path <<
" to " << output_dir << endl;
156 CPPUNIT_ASSERT (test_files.size() != 0);
160 vector<string> copied_files;
164 CPPUNIT_ASSERT (copied_files.size() == test_files.size());
166 string subdir_path = Glib::build_filename (output_dir,
"subdir");
168 CPPUNIT_ASSERT (g_mkdir_with_parents (subdir_path.c_str(), 0755) == 0);
171 cerr <<
"Copying " << i18n_files.size() <<
" i18n test files to: "
172 << subdir_path << endl;
174 for (vector<string>::iterator i = i18n_files.begin(); i != i18n_files.end(); ++i) {
175 string input_filepath = *i;
176 string output_filename = Glib::path_get_basename(*i);
177 string output_filepath = Glib::build_filename (subdir_path, output_filename);
179 CPPUNIT_ASSERT (
PBD::copy_file (input_filepath, output_filepath));
182 copied_files.clear();
185 CPPUNIT_ASSERT (copied_files.size() == i18n_files.size());
195 vector<string> files_in_output_dir;
197 PBD::get_paths (files_in_output_dir, output_dir_path,
true,
true);
199 size_t removed_file_size = 0;
200 vector<string> removed_files;
202 CPPUNIT_ASSERT (
PBD::clear_directory (output_dir_path, &removed_file_size, &removed_files) ==0);
204 cerr <<
"Removed " << removed_files.size() <<
" files of total size: "
205 << removed_file_size << endl;
207 CPPUNIT_ASSERT (removed_files.size () == files_in_output_dir.size ());
209 string subdir_path = Glib::build_filename (output_dir_path,
"subdir");
212 CPPUNIT_ASSERT (Glib::file_test (subdir_path, Glib::FILE_TEST_IS_DIR));
220 vector<string> files_in_output_dir;
222 PBD::get_paths (files_in_output_dir, output_dir_path,
false,
true);
224 CPPUNIT_ASSERT (files_in_output_dir.size () != 0);
229 CPPUNIT_ASSERT (Glib::file_test (output_dir_path, Glib::FILE_TEST_IS_DIR));
231 files_in_output_dir.clear ();
233 PBD::get_paths (files_in_output_dir, output_dir_path,
false,
true);
235 CPPUNIT_ASSERT (files_in_output_dir.size () == 0);
241 #ifndef PLATFORM_WINDOWS
243 PwdReset pwd_reset(top_dir);
245 string pwd = Glib::get_current_dir ();
247 CPPUNIT_ASSERT (!pwd.empty());
248 CPPUNIT_ASSERT (pwd == top_dir);
250 CPPUNIT_ASSERT (g_mkdir (
"gtk2_ardour", 0755) == 0);
251 CPPUNIT_ASSERT (g_mkdir_with_parents (
"libs/pbd/test", 0755) == 0);
253 const char* relative_path =
"./gtk2_ardour/../libs/pbd/test";
257 string expected_path = top_dir + string(
"/libs/pbd/test");
259 CPPUNIT_ASSERT (canonical_path == expected_path);
260 CPPUNIT_ASSERT (expanded_path == expected_path);
LIBPBD_API std::string path_expand(std::string path)
void remove_directory(const std::string &dir)
bool path_is_within(std::string const &haystack, std::string needle)
bool find_file(const Searchpath &search_path, const string &filename, std::string &result)
int clear_directory(const string &dir, size_t *size, vector< string > *paths)
LIBPBD_TEMPLATE_MEMBER_API Searchpath & add_subdirectory_to_paths(const std::string &subdir)
bool copy_file(const std::string &from_path, const std::string &to_path)
void find_files_matching_pattern(vector< string > &result, const Searchpath &paths, const Glib::PatternSpec &pattern)
void testClearDirectory()
void testCopyFileASCIIFilename()
void copy_files(const std::string &from_path, const std::string &to_dir)
PBD::Searchpath test_search_path()
void get_paths(vector< string > &result, const Searchpath &paths, bool files_only, bool recurse)
LIBPBD_TEMPLATE_MEMBER_API const std::string to_string() const
std::string test_output_directory(std::string prefix)
void testFindFilesMatchingPattern()
void get_files(vector< string > &result, const Searchpath &paths)
CPPUNIT_TEST_SUITE_REGISTRATION(FilesystemTest)
void testCopyFileUTF8Filename()
void testRemoveDirectory()
LIBPBD_API std::string canonical_path(const std::string &path)
string create_test_directory(std::string test_dir)