blob: 4b5d569a808db1e5384a6893da34f28fe845ea35 [file] [log] [blame]
David Blaikie67fc79f2013-07-13 19:23:35 +00001//===- 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"
Will Dietzdff50cb2014-08-25 16:09:51 +000017#include "clang/Basic/Builtins.h"
18
19#include "gtest/gtest.h"
20
David Blaikie67fc79f2013-07-13 19:23:35 +000021using namespace clang;
22
Will Dietzdff50cb2014-08-25 16:09:51 +000023namespace clang {
24namespace ast {
25
26namespace {
27class ASTVectorTest : public ::testing::Test {
28protected:
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
48TEST_F(ASTVectorTest, Compile) {
David Blaikie67fc79f2013-07-13 19:23:35 +000049 ASTVector<int> V;
Will Dietzdff50cb2014-08-25 16:09:51 +000050 V.insert(Ctxt, V.begin(), 0);
David Blaikie67fc79f2013-07-13 19:23:35 +000051}
Will Dietzdff50cb2014-08-25 16:09:51 +000052
53TEST_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
69TEST_F(ASTVectorTest, InsertEmpty) {
70 ASTVector<double> V;
71
72 // Ensure no pointer overflow when inserting empty range
Aaron Ballmancc7f4aa2014-08-26 14:17:25 +000073 int Values[] = { 0, 1, 2, 3 };
Aaron Ballmand71a5c72014-08-26 17:05:57 +000074 ArrayRef<int> IntVec(Values);
Will Dietzdff50cb2014-08-25 16:09:51 +000075 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