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