diff options
author | Eli Bendersky <eliben@google.com> | 2013-07-22 22:46:21 +0000 |
---|---|---|
committer | Eli Bendersky <eliben@google.com> | 2013-07-22 22:46:21 +0000 |
commit | f65712bfe35a038e5895ffc859bcf43fda35a8fd (patch) | |
tree | ee2e7cb797bd1cfd35bb42a01b821d40610fd437 /unittests | |
parent | bd8f8a34ba13067e23bfff743a58df53a11a475d (diff) | |
download | external_llvm-f65712bfe35a038e5895ffc859bcf43fda35a8fd.zip external_llvm-f65712bfe35a038e5895ffc859bcf43fda35a8fd.tar.gz external_llvm-f65712bfe35a038e5895ffc859bcf43fda35a8fd.tar.bz2 |
Add a simple unit test for MemoryBuffer::getOpenFile
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186887 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Support/MemoryBufferTest.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/unittests/Support/MemoryBufferTest.cpp b/unittests/Support/MemoryBufferTest.cpp index 1d9f482..336a0e4 100644 --- a/unittests/Support/MemoryBufferTest.cpp +++ b/unittests/Support/MemoryBufferTest.cpp @@ -11,7 +11,9 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/ADT/OwningPtr.h" #include "gtest/gtest.h" @@ -95,4 +97,35 @@ TEST_F(MemoryBufferTest, make_new) { EXPECT_EQ(0, Four->getBufferStart()[0]); } +TEST_F(MemoryBufferTest, getOpenFileNoNullTerminator) { + // Test that MemoryBuffer::getOpenFile works properly when no null + // terminator is requested and the size is large enough to trigger + // the usage of memory mapping. + int TestFD; + SmallString<64> TestPath; + // Create a temporary file and write data into it. + sys::fs::createTemporaryFile("prefix", "temp", TestFD, TestPath); + // OF is responsible for closing the file, and is unbuffered so that + // the results are immediately visible through the fd. + raw_fd_ostream OF(TestFD, true, true); + for (int i = 0; i < 60000; ++i) { + OF << "0123456789"; + } + + OwningBuffer Buf; + error_code EC = MemoryBuffer::getOpenFile(TestFD, + TestPath.c_str(), + Buf, + 40000, // Size + -1, + 8000, // Offset + false); + EXPECT_FALSE(EC); + + StringRef BufData = Buf->getBuffer(); + EXPECT_EQ(BufData.size(), 40000U); + EXPECT_EQ(BufData[0], '0'); + EXPECT_EQ(BufData[9], '9'); +} + } |