summaryrefslogtreecommitdiff
path: root/unittests/Support
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2011-01-06 05:58:02 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2011-01-06 05:58:02 +0000
commit238589ebf571a4acefbb02e47812f8e0cfaaec7f (patch)
tree24a317ae66041c4da9ae59fb361dc6eeb432b587 /unittests/Support
parentf9fd07864e992e6d934f05d5760e5600c399c6f0 (diff)
downloadllvm-238589ebf571a4acefbb02e47812f8e0cfaaec7f.tar.gz
llvm-238589ebf571a4acefbb02e47812f8e0cfaaec7f.tar.bz2
llvm-238589ebf571a4acefbb02e47812f8e0cfaaec7f.tar.xz
UnitTests/Path: Add magical tests. This will also test identify_magic.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122948 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Support')
-rw-r--r--unittests/Support/Path.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp
index a84ea732da..fa2b45f03b 100644
--- a/unittests/Support/Path.cpp
+++ b/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);
}
}