Add a portable thread-safe version of strerror.

This commit is contained in:
Victor Zverovich
2014-04-30 09:42:48 -07:00
parent 5019b6b0f4
commit 2c6372d790
3 changed files with 46 additions and 1 deletions

View File

@@ -248,6 +248,22 @@ TEST(UtilTest, UTF8ToUTF16) {
// TODO: test UTF16ToUTF8::Convert
#endif // _WIN32
TEST(UtilTest, StrError) {
using fmt::internal::StrError;
EXPECT_DEBUG_DEATH(StrError(EDOM, 0, 0), "Assertion");
char buffer[BUFFER_SIZE];
EXPECT_DEBUG_DEATH(StrError(EDOM, buffer, 0), "Assertion");
buffer[0] = 'x';
const char *message = StrError(-1, buffer, 1);
EXPECT_EQ(ERANGE, errno);
EXPECT_STREQ("", message);
message = StrError(-1, buffer, BUFFER_SIZE);
EXPECT_EQ(0, errno);
EXPECT_GE(BUFFER_SIZE - 1, std::strlen(message));
message = StrError(-1, buffer, std::strlen(message));
EXPECT_EQ(ERANGE, errno);
}
class TestString {
private:
std::string value_;