120
|
1 //=== llvm/unittest/ADT/DepthFirstIteratorTest.cpp - DFS iterator 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
|
121
|
10 #include "llvm/ADT/DepthFirstIterator.h"
|
120
|
11 #include "TestGraph.h"
|
|
12 #include "gtest/gtest.h"
|
|
13
|
|
14 using namespace llvm;
|
|
15
|
|
16 namespace llvm {
|
|
17
|
|
18 template <typename T> struct CountedSet {
|
|
19 typedef typename SmallPtrSet<T, 4>::iterator iterator;
|
|
20
|
|
21 SmallPtrSet<T, 4> S;
|
|
22 int InsertVisited = 0;
|
|
23
|
|
24 std::pair<iterator, bool> insert(const T &Item) {
|
|
25 InsertVisited++;
|
|
26 return S.insert(Item);
|
|
27 }
|
|
28
|
|
29 size_t count(const T &Item) const { return S.count(Item); }
|
|
30
|
|
31 void completed(T) { }
|
|
32 };
|
|
33
|
|
34 template <typename T> class df_iterator_storage<CountedSet<T>, true> {
|
|
35 public:
|
|
36 df_iterator_storage(CountedSet<T> &VSet) : Visited(VSet) {}
|
|
37
|
|
38 CountedSet<T> &Visited;
|
|
39 };
|
|
40
|
|
41 TEST(DepthFirstIteratorTest, ActuallyUpdateIterator) {
|
|
42 typedef CountedSet<Graph<3>::NodeType *> StorageT;
|
|
43 typedef df_iterator<Graph<3>, StorageT, true> DFIter;
|
|
44
|
|
45 Graph<3> G;
|
|
46 G.AddEdge(0, 1);
|
|
47 G.AddEdge(0, 2);
|
|
48 StorageT S;
|
|
49 for (auto N : make_range(DFIter::begin(G, S), DFIter::end(G, S)))
|
|
50 (void)N;
|
|
51
|
|
52 EXPECT_EQ(3, S.InsertVisited);
|
|
53 }
|
|
54 }
|