xref: /aosp_15_r20/external/llvm-libc/test/src/string/strcoll_test.cpp (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
1 //===-- Unittests for strcoll ---------------------------------------------===//
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/strcoll.h"
10 #include "test/UnitTest/Test.h"
11 
12 // TODO: Add more comprehensive tests once locale support is added.
13 
TEST(LlvmLibcStrcollTest,SimpleTest)14 TEST(LlvmLibcStrcollTest, SimpleTest) {
15   const char *s1 = "abc";
16   const char *s2 = "abc";
17   const char *s3 = "def";
18   int result = LIBC_NAMESPACE::strcoll(s1, s2);
19   ASSERT_EQ(result, 0);
20 
21   // Verify operands reversed.
22   result = LIBC_NAMESPACE::strcoll(s2, s1);
23   ASSERT_EQ(result, 0);
24 
25   result = LIBC_NAMESPACE::strcoll(s1, s3);
26   ASSERT_LT(result, 0);
27 
28   result = LIBC_NAMESPACE::strcoll(s3, s1);
29   ASSERT_GT(result, 0);
30 }
31