Files
FEX-Emu--FEX/FEXCore/unittests/APITests/FileLoading.cpp
T
Ryan Houdek b15f0b5d36 FEXCore/FileLoading: Updates helper to load file that is backed by memory
When attempting to read files that aren't backed by a filesystem then
our current read file helpers fail since they query the file size
upfront.

Change the helper so that it doesn't query the size and just reads the file if it
can be opened. This lets us read `/proc/self/maps` using helpers.
2023-11-03 07:01:39 -07:00

23 lines
626 B
C++

#include <FEXCore/Utils/FileLoading.h>
#include <catch2/catch.hpp>
TEST_CASE("LoadFile-Doesn'tExist") {
fextl::string MapsFile;
auto Read = FEXCore::FileLoading::LoadFile(MapsFile, "/tmp/a/b/c/d/e/z");
REQUIRE(MapsFile.size() == 0);
REQUIRE(Read == false);
}
TEST_CASE("LoadFile-procfs") {
fextl::string MapsFile;
FEXCore::FileLoading::LoadFile(MapsFile, "/proc/self/maps");
REQUIRE(MapsFile.size() != 0);
}
TEST_CASE("LoadFile-Buffer") {
fextl::string MapsFile;
MapsFile.resize(16);
auto Read = FEXCore::FileLoading::LoadFileToBuffer("/proc/self/maps", MapsFile);
REQUIRE(MapsFile.size() == Read);
}