summaryrefslogtreecommitdiff
path: root/libc/test/src/stdio/fwrite_test.cpp
blob: 9d38d84f160baa912e2bfaaf6c72e5ebae089397 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//===-- Unittests for fwrite ----------------------------------------------===//
//
// 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/CPP/Array.h"
#include "src/stdio/FILE.h"
#include "src/stdio/fwrite.h"
#include "utils/UnitTest/Test.h"

TEST(LlvmLibcStdio, FWriteBasic) {
  struct StrcpyFile : __llvm_libc::FILE {
    char *buf;
  } f;
  char array[6];
  f.buf = array;
  f.write = +[](__llvm_libc::FILE *file, const char *ptr, size_t size) {
    StrcpyFile *strcpyFile = static_cast<StrcpyFile *>(file);
    for (size_t i = 0; i < size; ++i)
      strcpyFile->buf[i] = ptr[i];
    return size;
  };
  EXPECT_EQ(fwrite("hello", 1, 6, &f), 6UL);
  EXPECT_STREQ(array, "hello");
}