1 #include "filesystem_test.h"
6 #include <glibmm/miscutils.h>
8 #include "pbd/file_utils.h"
10 #include "test_common.h"
15 CPPUNIT_TEST_SUITE_REGISTRATION (FilesystemTest);
18 FilesystemTest::testPathIsWithin ()
20 #ifndef PLATFORM_WINDOWS
22 CPPUNIT_ASSERT (g_mkdir_with_parents ("foo/bar/baz", 0755) == 0);
24 CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar/baz", "foo/bar/baz"));
25 CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar", "foo/bar/baz"));
26 CPPUNIT_ASSERT (PBD::path_is_within ("foo", "foo/bar/baz"));
27 CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar", "foo/bar/baz"));
28 CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar", "foo/bar"));
30 CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar/baz", "frobozz") == false);
32 int const r = symlink ("bar", "foo/jim");
33 CPPUNIT_ASSERT (r == 0);
35 CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar/baz", "foo/bar/baz"));
36 CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar", "foo/bar/baz"));
37 CPPUNIT_ASSERT (PBD::path_is_within ("foo", "foo/bar/baz"));
38 CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar", "foo/bar/baz"));
39 CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar", "foo/bar"));
41 CPPUNIT_ASSERT (PBD::path_is_within ("foo/jim/baz", "frobozz") == false);
46 FilesystemTest::testCopyFileASCIIFilename ()
49 CPPUNIT_ASSERT (find_file (test_search_path (), "RosegardenPatchFile.xml", testdata_path));
51 string output_path = test_output_directory ("CopyFile");
53 output_path = Glib::build_filename (output_path, "RosegardenPatchFile.xml");
56 cerr << "CopyFile test output path: " << output_path << endl;
58 CPPUNIT_ASSERT (PBD::copy_file (testdata_path, output_path));
62 FilesystemTest::testCopyFileUTF8Filename ()
64 vector<string> i18n_files;
66 Searchpath i18n_path(test_search_path());
67 i18n_path.add_subdirectory_to_paths("i18n_test");
69 PBD::find_files_matching_pattern (i18n_files, i18n_path, "*.tst");
72 cerr << "Copying " << i18n_files.size() << " test files from: "
73 << i18n_path.to_string () << endl;
75 for (vector<string>::iterator i = i18n_files.begin(); i != i18n_files.end(); ++i) {
76 string input_path = *i;
77 string output_file = Glib::path_get_basename(*i);
78 string output_path = test_output_directory ("CopyFile");
79 output_path = Glib::build_filename (output_path, output_file);
81 cerr << "Copying test file: " << input_path
82 << " To " << output_path << endl;
84 CPPUNIT_ASSERT (PBD::copy_file (input_path, output_path));
89 FilesystemTest::testFindFilesMatchingPattern ()
91 vector<string> patch_files;
93 PBD::find_files_matching_pattern (patch_files, test_search_path (), "*PatchFile*");
95 CPPUNIT_ASSERT(test_search_path ().size() == 1);
97 CPPUNIT_ASSERT(patch_files.size() == 2);