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

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