llvm.org GIT mirror llvm / c9024c6
Path: Add tests for existing file magics. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194607 91177308-0d34-0410-b5e6-96231b3b80d8 Rui Ueyama 5 years ago
1 changed file(s) with 36 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
415415 ASSERT_LT(z0, za1);
416416 }
417417
418 const char elf[] = {0x7f, 'E', 'L', 'F', 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
418 const char archive[] = "!\x0A";
419 const char bitcode[] = "\xde\xc0\x17\x0b";
420 const char elf_relocatable[] = { 0x7f, 'E', 'L', 'F', 1, 2, 1, 0, 0,
421 0, 0, 0, 0, 0, 0, 0, 0, 1 };
422 const char macho_universal_binary[] = "\xca\xfe\xba\xbe...\0x00";
423 const char macho_object[] = "\xfe\xed\xfa\xce..........\x00\x01";
424 const char macho_executable[] = "\xfe\xed\xfa\xce..........\x00\x02";
425 const char macho_fixed_virtual_memory_shared_lib[] =
426 "\xfe\xed\xfa\xce..........\x00\x03";
427 const char macho_core[] = "\xfe\xed\xfa\xce..........\x00\x04";
428 const char macho_preload_executable[] = "\xfe\xed\xfa\xce..........\x00\x05";
429 const char macho_dynamically_linked_shared_lib[] =
430 "\xfe\xed\xfa\xce..........\x00\x06";
431 const char macho_dynamic_linker[] = "\xfe\xed\xfa\xce..........\x00\x07";
432 const char macho_bundle[] = "\xfe\xed\xfa\xce..........\x00\x08";
433 const char macho_dsym_companion[] = "\xfe\xed\xfa\xce..........\x00\x0a";
434 const char windows_resource[] = "\x00\x00\x00\x00\x020\x00\x00\x00\xff";
419435
420436 TEST_F(FileSystemTest, Magic) {
421437 struct type {
423439 const char *magic_str;
424440 size_t magic_str_len;
425441 fs::file_magic magic;
426 } types [] = {
427 {"magic.archive", "!\x0A", 8, fs::file_magic::archive},
428 {"magic.elf", elf, sizeof(elf),
429 fs::file_magic::elf_relocatable}
430 };
442 } types[] = {
443 #define DEFINE(magic) \
444 { #magic, magic, sizeof(magic), fs::file_magic::magic }
445 DEFINE(archive),
446 DEFINE(bitcode),
447 DEFINE(elf_relocatable),
448 DEFINE(macho_universal_binary),
449 DEFINE(macho_object),
450 DEFINE(macho_executable),
451 DEFINE(macho_fixed_virtual_memory_shared_lib),
452 DEFINE(macho_core),
453 DEFINE(macho_preload_executable),
454 DEFINE(macho_dynamically_linked_shared_lib),
455 DEFINE(macho_dynamic_linker),
456 DEFINE(macho_bundle),
457 DEFINE(macho_dsym_companion),
458 DEFINE(windows_resource)
459 #undef DEFINE
460 };
431461
432462 // Create some files filled with magic.
433463 for (type *i = types, *e = types + (sizeof(types) / sizeof(type)); i != e;