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 "hdr/signal_macros.h" |
10 | #include "src/string/strcoll.h" |
11 | #include "test/UnitTest/Test.h" |
12 | |
13 | // TODO: Add more comprehensive tests once locale support is added. |
14 | |
15 | TEST(LlvmLibcStrcollTest, SimpleTest) { |
16 | const char *s1 = "abc"; |
17 | const char *s2 = "abc"; |
18 | const char *s3 = "def"; |
19 | int result = LIBC_NAMESPACE::strcoll(s1, s2); |
20 | ASSERT_EQ(result, 0); |
21 | |
22 | // Verify operands reversed. |
23 | result = LIBC_NAMESPACE::strcoll(s2, s1); |
24 | ASSERT_EQ(result, 0); |
25 | |
26 | result = LIBC_NAMESPACE::strcoll(s1, s3); |
27 | ASSERT_LT(result, 0); |
28 | |
29 | result = LIBC_NAMESPACE::strcoll(s3, s1); |
30 | ASSERT_GT(result, 0); |
31 | } |
32 | |
33 | #if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) |
34 | |
35 | TEST(LlvmLibcStrcollTest, CrashOnNullPtr) { |
36 | ASSERT_DEATH([]() { LIBC_NAMESPACE::strcoll(nullptr, nullptr); }, |
37 | WITH_SIGNAL(-1)); |
38 | } |
39 | |
40 | #endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) |
41 |