4 changes: 2 additions & 2 deletions libc/test/src/stdio/fopen_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "src/__support/File/file.h"
#include "src/stdio/fclose.h"
#include "src/stdio/fopen.h"
#include "src/stdio/fputs.h"
#include "src/stdio/fwrite.h"
#include "src/stdio/fread.h"

#include "test/UnitTest/Test.h"
Expand All @@ -21,7 +21,7 @@ TEST(LlvmLibcFOpenTest, PrintToFile) {
ASSERT_FALSE(file == nullptr);

static constexpr char STRING[] = "A simple string written to a file\n";
result = __llvm_libc::fputs(STRING, file);
result = __llvm_libc::fwrite(STRING, 1, sizeof(STRING) - 1, file);
EXPECT_GE(result, 0);

ASSERT_EQ(0, __llvm_libc::fclose(file));
Expand Down
30 changes: 30 additions & 0 deletions libc/test/src/stdio/fputc_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===-- Unittests for fputc / putchar -------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/__support/File/file.h"
#include "src/stdio/fputc.h"
#include "src/stdio/putchar.h"

#include "test/UnitTest/Test.h"

TEST(LlvmLibcPutcTest, PrintOut) {
int result;

constexpr char simple[] = "A simple string written to stdout\n";
for (const char &c : simple) {
result = __llvm_libc::putchar(c);
EXPECT_GE(result, 0);
}

constexpr char more[] = "A simple string written to stderr\n";
for (const char &c : simple) {
result =
__llvm_libc::fputc(c, reinterpret_cast<FILE *>(__llvm_libc::stderr));
}
EXPECT_GE(result, 0);
}