2014-06-24 03:05:45 -04:00
|
|
|
#include "filesystem_test.h"
|
|
|
|
|
2012-05-28 12:48:39 -04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
2014-06-24 03:05:45 -04:00
|
|
|
|
|
|
|
#include <glibmm/miscutils.h>
|
|
|
|
|
2012-06-23 01:08:14 -04:00
|
|
|
#include "pbd/file_utils.h"
|
2012-05-28 12:48:39 -04:00
|
|
|
|
2014-06-24 03:05:45 -04:00
|
|
|
#include "test_common.h"
|
|
|
|
|
2012-05-28 12:48:39 -04:00
|
|
|
using namespace std;
|
2014-06-24 23:51:58 -04:00
|
|
|
using namespace PBD;
|
2012-05-28 12:48:39 -04:00
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION (FilesystemTest);
|
|
|
|
|
|
|
|
void
|
|
|
|
FilesystemTest::testPathIsWithin ()
|
|
|
|
{
|
2013-07-17 03:08:46 -04:00
|
|
|
#ifndef PLATFORM_WINDOWS
|
2012-05-28 12:48:39 -04:00
|
|
|
system ("rm -r foo");
|
2012-06-23 01:09:19 -04:00
|
|
|
CPPUNIT_ASSERT (g_mkdir_with_parents ("foo/bar/baz", 0755) == 0);
|
2012-05-28 12:48:39 -04:00
|
|
|
|
2012-06-23 01:08:14 -04:00
|
|
|
CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar/baz", "foo/bar/baz"));
|
|
|
|
CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar", "foo/bar/baz"));
|
|
|
|
CPPUNIT_ASSERT (PBD::path_is_within ("foo", "foo/bar/baz"));
|
|
|
|
CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar", "foo/bar/baz"));
|
|
|
|
CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar", "foo/bar"));
|
2012-05-28 12:48:39 -04:00
|
|
|
|
2012-06-23 01:08:14 -04:00
|
|
|
CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar/baz", "frobozz") == false);
|
2012-05-28 12:48:39 -04:00
|
|
|
|
|
|
|
int const r = symlink ("bar", "foo/jim");
|
|
|
|
CPPUNIT_ASSERT (r == 0);
|
|
|
|
|
2012-06-23 01:08:14 -04:00
|
|
|
CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar/baz", "foo/bar/baz"));
|
|
|
|
CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar", "foo/bar/baz"));
|
|
|
|
CPPUNIT_ASSERT (PBD::path_is_within ("foo", "foo/bar/baz"));
|
|
|
|
CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar", "foo/bar/baz"));
|
|
|
|
CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar", "foo/bar"));
|
2012-05-28 12:48:39 -04:00
|
|
|
|
2012-06-23 01:08:14 -04:00
|
|
|
CPPUNIT_ASSERT (PBD::path_is_within ("foo/jim/baz", "frobozz") == false);
|
2013-07-11 12:47:56 -04:00
|
|
|
#endif
|
2012-05-28 12:48:39 -04:00
|
|
|
}
|
|
|
|
|
2014-06-24 03:05:45 -04:00
|
|
|
void
|
2014-06-24 23:51:58 -04:00
|
|
|
FilesystemTest::testCopyFileASCIIFilename ()
|
2014-06-24 03:05:45 -04:00
|
|
|
{
|
2014-06-24 23:51:58 -04:00
|
|
|
string testdata_path;
|
2014-06-24 03:05:45 -04:00
|
|
|
CPPUNIT_ASSERT (find_file (test_search_path (), "RosegardenPatchFile.xml", testdata_path));
|
|
|
|
|
2014-06-24 23:51:58 -04:00
|
|
|
string output_path = test_output_directory ("CopyFile");
|
2014-06-24 03:05:45 -04:00
|
|
|
|
|
|
|
output_path = Glib::build_filename (output_path, "RosegardenPatchFile.xml");
|
|
|
|
|
2014-06-24 23:51:58 -04:00
|
|
|
cerr << endl;
|
2014-06-24 03:05:45 -04:00
|
|
|
cerr << "CopyFile test output path: " << output_path << endl;
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT (PBD::copy_file (testdata_path, output_path));
|
|
|
|
}
|
2014-06-24 23:51:58 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
FilesystemTest::testCopyFileUTF8Filename ()
|
|
|
|
{
|
|
|
|
vector<string> i18n_files;
|
|
|
|
|
|
|
|
Searchpath i18n_path(test_search_path());
|
|
|
|
i18n_path.add_subdirectory_to_paths("i18n_test");
|
|
|
|
|
|
|
|
PBD::find_files_matching_pattern (i18n_files, i18n_path, "*.tst");
|
|
|
|
|
|
|
|
cerr << endl;
|
|
|
|
cerr << "Copying " << i18n_files.size() << " test files from: "
|
|
|
|
<< i18n_path.to_string () << endl;
|
|
|
|
|
|
|
|
for (vector<string>::iterator i = i18n_files.begin(); i != i18n_files.end(); ++i) {
|
|
|
|
string input_path = *i;
|
|
|
|
string output_file = Glib::path_get_basename(*i);
|
|
|
|
string output_path = test_output_directory ("CopyFile");
|
|
|
|
output_path = Glib::build_filename (output_path, output_file);
|
|
|
|
|
|
|
|
cerr << "Copying test file: " << input_path
|
|
|
|
<< " To " << output_path << endl;
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT (PBD::copy_file (input_path, output_path));
|
|
|
|
}
|
|
|
|
}
|