Commit d3b17836 authored by Victor Zverovich's avatar Victor Zverovich

Fix test.

parent 0bece942
...@@ -281,34 +281,40 @@ TEST(UtilTest, SystemError) { ...@@ -281,34 +281,40 @@ TEST(UtilTest, SystemError) {
EXPECT_EQ(42, e.error_code()); EXPECT_EQ(42, e.error_code());
} }
#ifndef _WIN32 TEST(UtilTest, ThrowSystemError) {
const int TEST_ERROR = EDOM; const int TEST_ERROR = EDOM;
std::string GetTestErrorMessage() { return strerror(TEST_ERROR); } fmt::SystemError error("", 0);
#else try {
const int TEST_ERROR = ERROR_FILE_EXISTS; fmt::ThrowSystemError(TEST_ERROR, "test {}") << "error";
std::string GetTestErrorMessage() { } catch (const fmt::SystemError &e) {
LPWSTR message = 0; error = e;
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | }
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, EXPECT_EQ(str(fmt::Format("test error: {}") << strerror(TEST_ERROR)),
ERROR_FILE_EXISTS, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), error.what());
reinterpret_cast<LPWSTR>(&message), 0, 0); EXPECT_EQ(TEST_ERROR, error.error_code());
fmt::internal::UTF16ToUTF8 utf8_message(message);
LocalFree(message);
return fmt::str(utf8_message);
} }
#endif
TEST(UtilTest, ThrowSystemError) { #ifdef _WIN32
TEST(UtilTest, ThrowWinError) {
const int TEST_ERROR = ERROR_FILE_EXISTS;
fmt::SystemError error("", 0); fmt::SystemError error("", 0);
try { try {
fmt::ThrowSystemError(TEST_ERROR, "test {}") << "error"; fmt::ThrowSystemError(TEST_ERROR, "test {}") << "error";
} catch (const fmt::SystemError &e) { } catch (const fmt::SystemError &e) {
error = e; error = e;
} }
EXPECT_EQ(str(fmt::Format("test error: {}") << GetTestErrorMessage()), LPWSTR message = 0;
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0,
ERROR_FILE_EXISTS, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPWSTR>(&message), 0, 0);
fmt::internal::UTF16ToUTF8 utf8_message(message);
LocalFree(message);
EXPECT_EQ(str(fmt::Format("test error: {}") << fmt::str(utf8_message)),
error.what()); error.what());
EXPECT_EQ(TEST_ERROR, error.error_code()); EXPECT_EQ(TEST_ERROR, error.error_code());
} }
#endif
class TestString { class TestString {
private: private:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment