llvm.org GIT mirror llvm / 072bd45
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 Dmitri Gribenko 6 years ago
1 changed file(s) with 22 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
6262 MB2.reset();
6363 MB3.reset();
6464 EXPECT_EQ("this is some data", data);
65 }
66
67 TEST_F(MemoryBufferTest, NullTerminator4K) {
68 // Test that a file with size that is a multiple of the page size can be null
69 // terminated correctly by MemoryBuffer.
70 int TestFD;
71 SmallString<64> TestPath;
72 sys::fs::createTemporaryFile("MemoryBufferTest_NullTerminator4K", "temp",
73 TestFD, TestPath);
74 raw_fd_ostream OF(TestFD, true, /*unbuffered=*/true);
75 for (unsigned i = 0; i < 4096 / 16; ++i) {
76 OF << "0123456789abcdef";
77 }
78 OF.close();
79
80 OwningPtr MB;
81 error_code EC = MemoryBuffer::getFile(TestPath, MB);
82 ASSERT_FALSE(EC);
83
84 const char *BufData = MB->getBufferStart();
85 EXPECT_EQ('f', BufData[4095]);
86 EXPECT_EQ('\0', BufData[4096]);
6587 }
6688
6789 TEST_F(MemoryBufferTest, copy) {