1 //===-- Unittests for memcmp ----------------------------------------------===//
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/memcmp.h"
10 #include "utils/UnitTest/Test.h"
11 
12 TEST(LlvmLibcMemcmpTest, CmpZeroByte) {
13   const char *lhs = "ab";
14   const char *rhs = "bc";
15   EXPECT_EQ(__llvm_libc::memcmp(lhs, rhs, 0), 0);
16 }
17 
18 TEST(LlvmLibcMemcmpTest, LhsRhsAreTheSame) {
19   const char *lhs = "ab";
20   const char *rhs = "ab";
21   EXPECT_EQ(__llvm_libc::memcmp(lhs, rhs, 2), 0);
22 }
23 
24 TEST(LlvmLibcMemcmpTest, LhsBeforeRhsLexically) {
25   const char *lhs = "ab";
26   const char *rhs = "ac";
27   EXPECT_EQ(__llvm_libc::memcmp(lhs, rhs, 2), -1);
28 }
29 
30 TEST(LlvmLibcMemcmpTest, LhsAfterRhsLexically) {
31   const char *lhs = "ac";
32   const char *rhs = "ab";
33   EXPECT_EQ(__llvm_libc::memcmp(lhs, rhs, 2), 1);
34 }
35