tests
This commit is contained in:
parent
60f5d7124d
commit
34119bfcd2
@ -2,32 +2,36 @@
|
||||
#include <uvw.hpp>
|
||||
|
||||
|
||||
TEST(FsEvent, StartAndStop) {
|
||||
const std::string dirname = std::string{TARGET_FS_EVENT_DIR};
|
||||
TEST(FsEvent, Functionalities) {
|
||||
const std::string relative = std::string{"test.file"};
|
||||
const std::string absolute = std::string{TARGET_FS_EVENT_DIR} + "/" + relative;
|
||||
const std::string rename = std::string{TARGET_FS_EVENT_DIR} + std::string{"/test.rename"};
|
||||
|
||||
auto loop = uvw::Loop::getDefault();
|
||||
auto handle = loop->resource<uvw::FsEventHandle>();
|
||||
auto req = loop->resource<uvw::FsReq>();
|
||||
auto fileReq = loop->resource<uvw::FileReq>();
|
||||
auto fsReq = loop->resource<uvw::FsReq>();
|
||||
|
||||
bool checkFsEventEvent = false;
|
||||
|
||||
req->mkdirSync(dirname, 0755);
|
||||
|
||||
handle->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
||||
req->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
||||
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
||||
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
||||
|
||||
handle->on<uvw::FsEventEvent>([&checkFsEventEvent, &dirname](const auto &, auto &hndl) {
|
||||
handle->on<uvw::FsEventEvent>([&checkFsEventEvent, &relative](const auto &event, auto &hndl) {
|
||||
ASSERT_FALSE(checkFsEventEvent);
|
||||
ASSERT_EQ(std::string{event.filename}, relative);
|
||||
checkFsEventEvent = true;
|
||||
hndl.stop();
|
||||
hndl.close();
|
||||
ASSERT_TRUE(hndl.closing());
|
||||
});
|
||||
|
||||
req->rmdir(dirname);
|
||||
handle->start(dirname);
|
||||
fileReq->openSync(absolute, O_CREAT | O_RDWR | O_TRUNC, 0644);
|
||||
fsReq->rename(absolute, rename);
|
||||
handle->start(absolute);
|
||||
|
||||
ASSERT_EQ(handle->path(), dirname);
|
||||
ASSERT_EQ(handle->path(), absolute);
|
||||
ASSERT_TRUE(handle->active());
|
||||
ASSERT_FALSE(handle->closing());
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user