Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / test / src / stdio / putc_test.cpp
blob7349a97d80e19dc01a5b4177c0b0e3082bedcea1
1 //===-- Unittests for putc ---------------------------------------------===//
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 #include "src/stdio/fclose.h"
10 #include "src/stdio/ferror.h"
11 #include "src/stdio/fopen.h"
12 #include "src/stdio/fread.h"
14 #include "src/stdio/putc.h"
16 #include "test/UnitTest/Test.h"
18 #include <stdio.h>
20 TEST(LlvmLibcPutcTest, WriteToFile) {
21 constexpr char FILENAME[] = "testdata/putc_output.test";
22 ::FILE *file = LIBC_NAMESPACE::fopen(FILENAME, "w");
23 ASSERT_FALSE(file == nullptr);
25 constexpr char simple[] = "simple letters";
26 for (size_t i = 0; i < sizeof(simple); ++i) {
27 ASSERT_EQ(LIBC_NAMESPACE::putc(simple[i], file), 0);
30 ASSERT_EQ(0, LIBC_NAMESPACE::fclose(file));
32 file = LIBC_NAMESPACE::fopen(FILENAME, "r");
33 ASSERT_FALSE(file == nullptr);
34 char data[50];
36 ASSERT_EQ(LIBC_NAMESPACE::fread(data, 1, sizeof(simple) - 1, file),
37 sizeof(simple) - 1);
38 data[sizeof(simple) - 1] = '\0';
40 ASSERT_STREQ(data, simple);
42 ASSERT_EQ(LIBC_NAMESPACE::ferror(file), 0);
43 EXPECT_LT(LIBC_NAMESPACE::putc('L', file), 0);
45 ASSERT_EQ(LIBC_NAMESPACE::fclose(file), 0);