This commit is contained in:
Владислав Щапов
2021-05-10 01:33:14 +05:00
committed by Victor Zverovich
parent 2a9b314627
commit 0036a1d195
4 changed files with 82 additions and 30 deletions

View File

@@ -45,7 +45,6 @@ void check_utf_conversion_error(
fmt::basic_string_view<Char> str = fmt::basic_string_view<Char>(0, 1)) {
fmt::memory_buffer out;
fmt::detail::format_windows_error(out, ERROR_INVALID_PARAMETER, message);
out.resize(out.size() - 2); // Remove newline.
auto error = std::system_error(std::error_code());
try {
(Converter)(str);
@@ -74,10 +73,10 @@ TEST(os_test, format_std_error_code) {
std::error_code(42, std::generic_category())));
EXPECT_EQ("system:42",
fmt::format(FMT_STRING("{0}"),
std::error_code(42, std::system_category())));
std::error_code(42, fmt::system_category())));
EXPECT_EQ("system:-42",
fmt::format(FMT_STRING("{0}"),
std::error_code(-42, std::system_category())));
std::error_code(-42, fmt::system_category())));
}
TEST(os_test, format_std_error_code_wide) {
@@ -86,10 +85,10 @@ TEST(os_test, format_std_error_code_wide) {
std::error_code(42, std::generic_category())));
EXPECT_EQ(L"system:42",
fmt::format(FMT_STRING(L"{0}"),
std::error_code(42, std::system_category())));
std::error_code(42, fmt::system_category())));
EXPECT_EQ(L"system:-42",
fmt::format(FMT_STRING(L"{0}"),
std::error_code(-42, std::system_category())));
std::error_code(-42, fmt::system_category())));
}
TEST(os_test, format_windows_error) {
@@ -99,7 +98,8 @@ TEST(os_test, format_windows_error) {
FORMAT_MESSAGE_IGNORE_INSERTS,
0, ERROR_FILE_EXISTS, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPWSTR>(&message), 0, 0);
fmt::detail::utf16_to_utf8 utf8_message(message);
fmt::detail::utf16_to_utf8 utf8_message(
fmt::wstring_view(message, result - 2));
LocalFree(message);
fmt::memory_buffer actual_message;
fmt::detail::format_windows_error(actual_message, ERROR_FILE_EXISTS, "test");
@@ -120,8 +120,12 @@ TEST(os_test, format_long_windows_error) {
0, static_cast<DWORD>(provisioning_not_allowed),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPWSTR>(&message), 0, 0);
EXPECT_NE(result, 0);
fmt::detail::utf16_to_utf8 utf8_message(message);
if (result == 0) {
LocalFree(message);
return;
}
fmt::detail::utf16_to_utf8 utf8_message(
fmt::wstring_view(message, result - 2));
LocalFree(message);
fmt::memory_buffer actual_message;
fmt::detail::format_windows_error(actual_message, provisioning_not_allowed,
@@ -139,7 +143,6 @@ TEST(os_test, windows_error) {
}
fmt::memory_buffer message;
fmt::detail::format_windows_error(message, ERROR_FILE_EXISTS, "test error");
message.resize(message.size() - 2);
EXPECT_THAT(error.what(), HasSubstr(to_string(message)));
EXPECT_EQ(ERROR_FILE_EXISTS, error.code().value());
}

View File

@@ -272,7 +272,7 @@ TEST(file_test, size) {
}
fstat_sim = none;
EXPECT_EQ(error_code,
std::error_code(ERROR_ACCESS_DENIED, std::system_category()));
std::error_code(ERROR_ACCESS_DENIED, fmt::system_category()));
# else
f.close();
EXPECT_SYSTEM_ERROR(f.size(), EBADF, "cannot get file attributes");