xref: /llvm-project/libc/test/src/stdio/printf_test.cpp (revision b6bc9d72f65a5086f310f321e969d96e9a559e75)
1ad233c60SMichael Jones //===-- Unittests for printf ---------------------------------------------===//
2ad233c60SMichael Jones //
3ad233c60SMichael Jones // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4ad233c60SMichael Jones // See https://llvm.org/LICENSE.txt for license information.
5ad233c60SMichael Jones // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6ad233c60SMichael Jones //
7ad233c60SMichael Jones //===----------------------------------------------------------------------===//
8ad233c60SMichael Jones 
9ad233c60SMichael Jones #include "src/stdio/printf.h"
10ad233c60SMichael Jones 
11af1315c2SSiva Chandra Reddy #include "test/UnitTest/Test.h"
12ad233c60SMichael Jones 
TEST(LlvmLibcPrintfTest,PrintOut)13ad233c60SMichael Jones TEST(LlvmLibcPrintfTest, PrintOut) {
14ad233c60SMichael Jones   int written;
15ad233c60SMichael Jones 
16ad233c60SMichael Jones   constexpr char simple[] = "A simple string with no conversions.\n";
17*b6bc9d72SGuillaume Chatelet   written = LIBC_NAMESPACE::printf(simple);
18ad233c60SMichael Jones   EXPECT_EQ(written, static_cast<int>(sizeof(simple) - 1));
19ad233c60SMichael Jones 
20ad233c60SMichael Jones   constexpr char numbers[] = "1234567890\n";
21*b6bc9d72SGuillaume Chatelet   written = LIBC_NAMESPACE::printf("%s", numbers);
22ad233c60SMichael Jones   EXPECT_EQ(written, static_cast<int>(sizeof(numbers) - 1));
23ad233c60SMichael Jones 
24ad233c60SMichael Jones   constexpr char format_more[] = "%s and more\n";
25ad233c60SMichael Jones   constexpr char short_numbers[] = "1234";
26*b6bc9d72SGuillaume Chatelet   written = LIBC_NAMESPACE::printf(format_more, short_numbers);
27ad233c60SMichael Jones   EXPECT_EQ(written,
28ad233c60SMichael Jones             static_cast<int>(sizeof(format_more) + sizeof(short_numbers) - 4));
29ad233c60SMichael Jones }
30