Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / test / src / stdio / vprintf_test.cpp
blob40eba723a0070714d13f65a6d0d69831d2ca94c9
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 //===----------------------------------------------------------------------===//
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.
13 #include "src/stdio/vprintf.h"
15 #include "test/UnitTest/Test.h"
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;
25 TEST(LlvmLibcVPrintfTest, PrintOut) {
26 int written;
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);
39 EXPECT_EQ(written,
40 static_cast<int>(sizeof(format_more) + sizeof(short_numbers) - 4));