From 484cfb93288ee593d860e824ee466dc244f72ceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 29 Dec 2019 15:42:16 +0100 Subject: [PATCH] UnitTests/FS: Add metadata tests --- Source/Core/Core/IOS/FS/FileSystem.h | 10 ++++++++ .../UnitTests/Core/IOS/FS/FileSystemTest.cpp | 25 ++++++++++++------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Source/Core/Core/IOS/FS/FileSystem.h b/Source/Core/Core/IOS/FS/FileSystem.h index 8b4b59a858..3b3c8e9ede 100644 --- a/Source/Core/Core/IOS/FS/FileSystem.h +++ b/Source/Core/Core/IOS/FS/FileSystem.h @@ -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 { diff --git a/Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp b/Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp index 3a4f443139..c84caf6f6a 100644 --- a/Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp +++ b/Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp @@ -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 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); @@ -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 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> 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)