mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-26 10:31:34 +08:00
Fixed file_event_handlers test for windows
This commit is contained in:
parent
37cbab363e
commit
8715f51c61
@ -111,47 +111,47 @@ TEST_CASE("file_event_handlers", "[file_helper]")
|
|||||||
};
|
};
|
||||||
prepare_logdir();
|
prepare_logdir();
|
||||||
|
|
||||||
|
spdlog::filename_t test_filename{TEST_FILENAME};
|
||||||
// define event handles that update vector of flags when called
|
// define event handles that update vector of flags when called
|
||||||
std::vector<flags> events;
|
std::vector<flags> events;
|
||||||
spdlog::file_event_handlers handlers;
|
spdlog::file_event_handlers handlers;
|
||||||
handlers.before_open = [&](spdlog::filename_t filename) {
|
handlers.before_open = [&](spdlog::filename_t filename) {
|
||||||
REQUIRE(filename == TEST_FILENAME);
|
REQUIRE(filename == test_filename);
|
||||||
events.push_back(flags::before_open);
|
events.push_back(flags::before_open);
|
||||||
};
|
};
|
||||||
handlers.after_open = [&](spdlog::filename_t filename, std::FILE* fstream) {
|
handlers.after_open = [&](spdlog::filename_t filename, std::FILE* fstream) {
|
||||||
REQUIRE(filename == TEST_FILENAME);
|
REQUIRE(filename == test_filename);
|
||||||
REQUIRE(fstream);
|
REQUIRE(fstream);
|
||||||
fputs("after_open\n", fstream);
|
fputs("after_open\n", fstream);
|
||||||
events.push_back(flags::after_open);
|
events.push_back(flags::after_open);
|
||||||
};
|
};
|
||||||
handlers.before_close = [&](spdlog::filename_t filename, std::FILE* fstream) {
|
handlers.before_close = [&](spdlog::filename_t filename, std::FILE* fstream) {
|
||||||
REQUIRE(filename == TEST_FILENAME);
|
REQUIRE(filename == test_filename);
|
||||||
REQUIRE(fstream);
|
REQUIRE(fstream);
|
||||||
fputs("before_close\n", fstream);
|
fputs("before_close\n", fstream);
|
||||||
fflush(fstream);
|
|
||||||
events.push_back(flags::before_close);
|
events.push_back(flags::before_close);
|
||||||
};
|
};
|
||||||
handlers.after_close = [&](spdlog::filename_t filename) {
|
handlers.after_close = [&](spdlog::filename_t filename) {
|
||||||
REQUIRE(filename == TEST_FILENAME);
|
REQUIRE(filename == test_filename);
|
||||||
events.push_back(flags::after_close);
|
events.push_back(flags::after_close);
|
||||||
};
|
};
|
||||||
{
|
{
|
||||||
spdlog::details::file_helper helper{handlers};
|
spdlog::details::file_helper helper{handlers};
|
||||||
REQUIRE(events.empty());
|
REQUIRE(events.empty());
|
||||||
|
|
||||||
helper.open(TEST_FILENAME);
|
helper.open(test_filename);
|
||||||
REQUIRE(events == std::vector<flags>{flags::before_open, flags::after_open});
|
REQUIRE(events == std::vector<flags>{flags::before_open, flags::after_open});
|
||||||
|
|
||||||
events.clear();
|
events.clear();
|
||||||
helper.close();
|
helper.close();
|
||||||
REQUIRE(events == std::vector<flags>{flags::before_close, flags::after_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);
|
helper.reopen(true);
|
||||||
events.clear();
|
events.clear();
|
||||||
}
|
}
|
||||||
// make sure that the file_helper destrcutor calls the close callbacks if needed
|
// 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(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");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user