Fixed file_event_handlers test for windows

This commit is contained in:
gabime 2021-12-10 18:31:32 +02:00
parent 37cbab363e
commit 8715f51c61

View File

@ -110,48 +110,48 @@ TEST_CASE("file_event_handlers", "[file_helper]")
after_close
};
prepare_logdir();
spdlog::filename_t test_filename{TEST_FILENAME};
// define event handles that update vector of flags when called
std::vector<flags> events;
spdlog::file_event_handlers handlers;
handlers.before_open = [&](spdlog::filename_t filename) {
REQUIRE(filename == TEST_FILENAME);
REQUIRE(filename == test_filename);
events.push_back(flags::before_open);
};
handlers.after_open = [&](spdlog::filename_t filename, std::FILE *fstream) {
REQUIRE(filename == TEST_FILENAME);
handlers.after_open = [&](spdlog::filename_t filename, std::FILE* fstream) {
REQUIRE(filename == test_filename);
REQUIRE(fstream);
fputs("after_open\n", fstream);
events.push_back(flags::after_open);
};
handlers.before_close = [&](spdlog::filename_t filename, std::FILE *fstream) {
REQUIRE(filename == TEST_FILENAME);
handlers.before_close = [&](spdlog::filename_t filename, std::FILE* fstream) {
REQUIRE(filename == test_filename);
REQUIRE(fstream);
fputs("before_close\n", fstream);
fflush(fstream);
events.push_back(flags::before_close);
};
handlers.after_close = [&](spdlog::filename_t filename) {
REQUIRE(filename == TEST_FILENAME);
REQUIRE(filename == test_filename);
events.push_back(flags::after_close);
};
{
spdlog::details::file_helper helper{handlers};
REQUIRE(events.empty());
helper.open(TEST_FILENAME);
helper.open(test_filename);
REQUIRE(events == std::vector<flags>{flags::before_open, flags::after_open});
events.clear();
helper.close();
REQUIRE(events == std::vector<flags>{flags::before_close, flags::after_close});
REQUIRE(file_contents(TEST_FILENAME) == "after_open\nbefore_close\n");
REQUIRE(file_contents(test_filename) == "after_open\nbefore_close\n");
helper.reopen(true);
events.clear();
}
// make sure that the file_helper destrcutor calls the close callbacks if needed
REQUIRE(events == std::vector<flags>{flags::before_close, flags::after_close});
REQUIRE(file_contents(TEST_FILENAME) == "after_open\nbefore_close\n");
REQUIRE(file_contents(test_filename) == "after_open\nbefore_close\n");
}