From e103e569631fac8bb3c12159bad446d7ad4205e7 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Thu, 19 Jan 2017 12:22:38 +0100 Subject: [PATCH] added tests for file reqs --- test/uvw/file_req.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/uvw/file_req.cpp b/test/uvw/file_req.cpp index ea04a373..58443c57 100644 --- a/test/uvw/file_req.cpp +++ b/test/uvw/file_req.cpp @@ -8,6 +8,49 @@ #endif +TEST(FileReq, OpenAndCloseErr) { + const std::string filename = std::string{TARGET_FILE_REQ_DIR} + std::string{"/err.file"}; + + auto loop = uvw::Loop::getDefault(); + auto openReq = loop->resource(); + auto closeReq = loop->resource(); + + bool checkFileOpenErrorEvent = false; + bool checkFileCloseErrorEvent = false; + + openReq->on([&checkFileOpenErrorEvent](const auto &, auto &) { + ASSERT_FALSE(checkFileOpenErrorEvent); + checkFileOpenErrorEvent = true; + }); + + closeReq->on([&checkFileCloseErrorEvent](const auto &, auto &) { + ASSERT_FALSE(checkFileCloseErrorEvent); + checkFileCloseErrorEvent = true; + }); + + openReq->open(filename, O_RDONLY, 0644); + closeReq->close(); + + loop->run(); + + ASSERT_TRUE(checkFileOpenErrorEvent); + ASSERT_TRUE(checkFileCloseErrorEvent); +} + + +TEST(FileReq, OpenErrSync) { + const std::string filename = std::string{TARGET_FILE_REQ_DIR} + std::string{"/err.file"}; + + auto loop = uvw::Loop::getDefault(); + auto request = loop->resource(); + + ASSERT_FALSE(request->openSync(filename, O_RDONLY, 0644)); + ASSERT_FALSE(request->closeSync()); + + loop->run(); +} + + TEST(FileReq, OpenAndClose) { const std::string filename = std::string{TARGET_FILE_REQ_DIR} + std::string{"/test.file"};