diff options
| author | Siva Chandra Reddy <sivachandra@google.com> | 2020-01-03 12:00:45 -0800 |
|---|---|---|
| committer | Siva Chandra Reddy <sivachandra@google.com> | 2020-01-06 10:14:43 -0800 |
| commit | 5b24c088171d3bd7a8ff559c82926e5d4b04f032 (patch) | |
| tree | 54ac5d666fef87a0e6337e388f6f5087c18e9ef9 /libc/test/src/string | |
| parent | 0239526cccf8aa708e29eeb7e49de8f6dc6c1a5f (diff) | |
| download | bcm5719-llvm-5b24c088171d3bd7a8ff559c82926e5d4b04f032.tar.gz bcm5719-llvm-5b24c088171d3bd7a8ff559c82926e5d4b04f032.zip | |
[libc] Move all tests to a top level `test` directory.
A toplevel target, `check-libc` has also been added.
Reviewers: abrachet, phosek
Tags: #libc-project
Differential Revision: https://reviews.llvm.org/D72177
Diffstat (limited to 'libc/test/src/string')
| -rw-r--r-- | libc/test/src/string/CMakeLists.txt | 23 | ||||
| -rw-r--r-- | libc/test/src/string/strcat_test.cpp | 39 | ||||
| -rw-r--r-- | libc/test/src/string/strcpy_test.cpp | 36 |
3 files changed, 98 insertions, 0 deletions
diff --git a/libc/test/src/string/CMakeLists.txt b/libc/test/src/string/CMakeLists.txt new file mode 100644 index 00000000000..bc5c088d169 --- /dev/null +++ b/libc/test/src/string/CMakeLists.txt @@ -0,0 +1,23 @@ +add_custom_target(libc_string_unittests) +add_dependencies(check_libc libc_string_unittests) + +add_libc_unittest( + strcat_test + SUITE + libc_string_unittests + SRCS + strcat_test.cpp + DEPENDS + strcat + strcpy +) + +add_libc_unittest( + strcpy_test + SUITE + libc_string_unittests + SRCS + strcpy_test.cpp + DEPENDS + strcpy +) diff --git a/libc/test/src/string/strcat_test.cpp b/libc/test/src/string/strcat_test.cpp new file mode 100644 index 00000000000..3b8a7a7e447 --- /dev/null +++ b/libc/test/src/string/strcat_test.cpp @@ -0,0 +1,39 @@ +//===---------------------- Unittests for strcat --------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <string> + +#include "src/string/strcat/strcat.h" +#include "gtest/gtest.h" + +TEST(StrCatTest, EmptyDest) { + std::string abc = "abc"; + char dest[4]; + + dest[0] = '\0'; + + char *result = __llvm_libc::strcat(dest, abc.c_str()); + ASSERT_EQ(dest, result); + ASSERT_EQ(std::string(dest), abc); + ASSERT_EQ(std::string(dest).size(), abc.size()); +} + +TEST(StrCatTest, NonEmptyDest) { + std::string abc = "abc"; + char dest[7]; + + dest[0] = 'x'; + dest[1] = 'y'; + dest[2] = 'z'; + dest[3] = '\0'; + + char *result = __llvm_libc::strcat(dest, abc.c_str()); + ASSERT_EQ(dest, result); + ASSERT_EQ(std::string(dest), std::string("xyz") + abc); + ASSERT_EQ(std::string(dest).size(), abc.size() + 3); +} diff --git a/libc/test/src/string/strcpy_test.cpp b/libc/test/src/string/strcpy_test.cpp new file mode 100644 index 00000000000..e68ea5103db --- /dev/null +++ b/libc/test/src/string/strcpy_test.cpp @@ -0,0 +1,36 @@ +//===----------------------- Unittests for strcpy -------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <string> + +#include "src/string/strcpy/strcpy.h" +#include "gtest/gtest.h" + +TEST(StrCpyTest, EmptyDest) { + std::string abc = "abc"; + char dest[4]; + + char *result = __llvm_libc::strcpy(dest, abc.c_str()); + ASSERT_EQ(dest, result); + ASSERT_EQ(std::string(dest), abc); + ASSERT_EQ(std::string(dest).size(), abc.size()); +} + +TEST(StrCpyTest, OffsetDest) { + std::string abc = "abc"; + char dest[7]; + + dest[0] = 'x'; + dest[1] = 'y'; + dest[2] = 'z'; + + char *result = __llvm_libc::strcpy(dest + 3, abc.c_str()); + ASSERT_EQ(dest + 3, result); + ASSERT_EQ(std::string(dest), std::string("xyz") + abc); + ASSERT_EQ(std::string(dest).size(), abc.size() + 3); +} |

