Use move semantics if possible to construct ConstantRanges.
[oota-llvm.git] / unittests / Support / FileOutputBufferTest.cpp
index edd350afcf5bc885a559899e46f2a34af0ebf2ed..5e873193f28868fbcc8a41665354cd16111cf4d3 100644 (file)
@@ -7,13 +7,12 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/Support/FileOutputBuffer.h"
 #include "llvm/ADT/OwningPtr.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/FileOutputBuffer.h"
 #include "llvm/Support/FileSystem.h"
-#include "llvm/Support/PathV2.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
-
 #include "gtest/gtest.h"
 
 using namespace llvm;
@@ -27,25 +26,14 @@ using namespace llvm::sys;
   } else {}
 
 namespace {
-
-
-// NOTE: Temporarily run this test on unix only.  Once the file mapping
-// routines are ported to Windows, this conditional can be removed.
-#if LLVM_ON_UNIX
-
-
 TEST(FileOutputBuffer, Test) {
   // Create unique temporary directory for these tests
   SmallString<128> TestDirectory;
   {
-    int fd;
     ASSERT_NO_ERROR(
-      fs::unique_file("FileOutputBuffer-test-%%-%%-%%-%%/dir", fd,
-                      TestDirectory));
-    ::close(fd);
-    TestDirectory = path::parent_path(TestDirectory);
+        fs::createUniqueDirectory("FileOutputBuffer-test", TestDirectory));
   }
-     
+
   // TEST 1: Verify commit case.
   SmallString<128> File1(TestDirectory);
        File1.append("/file1");
@@ -61,7 +49,7 @@ TEST(FileOutputBuffer, Test) {
   }
   // Verify file exists and starts with special header.
   bool MagicMatches = false;
-  ASSERT_NO_ERROR(fs::has_magic(Twine(File1), Twine("AABBCCDDEEFFGGHHIIJJ"), 
+  ASSERT_NO_ERROR(fs::has_magic(Twine(File1), Twine("AABBCCDDEEFFGGHHIIJJ"),
                                                                 MagicMatches));
   EXPECT_TRUE(MagicMatches);
   // Verify file is correct size.
@@ -82,8 +70,7 @@ TEST(FileOutputBuffer, Test) {
   // Verify file does not exist (because buffer not commited).
   bool Exists = false;
   ASSERT_NO_ERROR(fs::exists(Twine(File2), Exists));
-  EXPECT_FALSE(Exists);  
-
+  EXPECT_FALSE(Exists);
 
   // TEST 3: Verify sizing down case.
   SmallString<128> File3(TestDirectory);
@@ -100,7 +87,7 @@ TEST(FileOutputBuffer, Test) {
   }
   // Verify file exists and starts with special header.
   bool MagicMatches3 = false;
-  ASSERT_NO_ERROR(fs::has_magic(Twine(File3), Twine("AABBCCDDEEFFGGHHIIJJ"), 
+  ASSERT_NO_ERROR(fs::has_magic(Twine(File3), Twine("AABBCCDDEEFFGGHHIIJJ"),
                                                               MagicMatches3));
   EXPECT_TRUE(MagicMatches3);
   // Verify file is correct size.
@@ -108,13 +95,12 @@ TEST(FileOutputBuffer, Test) {
   ASSERT_NO_ERROR(fs::file_size(Twine(File3), File3Size));
   ASSERT_EQ(File3Size, 5000ULL);
 
-
   // TEST 4: Verify file can be made executable.
   SmallString<128> File4(TestDirectory);
        File4.append("/file4");
   {
     OwningPtr<FileOutputBuffer> Buffer;
-    ASSERT_NO_ERROR(FileOutputBuffer::create(File4, 8192, Buffer, 
+    ASSERT_NO_ERROR(FileOutputBuffer::create(File4, 8192, Buffer,
                                               FileOutputBuffer::F_executable));
     // Start buffer with special header.
     memcpy(Buffer->getBufferStart(), "AABBCCDDEEFFGGHHIIJJ", 20);
@@ -131,7 +117,4 @@ TEST(FileOutputBuffer, Test) {
   uint32_t RemovedCount;
   ASSERT_NO_ERROR(fs::remove_all(TestDirectory.str(), RemovedCount));
 }
-
-#endif // LLVM_ON_UNIX
-
 } // anonymous namespace