raw_pwrite_stream_test.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #include "gtest/gtest.h"
  10. #include "llvm/ADT/SmallString.h"
  11. #include "llvm/Support/FileSystem.h"
  12. #include "llvm/Support/raw_ostream.h"
  13. using namespace llvm;
  14. namespace {
  15. TEST(raw_pwrite_ostreamTest, TestSVector) {
  16. SmallVector<char, 0> Buffer;
  17. raw_svector_ostream OS(Buffer);
  18. OS << "abcd";
  19. StringRef Test = "test";
  20. OS.pwrite(Test.data(), Test.size(), 0);
  21. EXPECT_EQ(Test, OS.str());
  22. #ifdef GTEST_HAS_DEATH_TEST
  23. #ifndef NDEBUG
  24. EXPECT_DEATH(OS.pwrite("12345", 5, 0),
  25. "We don't support extending the stream");
  26. #endif
  27. #endif
  28. }
  29. TEST(raw_pwrite_ostreamTest, TestFD) {
  30. SmallString<64> Path;
  31. int FD;
  32. sys::fs::createTemporaryFile("foo", "bar", FD, Path);
  33. raw_fd_ostream OS(FD, true);
  34. OS << "abcd";
  35. StringRef Test = "test";
  36. OS.pwrite(Test.data(), Test.size(), 0);
  37. OS.pwrite(Test.data(), Test.size(), 0);
  38. #ifdef GTEST_HAS_DEATH_TEST
  39. #ifndef NDEBUG
  40. EXPECT_DEATH(OS.pwrite("12345", 5, 0),
  41. "We don't support extending the stream");
  42. #endif
  43. #endif
  44. }
  45. #ifdef LLVM_ON_UNIX
  46. TEST(raw_pwrite_ostreamTest, TestDevNull) {
  47. int FD;
  48. sys::fs::openFileForWrite("/dev/null", FD, sys::fs::F_None);
  49. raw_fd_ostream OS(FD, true);
  50. OS << "abcd";
  51. StringRef Test = "test";
  52. OS.pwrite(Test.data(), Test.size(), 0);
  53. OS.pwrite(Test.data(), Test.size(), 0);
  54. }
  55. #endif
  56. }