sys_fs: Add unit tests

This commit is contained in:
Elad 2026-04-15 21:35:14 +03:00
parent 48acbbe4f5
commit a7c606c8ac
4 changed files with 54 additions and 0 deletions

View File

@ -187,6 +187,7 @@ if(BUILD_RPCS3_TESTS)
tests/test_tuple.cpp
tests/test_simple_array.cpp
tests/test_address_range.cpp
tests/test_sys_fs.cpp
tests/test_rsx_cfg.cpp
tests/test_rsx_fp_asm.cpp
tests/test_dmux_pamf.cpp

View File

@ -4,6 +4,7 @@
#include "Emu/Cell/ErrorCodes.h"
#include "Utilities/File.h"
#include "Utilities/StrUtil.h"
#include "Utilities/mutex.h"
#include <string>

View File

@ -100,6 +100,7 @@
<ClCompile Include="test_rsx_fp_asm.cpp" />
<ClCompile Include="test_simple_array.cpp" />
<ClCompile Include="test_address_range.cpp" />
<ClCompile Include="test_sys_fs.cpp" />
<ClCompile Include="test_tuple.cpp" />
<ClCompile Include="test_pair.cpp" />
</ItemGroup>

View File

@ -0,0 +1,51 @@
#include <gtest/gtest.h>
#define private public
#include "Emu/Cell/lv2/sys_fs.h"
#undef private
using namespace utils;
namespace utils
{
TEST(cellFs, PathRoot)
{
std::string path = "/.";
auto [root, trail] = lv2_fs_object::get_path_root_and_trail(path);
EXPECT_TRUE(root.empty());
EXPECT_TRUE(trail.empty());
path = "/./././dev_bdvd/./";
std::tie(root, trail) = lv2_fs_object::get_path_root_and_trail(path);
EXPECT_EQ(root, "dev_bdvd"sv);
EXPECT_TRUE(trail.empty());
path = "/../";
std::tie(root, trail) = lv2_fs_object::get_path_root_and_trail(path);
EXPECT_TRUE(root.empty());
EXPECT_EQ(trail, "ENOENT"sv);
}
TEST(cellFs, PathSimplify)
{
std::string path = "/dev_hdd0/";
auto [root, trail] = lv2_fs_object::get_path_root_and_trail(path);
EXPECT_EQ(root, "dev_hdd0"sv);
EXPECT_TRUE(trail.empty());
path = "/dev_hdd0/game";
std::tie(root, trail) = lv2_fs_object::get_path_root_and_trail(path);
EXPECT_EQ(root, "dev_hdd0"sv);
EXPECT_EQ(trail, "game"sv);
path = "/dev_hdd0/game/NP1234567";
std::tie(root, trail) = lv2_fs_object::get_path_root_and_trail(path);
EXPECT_EQ(root, "dev_hdd0"sv);
EXPECT_EQ(trail, "game/NP1234567"sv);
path = "/dev_hdd0/game/NP1234567/../../NP1234568/.";
std::tie(root, trail) = lv2_fs_object::get_path_root_and_trail(path);
EXPECT_EQ(root, "dev_hdd0"sv);
EXPECT_EQ(trail, "NP1234568"sv);
}
}