2012-05-28 12:48:39 -04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "filesystem_test.h"
|
2012-06-23 01:08:14 -04:00
|
|
|
#include "pbd/file_utils.h"
|
2012-05-28 12:48:39 -04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|