added tests for file reqs

This commit is contained in:
Michele Caini 2017-01-19 12:22:38 +01:00
parent e60b68f05f
commit e103e56963

View File

@ -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<uvw::FileReq>();
auto closeReq = loop->resource<uvw::FileReq>();
bool checkFileOpenErrorEvent = false;
bool checkFileCloseErrorEvent = false;
openReq->on<uvw::ErrorEvent>([&checkFileOpenErrorEvent](const auto &, auto &) {
ASSERT_FALSE(checkFileOpenErrorEvent);
checkFileOpenErrorEvent = true;
});
closeReq->on<uvw::ErrorEvent>([&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<uvw::FileReq>();
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"};