diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2013-06-19 21:03:50 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2013-06-19 21:03:50 +0000 |
commit | 4655485eb7dc1d137595149b9bd58eb73e11bb19 (patch) | |
tree | 491409b3cdc3810bc088ef129469167e7c999d01 /unittests/Support | |
parent | 7032c883cdf8da579fbf9bf499d36a711eef676f (diff) | |
download | external_llvm-4655485eb7dc1d137595149b9bd58eb73e11bb19.zip external_llvm-4655485eb7dc1d137595149b9bd58eb73e11bb19.tar.gz external_llvm-4655485eb7dc1d137595149b9bd58eb73e11bb19.tar.bz2 |
Modified the implementation of fs::GetUniqueID on Windows such that it actually finds a unique identifier for a file. Also adds unit tests for GetUniqueID.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184351 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Support')
-rw-r--r-- | unittests/Support/Path.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp index 2f820b9..4f9d146 100644 --- a/unittests/Support/Path.cpp +++ b/unittests/Support/Path.cpp @@ -164,6 +164,42 @@ protected: } }; +TEST_F(FileSystemTest, Unique) { + // Create a temp file. + int FileDescriptor; + SmallString<64> TempPath; + ASSERT_NO_ERROR( + fs::unique_file("%%-%%-%%-%%.temp", FileDescriptor, TempPath)); + + // The same file should return an identical unique id. + uint64_t F1, F2; + ASSERT_NO_ERROR(fs::GetUniqueID(Twine(TempPath), F1)); + ASSERT_NO_ERROR(fs::GetUniqueID(Twine(TempPath), F2)); + ASSERT_EQ(F1, F2); + + // Different files should return different unique ids. + int FileDescriptor2; + SmallString<64> TempPath2; + ASSERT_NO_ERROR( + fs::unique_file("%%-%%-%%-%%.temp", FileDescriptor2, TempPath2)); + + uint64_t D; + ASSERT_NO_ERROR(fs::GetUniqueID(Twine(TempPath2), D)); + ASSERT_NE(D, F1); + ::close(FileDescriptor2); + + ASSERT_NO_ERROR(fs::remove(Twine(TempPath2))); + + // Two paths representing the same file on disk should still provide the + // same unique id. We can test this by making a hard link. + ASSERT_NO_ERROR(fs::create_hard_link(Twine(TempPath), Twine(TempPath2))); + uint64_t D2; + ASSERT_NO_ERROR(fs::GetUniqueID(Twine(TempPath2), D2)); + ASSERT_EQ(D2, F1); + + ::close(FileDescriptor); +} + TEST_F(FileSystemTest, TempFiles) { // Create a temp file. int FileDescriptor; |