blob: 2f820b9181deab52fdaca1eeb499670981f24717 [file] [log] [blame]
Michael J. Spencer013d15a2010-11-29 22:29:04 +00001//===- llvm/unittest/Support/Path.cpp - Path tests ------------------------===//
Michael J. Spencerf2ca4cb2010-11-24 19:20:05 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Rafael Espindolaa11c3e22013-06-11 22:21:28 +000010#include "llvm/Support/Path.h"
Michael J. Spencer753cbbb2010-12-06 04:28:42 +000011#include "llvm/Support/ErrorHandling.h"
Chandler Carruth5a88dda2012-12-04 10:23:08 +000012#include "llvm/Support/FileSystem.h"
Michael J. Spencerf9fd0782011-01-06 05:57:54 +000013#include "llvm/Support/raw_ostream.h"
Michael J. Spencerf2ca4cb2010-11-24 19:20:05 +000014#include "gtest/gtest.h"
15
Michael J. Spencerdffde992010-11-29 22:28:51 +000016using namespace llvm;
Michael J. Spencer3cb84ef2010-12-03 01:21:28 +000017using namespace llvm::sys;
Michael J. Spencerdffde992010-11-29 22:28:51 +000018
Michael J. Spencerba64b972011-01-04 17:00:18 +000019#define ASSERT_NO_ERROR(x) \
Michael J. Spencerf9fd0782011-01-06 05:57:54 +000020 if (error_code ASSERT_NO_ERROR_ec = x) { \
21 SmallString<128> MessageStorage; \
22 raw_svector_ostream Message(MessageStorage); \
23 Message << #x ": did not return errc::success.\n" \
24 << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
25 << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
26 GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \
Michael J. Spencerba64b972011-01-04 17:00:18 +000027 } else {}
28
Michael J. Spencerf2ca4cb2010-11-24 19:20:05 +000029namespace {
30
Zhanyong Wan63cc3a82011-02-11 21:24:40 +000031TEST(is_separator, Works) {
32 EXPECT_TRUE(path::is_separator('/'));
33 EXPECT_FALSE(path::is_separator('\0'));
34 EXPECT_FALSE(path::is_separator('-'));
35 EXPECT_FALSE(path::is_separator(' '));
36
37#ifdef LLVM_ON_WIN32
38 EXPECT_TRUE(path::is_separator('\\'));
39#else
40 EXPECT_FALSE(path::is_separator('\\'));
41#endif
42}
43
Michael J. Spencer013d15a2010-11-29 22:29:04 +000044TEST(Support, Path) {
Michael J. Spencerdffde992010-11-29 22:28:51 +000045 SmallVector<StringRef, 40> paths;
46 paths.push_back("");
47 paths.push_back(".");
48 paths.push_back("..");
49 paths.push_back("foo");
50 paths.push_back("/");
51 paths.push_back("/foo");
52 paths.push_back("foo/");
53 paths.push_back("/foo/");
54 paths.push_back("foo/bar");
55 paths.push_back("/foo/bar");
56 paths.push_back("//net");
57 paths.push_back("//net/foo");
58 paths.push_back("///foo///");
59 paths.push_back("///foo///bar");
60 paths.push_back("/.");
61 paths.push_back("./");
62 paths.push_back("/..");
63 paths.push_back("../");
64 paths.push_back("foo/.");
65 paths.push_back("foo/..");
66 paths.push_back("foo/./");
67 paths.push_back("foo/./bar");
68 paths.push_back("foo/..");
69 paths.push_back("foo/../");
70 paths.push_back("foo/../bar");
71 paths.push_back("c:");
72 paths.push_back("c:/");
73 paths.push_back("c:foo");
74 paths.push_back("c:/foo");
75 paths.push_back("c:foo/");
76 paths.push_back("c:/foo/");
77 paths.push_back("c:/foo/bar");
78 paths.push_back("prn:");
79 paths.push_back("c:\\");
80 paths.push_back("c:foo");
81 paths.push_back("c:\\foo");
82 paths.push_back("c:foo\\");
83 paths.push_back("c:\\foo\\");
84 paths.push_back("c:\\foo/");
85 paths.push_back("c:/foo\\bar");
86
87 for (SmallVector<StringRef, 40>::const_iterator i = paths.begin(),
88 e = paths.end();
89 i != e;
90 ++i) {
Michael J. Spencerdffde992010-11-29 22:28:51 +000091 for (sys::path::const_iterator ci = sys::path::begin(*i),
92 ce = sys::path::end(*i);
93 ci != ce;
94 ++ci) {
Michael J. Spencer371716c2010-12-03 02:22:34 +000095 ASSERT_FALSE(ci->empty());
Michael J. Spencerdffde992010-11-29 22:28:51 +000096 }
Michael J. Spencerdffde992010-11-29 22:28:51 +000097
Michael J. Spencer506e5792010-12-01 22:28:42 +000098#if 0 // Valgrind is whining about this.
Michael J. Spencera42cf732010-11-30 23:28:07 +000099 outs() << " Reverse Iteration: [";
100 for (sys::path::reverse_iterator ci = sys::path::rbegin(*i),
101 ce = sys::path::rend(*i);
102 ci != ce;
103 ++ci) {
104 outs() << *ci << ',';
105 }
106 outs() << "]\n";
Michael J. Spencer506e5792010-12-01 22:28:42 +0000107#endif
Michael J. Spencera42cf732010-11-30 23:28:07 +0000108
Michael J. Spencer50291592010-12-07 17:04:04 +0000109 path::has_root_path(*i);
110 path::root_path(*i);
111 path::has_root_name(*i);
112 path::root_name(*i);
113 path::has_root_directory(*i);
114 path::root_directory(*i);
115 path::has_parent_path(*i);
116 path::parent_path(*i);
117 path::has_filename(*i);
118 path::filename(*i);
119 path::has_stem(*i);
120 path::stem(*i);
121 path::has_extension(*i);
122 path::extension(*i);
123 path::is_absolute(*i);
124 path::is_relative(*i);
Michael J. Spencerdffde992010-11-29 22:28:51 +0000125
Michael J. Spencerba64b972011-01-04 17:00:18 +0000126 SmallString<128> temp_store;
Michael J. Spencer371716c2010-12-03 02:22:34 +0000127 temp_store = *i;
Michael J. Spencerba64b972011-01-04 17:00:18 +0000128 ASSERT_NO_ERROR(fs::make_absolute(temp_store));
Michael J. Spencer371716c2010-12-03 02:22:34 +0000129 temp_store = *i;
Michael J. Spencer936671b2010-12-07 03:57:37 +0000130 path::remove_filename(temp_store);
Michael J. Spencer1d389622010-12-01 06:03:33 +0000131
Michael J. Spencer371716c2010-12-03 02:22:34 +0000132 temp_store = *i;
Michael J. Spencer936671b2010-12-07 03:57:37 +0000133 path::replace_extension(temp_store, "ext");
Michael J. Spencer1d389622010-12-01 06:03:33 +0000134 StringRef filename(temp_store.begin(), temp_store.size()), stem, ext;
Michael J. Spencer50291592010-12-07 17:04:04 +0000135 stem = path::stem(filename);
136 ext = path::extension(filename);
Michael J. Spencer1d389622010-12-01 06:03:33 +0000137 EXPECT_EQ(*(--sys::path::end(filename)), (stem + ext).str());
138
Michael J. Spencer936671b2010-12-07 03:57:37 +0000139 path::native(*i, temp_store);
Michael J. Spencerdffde992010-11-29 22:28:51 +0000140 }
Michael J. Spencer25585162011-01-05 16:39:05 +0000141}
Michael J. Spencer3cb84ef2010-12-03 01:21:28 +0000142
Michael J. Spencer25585162011-01-05 16:39:05 +0000143class FileSystemTest : public testing::Test {
144protected:
145 /// Unique temporary directory in which all created filesystem entities must
146 /// be placed. It is recursively removed at the end of each test.
147 SmallString<128> TestDirectory;
148
149 virtual void SetUp() {
Michael J. Spencerf94f7322011-01-05 16:39:46 +0000150 int fd;
Michael J. Spencer25585162011-01-05 16:39:05 +0000151 ASSERT_NO_ERROR(
Michael J. Spencerf94f7322011-01-05 16:39:46 +0000152 fs::unique_file("file-system-test-%%-%%-%%-%%/test-directory.anchor", fd,
153 TestDirectory));
Michael J. Spencer25585162011-01-05 16:39:05 +0000154 // We don't care about this specific file.
Michael J. Spencerf94f7322011-01-05 16:39:46 +0000155 ::close(fd);
156 TestDirectory = path::parent_path(TestDirectory);
157 errs() << "Test Directory: " << TestDirectory << '\n';
158 errs().flush();
Michael J. Spencer25585162011-01-05 16:39:05 +0000159 }
160
161 virtual void TearDown() {
Michael J. Spencerf94f7322011-01-05 16:39:46 +0000162 uint32_t removed;
163 ASSERT_NO_ERROR(fs::remove_all(TestDirectory.str(), removed));
Michael J. Spencer25585162011-01-05 16:39:05 +0000164 }
165};
166
167TEST_F(FileSystemTest, TempFiles) {
Michael J. Spencer9ad82212010-12-04 03:18:42 +0000168 // Create a temp file.
Michael J. Spencer3cb84ef2010-12-03 01:21:28 +0000169 int FileDescriptor;
170 SmallString<64> TempPath;
Michael J. Spencerba64b972011-01-04 17:00:18 +0000171 ASSERT_NO_ERROR(
172 fs::unique_file("%%-%%-%%-%%.temp", FileDescriptor, TempPath));
Michael J. Spencer3cb84ef2010-12-03 01:21:28 +0000173
Michael J. Spencer9ad82212010-12-04 03:18:42 +0000174 // Make sure it exists.
Michael J. Spencer3cb84ef2010-12-03 01:21:28 +0000175 bool TempFileExists;
Michael J. Spencerba64b972011-01-04 17:00:18 +0000176 ASSERT_NO_ERROR(sys::fs::exists(Twine(TempPath), TempFileExists));
Michael J. Spencer3cb84ef2010-12-03 01:21:28 +0000177 EXPECT_TRUE(TempFileExists);
178
Michael J. Spencer9ad82212010-12-04 03:18:42 +0000179 // Create another temp tile.
180 int FD2;
181 SmallString<64> TempPath2;
Michael J. Spencerba64b972011-01-04 17:00:18 +0000182 ASSERT_NO_ERROR(fs::unique_file("%%-%%-%%-%%.temp", FD2, TempPath2));
Michael J. Spencer9ad82212010-12-04 03:18:42 +0000183 ASSERT_NE(TempPath.str(), TempPath2.str());
184
Michael J. Spencerd45fbe62011-12-12 06:04:28 +0000185 fs::file_status A, B;
186 ASSERT_NO_ERROR(fs::status(Twine(TempPath), A));
187 ASSERT_NO_ERROR(fs::status(Twine(TempPath2), B));
188 EXPECT_FALSE(fs::equivalent(A, B));
189
Michael J. Spencer9ad82212010-12-04 03:18:42 +0000190 // Try to copy the first to the second.
Michael J. Spencerba64b972011-01-04 17:00:18 +0000191 EXPECT_EQ(
192 fs::copy_file(Twine(TempPath), Twine(TempPath2)), errc::file_exists);
Michael J. Spencer9ad82212010-12-04 03:18:42 +0000193
194 ::close(FD2);
195 // Try again with the proper options.
Michael J. Spencerba64b972011-01-04 17:00:18 +0000196 ASSERT_NO_ERROR(fs::copy_file(Twine(TempPath), Twine(TempPath2),
197 fs::copy_option::overwrite_if_exists));
Michael J. Spencer9ad82212010-12-04 03:18:42 +0000198 // Remove Temp2.
Michael J. Spencerba64b972011-01-04 17:00:18 +0000199 ASSERT_NO_ERROR(fs::remove(Twine(TempPath2), TempFileExists));
Michael J. Spencer9ad82212010-12-04 03:18:42 +0000200 EXPECT_TRUE(TempFileExists);
201
202 // Make sure Temp2 doesn't exist.
Michael J. Spencerba64b972011-01-04 17:00:18 +0000203 ASSERT_NO_ERROR(fs::exists(Twine(TempPath2), TempFileExists));
Michael J. Spencer9ad82212010-12-04 03:18:42 +0000204 EXPECT_FALSE(TempFileExists);
205
206 // Create a hard link to Temp1.
Michael J. Spencerba64b972011-01-04 17:00:18 +0000207 ASSERT_NO_ERROR(fs::create_hard_link(Twine(TempPath), Twine(TempPath2)));
Michael J. Spencer9ad82212010-12-04 03:18:42 +0000208 bool equal;
Michael J. Spencerba64b972011-01-04 17:00:18 +0000209 ASSERT_NO_ERROR(fs::equivalent(Twine(TempPath), Twine(TempPath2), equal));
Michael J. Spencer9ad82212010-12-04 03:18:42 +0000210 EXPECT_TRUE(equal);
Michael J. Spencerd45fbe62011-12-12 06:04:28 +0000211 ASSERT_NO_ERROR(fs::status(Twine(TempPath), A));
212 ASSERT_NO_ERROR(fs::status(Twine(TempPath2), B));
213 EXPECT_TRUE(fs::equivalent(A, B));
Michael J. Spencer9ad82212010-12-04 03:18:42 +0000214
215 // Remove Temp1.
Michael J. Spencer3cb84ef2010-12-03 01:21:28 +0000216 ::close(FileDescriptor);
Michael J. Spencerba64b972011-01-04 17:00:18 +0000217 ASSERT_NO_ERROR(fs::remove(Twine(TempPath), TempFileExists));
Michael J. Spencer106aa732010-12-03 17:53:43 +0000218 EXPECT_TRUE(TempFileExists);
Michael J. Spencer3cb84ef2010-12-03 01:21:28 +0000219
Michael J. Spencer9ad82212010-12-04 03:18:42 +0000220 // Remove the hard link.
Michael J. Spencerba64b972011-01-04 17:00:18 +0000221 ASSERT_NO_ERROR(fs::remove(Twine(TempPath2), TempFileExists));
Michael J. Spencer9ad82212010-12-04 03:18:42 +0000222 EXPECT_TRUE(TempFileExists);
223
224 // Make sure Temp1 doesn't exist.
Michael J. Spencerba64b972011-01-04 17:00:18 +0000225 ASSERT_NO_ERROR(fs::exists(Twine(TempPath), TempFileExists));
Benjamin Kramer6d6d16a2010-12-03 12:33:32 +0000226 EXPECT_FALSE(TempFileExists);
Aaron Ballman551152f2013-03-16 15:00:51 +0000227
228#ifdef LLVM_ON_WIN32
229 // Path name > 260 chars should get an error.
230 const char *Path270 =
231 "abcdefghijklmnopqrstuvwxyz9abcdefghijklmnopqrstuvwxyz8"
232 "abcdefghijklmnopqrstuvwxyz7abcdefghijklmnopqrstuvwxyz6"
233 "abcdefghijklmnopqrstuvwxyz5abcdefghijklmnopqrstuvwxyz4"
234 "abcdefghijklmnopqrstuvwxyz3abcdefghijklmnopqrstuvwxyz2"
235 "abcdefghijklmnopqrstuvwxyz1abcdefghijklmnopqrstuvwxyz0";
236 EXPECT_EQ(fs::unique_file(Twine(Path270), FileDescriptor, TempPath),
237 windows_error::path_not_found);
238#endif
Michael J. Spencer25585162011-01-05 16:39:05 +0000239}
Michael J. Spencer753cbbb2010-12-06 04:28:42 +0000240
Michael J. Spencer25585162011-01-05 16:39:05 +0000241TEST_F(FileSystemTest, DirectoryIteration) {
Michael J. Spencer753cbbb2010-12-06 04:28:42 +0000242 error_code ec;
Michael J. Spencerf9fd0782011-01-06 05:57:54 +0000243 for (fs::directory_iterator i(".", ec), e; i != e; i.increment(ec))
244 ASSERT_NO_ERROR(ec);
Michael J. Spencera81ac8f2011-12-08 22:50:09 +0000245
246 // Create a known hierarchy to recurse over.
247 bool existed;
248 ASSERT_NO_ERROR(fs::create_directories(Twine(TestDirectory)
249 + "/recursive/a0/aa1", existed));
250 ASSERT_NO_ERROR(fs::create_directories(Twine(TestDirectory)
251 + "/recursive/a0/ab1", existed));
252 ASSERT_NO_ERROR(fs::create_directories(Twine(TestDirectory)
253 + "/recursive/dontlookhere/da1", existed));
254 ASSERT_NO_ERROR(fs::create_directories(Twine(TestDirectory)
255 + "/recursive/z0/za1", existed));
256 ASSERT_NO_ERROR(fs::create_directories(Twine(TestDirectory)
257 + "/recursive/pop/p1", existed));
258 typedef std::vector<std::string> v_t;
259 v_t visited;
260 for (fs::recursive_directory_iterator i(Twine(TestDirectory)
261 + "/recursive", ec), e; i != e; i.increment(ec)){
262 ASSERT_NO_ERROR(ec);
NAKAMURA Takumi52ee2302011-12-09 23:20:03 +0000263 if (path::filename(i->path()) == "p1") {
Michael J. Spencera81ac8f2011-12-08 22:50:09 +0000264 i.pop();
NAKAMURA Takumi52ee2302011-12-09 23:20:03 +0000265 // FIXME: recursive_directory_iterator should be more robust.
266 if (i == e) break;
267 }
Michael J. Spencerbd3825e2011-12-09 01:14:41 +0000268 if (path::filename(i->path()) == "dontlookhere")
269 i.no_push();
Michael J. Spencera81ac8f2011-12-08 22:50:09 +0000270 visited.push_back(path::filename(i->path()));
271 }
272 v_t::const_iterator a0 = std::find(visited.begin(), visited.end(), "a0");
273 v_t::const_iterator aa1 = std::find(visited.begin(), visited.end(), "aa1");
274 v_t::const_iterator ab1 = std::find(visited.begin(), visited.end(), "ab1");
275 v_t::const_iterator dontlookhere = std::find(visited.begin(), visited.end(),
276 "dontlookhere");
277 v_t::const_iterator da1 = std::find(visited.begin(), visited.end(), "da1");
278 v_t::const_iterator z0 = std::find(visited.begin(), visited.end(), "z0");
279 v_t::const_iterator za1 = std::find(visited.begin(), visited.end(), "za1");
280 v_t::const_iterator pop = std::find(visited.begin(), visited.end(), "pop");
281 v_t::const_iterator p1 = std::find(visited.begin(), visited.end(), "p1");
282
283 // Make sure that each path was visited correctly.
284 ASSERT_NE(a0, visited.end());
285 ASSERT_NE(aa1, visited.end());
286 ASSERT_NE(ab1, visited.end());
287 ASSERT_NE(dontlookhere, visited.end());
288 ASSERT_EQ(da1, visited.end()); // Not visited.
289 ASSERT_NE(z0, visited.end());
290 ASSERT_NE(za1, visited.end());
291 ASSERT_NE(pop, visited.end());
292 ASSERT_EQ(p1, visited.end()); // Not visited.
293
294 // Make sure that parents were visited before children. No other ordering
295 // guarantees can be made across siblings.
296 ASSERT_LT(a0, aa1);
297 ASSERT_LT(a0, ab1);
298 ASSERT_LT(z0, za1);
Michael J. Spencerf9fd0782011-01-06 05:57:54 +0000299}
Michael J. Spencer238589e2011-01-06 05:58:02 +0000300
Michael J. Spencerc0a74e22013-04-05 20:10:04 +0000301const char elf[] = {0x7f, 'E', 'L', 'F', 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
302
Michael J. Spencer238589e2011-01-06 05:58:02 +0000303TEST_F(FileSystemTest, Magic) {
304 struct type {
305 const char *filename;
306 const char *magic_str;
Michael J. Spencerc0a74e22013-04-05 20:10:04 +0000307 size_t magic_str_len;
308 fs::file_magic magic;
309 } types [] = {
310 {"magic.archive", "!<arch>\x0A", 8, fs::file_magic::archive},
311 {"magic.elf", elf, sizeof(elf),
312 fs::file_magic::elf_relocatable}
313 };
Michael J. Spencer238589e2011-01-06 05:58:02 +0000314
315 // Create some files filled with magic.
316 for (type *i = types, *e = types + (sizeof(types) / sizeof(type)); i != e;
317 ++i) {
318 SmallString<128> file_pathname(TestDirectory);
319 path::append(file_pathname, i->filename);
320 std::string ErrMsg;
321 raw_fd_ostream file(file_pathname.c_str(), ErrMsg,
322 raw_fd_ostream::F_Binary);
323 ASSERT_FALSE(file.has_error());
324 StringRef magic(i->magic_str, i->magic_str_len);
325 file << magic;
Michael J. Spencer248f9f22011-01-15 18:52:49 +0000326 file.close();
Michael J. Spencer238589e2011-01-06 05:58:02 +0000327 bool res = false;
328 ASSERT_NO_ERROR(fs::has_magic(file_pathname.c_str(), magic, res));
329 EXPECT_TRUE(res);
Michael J. Spencerc0a74e22013-04-05 20:10:04 +0000330 EXPECT_EQ(i->magic, fs::identify_magic(magic));
Michael J. Spencer753cbbb2010-12-06 04:28:42 +0000331 }
Michael J. Spencerf2ca4cb2010-11-24 19:20:05 +0000332}
333
NAKAMURA Takumiebbd6fe2012-06-24 03:48:34 +0000334#if !defined(_WIN32) // FIXME: Win32 has different permission schema.
Nick Kledzikca077ec2012-06-20 00:28:54 +0000335TEST_F(FileSystemTest, Permissions) {
336 // Create a temp file.
337 int FileDescriptor;
338 SmallString<64> TempPath;
339 ASSERT_NO_ERROR(
340 fs::unique_file("%%-%%-%%-%%.temp", FileDescriptor, TempPath));
341
342 // Mark file as read-only
343 const fs::perms AllWrite = fs::owner_write|fs::group_write|fs::others_write;
344 ASSERT_NO_ERROR(fs::permissions(Twine(TempPath), fs::remove_perms|AllWrite));
345
346 // Verify file is read-only
347 fs::file_status Status;
348 ASSERT_NO_ERROR(fs::status(Twine(TempPath), Status));
349 bool AnyWriteBits = (Status.permissions() & AllWrite);
350 EXPECT_FALSE(AnyWriteBits);
351
352 // Mark file as read-write
353 ASSERT_NO_ERROR(fs::permissions(Twine(TempPath), fs::add_perms|AllWrite));
354
355 // Verify file is read-write
356 ASSERT_NO_ERROR(fs::status(Twine(TempPath), Status));
357 AnyWriteBits = (Status.permissions() & AllWrite);
358 EXPECT_TRUE(AnyWriteBits);
359}
NAKAMURA Takumiebbd6fe2012-06-24 03:48:34 +0000360#endif
Nick Kledzikca077ec2012-06-20 00:28:54 +0000361
362TEST_F(FileSystemTest, FileMapping) {
363 // Create a temp file.
364 int FileDescriptor;
365 SmallString<64> TempPath;
366 ASSERT_NO_ERROR(
367 fs::unique_file("%%-%%-%%-%%.temp", FileDescriptor, TempPath));
Nick Kledzikca077ec2012-06-20 00:28:54 +0000368 // Map in temp file and add some content
Michael J. Spencer1ebd25e2012-08-15 19:05:47 +0000369 error_code EC;
370 StringRef Val("hello there");
371 {
372 fs::mapped_file_region mfr(FileDescriptor,
Michael J. Spencerd483d282013-03-14 00:33:37 +0000373 true,
Michael J. Spencer1ebd25e2012-08-15 19:05:47 +0000374 fs::mapped_file_region::readwrite,
375 4096,
376 0,
377 EC);
378 ASSERT_NO_ERROR(EC);
379 std::copy(Val.begin(), Val.end(), mfr.data());
380 // Explicitly add a 0.
381 mfr.data()[Val.size()] = 0;
382 // Unmap temp file
383 }
Nick Kledzikca077ec2012-06-20 00:28:54 +0000384
385 // Map it back in read-only
Michael J. Spencer1ebd25e2012-08-15 19:05:47 +0000386 fs::mapped_file_region mfr(Twine(TempPath),
387 fs::mapped_file_region::readonly,
388 0,
389 0,
390 EC);
391 ASSERT_NO_ERROR(EC);
Nick Kledzikca077ec2012-06-20 00:28:54 +0000392
393 // Verify content
Michael J. Spencer1ebd25e2012-08-15 19:05:47 +0000394 EXPECT_EQ(StringRef(mfr.const_data()), Val);
Nick Kledzikca077ec2012-06-20 00:28:54 +0000395
396 // Unmap temp file
Michael J. Spencer1ebd25e2012-08-15 19:05:47 +0000397
Chandler Carruth4334dd92012-11-30 11:45:22 +0000398#if LLVM_HAS_RVALUE_REFERENCES
Michael J. Spencer1ebd25e2012-08-15 19:05:47 +0000399 fs::mapped_file_region m(Twine(TempPath),
400 fs::mapped_file_region::readonly,
401 0,
402 0,
403 EC);
404 ASSERT_NO_ERROR(EC);
405 const char *Data = m.const_data();
406 fs::mapped_file_region mfrrv(llvm_move(m));
407 EXPECT_EQ(mfrrv.const_data(), Data);
NAKAMURA Takumiae241ea2012-06-24 03:48:40 +0000408#endif
Michael J. Spencer1ebd25e2012-08-15 19:05:47 +0000409}
Michael J. Spencerf2ca4cb2010-11-24 19:20:05 +0000410} // anonymous namespace