1//===-- Unittests for strcasecmp ------------------------------------------===//
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//===----------------------------------------------------------------------===//
8
9#include "src/string/strcasecmp.h"
10#include "test/UnitTest/Test.h"
11
12TEST(LlvmLibcStrCaseCmpTest, EmptyStringsShouldReturnZero) {
13 const char *s1 = "";
14 const char *s2 = "";
15 int result = LIBC_NAMESPACE::strcasecmp(left: s1, right: s2);
16 ASSERT_EQ(result, 0);
17
18 // Verify operands reversed.
19 result = LIBC_NAMESPACE::strcasecmp(left: s2, right: s1);
20 ASSERT_EQ(result, 0);
21}
22
23TEST(LlvmLibcStrCaseCmpTest, EmptyStringShouldNotEqualNonEmptyString) {
24 const char *empty = "";
25 const char *s2 = "abc";
26 int result = LIBC_NAMESPACE::strcasecmp(left: empty, right: s2);
27 // This should be '\0' - 'a' = -97
28 ASSERT_LT(result, 0);
29
30 // Similar case if empty string is second argument.
31 const char *s3 = "123";
32 result = LIBC_NAMESPACE::strcasecmp(left: s3, right: empty);
33 // This should be '1' - '\0' = 49
34 ASSERT_GT(result, 0);
35}
36
37TEST(LlvmLibcStrCaseCmpTest, Case) {
38 const char *s1 = "aB";
39 const char *s2 = "ab";
40 int result = LIBC_NAMESPACE::strcasecmp(left: s1, right: s2);
41 ASSERT_EQ(result, 0);
42
43 // Verify operands reversed.
44 result = LIBC_NAMESPACE::strcasecmp(left: s2, right: s1);
45 ASSERT_EQ(result, 0);
46}
47

source code of libc/test/src/string/strcasecmp_test.cpp