From c9024c6ebcea89746e01207195eeb52c60c3c3bb Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 13 Nov 2013 21:55:41 +0000 Subject: Path: Add tests for existing file magics. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194607 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/Support/Path.cpp | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'unittests') diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp index 7efaa5e..caf17b9 100644 --- a/unittests/Support/Path.cpp +++ b/unittests/Support/Path.cpp @@ -416,7 +416,23 @@ TEST_F(FileSystemTest, DirectoryIteration) { ASSERT_LT(z0, za1); } -const char elf[] = {0x7f, 'E', 'L', 'F', 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; +const char archive[] = "!\x0A"; +const char bitcode[] = "\xde\xc0\x17\x0b"; +const char elf_relocatable[] = { 0x7f, 'E', 'L', 'F', 1, 2, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1 }; +const char macho_universal_binary[] = "\xca\xfe\xba\xbe...\0x00"; +const char macho_object[] = "\xfe\xed\xfa\xce..........\x00\x01"; +const char macho_executable[] = "\xfe\xed\xfa\xce..........\x00\x02"; +const char macho_fixed_virtual_memory_shared_lib[] = + "\xfe\xed\xfa\xce..........\x00\x03"; +const char macho_core[] = "\xfe\xed\xfa\xce..........\x00\x04"; +const char macho_preload_executable[] = "\xfe\xed\xfa\xce..........\x00\x05"; +const char macho_dynamically_linked_shared_lib[] = + "\xfe\xed\xfa\xce..........\x00\x06"; +const char macho_dynamic_linker[] = "\xfe\xed\xfa\xce..........\x00\x07"; +const char macho_bundle[] = "\xfe\xed\xfa\xce..........\x00\x08"; +const char macho_dsym_companion[] = "\xfe\xed\xfa\xce..........\x00\x0a"; +const char windows_resource[] = "\x00\x00\x00\x00\x020\x00\x00\x00\xff"; TEST_F(FileSystemTest, Magic) { struct type { @@ -424,11 +440,25 @@ TEST_F(FileSystemTest, Magic) { const char *magic_str; size_t magic_str_len; fs::file_magic magic; - } types [] = { - {"magic.archive", "!\x0A", 8, fs::file_magic::archive}, - {"magic.elf", elf, sizeof(elf), - fs::file_magic::elf_relocatable} - }; + } types[] = { +#define DEFINE(magic) \ + { #magic, magic, sizeof(magic), fs::file_magic::magic } + DEFINE(archive), + DEFINE(bitcode), + DEFINE(elf_relocatable), + DEFINE(macho_universal_binary), + DEFINE(macho_object), + DEFINE(macho_executable), + DEFINE(macho_fixed_virtual_memory_shared_lib), + DEFINE(macho_core), + DEFINE(macho_preload_executable), + DEFINE(macho_dynamically_linked_shared_lib), + DEFINE(macho_dynamic_linker), + DEFINE(macho_bundle), + DEFINE(macho_dsym_companion), + DEFINE(windows_resource) +#undef DEFINE + }; // Create some files filled with magic. for (type *i = types, *e = types + (sizeof(types) / sizeof(type)); i != e; -- cgit v1.1