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