Duncan P. N. Exon Smith | b036f1c | 2015-02-03 21:08:33 +0000 | [diff] [blame] | 1 | //===- unittest/Support/DwarfTest.cpp - Dwarf support tests ---------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "llvm/Support/Dwarf.h" |
| 11 | #include "gtest/gtest.h" |
| 12 | |
| 13 | using namespace llvm; |
| 14 | using namespace llvm::dwarf; |
| 15 | |
| 16 | namespace { |
| 17 | |
| 18 | TEST(DwarfTest, TagStringOnInvalid) { |
| 19 | // This is invalid, so it shouldn't be stringified. |
| 20 | EXPECT_EQ(nullptr, TagString(DW_TAG_invalid)); |
| 21 | |
| 22 | // These aren't really tags: they describe ranges within tags. They |
| 23 | // shouldn't be stringified either. |
| 24 | EXPECT_EQ(nullptr, TagString(DW_TAG_lo_user)); |
| 25 | EXPECT_EQ(nullptr, TagString(DW_TAG_hi_user)); |
| 26 | EXPECT_EQ(nullptr, TagString(DW_TAG_user_base)); |
| 27 | } |
| 28 | |
Duncan P. N. Exon Smith | 6f5546c | 2015-02-03 21:16:49 +0000 | [diff] [blame] | 29 | TEST(DwarfTest, getTag) { |
| 30 | // A couple of valid tags. |
| 31 | EXPECT_EQ(DW_TAG_array_type, getTag("DW_TAG_array_type")); |
| 32 | EXPECT_EQ(DW_TAG_module, getTag("DW_TAG_module")); |
| 33 | |
| 34 | // Invalid tags. |
| 35 | EXPECT_EQ(DW_TAG_invalid, getTag("DW_TAG_invalid")); |
| 36 | EXPECT_EQ(DW_TAG_invalid, getTag("DW_TAG_madeuptag")); |
| 37 | EXPECT_EQ(DW_TAG_invalid, getTag("something else")); |
| 38 | |
| 39 | // Tag range markers should not be recognized. |
| 40 | EXPECT_EQ(DW_TAG_invalid, getTag("DW_TAG_lo_user")); |
| 41 | EXPECT_EQ(DW_TAG_invalid, getTag("DW_TAG_hi_user")); |
| 42 | EXPECT_EQ(DW_TAG_invalid, getTag("DW_TAG_user_base")); |
| 43 | } |
| 44 | |
Duncan P. N. Exon Smith | 4031beb | 2015-02-06 22:34:48 +0000 | [diff] [blame] | 45 | TEST(DwarfTest, LanguageStringOnInvalid) { |
| 46 | // This is invalid, so it shouldn't be stringified. |
| 47 | EXPECT_EQ(nullptr, LanguageString(0)); |
| 48 | |
| 49 | // These aren't really tags: they describe ranges within tags. They |
| 50 | // shouldn't be stringified either. |
| 51 | EXPECT_EQ(nullptr, LanguageString(DW_LANG_lo_user)); |
| 52 | EXPECT_EQ(nullptr, LanguageString(DW_LANG_hi_user)); |
| 53 | } |
| 54 | |
Duncan P. N. Exon Smith | d40af00 | 2015-02-06 22:55:13 +0000 | [diff] [blame] | 55 | TEST(DwarfTest, getLanguage) { |
| 56 | // A couple of valid languages. |
| 57 | EXPECT_EQ(DW_LANG_C89, getLanguage("DW_LANG_C89")); |
| 58 | EXPECT_EQ(DW_LANG_C_plus_plus_11, getLanguage("DW_LANG_C_plus_plus_11")); |
| 59 | EXPECT_EQ(DW_LANG_OCaml, getLanguage("DW_LANG_OCaml")); |
| 60 | EXPECT_EQ(DW_LANG_Mips_Assembler, getLanguage("DW_LANG_Mips_Assembler")); |
| 61 | |
| 62 | // Invalid languages. |
| 63 | EXPECT_EQ(0u, getLanguage("DW_LANG_invalid")); |
| 64 | EXPECT_EQ(0u, getLanguage("DW_TAG_array_type")); |
| 65 | EXPECT_EQ(0u, getLanguage("something else")); |
| 66 | |
| 67 | // Language range markers should not be recognized. |
| 68 | EXPECT_EQ(0u, getLanguage("DW_LANG_lo_user")); |
| 69 | EXPECT_EQ(0u, getLanguage("DW_LANG_hi_user")); |
| 70 | } |
| 71 | |
Duncan P. N. Exon Smith | 8d4eeb5 | 2015-02-06 23:44:24 +0000 | [diff] [blame^] | 72 | TEST(DwarfTest, AttributeEncodingStringOnInvalid) { |
| 73 | // This is invalid, so it shouldn't be stringified. |
| 74 | EXPECT_EQ(nullptr, AttributeEncodingString(0)); |
| 75 | |
| 76 | // These aren't really tags: they describe ranges within tags. They |
| 77 | // shouldn't be stringified either. |
| 78 | EXPECT_EQ(nullptr, AttributeEncodingString(DW_ATE_lo_user)); |
| 79 | EXPECT_EQ(nullptr, AttributeEncodingString(DW_ATE_hi_user)); |
| 80 | } |
| 81 | |
Duncan P. N. Exon Smith | b036f1c | 2015-02-03 21:08:33 +0000 | [diff] [blame] | 82 | } // end namespace |