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