|
2 | 2 | #include <uvw.hpp> |
3 | 3 |
|
4 | 4 |
|
5 | | -TEST(FsEvent, StartAndStop) { |
6 | | - const std::string dirname = std::string{TARGET_FS_EVENT_DIR}; |
| 5 | +TEST(FsEvent, Functionalities) { |
| 6 | + const std::string relative = std::string{"test.file"}; |
| 7 | + const std::string absolute = std::string{TARGET_FS_EVENT_DIR} + "/" + relative; |
| 8 | + const std::string rename = std::string{TARGET_FS_EVENT_DIR} + std::string{"/test.rename"}; |
7 | 9 |
|
8 | 10 | auto loop = uvw::Loop::getDefault(); |
9 | 11 | auto handle = loop->resource<uvw::FsEventHandle>(); |
10 | | - auto req = loop->resource<uvw::FsReq>(); |
| 12 | + auto fileReq = loop->resource<uvw::FileReq>(); |
| 13 | + auto fsReq = loop->resource<uvw::FsReq>(); |
11 | 14 |
|
12 | 15 | bool checkFsEventEvent = false; |
13 | 16 |
|
14 | | - req->mkdirSync(dirname, 0755); |
15 | | - |
16 | 17 | handle->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); }); |
17 | | - req->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); }); |
| 18 | + fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); }); |
| 19 | + fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); }); |
18 | 20 |
|
19 | | - handle->on<uvw::FsEventEvent>([&checkFsEventEvent, &dirname](const auto &, auto &hndl) { |
| 21 | + handle->on<uvw::FsEventEvent>([&checkFsEventEvent, &relative](const auto &event, auto &hndl) { |
20 | 22 | ASSERT_FALSE(checkFsEventEvent); |
| 23 | + ASSERT_EQ(std::string{event.filename}, relative); |
21 | 24 | checkFsEventEvent = true; |
22 | 25 | hndl.stop(); |
23 | 26 | hndl.close(); |
24 | 27 | ASSERT_TRUE(hndl.closing()); |
25 | 28 | }); |
26 | 29 |
|
27 | | - req->rmdir(dirname); |
28 | | - handle->start(dirname); |
| 30 | + fileReq->openSync(absolute, O_CREAT | O_RDWR | O_TRUNC, 0644); |
| 31 | + fsReq->rename(absolute, rename); |
| 32 | + handle->start(absolute); |
29 | 33 |
|
30 | | - ASSERT_EQ(handle->path(), dirname); |
| 34 | + ASSERT_EQ(handle->path(), absolute); |
31 | 35 | ASSERT_TRUE(handle->active()); |
32 | 36 | ASSERT_FALSE(handle->closing()); |
33 | 37 |
|
|
0 commit comments