mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-18 11:13:57 +00:00
Add working directory tests
This commit is contained in:
@@ -125,9 +125,8 @@ bool test_env()
|
||||
return !computername.empty() && blub == "LUL";
|
||||
}
|
||||
|
||||
bool test_io()
|
||||
bool test_file_path_io(const std::filesystem::path& filename)
|
||||
{
|
||||
const std::filesystem::path filename = "a.txt";
|
||||
std::error_code ec{};
|
||||
const auto absolute_file = std::filesystem::absolute(filename, ec);
|
||||
|
||||
@@ -146,6 +145,18 @@ bool test_io()
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool test_io()
|
||||
{
|
||||
const std::filesystem::path filename = "a.txt";
|
||||
|
||||
if (!test_file_path_io(filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
FILE* fp{};
|
||||
(void)fopen_s(&fp, filename.string().c_str(), "wb");
|
||||
|
||||
@@ -170,6 +181,43 @@ bool test_io()
|
||||
return text == buffer;
|
||||
}
|
||||
|
||||
bool test_working_directory()
|
||||
{
|
||||
std::error_code ec{};
|
||||
|
||||
const auto current_dir = std::filesystem::current_path(ec);
|
||||
if (ec)
|
||||
{
|
||||
puts("Failed to get current path");
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::filesystem::path sys32 = "C:/windows/system32";
|
||||
current_path(sys32, ec);
|
||||
|
||||
if (ec)
|
||||
{
|
||||
puts("Failed to update working directory");
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto new_current_dir = std::filesystem::current_path();
|
||||
if (sys32 != new_current_dir)
|
||||
{
|
||||
puts("Updated directory is wrong!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!std::ifstream("ntdll.dll"))
|
||||
{
|
||||
puts("Working directory is not active!");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::filesystem::current_path(current_dir);
|
||||
return std::filesystem::current_path() == current_dir;
|
||||
}
|
||||
|
||||
bool test_dir_io()
|
||||
{
|
||||
size_t count = 0;
|
||||
@@ -367,6 +415,7 @@ int main(const int argc, const char* argv[])
|
||||
|
||||
RUN_TEST(test_io, "I/O")
|
||||
RUN_TEST(test_dir_io, "Dir I/O")
|
||||
RUN_TEST(test_working_directory, "Working Directory")
|
||||
RUN_TEST(test_registry, "Registry")
|
||||
RUN_TEST(test_threads, "Threads")
|
||||
RUN_TEST(test_env, "Environment")
|
||||
|
||||
Reference in New Issue
Block a user