1c8f79892SGuillaume Chatelet //===-- Unittests for bcmp ------------------------------------------------===// 2c8f79892SGuillaume Chatelet // 3c8f79892SGuillaume Chatelet // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4c8f79892SGuillaume Chatelet // See https://llvm.org/LICENSE.txt for license information. 5c8f79892SGuillaume Chatelet // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6c8f79892SGuillaume Chatelet // 7c8f79892SGuillaume Chatelet //===----------------------------------------------------------------------===// 8c8f79892SGuillaume Chatelet 9c8f79892SGuillaume Chatelet #include "src/string/bcmp.h" 10c8f79892SGuillaume Chatelet #include "utils/UnitTest/Test.h" 11c8f79892SGuillaume Chatelet 12c8f79892SGuillaume Chatelet TEST(LlvmLibcBcmpTest, CmpZeroByte) { 13c8f79892SGuillaume Chatelet const char *lhs = "ab"; 14c8f79892SGuillaume Chatelet const char *rhs = "bc"; 15c8f79892SGuillaume Chatelet EXPECT_EQ(__llvm_libc::bcmp(lhs, rhs, 0), 0); 16c8f79892SGuillaume Chatelet } 17c8f79892SGuillaume Chatelet 18c8f79892SGuillaume Chatelet TEST(LlvmLibcBcmpTest, LhsRhsAreTheSame) { 19c8f79892SGuillaume Chatelet const char *lhs = "ab"; 20c8f79892SGuillaume Chatelet const char *rhs = "ab"; 21c8f79892SGuillaume Chatelet EXPECT_EQ(__llvm_libc::bcmp(lhs, rhs, 2), 0); 22c8f79892SGuillaume Chatelet } 23c8f79892SGuillaume Chatelet 24c8f79892SGuillaume Chatelet TEST(LlvmLibcBcmpTest, LhsBeforeRhsLexically) { 25c8f79892SGuillaume Chatelet const char *lhs = "ab"; 26c8f79892SGuillaume Chatelet const char *rhs = "ac"; 27*af059dfeSGuillaume Chatelet EXPECT_NE(__llvm_libc::bcmp(lhs, rhs, 2), 0); 28c8f79892SGuillaume Chatelet } 29c8f79892SGuillaume Chatelet 30c8f79892SGuillaume Chatelet TEST(LlvmLibcBcmpTest, LhsAfterRhsLexically) { 31c8f79892SGuillaume Chatelet const char *lhs = "ac"; 32c8f79892SGuillaume Chatelet const char *rhs = "ab"; 33*af059dfeSGuillaume Chatelet EXPECT_NE(__llvm_libc::bcmp(lhs, rhs, 2), 0); 34c8f79892SGuillaume Chatelet } 35c8f79892SGuillaume Chatelet 36c8f79892SGuillaume Chatelet TEST(LlvmLibcBcmpTest, Sweep) { 37c8f79892SGuillaume Chatelet static constexpr size_t kMaxSize = 1024; 38c8f79892SGuillaume Chatelet char lhs[kMaxSize]; 39c8f79892SGuillaume Chatelet char rhs[kMaxSize]; 40c8f79892SGuillaume Chatelet 41c8f79892SGuillaume Chatelet const auto reset = [](char *const ptr) { 42c8f79892SGuillaume Chatelet for (size_t i = 0; i < kMaxSize; ++i) 43c8f79892SGuillaume Chatelet ptr[i] = 'a'; 44c8f79892SGuillaume Chatelet }; 45c8f79892SGuillaume Chatelet 46c8f79892SGuillaume Chatelet reset(lhs); 47c8f79892SGuillaume Chatelet reset(rhs); 48c8f79892SGuillaume Chatelet for (size_t i = 0; i < kMaxSize; ++i) 49c8f79892SGuillaume Chatelet EXPECT_EQ(__llvm_libc::bcmp(lhs, rhs, i), 0); 50c8f79892SGuillaume Chatelet 51c8f79892SGuillaume Chatelet reset(lhs); 52c8f79892SGuillaume Chatelet reset(rhs); 53c8f79892SGuillaume Chatelet for (size_t i = 0; i < kMaxSize; ++i) { 54c8f79892SGuillaume Chatelet rhs[i] = 'b'; 55*af059dfeSGuillaume Chatelet EXPECT_NE(__llvm_libc::bcmp(lhs, rhs, kMaxSize), 0); 56c8f79892SGuillaume Chatelet rhs[i] = 'a'; 57c8f79892SGuillaume Chatelet } 58c8f79892SGuillaume Chatelet } 59