|
| 1 | +//===-- Unittests for wmemcmp ----------------------------------------------===// |
| 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/types/size_t.h" |
| 10 | +#include "hdr/types/wchar_t.h" |
| 11 | +#include "src/wchar/wmemcmp.h" |
| 12 | +#include "test/UnitTest/Test.h" |
| 13 | + |
| 14 | +TEST(LlvmLibcWMemcmpTest, CmpZeroByte) { |
| 15 | + // Comparing zero bytes should result in 0. |
| 16 | + const wchar_t *lhs = L"ab"; |
| 17 | + const wchar_t *rhs = L"yz"; |
| 18 | + EXPECT_EQ(LIBC_NAMESPACE::wmemcmp(lhs, rhs, 0), 0); |
| 19 | +} |
| 20 | + |
| 21 | +TEST(LlvmLibcWMemcmpTest, LhsRhsAreTheSame) { |
| 22 | + // Comparing strings of equal value should result in 0. |
| 23 | + const wchar_t *lhs = L"ab"; |
| 24 | + const wchar_t *rhs = L"ab"; |
| 25 | + EXPECT_EQ(LIBC_NAMESPACE::wmemcmp(lhs, rhs, 2), 0); |
| 26 | +} |
| 27 | + |
| 28 | +TEST(LlvmLibcWMemcmpTest, LhsBeforeRhsLexically) { |
| 29 | + // z after b, should result in a value less than 0. |
| 30 | + const wchar_t *lhs = L"ab"; |
| 31 | + const wchar_t *rhs = L"az"; |
| 32 | + EXPECT_LT(LIBC_NAMESPACE::wmemcmp(lhs, rhs, 2), 0); |
| 33 | +} |
| 34 | + |
| 35 | +TEST(LlvmLibcWMemcmpTest, LhsAfterRhsLexically) { |
| 36 | + // z after b, should result in a value greater than 0. |
| 37 | + const wchar_t *lhs = L"az"; |
| 38 | + const wchar_t *rhs = L"ab"; |
| 39 | + EXPECT_GT(LIBC_NAMESPACE::wmemcmp(lhs, rhs, 2), 0); |
| 40 | +} |
0 commit comments