Commit c880e31d authored by Victor Zverovich's avatar Victor Zverovich

Fix warnings.

parent a2cf54fc
...@@ -132,6 +132,18 @@ std::string ReadFile(fmt::StringRef filename) { ...@@ -132,6 +132,18 @@ std::string ReadFile(fmt::StringRef filename) {
content << out.rdbuf(); content << out.rdbuf();
return content.str(); return content.str();
} }
std::string GetSystemErrorMessage(int error_code) {
#ifndef _WIN32
return strerror(error_code);
#else
enum { BUFFER_SIZE = 200 };
char buffer[BUFFER_SIZE];
EXPECT_EQ(0, strerror_s(buffer, BUFFER_SIZE, error_code));
EXPECT_LT(std::strlen(buffer), BUFFER_SIZE - 1);
return buffer;
#endif
}
} }
TEST(UtilTest, Increment) { TEST(UtilTest, Increment) {
...@@ -235,7 +247,7 @@ TEST(UtilTest, StrError) { ...@@ -235,7 +247,7 @@ TEST(UtilTest, StrError) {
EXPECT_EQ(0, result); EXPECT_EQ(0, result);
std::size_t message_size = std::strlen(message); std::size_t message_size = std::strlen(message);
EXPECT_GE(BUFFER_SIZE - 1u, message_size); EXPECT_GE(BUFFER_SIZE - 1u, message_size);
EXPECT_STREQ(strerror(error_code), message); EXPECT_EQ(GetSystemErrorMessage(error_code), message);
result = StrError(error_code, message = buffer, message_size); result = StrError(error_code, message = buffer, message_size);
EXPECT_EQ(ERANGE, result); EXPECT_EQ(ERANGE, result);
} }
...@@ -284,7 +296,8 @@ void CheckThrowError(int error_code, FormatErrorMessage format, ...@@ -284,7 +296,8 @@ void CheckThrowError(int error_code, FormatErrorMessage format,
TEST(UtilTest, FormatSystemErrorMessage) { TEST(UtilTest, FormatSystemErrorMessage) {
fmt::Writer message; fmt::Writer message;
fmt::internal::FormatSystemErrorMessage(message, EDOM, "test"); fmt::internal::FormatSystemErrorMessage(message, EDOM, "test");
EXPECT_EQ(str(fmt::Format("test: {}") << strerror(EDOM)), fmt::str(message)); EXPECT_EQ(str(fmt::Format("test: {}")
<< GetSystemErrorMessage(EDOM)), fmt::str(message));
} }
TEST(UtilTest, SystemErrorSink) { TEST(UtilTest, SystemErrorSink) {
......
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