Files
clang-p2996/libc/test/src/string/strlcat_test.cpp
Siva Chandra Reddy af1315c28f [libc][NFC] Move UnitTest and IntegrationTest to the 'test' directory.
This part of the effort to make all test related pieces into the `test`
directory. This helps is excluding test related pieces in a straight
forward manner if LLVM_INCLUDE_TESTS is OFF. Future patches will also move
the MPFR wrapper and testutils into the 'test' directory.
2023-02-07 19:45:51 +00:00

38 lines
1.1 KiB
C++

//===-- Unittests for strlcat ---------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "src/string/strlcat.h"
#include "test/UnitTest/Test.h"
#include <stdlib.h>
TEST(LlvmLibcStrlcatTest, TooBig) {
const char *str = "cd";
char buf[4]{"ab"};
EXPECT_EQ(__llvm_libc::strlcat(buf, str, 3), size_t(4));
EXPECT_STREQ(buf, "ab");
EXPECT_EQ(__llvm_libc::strlcat(buf, str, 4), size_t(4));
EXPECT_STREQ(buf, "abc");
}
TEST(LlvmLibcStrlcatTest, Smaller) {
const char *str = "cd";
char buf[7]{"ab"};
EXPECT_EQ(__llvm_libc::strlcat(buf, str, 7), size_t(4));
EXPECT_STREQ(buf, "abcd");
}
TEST(LlvmLibcStrlcatTest, No0) {
const char *str = "cd";
char buf[7]{"ab"};
EXPECT_EQ(__llvm_libc::strlcat(buf, str, 1), size_t(3));
EXPECT_STREQ(buf, "ab");
EXPECT_EQ(__llvm_libc::strlcat(buf, str, 2), size_t(4));
EXPECT_STREQ(buf, "ab");
}