1 //===-- Unittests for strerror --------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/string/strerror_r.h"
10 #include "test/UnitTest/Test.h"
14 // This tests the gnu variant of strerror_r (which returns a char*).
15 TEST(LlvmLibcStrErrorRTest
, GnuVariantTests
) {
16 const size_t BUFF_SIZE
= 128;
17 char buffer
[BUFF_SIZE
];
19 // If strerror_r returns a constant string, then it shouldn't affect the
21 ASSERT_STREQ(LIBC_NAMESPACE::strerror_r(0, buffer
, BUFF_SIZE
), "Success");
22 ASSERT_EQ(buffer
[0], '\0');
24 // Else it should write the result to the provided buffer.
25 ASSERT_STREQ(LIBC_NAMESPACE::strerror_r(-1, buffer
, BUFF_SIZE
),
27 ASSERT_STREQ(buffer
, "Unknown error -1");