sapling/eden/fs/inodes/test/InodeBaseTest.cpp
Chad Austin 8b9261f2a1 run clang-format across all C++ files
Summary:
Per discussion with bolinfest, this brings Eden in line with clang-format.

This diff was generated with `find . \( -iname '*.cpp' -o -iname '*.h' \) -exec bash -c "yes | arc lint {}" \;`

Reviewed By: bolinfest

Differential Revision: D6232695

fbshipit-source-id: d54942bf1c69b5b0dcd4df629f1f2d5538c9e28c
2017-11-03 16:02:03 -07:00

71 lines
2.5 KiB
C++

/*
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#include "eden/fs/inodes/InodeBase.h"
#include <gtest/gtest.h>
#include "eden/fs/inodes/FileInode.h"
#include "eden/fs/inodes/TreeInode.h"
#include "eden/fs/testharness/FakeTreeBuilder.h"
#include "eden/fs/testharness/TestMount.h"
using namespace facebook::eden;
using folly::StringPiece;
using std::dynamic_pointer_cast;
TEST(InodeBase, getPath) {
FakeTreeBuilder builder;
builder.setFiles({
{"a/b/c/noop.c", "int main() { return 0; }\n"},
});
TestMount testMount{builder};
auto root = testMount.getEdenMount()->getRootInode();
EXPECT_EQ(RelativePathPiece(), root->getPath().value());
EXPECT_EQ("<root>", root->getLogPath());
auto getChild = [](const TreeInodePtr& parent, StringPiece name) {
return parent->getChildByName(PathComponentPiece{name}).get();
};
auto childTree = [&getChild](const TreeInodePtr& parent, StringPiece name) {
return getChild(parent, name).asTreePtr();
};
auto childFile = [&getChild](const TreeInodePtr& parent, StringPiece name) {
return getChild(parent, name).asFilePtr();
};
auto a = childTree(root, "a");
EXPECT_EQ(RelativePath{"a"}, a->getPath().value());
EXPECT_EQ("a", a->getLogPath());
auto ab = childTree(a, "b");
EXPECT_EQ(RelativePath{"a/b"}, ab->getPath().value());
EXPECT_EQ("a/b", ab->getLogPath());
auto abc = childTree(ab, "c");
EXPECT_EQ(RelativePath{"a/b/c"}, abc->getPath().value());
EXPECT_EQ("a/b/c", abc->getLogPath());
auto noopC = childFile(abc, "noop.c");
EXPECT_EQ(RelativePath{"a/b/c/noop.c"}, noopC->getPath().value());
EXPECT_EQ("a/b/c/noop.c", noopC->getLogPath());
// TODO: Test that the path gets updated after unlink() and rename()
// operations.
//
// Currently calling TreeInode::unlink() and TreeInode::rename() here does
// not work. (TreeInode::getChildByName() does not correctly register new
// inodes it creates in the EdenDispatcher's inode map. The unlink() and
// rename() operations require that the inode exist in the dispatcher map.)
//
// I am currently working on refactoring the inode map in a subsequent diff.
// My refactoring ensures that inodes always get registered correctly,
// regardless of how they are created. I'll come back and work on test cases
// here once my refactored InodeMap code lands.
}