diff options
author | Stephen Hines <srhines@google.com> | 2014-02-11 20:01:10 -0800 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2014-02-11 20:01:10 -0800 |
commit | ce9904c6ea8fd669978a8eefb854b330eb9828ff (patch) | |
tree | 2418ee2e96ea220977c8fb74959192036ab5b133 /unittests/Support/MemoryBufferTest.cpp | |
parent | c27b10b198c1d9e9b51f2303994313ec2778edd7 (diff) | |
parent | dbb832b83351cec97b025b61c26536ef50c3181c (diff) | |
download | external_llvm-ce9904c6ea8fd669978a8eefb854b330eb9828ff.zip external_llvm-ce9904c6ea8fd669978a8eefb854b330eb9828ff.tar.gz external_llvm-ce9904c6ea8fd669978a8eefb854b330eb9828ff.tar.bz2 |
Merge remote-tracking branch 'upstream/release_34' into merge-20140211
Conflicts:
lib/Linker/LinkModules.cpp
lib/Support/Unix/Signals.inc
Change-Id: Ia54f291fa5dc828052d2412736e8495c1282aa64
Diffstat (limited to 'unittests/Support/MemoryBufferTest.cpp')
-rw-r--r-- | unittests/Support/MemoryBufferTest.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/unittests/Support/MemoryBufferTest.cpp b/unittests/Support/MemoryBufferTest.cpp index de1dbb7..2b8806c 100644 --- a/unittests/Support/MemoryBufferTest.cpp +++ b/unittests/Support/MemoryBufferTest.cpp @@ -65,6 +65,28 @@ TEST_F(MemoryBufferTest, get) { EXPECT_EQ("this is some data", data); } +TEST_F(MemoryBufferTest, NullTerminator4K) { + // Test that a file with size that is a multiple of the page size can be null + // terminated correctly by MemoryBuffer. + int TestFD; + SmallString<64> TestPath; + sys::fs::createTemporaryFile("MemoryBufferTest_NullTerminator4K", "temp", + TestFD, TestPath); + raw_fd_ostream OF(TestFD, true, /*unbuffered=*/true); + for (unsigned i = 0; i < 4096 / 16; ++i) { + OF << "0123456789abcdef"; + } + OF.close(); + + OwningPtr<MemoryBuffer> MB; + error_code EC = MemoryBuffer::getFile(TestPath.c_str(), MB); + ASSERT_FALSE(EC); + + const char *BufData = MB->getBufferStart(); + EXPECT_EQ('f', BufData[4095]); + EXPECT_EQ('\0', BufData[4096]); +} + TEST_F(MemoryBufferTest, copy) { // copy with no name OwningBuffer MBC1(MemoryBuffer::getMemBufferCopy(data)); @@ -112,7 +134,7 @@ void MemoryBufferTest::testGetOpenFileSlice(bool Reopen) { 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; If the file is not + // OF is responsible for closing the file; If the file is not // reopened, it will be unbuffered so that the results are // immediately visible through the fd. raw_fd_ostream OF(TestFD, true, !Reopen); @@ -128,7 +150,7 @@ void MemoryBufferTest::testGetOpenFileSlice(bool Reopen) { OwningBuffer Buf; error_code EC = MemoryBuffer::getOpenFileSlice(TestFD, TestPath.c_str(), Buf, 40000, // Size - 8000 // Offset + 80000 // Offset ); EXPECT_FALSE(EC); |