47 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/strings/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(s1, s2);16 ASSERT_EQ(result, 0);17 18 // Verify operands reversed.19 result = LIBC_NAMESPACE::strcasecmp(s2, 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(empty, s2);27 // This should be '\0' - 'a' = -9728 ASSERT_LT(result, 0);29 30 // Similar case if empty string is second argument.31 const char *s3 = "123";32 result = LIBC_NAMESPACE::strcasecmp(s3, empty);33 // This should be '1' - '\0' = 4934 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(s1, s2);41 ASSERT_EQ(result, 0);42 43 // Verify operands reversed.44 result = LIBC_NAMESPACE::strcasecmp(s2, s1);45 ASSERT_EQ(result, 0);46}47