llvm.org GIT mirror llvm / 238589e
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 Michael J. Spencer 9 years ago
1 changed file(s) with 23 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
210210 for (fs::directory_iterator i(".", ec), e; i != e; i.increment(ec))
211211 ASSERT_NO_ERROR(ec);
212212 }
213
214 TEST_F(FileSystemTest, Magic) {
215 struct type {
216 const char *filename;
217 const char *magic_str;
218 size_t magic_str_len;
219 } types [] = {{"magic.archive", "!\x0A", 8}};
220
221 // Create some files filled with magic.
222 for (type *i = types, *e = types + (sizeof(types) / sizeof(type)); i != e;
223 ++i) {
224 SmallString<128> file_pathname(TestDirectory);
225 path::append(file_pathname, i->filename);
226 std::string ErrMsg;
227 raw_fd_ostream file(file_pathname.c_str(), ErrMsg,
228 raw_fd_ostream::F_Binary);
229 ASSERT_FALSE(file.has_error());
230 StringRef magic(i->magic_str, i->magic_str_len);
231 file << magic;
232 file.flush();
233 bool res = false;
234 ASSERT_NO_ERROR(fs::has_magic(file_pathname.c_str(), magic, res));
235 EXPECT_TRUE(res);
213236 }
214237 }
215238