[llvm-commits] [llvm] r122948 - /llvm/trunk/unittests/Support/Path.cpp
Michael J. Spencer
bigcheesegs at gmail.com
Wed Jan 5 21:58:02 PST 2011
Author: mspencer
Date: Wed Jan 5 23:58:02 2011
New Revision: 122948
URL: http://llvm.org/viewvc/llvm-project?rev=122948&view=rev
Log:
UnitTests/Path: Add magical tests. This will also test identify_magic.
Modified:
llvm/trunk/unittests/Support/Path.cpp
Modified: llvm/trunk/unittests/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/Path.cpp?rev=122948&r1=122947&r2=122948&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/Path.cpp (original)
+++ llvm/trunk/unittests/Support/Path.cpp Wed Jan 5 23:58:02 2011
@@ -211,6 +211,29 @@
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);
}
}
More information about the llvm-commits
mailing list