From 55557006c7f7894dc8bb07366194258435dbe54e Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 8 Feb 2025 14:06:59 +0100 Subject: [PATCH] Add std::filesystem tests --- src/samples/test-sample/test.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/samples/test-sample/test.cpp b/src/samples/test-sample/test.cpp index 924bf305..480263c9 100644 --- a/src/samples/test-sample/test.cpp +++ b/src/samples/test-sample/test.cpp @@ -127,10 +127,27 @@ bool test_env() bool test_io() { - const auto* filename = "a.txt"; + const std::filesystem::path filename = "a.txt"; + std::error_code ec{}; + const auto absolute_file = std::filesystem::absolute(filename, ec); + + if (ec) + { + puts("Getting absolute path failed"); + return false; + } + + const auto canonical_file = std::filesystem::canonical(filename, ec); + (void)canonical_file; + + if (ec) + { + puts("Getting canonical path failed"); + return false; + } FILE* fp{}; - (void)fopen_s(&fp, filename, "wb"); + (void)fopen_s(&fp, filename.string().c_str(), "wb"); if (!fp) {