• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- Unittests for fwrite ----------------------------------------------===//
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/FILE.h"
10 #include "src/stdio/fwrite.h"
11 #include "utils/CPP/Array.h"
12 #include "utils/UnitTest/Test.h"
13 
TEST(Stdio,FWriteBasic)14 TEST(Stdio, FWriteBasic) {
15   struct StrcpyFile : __llvm_libc::FILE {
16     char *buf;
17   } f;
18   char array[6];
19   f.buf = array;
20   f.write = +[](__llvm_libc::FILE *file, const char *ptr, size_t size) {
21     StrcpyFile *strcpyFile = static_cast<StrcpyFile *>(file);
22     for (size_t i = 0; i < size; ++i)
23       strcpyFile->buf[i] = ptr[i];
24     return size;
25   };
26   EXPECT_EQ(fwrite("hello", 1, 6, &f), 6UL);
27   EXPECT_STREQ(array, "hello");
28 }
29