Improving test coverage [adding FsReq::readdir]

This commit is contained in:
Stefano Fiorentino 2020-03-25 10:37:57 +01:00 committed by Michele Caini
parent fe73fa048a
commit 216f5f4da1

View File

@ -765,3 +765,40 @@ TEST(FsReq, LchownSync) {
loop->run();
}
TEST(FsReq, ReadDir) {
const std::string dir_name = std::string{TARGET_FS_REQ_DIR};
auto loop = uvw::Loop::getDefault();
auto fsReq = loop->resource<uvw::FsReq>();
bool checkFsReadDirEvent = false;
bool checkFsOpenDirEvent = false;
bool checkFsCloseDirEvent = false;
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::CLOSEDIR>>([&checkFsCloseDirEvent](const auto &, auto &) {
ASSERT_FALSE(checkFsCloseDirEvent);
checkFsCloseDirEvent = true;
});
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::READDIR>>([&checkFsReadDirEvent](const auto &, auto &hndl) {
ASSERT_FALSE(checkFsReadDirEvent);
checkFsReadDirEvent = true;
hndl.closedir();
});
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::OPENDIR>>([&checkFsOpenDirEvent](const auto &, auto &hndl) {
ASSERT_FALSE(checkFsOpenDirEvent);
checkFsOpenDirEvent = true;
hndl.readdir();
});
fsReq->opendir(dir_name);
loop->run();
ASSERT_TRUE(checkFsCloseDirEvent);
ASSERT_TRUE(checkFsReadDirEvent);
ASSERT_TRUE(checkFsOpenDirEvent);
}