[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / libc / test / src / string / strerror_r_test.cpp
blob868362edd84b1136b212bef260fd2e7b814ed461
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 //===----------------------------------------------------------------------===//
9 #include "src/string/strerror_r.h"
10 #include "test/UnitTest/Test.h"
12 #include <stddef.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];
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');
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");