1 //===- raw_pwrite_stream_test.cpp - raw_pwrite_stream tests ---------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "gtest/gtest.h"
11 #include "llvm/ADT/SmallString.h"
12 #include "llvm/Support/FileSystem.h"
13 #include "llvm/Support/raw_ostream.h"
19 TEST(raw_pwrite_ostreamTest, TestSVector) {
20 SmallVector<char, 0> Buffer;
21 raw_svector_ostream OS(Buffer);
23 StringRef Test = "test";
24 OS.pwrite(Test.data(), Test.size(), 0);
25 EXPECT_EQ(Test, OS.str());
27 #ifdef GTEST_HAS_DEATH_TEST
29 EXPECT_DEATH(OS.pwrite("12345", 5, 0),
30 "We don't support extending the stream");
35 TEST(raw_pwrite_ostreamTest, TestFD) {
38 sys::fs::createTemporaryFile("foo", "bar", FD, Path);
39 raw_fd_ostream OS(FD, true);
41 StringRef Test = "test";
42 OS.pwrite(Test.data(), Test.size(), 0);
43 OS.pwrite(Test.data(), Test.size(), 0);
45 #ifdef GTEST_HAS_DEATH_TEST
47 EXPECT_DEATH(OS.pwrite("12345", 5, 0),
48 "We don't support extending the stream");
54 TEST(raw_pwrite_ostreamTest, TestDevNull) {
56 sys::fs::openFileForWrite("/dev/null", FD, sys::fs::F_None);
57 raw_fd_ostream OS(FD, true);
59 StringRef Test = "test";
60 OS.pwrite(Test.data(), Test.size(), 0);
61 OS.pwrite(Test.data(), Test.size(), 0);