| 1 | //===-- Unittests for vprintf --------------------------------------------===// |
| 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 | // These tests are copies of the non-v variants of the printf functions. This is |
| 10 | // because these functions are identical in every way except for how the varargs |
| 11 | // are passed. |
| 12 | |
| 13 | #include "src/stdio/vprintf.h" |
| 14 | |
| 15 | #include "test/UnitTest/Test.h" |
| 16 | |
| 17 | int call_vprintf(const char *__restrict format, ...) { |
| 18 | va_list vlist; |
| 19 | va_start(vlist, format); |
| 20 | int ret = LIBC_NAMESPACE::vprintf(format, vlist); |
| 21 | va_end(vlist); |
| 22 | return ret; |
| 23 | } |
| 24 | |
| 25 | TEST(LlvmLibcVPrintfTest, PrintOut) { |
| 26 | int written; |
| 27 | |
| 28 | constexpr char simple[] = "A simple string with no conversions.\n" ; |
| 29 | written = call_vprintf(format: simple); |
| 30 | EXPECT_EQ(written, static_cast<int>(sizeof(simple) - 1)); |
| 31 | |
| 32 | constexpr char numbers[] = "1234567890\n" ; |
| 33 | written = call_vprintf(format: "%s" , numbers); |
| 34 | EXPECT_EQ(written, static_cast<int>(sizeof(numbers) - 1)); |
| 35 | |
| 36 | constexpr char format_more[] = "%s and more\n" ; |
| 37 | constexpr char short_numbers[] = "1234" ; |
| 38 | written = call_vprintf(format: format_more, short_numbers); |
| 39 | EXPECT_EQ(written, |
| 40 | static_cast<int>(sizeof(format_more) + sizeof(short_numbers) - 4)); |
| 41 | } |
| 42 | |