From b8345246dcc2121bcb6d1515a9341789de20199f Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Sun, 27 Oct 2024 09:04:05 -0500 Subject: First crack at file objects. --- test/test_directory.cpp | 45 +-------------------------------------------- 1 file changed, 1 insertion(+), 44 deletions(-) (limited to 'test/test_directory.cpp') diff --git a/test/test_directory.cpp b/test/test_directory.cpp index 2f69dab..e30dafb 100644 --- a/test/test_directory.cpp +++ b/test/test_directory.cpp @@ -18,8 +18,8 @@ #include "fud_array.hpp" #include "fud_c_file.hpp" #include "fud_directory.hpp" -#include "fud_memory.hpp" #include "fud_string.hpp" +#include "test_common.hpp" #include "gtest/gtest.h" #include @@ -30,49 +30,6 @@ namespace fud { -int unlink_cb(const char* fpath, const struct stat* sb_unused, int typeflag, struct FTW* ftwbuf) -{ - static_cast(sb_unused); - int retValue = remove(fpath); - - EXPECT_EQ(retValue, 0); - if (retValue != 0) { - perror(fpath); - } - - return retValue; -} - -FudStatus removeRecursive(const String& path) -{ - if (!path.utf8Valid()) { - return FudStatus::Utf8Invalid; - } - if (path.length() < 5) { - return FudStatus::ArgumentInvalid; - } - auto prefix{String::makeFromCString("/tmp/").takeOkay()}; - auto diffResult = compareMem(path.data(), path.length(), prefix.data(), prefix.length()); - if (diffResult.isError()) { - return FudStatus::ArgumentInvalid; - } - auto diff = diffResult.getOkay(); - if (diff != 0) { - return FudStatus::ArgumentInvalid; - } - constexpr int maxOpenFd = 64; - auto status = nftw(path.c_str(), unlink_cb, maxOpenFd, FTW_DEPTH | FTW_PHYS); - if (status == 0) { - return FudStatus::Success; - } - - if (errno == ENOENT) { - return FudStatus::Success; - } - - return FudStatus::Failure; -} - TEST(FudDirectory, Basic) { const auto testDirName{String::makeFromCString("/tmp/fud_directory_test").takeOkay()}; -- cgit v1.2.3