1 //===- raw_pwrite_stream_test.cpp - raw_pwrite_stream tests ---------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "gtest/gtest.h"
11 #include "llvm/ADT/SmallString.h"
12 #include "llvm/Support/FileSystem.h"
13 #include "llvm/Support/raw_ostream.h"
14
15 using namespace llvm;
16
17 namespace {
18
TEST(raw_pwrite_ostreamTest,TestSVector)19 TEST(raw_pwrite_ostreamTest, TestSVector) {
20 SmallVector<char, 0> Buffer;
21 raw_svector_ostream OS(Buffer);
22 OS << "abcd";
23 StringRef Test = "test";
24 OS.pwrite(Test.data(), Test.size(), 0);
25 EXPECT_EQ(Test, OS.str());
26
27 #ifdef GTEST_HAS_DEATH_TEST
28 #ifndef NDEBUG
29 EXPECT_DEATH(OS.pwrite("12345", 5, 0),
30 "We don't support extending the stream");
31 #endif
32 #endif
33 }
34
TEST(raw_pwrite_ostreamTest,TestFD)35 TEST(raw_pwrite_ostreamTest, TestFD) {
36 SmallString<64> Path;
37 int FD;
38 sys::fs::createTemporaryFile("foo", "bar", FD, Path);
39 raw_fd_ostream OS(FD, true);
40 OS << "abcd";
41 StringRef Test = "test";
42 OS.pwrite(Test.data(), Test.size(), 0);
43 OS.pwrite(Test.data(), Test.size(), 0);
44
45 #ifdef GTEST_HAS_DEATH_TEST
46 #ifndef NDEBUG
47 EXPECT_DEATH(OS.pwrite("12345", 5, 0),
48 "We don't support extending the stream");
49 #endif
50 #endif
51 }
52
53 #ifdef LLVM_ON_UNIX
TEST(raw_pwrite_ostreamTest,TestDevNull)54 TEST(raw_pwrite_ostreamTest, TestDevNull) {
55 int FD;
56 sys::fs::openFileForWrite("/dev/null", FD, sys::fs::F_None);
57 raw_fd_ostream OS(FD, true);
58 OS << "abcd";
59 StringRef Test = "test";
60 OS.pwrite(Test.data(), Test.size(), 0);
61 OS.pwrite(Test.data(), Test.size(), 0);
62 }
63 #endif
64 }
65