diff options
| author | Michael J. Spencer <bigcheesegs@gmail.com> | 2011-01-06 05:58:02 +0000 |
|---|---|---|
| committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2011-01-06 05:58:02 +0000 |
| commit | 1d3c4a7b94fca7c7c4d92f2ea23fb61171541637 (patch) | |
| tree | 3d9d64443abdcf6761b182661c5452a92534a6a8 | |
| parent | 1f06360002a0ea3b9d5a720a5a5f95841ca8e587 (diff) | |
| download | bcm5719-llvm-1d3c4a7b94fca7c7c4d92f2ea23fb61171541637.tar.gz bcm5719-llvm-1d3c4a7b94fca7c7c4d92f2ea23fb61171541637.zip | |
UnitTests/Path: Add magical tests. This will also test identify_magic.
llvm-svn: 122948
| -rw-r--r-- | llvm/unittests/Support/Path.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp index a84ea732dab..fa2b45f03b3 100644 --- a/llvm/unittests/Support/Path.cpp +++ b/llvm/unittests/Support/Path.cpp @@ -211,6 +211,29 @@ TEST_F(FileSystemTest, DirectoryIteration) { for (fs::directory_iterator i(".", ec), e; i != e; i.increment(ec)) ASSERT_NO_ERROR(ec); } + +TEST_F(FileSystemTest, Magic) { + struct type { + const char *filename; + const char *magic_str; + size_t magic_str_len; + } types [] = {{"magic.archive", "!<arch>\x0A", 8}}; + + // Create some files filled with magic. + for (type *i = types, *e = types + (sizeof(types) / sizeof(type)); i != e; + ++i) { + SmallString<128> file_pathname(TestDirectory); + path::append(file_pathname, i->filename); + std::string ErrMsg; + raw_fd_ostream file(file_pathname.c_str(), ErrMsg, + raw_fd_ostream::F_Binary); + ASSERT_FALSE(file.has_error()); + StringRef magic(i->magic_str, i->magic_str_len); + file << magic; + file.flush(); + bool res = false; + ASSERT_NO_ERROR(fs::has_magic(file_pathname.c_str(), magic, res)); + EXPECT_TRUE(res); } } |

