diff options
author | Zachary Turner <zturner@google.com> | 2017-03-20 23:33:18 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2017-03-20 23:33:18 +0000 |
commit | 82a0c97b32c2d581a239308a699f265f144e975b (patch) | |
tree | 0a10ad6e79b5e43a0ad7f44c0bdec40493d56aaf /llvm/unittests/Support/Path.cpp | |
parent | ba789cbd3da2fac7d46a39f8cef06d0ea51c5049 (diff) | |
download | bcm5719-llvm-82a0c97b32c2d581a239308a699f265f144e975b.tar.gz bcm5719-llvm-82a0c97b32c2d581a239308a699f265f144e975b.zip |
Add a function to MD5 a file's contents.
In doing so, clean up the MD5 interface a little. Most
existing users only care about the lower 8 bytes of an MD5,
but for some users that care about the upper and lower,
there wasn't a good interface. Furthermore, consumers
of the MD5 checksum were required to handle endianness
details on their own, so it seems reasonable to abstract
this into a nicer interface that just gives you the right
value.
Differential Revision: https://reviews.llvm.org/D31105
llvm-svn: 298322
Diffstat (limited to 'llvm/unittests/Support/Path.cpp')
-rw-r--r-- | llvm/unittests/Support/Path.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp index edda1cd6d24..4883adef165 100644 --- a/llvm/unittests/Support/Path.cpp +++ b/llvm/unittests/Support/Path.cpp @@ -1011,6 +1011,20 @@ TEST_F(FileSystemTest, Resize) { ASSERT_NO_ERROR(fs::remove(TempPath)); } +TEST_F(FileSystemTest, MD5) { + int FD; + SmallString<64> TempPath; + ASSERT_NO_ERROR(fs::createTemporaryFile("prefix", "temp", FD, TempPath)); + StringRef Data("abcdefghijklmnopqrstuvwxyz"); + write(FD, Data.data(), Data.size()); + lseek(FD, 0, SEEK_SET); + auto Hash = fs::md5_contents(FD); + ::close(FD); + ASSERT_NO_ERROR(Hash.getError()); + + EXPECT_STREQ("c3fcd3d76192e4007dfb496cca67e13b", Hash->digest().c_str()); +} + TEST_F(FileSystemTest, FileMapping) { // Create a temp file. int FileDescriptor; |