| 1 | //===-- Unittests for printf ---------------------------------------------===// |
| 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 | #include "src/stdio/printf.h" |
| 10 | |
| 11 | #include "test/UnitTest/Test.h" |
| 12 | |
| 13 | TEST(LlvmLibcPrintfTest, PrintOut) { |
| 14 | int written; |
| 15 | |
| 16 | constexpr char simple[] = "A simple string with no conversions.\n" ; |
| 17 | written = LIBC_NAMESPACE::printf(simple); |
| 18 | EXPECT_EQ(written, static_cast<int>(sizeof(simple) - 1)); |
| 19 | |
| 20 | constexpr char numbers[] = "1234567890\n" ; |
| 21 | written = LIBC_NAMESPACE::printf("%s" , numbers); |
| 22 | EXPECT_EQ(written, static_cast<int>(sizeof(numbers) - 1)); |
| 23 | |
| 24 | constexpr char format_more[] = "%s and more\n" ; |
| 25 | constexpr char short_numbers[] = "1234" ; |
| 26 | written = LIBC_NAMESPACE::printf(format_more, short_numbers); |
| 27 | EXPECT_EQ(written, |
| 28 | static_cast<int>(sizeof(format_more) + sizeof(short_numbers) - 4)); |
| 29 | } |
| 30 | |