bug fixing + updated tests
This commit is contained in:
parent
ba0266417e
commit
5f857f8587
@ -808,13 +808,17 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sync [mktemp](http://linux.die.net/man/3/mkdtemp).
|
* @brief Sync [mktemp](http://linux.die.net/man/3/mkdtemp).
|
||||||
|
*
|
||||||
* @param tpl Template, as described in the official documentation.
|
* @param tpl Template, as described in the official documentation.
|
||||||
* @return True in case of success, false otherwise.
|
*
|
||||||
|
* @return A `std::pair` composed as it follows:
|
||||||
|
* * A boolean value that is true in case of success, false otherwise.
|
||||||
|
* * The actual path of the newly created directoy.
|
||||||
*/
|
*/
|
||||||
bool mkdtempSync(std::string tpl) {
|
std::pair<bool, const char *> mkdtempSync(std::string tpl) {
|
||||||
auto req = get();
|
auto req = get();
|
||||||
cleanupAndInvokeSync(&uv_fs_mkdtemp, parent(), req, tpl.data());
|
cleanupAndInvokeSync(&uv_fs_mkdtemp, parent(), req, tpl.data());
|
||||||
return !(req->result < 0);
|
return std::make_pair(!(req->result < 0), req->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -535,21 +535,28 @@ TEST(FsReq, MkdirAndRmdirSync) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(FsReq, Mkdtemp) {
|
TEST(FsReq, MkdtempAndRmdir) {
|
||||||
const std::string dirname = std::string{TARGET_FS_DIR} + std::string{"/test.dir.XXXXXX"};
|
const std::string dirname = std::string{TARGET_FS_DIR} + std::string{"/test.dir.XXXXXX"};
|
||||||
|
|
||||||
auto loop = uvw::Loop::getDefault();
|
auto loop = uvw::Loop::getDefault();
|
||||||
auto request = loop->resource<uvw::FsReq>();
|
auto request = loop->resource<uvw::FsReq>();
|
||||||
|
|
||||||
bool checkFsMkdtempEvent = false;
|
bool checkFsMkdtempEvent = false;
|
||||||
|
bool checkFsRmdirEvent = false;
|
||||||
|
|
||||||
request->on<uvw::ErrorEvent>([](const auto &, auto &) {
|
request->on<uvw::ErrorEvent>([](const auto &, auto &) {
|
||||||
FAIL();
|
FAIL();
|
||||||
});
|
});
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::MKDTEMP>>([&checkFsMkdtempEvent](const auto &, auto &) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::RMDIR>>([&checkFsRmdirEvent](const auto &, auto &) {
|
||||||
|
ASSERT_FALSE(checkFsRmdirEvent);
|
||||||
|
checkFsRmdirEvent = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
request->on<uvw::FsEvent<uvw::FileReq::Type::MKDTEMP>>([&checkFsMkdtempEvent](const auto &event, auto &request) {
|
||||||
ASSERT_FALSE(checkFsMkdtempEvent);
|
ASSERT_FALSE(checkFsMkdtempEvent);
|
||||||
checkFsMkdtempEvent = true;
|
checkFsMkdtempEvent = true;
|
||||||
|
request.rmdir(event.path);
|
||||||
});
|
});
|
||||||
|
|
||||||
request->mkdtemp(dirname);
|
request->mkdtemp(dirname);
|
||||||
@ -557,16 +564,20 @@ TEST(FsReq, Mkdtemp) {
|
|||||||
loop->run();
|
loop->run();
|
||||||
|
|
||||||
ASSERT_TRUE(checkFsMkdtempEvent);
|
ASSERT_TRUE(checkFsMkdtempEvent);
|
||||||
|
ASSERT_TRUE(checkFsRmdirEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(FsReq, MkdtempSync) {
|
TEST(FsReq, MkdtempAndRmdirSync) {
|
||||||
const std::string dirname = std::string{TARGET_FS_DIR} + std::string{"/test.dir.XXXXXX"};
|
const std::string dirname = std::string{TARGET_FS_DIR} + std::string{"/test.dir.XXXXXX"};
|
||||||
|
|
||||||
auto loop = uvw::Loop::getDefault();
|
auto loop = uvw::Loop::getDefault();
|
||||||
auto request = loop->resource<uvw::FsReq>();
|
auto request = loop->resource<uvw::FsReq>();
|
||||||
|
|
||||||
ASSERT_TRUE(request->mkdtempSync(dirname));
|
auto mkdtempR = request->mkdtempSync(dirname);
|
||||||
|
|
||||||
|
ASSERT_TRUE(mkdtempR.first);
|
||||||
|
ASSERT_TRUE(request->rmdirSync(mkdtempR.second));
|
||||||
|
|
||||||
loop->run();
|
loop->run();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user