From ba0266417ee60a26d3f11bb3568349d397f83140 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Thu, 10 Nov 2016 14:02:17 +0100 Subject: [PATCH] tests: fs/FileReq/SymlinkAndUnlink and fs/FileReq/SymlinkAndUnlinkSync --- test/uvw/fs.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/test/uvw/fs.cpp b/test/uvw/fs.cpp index 742c6f54..dcc4e18a 100644 --- a/test/uvw/fs.cpp +++ b/test/uvw/fs.cpp @@ -884,17 +884,80 @@ TEST(FsReq, LinkAndUnlinkSync) { } -/* TEST(FsReq, SymlinkAndUnlink) { - // TODO + const std::string filename = std::string{TARGET_FS_DIR} + std::string{"/test.file"}; + const std::string linkname = std::string{TARGET_FS_DIR} + std::string{"/test.link"}; + + auto loop = uvw::Loop::getDefault(); + auto fileReq = loop->resource(); + auto fsReq = loop->resource(); + + bool checkFsLinkEvent = false; + bool checkFsUnlinkEvent = false; + + fsReq->on([](const auto &, auto &) { + FAIL(); + }); + + fsReq->on>([&checkFsUnlinkEvent](const auto &, auto &) { + ASSERT_FALSE(checkFsUnlinkEvent); + checkFsUnlinkEvent = true; + }); + + fsReq->on>([&checkFsLinkEvent, &linkname](const auto &, auto &request) { + ASSERT_FALSE(checkFsLinkEvent); + checkFsLinkEvent = true; + request.unlink(linkname); + }); + + fileReq->on([](const auto &, auto &) { + FAIL(); + }); + + fileReq->on>([&fsReq, &filename, &linkname](const auto &, auto &) { + fsReq->symlink(filename, linkname, 0); + }); + + fileReq->on>([](const auto &, auto &request) { + request.close(); + }); + +#ifdef _WIN32 + fileReq->open(filename, _O_CREAT | _O_RDWR | _O_TRUNC, 0644); +#else + fileReq->open(filename, O_CREAT | O_RDWR | O_TRUNC, 0644); +#endif + + loop->run(); + + ASSERT_TRUE(checkFsLinkEvent); + ASSERT_TRUE(checkFsUnlinkEvent); } TEST(FsReq, SymlinkAndUnlinkSync) { - // TODO + const std::string filename = std::string{TARGET_FS_DIR} + std::string{"/test.file"}; + const std::string linkname = std::string{TARGET_FS_DIR} + std::string{"/test.link"}; + + auto loop = uvw::Loop::getDefault(); + auto fileReq = loop->resource(); + auto fsReq = loop->resource(); + +#ifdef _WIN32 + ASSERT_TRUE(fileReq->openSync(filename, _O_CREAT | _O_RDWR | _O_TRUNC, 0644)); +#else + ASSERT_TRUE(fileReq->openSync(filename, O_CREAT | O_RDWR | O_TRUNC, 0644)); +#endif + + ASSERT_TRUE(fileReq->closeSync()); + ASSERT_TRUE(fsReq->symlinkSync(filename, linkname, 0)); + ASSERT_TRUE(fsReq->unlinkSync(linkname)); + + loop->run(); } +/* TEST(FsReq, Readlink) { // TODO }