//
//===----------------------------------------------------------------------===//
+#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;
} 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");
}
// 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.
// 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);
}
// 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.
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);
uint32_t RemovedCount;
ASSERT_NO_ERROR(fs::remove_all(TestDirectory.str(), RemovedCount));
}
-
-#endif // LLVM_ON_UNIX
-
} // anonymous namespace