summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/clang-doc
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/unittests/clang-doc')
-rw-r--r--clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp4
-rw-r--r--clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp13
-rw-r--r--clang-tools-extra/unittests/clang-doc/ClangDocTest.h1
-rw-r--r--clang-tools-extra/unittests/clang-doc/MergeTest.cpp4
-rw-r--r--clang-tools-extra/unittests/clang-doc/SerializeTest.cpp84
-rw-r--r--clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp24
6 files changed, 118 insertions, 12 deletions
diff --git a/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp b/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
index ed75d994d9b..ca51f14dfaf 100644
--- a/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
@@ -81,6 +81,10 @@ TEST(BitcodeTest, emitRecordInfoBitcode) {
I.Members.emplace_back("int", "X", AccessSpecifier::AS_private);
I.TagType = TagTypeKind::TTK_Class;
I.IsTypeDef = true;
+ I.Bases.emplace_back(EmptySID, "F", "path/to/F", true,
+ AccessSpecifier::AS_public, true);
+ I.Bases.back().ChildFunctions.emplace_back();
+ I.Bases.back().Members.emplace_back("int", "X", AccessSpecifier::AS_private);
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 4350225df39..970ffcebd71 100644
--- a/clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "ClangDocTest.h"
#include "Representation.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "gtest/gtest.h"
@@ -168,6 +169,10 @@ void CheckRecordInfo(RecordInfo *Expected, RecordInfo *Actual) {
for (size_t Idx = 0; Idx < Actual->VirtualParents.size(); ++Idx)
CheckReference(Expected->VirtualParents[Idx], Actual->VirtualParents[Idx]);
+ ASSERT_EQ(Expected->Bases.size(), Actual->Bases.size());
+ for (size_t Idx = 0; Idx < Actual->Bases.size(); ++Idx)
+ CheckBaseRecordInfo(&Expected->Bases[Idx], &Actual->Bases[Idx]);
+
ASSERT_EQ(Expected->ChildRecords.size(), Actual->ChildRecords.size());
for (size_t Idx = 0; Idx < Actual->ChildRecords.size(); ++Idx)
CheckReference(Expected->ChildRecords[Idx], Actual->ChildRecords[Idx]);
@@ -182,6 +187,14 @@ void CheckRecordInfo(RecordInfo *Expected, RecordInfo *Actual) {
CheckEnumInfo(&Expected->ChildEnums[Idx], &Actual->ChildEnums[Idx]);
}
+void CheckBaseRecordInfo(BaseRecordInfo *Expected, BaseRecordInfo *Actual) {
+ CheckRecordInfo(Expected, Actual);
+
+ EXPECT_EQ(Expected->IsVirtual, Actual->IsVirtual);
+ EXPECT_EQ(Expected->Access, Actual->Access);
+ EXPECT_EQ(Expected->IsParent, Actual->IsParent);
+}
+
void CheckIndex(Index &Expected, Index &Actual) {
CheckReference(Expected, Actual);
ASSERT_EQ(Expected.Children.size(), Actual.Children.size());
diff --git a/clang-tools-extra/unittests/clang-doc/ClangDocTest.h b/clang-tools-extra/unittests/clang-doc/ClangDocTest.h
index a8c6fe5d29f..08f4534fd92 100644
--- a/clang-tools-extra/unittests/clang-doc/ClangDocTest.h
+++ b/clang-tools-extra/unittests/clang-doc/ClangDocTest.h
@@ -43,6 +43,7 @@ void CheckFunctionInfo(FunctionInfo *Expected, FunctionInfo *Actual);
void CheckEnumInfo(EnumInfo *Expected, EnumInfo *Actual);
void CheckNamespaceInfo(NamespaceInfo *Expected, NamespaceInfo *Actual);
void CheckRecordInfo(RecordInfo *Expected, RecordInfo *Actual);
+void CheckBaseRecordInfo(BaseRecordInfo *Expected, BaseRecordInfo *Actual);
void CheckIndex(Index &Expected, Index &Actual);
diff --git a/clang-tools-extra/unittests/clang-doc/MergeTest.cpp b/clang-tools-extra/unittests/clang-doc/MergeTest.cpp
index 7f738734dbd..31b565352ee 100644
--- a/clang-tools-extra/unittests/clang-doc/MergeTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/MergeTest.cpp
@@ -87,6 +87,8 @@ TEST(MergeTest, mergeRecordInfos) {
One.Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
One.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
+ One.Bases.emplace_back(EmptySID, "F", "path/to/F", true,
+ AccessSpecifier::AS_protected, true);
One.ChildRecords.emplace_back(NonEmptySID, "SharedChildStruct",
InfoType::IT_record);
One.ChildFunctions.emplace_back();
@@ -126,6 +128,8 @@ TEST(MergeTest, mergeRecordInfos) {
Expected->TagType = TagTypeKind::TTK_Class;
Expected->Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
Expected->VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
+ Expected->Bases.emplace_back(EmptySID, "F", "path/to/F", true,
+ AccessSpecifier::AS_protected, true);
Expected->ChildRecords.emplace_back(NonEmptySID, "SharedChildStruct",
InfoType::IT_record, "path");
diff --git a/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp b/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
index 757fff6fa8b..9c804ee5a7a 100644
--- a/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -321,15 +321,16 @@ TEST(SerializeTest, emitInlinedFunctionInfo) {
CheckNamespaceInfo(&ExpectedBWithFunction, BWithFunction);
}
-TEST(SerializeTest, ) {
+TEST(SerializeTest, emitInheritedRecordInfo) {
EmittedInfoList Infos;
- ExtractInfosFromCode(R"raw(class F {};
-class G {} ;
+ ExtractInfosFromCode(R"raw(class F { protected: void set(int N); };
+class G { public: int get() { return 1; } protected: int I; };
class E : public F, virtual private G {};
+class H : private E {};
template <typename T>
-class H {} ;
-class I : public H<int> {} ;)raw",
- 10, /*Public=*/false, Infos);
+class I {} ;
+class J : public I<int> {} ;)raw",
+ 14, /*Public=*/false, Infos);
RecordInfo *F = InfoAsRecord(Infos[0].get());
RecordInfo ExpectedF(EmptySID, "F");
@@ -337,32 +338,91 @@ class I : public H<int> {} ;)raw",
ExpectedF.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
CheckRecordInfo(&ExpectedF, F);
- RecordInfo *G = InfoAsRecord(Infos[2].get());
+ RecordInfo *G = InfoAsRecord(Infos[3].get());
RecordInfo ExpectedG(EmptySID, "G");
ExpectedG.TagType = TagTypeKind::TTK_Class;
ExpectedG.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
+ ExpectedG.Members.emplace_back("int", "I", AccessSpecifier::AS_protected);
CheckRecordInfo(&ExpectedG, G);
- RecordInfo *E = InfoAsRecord(Infos[4].get());
+ RecordInfo *E = InfoAsRecord(Infos[6].get());
RecordInfo ExpectedE(EmptySID, "E");
ExpectedE.Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
ExpectedE.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
+ ExpectedE.Bases.emplace_back(EmptySID, "F", "", false,
+ AccessSpecifier::AS_public, true);
+ FunctionInfo FunctionSet;
+ FunctionSet.Name = "set";
+ FunctionSet.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
+ FunctionSet.Loc.emplace_back();
+ FunctionSet.Params.emplace_back("int", "N");
+ FunctionSet.Namespace.emplace_back(EmptySID, "F", InfoType::IT_record);
+ FunctionSet.Access = AccessSpecifier::AS_protected;
+ FunctionSet.IsMethod = true;
+ ExpectedE.Bases.back().ChildFunctions.emplace_back(std::move(FunctionSet));
+ ExpectedE.Bases.emplace_back(EmptySID, "G", "", true,
+ AccessSpecifier::AS_private, true);
+ FunctionInfo FunctionGet;
+ FunctionGet.Name = "get";
+ FunctionGet.ReturnType = TypeInfo(EmptySID, "int", InfoType::IT_default);
+ FunctionGet.DefLoc = Location();
+ FunctionGet.Namespace.emplace_back(EmptySID, "G", InfoType::IT_record);
+ FunctionGet.Access = AccessSpecifier::AS_private;
+ FunctionGet.IsMethod = true;
+ ExpectedE.Bases.back().ChildFunctions.emplace_back(std::move(FunctionGet));
+ ExpectedE.Bases.back().Members.emplace_back("int", "I",
+ AccessSpecifier::AS_private);
ExpectedE.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
ExpectedE.TagType = TagTypeKind::TTK_Class;
CheckRecordInfo(&ExpectedE, E);
- RecordInfo *H = InfoAsRecord(Infos[6].get());
+ RecordInfo *H = InfoAsRecord(Infos[8].get());
RecordInfo ExpectedH(EmptySID, "H");
ExpectedH.TagType = TagTypeKind::TTK_Class;
ExpectedH.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
+ ExpectedH.Parents.emplace_back(EmptySID, "E", InfoType::IT_record);
+ ExpectedH.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
+ ExpectedH.Bases.emplace_back(EmptySID, "E", "", false,
+ AccessSpecifier::AS_private, true);
+ ExpectedH.Bases.emplace_back(EmptySID, "F", "", false,
+ AccessSpecifier::AS_private, false);
+ FunctionInfo FunctionSetNew;
+ FunctionSetNew.Name = "set";
+ FunctionSetNew.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
+ FunctionSetNew.Loc.emplace_back();
+ FunctionSetNew.Params.emplace_back("int", "N");
+ FunctionSetNew.Namespace.emplace_back(EmptySID, "F", InfoType::IT_record);
+ FunctionSetNew.Access = AccessSpecifier::AS_private;
+ FunctionSetNew.IsMethod = true;
+ ExpectedH.Bases.back().ChildFunctions.emplace_back(std::move(FunctionSetNew));
+ ExpectedH.Bases.emplace_back(EmptySID, "G", "", true,
+ AccessSpecifier::AS_private, false);
+ FunctionInfo FunctionGetNew;
+ FunctionGetNew.Name = "get";
+ FunctionGetNew.ReturnType = TypeInfo(EmptySID, "int", InfoType::IT_default);
+ FunctionGetNew.DefLoc = Location();
+ FunctionGetNew.Namespace.emplace_back(EmptySID, "G", InfoType::IT_record);
+ FunctionGetNew.Access = AccessSpecifier::AS_private;
+ FunctionGetNew.IsMethod = true;
+ ExpectedH.Bases.back().ChildFunctions.emplace_back(std::move(FunctionGetNew));
+ ExpectedH.Bases.back().Members.emplace_back("int", "I",
+ AccessSpecifier::AS_private);
CheckRecordInfo(&ExpectedH, H);
- RecordInfo *I = InfoAsRecord(Infos[8].get());
+ RecordInfo *I = InfoAsRecord(Infos[10].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;
+ ExpectedI.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
CheckRecordInfo(&ExpectedI, I);
+
+ RecordInfo *J = InfoAsRecord(Infos[12].get());
+ RecordInfo ExpectedJ(EmptySID, "J");
+ ExpectedJ.Parents.emplace_back(EmptySID, "I<int>", InfoType::IT_record);
+ ExpectedJ.Bases.emplace_back(EmptySID, "I<int>", "", false,
+ AccessSpecifier::AS_public, true);
+ ExpectedJ.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
+ ExpectedJ.TagType = TagTypeKind::TTK_Class;
+ CheckRecordInfo(&ExpectedJ, J);
}
TEST(SerializeTest, emitModulePublicLFunctions) {
diff --git a/clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp b/clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
index 61a7d5615e0..8d116d8df8b 100644
--- a/clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -84,6 +84,12 @@ TEST(YAMLGeneratorTest, emitRecordYAML) {
I.Members.emplace_back("int", "path/to/int", "X",
AccessSpecifier::AS_private);
I.TagType = TagTypeKind::TTK_Class;
+ I.Bases.emplace_back(EmptySID, "F", "path/to/F", true,
+ AccessSpecifier::AS_public, true);
+ I.Bases.back().ChildFunctions.emplace_back();
+ I.Bases.back().ChildFunctions.back().Name = "InheritedFunctionOne";
+ I.Bases.back().Members.emplace_back("int", "path/to/int", "N",
+ AccessSpecifier::AS_private);
// F is in the global namespace
I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record, "");
I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record,
@@ -123,6 +129,24 @@ Members:
Path: 'path/to/int'
Name: 'X'
Access: Private
+Bases:
+ - USR: '0000000000000000000000000000000000000000'
+ Name: 'F'
+ Path: 'path/to/F'
+ Members:
+ - Type:
+ Name: 'int'
+ Path: 'path/to/int'
+ Name: 'N'
+ Access: Private
+ ChildFunctions:
+ - USR: '0000000000000000000000000000000000000000'
+ Name: 'InheritedFunctionOne'
+ ReturnType: {}
+ Access: Public
+ IsVirtual: true
+ Access: Public
+ IsParent: true
Parents:
- Type: Record
Name: 'F'
OpenPOWER on IntegriCloud