summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/unittests')
-rw-r--r--clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp1
-rw-r--r--clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp2
-rw-r--r--clang-tools-extra/unittests/clang-doc/SerializeTest.cpp78
3 files changed, 77 insertions, 4 deletions
diff --git a/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp b/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
index c89a6491b6c..a22f8af7394 100644
--- a/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
@@ -80,6 +80,7 @@ TEST(BitcodeTest, emitRecordInfoBitcode) {
I.Members.emplace_back("int", "X", AccessSpecifier::AS_private);
I.TagType = TagTypeKind::TTK_Class;
+ I.IsTypeDef = true;
I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
diff --git a/clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp b/clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
index 99ea76b7aff..75767986e63 100644
--- a/clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
@@ -151,6 +151,8 @@ void CheckRecordInfo(RecordInfo *Expected, RecordInfo *Actual) {
EXPECT_EQ(Expected->TagType, Actual->TagType);
+ EXPECT_EQ(Expected->IsTypeDef, Actual->IsTypeDef);
+
ASSERT_EQ(Expected->Members.size(), Actual->Members.size());
for (size_t Idx = 0; Idx < Actual->Members.size(); ++Idx)
EXPECT_EQ(Expected->Members[Idx], Actual->Members[Idx]);
diff --git a/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp b/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
index 1c044f7d0da..8a1ee77ebf2 100644
--- a/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -142,7 +142,15 @@ public:
E() {}
protected:
void ProtectedMethod();
-};)raw", 3, /*Public=*/false, Infos);
+};
+template <typename T>
+struct F {
+ void TemplateMethod();
+};
+template <>
+void F<int>::TemplateMethod();
+typedef struct {} G;)raw",
+ 7, /*Public=*/false, Infos);
RecordInfo *E = InfoAsRecord(Infos[0].get());
RecordInfo ExpectedE(EmptySID, "E");
@@ -176,6 +184,51 @@ protected:
Method.IsMethod = true;
ExpectedRecordWithMethod.ChildFunctions.emplace_back(std::move(Method));
CheckRecordInfo(&ExpectedRecordWithMethod, RecordWithMethod);
+
+ RecordInfo *F = InfoAsRecord(Infos[3].get());
+ RecordInfo ExpectedF(EmptySID, "F");
+ ExpectedF.TagType = TagTypeKind::TTK_Struct;
+ ExpectedF.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
+ CheckRecordInfo(&ExpectedF, F);
+
+ RecordInfo *RecordWithTemplateMethod = InfoAsRecord(Infos[4].get());
+ RecordInfo ExpectedRecordWithTemplateMethod(EmptySID);
+ FunctionInfo TemplateMethod;
+ TemplateMethod.Name = "TemplateMethod";
+ TemplateMethod.Parent = Reference(EmptySID, "F", InfoType::IT_record);
+ TemplateMethod.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
+ TemplateMethod.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"});
+ TemplateMethod.Namespace.emplace_back(EmptySID, "F", InfoType::IT_record);
+ TemplateMethod.Access = AccessSpecifier::AS_public;
+ TemplateMethod.IsMethod = true;
+ ExpectedRecordWithTemplateMethod.ChildFunctions.emplace_back(
+ std::move(TemplateMethod));
+ CheckRecordInfo(&ExpectedRecordWithTemplateMethod, RecordWithTemplateMethod);
+
+ RecordInfo *TemplatedRecord = InfoAsRecord(Infos[5].get());
+ RecordInfo ExpectedTemplatedRecord(EmptySID);
+ FunctionInfo SpecializedTemplateMethod;
+ SpecializedTemplateMethod.Name = "TemplateMethod";
+ SpecializedTemplateMethod.Parent =
+ Reference(EmptySID, "F", InfoType::IT_record);
+ SpecializedTemplateMethod.ReturnType =
+ TypeInfo(EmptySID, "void", InfoType::IT_default);
+ SpecializedTemplateMethod.Loc.emplace_back(0,
+ llvm::SmallString<16>{"test.cpp"});
+ SpecializedTemplateMethod.Namespace.emplace_back(EmptySID, "F",
+ InfoType::IT_record);
+ SpecializedTemplateMethod.Access = AccessSpecifier::AS_public;
+ SpecializedTemplateMethod.IsMethod = true;
+ ExpectedTemplatedRecord.ChildFunctions.emplace_back(
+ std::move(SpecializedTemplateMethod));
+ CheckRecordInfo(&ExpectedTemplatedRecord, TemplatedRecord);
+
+ RecordInfo *G = InfoAsRecord(Infos[6].get());
+ RecordInfo ExpectedG(EmptySID, "G");
+ ExpectedG.TagType = TagTypeKind::TTK_Struct;
+ ExpectedG.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
+ ExpectedG.IsTypeDef = true;
+ CheckRecordInfo(&ExpectedG, G);
}
// Test serialization of enum declarations.
@@ -284,9 +337,13 @@ TEST(SerializeTest, emitInlinedFunctionInfo) {
TEST(SerializeTest, emitInheritedRecordInfo) {
EmittedInfoList Infos;
- ExtractInfosFromCode(
- "class F {}; class G{} ; class E : public F, virtual private G {};", 3,
- /*Public=*/false, Infos);
+ ExtractInfosFromCode(R"raw(class F {};
+class G {} ;
+class E : public F, virtual private G {};
+template <typename T>
+class H {} ;
+class I : public H<int> {} ;)raw",
+ 5, /*Public=*/false, Infos);
RecordInfo *F = InfoAsRecord(Infos[0].get());
RecordInfo ExpectedF(EmptySID, "F");
@@ -307,6 +364,19 @@ TEST(SerializeTest, emitInheritedRecordInfo) {
ExpectedE.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
ExpectedE.TagType = TagTypeKind::TTK_Class;
CheckRecordInfo(&ExpectedE, E);
+
+ RecordInfo *H = InfoAsRecord(Infos[3].get());
+ RecordInfo ExpectedH(EmptySID, "H");
+ ExpectedH.TagType = TagTypeKind::TTK_Class;
+ ExpectedH.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
+ CheckRecordInfo(&ExpectedH, H);
+
+ RecordInfo *I = InfoAsRecord(Infos[4].get());
+ RecordInfo ExpectedI(EmptySID, "I");
+ ExpectedI.Parents.emplace_back(EmptySID, "H<int>", InfoType::IT_record);
+ ExpectedI.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
+ ExpectedI.TagType = TagTypeKind::TTK_Class;
+ CheckRecordInfo(&ExpectedI, I);
}
TEST(SerializeTest, emitModulePublicLFunctions) {
OpenPOWER on IntegriCloud