summaryrefslogtreecommitdiff
path: root/unittests/Basic
diff options
context:
space:
mode:
authorBen Hamilton <benhamilton@google.com>2017-11-09 16:01:16 +0000
committerBen Hamilton <benhamilton@google.com>2017-11-09 16:01:16 +0000
commit5140a709d303679fce3218d238fd4ee5043ae851 (patch)
treedd00ad7e72c7902b9010be63b794753978a2c376 /unittests/Basic
parent78960a92a5a858bcab2c0ef18de6901930363822 (diff)
[VirtualFileSystem] InMemoryFileSystem::addFile(): Type and Perms
Summary: This implements a FIXME in InMemoryFileSystem::addFile(), allowing clients to specify User, Group, Type, and/or Perms when creating a file in an in-memory filesystem. New tests included. Ran tests with: % ninja BasicTests && ./tools/clang/unittests/Basic/BasicTests Fixes PR#35172 (https://bugs.llvm.org/show_bug.cgi?id=35172) Reviewers: bkramer, hokein Reviewed By: bkramer, hokein Subscribers: alexfh Differential Revision: https://reviews.llvm.org/D39572 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@317800 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Basic')
-rw-r--r--unittests/Basic/VirtualFileSystemTest.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/unittests/Basic/VirtualFileSystemTest.cpp b/unittests/Basic/VirtualFileSystemTest.cpp
index 40add2195b..513e812576 100644
--- a/unittests/Basic/VirtualFileSystemTest.cpp
+++ b/unittests/Basic/VirtualFileSystemTest.cpp
@@ -760,6 +760,75 @@ TEST_F(InMemoryFileSystemTest, WorkingDirectory) {
NormalizedFS.getCurrentWorkingDirectory().get()));
}
+TEST_F(InMemoryFileSystemTest, AddFileWithUser) {
+ FS.addFile("/a/b/c", 0, MemoryBuffer::getMemBuffer("abc"), 0xFEEDFACE);
+ auto Stat = FS.status("/a");
+ ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
+ ASSERT_TRUE(Stat->isDirectory());
+ ASSERT_EQ(0xFEEDFACE, Stat->getUser());
+ Stat = FS.status("/a/b");
+ ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
+ ASSERT_TRUE(Stat->isDirectory());
+ ASSERT_EQ(0xFEEDFACE, Stat->getUser());
+ Stat = FS.status("/a/b/c");
+ ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
+ ASSERT_TRUE(Stat->isRegularFile());
+ ASSERT_EQ(sys::fs::perms::all_all, Stat->getPermissions());
+ ASSERT_EQ(0xFEEDFACE, Stat->getUser());
+}
+
+TEST_F(InMemoryFileSystemTest, AddFileWithGroup) {
+ FS.addFile("/a/b/c", 0, MemoryBuffer::getMemBuffer("abc"), None, 0xDABBAD00);
+ auto Stat = FS.status("/a");
+ ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
+ ASSERT_TRUE(Stat->isDirectory());
+ ASSERT_EQ(0xDABBAD00, Stat->getGroup());
+ Stat = FS.status("/a/b");
+ ASSERT_TRUE(Stat->isDirectory());
+ ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
+ ASSERT_EQ(0xDABBAD00, Stat->getGroup());
+ Stat = FS.status("/a/b/c");
+ ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
+ ASSERT_TRUE(Stat->isRegularFile());
+ ASSERT_EQ(sys::fs::perms::all_all, Stat->getPermissions());
+ ASSERT_EQ(0xDABBAD00, Stat->getGroup());
+}
+
+TEST_F(InMemoryFileSystemTest, AddFileWithFileType) {
+ FS.addFile("/a/b/c", 0, MemoryBuffer::getMemBuffer("abc"), None, None,
+ sys::fs::file_type::socket_file);
+ auto Stat = FS.status("/a");
+ ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
+ ASSERT_TRUE(Stat->isDirectory());
+ Stat = FS.status("/a/b");
+ ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
+ ASSERT_TRUE(Stat->isDirectory());
+ Stat = FS.status("/a/b/c");
+ ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
+ ASSERT_EQ(sys::fs::file_type::socket_file, Stat->getType());
+ ASSERT_EQ(sys::fs::perms::all_all, Stat->getPermissions());
+}
+
+TEST_F(InMemoryFileSystemTest, AddFileWithPerms) {
+ FS.addFile("/a/b/c", 0, MemoryBuffer::getMemBuffer("abc"), None, None,
+ None, sys::fs::perms::owner_read | sys::fs::perms::owner_write);
+ auto Stat = FS.status("/a");
+ ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
+ ASSERT_TRUE(Stat->isDirectory());
+ ASSERT_EQ(sys::fs::perms::owner_read | sys::fs::perms::owner_write |
+ sys::fs::perms::owner_exe, Stat->getPermissions());
+ Stat = FS.status("/a/b");
+ ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
+ ASSERT_TRUE(Stat->isDirectory());
+ ASSERT_EQ(sys::fs::perms::owner_read | sys::fs::perms::owner_write |
+ sys::fs::perms::owner_exe, Stat->getPermissions());
+ Stat = FS.status("/a/b/c");
+ ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
+ ASSERT_TRUE(Stat->isRegularFile());
+ ASSERT_EQ(sys::fs::perms::owner_read | sys::fs::perms::owner_write,
+ Stat->getPermissions());
+}
+
// NOTE: in the tests below, we use '//root/' as our root directory, since it is
// a legal *absolute* path on Windows as well as *nix.
class VFSFromYAMLTest : public ::testing::Test {