aboutsummaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2012-08-15 19:05:47 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2012-08-15 19:05:47 +0000
commit1ebd25e438444ae80ec3d9504fe2173b8306501d (patch)
treef65c9ea701488f59ab30a7f9091f135ab135370f /unittests
parentb9d565ac998fc857b20786bae08bb30719eb966b (diff)
[PathV2] Add mapped_file_region. Implementation for Windows and POSIX.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161976 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Support/Path.cpp59
1 files changed, 33 insertions, 26 deletions
diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp
index a071a5a8d6..30ad103420 100644
--- a/unittests/Support/Path.cpp
+++ b/unittests/Support/Path.cpp
@@ -340,44 +340,51 @@ TEST_F(FileSystemTest, Permissions) {
}
#endif
-#if !defined(_WIN32) // FIXME: temporary suppressed.
TEST_F(FileSystemTest, FileMapping) {
// Create a temp file.
int FileDescriptor;
SmallString<64> TempPath;
ASSERT_NO_ERROR(
fs::unique_file("%%-%%-%%-%%.temp", FileDescriptor, TempPath));
-
- // Grow temp file to be 4096 bytes
- ASSERT_NO_ERROR(sys::fs::resize_file(Twine(TempPath), 4096));
-
// Map in temp file and add some content
- void* MappedMemory;
- ASSERT_NO_ERROR(fs::map_file_pages(Twine(TempPath), 0, 4096,
- true /*writable*/, MappedMemory));
- char* Memory = reinterpret_cast<char*>(MappedMemory);
- strcpy(Memory, "hello there");
-
- // Unmap temp file
- ASSERT_NO_ERROR(fs::unmap_file_pages(MappedMemory, 4096));
- MappedMemory = NULL;
- Memory = NULL;
+ error_code EC;
+ StringRef Val("hello there");
+ {
+ fs::mapped_file_region mfr(FileDescriptor,
+ fs::mapped_file_region::readwrite,
+ 4096,
+ 0,
+ EC);
+ ASSERT_NO_ERROR(EC);
+ std::copy(Val.begin(), Val.end(), mfr.data());
+ // Explicitly add a 0.
+ mfr.data()[Val.size()] = 0;
+ // Unmap temp file
+ }
// Map it back in read-only
- ASSERT_NO_ERROR(fs::map_file_pages(Twine(TempPath), 0, 4096,
- false /*read-only*/, MappedMemory));
+ fs::mapped_file_region mfr(Twine(TempPath),
+ fs::mapped_file_region::readonly,
+ 0,
+ 0,
+ EC);
+ ASSERT_NO_ERROR(EC);
// Verify content
- Memory = reinterpret_cast<char*>(MappedMemory);
- bool SAME = (strcmp(Memory, "hello there") == 0);
- EXPECT_TRUE(SAME);
+ EXPECT_EQ(StringRef(mfr.const_data()), Val);
// Unmap temp file
- ASSERT_NO_ERROR(fs::unmap_file_pages(MappedMemory, 4096));
- MappedMemory = NULL;
- Memory = NULL;
-}
-#endif
-
+#ifdef LLVM_USE_RVALUE_REFERENCES
+ fs::mapped_file_region m(Twine(TempPath),
+ fs::mapped_file_region::readonly,
+ 0,
+ 0,
+ EC);
+ ASSERT_NO_ERROR(EC);
+ const char *Data = m.const_data();
+ fs::mapped_file_region mfrrv(llvm_move(m));
+ EXPECT_EQ(mfrrv.const_data(), Data);
+#endif
+}
} // anonymous namespace