1 //===- unittests/AST/DeclTest.cpp --- Declaration 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 // Unit tests for the ASTVector container. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "llvm/Support/Compiler.h" 15 #include "clang/AST/ASTContext.h" 16 #include "clang/AST/ASTVector.h" 17 #include "clang/Basic/Builtins.h" 18 19 #include "gtest/gtest.h" 20 21 using namespace clang; 22 23 namespace clang { 24 namespace ast { 25 26 namespace { 27 class ASTVectorTest : public ::testing::Test { 28 protected: 29 ASTVectorTest() 30 : FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()), 31 Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()), 32 SourceMgr(Diags, FileMgr), Idents(LangOpts, nullptr), 33 Ctxt(LangOpts, SourceMgr, Idents, Sels, Builtins) {} 34 35 FileSystemOptions FileMgrOpts; 36 FileManager FileMgr; 37 IntrusiveRefCntPtr<DiagnosticIDs> DiagID; 38 DiagnosticsEngine Diags; 39 SourceManager SourceMgr; 40 LangOptions LangOpts; 41 IdentifierTable Idents; 42 SelectorTable Sels; 43 Builtin::Context Builtins; 44 ASTContext Ctxt; 45 }; 46 } // unnamed namespace 47 48 TEST_F(ASTVectorTest, Compile) { 49 ASTVector<int> V; 50 V.insert(Ctxt, V.begin(), 0); 51 } 52 53 TEST_F(ASTVectorTest, InsertFill) { 54 ASTVector<double> V; 55 56 // Ensure returned iterator points to first of inserted elements 57 auto I = V.insert(Ctxt, V.begin(), 5, 1.0); 58 ASSERT_EQ(V.begin(), I); 59 60 // Check non-empty case as well 61 I = V.insert(Ctxt, V.begin() + 1, 5, 1.0); 62 ASSERT_EQ(V.begin() + 1, I); 63 64 // And insert-at-end 65 I = V.insert(Ctxt, V.end(), 5, 1.0); 66 ASSERT_EQ(V.end() - 5, I); 67 } 68 69 TEST_F(ASTVectorTest, InsertEmpty) { 70 ASTVector<double> V; 71 72 // Ensure no pointer overflow when inserting empty range 73 int Values[] = { 0, 1, 2, 3 }; 74 ArrayRef<int> IntVec(Values); 75 auto I = V.insert(Ctxt, V.begin(), IntVec.begin(), IntVec.begin()); 76 ASSERT_EQ(V.begin(), I); 77 ASSERT_TRUE(V.empty()); 78 79 // Non-empty range 80 I = V.insert(Ctxt, V.begin(), IntVec.begin(), IntVec.end()); 81 ASSERT_EQ(V.begin(), I); 82 83 // Non-Empty Vector, empty range 84 I = V.insert(Ctxt, V.end(), IntVec.begin(), IntVec.begin()); 85 ASSERT_EQ(V.begin() + IntVec.size(), I); 86 87 // Non-Empty Vector, non-empty range 88 I = V.insert(Ctxt, V.end(), IntVec.begin(), IntVec.end()); 89 ASSERT_EQ(V.begin() + IntVec.size(), I); 90 } 91 92 } // end namespace ast 93 } // end namespace clang 94