From 2f90c47d035ab86fe043d7287dc924d14788991b Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 11 Sep 2018 22:17:01 +0300 Subject: [PATCH] Add explicit walk_path test. GitOrigin-RevId: ec04003641d149168abe0b8c09af056ce50f48b6 --- tdutils/td/utils/port/path.h | 4 ++-- tdutils/test/port.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tdutils/td/utils/port/path.h b/tdutils/td/utils/port/path.h index c1e7151db..9fef36109 100644 --- a/tdutils/td/utils/port/path.h +++ b/tdutils/td/utils/port/path.h @@ -50,7 +50,7 @@ Result> mkstemp(CSlice dir) TD_WARN_UNUSED_RESULT; Result mkdtemp(CSlice dir, Slice prefix) TD_WARN_UNUSED_RESULT; template -Status walk_path(CSlice path, Func &func) TD_WARN_UNUSED_RESULT; +Status walk_path(CSlice path, Func &&func) TD_WARN_UNUSED_RESULT; #if TD_PORT_POSIX @@ -221,7 +221,7 @@ Status walk_path(CSlice path, Func &&func) { path_slice.remove_suffix(1); wpath.pop_back(); } - return detail::walk_path_dir(wpath.c_str(), func); + return detail::walk_path_dir(wpath.c_str(), std::forward(func)); } #endif diff --git a/tdutils/test/port.cpp b/tdutils/test/port.cpp index 95c0d2a2a..d4122391f 100644 --- a/tdutils/test/port.cpp +++ b/tdutils/test/port.cpp @@ -16,6 +16,7 @@ using namespace td; TEST(Port, files) { CSlice main_dir = "test_dir"; rmrf(main_dir).ignore(); + ASSERT_TRUE(FileFd::open(main_dir, FileFd::Write).is_error()); mkdir(main_dir).ensure(); mkdir(PSLICE() << main_dir << TD_DIR_SLASH << "A").ensure(); mkdir(PSLICE() << main_dir << TD_DIR_SLASH << "B").ensure(); @@ -24,6 +25,19 @@ TEST(Port, files) { std::string fd_path = PSTRING() << main_dir << TD_DIR_SLASH << "t.txt"; auto fd = FileFd::open(fd_path, FileFd::Write | FileFd::CreateNew).move_as_ok(); + + int cnt = 0; + const int ITER_COUNT = 1000; + for (int i = 0; i < ITER_COUNT; i++) { + walk_path(main_dir, [&](CSlice name, bool is_directory) { + if (!is_directory) { + ASSERT_EQ(fd_path, name); + } + cnt++; + }); + } + ASSERT_EQ(4 * ITER_COUNT, cnt); + ASSERT_EQ(0u, fd.get_size()); ASSERT_EQ(12u, fd.write("Hello world!").move_as_ok()); ASSERT_EQ(4u, fd.pwrite("abcd", 1).move_as_ok());