From c4a8783b7d1af729f39216197713488aefa8fc9d Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Thu, 10 Nov 2016 14:34:07 +0100 Subject: [PATCH] tests: fs/FileReq/Chown and fs/FileReq/ChownSync --- test/uvw/fs.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/test/uvw/fs.cpp b/test/uvw/fs.cpp index 3e118dd5..e3104d26 100644 --- a/test/uvw/fs.cpp +++ b/test/uvw/fs.cpp @@ -477,16 +477,64 @@ TEST(FileReq, UtimeSync) { } -/* TEST(FileReq, Chown) { - // TODO + const std::string filename = std::string{TARGET_FS_DIR} + std::string{"/test.file"}; + + auto loop = uvw::Loop::getDefault(); + auto request = loop->resource(); + + bool checkFileChownEvent = false; + + request->on([](const auto &, auto &) { + FAIL(); + }); + + request->on>([&checkFileChownEvent](const auto &, auto &request) { + ASSERT_FALSE(checkFileChownEvent); + checkFileChownEvent = true; + request.close(); + }); + + request->on>([](const auto &event, auto &request) { + request.chown(event.stat.st_uid, event.stat.st_gid); + }); + + request->on>([](const auto &, auto &request) { + request.stat(); + }); + +#ifdef _WIN32 + request->open(filename, _O_CREAT | _O_RDWR | _O_TRUNC, 0644); +#else + request->open(filename, O_CREAT | O_RDWR | O_TRUNC, 0644); +#endif + + loop->run(); + + ASSERT_TRUE(checkFileChownEvent); } TEST(FileReq, ChownSync) { - // TODO + const std::string filename = std::string{TARGET_FS_DIR} + std::string{"/test.file"}; + + auto loop = uvw::Loop::getDefault(); + auto request = loop->resource(); + +#ifdef _WIN32 + ASSERT_TRUE(request->openSync(filename, _O_CREAT | _O_RDWR | _O_TRUNC, 0644)); +#else + ASSERT_TRUE(request->openSync(filename, O_CREAT | O_RDWR | O_TRUNC, 0644)); +#endif + + auto statR = request->statSync(); + + ASSERT_TRUE(statR.first); + ASSERT_TRUE(request->chownSync(statR.second.st_uid, statR.second.st_gid)); + ASSERT_TRUE(request->closeSync()); + + loop->run(); } -*/ TEST(FsReq, MkdirAndRmdir) {