1 //===-- Unittests for vprintf --------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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
13 #include "src/stdio/vprintf.h"
15 #include "test/UnitTest/Test.h"
17 int call_vprintf(const char *__restrict format
, ...) {
19 va_start(vlist
, format
);
20 int ret
= LIBC_NAMESPACE::vprintf(format
, vlist
);
25 TEST(LlvmLibcVPrintfTest
, PrintOut
) {
28 constexpr char simple
[] = "A simple string with no conversions.\n";
29 written
= call_vprintf(simple
);
30 EXPECT_EQ(written
, static_cast<int>(sizeof(simple
) - 1));
32 constexpr char numbers
[] = "1234567890\n";
33 written
= call_vprintf("%s", numbers
);
34 EXPECT_EQ(written
, static_cast<int>(sizeof(numbers
) - 1));
36 constexpr char format_more
[] = "%s and more\n";
37 constexpr char short_numbers
[] = "1234";
38 written
= call_vprintf(format_more
, short_numbers
);
40 static_cast<int>(sizeof(format_more
) + sizeof(short_numbers
) - 4));