summaryrefslogtreecommitdiff
path: root/test/test_directory.cpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-10-27 09:04:05 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-10-27 09:04:05 -0500
commitb8345246dcc2121bcb6d1515a9341789de20199f (patch)
tree4a25857512a90ff38e8a40166c54694b74920216 /test/test_directory.cpp
parentf84b8259f6e980fed647d8e1ec0634f89ee59c06 (diff)
First crack at file objects.
Diffstat (limited to 'test/test_directory.cpp')
-rw-r--r--test/test_directory.cpp45
1 files changed, 1 insertions, 44 deletions
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 <algorithm>
@@ -30,49 +30,6 @@
namespace fud {
-int unlink_cb(const char* fpath, const struct stat* sb_unused, int typeflag, struct FTW* ftwbuf)
-{
- static_cast<void>(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()};