1*65bb6593SMichael Jones //===-- Unittests for strdup ----------------------------------------------===//
2*65bb6593SMichael Jones //
3*65bb6593SMichael Jones // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*65bb6593SMichael Jones // See https://llvm.org/LICENSE.txt for license information.
5*65bb6593SMichael Jones // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*65bb6593SMichael Jones //
7*65bb6593SMichael Jones //===----------------------------------------------------------------------===//
8*65bb6593SMichael Jones
9*65bb6593SMichael Jones #include "src/string/strdup.h"
10*65bb6593SMichael Jones #include "utils/UnitTest/Test.h"
11*65bb6593SMichael Jones #include <stdlib.h>
12*65bb6593SMichael Jones
TEST(LlvmLibcStrDupTest,EmptyString)13*65bb6593SMichael Jones TEST(LlvmLibcStrDupTest, EmptyString) {
14*65bb6593SMichael Jones const char *empty = "";
15*65bb6593SMichael Jones
16*65bb6593SMichael Jones char *result = __llvm_libc::strdup(empty);
17*65bb6593SMichael Jones ASSERT_NE(result, static_cast<char *>(nullptr));
18*65bb6593SMichael Jones ASSERT_NE(empty, const_cast<const char *>(result));
19*65bb6593SMichael Jones ASSERT_STREQ(empty, result);
20*65bb6593SMichael Jones ::free(result);
21*65bb6593SMichael Jones }
22*65bb6593SMichael Jones
TEST(LlvmLibcStrDupTest,AnyString)23*65bb6593SMichael Jones TEST(LlvmLibcStrDupTest, AnyString) {
24*65bb6593SMichael Jones const char *abc = "abc";
25*65bb6593SMichael Jones
26*65bb6593SMichael Jones char *result = __llvm_libc::strdup(abc);
27*65bb6593SMichael Jones
28*65bb6593SMichael Jones ASSERT_NE(result, static_cast<char *>(nullptr));
29*65bb6593SMichael Jones ASSERT_NE(abc, const_cast<const char *>(result));
30*65bb6593SMichael Jones ASSERT_STREQ(abc, result);
31*65bb6593SMichael Jones ::free(result);
32*65bb6593SMichael Jones }
33*65bb6593SMichael Jones
TEST(LlvmLibcStrDupTest,NullPtr)34*65bb6593SMichael Jones TEST(LlvmLibcStrDupTest, NullPtr) {
35*65bb6593SMichael Jones
36*65bb6593SMichael Jones char *result = __llvm_libc::strdup(nullptr);
37*65bb6593SMichael Jones
38*65bb6593SMichael Jones ASSERT_EQ(result, static_cast<char *>(nullptr));
39*65bb6593SMichael Jones }
40