1 //===- llvm/unittest/Support/raw_fd_stream_test.cpp - raw_fd_stream tests -===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/SmallString.h"
10 #include "llvm/Config/llvm-config.h"
11 #include "llvm/Support/Casting.h"
12 #include "llvm/Support/FileSystem.h"
13 #include "llvm/Support/FileUtilities.h"
14 #include "llvm/Support/raw_ostream.h"
15 #include "gtest/gtest.h"
21 TEST(raw_fd_streamTest
, ReadAfterWrite
) {
24 ASSERT_FALSE(sys::fs::createTemporaryFile("foo", "bar", FD
, Path
));
25 FileRemover
Cleanup(Path
);
27 raw_fd_stream
OS(Path
, EC
);
32 OS
.write("01234567", 8);
35 EXPECT_EQ(OS
.read(Bytes
, 2), 2);
36 EXPECT_EQ(Bytes
[0], '3');
37 EXPECT_EQ(Bytes
[1], '4');
43 EXPECT_EQ(OS
.read(Bytes
, 8), 8);
44 EXPECT_EQ(Bytes
[0], '0');
45 EXPECT_EQ(Bytes
[1], '1');
46 EXPECT_EQ(Bytes
[2], '2');
47 EXPECT_EQ(Bytes
[3], '3');
48 EXPECT_EQ(Bytes
[4], 'x');
49 EXPECT_EQ(Bytes
[5], 'y');
50 EXPECT_EQ(Bytes
[6], 'z');
51 EXPECT_EQ(Bytes
[7], '7');
54 TEST(raw_fd_streamTest
, DynCast
) {
57 raw_fd_stream
OS("-", EC
);
58 EXPECT_TRUE(dyn_cast
<raw_fd_stream
>(&OS
));
62 raw_fd_ostream
OS("-", EC
);
63 EXPECT_FALSE(dyn_cast
<raw_fd_stream
>(&OS
));