diff options
| author | Michael Kruse <llvm-project@meinersbur.de> | 2025-01-03 10:22:51 +0100 |
|---|---|---|
| committer | Michael Kruse <llvm-project@meinersbur.de> | 2025-01-03 10:22:51 +0100 |
| commit | 38500d63e14ce340236840f60d356cdefb56a52c (patch) | |
| tree | 17edbec446ce9b50d2f215a483b83afb293a635d /libc/test/src/strings/strcasecmp_test.cpp | |
| parent | 1a3d5daaef7a6a63448a497da3eff7fc9e23df26 (diff) | |
| parent | 27f30029741ecf023baece7b3dde1ff9011ffefc (diff) | |
Merge branch 'main' into users/meinersbur/flang_runtime_split-headersusers/meinersbur/flang_runtime_split-headers
Diffstat (limited to 'libc/test/src/strings/strcasecmp_test.cpp')
| -rw-r--r-- | libc/test/src/strings/strcasecmp_test.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/libc/test/src/strings/strcasecmp_test.cpp b/libc/test/src/strings/strcasecmp_test.cpp new file mode 100644 index 000000000000..cd29c213a732 --- /dev/null +++ b/libc/test/src/strings/strcasecmp_test.cpp @@ -0,0 +1,46 @@ +//===-- Unittests for strcasecmp ------------------------------------------===// +// +// 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 "src/strings/strcasecmp.h" +#include "test/UnitTest/Test.h" + +TEST(LlvmLibcStrCaseCmpTest, EmptyStringsShouldReturnZero) { + const char *s1 = ""; + const char *s2 = ""; + int result = LIBC_NAMESPACE::strcasecmp(s1, s2); + ASSERT_EQ(result, 0); + + // Verify operands reversed. + result = LIBC_NAMESPACE::strcasecmp(s2, s1); + ASSERT_EQ(result, 0); +} + +TEST(LlvmLibcStrCaseCmpTest, EmptyStringShouldNotEqualNonEmptyString) { + const char *empty = ""; + const char *s2 = "abc"; + int result = LIBC_NAMESPACE::strcasecmp(empty, s2); + // This should be '\0' - 'a' = -97 + ASSERT_LT(result, 0); + + // Similar case if empty string is second argument. + const char *s3 = "123"; + result = LIBC_NAMESPACE::strcasecmp(s3, empty); + // This should be '1' - '\0' = 49 + ASSERT_GT(result, 0); +} + +TEST(LlvmLibcStrCaseCmpTest, Case) { + const char *s1 = "aB"; + const char *s2 = "ab"; + int result = LIBC_NAMESPACE::strcasecmp(s1, s2); + ASSERT_EQ(result, 0); + + // Verify operands reversed. + result = LIBC_NAMESPACE::strcasecmp(s2, s1); + ASSERT_EQ(result, 0); +} |
