Skip to content

Commit

Permalink
UnitTests/FS: Add metadata tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leoetlino committed Jan 25, 2020
1 parent 142b7e0 commit 484cfb9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
10 changes: 10 additions & 0 deletions Source/Core/Core/IOS/FS/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ struct Modes
{
Mode owner, group, other;
};
inline bool operator==(const Modes& lhs, const Modes& rhs)
{
const auto fields = [](const Modes& obj) { return std::tie(obj.owner, obj.group, obj.other); };
return fields(lhs) == fields(rhs);
}

inline bool operator!=(const Modes& lhs, const Modes& rhs)
{
return !(lhs == rhs);
}

struct Metadata
{
Expand Down
25 changes: 16 additions & 9 deletions Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,18 @@ TEST_F(FileSystemTest, CreateFile)
{
const std::string PATH = "/tmp/f";

ASSERT_EQ(m_fs->CreateFile(Uid{0}, Gid{0}, PATH, 0, modes), ResultCode::Success);
constexpr u8 ArbitraryAttribute = 0xE1;

ASSERT_EQ(m_fs->CreateFile(Uid{0}, Gid{0}, PATH, ArbitraryAttribute, modes), ResultCode::Success);

const Result<Metadata> stats = m_fs->GetMetadata(Uid{0}, Gid{0}, PATH);
ASSERT_TRUE(stats.Succeeded());
EXPECT_TRUE(stats->is_file);
EXPECT_EQ(stats->size, 0u);
// TODO: After we start saving metadata correctly, check the UID, GID, permissions
// as well (issue 10234).
EXPECT_EQ(stats->uid, 0);
EXPECT_EQ(stats->gid, 0);
EXPECT_EQ(stats->modes, modes);
EXPECT_EQ(stats->attribute, ArbitraryAttribute);

ASSERT_EQ(m_fs->CreateFile(Uid{0}, Gid{0}, PATH, 0, modes), ResultCode::AlreadyExists);

Expand All @@ -72,21 +76,24 @@ TEST_F(FileSystemTest, CreateDirectory)
{
const std::string PATH = "/tmp/d";

ASSERT_EQ(m_fs->CreateDirectory(Uid{0}, Gid{0}, PATH, 0, modes), ResultCode::Success);
constexpr u8 ArbitraryAttribute = 0x20;

ASSERT_EQ(m_fs->CreateDirectory(Uid{0}, Gid{0}, PATH, ArbitraryAttribute, modes),
ResultCode::Success);

const Result<Metadata> stats = m_fs->GetMetadata(Uid{0}, Gid{0}, PATH);
ASSERT_TRUE(stats.Succeeded());
EXPECT_FALSE(stats->is_file);
// TODO: After we start saving metadata correctly, check the UID, GID, permissions
// as well (issue 10234).
EXPECT_EQ(stats->uid, 0);
EXPECT_EQ(stats->gid, 0);
EXPECT_EQ(stats->modes, modes);
EXPECT_EQ(stats->attribute, ArbitraryAttribute);

const Result<std::vector<std::string>> children = m_fs->ReadDirectory(Uid{0}, Gid{0}, PATH);
ASSERT_TRUE(children.Succeeded());
EXPECT_TRUE(children->empty());

// TODO: uncomment this after the FS code is fixed to return AlreadyExists.
// EXPECT_EQ(m_fs->CreateDirectory(Uid{0}, Gid{0}, PATH, 0, Mode::Read, Mode::None, Mode::None),
// ResultCode::AlreadyExists);
EXPECT_EQ(m_fs->CreateDirectory(Uid{0}, Gid{0}, PATH, 0, modes), ResultCode::AlreadyExists);
}

TEST_F(FileSystemTest, Delete)
Expand Down

0 comments on commit 484cfb9

Please sign in to comment.