xref: /llvm-project/libc/test/src/stdio/fputc_test.cpp (revision dbceb1d93667b2d29e78939cc24f67665fb5109b)
160c0d303SJoseph Huber //===-- Unittests for fputc / putchar -------------------------------------===//
260c0d303SJoseph Huber //
360c0d303SJoseph Huber // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
460c0d303SJoseph Huber // See https://llvm.org/LICENSE.txt for license information.
560c0d303SJoseph Huber // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
660c0d303SJoseph Huber //
760c0d303SJoseph Huber //===----------------------------------------------------------------------===//
860c0d303SJoseph Huber 
960c0d303SJoseph Huber #include "src/__support/File/file.h"
1060c0d303SJoseph Huber #include "src/stdio/fputc.h"
1160c0d303SJoseph Huber #include "src/stdio/putchar.h"
1260c0d303SJoseph Huber 
1360c0d303SJoseph Huber #include "test/UnitTest/Test.h"
1460c0d303SJoseph Huber 
TEST(LlvmLibcPutcTest,PrintOut)1560c0d303SJoseph Huber TEST(LlvmLibcPutcTest, PrintOut) {
1660c0d303SJoseph Huber   int result;
1760c0d303SJoseph Huber 
1860c0d303SJoseph Huber   constexpr char simple[] = "A simple string written to stdout\n";
1960c0d303SJoseph Huber   for (const char &c : simple) {
20b6bc9d72SGuillaume Chatelet     result = LIBC_NAMESPACE::putchar(c);
2160c0d303SJoseph Huber     EXPECT_GE(result, 0);
2260c0d303SJoseph Huber   }
2360c0d303SJoseph Huber 
2460c0d303SJoseph Huber   constexpr char more[] = "A simple string written to stderr\n";
25*dbceb1d9SMikhail R. Gadelha   for (const char &c : more) {
26b6bc9d72SGuillaume Chatelet     result = LIBC_NAMESPACE::fputc(
27b6bc9d72SGuillaume Chatelet         c, reinterpret_cast<FILE *>(LIBC_NAMESPACE::stderr));
2860c0d303SJoseph Huber   }
2960c0d303SJoseph Huber   EXPECT_GE(result, 0);
3060c0d303SJoseph Huber }
31