From 072bd45a36e06dd9ae0a46ce4bb029bea0ca9eae Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Wed, 4 Sep 2013 18:02:13 +0000 Subject: MemoryBufer: add a test: check that a file with size that is a multiple of the page size can be null terminated correctly by MemoryBuffer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189965 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/Support/MemoryBufferTest.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'unittests') diff --git a/unittests/Support/MemoryBufferTest.cpp b/unittests/Support/MemoryBufferTest.cpp index d9102e0..aa7ff6f 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 MB; + error_code EC = MemoryBuffer::getFile(TestPath, 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)); -- cgit v1.1