1 | //===-- Unittests for strerror --------------------------------------------===// |
2 | // |
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 |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "src/string/strerror_r.h" |
10 | #include "test/UnitTest/Test.h" |
11 | |
12 | #include <stddef.h> |
13 | |
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]; |
18 | buffer[0] = '\0'; |
19 | // If strerror_r returns a constant string, then it shouldn't affect the |
20 | // buffer. |
21 | ASSERT_STREQ(LIBC_NAMESPACE::strerror_r(0, buffer, BUFF_SIZE), "Success" ); |
22 | ASSERT_EQ(buffer[0], '\0'); |
23 | |
24 | // Else it should write the result to the provided buffer. |
25 | ASSERT_STREQ(LIBC_NAMESPACE::strerror_r(-1, buffer, BUFF_SIZE), |
26 | "Unknown error -1" ); |
27 | ASSERT_STREQ(buffer, "Unknown error -1" ); |
28 | } |
29 | |