[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / libc / test / src / string / strdup_test.cpp
blob20b85c37637dd1ed8ca0b0e6e3de0d38daa90781
1 //===-- Unittests for strdup ----------------------------------------------===//
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/errno/libc_errno.h"
10 #include "src/string/strdup.h"
11 #include "test/UnitTest/Test.h"
13 TEST(LlvmLibcStrDupTest, EmptyString) {
14 const char *empty = "";
16 LIBC_NAMESPACE::libc_errno = 0;
17 char *result = LIBC_NAMESPACE::strdup(empty);
18 ASSERT_ERRNO_SUCCESS();
20 ASSERT_NE(result, static_cast<char *>(nullptr));
21 ASSERT_NE(empty, const_cast<const char *>(result));
22 ASSERT_STREQ(empty, result);
23 ::free(result);
26 TEST(LlvmLibcStrDupTest, AnyString) {
27 const char *abc = "abc";
29 LIBC_NAMESPACE::libc_errno = 0;
30 char *result = LIBC_NAMESPACE::strdup(abc);
31 ASSERT_ERRNO_SUCCESS();
33 ASSERT_NE(result, static_cast<char *>(nullptr));
34 ASSERT_NE(abc, const_cast<const char *>(result));
35 ASSERT_STREQ(abc, result);
36 ::free(result);
39 TEST(LlvmLibcStrDupTest, NullPtr) {
40 LIBC_NAMESPACE::libc_errno = 0;
41 char *result = LIBC_NAMESPACE::strdup(nullptr);
42 ASSERT_ERRNO_SUCCESS();
44 ASSERT_EQ(result, static_cast<char *>(nullptr));